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')
76 for (
int y = 0; y < avctx->
height; y++) {
77 memset(dst, 0, avctx->
width *
s->bpp);
88 for (
int y = 0; y < avctx->
height; y++) {
89 memcpy(dstp, srcp,
s->stride);
90 srcp +=
src->linesize[0];
122 if (bytestream2_peek_le32(gb) != 0x65) {
123 if (!
s->frame2->data[0] || !
s->frame1->data[0])
134 w = bytestream2_get_le32(gb);
135 h = bytestream2_get_le32(gb);
137 fmt = bytestream2_get_le16(gb);
144 case 16:
s->stride =
w * 2;
147 case 32:
s->stride =
w * 4;
165 uint32_t *pal = (uint32_t *)
s->frame2->data[1];
167 for (
int i = 0;
i < 256;
i++)
168 pal[
i] = bytestream2_get_le32(gb) | 0xFF000000u;
175 unsigned size,
unsigned uncompressed_size)
181 zret = inflateReset(&
s->zstream);
194 s->zstream.next_out =
s->delta;
195 s->zstream.avail_out =
s->delta_size;
197 zret =
inflate(&
s->zstream, Z_FINISH);
198 if (zret != Z_STREAM_END) {
200 "Inflate failed with return code: %d.\n", zret);
213 unsigned pos, compression, nb_moves;
214 unsigned uncompressed_size;
219 nb_moves = bytestream2_get_le32(gb);
221 compression = bytestream2_get_le32(gb);
223 if (nb_moves > INT32_MAX / 16 || nb_moves > avctx->
width * avctx->
height)
226 uncompressed_size = 16 * nb_moves;
228 if (compression == 1) {
235 }
else if (compression == 0) {
238 }
else if (compression == 2) {
248 for (
int i = 0;
i < nb_moves;
i++) {
249 int type, start_x, start_y, end_x, end_y, mov_x, mov_y;
253 type = bytestream2_get_le16(&
mc);
254 start_x = bytestream2_get_le16(&
mc);
255 start_y = bytestream2_get_le16(&
mc);
256 end_x = bytestream2_get_le16(&
mc);
257 end_y = bytestream2_get_le16(&
mc);
258 mov_x = bytestream2_get_le16(&
mc);
259 mov_y = bytestream2_get_le16(&
mc);
262 if (start_x >= avctx->
width || start_y >= avctx->
height ||
268 if (start_x >= end_x || start_y >= end_y)
277 if (!
s->frame2->data[0] || !
s->frame1->data[0])
280 b1 =
s->frame1->data[0] +
s->frame1->linesize[0] * (start_y +
h - 1) + start_x *
s->bpp;
281 b2 =
s->frame2->data[0] +
s->frame2->linesize[0] * (start_y +
h - 1) + start_x *
s->bpp;
282 e2 =
s->frame2->data[0] +
s->frame2->linesize[0] * (mov_y +
h - 1) + mov_x *
s->bpp;
285 for (
int j = 0; j <
h; j++) {
286 memcpy(
b1,
b2,
w *
s->bpp);
287 b1 -=
s->frame1->linesize[0];
288 b2 -=
s->frame2->linesize[0];
290 }
else if (
type == 1) {
291 for (
int j = 0; j <
h; j++) {
292 memset(
b2, 0,
w *
s->bpp);
293 b2 -=
s->frame2->linesize[0];
295 }
else if (
type == 0) {
303 for (
int j = 0; j <
h; j++) {
304 memcpy(
buffer + j *
w *
s->bpp, e2,
w *
s->bpp);
305 e2 -=
s->frame2->linesize[0];
308 for (
int j = 0; j <
h; j++) {
310 b2 -=
s->frame2->linesize[0];
323 if (cx >= w * s->bpp) { \
326 b1 -= s->frame1->linesize[0]; \
327 b2 -= s->frame2->linesize[0]; \
337 unsigned uncompressed_size,
pos;
339 int ret, cx, cy, compression;
344 uncompressed_size = bytestream2_get_le32(gb);
345 x = bytestream2_get_le32(gb);
346 y = bytestream2_get_le32(gb);
347 w = bytestream2_get_le32(gb);
348 h = bytestream2_get_le32(gb);
358 compression = bytestream2_get_le32(gb);
360 if (compression == 1) {
361 if (
w *
h *
s->bpp * 3 < uncompressed_size)
367 }
else if (compression == 0) {
372 }
else if (compression == 2) {
379 if (!
s->frame2->data[0] || !
s->frame1->data[0])
382 b1 =
s->frame1->data[0] +
s->frame1->linesize[0] * (y +
h - 1) + x *
s->bpp;
383 b2 =
s->frame2->data[0] +
s->frame2->linesize[0] * (y +
h - 1) + x *
s->bpp;
386 int type = bytestream2_get_byte(&
dc);
387 int len = bytestream2_get_byte(&
dc);
392 while (
len > 0 && cy > 0) {
398 while (
len > 0 && cy > 0) {
409 while (
len > 0 && cy > 0) {
410 fill = bytestream2_get_byte(&
dc);
418 fill = bytestream2_get_byte(&
dc);
419 while (
len > 0 && cy > 0) {
427 fill = bytestream2_get_le32(&
dc);
428 while (
len > 0 && cy > 0) {
436 while (
len > 0 && cy > 0) {
442 while (
len > 0 && cy > 0) {
454 while (
len > 0 && cy > 0) {
455 fill = bytestream2_get_le32(&
dc);
483 if (bytestream2_peek_le32(gb) == 0x65) {
489 if (!
s->frame2->data[0])
492 zret = inflateReset(&
s->zstream);
501 dst =
s->frame2->data[0] + (avctx->
height - 1) *
s->frame2->linesize[0];
503 s->zstream.next_out = dst;
504 s->zstream.avail_out =
s->stride;
506 zret =
inflate(&
s->zstream, Z_SYNC_FLUSH);
507 if (zret != Z_OK && zret != Z_STREAM_END) {
509 "Inflate failed with return code: %d.\n", zret);
513 dst -=
s->frame2->linesize[0];
516 dst =
s->frame1->data[0] + (avctx->
height - 1) *
s->frame1->linesize[0];
518 s->zstream.next_out = dst;
519 s->zstream.avail_out =
s->stride;
521 zret =
inflate(&
s->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->frame1->linesize[0];
541 unsigned w,
h,
pos, uncompressed_size;
546 w = bytestream2_get_le32(gb);
547 h = bytestream2_get_le32(gb);
549 uncompressed_size = bytestream2_get_le32(gb);
554 if (uncompressed_size != 3 *
w *
h)
566 memcpy(
s->cursor,
s->delta, uncompressed_size);
585 s->cursor_x = bytestream2_get_le32(gb);
586 s->cursor_y = bytestream2_get_le32(gb);
601 if (
s->cursor_x >= avctx->
width ||
s->cursor_y >= avctx->
height)
604 if (
s->cursor_x +
s->cursor_w > avctx->
width ||
605 s->cursor_y +
s->cursor_h > avctx->
height)
609 pal =
s->frame->data[1];
610 for (
int i = 0;
i <
s->cursor_h;
i++) {
611 for (
int j = 0; j <
s->cursor_w; j++) {
612 int cr =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 0];
613 int cg =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 1];
614 int cb =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 2];
619 if (
cr ==
s->cursor[0] && cg ==
s->cursor[1] &&
cb ==
s->cursor[2])
622 dst =
s->frame->data[0] +
s->frame->linesize[0] * (
s->cursor_y +
i) + (
s->cursor_x + j);
623 for (
int k = 0; k < 256; k++) {
624 int pr = pal[k * 4 + 0];
625 int pg = pal[k * 4 + 1];
626 int pb = pal[k * 4 + 2];
638 for (
int i = 0;
i <
s->cursor_h;
i++) {
639 for (
int j = 0; j <
s->cursor_w; j++) {
640 int cr =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 0];
641 int cg =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 1];
642 int cb =
s->cursor[3 *
s->cursor_w * (
s->cursor_h -
i - 1) + 3 * j + 2];
644 if (
cr ==
s->cursor[0] && cg ==
s->cursor[1] &&
cb ==
s->cursor[2])
647 cr >>= 3; cg >>=3;
cb >>= 3;
648 dst =
s->frame->data[0] +
s->frame->linesize[0] * (
s->cursor_y +
i) + 2 * (
s->cursor_x + j);
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 dst =
s->frame->data[0] +
s->frame->linesize[0] * (
s->cursor_y +
i) + 4 * (
s->cursor_x + j);
672 void *
data,
int *got_frame,
682 if (bytestream2_peek_le32(gb) ==
EMPT)
693 type = bytestream2_get_le32(gb);
696 type = bytestream2_get_le32(gb);
699 size = bytestream2_get_le32(gb);
731 if (!
s->frame2->data[0] || !
s->frame1->data[0])
739 memcpy(
s->frame->data[1],
s->frame2->data[1], 1024);
743 s->frame->key_frame = intra;
756 s->zstream.zalloc = Z_NULL;
757 s->zstream.zfree = Z_NULL;
758 s->zstream.opaque = Z_NULL;
759 zret = inflateInit(&
s->zstream);
767 if (!
s->frame1 || !
s->frame2)
783 inflateEnd(&
s->zstream);
static void flush(AVCodecContext *avctx)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> dc
simple assert() macros that are a bit more flexible than ISO C assert().
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
static av_always_inline int bytestream2_get_bytes_left(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(GetByteContext *g)
#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.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#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.
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
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#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_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 int decode_kfrm(AVCodecContext *avctx, const AVPacket *avpkt, unsigned size)
static const AVOption options[]
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 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 decode_flush(AVCodecContext *avctx)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
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.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
This structure stores compressed data.
#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)