1 /*
2 * Duck TrueMotion 2.0 Real Time decoder
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24
28
29 #define BITSTREAM_READER_LE
34
40
42 5, -7, 36, -36,
43 };
44
46 2, -3, 8, -8, 18, -18, 36, -36,
47 };
48
50 1, -1, 2, -3, 8, -8, 18, -18, 36, -36, 54, -54, 96, -96, 144, -144,
51 };
52
55 };
56
57 /* Returns the number of bytes consumed from the bytestream, or
58 * AVERROR_INVALIDDATA if there was an error while decoding the header. */
60 {
62 int header_size;
63 uint8_t header_buffer[128] = { 0 }; /* logical maximum header size */
64 const uint8_t *buf = avpkt->
data;
68
72 }
73
74 header_size = ((buf[0] >> 5) | (buf[0] << 3)) & 0x7f;
75 if (header_size < 10) {
78 }
79
80 if (header_size + 1 >
size) {
83 }
84
85 /* unscramble the header bytes with a XOR operation */
86 for (
i = 1;
i < header_size;
i++)
87 header_buffer[
i - 1] = buf[
i] ^ buf[
i + 1];
88
89 s->delta_size = header_buffer[1];
90 s->hscale = 1 + !!header_buffer[3];
91 if (
s->delta_size < 2 ||
s->delta_size > 4)
93
96
100
102 return header_size;
103 }
104
107 {
110 uint8_t *dst;
111 int x, y, delta_mode;
113
117
118 if ((avctx->
width +
s->hscale - 1)/
s->hscale * avctx->
height *
s->delta_size > avpkt->
size * 8LL * 4)
120
124
128
130 delta_mode =
s->delta_size - 2;
132 for (y = 0; y < avctx->
height; y++) {
134 for (x = 0; x < avctx->
width; x +=
s->hscale) {
137 }
139 }
140
143 for (y = 0; y < avctx->
height; y++) {
144 for (x = 1; x < avctx->
width; x +=
s->hscale)
145 dst[x] = dst[x - 1];
147 }
148 }
149
151 for (y = 0; y < avctx->
height; y++) {
152 for (x = 0; x < avctx->
width; x++)
155 }
156
158 for (y = 0; y < avctx->
height >> 2; y++) {
160 for (x = 0; x < avctx->
width >> 2; x +=
s->hscale) {
163 }
165 }
166
169 for (y = 0; y < avctx->
height >> 2; y++) {
170 for (x = 1; x < avctx->
width >> 2; x +=
s->hscale)
171 dst[x] = dst[x - 1];
173 }
174 }
175
177 for (y = 0; y < avctx->
height >> 2; y++) {
178 for (x = 0; x < avctx->
width >> 2; x++)
179 dst[x] += (dst[x] - 128) / 8;
181 }
182
184 for (y = 0; y < avctx->
height >> 2; y++) {
186 for (x = 0; x < avctx->
width >> 2; x +=
s->hscale) {
189 }
191 }
192
195 for (y = 0; y < avctx->
height >> 2; y++) {
196 for (x = 1; x < avctx->
width >> 2; x +=
s->hscale)
197 dst[x] = dst[x - 1];
199 }
200 }
201
203 for (y = 0; y < avctx->
height >> 2; y++) {
204 for (x = 0; x < avctx->
width >> 2; x++)
205 dst[x] += (dst[x] - 128) / 8;
207 }
208
211 *got_frame = 1;
212
214 }
215
217 {
219 return 0;
220 }
221
223 .
p.
name =
"truemotion2rt",
232 };