• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavcodec/ivi_dsp.c

Go to the documentation of this file.
00001 /*
00002  * DSP functions for Indeo Video Interactive codecs (Indeo4 and Indeo5)
00003  *
00004  * Copyright (c) 2009-2011 Maxim Poliakovski
00005  *
00006  * This file is part of Libav.
00007  *
00008  * Libav is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * Libav is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Libav; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00029 #include "avcodec.h"
00030 #include "dsputil.h"
00031 #include "dwt.h"
00032 #include "ivi_common.h"
00033 #include "ivi_dsp.h"
00034 
00035 void ff_ivi_recompose53(const IVIPlaneDesc *plane, uint8_t *dst,
00036                         const int dst_pitch, const int num_bands)
00037 {
00038     int             x, y, indx;
00039     int32_t         p0, p1, p2, p3, tmp0, tmp1, tmp2;
00040     int32_t         b0_1, b0_2, b1_1, b1_2, b1_3, b2_1, b2_2, b2_3, b2_4, b2_5, b2_6;
00041     int32_t         b3_1, b3_2, b3_3, b3_4, b3_5, b3_6, b3_7, b3_8, b3_9;
00042     int32_t         pitch, back_pitch;
00043     const IDWTELEM *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr;
00044 
00045     /* all bands should have the same pitch */
00046     pitch = plane->bands[0].pitch;
00047 
00048     /* pixels at the position "y-1" will be set to pixels at the "y" for the 1st iteration */
00049     back_pitch = 0;
00050 
00051     /* get pointers to the wavelet bands */
00052     b0_ptr = plane->bands[0].buf;
00053     b1_ptr = plane->bands[1].buf;
00054     b2_ptr = plane->bands[2].buf;
00055     b3_ptr = plane->bands[3].buf;
00056 
00057     for (y = 0; y < plane->height; y += 2) {
00058         /* load storage variables with values */
00059         if (num_bands > 0) {
00060             b0_1 = b0_ptr[0];
00061             b0_2 = b0_ptr[pitch];
00062         }
00063 
00064         if (num_bands > 1) {
00065             b1_1 = b1_ptr[back_pitch];
00066             b1_2 = b1_ptr[0];
00067             b1_3 = b1_1 - b1_2*6 + b1_ptr[pitch];
00068         }
00069 
00070         if (num_bands > 2) {
00071             b2_2 = b2_ptr[0];     // b2[x,  y  ]
00072             b2_3 = b2_2;          // b2[x+1,y  ] = b2[x,y]
00073             b2_5 = b2_ptr[pitch]; // b2[x  ,y+1]
00074             b2_6 = b2_5;          // b2[x+1,y+1] = b2[x,y+1]
00075         }
00076 
00077         if (num_bands > 3) {
00078             b3_2 = b3_ptr[back_pitch]; // b3[x  ,y-1]
00079             b3_3 = b3_2;               // b3[x+1,y-1] = b3[x  ,y-1]
00080             b3_5 = b3_ptr[0];          // b3[x  ,y  ]
00081             b3_6 = b3_5;               // b3[x+1,y  ] = b3[x  ,y  ]
00082             b3_8 = b3_2 - b3_5*6 + b3_ptr[pitch];
00083             b3_9 = b3_8;
00084         }
00085 
00086         for (x = 0, indx = 0; x < plane->width; x+=2, indx++) {
00087             /* some values calculated in the previous iterations can */
00088             /* be reused in the next ones, so do appropriate copying */
00089             b2_1 = b2_2; // b2[x-1,y  ] = b2[x,  y  ]
00090             b2_2 = b2_3; // b2[x  ,y  ] = b2[x+1,y  ]
00091             b2_4 = b2_5; // b2[x-1,y+1] = b2[x  ,y+1]
00092             b2_5 = b2_6; // b2[x  ,y+1] = b2[x+1,y+1]
00093             b3_1 = b3_2; // b3[x-1,y-1] = b3[x  ,y-1]
00094             b3_2 = b3_3; // b3[x  ,y-1] = b3[x+1,y-1]
00095             b3_4 = b3_5; // b3[x-1,y  ] = b3[x  ,y  ]
00096             b3_5 = b3_6; // b3[x  ,y  ] = b3[x+1,y  ]
00097             b3_7 = b3_8; // vert_HPF(x-1)
00098             b3_8 = b3_9; // vert_HPF(x  )
00099 
00100             p0 = p1 = p2 = p3 = 0;
00101 
00102             /* process the LL-band by applying LPF both vertically and horizontally */
00103             if (num_bands > 0) {
00104                 tmp0 = b0_1;
00105                 tmp2 = b0_2;
00106                 b0_1 = b0_ptr[indx+1];
00107                 b0_2 = b0_ptr[pitch+indx+1];
00108                 tmp1 = tmp0 + b0_1;
00109 
00110                 p0 =  tmp0 << 4;
00111                 p1 =  tmp1 << 3;
00112                 p2 = (tmp0 + tmp2) << 3;
00113                 p3 = (tmp1 + tmp2 + b0_2) << 2;
00114             }
00115 
00116             /* process the HL-band by applying HPF vertically and LPF horizontally */
00117             if (num_bands > 1) {
00118                 tmp0 = b1_2;
00119                 tmp1 = b1_1;
00120                 b1_2 = b1_ptr[indx+1];
00121                 b1_1 = b1_ptr[back_pitch+indx+1];
00122 
00123                 tmp2 = tmp1 - tmp0*6 + b1_3;
00124                 b1_3 = b1_1 - b1_2*6 + b1_ptr[pitch+indx+1];
00125 
00126                 p0 += (tmp0 + tmp1) << 3;
00127                 p1 += (tmp0 + tmp1 + b1_1 + b1_2) << 2;
00128                 p2 +=  tmp2 << 2;
00129                 p3 += (tmp2 + b1_3) << 1;
00130             }
00131 
00132             /* process the LH-band by applying LPF vertically and HPF horizontally */
00133             if (num_bands > 2) {
00134                 b2_3 = b2_ptr[indx+1];
00135                 b2_6 = b2_ptr[pitch+indx+1];
00136 
00137                 tmp0 = b2_1 + b2_2;
00138                 tmp1 = b2_1 - b2_2*6 + b2_3;
00139 
00140                 p0 += tmp0 << 3;
00141                 p1 += tmp1 << 2;
00142                 p2 += (tmp0 + b2_4 + b2_5) << 2;
00143                 p3 += (tmp1 + b2_4 - b2_5*6 + b2_6) << 1;
00144             }
00145 
00146             /* process the HH-band by applying HPF both vertically and horizontally */
00147             if (num_bands > 3) {
00148                 b3_6 = b3_ptr[indx+1];            // b3[x+1,y  ]
00149                 b3_3 = b3_ptr[back_pitch+indx+1]; // b3[x+1,y-1]
00150 
00151                 tmp0 = b3_1 + b3_4;
00152                 tmp1 = b3_2 + b3_5;
00153                 tmp2 = b3_3 + b3_6;
00154 
00155                 b3_9 = b3_3 - b3_6*6 + b3_ptr[pitch+indx+1];
00156 
00157                 p0 += (tmp0 + tmp1) << 2;
00158                 p1 += (tmp0 - tmp1*6 + tmp2) << 1;
00159                 p2 += (b3_7 + b3_8) << 1;
00160                 p3 +=  b3_7 - b3_8*6 + b3_9;
00161             }
00162 
00163             /* output four pixels */
00164             dst[x]             = av_clip_uint8((p0 >> 6) + 128);
00165             dst[x+1]           = av_clip_uint8((p1 >> 6) + 128);
00166             dst[dst_pitch+x]   = av_clip_uint8((p2 >> 6) + 128);
00167             dst[dst_pitch+x+1] = av_clip_uint8((p3 >> 6) + 128);
00168         }// for x
00169 
00170         dst += dst_pitch << 1;
00171 
00172         back_pitch = -pitch;
00173 
00174         b0_ptr += pitch;
00175         b1_ptr += pitch;
00176         b2_ptr += pitch;
00177         b3_ptr += pitch;
00178     }
00179 }
00180 
00181 void ff_ivi_recompose_haar(const IVIPlaneDesc *plane, uint8_t *dst,
00182                            const int dst_pitch, const int num_bands)
00183 {
00184     int             x, y, indx, b0, b1, b2, b3, p0, p1, p2, p3;
00185     const IDWTELEM *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr;
00186     int32_t         pitch;
00187 
00188     /* all bands should have the same pitch */
00189     pitch = plane->bands[0].pitch;
00190 
00191     /* get pointers to the wavelet bands */
00192     b0_ptr = plane->bands[0].buf;
00193     b1_ptr = plane->bands[1].buf;
00194     b2_ptr = plane->bands[2].buf;
00195     b3_ptr = plane->bands[3].buf;
00196 
00197     for (y = 0; y < plane->height; y += 2) {
00198         for (x = 0, indx = 0; x < plane->width; x += 2, indx++) {
00199             /* load coefficients */
00200             b0 = b0_ptr[indx]; //should be: b0 = (num_bands > 0) ? b0_ptr[indx] : 0;
00201             b1 = b1_ptr[indx]; //should be: b1 = (num_bands > 1) ? b1_ptr[indx] : 0;
00202             b2 = b2_ptr[indx]; //should be: b2 = (num_bands > 2) ? b2_ptr[indx] : 0;
00203             b3 = b3_ptr[indx]; //should be: b3 = (num_bands > 3) ? b3_ptr[indx] : 0;
00204 
00205             /* haar wavelet recomposition */
00206             p0 = (b0 + b1 + b2 + b3 + 2) >> 2;
00207             p1 = (b0 + b1 - b2 - b3 + 2) >> 2;
00208             p2 = (b0 - b1 + b2 - b3 + 2) >> 2;
00209             p3 = (b0 - b1 - b2 + b3 + 2) >> 2;
00210 
00211             /* bias, convert and output four pixels */
00212             dst[x]                 = av_clip_uint8(p0 + 128);
00213             dst[x + 1]             = av_clip_uint8(p1 + 128);
00214             dst[dst_pitch + x]     = av_clip_uint8(p2 + 128);
00215             dst[dst_pitch + x + 1] = av_clip_uint8(p3 + 128);
00216         }// for x
00217 
00218         dst += dst_pitch << 1;
00219 
00220         b0_ptr += pitch;
00221         b1_ptr += pitch;
00222         b2_ptr += pitch;
00223         b3_ptr += pitch;
00224     }// for y
00225 }
00226 
00228 #define IVI_HAAR_BFLY(s1, s2, o1, o2, t) \
00229     t  = (s1 - s2) >> 1;\
00230     o1 = (s1 + s2) >> 1;\
00231     o2 = t;\
00232 
00233 
00234 #define INV_HAAR8(s1, s5, s3, s7, s2, s4, s6, s8,\
00235                   d1, d2, d3, d4, d5, d6, d7, d8,\
00236                   t0, t1, t2, t3, t4, t5, t6, t7, t8) {\
00237     t1 = s1 << 1; t5 = s5 << 1;\
00238     IVI_HAAR_BFLY(t1, t5, t1, t5, t0); IVI_HAAR_BFLY(t1, s3, t1, t3, t0);\
00239     IVI_HAAR_BFLY(t5, s7, t5, t7, t0); IVI_HAAR_BFLY(t1, s2, t1, t2, t0);\
00240     IVI_HAAR_BFLY(t3, s4, t3, t4, t0); IVI_HAAR_BFLY(t5, s6, t5, t6, t0);\
00241     IVI_HAAR_BFLY(t7, s8, t7, t8, t0);\
00242     d1 = COMPENSATE(t1);\
00243     d2 = COMPENSATE(t2);\
00244     d3 = COMPENSATE(t3);\
00245     d4 = COMPENSATE(t4);\
00246     d5 = COMPENSATE(t5);\
00247     d6 = COMPENSATE(t6);\
00248     d7 = COMPENSATE(t7);\
00249     d8 = COMPENSATE(t8); }
00250 
00252 #define INV_HAAR4(s1, s3, s5, s7) {\
00253     HAAR_BFLY(s1, s5);  HAAR_BFLY(s1, s3);  HAAR_BFLY(s5, s7);\
00254     s1 = COMPENSATE(s1);\
00255     s3 = COMPENSATE(s3);\
00256     s5 = COMPENSATE(s5);\
00257     s7 = COMPENSATE(s7); }
00258 
00259 void ff_ivi_inverse_haar_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
00260                              const uint8_t *flags)
00261 {
00262     int     i, shift, sp1, sp2, sp3, sp4;
00263     const int32_t *src;
00264     int32_t *dst;
00265     int     tmp[64];
00266     int     t0, t1, t2, t3, t4, t5, t6, t7, t8;
00267 
00268     /* apply the InvHaar8 to all columns */
00269 #define COMPENSATE(x) (x)
00270     src = in;
00271     dst = tmp;
00272     for (i = 0; i < 8; i++) {
00273         if (flags[i]) {
00274             /* pre-scaling */
00275             shift = !(i & 4);
00276             sp1 = src[ 0] << shift;
00277             sp2 = src[ 8] << shift;
00278             sp3 = src[16] << shift;
00279             sp4 = src[24] << shift;
00280             INV_HAAR8(    sp1,     sp2,     sp3,     sp4,
00281                       src[32], src[40], src[48], src[56],
00282                       dst[ 0], dst[ 8], dst[16], dst[24],
00283                       dst[32], dst[40], dst[48], dst[56],
00284                       t0, t1, t2, t3, t4, t5, t6, t7, t8);
00285         } else
00286             dst[ 0] = dst[ 8] = dst[16] = dst[24] =
00287             dst[32] = dst[40] = dst[48] = dst[56] = 0;
00288 
00289         src++;
00290         dst++;
00291     }
00292 #undef  COMPENSATE
00293 
00294     /* apply the InvHaar8 to all rows */
00295 #define COMPENSATE(x) (x)
00296     src = tmp;
00297     for (i = 0; i < 8; i++) {
00298         if (   !src[0] && !src[1] && !src[2] && !src[3]
00299             && !src[4] && !src[5] && !src[6] && !src[7]) {
00300             memset(out, 0, 8 * sizeof(out[0]));
00301         } else {
00302             INV_HAAR8(src[0], src[1], src[2], src[3],
00303                       src[4], src[5], src[6], src[7],
00304                       out[0], out[1], out[2], out[3],
00305                       out[4], out[5], out[6], out[7],
00306                       t0, t1, t2, t3, t4, t5, t6, t7, t8);
00307         }
00308         src += 8;
00309         out += pitch;
00310     }
00311 #undef  COMPENSATE
00312 }
00313 
00314 void ff_ivi_dc_haar_2d(const int32_t *in, int16_t *out, uint32_t pitch,
00315                        int blk_size)
00316 {
00317     int     x, y;
00318     int16_t dc_coeff;
00319 
00320     dc_coeff = (*in + 0) >> 3;
00321 
00322     for (y = 0; y < blk_size; out += pitch, y++) {
00323         for (x = 0; x < blk_size; x++)
00324             out[x] = dc_coeff;
00325     }
00326 }
00327 
00329 #define IVI_SLANT_BFLY(s1, s2, o1, o2, t) \
00330     t  = s1 - s2;\
00331     o1 = s1 + s2;\
00332     o2 = t;\
00333 
00334 
00335 #define IVI_IREFLECT(s1, s2, o1, o2, t) \
00336     t  = ((s1 + s2*2 + 2) >> 2) + s1;\
00337     o2 = ((s1*2 - s2 + 2) >> 2) - s2;\
00338     o1 = t;\
00339 
00340 
00341 #define IVI_SLANT_PART4(s1, s2, o1, o2, t) \
00342     t  = s2 + ((s1*4  - s2 + 4) >> 3);\
00343     o2 = s1 + ((-s1 - s2*4 + 4) >> 3);\
00344     o1 = t;\
00345 
00346 
00347 #define IVI_INV_SLANT8(s1, s4, s8, s5, s2, s6, s3, s7,\
00348                        d1, d2, d3, d4, d5, d6, d7, d8,\
00349                        t0, t1, t2, t3, t4, t5, t6, t7, t8) {\
00350     IVI_SLANT_PART4(s4, s5, t4, t5, t0);\
00351 \
00352     IVI_SLANT_BFLY(s1, t5, t1, t5, t0); IVI_SLANT_BFLY(s2, s6, t2, t6, t0);\
00353     IVI_SLANT_BFLY(s7, s3, t7, t3, t0); IVI_SLANT_BFLY(t4, s8, t4, t8, t0);\
00354 \
00355     IVI_SLANT_BFLY(t1, t2, t1, t2, t0); IVI_IREFLECT  (t4, t3, t4, t3, t0);\
00356     IVI_SLANT_BFLY(t5, t6, t5, t6, t0); IVI_IREFLECT  (t8, t7, t8, t7, t0);\
00357     IVI_SLANT_BFLY(t1, t4, t1, t4, t0); IVI_SLANT_BFLY(t2, t3, t2, t3, t0);\
00358     IVI_SLANT_BFLY(t5, t8, t5, t8, t0); IVI_SLANT_BFLY(t6, t7, t6, t7, t0);\
00359     d1 = COMPENSATE(t1);\
00360     d2 = COMPENSATE(t2);\
00361     d3 = COMPENSATE(t3);\
00362     d4 = COMPENSATE(t4);\
00363     d5 = COMPENSATE(t5);\
00364     d6 = COMPENSATE(t6);\
00365     d7 = COMPENSATE(t7);\
00366     d8 = COMPENSATE(t8);}
00367 
00369 #define IVI_INV_SLANT4(s1, s4, s2, s3, d1, d2, d3, d4, t0, t1, t2, t3, t4) {\
00370     IVI_SLANT_BFLY(s1, s2, t1, t2, t0); IVI_IREFLECT  (s4, s3, t4, t3, t0);\
00371 \
00372     IVI_SLANT_BFLY(t1, t4, t1, t4, t0); IVI_SLANT_BFLY(t2, t3, t2, t3, t0);\
00373     d1 = COMPENSATE(t1);\
00374     d2 = COMPENSATE(t2);\
00375     d3 = COMPENSATE(t3);\
00376     d4 = COMPENSATE(t4);}
00377 
00378 void ff_ivi_inverse_slant_8x8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
00379 {
00380     int     i;
00381     const int32_t *src;
00382     int32_t *dst;
00383     int     tmp[64];
00384     int     t0, t1, t2, t3, t4, t5, t6, t7, t8;
00385 
00386 #define COMPENSATE(x) (x)
00387     src = in;
00388     dst = tmp;
00389     for (i = 0; i < 8; i++) {
00390         if (flags[i]) {
00391             IVI_INV_SLANT8(src[0], src[8], src[16], src[24], src[32], src[40], src[48], src[56],
00392                            dst[0], dst[8], dst[16], dst[24], dst[32], dst[40], dst[48], dst[56],
00393                            t0, t1, t2, t3, t4, t5, t6, t7, t8);
00394         } else
00395             dst[0] = dst[8] = dst[16] = dst[24] = dst[32] = dst[40] = dst[48] = dst[56] = 0;
00396 
00397             src++;
00398             dst++;
00399     }
00400 #undef COMPENSATE
00401 
00402 #define COMPENSATE(x) ((x + 1)>>1)
00403     src = tmp;
00404     for (i = 0; i < 8; i++) {
00405         if (!src[0] && !src[1] && !src[2] && !src[3] && !src[4] && !src[5] && !src[6] && !src[7]) {
00406             memset(out, 0, 8*sizeof(out[0]));
00407         } else {
00408             IVI_INV_SLANT8(src[0], src[1], src[2], src[3], src[4], src[5], src[6], src[7],
00409                            out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
00410                            t0, t1, t2, t3, t4, t5, t6, t7, t8);
00411         }
00412         src += 8;
00413         out += pitch;
00414     }
00415 #undef COMPENSATE
00416 }
00417 
00418 void ff_ivi_inverse_slant_4x4(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
00419 {
00420     int     i;
00421     const int32_t *src;
00422     int32_t *dst;
00423     int     tmp[16];
00424     int     t0, t1, t2, t3, t4;
00425 
00426 #define COMPENSATE(x) (x)
00427     src = in;
00428     dst = tmp;
00429     for (i = 0; i < 4; i++) {
00430         if (flags[i]) {
00431             IVI_INV_SLANT4(src[0], src[4], src[8], src[12],
00432                            dst[0], dst[4], dst[8], dst[12],
00433                            t0, t1, t2, t3, t4);
00434         } else
00435             dst[0] = dst[4] = dst[8] = dst[12] = 0;
00436 
00437             src++;
00438             dst++;
00439     }
00440 #undef COMPENSATE
00441 
00442 #define COMPENSATE(x) ((x + 1)>>1)
00443     src = tmp;
00444     for (i = 0; i < 4; i++) {
00445         if (!src[0] && !src[1] && !src[2] && !src[3]) {
00446             out[0] = out[1] = out[2] = out[3] = 0;
00447         } else {
00448             IVI_INV_SLANT4(src[0], src[1], src[2], src[3],
00449                            out[0], out[1], out[2], out[3],
00450                            t0, t1, t2, t3, t4);
00451         }
00452         src += 4;
00453         out += pitch;
00454     }
00455 #undef COMPENSATE
00456 }
00457 
00458 void ff_ivi_dc_slant_2d(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
00459 {
00460     int     x, y;
00461     int16_t dc_coeff;
00462 
00463     dc_coeff = (*in + 1) >> 1;
00464 
00465     for (y = 0; y < blk_size; out += pitch, y++) {
00466         for (x = 0; x < blk_size; x++)
00467             out[x] = dc_coeff;
00468     }
00469 }
00470 
00471 void ff_ivi_row_slant8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
00472 {
00473     int     i;
00474     int     t0, t1, t2, t3, t4, t5, t6, t7, t8;
00475 
00476 #define COMPENSATE(x) ((x + 1)>>1)
00477     for (i = 0; i < 8; i++) {
00478         if (!in[0] && !in[1] && !in[2] && !in[3] && !in[4] && !in[5] && !in[6] && !in[7]) {
00479             memset(out, 0, 8*sizeof(out[0]));
00480         } else {
00481             IVI_INV_SLANT8( in[0],  in[1],  in[2],  in[3],  in[4],  in[5],  in[6],  in[7],
00482                            out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
00483                            t0, t1, t2, t3, t4, t5, t6, t7, t8);
00484         }
00485         in += 8;
00486         out += pitch;
00487     }
00488 #undef COMPENSATE
00489 }
00490 
00491 void ff_ivi_dc_row_slant(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
00492 {
00493     int     x, y;
00494     int16_t dc_coeff;
00495 
00496     dc_coeff = (*in + 1) >> 1;
00497 
00498     for (x = 0; x < blk_size; x++)
00499         out[x] = dc_coeff;
00500 
00501     out += pitch;
00502 
00503     for (y = 1; y < blk_size; out += pitch, y++) {
00504         for (x = 0; x < blk_size; x++)
00505             out[x] = 0;
00506     }
00507 }
00508 
00509 void ff_ivi_col_slant8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
00510 {
00511     int     i, row2, row4, row8;
00512     int     t0, t1, t2, t3, t4, t5, t6, t7, t8;
00513 
00514     row2 = pitch << 1;
00515     row4 = pitch << 2;
00516     row8 = pitch << 3;
00517 
00518 #define COMPENSATE(x) ((x + 1)>>1)
00519     for (i = 0; i < 8; i++) {
00520         if (flags[i]) {
00521             IVI_INV_SLANT8(in[0], in[8], in[16], in[24], in[32], in[40], in[48], in[56],
00522                            out[0], out[pitch], out[row2], out[row2 + pitch], out[row4],
00523                            out[row4 + pitch],  out[row4 + row2], out[row8 - pitch],
00524                            t0, t1, t2, t3, t4, t5, t6, t7, t8);
00525         } else {
00526             out[0] = out[pitch] = out[row2] = out[row2 + pitch] = out[row4] =
00527             out[row4 + pitch] =  out[row4 + row2] = out[row8 - pitch] = 0;
00528         }
00529 
00530         in++;
00531         out++;
00532     }
00533 #undef COMPENSATE
00534 }
00535 
00536 void ff_ivi_dc_col_slant(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
00537 {
00538     int     x, y;
00539     int16_t dc_coeff;
00540 
00541     dc_coeff = (*in + 1) >> 1;
00542 
00543     for (y = 0; y < blk_size; out += pitch, y++) {
00544         out[0] = dc_coeff;
00545         for (x = 1; x < blk_size; x++)
00546             out[x] = 0;
00547     }
00548 }
00549 
00550 void ff_ivi_put_pixels_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
00551                            const uint8_t *flags)
00552 {
00553     int     x, y;
00554 
00555     for (y = 0; y < 8; out += pitch, in += 8, y++)
00556         for (x = 0; x < 8; x++)
00557             out[x] = in[x];
00558 }
00559 
00560 void ff_ivi_put_dc_pixel_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
00561                              int blk_size)
00562 {
00563     int     y;
00564 
00565     out[0] = in[0];
00566     memset(out + 1, 0, 7*sizeof(out[0]));
00567     out += pitch;
00568 
00569     for (y = 1; y < 8; out += pitch, y++)
00570         memset(out, 0, 8*sizeof(out[0]));
00571 }
00572 
00573 #define IVI_MC_TEMPLATE(size, suffix, OP) \
00574 void ff_ivi_mc_ ## size ##x## size ## suffix (int16_t *buf, const int16_t *ref_buf, \
00575                                               uint32_t pitch, int mc_type) \
00576 { \
00577     int     i, j; \
00578     const int16_t *wptr; \
00579 \
00580     switch (mc_type) { \
00581     case 0: /* fullpel (no interpolation) */ \
00582         for (i = 0; i < size; i++, buf += pitch, ref_buf += pitch) { \
00583             for (j = 0; j < size; j++) {\
00584                 OP(buf[j], ref_buf[j]); \
00585             } \
00586         } \
00587         break; \
00588     case 1: /* horizontal halfpel interpolation */ \
00589         for (i = 0; i < size; i++, buf += pitch, ref_buf += pitch) \
00590             for (j = 0; j < size; j++) \
00591                 OP(buf[j], (ref_buf[j] + ref_buf[j+1]) >> 1); \
00592         break; \
00593     case 2: /* vertical halfpel interpolation */ \
00594         wptr = ref_buf + pitch; \
00595         for (i = 0; i < size; i++, buf += pitch, wptr += pitch, ref_buf += pitch) \
00596             for (j = 0; j < size; j++) \
00597                 OP(buf[j], (ref_buf[j] + wptr[j]) >> 1); \
00598         break; \
00599     case 3: /* vertical and horizontal halfpel interpolation */ \
00600         wptr = ref_buf + pitch; \
00601         for (i = 0; i < size; i++, buf += pitch, wptr += pitch, ref_buf += pitch) \
00602             for (j = 0; j < size; j++) \
00603                 OP(buf[j], (ref_buf[j] + ref_buf[j+1] + wptr[j] + wptr[j+1]) >> 2); \
00604         break; \
00605     } \
00606 } \
00607 
00608 #define OP_PUT(a, b)  (a) = (b)
00609 #define OP_ADD(a, b)  (a) += (b)
00610 
00611 IVI_MC_TEMPLATE(8, _no_delta, OP_PUT)
00612 IVI_MC_TEMPLATE(8, _delta,    OP_ADD)
00613 IVI_MC_TEMPLATE(4, _no_delta, OP_PUT)
00614 IVI_MC_TEMPLATE(4, _delta,    OP_ADD)
Generated on Sat Mar 17 2012 12:57:46 for Libav by doxygen 1.7.1