[FFmpeg-soc] [soc]: r5556 - in indeo5: TODO indeo5.c ivi_common.c ivi_common.h ivi_dsp.c ivi_dsp.h
maximum
subversion at mplayerhq.hu
Sun Jan 3 02:19:11 CET 2010
Author: maximum
Date: Sun Jan 3 02:19:11 2010
New Revision: 5556
Log:
This commit adds a support for the scalability mode. The code still contains several minor bugs but I'm working hard on fixing them.
Added:
indeo5/ivi_dsp.c
indeo5/ivi_dsp.h
Modified:
indeo5/TODO
indeo5/indeo5.c
indeo5/ivi_common.c
indeo5/ivi_common.h
Modified: indeo5/TODO
==============================================================================
--- indeo5/TODO Sat Jan 2 17:24:08 2010 (r5555)
+++ indeo5/TODO Sun Jan 3 02:19:11 2010 (r5556)
@@ -7,3 +7,6 @@ decode indeo5 videos:
snow.c:spatial_compose53i) and adapt it to indeo5. The indeo5
high-pass coefficients must be upscaled by -2 in this case
before they can be passed to that filter.
+
+* Sometimes doxygen parameters descriptions were placed in the source
+ directly. Move them to the header files.
Modified: indeo5/indeo5.c
==============================================================================
--- indeo5/indeo5.c Sat Jan 2 17:24:08 2010 (r5555)
+++ indeo5/indeo5.c Sun Jan 3 02:19:11 2010 (r5556)
@@ -29,7 +29,7 @@
#define ALT_BITSTREAM_READER_LE
#include "avcodec.h"
#include "get_bits.h"
-#include "ivi_slant.h"
+#include "ivi_dsp.h"
#include "ivi_common.h"
#include "indeo5data.h"
@@ -48,6 +48,9 @@ typedef struct {
RVMapDesc rvmap_tabs[9]; ///< local changeable copy of the static rvmap tables
IVIPlaneDesc planes[3]; ///< color planes
const uint8_t *frame_data; ///< ptr to the input frame data
+ uint8_t buf_switch; ///< used to switch between three buffers
+ uint8_t dst_buf;
+ uint8_t ref_buf;
uint32_t frame_size; ///< frame size in bytes
uint32_t frame_type;
uint32_t prev_frame_type; ///< frame type of the previous frame
@@ -214,13 +217,6 @@ static int decode_gop_header(IVI5DecCont
band->is_2d_trans = band->inv_transform == ff_ivi_inverse_slant_8x8 ||
band->inv_transform == ff_ivi_inverse_slant_4x4;
- /* select transform functions according with plane and band number */
- //band->inv_transform = !p ? ff_ivi_inverse_slant_8x8 : ff_ivi_inverse_slant_4x4;
- //band->dc_transform = ff_ivi_dc_slant_2d;
-
- /* select scan pattern for this band */
- //band->scan = (!p) ? ivi5_scans8x8[0] : ivi5_scan4x4;
-
/* select dequant matrix according with plane and band number */
if (!p) {
band->quant_mat = (pic_conf.luma_bands > 1) ? i+1 : 0;
@@ -276,9 +272,11 @@ static int decode_gop_header(IVI5DecCont
skip_bits(&ctx->gb, 23); /* FIXME: unknown meaning */
+ /* skip GOP extension if any */
if (get_bits1(&ctx->gb)) {
- av_log(avctx, AV_LOG_ERROR, "GOP extension encountered!\n");
- return -1;
+ do {
+ i = get_bits(&ctx->gb, 16);
+ } while (i & 0x8000);
}
align_get_bits(&ctx->gb);
@@ -396,7 +394,6 @@ static int decode_band_hdr(IVI5DecContex
{
int i, result;
uint8_t band_flags;
- //uint32_t band_data_size;
IVIHuffDesc new_huff;
band_flags = get_bits(&ctx->gb, 8);
@@ -639,13 +636,8 @@ static int decode_band(IVI5DecContext *c
#endif
/* setup buffer pointers according with the buffer switch */
- if (ctx->planes[plane_num].buf_switch) {
- band->buf = band->buf2;
- band->ref_buf = band->buf1;
- } else {
- band->buf = band->buf1;
- band->ref_buf = band->buf2;
- }
+ band->buf = band->bufs[ctx->dst_buf];
+ band->ref_buf = band->bufs[ctx->ref_buf];
/* get the starting position of the band data */
band->data_ptr = ctx->frame_data + (get_bits_count(&ctx->gb) >> 3);
@@ -741,38 +733,52 @@ static int decode_band(IVI5DecContext *c
*/
static void switch_buffers(IVI5DecContext *ctx, AVCodecContext *avctx)
{
- int p;
- IVIPlaneDesc *plane;
-
- for (p = 0; p < 3; p++) {
- plane = &ctx->planes[p];
-
- switch (ctx->frame_type) {
- case IVI5_FRAMETYPE_INTRA:
- plane->buf_switch = 0;
- break;
- case 1:
- if (ctx->prev_frame_type != 3)
- plane->buf_switch ^= 1; /* swap buffers only if there is no frame of the type 3 */
- break;
- case 2:
- plane->buf_switch ^= 1;
- break;
- case 3:
- plane->buf_switch ^= 1;
+ switch (ctx->frame_type) {
+ case IVI5_FRAMETYPE_INTRA:
+ ctx->buf_switch = 0;
+ ctx->dst_buf = 0;
+ ctx->ref_buf = 0;
+ break;
+ case 1:
+ ctx->buf_switch &= 1;
+ /* swap buffers only if there is no frame of the type 3 */
+ if (ctx->prev_frame_type != 3 && ctx->prev_frame_type != 2)
+ ctx->buf_switch ^= 1;
+ ctx->dst_buf = ctx->buf_switch;
+ ctx->ref_buf = ctx->buf_switch ^ 1;
+ break;
+ case 2:
+ if (ctx->prev_frame_type == 3)
break;
- case IVI5_FRAMETYPE_NULL:
- return;
- default:
- av_log(avctx, AV_LOG_ERROR, "unsupported frame type: %d\n", ctx->frame_type);
+ if (ctx->prev_frame_type != 2) {
+ ctx->buf_switch ^= 1;
+ ctx->dst_buf = ctx->buf_switch;
+ ctx->ref_buf = ctx->buf_switch ^ 1;
+ } else {
+ ctx->buf_switch ^= 2;
+ ctx->dst_buf = 2;
+ ctx->ref_buf = ctx->buf_switch & 1;
+ if (!(ctx->buf_switch & 2))
+ FFSWAP(uint8_t, ctx->dst_buf, ctx->ref_buf);
}
-
- //if (plane->num_bands == 1) {
- // plane->bands[0].buf = (plane->buf_switch) ? plane->buf2
- // : plane->buf1;
- // plane->bands[0].ref_buf = (plane->buf_switch) ? plane->buf1
- // : plane->buf2;
- //}
+ break;
+ case 3:
+ if (ctx->prev_frame_type == 2) {
+ ctx->buf_switch ^= 2;
+ ctx->dst_buf = 2;
+ ctx->ref_buf = ctx->buf_switch & 1;
+ if (!(ctx->buf_switch & 2))
+ FFSWAP(uint8_t, ctx->dst_buf, ctx->ref_buf);
+ } else {
+ ctx->buf_switch ^= 1;
+ ctx->dst_buf = ctx->buf_switch & 1;
+ ctx->ref_buf = (ctx->buf_switch & 1) ^ 1;
+ }
+ break;
+ case IVI5_FRAMETYPE_NULL:
+ return;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "unsupported frame type: %d\n", ctx->frame_type);
}
}
@@ -845,16 +851,13 @@ static int decode_frame(AVCodecContext *
return -1;
}
- if (ctx->gop_flags & IVI5_IS_PROTECTED)
- return -1;
-
- switch_buffers(ctx, avctx);
-
if (ctx->gop_flags & IVI5_IS_PROTECTED) {
- av_log(avctx, AV_LOG_ERROR, "Protected clip!\n");
+ av_log(avctx, AV_LOG_ERROR, "Password-protected clip!\n");
return -1;
}
+ switch_buffers(ctx, avctx);
+
//START_TIMER;
if (ctx->frame_type == IVI5_FRAMETYPE_NULL) {
@@ -883,7 +886,12 @@ static int decode_frame(AVCodecContext *
return -1;
}
- ff_ivi_output_plane(&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0]);
+ if (ctx->is_scalable) {
+ ff_ivi_recompose53 (&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0], 4);
+ } else {
+ ff_ivi_output_plane(&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0]);
+ }
+
ff_ivi_output_plane(&ctx->planes[2], ctx->frame.data[1], ctx->frame.linesize[1]);
ff_ivi_output_plane(&ctx->planes[1], ctx->frame.data[2], ctx->frame.linesize[2]);
@@ -904,6 +912,9 @@ static av_cold int decode_close(AVCodecC
/* free allocated decoder buffers */
ff_ivi_free_buffers(&ctx->planes[0]);
+ if (ctx->frame.data[0])
+ avctx->release_buffer(avctx, &ctx->frame);
+
return 0;
}
Modified: indeo5/ivi_common.c
==============================================================================
--- indeo5/ivi_common.c Sat Jan 2 17:24:08 2010 (r5555)
+++ indeo5/ivi_common.c Sun Jan 3 02:19:11 2010 (r5556)
@@ -30,7 +30,8 @@
#include "avcodec.h"
#include "get_bits.h"
#include "ivi_common.h"
-#include "ivi_mc.h"
+#include "libavutil/common.h"
+#include "ivi_dsp.h"
/**
* Reverse "nbits" bits of the value "val" and return the result
@@ -41,9 +42,9 @@ static uint16_t inv_bits(const uint16_t
uint16_t res;
if (nbits <= 8) {
- res = ff_reverse[val & 0xFF] >> (8-nbits);
+ res = av_reverse[val & 0xFF] >> (8-nbits);
} else
- res = ((ff_reverse[val & 0xFF] << 8) + (ff_reverse[val >> 8])) >> (16-nbits);
+ res = ((av_reverse[val & 0xFF] << 8) + (av_reverse[val >> 8])) >> (16-nbits);
return res;
}
@@ -174,8 +175,7 @@ int av_cold ff_ivi_init_planes(IVIPlaneD
planes[1].num_bands = planes[2].num_bands = cfg->chroma_bands;
for (p = 0; p < 3; p++) {
- planes[p].bands = av_mallocz(planes[p].num_bands * sizeof(IVIBandDesc));
- planes[p].buf_switch = 0; /* use primary buffer */
+ planes[p].bands = av_mallocz(planes[p].num_bands * sizeof(IVIBandDesc));
/* select band dimensions: if there is only one band then it
* has the full size, if there are several bands each of them
@@ -197,8 +197,12 @@ int av_cold ff_ivi_init_planes(IVIPlaneD
band->width = b_width;
band->height = b_height;
band->pitch = width_aligned;
- band->buf1 = av_malloc(buf_size);
- band->buf2 = av_malloc(buf_size);
+ band->bufs[0] = av_malloc(buf_size);
+ band->bufs[1] = av_malloc(buf_size);
+
+ /* allocate the 3rd band buffer for scalability mode */
+ if (cfg->luma_bands > 1)
+ band->bufs[2] = av_malloc(buf_size);
planes[p].bands[0].huff_desc.num_rows = 0; /* reset custom vlc */
}
@@ -219,8 +223,9 @@ void av_cold ff_ivi_free_buffers(IVIPlan
for (p = 0; p < 3; p++) {
for (b = 0; b < planes[p].num_bands; b++) {
- av_freep(&planes[p].bands[b].buf1);
- av_freep(&planes[p].bands[b].buf2);
+ av_freep(&planes[p].bands[b].bufs[0]);
+ av_freep(&planes[p].bands[b].bufs[1]);
+ av_freep(&planes[p].bands[b].bufs[2]);
for (t = 0; t < planes[p].bands[b].num_tiles; t++)
av_freep(&planes[p].bands[b].tiles[t].mbs);
@@ -321,6 +326,7 @@ void ff_ivi_put_dc_pixel_8x8(int32_t *in
out[0] = in[0];
memset(&out[1], 0, 7*sizeof(int16_t));
+ out += pitch;
for (y = 1; y < 8; out += pitch, y++)
memset(out, 0, 8*sizeof(int16_t));
@@ -682,7 +688,7 @@ int ivi_check_band (IVIBandDesc *band, u
* @param dst [out] pointer to the buffer receiving converted pixels
* @param dst_pitch [in] pitch for moving to the next y line
*/
-void ff_ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, int dst_pitch)
+void ff_ivi_output_plane(const IVIPlaneDesc *plane, uint8_t *dst, const int dst_pitch)
{
int x, y;
const int16_t *src = plane->bands[0].buf;
Modified: indeo5/ivi_common.h
==============================================================================
--- indeo5/ivi_common.h Sat Jan 2 17:24:08 2010 (r5555)
+++ indeo5/ivi_common.h Sun Jan 3 02:19:11 2010 (r5556)
@@ -29,6 +29,8 @@
#ifndef AVCODEC_IVI_COMMON_H
#define AVCODEC_IVI_COMMON_H
+#include "avcodec.h"
+#include "get_bits.h"
#include <stdint.h>
#define IVI_DEBUG
@@ -104,8 +106,7 @@ typedef struct {
uint32_t data_size; ///< size of the band data
int16_t *buf; ///< ptr to the output buffer for this band
int16_t *ref_buf; ///< ptr to the reference frame buffer for motion compensation
- int16_t *buf1; ///< primary band buffer
- int16_t *buf2; ///< secondary band buffer
+ int16_t *bufs[3]; ///< array of pointers to the band buffers
uint32_t pitch; ///< pitch associated with the buffers above
uint8_t is_empty; ///< = 1 if this band doesn't contain any data
uint8_t mb_size; ///< macroblock size
@@ -152,10 +153,6 @@ typedef struct {
typedef struct {
uint16_t width;
uint16_t height;
- // uint32_t pitch;
- uint8_t buf_switch; ///< used to switch between two buffers
- //int16_t *buf1; ///< primary buffer to store decoded pixels
- //int16_t *buf2; ///< secondary buffer to store decoded pixels
uint8_t num_bands; ///< number of bands this plane subdivided into
IVIBandDesc *bands; ///< array of band descriptors
} IVIPlaneDesc;
@@ -206,7 +203,7 @@ int ff_ivi_init_tiles(IVIPlaneDesc *pla
int ff_ivi_dec_tile_data_size(GetBitContext *gb);
int ff_ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band, IVITile *tile);
void ff_ivi_process_empty_tile(AVCodecContext *avctx, IVIBandDesc *band, IVITile *tile, int32_t mv_scale);
-void ff_ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, int dst_pitch);
+void ff_ivi_output_plane(const IVIPlaneDesc *plane, uint8_t *dst, const int dst_pitch);
void ff_ivi_put_pixels_8x8(int32_t *in, int16_t *out, uint32_t pitch, uint8_t *flags);
void ff_ivi_put_dc_pixel_8x8(int32_t *in, int16_t *out, uint32_t pitch, int blk_size);
Added: indeo5/ivi_dsp.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ indeo5/ivi_dsp.c Sun Jan 3 02:19:11 2010 (r5556)
@@ -0,0 +1,588 @@
+/*
+ * DSP functions for Indeo Video Interactive codecs (indeo4 and indeo5)
+ *
+ * Copyright (c) 2009 Maxim Poliakovski
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file libavcodec/ivi_dsp.c
+ * DSP functions (inverse transforms, motion compensation, wavelet recompostions)
+ * for indeo video interactive codecs.
+ */
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "ivi_common.h"
+#include "ivi_dsp.h"
+
+/**
+ * 5/3 - Wavelet recomposition filter for indeo5.
+ */
+void ff_ivi_recompose53(const IVIPlaneDesc *plane, uint8_t *dst, const int dst_pitch, const int num_bands)
+{
+ int x, y, indx;
+ int32_t p0, p1, p2, p3, tmp0, tmp1, tmp2;
+ int32_t b0_1, b0_2, b1_1, b1_2, b1_3, b2_1, b2_2, b2_3, b2_4, b2_5, b2_6;
+ int32_t b3_1, b3_2, b3_3, b3_4, b3_5, b3_6, b3_7, b3_8, b3_9;
+ uint32_t pitch, back_pitch;
+ const IDWTELEM *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr;
+
+ /* all bands should have the same pitch */
+ pitch = plane->bands[0].pitch;
+
+ /* pixels at the position "y-1" will be set to pixels at the "y" for the 1st iteration */
+ back_pitch = 0;
+
+ /* get pointers to the wavelet bands */
+ b0_ptr = plane->bands[0].buf;
+ b1_ptr = plane->bands[1].buf;
+ b2_ptr = plane->bands[2].buf;
+ b3_ptr = plane->bands[3].buf;
+
+ for (y = 0; y < plane->height; y += 2) {
+ /* load storage variables with values */
+ if (num_bands > 0) {
+ b0_1 = b0_ptr[0];
+ b0_2 = b0_ptr[pitch];
+ }
+
+ if (num_bands > 1) {
+ b1_1 = b1_ptr[back_pitch];
+ b1_2 = b1_ptr[0];
+ b1_3 = b1_1 - b1_2*6 + b1_ptr[pitch];
+ }
+
+ if (num_bands > 2) {
+ b2_2 = b2_ptr[0]; // b2[x, y ]
+ b2_3 = b2_2; // b2[x+1,y ] = b2[x,y]
+ b2_5 = b2_ptr[pitch]; // b2[x ,y+1]
+ b2_6 = b2_5; // b2[x+1,y+1] = b2[x,y+1]
+ }
+
+ if (num_bands > 3) {
+ b3_2 = b3_ptr[back_pitch]; // b3[x ,y-1]
+ b3_3 = b3_2; // b3[x+1,y-1] = b3[x ,y-1]
+ b3_5 = b3_ptr[0]; // b3[x ,y ]
+ b3_6 = b3_5; // b3[x+1,y ] = b3[x ,y ]
+ b3_8 = b3_2 - b3_5*6 + b3_ptr[pitch];
+ b3_9 = b3_8;
+ }
+
+ for (x = 0, indx = 0; x < plane->width; x+=2, indx++) {
+ /* some values calculated in the previous iterations can */
+ /* be reused in the next ones, so do appropriate copying */
+ b2_1 = b2_2; // b2[x-1,y ] = b2[x, y ]
+ b2_2 = b2_3; // b2[x ,y ] = b2[x+1,y ]
+ b2_4 = b2_5; // b2[x-1,y+1] = b2[x ,y+1]
+ b2_5 = b2_6; // b2[x ,y+1] = b2[x+1,y+1]
+ b3_1 = b3_2; // b3[x-1,y-1] = b3[x ,y-1]
+ b3_2 = b3_3; // b3[x ,y-1] = b3[x+1,y-1]
+ b3_4 = b3_5; // b3[x-1,y ] = b3[x ,y ]
+ b3_5 = b3_6; // b3[x ,y ] = b3[x+1,y ]
+ b3_7 = b3_8; // vert_HPF(x-1)
+ b3_8 = b3_9; // vert_HPF(x )
+
+ p0 = p1 = p2 = p3 = 0;
+
+ /* process the LL-band by applying LPF both vertically and horizontally */
+ if (num_bands > 0) {
+ tmp0 = b0_1;
+ tmp2 = b0_2;
+ b0_1 = b0_ptr[indx+1];
+ b0_2 = b0_ptr[pitch+indx+1];
+ tmp1 = tmp0 + b0_1;
+
+ p0 = tmp0 << 4;
+ p1 = tmp1 << 3;
+ p2 = (tmp0 + tmp2) << 3;
+ p3 = (tmp1 + tmp2 + b0_2) << 2;
+ }
+
+ /* process the HL-band by applying HPF vertically and LPF horizontally */
+ if (num_bands > 1) {
+ tmp0 = b1_2;
+ tmp1 = b1_1;
+ b1_2 = b1_ptr[indx+1];
+ b1_1 = b1_ptr[back_pitch+indx+1];
+
+ tmp2 = tmp1 - tmp0*6 + b1_3;
+ b1_3 = b1_1 - b1_2*6 + b1_ptr[pitch+indx+1];
+
+ p0 += (tmp0 + tmp1) << 3;
+ p1 += (tmp0 + tmp1 + b1_1 + b1_2) << 2;
+ p2 += tmp2 << 2;
+ p3 += (tmp2 + b1_3) << 1;
+ }
+
+ /* process the LH-band by applying LPF vertically and HPF horizontally */
+ if (num_bands > 2) {
+ b2_3 = b2_ptr[indx+1];
+ b2_6 = b2_ptr[pitch+indx+1];
+
+ tmp0 = b2_1 + b2_2;
+ tmp1 = b2_1 - b2_2*6 + b2_3;
+
+ p0 += tmp0 << 3;
+ p1 += tmp1 << 2;
+ p2 += (tmp0 + b2_4 + b2_5) << 2;
+ p3 += (tmp1 + b2_4 - b2_5*6 + b2_6) << 1;
+ }
+
+ /* process the HH-band by applying HPF both vertically and horizontally */
+ if (num_bands > 3) {
+ b3_6 = b3_ptr[indx+1]; // b3[x+1,y ]
+ b3_3 = b3_ptr[back_pitch+indx+1]; // b3[x+1,y-1]
+
+ tmp0 = b3_1 + b3_4;
+ tmp1 = b3_2 + b3_5;
+ tmp2 = b3_3 + b3_6;
+
+ b3_9 = b3_3 - b3_6*6 + b3_ptr[pitch+indx+1];
+
+ p0 += (tmp0 + tmp1) << 2;
+ p1 += (tmp0 - tmp1*6 + tmp2) << 1;
+ p2 += (b3_7 + b3_8) << 1;
+ p3 += b3_7 - b3_8*6 + b3_9;
+ }
+
+ /* output four pixels */
+ dst[x] = av_clip_uint8((p0 >> 6) + 128);
+ dst[x+1] = av_clip_uint8((p1 >> 6) + 128);
+ dst[dst_pitch+x] = av_clip_uint8((p2 >> 6) + 128);
+ dst[dst_pitch+x+1] = av_clip_uint8((p3 >> 6) + 128);
+ }// for x
+
+ dst += dst_pitch << 1;
+
+ back_pitch = -pitch;
+
+ b0_ptr += pitch;
+ b1_ptr += pitch;
+ b2_ptr += pitch;
+ b3_ptr += pitch;
+ }
+}
+
+/** butterfly operation for the inverse slant transform */
+#define IVI_SLANT_BFLY(x, y) t1 = x-y; x += y; y = t1;
+
+/** This is a reflection a,b = 1/2, 5/4 for the inverse slant transform */
+#define IVI_IREFLECT(s1, s2) {\
+ t1 = s1 + ((s1 + s2*2 + 2) >> 2);\
+ s2 = ((s1*2 - s2 + 2) >> 2) - s2;\
+ s1 = t1;}
+
+/** This is a reflection a,b = 1/2, 7/8 for the inverse slant transform */
+#define IVI_SLANT_PART4(s1, s2) {\
+ t1 = s2 + ((s1*4 - s2 + 4) >> 3);\
+ s2 = ((-s1 - s2*4 + 4) >> 3) + s1;\
+ s1 = t1;}
+
+/** inverse slant8 transform */
+#define IVI_INV_SLANT8(s1, s4, s8, s5, s2, s6, s3, s7, d1, d2, d3, d4, d5, d6, d7, d8) {\
+ IVI_SLANT_PART4(s4, s5);\
+ IVI_SLANT_BFLY(s1, s5); IVI_SLANT_BFLY(s2, s6); IVI_SLANT_BFLY(s7, s3); IVI_SLANT_BFLY(s4, s8);\
+ IVI_SLANT_BFLY(s1, s2); IVI_IREFLECT (s4, s3); IVI_SLANT_BFLY(s5, s6); IVI_IREFLECT (s8, s7);\
+ IVI_SLANT_BFLY(s1, s4); IVI_SLANT_BFLY(s2, s3); IVI_SLANT_BFLY(s5, s8); IVI_SLANT_BFLY(s6, s7);\
+ d1 = COMPENSATE(s1);\
+ d2 = COMPENSATE(s2);\
+ d3 = COMPENSATE(s3);\
+ d4 = COMPENSATE(s4);\
+ d5 = COMPENSATE(s5);\
+ d6 = COMPENSATE(s6);\
+ d7 = COMPENSATE(s7);\
+ d8 = COMPENSATE(s8);}
+
+/** inverse slant4 transform */
+#define IVI_INV_SLANT4(s1, s4, s2, s3, d1, d2, d3, d4) {\
+ IVI_SLANT_BFLY(s1, s2); IVI_IREFLECT (s4, s3);\
+ IVI_SLANT_BFLY(s1, s4); IVI_SLANT_BFLY(s2, s3);\
+ d1 = COMPENSATE(s1);\
+ d2 = COMPENSATE(s2);\
+ d3 = COMPENSATE(s3);\
+ d4 = COMPENSATE(s4);}
+
+
+/**
+ * Two-dimensional inverse slant 8x8 transform.
+ */
+void ff_ivi_inverse_slant_8x8(int32_t *in, int16_t *out, uint32_t pitch, uint8_t *flags)
+{
+ int i, t1;
+ int32_t *src, *dst, tmp[64];
+
+ /* apply the InvSlant8 to all columns */
+#define COMPENSATE(x) (x)
+ src = in;
+ dst = tmp;
+ for (i = 0; i < 8; i++) {
+ if (flags[i]) {
+ IVI_INV_SLANT8(src[0], src[8], src[16], src[24], src[32], src[40], src[48], src[56],
+ dst[0], dst[8], dst[16], dst[24], dst[32], dst[40], dst[48], dst[56]);
+ } else
+ dst[0] = dst[8] = dst[16] = dst[24] = dst[32] = dst[40] = dst[48] = dst[56] = 0;
+
+ src++;
+ dst++;
+ }
+#undef COMPENSATE
+
+ /* apply the InvSlant8 to all rows and output the resulting coeffs in the band buffer */
+ /* the (x + 1)/2 term is needed to compensate the normalization of the forward transform */
+#define COMPENSATE(x) ((x + 1)>>1)
+ src = tmp;
+ for (i = 0; i < 8; i++) {
+ if (!src[0] && !src[1] && !src[2] && !src[3] && !src[4] && !src[5] && !src[6] && !src[7]) {
+ memset(out, 0, 8*sizeof(int16_t));
+ } else {
+ IVI_INV_SLANT8(src[0], src[1], src[2], src[3], src[4], src[5], src[6], src[7],
+ out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]);
+ }
+ src += 8;
+ out += pitch;
+ }
+#undef COMPENSATE
+}
+
+
+/**
+ * Two-dimensional inverse slant 4x4 transform.
+ */
+void ff_ivi_inverse_slant_4x4(int32_t *in, int16_t *out, uint32_t pitch, uint8_t *flags)
+{
+ int i, t1;
+ int32_t *src, *dst, tmp[16];
+
+ /* apply the InvSlant4 to all columns */
+#define COMPENSATE(x) (x)
+ src = in;
+ dst = tmp;
+ for (i = 0; i < 4; i++) {
+ if (flags[i]) {
+ IVI_INV_SLANT4(src[0], src[4], src[8], src[12], dst[0], dst[4], dst[8], dst[12]);
+ } else
+ dst[0] = dst[4] = dst[8] = dst[12] = 0;
+
+ src++;
+ dst++;
+ }
+#undef COMPENSATE
+
+ /* apply the InvSlant4 to all rows */
+#define COMPENSATE(x) ((x + 1)>>1)
+ src = tmp;
+ for (i = 0; i < 4; i++) {
+ if (!src[0] && !src[1] && !src[2] && !src[3]) {
+ out[0] = out[1] = out[2] = out[3] = 0;
+ } else {
+ IVI_INV_SLANT4(src[0], src[1], src[2], src[3], out[0], out[1], out[2], out[3]);
+ }
+ src += 4;
+ out += pitch;
+ }
+#undef COMPENSATE
+}
+
+
+/**
+ * Speed-up inverse 2D slant transforms.
+ */
+void ff_ivi_dc_slant_2d(int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
+{
+ int x, y;
+ int16_t dc_coeff;
+
+ dc_coeff = (*in + 1) >> 1;
+
+ for (y = 0; y < blk_size; out += pitch, y++) {
+ for (x = 0; x < blk_size; x++)
+ out[x] = dc_coeff;
+ }
+}
+
+
+/**
+ * inverse 1D row slant transform
+ */
+void ff_ivi_row_slant8(int32_t *in, int16_t *out, uint32_t pitch, uint8_t *flags)
+{
+ int i, t1;
+
+ /* apply the InvSlant8 to all rows and output the resulting coeffs in the band buffer */
+ /* the (x + 1)/2 term is needed to compensate the normalization of the forward transform */
+#define COMPENSATE(x) ((x + 1)>>1)
+ for (i = 0; i < 8; i++) {
+ if (!in[0] && !in[1] && !in[2] && !in[3] && !in[4] && !in[5] && !in[6] && !in[7]) {
+ memset(out, 0, 8*sizeof(int16_t));
+ } else {
+ IVI_INV_SLANT8( in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7],
+ out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]);
+ }
+ in += 8;
+ out += pitch;
+ }
+#undef COMPENSATE
+}
+
+
+/**
+ * Speed-up inverse row slant transform.
+ */
+void ff_ivi_dc_row_slant(int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
+{
+ int x, y;
+ int16_t dc_coeff;
+
+ dc_coeff = (*in + 1) >> 1;
+
+ for (x = 0; x < blk_size; x++)
+ out[x] = dc_coeff;
+
+ out += pitch;
+
+ for (y = 1; y < blk_size; out += pitch, y++) {
+ for (x = 0; x < blk_size; x++)
+ out[x] = 0;
+ }
+}
+
+
+/**
+ * inverse 1D column slant transform
+ */
+void ff_ivi_col_slant8(int32_t *in, int16_t *out, uint32_t pitch, uint8_t *flags)
+{
+ int i, t1, row2, row4, row8;
+
+ row2 = pitch << 1;
+ row4 = pitch << 2;
+ row8 = pitch << 3;
+
+ /* apply the InvSlant8 to all columns and output the resulting coeffs in the band buffer */
+ /* the (x + 1)/2 term is needed to compensate the normalization of the forward transform */
+#define COMPENSATE(x) ((x + 1)>>1)
+ for (i = 0; i < 8; i++) {
+ if (flags[i]) {
+ IVI_INV_SLANT8(in[0], in[8], in[16], in[24], in[32], in[40], in[48], in[56],
+ out[0], out[pitch], out[row2], out[row2 + pitch], out[row4],
+ out[row4 + pitch], out[row4 + row2], out[row8 - pitch]);
+ } else {
+ out[0] = out[pitch] = out[row2] = out[row2 + pitch] = out[row4] =
+ out[row4 + pitch] = out[row4 + row2] = out[row8 - pitch] = 0;
+ }
+
+ in++;
+ out++;
+ }
+#undef COMPENSATE
+}
+
+
+/**
+ * Speed-up inverse column slant transform.
+ */
+void ff_ivi_dc_col_slant(int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
+{
+ int x, y;
+ int16_t dc_coeff;
+
+ dc_coeff = (*in + 1) >> 1;
+
+ for (y = 0; y < blk_size; out += pitch, y++) {
+ out[0] = dc_coeff;
+ for (x = 1; x < blk_size; x++)
+ out[x] = 0;
+ }
+}
+
+
+/**
+ * 8x8 block motion compensation with adding delta.
+ */
+void ff_ivi_mc_8x8_delta(int16_t *buf, int16_t *ref_buf, uint32_t pitch, int mc_type)
+{
+ int i, j;
+ int16_t *wptr;
+
+ switch (mc_type) {
+ case 0: /* fullpel (no interpolation) */
+ for (i = 0; i < 8; i++, buf += pitch, ref_buf += pitch) {
+ buf[0] += ref_buf[0];
+ buf[1] += ref_buf[1];
+ buf[2] += ref_buf[2];
+ buf[3] += ref_buf[3];
+ buf[4] += ref_buf[4];
+ buf[5] += ref_buf[5];
+ buf[6] += ref_buf[6];
+ buf[7] += ref_buf[7];
+ }
+ break;
+ case 1: /* horizontal halfpel interpolation */
+ for (i = 0; i < 8; i++, buf += pitch, ref_buf += pitch) {
+ for (j = 0; j < 8; j++)
+ buf[j] += (ref_buf[j] + ref_buf[j+1]) >> 1;
+ }
+ break;
+ case 2: /* vertical halfpel interpolation */
+ wptr = ref_buf + pitch;
+ for (i = 0; i < 8; i++, buf += pitch, wptr += pitch, ref_buf += pitch) {
+ for (j = 0; j < 8; j++)
+ buf[j] += (ref_buf[j] + wptr[j]) >> 1;
+ }
+ break;
+ case 3: /* vertical and horizontal halfpel interpolation */
+ wptr = ref_buf + pitch;
+ for (i = 0; i < 8; i++, buf += pitch, wptr += pitch, ref_buf += pitch) {
+ for (j = 0; j < 8; j++)
+ buf[j] += (ref_buf[j] + ref_buf[j+1] + wptr[j] + wptr[j+1]) >> 2;
+ }
+ break;
+ }
+}
+
+
+/**
+ * 4x4 block motion compensation with adding delta.
+ */
+void ff_ivi_mc_4x4_delta(int16_t *buf, int16_t *ref_buf, uint32_t pitch, int mc_type)
+{
+ int i;
+ int16_t *wptr;
+
+ switch (mc_type) {
+ case 0: /* fullpel (no interpolation) */
+ for (i = 0; i < 4; i++, buf += pitch, ref_buf += pitch) {
+ buf[0] += ref_buf[0];
+ buf[1] += ref_buf[1];
+ buf[2] += ref_buf[2];
+ buf[3] += ref_buf[3];
+ }
+ break;
+ case 1: /* horizontal halfpel interpolation */
+ for (i = 0; i < 4; i++, buf += pitch, ref_buf += pitch) {
+ buf[0] += (ref_buf[0] + ref_buf[1]) >> 1;
+ buf[1] += (ref_buf[1] + ref_buf[2]) >> 1;
+ buf[2] += (ref_buf[2] + ref_buf[3]) >> 1;
+ buf[3] += (ref_buf[3] + ref_buf[4]) >> 1;
+ }
+ break;
+ case 2: /* vertical halfpel interpolation */
+ wptr = ref_buf + pitch;
+ for (i = 0; i < 4; i++, buf += pitch, wptr += pitch, ref_buf += pitch) {
+ buf[0] += (ref_buf[0] + wptr[0]) >> 1;
+ buf[1] += (ref_buf[1] + wptr[1]) >> 1;
+ buf[2] += (ref_buf[2] + wptr[2]) >> 1;
+ buf[3] += (ref_buf[3] + wptr[3]) >> 1;
+ }
+ break;
+ case 3: /* vertical and horizontal halfpel interpolation */
+ wptr = ref_buf + pitch;
+ for (i = 0; i < 4; i++, buf += pitch, wptr += pitch, ref_buf += pitch) {
+ buf[0] += (ref_buf[0] + ref_buf[1] + wptr[0] + wptr[1]) >> 2;
+ buf[1] += (ref_buf[1] + ref_buf[2] + wptr[1] + wptr[2]) >> 2;
+ buf[2] += (ref_buf[2] + ref_buf[3] + wptr[2] + wptr[3]) >> 2;
+ buf[3] += (ref_buf[3] + ref_buf[4] + wptr[3] + wptr[4]) >> 2;
+ }
+ break;
+ }
+}
+
+
+/**
+ * Motion compensation without adding delta.
+ */
+void ff_ivi_mc_8x8_no_delta(int16_t *buf, int16_t *ref_buf, uint32_t pitch, int mc_type)
+{
+ int i, j;
+ int16_t *wptr;
+
+ switch (mc_type) {
+ case 0: /* fullpel (no interpolation, just copy) */
+ for (i = 0; i < 8; i++, buf += pitch, ref_buf += pitch)
+ memcpy(buf, ref_buf, 8*sizeof(int16_t)); /* FIXME: speed critical? */
+ break;
+ case 1: /* horizontal halfpel interpolation */
+ for (i = 0; i < 8; i++, buf += pitch, ref_buf += pitch) {
+ for (j = 0; j < 8; j++)
+ buf[j] = (ref_buf[j] + ref_buf[j+1]) >> 1;
+ }
+ break;
+ case 2: /* vertical halfpel interpolation */
+ wptr = ref_buf + pitch;
+ for (i = 0; i < 8; i++, buf += pitch, wptr += pitch, ref_buf += pitch) {
+ for (j = 0; j < 8; j++)
+ buf[j] = (ref_buf[j] + wptr[j]) >> 1;
+ }
+ break;
+ case 3: /* vertical and horizontal halfpel interpolation */
+ wptr = ref_buf + pitch;
+ for (i = 0; i < 8; i++, buf += pitch, wptr += pitch, ref_buf += pitch) {
+ for (j = 0; j < 8; j++)
+ buf[j] = (ref_buf[j] + ref_buf[j+1] + wptr[j] + wptr[j+1]) >> 2;
+ }
+ break;
+ }
+}
+
+
+/**
+ * 4x4 block motion compensation without adding delta.
+ */
+void ff_ivi_mc_4x4_no_delta(int16_t *buf, int16_t *ref_buf, uint32_t pitch, int mc_type)
+{
+ int i;
+ int16_t *wptr;
+
+ switch (mc_type) {
+ case 0: /* fullpel (no interpolation, just copy) */
+ for (i = 0; i < 4; i++, buf += pitch, ref_buf += pitch) {
+ buf[0] = ref_buf[0];
+ buf[1] = ref_buf[1];
+ buf[2] = ref_buf[2];
+ buf[3] = ref_buf[3];
+ }
+ break;
+ case 1: /* horizontal halfpel interpolation */
+ for (i = 0; i < 4; i++, buf += pitch, ref_buf += pitch) {
+ buf[0] = (ref_buf[0] + ref_buf[1]) >> 1;
+ buf[1] = (ref_buf[1] + ref_buf[2]) >> 1;
+ buf[2] = (ref_buf[2] + ref_buf[3]) >> 1;
+ buf[3] = (ref_buf[3] + ref_buf[4]) >> 1;
+ }
+ break;
+ case 2: /* vertical halfpel interpolation */
+ wptr = ref_buf + pitch;
+ for (i = 0; i < 4; i++, buf += pitch, wptr += pitch, ref_buf += pitch) {
+ buf[0] = (ref_buf[0] + wptr[0]) >> 1;
+ buf[1] = (ref_buf[1] + wptr[1]) >> 1;
+ buf[2] = (ref_buf[2] + wptr[2]) >> 1;
+ buf[3] = (ref_buf[3] + wptr[3]) >> 1;
+ }
+ break;
+ case 3: /* vertical and horizontal halfpel interpolation */
+ wptr = ref_buf + pitch;
+ for (i = 0; i < 4; i++, buf += pitch, wptr += pitch, ref_buf += pitch) {
+ buf[0] = (ref_buf[0] + ref_buf[1] + wptr[0] + wptr[1]) >> 2;
+ buf[1] = (ref_buf[1] + ref_buf[2] + wptr[1] + wptr[2]) >> 2;
+ buf[2] = (ref_buf[2] + ref_buf[3] + wptr[2] + wptr[3]) >> 2;
+ buf[3] = (ref_buf[3] + ref_buf[4] + wptr[3] + wptr[4]) >> 2;
+ }
+ break;
+ }
+}
Added: indeo5/ivi_dsp.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ indeo5/ivi_dsp.h Sun Jan 3 02:19:11 2010 (r5556)
@@ -0,0 +1,149 @@
+/*
+ * DSP functions for Indeo Video Interactive codecs (indeo4 and indeo5)
+ *
+ * Copyright (c) 2009 Maxim Poliakovski
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file libavcodec/ivi_dsp.h
+ * DSP functions (inverse transforms, motion compensations, wavelet recompostion)
+ * for indeo video interactive codecs.
+ */
+
+#ifndef AVCODEC_IVI_DSP_H
+#define AVCODEC_IVI_DSP_H
+
+#include "avcodec.h"
+#include "ivi_common.h"
+
+/**
+ * 5/3 - Wavelet recomposition filter for indeo5.
+ *
+ * @param plane [in] pointer to the descriptor of the plane being processed
+ * @param dst [out] pointer to the destination buffer
+ * @param dst_pitch [in] pitch of the destination buffer
+ * @param num_bands [in] number of wavelet bands to be processed
+ */
+void ff_ivi_recompose53(const IVIPlaneDesc *plane, uint8_t *dst, const int dst_pitch, const int num_bands);
+
+/**
+ * Two-dimensional inverse slant 8x8 transform.
+ *
+ * @param in [in] pointer to the vector of transform coefficients
+ * @param out [out] pointer to the output buffer (frame)
+ * @param pitch [in] pitch to move to the next y line
+ * @param flags [in] pointer to the array of column flags:
+ * != 0 - non_empty column, 0 - empty one
+ * (this array must be filled by caller)
+ */
+void ff_ivi_inverse_slant_8x8(int32_t *in, int16_t *out, uint32_t pitch, uint8_t *flags);
+
+/**
+ * Two-dimensional inverse slant 4x4 transform.
+ *
+ * @param in [in] pointer to the vector of transform coefficients
+ * @param out [out] pointer to the output buffer (frame)
+ * @param pitch [in] pitch to move to the next y line
+ * @param flags [in] pointer to the array of column flags:
+ * != 0 - non_empty column, 0 - empty one
+ * (this array must be filled by caller)
+ */
+void ff_ivi_inverse_slant_4x4(int32_t *in, int16_t *out, uint32_t pitch, uint8_t *flags);
+
+/**
+ * This is a speed-up version of the inverse 2D slant transforms
+ * for the case if there is a non-zero DC coeff and all AC coeffs are zero.
+ * Performing the inverse slant transform in this case is equivalent to
+ * spreading (DC_coeff + 1)/2 over the whole block.
+ * It works much faster than performing the slant transform on a vector of zeroes.
+ *
+ * @param in [in] pointer to the dc coefficient
+ * @param out [out] pointer to the output buffer (frame)
+ * @param pitch [in] pitch to move to the next y line
+ * @param blk_size [in] transform block size
+ */
+void ff_ivi_dc_slant_2d(int32_t *in, int16_t *out, uint32_t pitch, int blk_size);
+
+/**
+ * inverse 1D row slant transform
+ *
+ * @param in [in] pointer to the vector of transform coefficients
+ * @param out [out] pointer to the output buffer (frame)
+ * @param pitch [in] pitch to move to the next y line
+ * @param flags [in] pointer to the array of column flags (unused here)
+ */
+void ff_ivi_row_slant8(int32_t *in, int16_t *out, uint32_t pitch, uint8_t *flags);
+
+/**
+ * inverse 1D column slant transform
+ *
+ * @param in [in] pointer to the vector of transform coefficients
+ * @param out [out] pointer to the output buffer (frame)
+ * @param pitch [in] pitch to move to the next y line
+ * @param flags [in] pointer to the array of column flags:
+ * != 0 - non_empty column, 0 - empty one
+ * (this array must be filled by caller)
+ */
+void ff_ivi_col_slant8(int32_t *in, int16_t *out, uint32_t pitch, uint8_t *flags);
+
+void ff_ivi_dc_row_slant(int32_t *in, int16_t *out, uint32_t pitch, int blk_size);
+
+void ff_ivi_dc_col_slant(int32_t *in, int16_t *out, uint32_t pitch, int blk_size);
+
+/**
+ * 8x8 block motion compensation with adding delta.
+ *
+ * @param buf [in,out] pointer to the block in the current frame buffer containing delta
+ * @param ref_buf [in] pointer to the corresponding block in the reference frame
+ * @param pitch [in] pitch for moving to the next y line
+ * @param mc_type [in] interpolation type
+ */
+void ff_ivi_mc_8x8_delta(int16_t *buf, int16_t *ref_buf, uint32_t pitch, int mc_type);
+
+/**
+ * 4x4 block motion compensation with adding delta.
+ *
+ * @param buf [in,out] pointer to the block in the current frame buffer containing delta
+ * @param ref_buf [in] pointer to the corresponding block in the reference frame
+ * @param pitch [in] pitch for moving to the next y line
+ * @param mc_type [in] interpolation type
+ */
+void ff_ivi_mc_4x4_delta(int16_t *buf, int16_t *ref_buf, uint32_t pitch, int mc_type);
+
+/**
+ * Motion compensation without adding delta.
+ *
+ * @param buf [in,out] pointer to the block in the current frame receiving the result
+ * @param ref_buf [in] pointer to the corresponding block in the reference frame
+ * @param pitch [in] pitch for moving to the next y line
+ * @param mc_type [in] interpolation type
+ */
+void ff_ivi_mc_8x8_no_delta(int16_t *buf, int16_t *ref_buf, uint32_t pitch, int mc_type);
+
+/**
+ * 4x4 block motion compensation without adding delta.
+ *
+ * @param buf [in,out] pointer to the block in the current frame receiving the result
+ * @param ref_buf [in] pointer to the corresponding block in the reference frame
+ * @param pitch [in] pitch for moving to the next y line
+ * @param mc_type [in] interpolation type
+ */
+void ff_ivi_mc_4x4_no_delta(int16_t *buf, int16_t *ref_buf, uint32_t pitch, int mc_type);
+
+#endif /* AVCODEC_IVI_DSP_H */
More information about the FFmpeg-soc
mailing list