45 #define COLORS_PER_TABLE 256
62 #define GET_BLOCK_COUNT() \
63 (opcode & 0x10) ? (1 + bytestream2_get_byte(gb)) : 1 + (opcode & 0x0F);
65 #define ADVANCE_BLOCK() \
68 if (pixel_ptr >= width) \
71 row_ptr += stride * 4; \
74 if (total_blocks < !!n_blocks) \
76 av_log(s->avctx, AV_LOG_ERROR, "block counter just went negative (this should not happen)\n"); \
77 return AVERROR_INVALIDDATA; \
84 int width =
s->avctx->width;
86 int stride =
s->frame->linesize[0];
92 unsigned int color_flags;
93 unsigned int color_flags_a;
94 unsigned int color_flags_b;
95 unsigned int flag_mask;
97 uint8_t *
const pixels =
s->frame->data[0];
99 int image_size =
height *
s->frame->linesize[0];
102 int pixel_x, pixel_y;
106 int prev_block_ptr1, prev_block_ptr2;
109 int color_table_index;
112 int color_pair_index = 0;
113 int color_quad_index = 0;
114 int color_octet_index = 0;
120 chunk_size = bytestream2_get_be24(gb);
121 if (chunk_size != buf_size)
122 av_log(
s->avctx,
AV_LOG_WARNING,
"MOV chunk size != encoded chunk size (%d != %d); using MOV chunk size\n",
123 chunk_size, buf_size);
125 chunk_size = buf_size;
126 total_blocks = ((
s->avctx->width + 3) / 4) * ((
s->avctx->height + 3) / 4);
129 while (total_blocks) {
132 if (row_ptr >= image_size) {
134 row_ptr, image_size);
142 opcode = bytestream2_get_byteu(gb);
143 switch (opcode & 0xF0) {
159 if ((row_ptr == 0) && (pixel_ptr == 0)) {
160 av_log(
s->avctx,
AV_LOG_ERROR,
"encountered repeat block opcode (%02X) but no blocks rendered yet\n",
168 (row_ptr -
s->avctx->width * 4) +
s->avctx->width - 4;
170 prev_block_ptr1 = row_ptr + pixel_ptr - 4;
173 block_ptr = row_ptr + pixel_ptr;
174 prev_block_ptr = prev_block_ptr1;
175 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
176 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
177 pixels[block_ptr++] = pixels[prev_block_ptr++];
179 block_ptr += row_inc;
180 prev_block_ptr += row_inc;
193 if ((row_ptr == 0) && (pixel_ptr < 2 * 4)) {
194 av_log(
s->avctx,
AV_LOG_ERROR,
"encountered repeat block opcode (%02X) but not enough blocks rendered yet\n",
201 prev_block_ptr1 = (row_ptr -
s->avctx->width * 4) +
202 s->avctx->width - 4 * 2;
203 else if (pixel_ptr == 4)
204 prev_block_ptr1 = (row_ptr -
s->avctx->width * 4) + row_inc;
206 prev_block_ptr1 = row_ptr + pixel_ptr - 4 * 2;
209 prev_block_ptr2 = (row_ptr -
s->avctx->width * 4) + row_inc;
211 prev_block_ptr2 = row_ptr + pixel_ptr - 4;
215 block_ptr = row_ptr + pixel_ptr;
217 prev_block_ptr = prev_block_ptr2;
219 prev_block_ptr = prev_block_ptr1;
220 prev_block_flag = !prev_block_flag;
222 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
223 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
224 pixels[block_ptr++] = pixels[prev_block_ptr++];
226 block_ptr += row_inc;
227 prev_block_ptr += row_inc;
237 pixel = bytestream2_get_byte(gb);
240 block_ptr = row_ptr + pixel_ptr;
241 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
242 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
243 pixels[block_ptr++] =
pixel;
245 block_ptr += row_inc;
254 n_blocks = (opcode & 0x0F) + 1;
257 if ((opcode & 0xF0) == 0x80) {
261 pixel = bytestream2_get_byte(gb);
262 color_table_index =
CPAIR * color_pair_index +
i;
263 s->color_pairs[color_table_index] =
pixel;
266 color_table_index =
CPAIR * color_pair_index;
270 color_pair_index = 0;
272 color_table_index =
CPAIR * bytestream2_get_byte(gb);
275 color_flags = bytestream2_get_be16(gb);
277 block_ptr = row_ptr + pixel_ptr;
278 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
279 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
280 if (color_flags & flag_mask)
281 pixel = color_table_index + 1;
283 pixel = color_table_index;
285 pixels[block_ptr++] =
s->color_pairs[
pixel];
287 block_ptr += row_inc;
296 n_blocks = (opcode & 0x0F) + 1;
299 if ((opcode & 0xF0) == 0xA0) {
303 pixel = bytestream2_get_byte(gb);
304 color_table_index =
CQUAD * color_quad_index +
i;
305 s->color_quads[color_table_index] =
pixel;
308 color_table_index =
CQUAD * color_quad_index;
312 color_quad_index = 0;
314 color_table_index =
CQUAD * bytestream2_get_byte(gb);
317 color_flags = bytestream2_get_be32(gb);
320 block_ptr = row_ptr + pixel_ptr;
321 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
322 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
323 pixel = color_table_index +
324 ((color_flags >> flag_mask) & 0x03);
326 pixels[block_ptr++] =
s->color_quads[
pixel];
328 block_ptr += row_inc;
337 n_blocks = (opcode & 0x0F) + 1;
340 if ((opcode & 0xF0) == 0xC0) {
344 pixel = bytestream2_get_byte(gb);
345 color_table_index =
COCTET * color_octet_index +
i;
346 s->color_octets[color_table_index] =
pixel;
349 color_table_index =
COCTET * color_octet_index;
353 color_octet_index = 0;
355 color_table_index =
COCTET * bytestream2_get_byte(gb);
365 int val1 = bytestream2_get_be16(gb);
366 int val2 = bytestream2_get_be16(gb);
367 int val3 = bytestream2_get_be16(gb);
368 color_flags_a = ((val1 & 0xFFF0) << 8) | (val2 >> 4);
369 color_flags_b = ((val3 & 0xFFF0) << 8) |
370 ((val1 & 0x0F) << 8) | ((val2 & 0x0F) << 4) | (val3 & 0x0F);
372 color_flags = color_flags_a;
375 block_ptr = row_ptr + pixel_ptr;
376 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
379 color_flags = color_flags_b;
382 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
383 pixel = color_table_index +
384 ((color_flags >> flag_mask) & 0x07);
386 pixels[block_ptr++] =
s->color_octets[
pixel];
388 block_ptr += row_inc;
397 n_blocks = (opcode & 0x0F) + 1;
400 block_ptr = row_ptr + pixel_ptr;
401 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
402 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
403 pixels[block_ptr++] = bytestream2_get_byte(gb);
405 block_ptr += row_inc;
431 void *
data,
int *got_frame,
434 const uint8_t *buf = avpkt->
data;
435 int buf_size = avpkt->
size;
438 int total_blocks = ((
s->avctx->width + 3) / 4) * ((
s->avctx->height + 3) / 4);
440 if (total_blocks / 1024 > avpkt->
size)