36 #define CDTOONS_HEADER_SIZE 44 37 #define CDTOONS_MAX_SPRITES 1200 67 int skip = 0, to_skip, x;
69 if (dst_x + width > avctx->
width)
70 width = avctx->
width - dst_x;
71 if (dst_y + height > avctx->
height)
72 height = avctx->
height - dst_y;
82 for (
int y = 0; y <
height; y++) {
87 line_size = bytestream_get_be16(&data);
88 if (end - data < line_size)
90 next_line = data + line_size;
98 while (x < width - skip) {
105 val = bytestream_get_byte(&data);
107 size = (
int)(val & 0x7F) + 1;
110 if (to_skip >= size) {
117 if (next_line - data < step)
121 }
else if (to_skip) {
124 if (next_line - data < to_skip)
131 if (x + size >= width - skip)
132 size = width - skip - x;
136 if (next_line - data < size)
138 memcpy(dest + x, data, size);
144 memset(dest + x, color, size);
159 const int buf_size = avpkt->
size;
162 uint16_t sprite_count, sprite_offset;
167 int saw_embedded_sprites = 0;
178 frame_id = bytestream_get_be16(&buf);
181 background_color = bytestream_get_byte(&buf);
184 sprite_count = bytestream_get_be16(&buf);
185 sprite_offset = bytestream_get_be16(&buf);
187 referenced_count = bytestream_get_byte(&buf);
189 palette_id = bytestream_get_be16(&buf);
190 palette_set = bytestream_get_byte(&buf);
193 if (sprite_offset > buf_size)
197 buf = avpkt->
data + sprite_offset;
198 while (sprite_count--) {
205 sprite_id = bytestream_get_be16(&buf);
208 "Sprite ID %d is too high.\n", sprite_id);
213 "Sprite ID %d is a duplicate.\n", sprite_id);
217 c->
sprites[sprite_id].
flags = bytestream_get_be16(&buf);
218 size = bytestream_get_be32(&buf);
221 "Sprite only has %d bytes of data.\n", size);
231 if (size > buf_size || buf + size > eod)
250 tag = bytestream_get_be32(&buf);
251 size = bytestream_get_be32(&buf);
252 if (tag ==
MKBETAG(
'D',
'i',
'f',
'f')) {
254 if (buf + 10 > eod) {
258 diff_count = bytestream_get_be16(&buf);
260 for (
int i = 0;
i < diff_count;
i++) {
264 if (buf + 16 > eod) {
269 top = bytestream_get_be16(&buf);
270 left = bytestream_get_be16(&buf);
272 diff_size = bytestream_get_be32(&buf);
273 width = bytestream_get_be16(&buf);
274 height = bytestream_get_be16(&buf);
275 if (diff_size < 8 || diff_size - 4 > eod - buf) {
280 left, top, width, height)) {
283 buf += diff_size - 4;
285 saw_embedded_sprites = 1;
288 if (size < 8 || size - 8 > eod - buf) {
289 av_log(avctx,
AV_LOG_WARNING,
"Ran out of data for ignored entry (size %X, %d left).\n", size, (
int)(eod - buf));
297 if (saw_embedded_sprites)
302 eod = avpkt->
data + sprite_offset;
303 for (
int i = 0;
i < referenced_count;
i++) {
306 int16_t top, left, right;
308 if (buf + 10 > eod) {
313 sprite_id = bytestream_get_be16(&buf);
314 top = bytestream_get_be16(&buf);
315 left = bytestream_get_be16(&buf);
317 right = bytestream_get_be16(&buf);
319 if ((
i == 0) && (sprite_id == 0)) {
321 memset(c->
frame->
data[0], background_color,
329 "Sprite ID %d is too high.\n", sprite_id);
344 height = bytestream_get_be16(&block_data);
345 width = bytestream_get_be16(&block_data);
349 left, top, width, height)) {
354 if (palette_id && (palette_id != c->
last_pal_id)) {
357 "Palette ID %d is too high.\n", palette_id);
363 "Palette ID %d is missing.\n", palette_id);
368 "Palette ID %d is wrong size (%d).\n",
375 for (
int i = 0;
i < 256;
i++) {
379 g = *(palette_data + 2);
380 b = *(palette_data + 4);
381 c->
pal[
i] = (0xFF
U << 24) | (r << 16) | (g << 8) | b;
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
static void flush(AVCodecContext *avctx)
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_cold int init(AVCodecContext *avctx)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
static av_cold int cdtoons_decode_end(AVCodecContext *avctx)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Macro definitions for various function/variable attributes.
CDToonsSprite sprites[CDTOONS_MAX_SPRITES]
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
8 bits with AV_PIX_FMT_RGB32 palette
#define CDTOONS_HEADER_SIZE
static av_cold int end(AVCodecContext *avctx)
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
#define i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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. ...
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available...
const char * name
Name of the codec implementation.
AVCodec ff_cdtoons_decoder
#define CDTOONS_MAX_SPRITES
common internal API header
int width
picture width / height.
static void cdtoons_flush(AVCodecContext *avctx)
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
int palette_has_changed
Tell user application that palette has changed from previous frame.
uint32_t pal[256]
The currently-used palette data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int cdtoons_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
common internal api header.
#define MKBETAG(a, b, c, d)
uint16_t last_pal_id
The index of the active palette sprite.
static int cdtoons_render_sprite(AVCodecContext *avctx, const uint8_t *data, uint32_t data_size, int dst_x, int dst_y, int width, int height)
static double val(void *priv, double ch)
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static av_cold int cdtoons_decode_init(AVCodecContext *avctx)