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
23
24 #define BITSTREAM_READER_LE
29
35
37 5, -7, 36, -36,
38 };
39
41 2, -3, 8, -8, 18, -18, 36, -36,
42 };
43
45 1, -1, 2, -3, 8, -8, 18, -18, 36, -36, 54, -54, 96, -96, 144, -144,
46 };
47
50 };
51
52 /* Returns the number of bytes consumed from the bytestream, or
53 * AVERROR_INVALIDDATA if there was an error while decoding the header. */
55 {
57 int header_size;
58 uint8_t header_buffer[128] = { 0 }; /* logical maximum header size */
59 const uint8_t *buf = avpkt->
data;
63
67 }
68
69 header_size = ((buf[0] >> 5) | (buf[0] << 3)) & 0x7f;
70 if (header_size < 10) {
73 }
74
75 if (header_size + 1 >
size) {
78 }
79
80 /* unscramble the header bytes with a XOR operation */
81 for (
i = 1;
i < header_size;
i++)
82 header_buffer[
i - 1] = buf[
i] ^ buf[
i + 1];
83
84 s->delta_size = header_buffer[1];
85 s->hscale = 1 + !!header_buffer[3];
86 if (
s->delta_size < 2 ||
s->delta_size > 4)
88
91
95
97 return header_size;
98 }
99
102 {
106 int x, y, delta_mode;
108
112
113 if ((avctx->
width +
s->hscale - 1)/
s->hscale * avctx->
height *
s->delta_size > avpkt->
size * 8LL * 4)
115
119
123
125 delta_mode =
s->delta_size - 2;
127 for (y = 0; y < avctx->
height; y++) {
129 for (x = 0; x < avctx->
width; x +=
s->hscale) {
132 }
134 }
135
138 for (y = 0; y < avctx->
height; y++) {
139 for (x = 1; x < avctx->
width; x +=
s->hscale)
142 }
143 }
144
146 for (y = 0; y < avctx->
height; y++) {
147 for (x = 0; x < avctx->
width; x++)
150 }
151
153 for (y = 0; y < avctx->
height >> 2; y++) {
155 for (x = 0; x < avctx->
width >> 2; x +=
s->hscale) {
158 }
160 }
161
164 for (y = 0; y < avctx->
height >> 2; y++) {
165 for (x = 1; x < avctx->
width >> 2; x +=
s->hscale)
168 }
169 }
170
172 for (y = 0; y < avctx->
height >> 2; y++) {
173 for (x = 0; x < avctx->
width >> 2; x++)
174 dst[x] += (
dst[x] - 128) / 8;
176 }
177
179 for (y = 0; y < avctx->
height >> 2; y++) {
181 for (x = 0; x < avctx->
width >> 2; x +=
s->hscale) {
184 }
186 }
187
190 for (y = 0; y < avctx->
height >> 2; y++) {
191 for (x = 1; x < avctx->
width >> 2; x +=
s->hscale)
194 }
195 }
196
198 for (y = 0; y < avctx->
height >> 2; y++) {
199 for (x = 0; x < avctx->
width >> 2; x++)
200 dst[x] += (
dst[x] - 128) / 8;
202 }
203
204 *got_frame = 1;
205
207 }
208
210 {
212 return 0;
213 }
214
216 .
p.
name =
"truemotion2rt",
224 };