[Ffmpeg-cvslog] CVS: ffmpeg/libavcodec indeo2.c, NONE, 1.1 indeo2data.h, NONE, 1.1 Makefile, 1.182, 1.183 allcodecs.c, 1.99, 1.100 avcodec.h, 1.389, 1.390

Michael Niedermayer CVS michael
Wed Apr 20 11:40:07 CEST 2005


Update of /cvsroot/ffmpeg/ffmpeg/libavcodec
In directory mail:/var2/tmp/cvs-serv30844/libavcodec

Modified Files:
	Makefile allcodecs.c avcodec.h 
Added Files:
	indeo2.c indeo2data.h 
Log Message:
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)


--- NEW FILE: indeo2.c ---
/*
 * Indel Indeo 2 codec
 * Copyright (c) 2005 Konstantin Shishkov
 *
 * This library 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 of the License, or (at your option) any later version.
 *
 * This library 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 this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
 
/**
 * @file indeo2.c
 * Intel Indeo 2 decoder.
 */
 
#include "avcodec.h"
#include "bitstream.h"
#include "indeo2data.h"

typedef struct Ir2Context{
    AVCodecContext *avctx;
    AVFrame picture;
    GetBitContext gb;
    int decode_delta;
} Ir2Context;

#define CODE_VLC_BITS 14
static VLC ir2_vlc;

/* Indeo 2 codes are in range 0x01..0x7F and 0x81..0x90 */
static inline int ir2_get_code(GetBitContext *gb)
{
    int code;
    
    code = get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1) + 1;
    if (code >= 0x80)
        return (code + 1);
    return code;
}
#define CLAMP_TO_BYTE(value) \
if (value > 255) \
    value = 255; \
else if (value < 0) \
    value = 0; \

static void ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
                             const uint8_t *table)
{
    int i;
    int j;
    int out = 0;
    int c;
    int t;
    
    /* first line contain absolute values, other lines contain deltas */
    while (out < width){
        c = ir2_get_code(&ctx->gb);
        if(c > 0x80) { /* we have a run */
            c -= 0x80;
            for (i = 0; i < c * 2; i++)
                dst[out++] = 0x80;
        } else { /* copy two values from table */
            dst[out++] = table[c * 2];
            dst[out++] = table[(c * 2) + 1];
        }
    }
    dst += stride;
    
    for (j = 1; j < height; j++){
        out = 0;
        while (out < width){
            c = ir2_get_code(&ctx->gb);
            if(c > 0x80) { /* we have a skip */
                c -= 0x80;
                for (i = 0; i < c * 2; i++) {
                    dst[out] = dst[out - stride];
                    out++;
                }
            } else { /* add two deltas from table */
                t = dst[out - stride] + (table[c * 2] - 128);
                CLAMP_TO_BYTE(t);
                dst[out] = t;
                out++;
                t = dst[out - stride] + (table[(c * 2) + 1] - 128);
                CLAMP_TO_BYTE(t);
                dst[out] = t;
                out++;
            }
        }
        dst += stride;
    }
}

static void ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
                             const uint8_t *table)
{
    int j;
    int out = 0;
    int c;
    int t;
    
    for (j = 0; j < height; j++){
        out = 0;
        while (out < width){
            c = ir2_get_code(&ctx->gb);
            if(c > 0x80) { /* we have a skip */
                c -= 0x80;
                out += c * 2;
            } else { /* add two deltas from table */
                t = dst[out] + (table[c * 2] - 128);
                CLAMP_TO_BYTE(t);
                dst[out] = t;
                out++;
                t = dst[out] + (table[(c * 2) + 1] - 128);
                CLAMP_TO_BYTE(t);
                dst[out] = t;
                out++;
            }
        }
        dst += stride;
    }
}

static int ir2_decode_frame(AVCodecContext *avctx, 
                        void *data, int *data_size,
                        uint8_t *buf, int buf_size)
{
    Ir2Context * const s = avctx->priv_data;
    AVFrame *picture = data;
    AVFrame * const p= (AVFrame*)&s->picture;
    int start;
    int i;

    if(p->data[0])
        avctx->release_buffer(avctx, p);

    p->reference = 1;
    p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
    if (avctx->reget_buffer(avctx, p)) {
        av_log(s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
        return -1;
    }

    s->decode_delta = buf[18];
    
    /* decide whether frame uses deltas or not */
    
    for (i = 0; i < buf_size; i++)
        buf[i] = ff_reverse[buf[i]];
        
    start = 48; /* hardcoded for now */

    init_get_bits(&s->gb, buf + start, buf_size - start);

    if (s->decode_delta) { /* intraframe */
        ir2_decode_plane(s, avctx->width, avctx->height,
                         s->picture.data[0], s->picture.linesize[0], ir2_luma_table);
        /* swapped U and V */
        ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
                         s->picture.data[2], s->picture.linesize[2], ir2_luma_table);
        ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
                         s->picture.data[1], s->picture.linesize[1], ir2_luma_table);
    } else { /* interframe */
        ir2_decode_plane_inter(s, avctx->width, avctx->height,
                         s->picture.data[0], s->picture.linesize[0], ir2_luma_table);
        /* swapped U and V */
        ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2,
                         s->picture.data[2], s->picture.linesize[2], ir2_luma_table);
        ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2,
                         s->picture.data[1], s->picture.linesize[1], ir2_luma_table);
    }

    *picture= *(AVFrame*)&s->picture;
    *data_size = sizeof(AVPicture);

    return buf_size;
}

static int ir2_decode_init(AVCodecContext *avctx){
    Ir2Context * const ic = avctx->priv_data;

    ic->avctx = avctx;

    avctx->pix_fmt= PIX_FMT_YUV410P;
    
    if (!ir2_vlc.table)
        init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES,
                 &ir2_codes[0][1], 4, 2,
                 &ir2_codes[0][0], 4, 2, 1);    

    return 0;
}

AVCodec indeo2_decoder = {
    "indeo2",
    CODEC_TYPE_VIDEO,
    CODEC_ID_INDEO2,
    sizeof(Ir2Context),
    ir2_decode_init,
    NULL,
    NULL,
    ir2_decode_frame,
    CODEC_CAP_DR1,
};

--- NEW FILE: indeo2data.h ---
#define IR2_CODES 143
static const uint16_t ir2_codes[IR2_CODES][2] = {
    {0x0000,  3}, {0x0001,  3}, {0x0003,  3}, {0x0010,  5},
    {0x0012,  5}, {0x0013,  5}, {0x0016,  5}, {0x0017,  5},
    {0x0031,  6}, {0x0032,  6}, {0x0033,  6}, {0x0034,  6},
    {0x0035,  6}, {0x0036,  6}, {0x00E0,  8}, {0x00E1,  8},
    {0x00E4,  8}, {0x00E5,  8}, {0x00E6,  8}, {0x00E7,  8},
    {0x00E9,  8}, {0x00EA,  8}, {0x00EC,  8}, {0x00ED,  8},
    {0x00EF,  8}, {0x01E0,  9}, {0x01E2,  9}, {0x01E3,  9},
    {0x01E5,  9}, {0x01E6,  9}, {0x01E8,  9}, {0x01E9,  9},
    {0x01EB,  9}, {0x01EC,  9}, {0x01EE,  9}, {0x01EF,  9},
    {0x03E0, 10}, {0x03E1, 10}, {0x03E2, 10}, {0x03E3, 10},
    {0x03E4, 10}, {0x03E5, 10}, {0x03E6, 10}, {0x03E7, 10},
    {0x03E8, 10}, {0x03E9, 10}, {0x03EA, 10}, {0x03EB, 10},
    {0x03EC, 10}, {0x03ED, 10}, {0x03EE, 10}, {0x03EF, 10},
    {0x1F80, 13}, {0x1F81, 13}, {0x1F82, 13}, {0x1F83, 13},
    {0x1F84, 13}, {0x1F85, 13}, {0x1F86, 13}, {0x1F87, 13},
    {0x1F88, 13}, {0x1F89, 13}, {0x1F8A, 13}, {0x1F8B, 13},
    {0x1F8C, 13}, {0x1F8D, 13}, {0x1F8E, 13}, {0x1F8F, 13},
    {0x1F90, 13}, {0x1F91, 13}, {0x1F92, 13}, {0x1F93, 13},
    {0x1F94, 13}, {0x1F95, 13}, {0x1F96, 13}, {0x1F97, 13},
    {0x1F98, 13}, {0x1F99, 13}, {0x1F9A, 13}, {0x1F9B, 13},
    {0x1F9C, 13}, {0x1F9D, 13}, {0x1F9E, 13}, {0x1F9F, 13},
    {0x1FA0, 13}, {0x1FA1, 13}, {0x1FA2, 13}, {0x1FA3, 13},
    {0x1FA4, 13}, {0x1FA5, 13}, {0x1FA6, 13}, {0x1FA7, 13},
    {0x1FA8, 13}, {0x1FA9, 13}, {0x1FAA, 13}, {0x1FAB, 13},
    {0x1FAC, 13}, {0x1FAD, 13}, {0x1FAE, 13}, {0x1FAF, 13},
    {0x1FB0, 13}, {0x1FB1, 13}, {0x1FB2, 13}, {0x1FB3, 13},
    {0x1FB4, 13}, {0x1FB5, 13}, {0x1FB6, 13}, {0x1FB7, 13},
    {0x1FB8, 13}, {0x1FB9, 13}, {0x1FBA, 13}, {0x1FBB, 13},
    {0x1FBC, 13}, {0x1FBD, 13}, {0x1FBE, 13}, {0x1FBF, 13},
    {0x3F80, 14}, {0x3F81, 14}, {0x3F82, 14}, {0x3F83, 14},
    {0x3F84, 14}, {0x3F85, 14}, {0x3F86, 14}, {0x3F87, 14},
    {0x3F88, 14}, {0x3F89, 14}, {0x3F8A, 14}, {0x0002,  3},
    {0x0011,  5}, {0x0014,  5}, {0x0015,  5}, {0x0030,  6},
    {0x0037,  6}, {0x00E2,  8}, {0x00E3,  8}, {0x00E8,  8},
    {0x00EB,  8}, {0x00EE,  8}, {0x01E1,  9}, {0x01E4,  9},
    {0x01E7,  9}, {0x01EA,  9}, {0x01ED,  9}
};

static const uint8_t ir2_luma_table[256] = {
 0x80, 0x80, 0x84, 0x84, 0x7C, 0x7C, 0x7F, 0x85,
 0x81, 0x7B, 0x85, 0x7F, 0x7B, 0x81, 0x8C, 0x8C,
 0x74, 0x74, 0x83, 0x8D, 0x7D, 0x73, 0x8D, 0x83,
 0x73, 0x7D, 0x77, 0x89, 0x89, 0x77, 0x89, 0x77,
 0x77, 0x89, 0x8C, 0x95, 0x74, 0x6B, 0x95, 0x8C, 
 0x6B, 0x74, 0x7C, 0x90, 0x84, 0x70, 0x90, 0x7C,
 0x70, 0x84, 0x96, 0x96, 0x6A,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, 0x38, 0x29, 0xD7, 0xC8, 
 0x29, 0x38, 0xA4, 0xD8, 0x5C, 0x28, 0xD8, 0xA4,
 0x28, 0x5C, 0x6C, 0xC1, 0x94, 0x3F, 0xC1, 0x6C, 
 0x3F, 0x94, 0xD9, 0xD9, 0x27, 0x27, 0x80, 0x80
};

Index: Makefile
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/Makefile,v
retrieving revision 1.182
retrieving revision 1.183
diff -u -d -r1.182 -r1.183
--- Makefile	3 Apr 2005 05:02:08 -0000	1.182
+++ Makefile	20 Apr 2005 09:40:04 -0000	1.183
@@ -23,7 +23,7 @@
       flac.o vp3dsp.o integer.o snow.o tscc.o sonic.o ulti.o h264idct.o \
       qdrw.o xl.o rangecoder.o png.o pnm.o qpeg.o vc9.o h263.o h261.o \
       msmpeg4.o h263dec.o svq1.o rv10.o wmadec.o indeo3.o shorten.o loco.o \
-      alac.o wnv1.o ws-snd1.o aasc.o
+      alac.o wnv1.o ws-snd1.o aasc.o indeo2.o
 
 AMROBJS=
 ifeq ($(AMR_NB),yes)

Index: allcodecs.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/allcodecs.c,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -d -r1.99 -r1.100
--- allcodecs.c	3 Apr 2005 05:02:08 -0000	1.99
+++ allcodecs.c	20 Apr 2005 09:40:04 -0000	1.100
@@ -122,6 +122,7 @@
     register_avcodec(&svq3_decoder);
     register_avcodec(&wmav1_decoder);
     register_avcodec(&wmav2_decoder);
+    register_avcodec(&indeo2_decoder);
     register_avcodec(&indeo3_decoder);
     register_avcodec(&tscc_decoder);
     register_avcodec(&ulti_decoder);

Index: avcodec.h
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/avcodec.h,v
retrieving revision 1.389
retrieving revision 1.390
diff -u -d -r1.389 -r1.390
--- avcodec.h	3 Apr 2005 05:02:08 -0000	1.389
+++ avcodec.h	20 Apr 2005 09:40:04 -0000	1.390
@@ -107,6 +107,7 @@
     CODEC_ID_LOCO,
     CODEC_ID_WNV1,
     CODEC_ID_AASC,
+    CODEC_ID_INDEO2,
 
     /* various pcm "codecs" */
     CODEC_ID_PCM_S16LE= 0x10000,
@@ -2019,6 +2020,7 @@
 extern AVCodec aasc_decoder;
 extern AVCodec alac_decoder;
 extern AVCodec ws_snd1_decoder;
+extern AVCodec indeo2_decoder;
 
 /* pcm codecs */
 #define PCM_CODEC(id, name) \





More information about the ffmpeg-cvslog mailing list