53 #define CHECK_BLOCK() \
54 if (total_blocks < 1) { \
55 av_log(s->avctx, AV_LOG_ERROR, \
56 "Block counter just went negative (this should not happen)\n"); \
57 return AVERROR_INVALIDDATA; \
60 #define ADVANCE_BLOCK() \
63 if (pixel_ptr >= width) \
66 row_ptr += stride * 4; \
73 int width =
s->avctx->width;
76 uint16_t colorA = 0, colorB;
88 if (bytestream2_peek_byte(&
s->gb) != 0xe1)
90 bytestream2_peek_byte(&
s->gb));
93 chunk_size = bytestream2_get_be32(&
s->gb) & 0x00FFFFFF;
98 "MOV chunk size %d != encoded chunk size %d\n",
104 total_blocks = ((
s->avctx->width + 3) / 4) * ((
s->avctx->height + 3) / 4);
111 pixels = (uint16_t *)
s->frame->data[0];
112 stride =
s->frame->linesize[0] / 2;
117 uint8_t opcode = bytestream2_get_byte(&
s->gb);
119 int n_blocks = (opcode & 0x1f) + 1;
122 if ((opcode & 0x80) == 0) {
123 colorA = (opcode << 8) | bytestream2_get_byte(&
s->gb);
125 if ((bytestream2_peek_byte(&
s->gb) & 0x80) != 0) {
134 n_blocks =
FFMIN(n_blocks, total_blocks);
136 switch (opcode & 0xe0) {
148 colorA = bytestream2_get_be16(&
s->gb);
151 block_ptr = row_ptr + pixel_ptr;
152 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
153 for (pixel_x = 0; pixel_x < 4; pixel_x++){
154 pixels[block_ptr] = colorA;
157 block_ptr += row_inc;
165 colorA = bytestream2_get_be16(&
s->gb);
167 colorB = bytestream2_get_be16(&
s->gb);
176 ta = (colorA >> 10) & 0x1F;
177 tb = (colorB >> 10) & 0x1F;
178 color4[1] |= ((11 * ta + 21 * tb) >> 5) << 10;
179 color4[2] |= ((21 * ta + 11 * tb) >> 5) << 10;
182 ta = (colorA >> 5) & 0x1F;
183 tb = (colorB >> 5) & 0x1F;
184 color4[1] |= ((11 * ta + 21 * tb) >> 5) << 5;
185 color4[2] |= ((21 * ta + 11 * tb) >> 5) << 5;
190 color4[1] |= ((11 * ta + 21 * tb) >> 5);
191 color4[2] |= ((21 * ta + 11 * tb) >> 5);
197 block_ptr = row_ptr + pixel_ptr;
198 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
199 uint8_t
index = bytestream2_get_byteu(&
s->gb);
200 for (pixel_x = 0; pixel_x < 4; pixel_x++){
201 uint8_t idx = (
index >> (2 * (3 - pixel_x))) & 0x03;
202 pixels[block_ptr] = color4[idx];
205 block_ptr += row_inc;
216 block_ptr = row_ptr + pixel_ptr;
217 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
218 for (pixel_x = 0; pixel_x < 4; pixel_x++){
220 if ((pixel_y != 0) || (pixel_x != 0))
221 colorA = bytestream2_get_be16u(&
s->gb);
222 pixels[block_ptr] = colorA;
225 block_ptr += row_inc;
233 " Skip remaining %d bytes of chunk data.\n", opcode,