1 /*
2 * TechSmith Screen Codec 2 (aka Dora) decoder
3 * Copyright (c) 2012 Konstantin Shishkov
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * TechSmith Screen Codec 2 decoder
25 */
26
27 #include <inttypes.h>
28
29 #define BITSTREAM_READER_LE
35
44
48
50 {
51 int i;
52
57 }
58 }
59
61 {
63
68 if (ret)
70
76 if (ret) {
79 }
84 if (ret) {
87 }
88 }
89
90 return 0;
91 }
92
93 #define DEQUANT(val, q) (((q) * (val) + 0x80) >> 8)
94 #define DCT1D(d0, d1, d2, d3, s0, s1, s2, s3, OP) \
95 OP(d0, 5 * ((s0) + (s1) + (s2)) + 2 * (s3)); \
96 OP(d1, 5 * ((s0) - (s2) - (s3)) + 2 * (s1)); \
97 OP(d2, 5 * ((s0) - (s2) + (s3)) - 2 * (s1)); \
98 OP(d3, 5 * ((s0) - (s1) + (s2)) - 2 * (s3)); \
99
100 #define COL_OP(a, b) a = (b)
101 #define ROW_OP(a, b) a = ((b) + 0x20) >> 6
102
104 {
105 int i;
106 int tblk[4 * 4];
108
109 for (i = 0; i < 4; i++) {
110 t0 =
DEQUANT(q[0 + (i & 1)], in[0 * 4 + i]);
111 t1 =
DEQUANT(q[1 + (i & 1)], in[1 * 4 + i]);
112 t2 =
DEQUANT(q[0 + (i & 1)], in[2 * 4 + i]);
113 t3 =
DEQUANT(q[1 + (i & 1)], in[3 * 4 + i]);
114 DCT1D(tblk[0 * 4 + i], tblk[1 * 4 + i],
115 tblk[2 * 4 + i], tblk[3 * 4 + i],
117 }
118 for (i = 0; i < 4; i++) {
119 DCT1D(dst[0], dst[1], dst[2], dst[3],
120 tblk[i * 4 + 0], tblk[i * 4 + 1],
121 tblk[i * 4 + 2], tblk[i * 4 + 3],
ROW_OP);
122 dst += stride;
123 }
124 }
125
128 {
130 int prev_dc,
dc, nc, ac, bpos,
val;
131 int i, j, k, l;
132
136 for (i = 0; i < 8; i++, dst += stride)
137 memset(dst, val, 16);
138 } else {
141 for (i = 0; i < 8; i++) {
142 for (j = 0; j < 16; j++)
144 dst += stride;
145 }
146 }
147 return 0;
148 }
149
150 prev_dc = 0;
151 for (j = 0; j < 2; j++) {
152 for (k = 0; k < 4; k++) {
153 if (!(j | k)) {
155 } else {
157 if (dc == -1)
159 if (dc == 0x100)
161 }
162 dc = (dc + prev_dc) & 0xFF;
165
167 if (nc == -1)
169
170 bpos = 1;
171 memset(c->
block + 1, 0, 15 *
sizeof(*c->
block));
172 for (l = 0; l < nc; l++) {
174 if (ac == -1)
176 if (ac == 0x1000)
178 bpos += ac & 0xF;
179 if (bpos >= 16)
183 }
185 }
186 dst += 4 * stride;
187 }
188 return 0;
189 }
190
193 {
195 int off;
196
199
200 for (mb_x = 0; mb_x < c->
mb_width; mb_x++) {
202
203 if (q == 0 || q == 3) // skip block
204 continue;
205 for (i = 0; i < 3; i++) {
209 if (ret)
211 }
212 }
213
214 return 0;
215 }
216
219 {
221 int buf_size = avpkt->
size;
224 uint32_t frame_type,
size;
228
230 frame_type = bytestream2_get_byte(&gb);
231 if (frame_type > 1) {
233 frame_type);
235 }
236
239 }
240
241 if (frame_type == 0) {
242 *got_frame = 1;
245
246 return buf_size;
247 }
248
252 }
253
254 c->
quant[0] = bytestream2_get_byte(&gb);
255 c->
quant[1] = bytestream2_get_byte(&gb);
261 }
262
263 for (i = 0; i < 3; i++) {
266 }
267
269
270 size = bytestream2_get_le32(&gb);
274 }
275
276 for (i = 0; i <
size; i++) {
277 val = bytestream2_get_byte(&gb);
278 len = val & 0x3F;
279 val >>= 6;
280 if (pos + len > num_mb) {
283 }
286 }
287 if (pos < num_mb) {
289 pos, num_mb);
291 }
292
294 size = bytestream2_peek_byte(&gb);
295 if (size & 1) {
296 size = bytestream2_get_byte(&gb) - 1;
297 } else {
298 size = bytestream2_get_le32(&gb) >> 1;
299 }
300 if (!size) {
301 int skip_row = 1, j, off = i * c->
mb_width;
305 skip_row = 0;
306 break;
307 }
308 }
309 if (!skip_row) {
312 }
313 }
318 }
320 if (ret) {
323 }
325 }
326
327 *got_frame = 1;
330
331 /* always report that the buffer was completely consumed */
332 return buf_size;
333 }
334
336 {
338
342
343 return 0;
344 }
345
347 {
350
352
354
358 }
359
367 }
368
373 }
374
375 return 0;
376 }
377
388 };