42 #define COLORS_PER_TABLE 256
57 #define GET_BLOCK_COUNT() \
58 (opcode & 0x10) ? (1 + bytestream2_get_byte(gb)) : 1 + (opcode & 0x0F);
60 #define ADVANCE_BLOCK() \
63 if (pixel_ptr >= width) \
66 row_ptr += stride * 4; \
69 if (total_blocks < !!n_blocks) \
71 av_log(s->avctx, AV_LOG_ERROR, "block counter just went negative (this should not happen)\n"); \
72 return AVERROR_INVALIDDATA; \
78 int width =
s->avctx->width;
80 int stride =
s->frame->linesize[0];
86 unsigned int color_flags;
87 unsigned int color_flags_a;
88 unsigned int color_flags_b;
89 unsigned int flag_mask;
91 uint8_t *
const pixels =
s->frame->data[0];
93 int image_size =
height *
s->frame->linesize[0];
100 int prev_block_ptr1, prev_block_ptr2;
103 int color_table_index;
106 int color_pair_index = 0;
107 int color_quad_index = 0;
108 int color_octet_index = 0;
114 chunk_size = bytestream2_get_be24(gb);
115 if (chunk_size != buf_size)
116 av_log(
s->avctx,
AV_LOG_WARNING,
"MOV chunk size != encoded chunk size (%d != %d); using MOV chunk size\n",
117 chunk_size, buf_size);
119 chunk_size = buf_size;
120 total_blocks = ((
s->avctx->width + 3) / 4) * ((
s->avctx->height + 3) / 4);
123 while (total_blocks) {
126 if (row_ptr >= image_size) {
128 row_ptr, image_size);
136 opcode = bytestream2_get_byteu(gb);
137 switch (opcode & 0xF0) {
153 if ((row_ptr == 0) && (pixel_ptr == 0)) {
154 av_log(
s->avctx,
AV_LOG_ERROR,
"encountered repeat block opcode (%02X) but no blocks rendered yet\n",
162 (row_ptr -
s->avctx->width * 4) +
s->avctx->width - 4;
164 prev_block_ptr1 = row_ptr + pixel_ptr - 4;
167 block_ptr = row_ptr + pixel_ptr;
168 prev_block_ptr = prev_block_ptr1;
169 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
170 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
171 pixels[block_ptr++] = pixels[prev_block_ptr++];
173 block_ptr += row_inc;
174 prev_block_ptr += row_inc;
187 if ((row_ptr == 0) && (pixel_ptr < 2 * 4)) {
188 av_log(
s->avctx,
AV_LOG_ERROR,
"encountered repeat block opcode (%02X) but not enough blocks rendered yet\n",
195 prev_block_ptr1 = (row_ptr -
s->avctx->width * 4) +
196 s->avctx->width - 4 * 2;
197 else if (pixel_ptr == 4)
198 prev_block_ptr1 = (row_ptr -
s->avctx->width * 4) + row_inc;
200 prev_block_ptr1 = row_ptr + pixel_ptr - 4 * 2;
203 prev_block_ptr2 = (row_ptr -
s->avctx->width * 4) + row_inc;
205 prev_block_ptr2 = row_ptr + pixel_ptr - 4;
209 block_ptr = row_ptr + pixel_ptr;
211 prev_block_ptr = prev_block_ptr2;
213 prev_block_ptr = prev_block_ptr1;
214 prev_block_flag = !prev_block_flag;
216 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
217 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
218 pixels[block_ptr++] = pixels[prev_block_ptr++];
220 block_ptr += row_inc;
221 prev_block_ptr += row_inc;
231 pixel = bytestream2_get_byte(gb);
234 block_ptr = row_ptr + pixel_ptr;
235 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
236 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
237 pixels[block_ptr++] =
pixel;
239 block_ptr += row_inc;
248 n_blocks = (opcode & 0x0F) + 1;
251 if ((opcode & 0xF0) == 0x80) {
255 pixel = bytestream2_get_byte(gb);
256 color_table_index =
CPAIR * color_pair_index +
i;
257 s->color_pairs[color_table_index] =
pixel;
260 color_table_index =
CPAIR * color_pair_index;
264 color_pair_index = 0;
266 color_table_index =
CPAIR * bytestream2_get_byte(gb);
269 color_flags = bytestream2_get_be16(gb);
271 block_ptr = row_ptr + pixel_ptr;
272 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
273 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
274 if (color_flags & flag_mask)
275 pixel = color_table_index + 1;
277 pixel = color_table_index;
279 pixels[block_ptr++] =
s->color_pairs[
pixel];
281 block_ptr += row_inc;
290 n_blocks = (opcode & 0x0F) + 1;
293 if ((opcode & 0xF0) == 0xA0) {
297 pixel = bytestream2_get_byte(gb);
298 color_table_index =
CQUAD * color_quad_index +
i;
299 s->color_quads[color_table_index] =
pixel;
302 color_table_index =
CQUAD * color_quad_index;
306 color_quad_index = 0;
308 color_table_index =
CQUAD * bytestream2_get_byte(gb);
311 color_flags = bytestream2_get_be32(gb);
314 block_ptr = row_ptr + pixel_ptr;
315 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
316 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
317 pixel = color_table_index +
318 ((color_flags >> flag_mask) & 0x03);
320 pixels[block_ptr++] =
s->color_quads[
pixel];
322 block_ptr += row_inc;
331 n_blocks = (opcode & 0x0F) + 1;
334 if ((opcode & 0xF0) == 0xC0) {
338 pixel = bytestream2_get_byte(gb);
339 color_table_index =
COCTET * color_octet_index +
i;
340 s->color_octets[color_table_index] =
pixel;
343 color_table_index =
COCTET * color_octet_index;
347 color_octet_index = 0;
349 color_table_index =
COCTET * bytestream2_get_byte(gb);
359 int val1 = bytestream2_get_be16(gb);
360 int val2 = bytestream2_get_be16(gb);
361 int val3 = bytestream2_get_be16(gb);
362 color_flags_a = ((val1 & 0xFFF0) << 8) | (val2 >> 4);
363 color_flags_b = ((val3 & 0xFFF0) << 8) |
364 ((val1 & 0x0F) << 8) | ((val2 & 0x0F) << 4) | (val3 & 0x0F);
366 color_flags = color_flags_a;
369 block_ptr = row_ptr + pixel_ptr;
370 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
373 color_flags = color_flags_b;
376 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
377 pixel = color_table_index +
378 ((color_flags >> flag_mask) & 0x07);
380 pixels[block_ptr++] =
s->color_octets[
pixel];
382 block_ptr += row_inc;
391 n_blocks = (opcode & 0x0F) + 1;
394 block_ptr = row_ptr + pixel_ptr;
395 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
396 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
397 pixels[block_ptr++] = bytestream2_get_byte(gb);
399 block_ptr += row_inc;
427 const uint8_t *buf = avpkt->
data;
428 int buf_size = avpkt->
size;
432 int total_blocks = ((
s->avctx->width + 3) / 4) * ((
s->avctx->height + 3) / 4);
434 if (total_blocks / 1024 > avpkt->
size)
440 #if FF_API_PALETTE_HAS_CHANGED
442 s->frame->palette_has_changed =
445 #if FF_API_PALETTE_HAS_CHANGED