44 #define COLORS_PER_TABLE 256
61 #define GET_BLOCK_COUNT() \
62 (opcode & 0x10) ? (1 + bytestream2_get_byte(&s->gb)) : 1 + (opcode & 0x0F);
64 #define ADVANCE_BLOCK() \
67 if (pixel_ptr >= width) \
70 row_ptr += stride * 4; \
73 if (total_blocks < !!n_blocks) \
75 av_log(s->avctx, AV_LOG_INFO, "warning: block counter just went negative (this should not happen)\n"); \
90 unsigned int color_flags;
91 unsigned int color_flags_a;
92 unsigned int color_flags_b;
93 unsigned int flag_mask;
100 int pixel_x, pixel_y;
101 int row_inc = stride - 4;
104 int prev_block_ptr1, prev_block_ptr2;
107 int color_table_index;
110 int color_pair_index = 0;
111 int color_quad_index = 0;
112 int color_octet_index = 0;
118 chunk_size = bytestream2_get_be24(&s->
gb);
119 if (chunk_size != buf_size)
120 av_log(s->
avctx,
AV_LOG_INFO,
"warning: MOV chunk size != encoded chunk size (%d != %d); using MOV chunk size\n",
121 chunk_size, buf_size);
123 chunk_size = buf_size;
127 while (total_blocks) {
130 if (row_ptr >= image_size) {
132 row_ptr, image_size);
140 opcode = bytestream2_get_byte(&s->
gb);
141 switch (opcode & 0xF0) {
157 if ((row_ptr == 0) && (pixel_ptr == 0)) {
168 prev_block_ptr1 = row_ptr + pixel_ptr - 4;
171 block_ptr = row_ptr + pixel_ptr;
172 prev_block_ptr = prev_block_ptr1;
173 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
174 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
175 pixels[block_ptr++] = pixels[prev_block_ptr++];
177 block_ptr += row_inc;
178 prev_block_ptr += row_inc;
191 if ((row_ptr == 0) && (pixel_ptr < 2 * 4)) {
192 av_log(s->
avctx,
AV_LOG_INFO,
"encountered repeat block opcode (%02X) but not enough blocks rendered yet\n",
199 prev_block_ptr1 = (row_ptr - s->
avctx->
width * 4) +
201 else if (pixel_ptr == 4)
202 prev_block_ptr1 = (row_ptr - s->
avctx->
width * 4) + row_inc;
204 prev_block_ptr1 = row_ptr + pixel_ptr - 4 * 2;
207 prev_block_ptr2 = (row_ptr - s->
avctx->
width * 4) + row_inc;
209 prev_block_ptr2 = row_ptr + pixel_ptr - 4;
213 block_ptr = row_ptr + pixel_ptr;
215 prev_block_ptr = prev_block_ptr2;
217 prev_block_ptr = prev_block_ptr1;
218 prev_block_flag = !prev_block_flag;
220 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
221 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
222 pixels[block_ptr++] = pixels[prev_block_ptr++];
224 block_ptr += row_inc;
225 prev_block_ptr += row_inc;
235 pixel = bytestream2_get_byte(&s->
gb);
238 block_ptr = row_ptr + pixel_ptr;
239 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
240 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
241 pixels[block_ptr++] =
pixel;
243 block_ptr += row_inc;
252 n_blocks = (opcode & 0x0F) + 1;
255 if ((opcode & 0xF0) == 0x80) {
258 for (i = 0; i <
CPAIR; i++) {
259 pixel = bytestream2_get_byte(&s->
gb);
260 color_table_index = CPAIR * color_pair_index + i;
264 color_table_index = CPAIR * color_pair_index;
268 color_pair_index = 0;
270 color_table_index =
CPAIR * bytestream2_get_byte(&s->
gb);
273 color_flags = bytestream2_get_be16(&s->
gb);
275 block_ptr = row_ptr + pixel_ptr;
276 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
277 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
278 if (color_flags & flag_mask)
279 pixel = color_table_index + 1;
281 pixel = color_table_index;
285 block_ptr += row_inc;
294 n_blocks = (opcode & 0x0F) + 1;
297 if ((opcode & 0xF0) == 0xA0) {
300 for (i = 0; i <
CQUAD; i++) {
301 pixel = bytestream2_get_byte(&s->
gb);
302 color_table_index = CQUAD * color_quad_index + i;
306 color_table_index = CQUAD * color_quad_index;
310 color_quad_index = 0;
312 color_table_index =
CQUAD * bytestream2_get_byte(&s->
gb);
315 color_flags = bytestream2_get_be32(&s->
gb);
318 block_ptr = row_ptr + pixel_ptr;
319 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
320 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
321 pixel = color_table_index +
322 ((color_flags >> flag_mask) & 0x03);
326 block_ptr += row_inc;
335 n_blocks = (opcode & 0x0F) + 1;
338 if ((opcode & 0xF0) == 0xC0) {
341 for (i = 0; i <
COCTET; i++) {
342 pixel = bytestream2_get_byte(&s->
gb);
343 color_table_index = COCTET * color_octet_index + i;
347 color_table_index = COCTET * color_octet_index;
351 color_octet_index = 0;
353 color_table_index =
COCTET * bytestream2_get_byte(&s->
gb);
363 int val1 = bytestream2_get_be16(&s->
gb);
364 int val2 = bytestream2_get_be16(&s->
gb);
365 int val3 = bytestream2_get_be16(&s->
gb);
366 color_flags_a = ((val1 & 0xFFF0) << 8) | (val2 >> 4);
367 color_flags_b = ((val3 & 0xFFF0) << 8) |
368 ((val1 & 0x0F) << 8) | ((val2 & 0x0F) << 4) | (val3 & 0x0F);
370 color_flags = color_flags_a;
373 block_ptr = row_ptr + pixel_ptr;
374 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
377 color_flags = color_flags_b;
380 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
381 pixel = color_table_index +
382 ((color_flags >> flag_mask) & 0x07);
386 block_ptr += row_inc;
394 n_blocks = (opcode & 0x0F) + 1;
397 block_ptr = row_ptr + pixel_ptr;
398 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
399 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
400 pixels[block_ptr++] = bytestream2_get_byte(&s->
gb);
402 block_ptr += row_inc;
432 void *
data,
int *got_frame,
436 int buf_size = avpkt->
size;
443 if (total_blocks / 1024 > avpkt->
size)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static av_cold int smc_decode_init(AVCodecContext *avctx)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static av_cold int init(AVCodecContext *avctx)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int smc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
unsigned char color_quads[COLORS_PER_TABLE *CQUAD]
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
8 bits with AV_PIX_FMT_RGB32 palette
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static av_always_inline int bytestream2_size(GetByteContext *g)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette...
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
const char * name
Name of the codec implementation.
unsigned char color_pairs[COLORS_PER_TABLE *CPAIR]
int width
picture width / height.
static av_cold int smc_decode_end(AVCodecContext *avctx)
#define AV_LOG_INFO
Standard information.
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
unsigned char color_octets[COLORS_PER_TABLE *COCTET]
main external API structure.
int palette_has_changed
Tell user application that palette has changed from previous frame.
static void smc_decode_stream(SmcContext *s)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
GLint GLenum GLboolean GLsizei stride
common internal api header.
#define GET_BLOCK_COUNT()
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.