Mercurial > libavcodec.hg
annotate indeo2.c @ 2619:c39756a516a5 libavcodec
buffer overflows
author | michael |
---|---|
date | Wed, 20 Apr 2005 09:52:04 +0000 |
parents | fc91ca5b9066 |
children | 0a55e35d3e5e |
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 */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
25 |
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 { |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
43 int code; |
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 code = get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1) + 1; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
46 if (code >= 0x80) |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
47 return (code + 1); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
48 return code; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
49 } |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
50 #define CLAMP_TO_BYTE(value) \ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
51 if (value > 255) \ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
52 value = 255; \ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
53 else if (value < 0) \ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
54 value = 0; \ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
55 |
2619 | 56 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
|
57 const uint8_t *table) |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
58 { |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
59 int i; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
60 int j; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
61 int out = 0; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
62 int c; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
63 int t; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
64 |
2619 | 65 if(width&1) |
66 return -1; | |
67 | |
2618
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
68 /* first line contain absolute values, other lines contain deltas */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
69 while (out < width){ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
70 c = ir2_get_code(&ctx->gb); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
71 if(c > 0x80) { /* we have a run */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
72 c -= 0x80; |
2619 | 73 if(out + c*2 > width) |
74 return -1; | |
2618
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
75 for (i = 0; i < c * 2; i++) |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
76 dst[out++] = 0x80; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
77 } else { /* copy two values from table */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
78 dst[out++] = table[c * 2]; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
79 dst[out++] = table[(c * 2) + 1]; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
80 } |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
81 } |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
82 dst += stride; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
83 |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
84 for (j = 1; j < height; j++){ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
85 out = 0; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
86 while (out < width){ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
87 c = ir2_get_code(&ctx->gb); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
88 if(c > 0x80) { /* we have a skip */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
89 c -= 0x80; |
2619 | 90 if(out + c*2 > width) |
91 return -1; | |
2618
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
92 for (i = 0; i < c * 2; i++) { |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
93 dst[out] = dst[out - stride]; |
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 } else { /* add two deltas from table */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
97 t = dst[out - stride] + (table[c * 2] - 128); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
98 CLAMP_TO_BYTE(t); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
99 dst[out] = t; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
100 out++; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
101 t = dst[out - stride] + (table[(c * 2) + 1] - 128); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
102 CLAMP_TO_BYTE(t); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
103 dst[out] = t; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
104 out++; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
105 } |
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 dst += stride; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
108 } |
2619 | 109 return 0; |
2618
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
110 } |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
111 |
2619 | 112 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
|
113 const uint8_t *table) |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
114 { |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
115 int j; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
116 int out = 0; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
117 int c; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
118 int t; |
2619 | 119 |
120 if(width&1) | |
121 return -1; | |
122 | |
2618
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
123 for (j = 0; j < height; j++){ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
124 out = 0; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
125 while (out < width){ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
126 c = ir2_get_code(&ctx->gb); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
127 if(c > 0x80) { /* we have a skip */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
128 c -= 0x80; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
129 out += c * 2; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
130 } else { /* add two deltas from table */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
131 t = dst[out] + (table[c * 2] - 128); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
132 CLAMP_TO_BYTE(t); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
133 dst[out] = t; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
134 out++; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
135 t = dst[out] + (table[(c * 2) + 1] - 128); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
136 CLAMP_TO_BYTE(t); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
137 dst[out] = t; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
138 out++; |
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 } |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
141 dst += stride; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
142 } |
2619 | 143 return 0; |
2618
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
144 } |
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 static int ir2_decode_frame(AVCodecContext *avctx, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
147 void *data, int *data_size, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
148 uint8_t *buf, int buf_size) |
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 Ir2Context * const s = avctx->priv_data; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
151 AVFrame *picture = data; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
152 AVFrame * const p= (AVFrame*)&s->picture; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
153 int start; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
154 int i; |
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 if(p->data[0]) |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
157 avctx->release_buffer(avctx, p); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
158 |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
159 p->reference = 1; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
160 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
|
161 if (avctx->reget_buffer(avctx, p)) { |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
162 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
|
163 return -1; |
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 |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
166 s->decode_delta = buf[18]; |
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 /* decide whether frame uses deltas or not */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
169 |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
170 for (i = 0; i < buf_size; i++) |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
171 buf[i] = ff_reverse[buf[i]]; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
172 |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
173 start = 48; /* hardcoded for now */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
174 |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
175 init_get_bits(&s->gb, buf + start, buf_size - start); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
176 |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
177 if (s->decode_delta) { /* intraframe */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
178 ir2_decode_plane(s, avctx->width, avctx->height, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
179 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
|
180 /* swapped U and V */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
181 ir2_decode_plane(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[2], s->picture.linesize[2], ir2_luma_table); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
183 ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
184 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
|
185 } else { /* interframe */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
186 ir2_decode_plane_inter(s, avctx->width, avctx->height, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
187 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
|
188 /* swapped U and V */ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
189 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
|
190 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
|
191 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
|
192 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
|
193 } |
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 *picture= *(AVFrame*)&s->picture; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
196 *data_size = sizeof(AVPicture); |
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 return buf_size; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
199 } |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
200 |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
201 static int ir2_decode_init(AVCodecContext *avctx){ |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
202 Ir2Context * const ic = avctx->priv_data; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
203 |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
204 ic->avctx = avctx; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
205 |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
206 avctx->pix_fmt= PIX_FMT_YUV410P; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
207 |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
208 if (!ir2_vlc.table) |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
209 init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
210 &ir2_codes[0][1], 4, 2, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
211 &ir2_codes[0][0], 4, 2, 1); |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
212 |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
213 return 0; |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
214 } |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
215 |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
216 AVCodec indeo2_decoder = { |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
217 "indeo2", |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
218 CODEC_TYPE_VIDEO, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
219 CODEC_ID_INDEO2, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
220 sizeof(Ir2Context), |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
221 ir2_decode_init, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
222 NULL, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
223 NULL, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
224 ir2_decode_frame, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
225 CODEC_CAP_DR1, |
fc91ca5b9066
Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff
changeset
|
226 }; |