43 #define COLORS_PER_TABLE 256
60 #define GET_BLOCK_COUNT() \
61 (opcode & 0x10) ? (1 + bytestream2_get_byte(&s->gb)) : 1 + (opcode & 0x0F);
63 #define ADVANCE_BLOCK() \
66 if (pixel_ptr >= width) \
69 row_ptr += stride * 4; \
72 if (total_blocks < 0) \
74 av_log(s->avctx, AV_LOG_INFO, "warning: block counter just went negative (this should not happen)\n"); \
89 unsigned int color_flags;
90 unsigned int color_flags_a;
91 unsigned int color_flags_b;
92 unsigned int flag_mask;
100 int row_inc = stride - 4;
103 int prev_block_ptr1, prev_block_ptr2;
106 int color_table_index;
109 int color_pair_index = 0;
110 int color_quad_index = 0;
111 int color_octet_index = 0;
117 chunk_size = bytestream2_get_be24(&s->
gb);
118 if (chunk_size != buf_size)
119 av_log(s->
avctx,
AV_LOG_INFO,
"warning: MOV chunk size != encoded chunk size (%d != %d); using MOV chunk size\n",
120 chunk_size, buf_size);
122 chunk_size = buf_size;
126 while (total_blocks) {
129 if (row_ptr >= image_size) {
131 row_ptr, image_size);
135 opcode = bytestream2_get_byte(&s->
gb);
136 switch (opcode & 0xF0) {
152 if ((row_ptr == 0) && (pixel_ptr == 0)) {
163 prev_block_ptr1 = row_ptr + pixel_ptr - 4;
166 block_ptr = row_ptr + pixel_ptr;
167 prev_block_ptr = prev_block_ptr1;
168 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
169 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
170 pixels[block_ptr++] = pixels[prev_block_ptr++];
172 block_ptr += row_inc;
173 prev_block_ptr += row_inc;
186 if ((row_ptr == 0) && (pixel_ptr < 2 * 4)) {
187 av_log(s->
avctx,
AV_LOG_INFO,
"encountered repeat block opcode (%02X) but not enough blocks rendered yet\n",
194 prev_block_ptr1 = (row_ptr - s->
avctx->
width * 4) +
196 else if (pixel_ptr == 4)
197 prev_block_ptr1 = (row_ptr - s->
avctx->
width * 4) + row_inc;
199 prev_block_ptr1 = row_ptr + pixel_ptr - 4 * 2;
202 prev_block_ptr2 = (row_ptr - s->
avctx->
width * 4) + row_inc;
204 prev_block_ptr2 = row_ptr + pixel_ptr - 4;
208 block_ptr = row_ptr + pixel_ptr;
210 prev_block_ptr = prev_block_ptr2;
212 prev_block_ptr = prev_block_ptr1;
213 prev_block_flag = !prev_block_flag;
215 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
216 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
217 pixels[block_ptr++] = pixels[prev_block_ptr++];
219 block_ptr += row_inc;
220 prev_block_ptr += row_inc;
230 pixel = bytestream2_get_byte(&s->
gb);
233 block_ptr = row_ptr + pixel_ptr;
234 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
235 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
236 pixels[block_ptr++] =
pixel;
238 block_ptr += row_inc;
247 n_blocks = (opcode & 0x0F) + 1;
250 if ((opcode & 0xF0) == 0x80) {
253 for (i = 0; i <
CPAIR; i++) {
254 pixel = bytestream2_get_byte(&s->
gb);
255 color_table_index = CPAIR * color_pair_index + i;
259 color_table_index = CPAIR * color_pair_index;
263 color_pair_index = 0;
265 color_table_index =
CPAIR * bytestream2_get_byte(&s->
gb);
268 color_flags = bytestream2_get_be16(&s->
gb);
270 block_ptr = row_ptr + pixel_ptr;
271 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
272 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
273 if (color_flags & flag_mask)
274 pixel = color_table_index + 1;
276 pixel = color_table_index;
280 block_ptr += row_inc;
289 n_blocks = (opcode & 0x0F) + 1;
292 if ((opcode & 0xF0) == 0xA0) {
295 for (i = 0; i <
CQUAD; i++) {
296 pixel = bytestream2_get_byte(&s->
gb);
297 color_table_index = CQUAD * color_quad_index + i;
301 color_table_index = CQUAD * color_quad_index;
305 color_quad_index = 0;
307 color_table_index =
CQUAD * bytestream2_get_byte(&s->
gb);
310 color_flags = bytestream2_get_be32(&s->
gb);
313 block_ptr = row_ptr + pixel_ptr;
314 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
315 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
316 pixel = color_table_index +
317 ((color_flags >> flag_mask) & 0x03);
321 block_ptr += row_inc;
330 n_blocks = (opcode & 0x0F) + 1;
333 if ((opcode & 0xF0) == 0xC0) {
336 for (i = 0; i <
COCTET; i++) {
337 pixel = bytestream2_get_byte(&s->
gb);
338 color_table_index = COCTET * color_octet_index + i;
342 color_table_index = COCTET * color_octet_index;
346 color_octet_index = 0;
348 color_table_index =
COCTET * bytestream2_get_byte(&s->
gb);
358 int val1 = bytestream2_get_be16(&s->
gb);
359 int val2 = bytestream2_get_be16(&s->
gb);
360 int val3 = bytestream2_get_be16(&s->
gb);
361 color_flags_a = ((val1 & 0xFFF0) << 8) | (val2 >> 4);
362 color_flags_b = ((val3 & 0xFFF0) << 8) |
363 ((val1 & 0x0F) << 8) | ((val2 & 0x0F) << 4) | (val3 & 0x0F);
365 color_flags = color_flags_a;
368 block_ptr = row_ptr + pixel_ptr;
369 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
372 color_flags = color_flags_b;
375 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
376 pixel = color_table_index +
377 ((color_flags >> flag_mask) & 0x07);
381 block_ptr += row_inc;
389 n_blocks = (opcode & 0x0F) + 1;
392 block_ptr = row_ptr + pixel_ptr;
393 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
394 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
395 pixels[block_ptr++] = bytestream2_get_byte(&s->
gb);
397 block_ptr += row_inc;
426 void *
data,
int *got_frame,
430 int buf_size = avpkt->
size;