41#define ZMBV_KEYFRAME 1
42#define ZMBV_DELTAPAL 2
86 uint8_t *
src =
c->decomp_buf;
87 uint8_t *output, *
prev;
90 int d, dx, dy, bw2, bh2;
99 for (
i = 0;
i < 768;
i++)
104 src += ((
c->bx *
c->by * 2 + 3) & ~3);
107 for (y = 0; y <
c->height; y +=
c->bh) {
108 bh2 = ((
c->height - y) >
c->bh) ?
c->bh : (
c->height - y);
109 for (x = 0; x <
c->width; x +=
c->bw) {
110 uint8_t *
out, *tprev;
113 dx = mvec[
block] >> 1;
114 dy = mvec[
block + 1] >> 1;
117 bw2 = ((
c->width - x) >
c->bw) ?
c->bw : (
c->width - x);
121 tprev =
prev + x + dx + dy *
c->width;
124 for (j = 0; j < bh2; j++) {
125 if (
my + j < 0 || my + j >=
c->height) {
127 }
else if (
mx >= 0 &&
mx + bw2 <= c->
width){
128 memcpy(
out, tprev,
sizeof(*
out) * bw2);
130 for (
i = 0;
i < bw2;
i++) {
142 if (
c->decomp_len - (
src -
c->decomp_buf) < bw2 * bh2)
145 for (j = 0; j < bh2; j++) {
146 for (
i = 0;
i < bw2;
i++)
152 output +=
c->width *
c->bh;
155 if (
src -
c->decomp_buf !=
c->decomp_len)
157 src-
c->decomp_buf,
c->decomp_len);
167 uint8_t *
src =
c->decomp_buf;
168 uint16_t *output, *
prev;
171 int d, dx, dy, bw2, bh2;
176 output = (uint16_t*)
c->cur;
177 prev = (uint16_t*)
c->prev;
180 src += ((
c->bx *
c->by * 2 + 3) & ~3);
183 for (y = 0; y <
c->height; y +=
c->bh) {
184 bh2 = ((
c->height - y) >
c->bh) ?
c->bh : (
c->height - y);
185 for (x = 0; x <
c->width; x +=
c->bw) {
186 uint16_t *
out, *tprev;
189 dx = mvec[
block] >> 1;
190 dy = mvec[
block + 1] >> 1;
193 bw2 = ((
c->width - x) >
c->bw) ?
c->bw : (
c->width - x);
197 tprev =
prev + x + dx + dy *
c->width;
200 for (j = 0; j < bh2; j++) {
201 if (
my + j < 0 || my + j >=
c->height) {
202 memset(
out, 0, bw2 * 2);
203 }
else if (
mx >= 0 &&
mx + bw2 <= c->
width){
204 memcpy(
out, tprev,
sizeof(*
out) * bw2);
206 for (
i = 0;
i < bw2;
i++) {
218 if (
c->decomp_len - (
src -
c->decomp_buf) < bw2 * bh2 * 2)
221 for (j = 0; j < bh2; j++){
222 for (
i = 0;
i < bw2;
i++) {
230 output +=
c->width *
c->bh;
233 if (
src -
c->decomp_buf !=
c->decomp_len)
235 src-
c->decomp_buf,
c->decomp_len);
239#ifdef ZMBV_ENABLE_24BPP
246 uint8_t *
src =
c->decomp_buf;
247 uint8_t *output, *
prev;
250 int d, dx, dy, bw2, bh2;
261 src += ((
c->bx *
c->by * 2 + 3) & ~3);
264 for (y = 0; y <
c->height; y +=
c->bh) {
265 bh2 = ((
c->height - y) >
c->bh) ?
c->bh : (
c->
height - y);
266 for (x = 0; x <
c->width; x +=
c->bw) {
267 uint8_t *
out, *tprev;
270 dx = mvec[
block] >> 1;
271 dy = mvec[
block + 1] >> 1;
274 bw2 = ((
c->width - x) >
c->bw) ?
c->bw : (
c->
width - x);
277 out = output + x * 3;
281 for (j = 0; j < bh2; j++) {
282 if (
my + j < 0 || my + j >=
c->height) {
283 memset(
out, 0, bw2 * 3);
284 }
else if (
mx >= 0 &&
mx + bw2 <= c->
width){
285 memcpy(
out, tprev, 3 * bw2);
287 for (
i = 0;
i < bw2;
i++){
293 out[
i * 3 + 0] = tprev[
i * 3 + 0];
294 out[
i * 3 + 1] = tprev[
i * 3 + 1];
295 out[
i * 3 + 2] = tprev[
i * 3 + 2];
304 if (
c->decomp_len - (
src -
c->decomp_buf) < bw2 * bh2 * 3)
306 out = output + x * 3;
307 for (j = 0; j < bh2; j++) {
308 for (
i = 0;
i < bw2;
i++) {
320 if (
src -
c->decomp_buf !=
c->decomp_len)
322 src-
c->decomp_buf,
c->decomp_len);
333 uint8_t *
src =
c->decomp_buf;
334 uint32_t *output, *
prev;
337 int d, dx, dy, bw2, bh2;
342 output = (uint32_t*)
c->cur;
343 prev = (uint32_t*)
c->prev;
346 src += ((
c->bx *
c->by * 2 + 3) & ~3);
349 for (y = 0; y <
c->height; y +=
c->bh) {
350 bh2 = ((
c->height - y) >
c->bh) ?
c->bh : (
c->height - y);
351 for (x = 0; x <
c->width; x +=
c->bw) {
352 uint32_t *
out, *tprev;
355 dx = mvec[
block] >> 1;
356 dy = mvec[
block + 1] >> 1;
359 bw2 = ((
c->width - x) >
c->bw) ?
c->bw : (
c->width - x);
363 tprev =
prev + x + dx + dy *
c->width;
366 for (j = 0; j < bh2; j++) {
367 if (
my + j < 0 || my + j >=
c->height) {
368 memset(
out, 0, bw2 * 4);
369 }
else if (
mx >= 0 &&
mx + bw2 <= c->
width){
370 memcpy(
out, tprev,
sizeof(*
out) * bw2);
372 for (
i = 0;
i < bw2;
i++){
384 if (
c->decomp_len - (
src -
c->decomp_buf) < bw2 * bh2 * 4)
387 for (j = 0; j < bh2; j++){
388 for (
i = 0;
i < bw2;
i++) {
396 output +=
c->width *
c->bh;
399 if (
src -
c->decomp_buf !=
c->decomp_len)
401 src-
c->decomp_buf,
c->decomp_len);
410 uint8_t *
src =
c->decomp_buf;
414 memcpy(
c->pal,
src, 768);
418 memcpy(
c->cur,
src,
c->width *
c->height * (
c->bpp / 8));
425 const uint8_t *buf = avpkt->
data;
426 int buf_size = avpkt->
size;
430 int hi_ver, lo_ver, ret;
449 c->decode_xor =
NULL;
454 "Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\n",
455 c->flags,hi_ver,lo_ver,
c->comp,
c->fmt,
c->bw,
c->bh);
456 if (hi_ver != 0 || lo_ver != 1) {
460 if (
c->bw == 0 ||
c->bh == 0) {
464 if (
c->comp != 0 &&
c->comp != 1) {
474 c->stride =
c->width;
484 c->stride =
c->width * 2;
486#ifdef ZMBV_ENABLE_24BPP
489 c->decode_xor = zmbv_decode_xor_24;
491 c->stride =
c->width * 3;
498 c->stride =
c->width * 4;
501 c->decode_xor =
NULL;
506 zret = inflateReset(&
c->zstream.zstream);
512 if (
c->alloc_bpp <
c->bpp) {
515 c->alloc_bpp =
c->bpp;
517 c->bx = (
c->width +
c->bw - 1) /
c->bw;
518 c->by = (
c->height+
c->bh - 1) /
c->bh;
519 if (!
c->cur || !
c->prev) {
530 expected_size = (
c->bx *
c->by * 2 + 3) & ~3;
534 expected_size += 768;
536 if (!
c->got_keyframe) {
542 if (
c->decomp_size <
len) {
546 memcpy(
c->decomp_buf, buf,
len);
549 z_stream *
const zstream = &
c->zstream.zstream;
555 zstream->avail_out =
c->decomp_size;
557 if (zret != Z_OK && zret != Z_STREAM_END) {
563 if (expected_size >
c->decomp_len ||
578 if (
c->decomp_len < 2LL * ((
c->width +
c->bw - 1) /
c->bw) * ((
c->height +
c->bh - 1) /
c->bh))
581 if ((ret =
c->decode_xor(
c)) < 0)
595 for (j = 0; j < 256; j++)
600#ifdef ZMBV_ENABLE_24BPP
605 c->stride,
c->height);
638 if (!
c->decomp_buf) {
640 "Can't allocate decompression buffer.\n");
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
const FFCodec ff_zmbv_decoder
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
#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...
common internal and external API header
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
static av_cold int decode_init(AVCodecContext *avctx)
static av_cold int decode_end(AVCodecContext *avctx)
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
Macro definitions for various function/variable attributes.
#define FFSWAP(type, a, b)
Memory handling functions.
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_RGB565LE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
@ 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
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int64_t max_pixels
The number of pixels per image to maximally accept.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
int(* decode_xor)(struct ZmbvContext *c)
#define av_realloc_f(p, o, n)
#define avpriv_request_sample(...)
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
void ff_inflate_end(FFZStream *zstream)
Wrapper around inflateEnd().
int ff_inflate_init(FFZStream *zstream, void *logctx)
Wrapper around inflateInit().
static int zmbv_decode_xor_16(ZmbvContext *c)
Decode XOR'ed frame - 15bpp and 16bpp version.
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static av_cold int decode_init(AVCodecContext *avctx)
static int zmbv_decode_xor_32(ZmbvContext *c)
Decode XOR'ed frame - 32bpp version.
static av_cold int decode_end(AVCodecContext *avctx)
static int zmbv_decode_xor_8(ZmbvContext *c)
Decode XOR'ed frame - 8bpp version.
static int zmbv_decode_intra(ZmbvContext *c)
Decode intraframe.