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 < !!n_blocks) \
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;
425 void *
data,
int *data_size,
428 const uint8_t *buf = avpkt->
data;
429 int buf_size = avpkt->
size;
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
static av_cold int smc_decode_init(AVCodecContext *avctx)
#define FF_BUFFER_HINTS_VALID
int buffer_hints
codec suggestion on buffer type if != 0
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
int(* reget_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of a frame to get cr buffer for it.
static int smc_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
unsigned char color_quads[COLORS_PER_TABLE *CQUAD]
static int init(AVCodecParserContext *s)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
unsigned char color_pairs[COLORS_PER_TABLE *CPAIR]
const uint8_t * buffer_end
int width
picture width / height.
struct AVFrame AVFrame
Audio Video Frame.
#define FF_BUFFER_HINTS_REUSABLE
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
static av_cold int smc_decode_end(AVCodecContext *avctx)
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
unsigned char color_octets[COLORS_PER_TABLE *COCTET]
main external API structure.
static void close(AVCodecParserContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const uint8_t * buffer_start
#define FF_BUFFER_HINTS_PRESERVE
int palette_has_changed
Tell user application that palette has changed from previous frame.
#define FF_BUFFER_HINTS_READABLE
static void smc_decode_stream(SmcContext *s)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
8 bit with PIX_FMT_RGB32 palette
#define GET_BLOCK_COUNT()
struct SmcContext SmcContext
void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.