~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/ivi_dsp.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:23:28 UTC
  • mfrom: (0.4.7 sid)
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20120112222328-8jqdyodym3p84ygu
Tags: 2:1.0~rc4.dfsg1+svn34540-1
* New upstream snapshot
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * DSP functions for Indeo Video Interactive codecs (Indeo4 and Indeo5)
3
3
 *
4
 
 * Copyright (c) 2009 Maxim Poliakovski
 
4
 * Copyright (c) 2009-2011 Maxim Poliakovski
5
5
 *
6
6
 * This file is part of Libav.
7
7
 *
178
178
    }
179
179
}
180
180
 
 
181
void ff_ivi_recompose_haar(const IVIPlaneDesc *plane, uint8_t *dst,
 
182
                           const int dst_pitch, const int num_bands)
 
183
{
 
184
    int             x, y, indx, b0, b1, b2, b3, p0, p1, p2, p3;
 
185
    const IDWTELEM *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr;
 
186
    int32_t         pitch;
 
187
 
 
188
    /* all bands should have the same pitch */
 
189
    pitch = plane->bands[0].pitch;
 
190
 
 
191
    /* get pointers to the wavelet bands */
 
192
    b0_ptr = plane->bands[0].buf;
 
193
    b1_ptr = plane->bands[1].buf;
 
194
    b2_ptr = plane->bands[2].buf;
 
195
    b3_ptr = plane->bands[3].buf;
 
196
 
 
197
    for (y = 0; y < plane->height; y += 2) {
 
198
        for (x = 0, indx = 0; x < plane->width; x += 2, indx++) {
 
199
            /* load coefficients */
 
200
            b0 = b0_ptr[indx]; //should be: b0 = (num_bands > 0) ? b0_ptr[indx] : 0;
 
201
            b1 = b1_ptr[indx]; //should be: b1 = (num_bands > 1) ? b1_ptr[indx] : 0;
 
202
            b2 = b2_ptr[indx]; //should be: b2 = (num_bands > 2) ? b2_ptr[indx] : 0;
 
203
            b3 = b3_ptr[indx]; //should be: b3 = (num_bands > 3) ? b3_ptr[indx] : 0;
 
204
 
 
205
            /* haar wavelet recomposition */
 
206
            p0 = (b0 + b1 + b2 + b3 + 2) >> 2;
 
207
            p1 = (b0 + b1 - b2 - b3 + 2) >> 2;
 
208
            p2 = (b0 - b1 + b2 - b3 + 2) >> 2;
 
209
            p3 = (b0 - b1 - b2 + b3 + 2) >> 2;
 
210
 
 
211
            /* bias, convert and output four pixels */
 
212
            dst[x]                 = av_clip_uint8(p0 + 128);
 
213
            dst[x + 1]             = av_clip_uint8(p1 + 128);
 
214
            dst[dst_pitch + x]     = av_clip_uint8(p2 + 128);
 
215
            dst[dst_pitch + x + 1] = av_clip_uint8(p3 + 128);
 
216
        }// for x
 
217
 
 
218
        dst += dst_pitch << 1;
 
219
 
 
220
        b0_ptr += pitch;
 
221
        b1_ptr += pitch;
 
222
        b2_ptr += pitch;
 
223
        b3_ptr += pitch;
 
224
    }// for y
 
225
}
 
226
 
 
227
/** butterfly operation for the inverse Haar transform */
 
228
#define IVI_HAAR_BFLY(s1, s2, o1, o2, t) \
 
229
    t  = (s1 - s2) >> 1;\
 
230
    o1 = (s1 + s2) >> 1;\
 
231
    o2 = t;\
 
232
 
 
233
/** inverse 8-point Haar transform */
 
234
#define INV_HAAR8(s1, s5, s3, s7, s2, s4, s6, s8,\
 
235
                  d1, d2, d3, d4, d5, d6, d7, d8,\
 
236
                  t0, t1, t2, t3, t4, t5, t6, t7, t8) {\
 
237
    t1 = s1 << 1; t5 = s5 << 1;\
 
238
    IVI_HAAR_BFLY(t1, t5, t1, t5, t0); IVI_HAAR_BFLY(t1, s3, t1, t3, t0);\
 
239
    IVI_HAAR_BFLY(t5, s7, t5, t7, t0); IVI_HAAR_BFLY(t1, s2, t1, t2, t0);\
 
240
    IVI_HAAR_BFLY(t3, s4, t3, t4, t0); IVI_HAAR_BFLY(t5, s6, t5, t6, t0);\
 
241
    IVI_HAAR_BFLY(t7, s8, t7, t8, t0);\
 
242
    d1 = COMPENSATE(t1);\
 
243
    d2 = COMPENSATE(t2);\
 
244
    d3 = COMPENSATE(t3);\
 
245
    d4 = COMPENSATE(t4);\
 
246
    d5 = COMPENSATE(t5);\
 
247
    d6 = COMPENSATE(t6);\
 
248
    d7 = COMPENSATE(t7);\
 
249
    d8 = COMPENSATE(t8); }
 
250
 
 
251
/** inverse 4-point Haar transform */
 
252
#define INV_HAAR4(s1, s3, s5, s7) {\
 
253
    HAAR_BFLY(s1, s5);  HAAR_BFLY(s1, s3);  HAAR_BFLY(s5, s7);\
 
254
    s1 = COMPENSATE(s1);\
 
255
    s3 = COMPENSATE(s3);\
 
256
    s5 = COMPENSATE(s5);\
 
257
    s7 = COMPENSATE(s7); }
 
258
 
 
259
void ff_ivi_inverse_haar_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
 
260
                             const uint8_t *flags)
 
261
{
 
262
    int     i, shift, sp1, sp2, sp3, sp4;
 
263
    const int32_t *src;
 
264
    int32_t *dst;
 
265
    int     tmp[64];
 
266
    int     t0, t1, t2, t3, t4, t5, t6, t7, t8;
 
267
 
 
268
    /* apply the InvHaar8 to all columns */
 
269
#define COMPENSATE(x) (x)
 
270
    src = in;
 
271
    dst = tmp;
 
272
    for (i = 0; i < 8; i++) {
 
273
        if (flags[i]) {
 
274
            /* pre-scaling */
 
275
            shift = !(i & 4);
 
276
            sp1 = src[ 0] << shift;
 
277
            sp2 = src[ 8] << shift;
 
278
            sp3 = src[16] << shift;
 
279
            sp4 = src[24] << shift;
 
280
            INV_HAAR8(    sp1,     sp2,     sp3,     sp4,
 
281
                      src[32], src[40], src[48], src[56],
 
282
                      dst[ 0], dst[ 8], dst[16], dst[24],
 
283
                      dst[32], dst[40], dst[48], dst[56],
 
284
                      t0, t1, t2, t3, t4, t5, t6, t7, t8);
 
285
        } else
 
286
            dst[ 0] = dst[ 8] = dst[16] = dst[24] =
 
287
            dst[32] = dst[40] = dst[48] = dst[56] = 0;
 
288
 
 
289
        src++;
 
290
        dst++;
 
291
    }
 
292
#undef  COMPENSATE
 
293
 
 
294
    /* apply the InvHaar8 to all rows */
 
295
#define COMPENSATE(x) (x)
 
296
    src = tmp;
 
297
    for (i = 0; i < 8; i++) {
 
298
        if (   !src[0] && !src[1] && !src[2] && !src[3]
 
299
            && !src[4] && !src[5] && !src[6] && !src[7]) {
 
300
            memset(out, 0, 8 * sizeof(out[0]));
 
301
        } else {
 
302
            INV_HAAR8(src[0], src[1], src[2], src[3],
 
303
                      src[4], src[5], src[6], src[7],
 
304
                      out[0], out[1], out[2], out[3],
 
305
                      out[4], out[5], out[6], out[7],
 
306
                      t0, t1, t2, t3, t4, t5, t6, t7, t8);
 
307
        }
 
308
        src += 8;
 
309
        out += pitch;
 
310
    }
 
311
#undef  COMPENSATE
 
312
}
 
313
 
 
314
void ff_ivi_dc_haar_2d(const int32_t *in, int16_t *out, uint32_t pitch,
 
315
                       int blk_size)
 
316
{
 
317
    int     x, y;
 
318
    int16_t dc_coeff;
 
319
 
 
320
    dc_coeff = (*in + 0) >> 3;
 
321
 
 
322
    for (y = 0; y < blk_size; out += pitch, y++) {
 
323
        for (x = 0; x < blk_size; x++)
 
324
            out[x] = dc_coeff;
 
325
    }
 
326
}
 
327
 
181
328
/** butterfly operation for the inverse slant transform */
182
329
#define IVI_SLANT_BFLY(s1, s2, o1, o2, t) \
183
330
    t  = s1 - s2;\