1 /*
2 * Psygnosis YOP decoder
3 *
4 * Copyright (C) 2010 Mohamed Naufal Basheer <naufal11@gmail.com>
5 * derived from the code by
6 * Copyright (C) 2009 Thomas P. Higdon <thomas.p.higdon@gmail.com>
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
27
31
35
39
46
47 // These tables are taken directly from:
48 // http://wiki.multimedia.cx/index.php?title=Psygnosis_YOP
49
50 /**
51 * Lookup table for painting macroblocks. Bytes 0-2 of each entry contain
52 * the macroblock positions to be painted (taken as (0, B0, B1, B2)).
53 * Byte 3 contains the number of bytes consumed on the input,
54 * equal to max(bytes 0-2) + 1.
55 */
57 {{1, 2, 3, 4}, {1, 2, 0, 3},
58 {1, 2, 1, 3}, {1, 2, 2, 3},
59 {1, 0, 2, 3}, {1, 0, 0, 2},
60 {1, 0, 1, 2}, {1, 1, 2, 3},
61 {0, 1, 2, 3}, {0, 1, 0, 2},
62 {1, 1, 0, 2}, {0, 1, 1, 2},
63 {0, 0, 1, 2}, {0, 0, 0, 1},
64 {1, 1, 1, 2},
65 };
66
67 /**
68 * Lookup table for copying macroblocks. Each entry contains the respective
69 * x and y pixel offset for the copy source.
70 */
72 {{-4, -4}, {-2, -4},
73 { 0, -4}, { 2, -4},
74 {-4, -2}, {-4, 0},
75 {-3, -3}, {-1, -3},
76 { 1, -3}, { 3, -3},
77 {-3, -1}, {-2, -2},
78 { 0, -2}, { 2, -2},
79 { 4, -2}, {-2, 0},
80 };
81
83 {
85
87
88 return 0;
89 }
90
92 {
95
100 }
101
105 }
106
108
112
116 "Palette parameters invalid, header probably corrupt\n");
118 }
119
121
122 return 0;
123 }
124
125 /**
126 * Paint a macroblock using the pattern in paint_lut.
127 * @param s codec context
128 * @param tag the tag that was in the nibble
129 */
131 {
135 }
136
141
142 // The number of src bytes consumed is in the last part of the lut entry.
144 return 0;
145 }
146
147 /**
148 * Copy a previously painted macroblock to the current_block.
149 * @param copy_tag the tag that was in the nibble
150 */
152 {
154
155 // Calculate position for the copy source
158 if (bufptr < s->dstbuf) {
161 }
162
165 s->
dstptr[linesize] = bufptr[linesize];
166 s->
dstptr[linesize + 1] = bufptr[linesize + 1];
167
168 return 0;
169 }
170
171 /**
172 * Return the next nibble in sequence, consuming a new byte on the input
173 * only if necessary.
174 */
176 {
178
182 }else {
185 }
187 }
188
191 {
194 int tag, firstcolor, is_odd_frame;
197
201 }
202
205
208
214
215 is_odd_frame = avpkt->
data[0];
216 if(is_odd_frame>1){
219 }
221 palette = (uint32_t *)frame->
data[1];
222
224 palette[i + firstcolor] = (s->
srcptr[0] << 18) |
227 palette[i + firstcolor] |= 0xFF
U << 24 |
228 (palette[i + firstcolor] >> 6) & 0x30303;
229 }
230
232
233 for (y = 0; y < avctx->
height; y += 2) {
234 for (x = 0; x < avctx->
width; x += 2) {
238 }
239
241
242 if (tag != 0xf) {
244 if (ret < 0)
246 } else {
249 if (ret < 0)
251 }
253 }
255 }
256
259
260 *got_frame = 1;
262 }
263
273 };