Home | History | Annotate | Download | only in encoder
      1 /*
      2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 
     12 #include <stdlib.h>
     13 
     14 unsigned int vp8_sad16x16_c(
     15     const unsigned char *src_ptr,
     16     int  src_stride,
     17     const unsigned char *ref_ptr,
     18     int  ref_stride,
     19     int max_sad)
     20 {
     21 
     22     int r, c;
     23     unsigned int sad = 0;
     24 
     25     for (r = 0; r < 16; r++)
     26     {
     27         for (c = 0; c < 16; c++)
     28         {
     29             sad += abs(src_ptr[c] - ref_ptr[c]);
     30         }
     31 
     32         src_ptr += src_stride;
     33         ref_ptr += ref_stride;
     34     }
     35 
     36     return sad;
     37 }
     38 
     39 
     40 static __inline
     41 unsigned int sad_mx_n_c(
     42     const unsigned char *src_ptr,
     43     int  src_stride,
     44     const unsigned char *ref_ptr,
     45     int  ref_stride,
     46     int m,
     47     int n)
     48 {
     49 
     50     int r, c;
     51     unsigned int sad = 0;
     52 
     53     for (r = 0; r < n; r++)
     54     {
     55         for (c = 0; c < m; c++)
     56         {
     57             sad += abs(src_ptr[c] - ref_ptr[c]);
     58         }
     59 
     60         src_ptr += src_stride;
     61         ref_ptr += ref_stride;
     62     }
     63 
     64     return sad;
     65 }
     66 
     67 
     68 unsigned int vp8_sad8x8_c(
     69     const unsigned char *src_ptr,
     70     int  src_stride,
     71     const unsigned char *ref_ptr,
     72     int  ref_stride,
     73     int max_sad)
     74 {
     75 
     76     return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, 8, 8);
     77 }
     78 
     79 
     80 unsigned int vp8_sad16x8_c(
     81     const unsigned char *src_ptr,
     82     int  src_stride,
     83     const unsigned char *ref_ptr,
     84     int  ref_stride,
     85     int max_sad)
     86 {
     87 
     88     return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, 16, 8);
     89 
     90 }
     91 
     92 
     93 unsigned int vp8_sad8x16_c(
     94     const unsigned char *src_ptr,
     95     int  src_stride,
     96     const unsigned char *ref_ptr,
     97     int  ref_stride,
     98     int max_sad)
     99 {
    100 
    101     return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, 8, 16);
    102 }
    103 
    104 
    105 unsigned int vp8_sad4x4_c(
    106     const unsigned char *src_ptr,
    107     int  src_stride,
    108     const unsigned char *ref_ptr,
    109     int  ref_stride,
    110     int max_sad)
    111 {
    112 
    113     return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, 4, 4);
    114 }
    115 
    116 void vp8_sad16x16x3_c(
    117     const unsigned char *src_ptr,
    118     int  src_stride,
    119     const unsigned char *ref_ptr,
    120     int  ref_stride,
    121     unsigned int *sad_array
    122 )
    123 {
    124     sad_array[0] = vp8_sad16x16_c(src_ptr, src_stride, ref_ptr  , ref_stride, 0x7fffffff);
    125     sad_array[1] = vp8_sad16x16_c(src_ptr, src_stride, ref_ptr + 1, ref_stride, 0x7fffffff);
    126     sad_array[2] = vp8_sad16x16_c(src_ptr, src_stride, ref_ptr + 2, ref_stride, 0x7fffffff);
    127 }
    128 
    129 void vp8_sad16x16x8_c(
    130     const unsigned char *src_ptr,
    131     int  src_stride,
    132     const unsigned char *ref_ptr,
    133     int  ref_stride,
    134     unsigned short *sad_array
    135 )
    136 {
    137     sad_array[0] = (unsigned short)vp8_sad16x16_c(src_ptr, src_stride, ref_ptr  , ref_stride, 0x7fffffff);
    138     sad_array[1] = (unsigned short)vp8_sad16x16_c(src_ptr, src_stride, ref_ptr + 1, ref_stride, 0x7fffffff);
    139     sad_array[2] = (unsigned short)vp8_sad16x16_c(src_ptr, src_stride, ref_ptr + 2, ref_stride, 0x7fffffff);
    140     sad_array[3] = (unsigned short)vp8_sad16x16_c(src_ptr, src_stride, ref_ptr + 3 , ref_stride, 0x7fffffff);
    141     sad_array[4] = (unsigned short)vp8_sad16x16_c(src_ptr, src_stride, ref_ptr + 4, ref_stride, 0x7fffffff);
    142     sad_array[5] = (unsigned short)vp8_sad16x16_c(src_ptr, src_stride, ref_ptr + 5, ref_stride, 0x7fffffff);
    143     sad_array[6] = (unsigned short)vp8_sad16x16_c(src_ptr, src_stride, ref_ptr + 6 , ref_stride, 0x7fffffff);
    144     sad_array[7] = (unsigned short)vp8_sad16x16_c(src_ptr, src_stride, ref_ptr + 7, ref_stride, 0x7fffffff);
    145 }
    146 
    147 void vp8_sad16x8x3_c(
    148     const unsigned char *src_ptr,
    149     int  src_stride,
    150     const unsigned char *ref_ptr,
    151     int  ref_stride,
    152     unsigned int *sad_array
    153 )
    154 {
    155     sad_array[0] = vp8_sad16x8_c(src_ptr, src_stride, ref_ptr  , ref_stride, 0x7fffffff);
    156     sad_array[1] = vp8_sad16x8_c(src_ptr, src_stride, ref_ptr + 1, ref_stride, 0x7fffffff);
    157     sad_array[2] = vp8_sad16x8_c(src_ptr, src_stride, ref_ptr + 2, ref_stride, 0x7fffffff);
    158 }
    159 
    160 void vp8_sad16x8x8_c(
    161     const unsigned char *src_ptr,
    162     int  src_stride,
    163     const unsigned char *ref_ptr,
    164     int  ref_stride,
    165     unsigned short *sad_array
    166 )
    167 {
    168     sad_array[0] = (unsigned short)vp8_sad16x8_c(src_ptr, src_stride, ref_ptr  , ref_stride, 0x7fffffff);
    169     sad_array[1] = (unsigned short)vp8_sad16x8_c(src_ptr, src_stride, ref_ptr + 1, ref_stride, 0x7fffffff);
    170     sad_array[2] = (unsigned short)vp8_sad16x8_c(src_ptr, src_stride, ref_ptr + 2, ref_stride, 0x7fffffff);
    171     sad_array[3] = (unsigned short)vp8_sad16x8_c(src_ptr, src_stride, ref_ptr + 3 , ref_stride, 0x7fffffff);
    172     sad_array[4] = (unsigned short)vp8_sad16x8_c(src_ptr, src_stride, ref_ptr + 4, ref_stride, 0x7fffffff);
    173     sad_array[5] = (unsigned short)vp8_sad16x8_c(src_ptr, src_stride, ref_ptr + 5, ref_stride, 0x7fffffff);
    174     sad_array[6] = (unsigned short)vp8_sad16x8_c(src_ptr, src_stride, ref_ptr + 6 , ref_stride, 0x7fffffff);
    175     sad_array[7] = (unsigned short)vp8_sad16x8_c(src_ptr, src_stride, ref_ptr + 7, ref_stride, 0x7fffffff);
    176 }
    177 
    178 void vp8_sad8x8x3_c(
    179     const unsigned char *src_ptr,
    180     int  src_stride,
    181     const unsigned char *ref_ptr,
    182     int  ref_stride,
    183     unsigned int *sad_array
    184 )
    185 {
    186     sad_array[0] = vp8_sad8x8_c(src_ptr, src_stride, ref_ptr  , ref_stride, 0x7fffffff);
    187     sad_array[1] = vp8_sad8x8_c(src_ptr, src_stride, ref_ptr + 1, ref_stride, 0x7fffffff);
    188     sad_array[2] = vp8_sad8x8_c(src_ptr, src_stride, ref_ptr + 2, ref_stride, 0x7fffffff);
    189 }
    190 
    191 void vp8_sad8x8x8_c(
    192     const unsigned char *src_ptr,
    193     int  src_stride,
    194     const unsigned char *ref_ptr,
    195     int  ref_stride,
    196     unsigned short *sad_array
    197 )
    198 {
    199     sad_array[0] = (unsigned short)vp8_sad8x8_c(src_ptr, src_stride, ref_ptr  , ref_stride, 0x7fffffff);
    200     sad_array[1] = (unsigned short)vp8_sad8x8_c(src_ptr, src_stride, ref_ptr + 1, ref_stride, 0x7fffffff);
    201     sad_array[2] = (unsigned short)vp8_sad8x8_c(src_ptr, src_stride, ref_ptr + 2, ref_stride, 0x7fffffff);
    202     sad_array[3] = (unsigned short)vp8_sad8x8_c(src_ptr, src_stride, ref_ptr + 3 , ref_stride, 0x7fffffff);
    203     sad_array[4] = (unsigned short)vp8_sad8x8_c(src_ptr, src_stride, ref_ptr + 4, ref_stride, 0x7fffffff);
    204     sad_array[5] = (unsigned short)vp8_sad8x8_c(src_ptr, src_stride, ref_ptr + 5, ref_stride, 0x7fffffff);
    205     sad_array[6] = (unsigned short)vp8_sad8x8_c(src_ptr, src_stride, ref_ptr + 6 , ref_stride, 0x7fffffff);
    206     sad_array[7] = (unsigned short)vp8_sad8x8_c(src_ptr, src_stride, ref_ptr + 7, ref_stride, 0x7fffffff);
    207 }
    208 
    209 void vp8_sad8x16x3_c(
    210     const unsigned char *src_ptr,
    211     int  src_stride,
    212     const unsigned char *ref_ptr,
    213     int  ref_stride,
    214     unsigned int *sad_array
    215 )
    216 {
    217     sad_array[0] = vp8_sad8x16_c(src_ptr, src_stride, ref_ptr  , ref_stride, 0x7fffffff);
    218     sad_array[1] = vp8_sad8x16_c(src_ptr, src_stride, ref_ptr + 1, ref_stride, 0x7fffffff);
    219     sad_array[2] = vp8_sad8x16_c(src_ptr, src_stride, ref_ptr + 2, ref_stride, 0x7fffffff);
    220 }
    221 
    222 void vp8_sad8x16x8_c(
    223     const unsigned char *src_ptr,
    224     int  src_stride,
    225     const unsigned char *ref_ptr,
    226     int  ref_stride,
    227     unsigned short *sad_array
    228 )
    229 {
    230     sad_array[0] = (unsigned short)vp8_sad8x16_c(src_ptr, src_stride, ref_ptr  , ref_stride, 0x7fffffff);
    231     sad_array[1] = (unsigned short)vp8_sad8x16_c(src_ptr, src_stride, ref_ptr + 1, ref_stride, 0x7fffffff);
    232     sad_array[2] = (unsigned short)vp8_sad8x16_c(src_ptr, src_stride, ref_ptr + 2, ref_stride, 0x7fffffff);
    233     sad_array[3] = (unsigned short)vp8_sad8x16_c(src_ptr, src_stride, ref_ptr + 3 , ref_stride, 0x7fffffff);
    234     sad_array[4] = (unsigned short)vp8_sad8x16_c(src_ptr, src_stride, ref_ptr + 4, ref_stride, 0x7fffffff);
    235     sad_array[5] = (unsigned short)vp8_sad8x16_c(src_ptr, src_stride, ref_ptr + 5, ref_stride, 0x7fffffff);
    236     sad_array[6] = (unsigned short)vp8_sad8x16_c(src_ptr, src_stride, ref_ptr + 6 , ref_stride, 0x7fffffff);
    237     sad_array[7] = (unsigned short)vp8_sad8x16_c(src_ptr, src_stride, ref_ptr + 7, ref_stride, 0x7fffffff);
    238 }
    239 
    240 void vp8_sad4x4x3_c(
    241     const unsigned char *src_ptr,
    242     int  src_stride,
    243     const unsigned char *ref_ptr,
    244     int  ref_stride,
    245     unsigned int *sad_array
    246 )
    247 {
    248     sad_array[0] = vp8_sad4x4_c(src_ptr, src_stride, ref_ptr  , ref_stride, 0x7fffffff);
    249     sad_array[1] = vp8_sad4x4_c(src_ptr, src_stride, ref_ptr + 1, ref_stride, 0x7fffffff);
    250     sad_array[2] = vp8_sad4x4_c(src_ptr, src_stride, ref_ptr + 2, ref_stride, 0x7fffffff);
    251 }
    252 
    253 void vp8_sad4x4x8_c(
    254     const unsigned char *src_ptr,
    255     int  src_stride,
    256     const unsigned char *ref_ptr,
    257     int  ref_stride,
    258     unsigned short *sad_array
    259 )
    260 {
    261     sad_array[0] = (unsigned short)vp8_sad4x4_c(src_ptr, src_stride, ref_ptr  , ref_stride, 0x7fffffff);
    262     sad_array[1] = (unsigned short)vp8_sad4x4_c(src_ptr, src_stride, ref_ptr + 1, ref_stride, 0x7fffffff);
    263     sad_array[2] = (unsigned short)vp8_sad4x4_c(src_ptr, src_stride, ref_ptr + 2, ref_stride, 0x7fffffff);
    264     sad_array[3] = (unsigned short)vp8_sad4x4_c(src_ptr, src_stride, ref_ptr + 3 , ref_stride, 0x7fffffff);
    265     sad_array[4] = (unsigned short)vp8_sad4x4_c(src_ptr, src_stride, ref_ptr + 4, ref_stride, 0x7fffffff);
    266     sad_array[5] = (unsigned short)vp8_sad4x4_c(src_ptr, src_stride, ref_ptr + 5, ref_stride, 0x7fffffff);
    267     sad_array[6] = (unsigned short)vp8_sad4x4_c(src_ptr, src_stride, ref_ptr + 6 , ref_stride, 0x7fffffff);
    268     sad_array[7] = (unsigned short)vp8_sad4x4_c(src_ptr, src_stride, ref_ptr + 7, ref_stride, 0x7fffffff);
    269 }
    270 
    271 void vp8_sad16x16x4d_c(
    272     const unsigned char *src_ptr,
    273     int  src_stride,
    274     unsigned char *ref_ptr[],
    275     int  ref_stride,
    276     unsigned int *sad_array
    277 )
    278 {
    279     sad_array[0] = vp8_sad16x16_c(src_ptr, src_stride, ref_ptr[0], ref_stride, 0x7fffffff);
    280     sad_array[1] = vp8_sad16x16_c(src_ptr, src_stride, ref_ptr[1], ref_stride, 0x7fffffff);
    281     sad_array[2] = vp8_sad16x16_c(src_ptr, src_stride, ref_ptr[2], ref_stride, 0x7fffffff);
    282     sad_array[3] = vp8_sad16x16_c(src_ptr, src_stride, ref_ptr[3], ref_stride, 0x7fffffff);
    283 }
    284 
    285 void vp8_sad16x8x4d_c(
    286     const unsigned char *src_ptr,
    287     int  src_stride,
    288     unsigned char *ref_ptr[],
    289     int  ref_stride,
    290     unsigned int *sad_array
    291 )
    292 {
    293     sad_array[0] = vp8_sad16x8_c(src_ptr, src_stride, ref_ptr[0], ref_stride, 0x7fffffff);
    294     sad_array[1] = vp8_sad16x8_c(src_ptr, src_stride, ref_ptr[1], ref_stride, 0x7fffffff);
    295     sad_array[2] = vp8_sad16x8_c(src_ptr, src_stride, ref_ptr[2], ref_stride, 0x7fffffff);
    296     sad_array[3] = vp8_sad16x8_c(src_ptr, src_stride, ref_ptr[3], ref_stride, 0x7fffffff);
    297 }
    298 
    299 void vp8_sad8x8x4d_c(
    300     const unsigned char *src_ptr,
    301     int  src_stride,
    302     unsigned char *ref_ptr[],
    303     int  ref_stride,
    304     unsigned int *sad_array
    305 )
    306 {
    307     sad_array[0] = vp8_sad8x8_c(src_ptr, src_stride, ref_ptr[0], ref_stride, 0x7fffffff);
    308     sad_array[1] = vp8_sad8x8_c(src_ptr, src_stride, ref_ptr[1], ref_stride, 0x7fffffff);
    309     sad_array[2] = vp8_sad8x8_c(src_ptr, src_stride, ref_ptr[2], ref_stride, 0x7fffffff);
    310     sad_array[3] = vp8_sad8x8_c(src_ptr, src_stride, ref_ptr[3], ref_stride, 0x7fffffff);
    311 }
    312 
    313 void vp8_sad8x16x4d_c(
    314     const unsigned char *src_ptr,
    315     int  src_stride,
    316     unsigned char *ref_ptr[],
    317     int  ref_stride,
    318     unsigned int *sad_array
    319 )
    320 {
    321     sad_array[0] = vp8_sad8x16_c(src_ptr, src_stride, ref_ptr[0], ref_stride, 0x7fffffff);
    322     sad_array[1] = vp8_sad8x16_c(src_ptr, src_stride, ref_ptr[1], ref_stride, 0x7fffffff);
    323     sad_array[2] = vp8_sad8x16_c(src_ptr, src_stride, ref_ptr[2], ref_stride, 0x7fffffff);
    324     sad_array[3] = vp8_sad8x16_c(src_ptr, src_stride, ref_ptr[3], ref_stride, 0x7fffffff);
    325 }
    326 
    327 void vp8_sad4x4x4d_c(
    328     const unsigned char *src_ptr,
    329     int  src_stride,
    330     unsigned char *ref_ptr[],
    331     int  ref_stride,
    332     unsigned int *sad_array
    333 )
    334 {
    335     sad_array[0] = vp8_sad4x4_c(src_ptr, src_stride, ref_ptr[0], ref_stride, 0x7fffffff);
    336     sad_array[1] = vp8_sad4x4_c(src_ptr, src_stride, ref_ptr[1], ref_stride, 0x7fffffff);
    337     sad_array[2] = vp8_sad4x4_c(src_ptr, src_stride, ref_ptr[2], ref_stride, 0x7fffffff);
    338     sad_array[3] = vp8_sad4x4_c(src_ptr, src_stride, ref_ptr[3], ref_stride, 0x7fffffff);
    339 }
    340