[FFmpeg-devel] [PATCH] Add scale filter
Stefano Sabatini
stefano.sabatini-lala
Wed Oct 28 00:42:43 CET 2009
On date Tuesday 2009-10-27 13:34:06 +0100, Michael Niedermayer encoded:
> On Tue, Oct 27, 2009 at 02:59:38AM +0100, Stefano Sabatini wrote:
[...]
> > +static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
> > +{
> > + ScaleContext *scale = link->dst->priv;
> > + AVFilterLink *out = link->dst->outputs[0];
> > + int64_t gcd;
> > +
> > + out->outpic = avfilter_get_video_buffer(out, AV_PERM_WRITE, out->w, out->h);
> > + out->outpic->pts = picref->pts;
> > +
>
> > + out->outpic->pixel_aspect.num = picref->pixel_aspect.num * out->h * link->w;
> > + out->outpic->pixel_aspect.den = picref->pixel_aspect.den * out->w * link->h;
> > +
> > + gcd = av_gcd(out->outpic->pixel_aspect.num, out->outpic->pixel_aspect.den);
> > + if (gcd > 1) {
> > + out->outpic->pixel_aspect.num /= gcd;
> > + out->outpic->pixel_aspect.den /= gcd;
> > + }
>
> this can overflow and it should use av_reduce()
Changed to:
out->outpic->pts = picref->pts;
av_reduce(&out->outpic->pixel_aspect.num, &out->outpic->pixel_aspect.den,
(int64_t)picref->pixel_aspect.num * out->h * link->w,
(int64_t)picref->pixel_aspect.den * out->w * link->h,
INT_MAX);
But there is still the possibility to get an overflow in
the expressions:
(int64_t)picref->pixel_aspect.num * out->h * link->w
(int64_t)picref->pixel_aspect.den * out->w * link->h,
I could check for example for:
(int64_t)out->h * link->w < MAX_INT
(int64_t)out->w * link->h < MAX_INT
in config_props() and then eventually fail, but maybe you can suggest
some more clever way to check it.
> > +
> > + scale->slice_dir = 0;
> > + avfilter_start_frame(out, avfilter_ref_pic(out->outpic, ~0));
> > +}
> > +
> > +static void draw_slice(AVFilterLink *link, int y, int h)
> > +{
> > + ScaleContext *scale = link->dst->priv;
> > + int out_h;
> > + AVFilterPicRef *cur_pic = link->cur_pic;
> > + uint8_t *data[4];
> > +
>
> > + if (!scale->slice_dir && y != 0 && y + h != link->h) {
> > + av_log(scale, AV_LOG_ERROR, "Slices start in the middle!\n");
> > + return;
> > + }
> > + if (!scale->slice_dir) {
>
> this check can be factored out
Done.
> > + scale->slice_dir = y ? -1 : 1;
> > + scale->slice_y = y ? link->dst->outputs[0]->h : y;
> > + }
> > +
> > + data[0] = cur_pic->data[0] + y * cur_pic->linesize[0];
> > + data[3] = cur_pic->data[3] + y * cur_pic->linesize[3];
> > +
> > + if (link->format == PIX_FMT_PAL8) {
>
> > + data[1] = cur_pic->data[1];
> > + data[2] = cur_pic->data[2];
>
> can be factored out
Fixed.
Regards.
--
FFmpeg = Free & Frenzy Mystic Problematic Elitist Geek
-------------- next part --------------
A non-text attachment was scrubbed...
Name: add-scale-filter.patch
Type: text/x-diff
Size: 8916 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20091028/ba1058fa/attachment.patch>
More information about the ffmpeg-devel
mailing list