00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 #include <stdint.h>
00023 #include "avcodec.h"
00024 #include "vp56dsp.h"
00025 
00026 
00027 static int vp5_adjust(int v, int t)
00028 {
00029     int s2, s1 = v >> 31;
00030     v ^= s1;
00031     v -= s1;
00032     v *= v < 2*t;
00033     v -= t;
00034     s2 = v >> 31;
00035     v ^= s2;
00036     v -= s2;
00037     v = t - v;
00038     v += s1;
00039     v ^= s1;
00040     return v;
00041 }
00042 
00043 static int vp6_adjust(int v, int t)
00044 {
00045     int V = v, s = v >> 31;
00046     V ^= s;
00047     V -= s;
00048     if (V-t-1 >= (unsigned)(t-1))
00049         return v;
00050     V = 2*t - V;
00051     V += s;
00052     V ^= s;
00053     return V;
00054 }
00055 
00056 
00057 #define VP56_EDGE_FILTER(pfx, suf, pix_inc, line_inc)                   \
00058 static void pfx##_edge_filter_##suf(uint8_t *yuv, int stride, int t)    \
00059 {                                                                       \
00060     int pix2_inc = 2 * pix_inc;                                         \
00061     int i, v;                                                           \
00062                                                                         \
00063     for (i=0; i<12; i++) {                                              \
00064         v = (yuv[-pix2_inc] + 3*(yuv[0]-yuv[-pix_inc]) - yuv[pix_inc] + 4)>>3;\
00065         v = pfx##_adjust(v, t);                                         \
00066         yuv[-pix_inc] = av_clip_uint8(yuv[-pix_inc] + v);               \
00067         yuv[0] = av_clip_uint8(yuv[0] - v);                             \
00068         yuv += line_inc;                                                \
00069     }                                                                   \
00070 }
00071 
00072 VP56_EDGE_FILTER(vp5, hor, 1, stride)
00073 VP56_EDGE_FILTER(vp5, ver, stride, 1)
00074 VP56_EDGE_FILTER(vp6, hor, 1, stride)
00075 VP56_EDGE_FILTER(vp6, ver, stride, 1)
00076 
00077 void ff_vp56dsp_init(VP56DSPContext *s, enum CodecID codec)
00078 {
00079     if (codec == CODEC_ID_VP5) {
00080         s->edge_filter_hor = vp5_edge_filter_hor;
00081         s->edge_filter_ver = vp5_edge_filter_ver;
00082     } else {
00083         s->edge_filter_hor = vp6_edge_filter_hor;
00084         s->edge_filter_ver = vp6_edge_filter_ver;
00085 
00086         if (CONFIG_VP6_DECODER) {
00087             s->vp6_filter_diag4 = ff_vp6_filter_diag4_c;
00088         }
00089     }
00090 
00091     if (ARCH_ARM) ff_vp56dsp_init_arm(s, codec);
00092     if (HAVE_MMX) ff_vp56dsp_init_x86(s, codec);
00093 }