annotate indeo2.c @ 2664:f20c1cdfce76 libavcodec

support the LE reader, so it can be tested a little
author michael
date Wed, 11 May 2005 01:50:46 +0000
parents 0a55e35d3e5e
children 7a411f408d74
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 /*
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
2 * Indel Indeo 2 codec
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 *
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
6 * 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
7 * License as published by the Free Software Foundation; either
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
9 *
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
13 * Lesser General Public License for more details.
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
14 *
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
18 *
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
19 */
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 /**
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
22 * @file indeo2.c
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
23 * Intel Indeo 2 decoder.
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
24 */
2664
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
25 #define ALT_BITSTREAM_READER_LE
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
26 #include "avcodec.h"
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
27 #include "bitstream.h"
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
28 #include "indeo2data.h"
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
29
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
30 typedef struct Ir2Context{
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
31 AVCodecContext *avctx;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
32 AVFrame picture;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
33 GetBitContext gb;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
34 int decode_delta;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
35 } Ir2Context;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
36
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
37 #define CODE_VLC_BITS 14
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
38 static VLC ir2_vlc;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
39
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
40 /* 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
41 static inline int ir2_get_code(GetBitContext *gb)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
42 {
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
43 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
44 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
45
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
46 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
47 const uint8_t *table)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
48 {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
49 int i;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
50 int j;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
51 int out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
52 int c;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
53 int t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
54
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
55 if(width&1)
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
56 return -1;
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
57
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
58 /* first line contain absolute values, other lines contain deltas */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
59 while (out < width){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
60 c = ir2_get_code(&ctx->gb);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
61 if(c >= 0x80) { /* we have a run */
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
62 c -= 0x7F;
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
63 if(out + c*2 > width)
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
64 return -1;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
65 for (i = 0; i < c * 2; i++)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
66 dst[out++] = 0x80;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
67 } else { /* copy two values from table */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
68 dst[out++] = table[c * 2];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
69 dst[out++] = table[(c * 2) + 1];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
70 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
71 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
72 dst += stride;
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 for (j = 1; j < height; j++){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
75 out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
76 while (out < width){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
77 c = ir2_get_code(&ctx->gb);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
78 if(c >= 0x80) { /* we have a skip */
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
79 c -= 0x7F;
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
80 if(out + c*2 > width)
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
81 return -1;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
82 for (i = 0; i < c * 2; i++) {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
83 dst[out] = dst[out - stride];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
84 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
85 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
86 } else { /* add two deltas from table */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
87 t = dst[out - stride] + (table[c * 2] - 128);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
88 t= clip_uint8(t);
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
89 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
90 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
91 t = dst[out - stride] + (table[(c * 2) + 1] - 128);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
92 t= clip_uint8(t);
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
93 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
94 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
95 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
96 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
97 dst += stride;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
98 }
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
99 return 0;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
100 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
101
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
102 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
103 const uint8_t *table)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
104 {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
105 int j;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
106 int out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
107 int c;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
108 int t;
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
109
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
110 if(width&1)
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
111 return -1;
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
112
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
113 for (j = 0; j < height; j++){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
114 out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
115 while (out < width){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
116 c = ir2_get_code(&ctx->gb);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
117 if(c >= 0x80) { /* we have a skip */
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
118 c -= 0x7F;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
119 out += c * 2;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
120 } else { /* add two deltas from table */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
121 t = dst[out] + (table[c * 2] - 128);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
122 t= clip_uint8(t);
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
123 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
124 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
125 t = dst[out] + (table[(c * 2) + 1] - 128);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
126 t= clip_uint8(t);
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
127 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
128 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
129 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
130 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
131 dst += stride;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
132 }
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
133 return 0;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
134 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
135
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
136 static int ir2_decode_frame(AVCodecContext *avctx,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
137 void *data, int *data_size,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
138 uint8_t *buf, int buf_size)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
139 {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
140 Ir2Context * const s = avctx->priv_data;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
141 AVFrame *picture = data;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
142 AVFrame * const p= (AVFrame*)&s->picture;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
143 int start;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
144 int i;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
145
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
146 if(p->data[0])
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
147 avctx->release_buffer(avctx, p);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
148
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
149 p->reference = 1;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
150 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
151 if (avctx->reget_buffer(avctx, p)) {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
152 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
153 return -1;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
154 }
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 s->decode_delta = buf[18];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
157
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
158 /* decide whether frame uses deltas or not */
2664
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
159 #ifndef ALT_BITSTREAM_READER_LE
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
160 for (i = 0; i < buf_size; i++)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
161 buf[i] = ff_reverse[buf[i]];
2664
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
162 #endif
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
163 start = 48; /* hardcoded for now */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
164
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
165 init_get_bits(&s->gb, buf + start, buf_size - start);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
166
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
167 if (s->decode_delta) { /* intraframe */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
168 ir2_decode_plane(s, avctx->width, avctx->height,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
169 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
170 /* swapped U and V */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
171 ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
172 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
173 ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
174 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
175 } else { /* interframe */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
176 ir2_decode_plane_inter(s, avctx->width, avctx->height,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
177 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
178 /* swapped U and V */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
179 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
180 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
181 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
182 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
183 }
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 *picture= *(AVFrame*)&s->picture;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
186 *data_size = sizeof(AVPicture);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
187
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
188 return buf_size;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
189 }
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 static int ir2_decode_init(AVCodecContext *avctx){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
192 Ir2Context * const ic = avctx->priv_data;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
193
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
194 ic->avctx = avctx;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
195
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
196 avctx->pix_fmt= PIX_FMT_YUV410P;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
197
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
198 if (!ir2_vlc.table)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
199 init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
200 &ir2_codes[0][1], 4, 2,
2664
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
201 #ifdef ALT_BITSTREAM_READER_LE
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
202 &ir2_codes[0][0], 4, 2, INIT_VLC_USE_STATIC | INIT_VLC_LE);
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
203 #else
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
204 &ir2_codes[0][0], 4, 2, INIT_VLC_USE_STATIC);
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
205 #endif
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
206
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
207 return 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
208 }
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 AVCodec indeo2_decoder = {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
211 "indeo2",
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
212 CODEC_TYPE_VIDEO,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
213 CODEC_ID_INDEO2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
214 sizeof(Ir2Context),
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
215 ir2_decode_init,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
216 NULL,
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 ir2_decode_frame,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
219 CODEC_CAP_DR1,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
220 };