annotate indeo2.c @ 4295:aabfa0a58cb0 libavcodec

fix playback of mp3_bits_left.avi
author michael
date Mon, 11 Dec 2006 13:01:20 +0000
parents c8c591fe26f8
children a96d905dcbaa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
1 /*
3724
42b08e756c3b Fix Indel --> Intel typo.
diego
parents: 3036
diff changeset
2 * Intel Indeo 2 codec
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
3 * Copyright (c) 2005 Konstantin Shishkov
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3724
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3724
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3724
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3724
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3724
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
16 *
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3724
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2967
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
20 *
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
21 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
22
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
23 /**
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
24 * @file indeo2.c
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
25 * Intel Indeo 2 decoder.
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
26 */
2664
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
27 #define ALT_BITSTREAM_READER_LE
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
28 #include "avcodec.h"
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
29 #include "bitstream.h"
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
30 #include "indeo2data.h"
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
31
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
32 typedef struct Ir2Context{
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
33 AVCodecContext *avctx;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
34 AVFrame picture;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
35 GetBitContext gb;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
36 int decode_delta;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
37 } Ir2Context;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
38
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
39 #define CODE_VLC_BITS 14
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
40 static VLC ir2_vlc;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
41
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
42 /* Indeo 2 codes are in range 0x01..0x7F and 0x81..0x90 */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
43 static inline int ir2_get_code(GetBitContext *gb)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
44 {
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
45 return get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1) + 1;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
46 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
47
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
48 static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
49 const uint8_t *table)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
50 {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
51 int i;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
52 int j;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
53 int out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
54 int c;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
55 int t;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
56
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
57 if(width&1)
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
58 return -1;
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
59
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
60 /* first line contain absolute values, other lines contain deltas */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
61 while (out < width){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
62 c = ir2_get_code(&ctx->gb);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
63 if(c >= 0x80) { /* we have a run */
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
64 c -= 0x7F;
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
65 if(out + c*2 > width)
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
66 return -1;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
67 for (i = 0; i < c * 2; i++)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
68 dst[out++] = 0x80;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
69 } else { /* copy two values from table */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
70 dst[out++] = table[c * 2];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
71 dst[out++] = table[(c * 2) + 1];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
72 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
73 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
74 dst += stride;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
75
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
76 for (j = 1; j < height; j++){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
77 out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
78 while (out < width){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
79 c = ir2_get_code(&ctx->gb);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
80 if(c >= 0x80) { /* we have a skip */
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
81 c -= 0x7F;
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
82 if(out + c*2 > width)
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
83 return -1;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
84 for (i = 0; i < c * 2; i++) {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
85 dst[out] = dst[out - stride];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
86 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
87 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
88 } else { /* add two deltas from table */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
89 t = dst[out - stride] + (table[c * 2] - 128);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
90 t= clip_uint8(t);
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
91 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
92 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
93 t = dst[out - stride] + (table[(c * 2) + 1] - 128);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
94 t= clip_uint8(t);
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
95 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
96 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
97 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
98 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
99 dst += stride;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
100 }
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
101 return 0;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
102 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
103
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
104 static int ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
105 const uint8_t *table)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
106 {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
107 int j;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
108 int out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
109 int c;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
110 int t;
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
111
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
112 if(width&1)
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
113 return -1;
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
114
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
115 for (j = 0; j < height; j++){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
116 out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
117 while (out < width){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
118 c = ir2_get_code(&ctx->gb);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
119 if(c >= 0x80) { /* we have a skip */
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
120 c -= 0x7F;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
121 out += c * 2;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
122 } else { /* add two deltas from table */
2783
7a411f408d74 Here is the patch suggested by: unkaggregate, users sf net
michael
parents: 2664
diff changeset
123 t = dst[out] + (((table[c * 2] - 128)*3) >> 2);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
124 t= clip_uint8(t);
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
125 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
126 out++;
2783
7a411f408d74 Here is the patch suggested by: unkaggregate, users sf net
michael
parents: 2664
diff changeset
127 t = dst[out] + (((table[(c * 2) + 1] - 128)*3) >> 2);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
128 t= clip_uint8(t);
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
129 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
130 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
131 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
132 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
133 dst += stride;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
134 }
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
135 return 0;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
136 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
137
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
138 static int ir2_decode_frame(AVCodecContext *avctx,
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
139 void *data, int *data_size,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
140 uint8_t *buf, int buf_size)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
141 {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
142 Ir2Context * const s = avctx->priv_data;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
143 AVFrame *picture = data;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
144 AVFrame * const p= (AVFrame*)&s->picture;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
145 int start;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
146
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
147 if(p->data[0])
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
148 avctx->release_buffer(avctx, p);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
149
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
150 p->reference = 1;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
151 p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
152 if (avctx->reget_buffer(avctx, p)) {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
153 av_log(s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
154 return -1;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
155 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
156
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
157 s->decode_delta = buf[18];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
158
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
159 /* decide whether frame uses deltas or not */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
160 #ifndef ALT_BITSTREAM_READER_LE
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
161 for (i = 0; i < buf_size; i++)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
162 buf[i] = ff_reverse[buf[i]];
2664
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
163 #endif
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
164 start = 48; /* hardcoded for now */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
165
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
166 init_get_bits(&s->gb, buf + start, buf_size - start);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
167
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
168 if (s->decode_delta) { /* intraframe */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
169 ir2_decode_plane(s, avctx->width, avctx->height,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
170 s->picture.data[0], s->picture.linesize[0], ir2_luma_table);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
171 /* swapped U and V */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
172 ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
173 s->picture.data[2], s->picture.linesize[2], ir2_luma_table);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
174 ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
175 s->picture.data[1], s->picture.linesize[1], ir2_luma_table);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
176 } else { /* interframe */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
177 ir2_decode_plane_inter(s, avctx->width, avctx->height,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
178 s->picture.data[0], s->picture.linesize[0], ir2_luma_table);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
179 /* swapped U and V */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
180 ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
181 s->picture.data[2], s->picture.linesize[2], ir2_luma_table);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
182 ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
183 s->picture.data[1], s->picture.linesize[1], ir2_luma_table);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
184 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
185
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
186 *picture= *(AVFrame*)&s->picture;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
187 *data_size = sizeof(AVPicture);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
188
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
189 return buf_size;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
190 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
191
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
192 static int ir2_decode_init(AVCodecContext *avctx){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
193 Ir2Context * const ic = avctx->priv_data;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
194
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
195 ic->avctx = avctx;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
196
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
197 avctx->pix_fmt= PIX_FMT_YUV410P;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
198
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
199 if (!ir2_vlc.table)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
200 init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
201 &ir2_codes[0][1], 4, 2,
2664
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
202 #ifdef ALT_BITSTREAM_READER_LE
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
203 &ir2_codes[0][0], 4, 2, INIT_VLC_USE_STATIC | INIT_VLC_LE);
2664
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
204 #else
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
205 &ir2_codes[0][0], 4, 2, INIT_VLC_USE_STATIC);
2664
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
206 #endif
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
207
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
208 return 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
209 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
210
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
211 AVCodec indeo2_decoder = {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
212 "indeo2",
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
213 CODEC_TYPE_VIDEO,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
214 CODEC_ID_INDEO2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
215 sizeof(Ir2Context),
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
216 ir2_decode_init,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
217 NULL,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
218 NULL,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
219 ir2_decode_frame,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
220 CODEC_CAP_DR1,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
221 };