1 /*
2 * Dxtory decoder
3 *
4 * Copyright (c) 2011 Konstantin Shishkov
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #define BITSTREAM_READER_LE
31
34 {
35 int h, w;
38
39 if (src_size < avctx->
width * avctx->
height * 3 / 2) {
42 }
43
47
52 for (h = 0; h < avctx->
height; h += 2) {
53 for (w = 0; w < avctx->
width; w += 2) {
56 U[w >> 1] = src[4] + 0x80;
57 V[w >> 1] = src[5] + 0x80;
58 src += 6;
59 }
64 }
65
66 return 0;
67 }
68
69 static const uint8_t def_lru[8] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xFF };
70
72 {
74
76 if (!c) {
78 memmove(lru + 1, lru, sizeof(*lru) * (8 - 1));
79 } else {
80 val = lru[c - 1];
81 memmove(lru + 1, lru, sizeof(*lru) * (c - 1));
82 }
84
86 }
87
90 int ystride, int ustride, int vstride)
91 {
94
95 for (i = 0; i < 3; i++)
97
98 for (y = 0; y <
height; y+=2) {
99 for (x = 0; x <
width; x += 2) {
100 Y[x + 0 + 0 * ystride] =
decode_sym(gb, lru[0]);
101 Y[x + 1 + 0 * ystride] =
decode_sym(gb, lru[0]);
102 Y[x + 0 + 1 * ystride] =
decode_sym(gb, lru[0]);
103 Y[x + 1 + 1 * ystride] =
decode_sym(gb, lru[0]);
106 }
107
108 Y += ystride << 1;
109 U += ustride;
110 V += vstride;
111 }
112
113 return 0;
114 }
115
118 {
121 int nslices, slice, slice_height;
122 uint32_t
off, slice_size;
125
127 nslices = bytestream2_get_le16(&gb);
128 off =
FFALIGN(nslices * 4 + 2, 16);
129 if (src_size < off) {
132 }
133
134 if (!nslices || avctx->
height % nslices) {
138 }
139
140 slice_height = avctx->
height / nslices;
141 if ((avctx->
width & 1) || (slice_height & 1)) {
143 avctx->
width, slice_height);
144 }
145
149
153
154 for (slice = 0; slice < nslices; slice++) {
155 slice_size = bytestream2_get_le32(&gb);
156 if (slice_size > src_size - off) {
158 "invalid slice size %d (only %d bytes left)\n",
159 slice_size, src_size - off);
161 }
162 if (slice_size <= 16) {
165 }
166
167 if (
AV_RL32(src + off) != slice_size - 16) {
169 "Slice sizes mismatch: got %d instead of %d\n",
170 AV_RL32(src + off), slice_size - 16);
171 }
175
176 Y += pic->
linesize[0] * slice_height;
177 U += pic->
linesize[1] * (slice_height >> 1);
178 V += pic->
linesize[2] * (slice_height >> 1);
179 off += slice_size;
180 }
181
182 return 0;
183 }
184
187 {
191
192 if (avpkt->
size < 16) {
195 }
196
198 case 0x02000001:
200 break;
201 case 0x02000009:
203 break;
204 default:
207 }
208
209 if (ret)
211
214 *got_frame = 1;
215
217 }
218
226 };