[FFmpeg-devel] [PATCH] Add crop filter

Michael Niedermayer michaelni
Mon Oct 12 09:28:29 CEST 2009


On Sun, Oct 11, 2009 at 09:40:40PM +0200, Stefano Sabatini wrote:
> On date Saturday 2009-10-10 01:51:39 +0200, Michael Niedermayer encoded:
> > On Wed, Oct 07, 2009 at 11:50:19PM +0200, Stefano Sabatini wrote:
> > > On date Tuesday 2009-10-06 15:01:32 +0200, Michael Niedermayer encoded:
> > > > On Tue, Oct 06, 2009 at 12:58:41AM +0200, Stefano Sabatini wrote:
[...]
> +#define SET_OFFSET(x, max)                                              \
> +    if (x < 0)                                                          \
> +        x = max + x;                                                    \
> +    if (x < 0 || x > max-1) {                                           \
> +        av_log(ctx, AV_LOG_ERROR, "Value for offset %d out of the valid range 0 - %d\n", x, max-1); \
> +        return -1;                                                      \
> +    }
> +
> +static int norm_size(int x, int max, int max_contained)
> +{
> +    if (x == 0)
> +        x = max;
> +    if (x < 0)
> +        x = max + x;
> +    return av_clip(x, 1, max_contained);
> +}
> +
> +static int config_input(AVFilterLink *link)
> +{
> +    AVFilterContext *ctx = link->dst;
> +    CropContext *crop = ctx->priv;
> +
> +    SET_OFFSET(crop->x, link->w);
> +    SET_OFFSET(crop->y, link->h);
> +
> +    crop->w = norm_size(crop->w, link->w, link->w - crop->x);
> +    crop->h = norm_size(crop->h, link->h, link->h - crop->y);

mess

if(   crop->x < 0 || crop->y < 0 || crop->w < 0 || crop->h < 0
   || (unsigned)crop->x + (unsigned)crop->w > link->w
   || (unsigned)crop->y + (unsigned)crop->h > link->h)


> +
> +    switch (link->format) {
> +    case PIX_FMT_RGB32:
> +    case PIX_FMT_BGR32:
> +        crop->bpp = 4;
> +        break;
> +    case PIX_FMT_RGB24:
> +    case PIX_FMT_BGR24:
> +        crop->bpp = 3;
> +        break;
> +    case PIX_FMT_RGB565:
> +    case PIX_FMT_RGB555:
> +    case PIX_FMT_BGR565:
> +    case PIX_FMT_BGR555:
> +    case PIX_FMT_GRAY16BE:
> +    case PIX_FMT_GRAY16LE:
> +        crop->bpp = 2;
> +        break;
> +    default:
> +        crop->bpp = 1;
> +    }

i wonder if we have some code that does that alraedy 


[...]
> +static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
> +{
> +    CropContext *crop = link->dst->priv;
> +    AVFilterPicRef *ref2 = avfilter_ref_pic(picref, ~0);
> +    int i;
> +
> +    ref2->w        = crop->w;
> +    ref2->h        = crop->h;
> +
> +    switch (link->format) {

> +    case PIX_FMT_MONOWHITE:
> +    case PIX_FMT_MONOBLACK:
> +        ref2->data[0] += (crop->y * ref2->linesize[0]) + (crop->x >> 3);
> +        break;
> +
> +    case PIX_FMT_PAL8:
> +        ref2->data[0] += crop->y * ref2->linesize[0] + crop->x;
> +        break;
> +
> +    default:
> +        ref2->data[0] += crop->y * ref2->linesize[0];
> +        ref2->data[0] += crop->x * crop->bpp;

that looks factorizeable


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I hate to see young programmers poisoned by the kind of thinking
Ulrich Drepper puts forward since it is simply too narrow -- Roman Shaposhnik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20091012/98d104f0/attachment.pgp>



More information about the ffmpeg-devel mailing list