54 #define CHECK_BLOCK() \
55 if (total_blocks < 1) { \
56 av_log(s->avctx, AV_LOG_ERROR, \
57 "Block counter just went negative (this should not happen)\n"); \
58 return AVERROR_INVALIDDATA; \
61 #define ADVANCE_BLOCK() \
64 if (pixel_ptr >= width) \
67 row_ptr += stride * 4; \
74 int width =
s->avctx->width;
77 uint16_t colorA = 0, colorB;
89 if (bytestream2_peek_byte(&
s->gb) != 0xe1)
91 bytestream2_peek_byte(&
s->gb));
94 chunk_size = bytestream2_get_be32(&
s->gb) & 0x00FFFFFF;
99 "MOV chunk size %d != encoded chunk size %d\n",
105 total_blocks = ((
s->avctx->width + 3) / 4) * ((
s->avctx->height + 3) / 4);
112 pixels = (uint16_t *)
s->frame->data[0];
113 stride =
s->frame->linesize[0] / 2;
118 uint8_t opcode = bytestream2_get_byte(&
s->gb);
120 int n_blocks = (opcode & 0x1f) + 1;
123 if ((opcode & 0x80) == 0) {
124 colorA = (opcode << 8) | bytestream2_get_byte(&
s->gb);
126 if ((bytestream2_peek_byte(&
s->gb) & 0x80) != 0) {
135 n_blocks =
FFMIN(n_blocks, total_blocks);
137 switch (opcode & 0xe0) {
149 colorA = bytestream2_get_be16(&
s->gb);
152 block_ptr = row_ptr + pixel_ptr;
153 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
154 for (pixel_x = 0; pixel_x < 4; pixel_x++){
155 pixels[block_ptr] = colorA;
158 block_ptr += row_inc;
166 colorA = bytestream2_get_be16(&
s->gb);
169 colorB = bytestream2_get_be16(&
s->gb);
178 ta = (colorA >> 10) & 0x1F;
179 tb = (colorB >> 10) & 0x1F;
180 color4[1] |= ((11 * ta + 21 * tb) >> 5) << 10;
181 color4[2] |= ((21 * ta + 11 * tb) >> 5) << 10;
184 ta = (colorA >> 5) & 0x1F;
185 tb = (colorB >> 5) & 0x1F;
186 color4[1] |= ((11 * ta + 21 * tb) >> 5) << 5;
187 color4[2] |= ((21 * ta + 11 * tb) >> 5) << 5;
192 color4[1] |= ((11 * ta + 21 * tb) >> 5);
193 color4[2] |= ((21 * ta + 11 * tb) >> 5);
199 block_ptr = row_ptr + pixel_ptr;
200 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
201 uint8_t
index = bytestream2_get_byteu(&
s->gb);
202 for (pixel_x = 0; pixel_x < 4; pixel_x++){
203 uint8_t idx = (
index >> (2 * (3 - pixel_x))) & 0x03;
204 pixels[block_ptr] = color4[idx];
207 block_ptr += row_inc;
218 block_ptr = row_ptr + pixel_ptr;
219 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
220 for (pixel_x = 0; pixel_x < 4; pixel_x++){
222 if ((pixel_y != 0) || (pixel_x != 0))
223 colorA = bytestream2_get_be16u(&
s->gb);
224 pixels[block_ptr] = colorA;
227 block_ptr += row_inc;
235 " Skip remaining %d bytes of chunk data.\n", opcode,