1 /*
2 * Escape 130 video decoder
3 * Copyright (C) 2008 Eli Friedman (eli.friedman <at> gmail.com)
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
25 #define BITSTREAM_READER_LE
28
31
35
39
42 { 0, 0, 0, 0 },
43 { -1, 1, 0, 0 },
44 { 1, -1, 0, 0 },
45 { -1, 0, 1, 0 },
46 { -1, 1, 1, 0 },
47 { 0, -1, 1, 0 },
48 { 1, -1, 1, 0 },
49 { -1, -1, 1, 0 },
50 { 1, 0, -1, 0 },
51 { 0, 1, -1, 0 },
52 { 1, 1, -1, 0 },
53 { -1, 1, -1, 0 },
54 { 1, -1, -1, 0 },
55 { -1, 0, 0, 1 },
56 { -1, 1, 0, 1 },
57 { 0, -1, 0, 1 },
58
59 { 0, 0, 0, 0 },
60 { 1, -1, 0, 1 },
61 { -1, -1, 0, 1 },
62 { -1, 0, 1, 1 },
63 { -1, 1, 1, 1 },
64 { 0, -1, 1, 1 },
65 { 1, -1, 1, 1 },
66 { -1, -1, 1, 1 },
67 { 0, 0, -1, 1 },
68 { 1, 0, -1, 1 },
69 { -1, 0, -1, 1 },
70 { 0, 1, -1, 1 },
71 { 1, 1, -1, 1 },
72 { -1, 1, -1, 1 },
73 { 0, -1, -1, 1 },
74 { 1, -1, -1, 1 },
75
76 { 0, 0, 0, 0 },
77 { -1, -1, -1, 1 },
78 { 1, 0, 0, -1 },
79 { 0, 1, 0, -1 },
80 { 1, 1, 0, -1 },
81 { -1, 1, 0, -1 },
82 { 1, -1, 0, -1 },
83 { 0, 0, 1, -1 },
84 { 1, 0, 1, -1 },
85 { -1, 0, 1, -1 },
86 { 0, 1, 1, -1 },
87 { 1, 1, 1, -1 },
88 { -1, 1, 1, -1 },
89 { 0, -1, 1, -1 },
90 { 1, -1, 1, -1 },
91 { -1, -1, 1, -1 },
92
93 { 0, 0, 0, 0 },
94 { 1, 0, -1, -1 },
95 { 0, 1, -1, -1 },
96 { 1, 1, -1, -1 },
97 { -1, 1, -1, -1 },
98 { 1, -1, -1, -1 }
99 };
100
101 static const int8_t
luma_adjust[] = { -4, -3, -2, -1, 1, 2, 3, 4 };
102
104 { 1, 1, 0, -1, -1, -1, 0, 1 },
105 { 0, 1, 1, 1, 0, -1, -1, -1 }
106 };
107
109 20, 28, 36, 44, 52, 60, 68, 76,
110 84, 92, 100, 106, 112, 116, 120, 124,
111 128, 132, 136, 140, 144, 150, 156, 164,
112 172, 180, 188, 196, 204, 212, 220, 228
113 };
114
116 {
119
122 "Dimensions should be a multiple of two.\n");
124 }
125
135 }
136
140
150
151 return 0;
152 }
153
155 {
157
161
162 return 0;
163 }
164
166 {
168
170 return -1;
171
173 if (value)
174 return 0;
175
177 if (value)
179
181 if (value)
182 return value + 7;
183
185 if (value)
186 return value + 262;
187
188 return -1;
189 }
190
193 {
194 int buf_size = avpkt->
size;
199
200 uint8_t *old_y, *old_cb, *old_cr,
201 *new_y, *new_cb, *new_cr;
203 unsigned old_y_stride, old_cb_stride, old_cr_stride,
204 new_y_stride, new_cb_stride, new_cr_stride;
205 unsigned total_blocks = avctx->
width * avctx->
height / 4,
206 block_index, block_x = 0;
207 unsigned y[4] = { 0 },
cb = 0x10,
cr = 0x10;
208 int skip = -1, y_avg = 0, i, j;
210
211 // first 16 bytes are header; no useful information in here
212 if (buf_size <= 16) {
215 }
216
219
223
236
237 for (block_index = 0; block_index < total_blocks; block_index++) {
238 // Note that this call will make us skip the rest of the blocks
239 // if the frame ends prematurely.
240 if (skip == -1)
242 if (skip == -1) {
245 }
246
247 if (skip) {
248 y[0] = old_y[0];
249 y[1] = old_y[1];
250 y[2] = old_y[old_y_stride];
251 y[3] = old_y[old_y_stride + 1];
252 y_avg = ya[0];
255 } else {
257 unsigned sign_selector =
get_bits(&gb, 6);
258 unsigned difference_selector =
get_bits(&gb, 2);
260 for (i = 0; i < 4; i++) {
261 y[i] = av_clip(y_avg +
offset_table[difference_selector] *
263 }
267 } else {
268 unsigned adjust_index =
get_bits(&gb, 3);
270 }
271 for (i = 0; i < 4; i++)
272 y[i] = y_avg;
273 }
274
279 } else {
280 unsigned adjust_index =
get_bits(&gb, 3);
283 }
284 }
285 }
286 *ya++ = y_avg;
287
288 new_y[0] = y[0];
289 new_y[1] = y[1];
290 new_y[new_y_stride] = y[2];
291 new_y[new_y_stride + 1] = y[3];
294
295 old_y += 2;
296 old_cb++;
297 old_cr++;
298 new_y += 2;
299 new_cb++;
300 new_cr++;
301 block_x++;
302 if (block_x * 2 == avctx->
width) {
303 block_x = 0;
304 old_y += old_y_stride * 2 - avctx->
width;
305 old_cb += old_cb_stride - avctx->
width / 2;
306 old_cr += old_cr_stride - avctx->
width / 2;
307 new_y += new_y_stride * 2 - avctx->
width;
308 new_cb += new_cb_stride - avctx->
width / 2;
309 new_cr += new_cr_stride - avctx->
width / 2;
310 }
311
312 skip--;
313 }
314
321 for (j = 0; j < avctx->
height; j++) {
322 for (i = 0; i < avctx->
width; i++)
323 dstY[i] = new_y[i] << 2;
325 new_y += new_y_stride;
326 }
327 for (j = 0; j < avctx->
height / 2; j++) {
328 for (i = 0; i < avctx->
width / 2; i++) {
331 }
334 new_cb += new_cb_stride;
335 new_cr += new_cr_stride;
336 }
337
338 av_dlog(avctx,
"Frame data: provided %d bytes, used %d bytes\n",
340
344
345 *got_frame = 1;
346
347 return buf_size;
348 }
349
360 };