1 /*
2 * MidiVid decoder
3 * Copyright (c) 2019 Paul B Mahol
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
26
27 #define BITSTREAM_READER_LE
33
36
40
43
45 {
49 uint16_t nb_vectors, intra_flag;
50 const uint8_t *vec;
51 const uint8_t *mask_start;
53 uint32_t mask_size;
54 int idx9bits = 0;
55 int idx9val = 0;
56 uint32_t nb_blocks;
57
58 nb_vectors = bytestream2_get_le16(gb);
59 intra_flag = !!bytestream2_get_le16(gb);
60 if (intra_flag) {
61 nb_blocks = (avctx->
width / 2) * (avctx->
height / 2);
62 } else {
63 int ret, skip_linesize, padding;
64
65 nb_blocks = bytestream2_get_le32(gb);
66 skip_linesize = avctx->
width >> 1;
70
73
79
80 for (
int y = 0; y < avctx->
height >> 2; y++) {
81 for (
int x = 0; x < avctx->
width >> 2; x++) {
83
84 skip[(y*2) *skip_linesize + x*2 ] =
flag;
85 skip[(y*2) *skip_linesize + x*2+1] =
flag;
86 skip[(y*2+1)*skip_linesize + x*2 ] =
flag;
87 skip[(y*2+1)*skip_linesize + x*2+1] =
flag;
88 }
90 }
91 }
92
97 if (nb_vectors > 256) {
102 }
103
105
106 for (
int y = avctx->
height - 2; y >= 0; y -= 2) {
107 uint8_t *dsty =
frame->data[0] + y *
frame->linesize[0];
108 uint8_t *dstu =
frame->data[1] + y *
frame->linesize[1];
109 uint8_t *dstv =
frame->data[2] + y *
frame->linesize[2];
110
111 for (
int x = 0; x < avctx->
width; x += 2) {
112 int idx;
113
114 if (!intra_flag && *
skip++)
115 continue;
118 if (nb_vectors <= 256) {
119 idx = bytestream2_get_byte(gb);
120 } else {
121 if (idx9bits == 0) {
122 idx9val = bytestream2_get_byte(&idx9);
123 idx9bits = 8;
124 }
125 idx9bits--;
126 idx = bytestream2_get_byte(gb) | (((idx9val >> (7 - idx9bits)) & 1) << 8);
127 }
128 if (idx >= nb_vectors)
130
131 dsty[x +
frame->linesize[0]] = vec[idx * 12 + 0];
132 dsty[x+1+
frame->linesize[0]] = vec[idx * 12 + 3];
133 dsty[x] = vec[idx * 12 + 6];
134 dsty[x+1] = vec[idx * 12 + 9];
135
136 dstu[x +
frame->linesize[1]] = vec[idx * 12 + 1];
137 dstu[x+1+
frame->linesize[1]] = vec[idx * 12 + 4];
138 dstu[x] = vec[idx * 12 + 7];
139 dstu[x+1] = vec[idx * 12 +10];
140
141 dstv[x +
frame->linesize[2]] = vec[idx * 12 + 2];
142 dstv[x+1+
frame->linesize[2]] = vec[idx * 12 + 5];
143 dstv[x] = vec[idx * 12 + 8];
144 dstv[x+1] = vec[idx * 12 +11];
145 }
146 }
147
148 return intra_flag;
149 }
150
152 {
153 uint8_t *dst_start =
dst;
155
157 int op = bytestream2_get_le16(gb);
158
159 for (
int i = 0;
i < 16;
i++) {
161 int s0 = bytestream2_get_byte(gb);
162 int s1 = bytestream2_get_byte(gb);
163 int offset = ((s0 & 0xF0) << 4) | s1;
164 int length = (s0 & 0xF) + 3;
165
166 if (
dst + length > dst_end ||
170 for (int j = 0; j < length; j++) {
172 }
173 }
175 } else {
178 *
dst++ = bytestream2_get_byte(gb);
179 }
181 }
182 }
183
184 return dst - dst_start;
185 }
186
189 {
193 int ret,
key, uncompressed;
194
195 if (avpkt->
size <= 13)
197
200 uncompressed = bytestream2_get_le32(gb);
201
202 if (!uncompressed) {
204 if (!
s->uncompressed)
206
211 }
212
215
217
221
224
228 else
230 *got_frame = 1;
231
233 }
234
236 {
239
242
247 }
248
250
257
258 return 0;
259 }
260
262 {
264
266 }
267
269 {
271
275
276 return 0;
277 }
278
291 };