Ticket #2171: 2171-filters-v2.patch

File 2171-filters-v2.patch, 13.6 KB (added by danielk, 18 years ago)

ports adjust,kerneldeint and ivtc filters

  • filters/adjust/filter_adjust.c

     
    3434{
    3535    VideoFilter vf;
    3636
    37     int yend;
    38     int cend;
    39 
    40     int width;
    41     int height;
    42 
    4337#ifdef MMX
    4438    int yfilt;
    4539    int cfilt;
     
    141135}
    142136#endif /* MMX */
    143137
    144 static void SetupSize(ThisFilter *filter, VideoFrameType inpixfmt,
    145                       int *width, int *height)
    146 {
    147     filter->width = *width;
    148     filter->height = *height;
    149 
    150     filter->yend = *width * *height;
    151 
    152     switch (inpixfmt)
    153     {
    154         case FMT_YV12:
    155             filter->cend = filter->yend + *width * *height / 2;
    156             break;
    157         case FMT_YUV422P:
    158             filter->cend = filter->yend + *width * *height;
    159             break;
    160         default:
    161             break;
    162     }
    163 }
    164 
    165138int adjustFilter (VideoFilter *vf, VideoFrame *frame)
    166139{
    167140    ThisFilter *filter = (ThisFilter *) vf;
    168141    TF_VARS;
    169142
    170     if (frame->width != filter->width || frame->height != filter->height)
    171         SetupSize(filter, frame->codec, &frame->width, &frame->height);
    172 
    173143    TF_START;
     144    {
     145        unsigned char *ybeg = frame->buf + frame->offsets[0];
     146        unsigned char *yend = ybeg + (frame->pitches[0] * frame->height);
     147        int cheight = (frame->codec == FMT_YV12) ?
     148            (frame->height >> 1) : frame->height;
     149        unsigned char *ubeg = frame->buf + frame->offsets[1];
     150        unsigned char *uend = ubeg + (frame->pitches[1] * cheight);
     151        unsigned char *vbeg = frame->buf + frame->offsets[2];
     152        unsigned char *vend = ubeg + (frame->pitches[2] * cheight);
    174153
    175154#ifdef MMX
    176     if (filter->yfilt)
    177         adjustRegionMMX(frame->buf, frame->buf + filter->yend, filter->ytable,
    178                         &(filter->yshift), &(filter->yscale), &(filter->ymin),
    179                         mm_cpool + 1, mm_cpool + 2);
    180     else
    181         adjustRegion(frame->buf, frame->buf + filter->yend, filter->ytable);
     155        if (filter->yfilt)
     156            adjustRegionMMX(ybeg, yend, filter->ytable,
     157                            &(filter->yshift), &(filter->yscale),
     158                            &(filter->ymin), mm_cpool + 1, mm_cpool + 2);
     159        else
     160            adjustRegion(ybeg, yend, filter->ytable);
    182161
    183     if (filter->cfilt)
    184         adjustRegionMMX(frame->buf + filter->yend, frame->buf + filter->cend,
    185                         filter->ctable, &(filter->cshift), &(filter->cscale),
    186                         &(filter->cmin), mm_cpool + 3, mm_cpool + 4);
    187     else
    188         adjustRegion(frame->buf + filter->yend, frame->buf + filter->cend,
    189                      filter->ctable);
     162        if (filter->cfilt)
     163        {
     164            adjustRegionMMX(ubeg, uend, filter->ctable,
     165                            &(filter->cshift), &(filter->cscale),
     166                            &(filter->cmin), mm_cpool + 3, mm_cpool + 4);
     167            adjustRegionMMX(vbeg, vend, filter->ctable,
     168                            &(filter->cshift), &(filter->cscale),
     169                            &(filter->cmin), mm_cpool + 3, mm_cpool + 4);
     170        }
     171        else
     172        {
     173            adjustRegion(ubeg, uend, filter->ctable);
     174            adjustRegion(vbeg, vend, filter->ctable);
     175        }
    190176
    191     if (filter->yfilt || filter->cfilt)
    192         emms();
     177        if (filter->yfilt || filter->cfilt)
     178            emms();
    193179
    194180#else /* MMX */
    195     adjustRegion(frame->buf, frame->buf + filter->yend, filter->ytable);
    196     adjustRegion(frame->buf + filter->yend, frame->buf + filter->cend,
    197                 filter->ctable);
     181        adjustRegion(ybeg, yend, filter->ytable);
     182        adjustRegion(ubeg, uend, filter->ctable);
     183        adjustRegion(vbeg, vend, filter->ctable);
    198184#endif /* MMX */
    199 
     185    }
    200186    TF_END(filter, "Adjust: ");
    201187    return 0;
    202188}
     
    249235
    250236VideoFilter *
    251237newAdjustFilter (VideoFrameType inpixfmt, VideoFrameType outpixfmt,
    252                     int *width, int *height, char *options)
     238                 int *width, int *height, char *options)
    253239{
    254240    ThisFilter *filter;
    255241    int numopts, ymin, ymax, cmin, cmax;
    256242    float ygamma, cgamma;
     243    (void) width;
     244    (void) height;
    257245
    258246    if (inpixfmt != outpixfmt ||
    259247        (inpixfmt != FMT_YV12 && inpixfmt != FMT_YUV422P))
     
    305293    fillTable (filter->ctable, cmin, cmax, 16, 240, cgamma);
    306294#endif
    307295
    308     SetupSize(filter, inpixfmt, width, height);
    309 
    310296    filter->vf.filter = &adjustFilter;
    311297    filter->vf.cleanup = NULL;
    312298   
  • filters/kerneldeint/filter_kerneldeint.c

     
    1616#include "config.h"
    1717#include "dsputil.h"
    1818
     19#undef ABS
    1920#define ABS(A) ( (A) > 0 ? (A) : -(A) )
    2021#define CLAMP(A,L,U) ((A)>(U)?(U):((A)<(L)?(L):(A)))
    2122
     
    3536{
    3637    VideoFilter vf;
    3738
    38     int width;
    39     int height;
    40     int uoff;
    41     int voff;
    42     int cwidth;
    43     int cheight;
    4439    int threshold;
    4540    int skipchroma;
    4641    int mm_flags;
    47     int size;
    4842    void (*filtfunc)(uint8_t*, uint8_t*, int, int, int);
    4943    mmx_t threshold_low;
    5044    mmx_t threshold_high;
    5145    uint8_t *line;
     46    int linesize;
    5247    TF_STRUCT;
    5348} ThisFilter;
    5449
     
    249244}
    250245#endif
    251246
    252 static void SetupSize(ThisFilter *filter, VideoFrameType inpixfmt,
    253                       int *width, int *height)
    254 {
    255     filter->width = *width;
    256     filter->height = *height;
    257     filter->cwidth = *width / 2;
    258     filter->uoff = *width * *height;
    259 
    260     switch (inpixfmt)
    261     {
    262         case FMT_YUV422P:
    263             filter->voff = filter->uoff + *width * *height / 2;
    264             filter->size = *width * *height * 2;
    265             filter->cheight = *height;
    266             break;
    267         case FMT_YV12:
    268             filter->voff = filter->uoff + *width * *height / 4;
    269             filter->size = *width * *height * 3 / 2;
    270             filter->cheight = *height / 2;
    271             break;
    272         default:
    273             ;
    274     }
    275 
    276     if (filter->line)
    277         free(filter->line);
    278 
    279     filter->line = malloc(*width);
    280 }
    281 
    282247static int
    283248KernelDeint (VideoFilter * f, VideoFrame * frame)
    284249{
    285250    ThisFilter *filter = (ThisFilter *) f;
    286251    TF_VARS;
    287252
    288     if (frame->width != filter->width || frame->height != filter->height)
    289         SetupSize(filter, frame->codec, &frame->width, &frame->height);
     253    if (frame->pitches[0] > filter->linesize)
     254    {
     255        if (filter->line)
     256            free(filter->line);
     257        filter->line = malloc(frame->pitches[0]);
     258        filter->linesize = frame->pitches[0];
     259    }
    290260
    291261    if (!filter->line)
    292262    {
     
    295265    }
    296266
    297267    TF_START;
    298     (filter->filtfunc)(frame->buf, filter->line, filter->width,
    299                            filter->height, filter->threshold);
    300     if (!filter->skipchroma)
    301268    {
    302         (filter->filtfunc)(frame->buf + filter->uoff, filter->line,
    303                            filter->cwidth, filter->cheight, filter->threshold);
    304         (filter->filtfunc)(frame->buf + filter->voff, filter->line,
    305                            filter->cwidth, filter->cheight, filter->threshold);
    306     }
     269        unsigned char *ybeg = frame->buf + frame->offsets[0];
     270        unsigned char *ubeg = frame->buf + frame->offsets[1];
     271        unsigned char *vbeg = frame->buf + frame->offsets[2];
     272        int cheight = (frame->codec == FMT_YV12) ?
     273            (frame->height >> 1) : frame->height;
     274
     275        (filter->filtfunc)(ybeg, filter->line, frame->pitches[0],
     276                           frame->height, filter->threshold);
     277
     278        if (!filter->skipchroma)
     279        {
     280            (filter->filtfunc)(ubeg, filter->line, frame->pitches[1],
     281                               cheight, filter->threshold);
     282            (filter->filtfunc)(vbeg, filter->line, frame->pitches[2],
     283                               cheight, filter->threshold);
     284        }
    307285#ifdef MMX
    308     if (filter->mm_flags)
    309         emms();
     286        if (filter->mm_flags)
     287            emms();
    310288#endif
     289    }
    311290    TF_END(filter, "KernelDeint: ");
    312291    return 0;
    313292}
     
    315294void
    316295CleanupKernelDeintFilter (VideoFilter * filter)
    317296{
    318     free (((ThisFilter *)filter)->line);
     297    if (((ThisFilter *)filter)->line)
     298        free (((ThisFilter *)filter)->line);
    319299}
    320300
    321301VideoFilter *
     
    324304{
    325305    ThisFilter *filter;
    326306    int numopts;
     307    (void) height;
    327308
    328309    if ( inpixfmt != outpixfmt ||
    329310        (inpixfmt != FMT_YV12 && inpixfmt != FMT_YUV422P) )
     
    356337#endif
    357338        filter->filtfunc = &KDP;
    358339
    359     filter->line = NULL;
    360     SetupSize(filter, inpixfmt, width, height);
     340    filter->line = malloc(*width);
     341    filter->linesize = *width;
    361342
    362343    if (filter->line == NULL)
    363344    {
  • filters/ivtc/filter_ivtc.c

     
    2222    VideoFilter vf;
    2323
    2424    struct pullup_context *context;
    25     int uoff;
    26     int voff;
    2725    int height;
    2826    int width;
    2927    int progressive_frame_seen;
     
    3129    int apply_filter;
    3230} ThisFilter;
    3331
     32static void SetupFilter(ThisFilter *vf, int width, int height, int *pitches);
     33
    3434static inline void * memcpy_pic(void * dst, const void * src, int height, int dstStride, int srcStride)
    3535{
    3636    void *retval=dst;
     
    7171    if (!filter->apply_filter)
    7272        return 1;
    7373   
     74    SetupFilter(filter, frame->width, frame->height, (int*)frame->pitches);
     75
    7476    struct pullup_buffer *b;
    7577    struct pullup_frame *f;
    76     int height  = frame->height;
    77     int width   = frame->width;
    78     int cwidth  = width / 2;
    79     int cheight = height / 2;
     78    int ypitch  = filter->context->stride[0];
     79    int height  = filter->height;
     80    int cpitch  = filter->context->stride[1];
     81    int cheight = filter->height >> 1;
    8082    int p = frame->top_field_first ^ 1;
    8183
    8284    struct pullup_context *c = filter->context;
    8385    if (c->bpp[0] == 0)
    8486        c->bpp[0] = c->bpp[1] = c->bpp[2] = frame->bpp;
    8587   
    86     if ((frame->width != filter->width) ||
    87         (frame->height != filter->height))
    88     {
    89         return 0;
    90     }
    91 
    92 
    9388    b = pullup_get_buffer(c,2);
    9489    if (!b)
    9590    {
     
    9893        return 0;   
    9994    }
    10095       
    101     memcpy_pic(b->planes[0], frame->buf, height, width, width);
    102     memcpy_pic(b->planes[1], frame->buf + filter->uoff, cheight, cwidth, cwidth);
    103     memcpy_pic(b->planes[2], frame->buf + filter->voff, cheight, cwidth, cwidth);
     96    memcpy_pic(b->planes[0], frame->buf + frame->offsets[0],
     97               height,  ypitch, ypitch);
     98    memcpy_pic(b->planes[1], frame->buf + frame->offsets[1],
     99               cheight, cpitch, cpitch);
     100    memcpy_pic(b->planes[2], frame->buf + frame->offsets[2],
     101               cheight, cpitch, cpitch);
    104102
    105103    pullup_submit_field(c, b, p);
    106104    pullup_submit_field(c, b, p^1);
     
    142140        pullup_pack_frame(c, f);
    143141    }
    144142
    145     memcpy_pic(frame->buf, f->buffer->planes[0], height, width, width);
    146     memcpy_pic(frame->buf + filter->uoff, f->buffer->planes[1], cheight, cwidth, cwidth);
    147     memcpy_pic(frame->buf + filter->voff, f->buffer->planes[2], cheight, cwidth, cwidth);
     143    memcpy_pic(frame->buf + frame->offsets[0], f->buffer->planes[0],
     144               height,  ypitch, ypitch);
     145    memcpy_pic(frame->buf + frame->offsets[1], f->buffer->planes[1],
     146               cheight, cpitch, cpitch);
     147    memcpy_pic(frame->buf + frame->offsets[2], f->buffer->planes[2],
     148               cheight, cpitch, cpitch);
    148149                           
    149150    pullup_release_frame(f);
     151
    150152    return 1;
    151153}
    152154
     
    156158    pullup_free_context((((ThisFilter *)filter)->context));   
    157159}
    158160
     161static void SetupFilter(ThisFilter *vf, int width, int height, int *pitches)
     162{
     163    if (vf->width  == width  &&
     164        vf->height == height &&
     165        vf->context->stride[0] == pitches[0] &&
     166        vf->context->stride[1] == pitches[1] &&
     167        vf->context->stride[2] == pitches[2])
     168    {
     169        return;
     170    }
     171   
     172    vf->width         = width;
     173    vf->height        = height;
     174
     175    vf->context->w[0] = width;
     176    vf->context->w[1] = width >> 1;
     177    vf->context->w[2] = width >> 1;
     178    vf->context->w[3] = 0;
     179    vf->context->h[0] = height;
     180    vf->context->h[1] = height >> 1;
     181    vf->context->h[2] = height >> 1;
     182    vf->context->h[3] = 0;
     183    vf->context->stride[0] = pitches[0];
     184    vf->context->stride[1] = pitches[1];
     185    vf->context->stride[2] = pitches[2];
     186    vf->context->stride[3] = 0;
     187}
     188
    159189VideoFilter *
    160190NewIvtcFilter (VideoFrameType inpixfmt, VideoFrameType outpixfmt,
    161191                        int *width, int *height, char *options)
     
    176206        return NULL;
    177207    }
    178208
     209    bzero (filter, sizeof (ThisFilter));
    179210    filter->progressive_frame_seen = 0;
    180211    filter->interlaced_frame_seen = 0;
    181212    filter->apply_filter = 0;
    182     filter->height = *height;
    183     filter->width  = *width;
    184     filter->uoff = *width * *height;
    185     filter->voff = *width * *height  * 5 /  4;
    186213    filter->context = pullup_alloc_context();
    187214    struct pullup_context *c = filter->context;
    188215    c->metric_plane = 0;
     
    194221    c->nplanes = 4;
    195222    pullup_preinit_context(c);
    196223    c->bpp[0] = c->bpp[1] = c->bpp[2] = 0;
    197     c->w[0] = *width;
    198     c->h[0] = *height;
    199     c->w[1] = c->w[2] = (*width >> 1);
    200     c->h[1] = c->h[2] = (*height >> 1);
    201     c->w[3] = 0;
    202     c->h[3] = 0;
    203     c->stride[0] = *width;
    204     c->stride[1] = c->stride[2] = (*width >> 1);
    205     c->stride[3] = c->w[3];
    206224    c->background[1] = c->background[2]  = 128;
    207225
     226    int pitches[3] = { *width, *width >> 1, *width >> 1 };
     227    SetupFilter(filter, *width, *height, pitches);
     228
    208229#ifdef HAVE_MMX
    209230    c->cpu      |= PULLUP_CPU_MMX;
    210231#endif