37#define KBND MKTAG('K', 'B', 'N', 'D')
38#define FINT MKTAG('F', 'I', 'N', 'T')
39#define INIT MKTAG('I', 'N', 'I', 'T')
40#define BNDL MKTAG('B', 'N', 'D', 'L')
41#define KFRM MKTAG('K', 'F', 'R', 'M')
42#define DLTA MKTAG('D', 'L', 'T', 'A')
43#define MOUS MKTAG('M', 'O', 'U', 'S')
44#define MPOS MKTAG('M', 'P', 'O', 'S')
45#define MOVE MKTAG('M', 'O', 'V', 'E')
46#define EMPT MKTAG('E', 'M', 'P', 'T')
78 for (
int y = 0; y < avctx->
height; y++) {
87 uint8_t *srcp =
src->data[0];
88 uint8_t *dstp =
dst->data[0];
90 for (
int y = 0; y < avctx->
height; y++) {
91 memcpy(dstp, srcp,
s->stride);
92 srcp +=
src->linesize[0];
93 dstp +=
dst->linesize[0];
124 if (bytestream2_peek_le32(gb) != 0x65) {
125 if (!
s->frame2->data[0] || !
s->frame1->data[0])
136 w = bytestream2_get_le32(gb);
137 h = bytestream2_get_le32(gb);
139 fmt = bytestream2_get_le16(gb);
146 case 16:
s->stride =
w * 2;
149 case 32:
s->stride =
w * 4;
167 uint32_t *pal = (uint32_t *)
s->frame2->data[1];
169 for (
int i = 0;
i < 256;
i++)
170 pal[
i] = bytestream2_get_le32(gb) | 0xFF000000u;
177 unsigned size,
unsigned uncompressed_size)
180 z_stream *
const zstream = &
s->zstream.zstream;
184 zret = inflateReset(zstream);
197 zstream->next_out =
s->delta;
198 zstream->avail_out =
s->delta_size;
200 zret =
inflate(zstream, Z_FINISH);
201 if (zret != Z_STREAM_END) {
203 "Inflate failed with return code: %d.\n", zret);
216 unsigned pos, compression, nb_moves;
217 unsigned uncompressed_size;
222 nb_moves = bytestream2_get_le32(gb);
224 compression = bytestream2_get_le32(gb);
226 if (nb_moves > INT32_MAX / 16 || nb_moves > avctx->
width * avctx->
height)
229 uncompressed_size = 16 * nb_moves;
231 if (compression == 1) {
238 }
else if (compression == 0) {
241 }
else if (compression == 2) {
251 for (
int i = 0;
i < nb_moves;
i++) {
252 int type, start_x, start_y, end_x, end_y, mov_x, mov_y;
253 uint8_t *e2, *
b1, *
b2;
256 type = bytestream2_get_le16(&
mc);
257 start_x = bytestream2_get_le16(&
mc);
258 start_y = bytestream2_get_le16(&
mc);
259 end_x = bytestream2_get_le16(&
mc);
260 end_y = bytestream2_get_le16(&
mc);
261 mov_x = bytestream2_get_le16(&
mc);
262 mov_y = bytestream2_get_le16(&
mc);
265 if (start_x >= avctx->
width || start_y >= avctx->
height ||
271 if (start_x >= end_x || start_y >= end_y)
280 if (!
s->frame2->data[0] || !
s->frame1->data[0])
283 b1 =
s->frame1->data[0] +
s->frame1->linesize[0] * (start_y +
h - 1) + start_x *
s->bpp;
284 b2 =
s->frame2->data[0] +
s->frame2->linesize[0] * (start_y +
h - 1) + start_x *
s->bpp;
285 e2 =
s->frame2->data[0] +
s->frame2->linesize[0] * (mov_y +
h - 1) + mov_x *
s->bpp;
288 for (
int j = 0; j <
h; j++) {
289 memcpy(
b1,
b2,
w *
s->bpp);
290 b1 -=
s->frame1->linesize[0];
291 b2 -=
s->frame2->linesize[0];
293 }
else if (
type == 1) {
294 for (
int j = 0; j <
h; j++) {
295 memset(
b2, 0,
w *
s->bpp);
296 b2 -=
s->frame2->linesize[0];
298 }
else if (
type == 0) {
300 uint8_t *
buffer =
s->mv_scratch;
304 for (
int j = 0; j <
h; j++) {
305 memcpy(
buffer + j *
w *
s->bpp, e2,
w *
s->bpp);
306 e2 -=
s->frame2->linesize[0];
309 for (
int j = 0; j <
h; j++) {
311 b2 -=
s->frame2->linesize[0];
323static inline int dlta_room(
unsigned cx,
unsigned w,
unsigned bpp,
unsigned need)
325 return cx + need <=
w * bpp;
329 if (cx >= w * s->bpp) { \
332 b1 -= s->frame1->linesize[0]; \
333 b2 -= s->frame2->linesize[0]; \
343 unsigned uncompressed_size,
pos;
345 int ret, cx, cy, compression;
350 uncompressed_size = bytestream2_get_le32(gb);
351 x = bytestream2_get_le32(gb);
352 y = bytestream2_get_le32(gb);
353 w = bytestream2_get_le32(gb);
354 h = bytestream2_get_le32(gb);
364 compression = bytestream2_get_le32(gb);
366 if (compression == 1) {
367 if (
w *
h *
s->bpp * 3 < uncompressed_size)
373 }
else if (compression == 0) {
378 }
else if (compression == 2) {
385 if (!
s->frame2->data[0] || !
s->frame1->data[0])
388 b1 =
s->frame1->data[0] +
s->frame1->linesize[0] * (int)(y +
h - 1) + ((int)x) *
s->bpp;
389 b2 =
s->frame2->data[0] +
s->frame2->linesize[0] * (int)(y +
h - 1) + ((int)x) *
s->bpp;
392 int type = bytestream2_get_byte(&dc);
393 int len = bytestream2_get_byte(&dc);
398 while (
len > 0 && cy > 0) {
404 while (
len > 0 && cy > 0) {
415 while (
len > 0 && cy > 0) {
416 fill = bytestream2_get_byte(&dc);
424 fill = bytestream2_get_byte(&dc);
425 while (
len > 0 && cy > 0) {
435 fill = bytestream2_get_le32(&dc);
436 while (
len > 0 && cy > 0) {
446 while (
len > 0 && cy > 0) {
452 while (
len > 0 && cy > 0) {
466 while (
len > 0 && cy > 0) {
467 fill = bytestream2_get_le32(&dc);
491 z_stream *
const zstream = &
s->zstream.zstream;
498 if (bytestream2_peek_le32(gb) == 0x65) {
504 if (!
s->frame2->data[0])
507 zret = inflateReset(zstream);
516 dst =
s->frame2->data[0] + (avctx->
height - 1) *
s->frame2->linesize[0];
517 for (
int i = 0;
i < avctx->
height;
i++) {
518 zstream->next_out =
dst;
519 zstream->avail_out =
s->stride;
521 zret =
inflate(zstream, Z_SYNC_FLUSH);
522 if (zret != Z_OK && zret != Z_STREAM_END) {
524 "Inflate failed with return code: %d.\n", zret);
528 dst -=
s->frame2->linesize[0];
531 dst =
s->frame1->data[0] + (avctx->
height - 1) *
s->frame1->linesize[0];
532 for (
int i = 0;
i < avctx->
height;
i++) {
533 zstream->next_out =
dst;
534 zstream->avail_out =
s->stride;
536 zret =
inflate(zstream, Z_SYNC_FLUSH);
537 if (zret != Z_OK && zret != Z_STREAM_END) {
539 "Inflate failed with return code: %d.\n", zret);
543 dst -=
s->frame1->linesize[0];
556 unsigned w,
h,
pos, uncompressed_size;
561 w = bytestream2_get_le32(gb);
562 h = bytestream2_get_le32(gb);
564 uncompressed_size = bytestream2_get_le32(gb);
569 if (uncompressed_size != 3 *
w *
h)
581 memcpy(
s->cursor,
s->delta, uncompressed_size);
600 s->cursor_x = bytestream2_get_le32(gb);
601 s->cursor_y = bytestream2_get_le32(gb);
616 if (
s->cursor_x >= avctx->
width ||
s->cursor_y >= avctx->
height)
619 if (
s->cursor_x +
s->cursor_w > avctx->
width ||
620 s->cursor_y +
s->cursor_h > avctx->
height)
624 pal =
s->frame->data[1];
625 for (
int i = 0;
i <
s->cursor_h;
i++) {
626 for (
int j = 0; j <
s->cursor_w; j++) {
627 int cr =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 0];
628 int cg =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 1];
629 int cb =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 2];
634 if (
cr ==
s->cursor[0] && cg ==
s->cursor[1] &&
cb ==
s->cursor[2])
637 dst =
s->frame->data[0] +
s->frame->linesize[0] * (int)(
s->cursor_y +
i) + (int)(
s->cursor_x + j);
638 for (
int k = 0; k < 256; k++) {
639 int pr = pal[k * 4 + 0];
640 int pg = pal[k * 4 + 1];
641 int pb = pal[k * 4 + 2];
653 for (
int i = 0;
i <
s->cursor_h;
i++) {
654 for (
int j = 0; j <
s->cursor_w; j++) {
655 int cr =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 0];
656 int cg =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 1];
657 int cb =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 2];
659 if (
cr ==
s->cursor[0] && cg ==
s->cursor[1] &&
cb ==
s->cursor[2])
662 cr >>= 3; cg >>=3;
cb >>= 3;
663 dst =
s->frame->data[0] +
s->frame->linesize[0] * (int)(
s->cursor_y +
i) + 2 * (
s->cursor_x + j);
668 for (
int i = 0;
i <
s->cursor_h;
i++) {
669 for (
int j = 0; j <
s->cursor_w; j++) {
670 int cr =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 0];
671 int cg =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 1];
672 int cb =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 2];
674 if (
cr ==
s->cursor[0] && cg ==
s->cursor[1] &&
cb ==
s->cursor[2])
677 dst =
s->frame->data[0] +
s->frame->linesize[0] * (int)(
s->cursor_y +
i) + 4 * (
s->cursor_x + j);
695 if (bytestream2_peek_le32(gb) ==
EMPT)
706 type = bytestream2_get_le32(gb);
709 type = bytestream2_get_le32(gb);
712 size = bytestream2_get_le32(gb);
745 if (!
s->frame2->data[0] || !
s->frame1->data[0])
753 memcpy(
s->frame->data[1],
s->frame2->data[1], 1024);
774 if (!
s->frame1 || !
s->frame2)
789 s->mv_scratch_size = 0;
811 .class_name =
"rasc decoder",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static av_cold void decode_flush(AVCodecContext *avctx)
const FFCodec ff_rasc_decoder
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_always_inline int bytestream2_tell(const GetByteContext *g)
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
int(* init)(AVBSFContext *ctx)
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
#define AV_OPT_FLAG_VIDEO_PARAM
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
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...
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
#define LIBAVUTIL_VERSION_INT
static av_cold int decode_init(AVCodecContext *avctx)
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
static av_cold int decode_close(AVCodecContext *avctx)
Memory handling functions.
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
static int decode_mpos(AVCodecContext *avctx, const AVPacket *avpkt, unsigned size)
static int decode_move(AVCodecContext *avctx, const AVPacket *avpkt, unsigned size)
static av_cold void decode_flush(AVCodecContext *avctx)
static int decode_kfrm(AVCodecContext *avctx, const AVPacket *avpkt, unsigned size)
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static av_cold int decode_close(AVCodecContext *avctx)
static int init_frames(AVCodecContext *avctx)
static const AVClass rasc_decoder_class
static int decode_mous(AVCodecContext *avctx, const AVPacket *avpkt, unsigned size)
static av_cold int decode_init(AVCodecContext *avctx)
static int dlta_room(unsigned cx, unsigned w, unsigned bpp, unsigned need)
static void copy_plane(AVCodecContext *avctx, AVFrame *src, AVFrame *dst)
static int decode_fint(AVCodecContext *avctx, const AVPacket *avpkt, unsigned size)
static int decode_zlib(AVCodecContext *avctx, const AVPacket *avpkt, unsigned size, unsigned uncompressed_size)
static void clear_plane(AVCodecContext *avctx, AVFrame *frame)
static void draw_cursor(AVCodecContext *avctx)
static int decode_dlta(AVCodecContext *avctx, const AVPacket *avpkt, unsigned size)
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
unsigned int mv_scratch_size
#define avpriv_request_sample(...)
static double cr(void *priv, double x, double y)
static double cb(void *priv, double x, double y)
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
static double b1(void *priv, double x, double y)
static double b2(void *priv, double x, double y)
void ff_inflate_end(FFZStream *zstream)
Wrapper around inflateEnd().
int ff_inflate_init(FFZStream *zstream, void *logctx)
Wrapper around inflateInit().