38 #define ZMBV_KEYFRAME 1
39 #define ZMBV_DELTAPAL 2
88 int d, dx, dy, bw2, bh2;
97 for (
i = 0;
i < 768;
i++)
102 src += ((
c->bx *
c->by * 2 + 3) & ~3);
105 for (y = 0; y <
c->height; y +=
c->bh) {
106 bh2 = ((
c->height - y) >
c->bh) ?
c->bh : (
c->height - y);
107 for (x = 0; x <
c->width; x +=
c->bw) {
111 dx = mvec[
block] >> 1;
112 dy = mvec[
block + 1] >> 1;
115 bw2 = ((
c->width - x) >
c->bw) ?
c->bw : (
c->width - x);
119 tprev =
prev + x + dx + dy *
c->width;
122 for (j = 0; j < bh2; j++) {
123 if (my + j < 0 || my + j >=
c->height) {
125 }
else if (mx >= 0 && mx + bw2 <= c->
width){
126 memcpy(
out, tprev,
sizeof(*
out) * bw2);
128 for (
i = 0;
i < bw2;
i++) {
129 if (mx + i < 0 || mx + i >=
c->width)
140 if (
c->decomp_len - (
src -
c->decomp_buf) < bw2 * bh2)
143 for (j = 0; j < bh2; j++) {
144 for (
i = 0;
i < bw2;
i++)
150 output +=
c->width *
c->bh;
153 if (
src -
c->decomp_buf !=
c->decomp_len)
155 src-
c->decomp_buf,
c->decomp_len);
166 uint16_t *output, *
prev;
169 int d, dx, dy, bw2, bh2;
174 output = (uint16_t*)
c->cur;
175 prev = (uint16_t*)
c->prev;
178 src += ((
c->bx *
c->by * 2 + 3) & ~3);
181 for (y = 0; y <
c->height; y +=
c->bh) {
182 bh2 = ((
c->height - y) >
c->bh) ?
c->bh : (
c->height - y);
183 for (x = 0; x <
c->width; x +=
c->bw) {
184 uint16_t *
out, *tprev;
187 dx = mvec[
block] >> 1;
188 dy = mvec[
block + 1] >> 1;
191 bw2 = ((
c->width - x) >
c->bw) ?
c->bw : (
c->width - x);
195 tprev =
prev + x + dx + dy *
c->width;
198 for (j = 0; j < bh2; j++) {
199 if (my + j < 0 || my + j >=
c->height) {
200 memset(
out, 0, bw2 * 2);
201 }
else if (mx >= 0 && mx + bw2 <= c->
width){
202 memcpy(
out, tprev,
sizeof(*
out) * bw2);
204 for (
i = 0;
i < bw2;
i++) {
205 if (mx + i < 0 || mx + i >=
c->width)
216 if (
c->decomp_len - (
src -
c->decomp_buf) < bw2 * bh2 * 2)
219 for (j = 0; j < bh2; j++){
220 for (
i = 0;
i < bw2;
i++) {
228 output +=
c->width *
c->bh;
231 if (
src -
c->decomp_buf !=
c->decomp_len)
233 src-
c->decomp_buf,
c->decomp_len);
237 #ifdef ZMBV_ENABLE_24BPP
248 int d, dx, dy, bw2, bh2;
259 src += ((
c->bx *
c->by * 2 + 3) & ~3);
262 for (y = 0; y <
c->height; y +=
c->bh) {
263 bh2 = ((
c->height - y) >
c->bh) ?
c->bh : (
c->height - y);
264 for (x = 0; x <
c->width; x +=
c->bw) {
268 dx = mvec[
block] >> 1;
269 dy = mvec[
block + 1] >> 1;
272 bw2 = ((
c->width - x) >
c->bw) ?
c->bw : (
c->width - x);
275 out = output + x * 3;
279 for (j = 0; j < bh2; j++) {
280 if (my + j < 0 || my + j >=
c->height) {
281 memset(
out, 0, bw2 * 3);
282 }
else if (mx >= 0 && mx + bw2 <= c->
width){
283 memcpy(
out, tprev, 3 * bw2);
285 for (
i = 0;
i < bw2;
i++){
286 if (mx + i < 0 || mx + i >=
c->width) {
291 out[
i * 3 + 0] = tprev[
i * 3 + 0];
292 out[
i * 3 + 1] = tprev[
i * 3 + 1];
293 out[
i * 3 + 2] = tprev[
i * 3 + 2];
302 if (
c->decomp_len - (
src -
c->decomp_buf) < bw2 * bh2 * 3)
304 out = output + x * 3;
305 for (j = 0; j < bh2; j++) {
306 for (
i = 0;
i < bw2;
i++) {
318 if (
src -
c->decomp_buf !=
c->decomp_len)
320 src-
c->decomp_buf,
c->decomp_len);
332 uint32_t *output, *
prev;
335 int d, dx, dy, bw2, bh2;
340 output = (uint32_t*)
c->cur;
341 prev = (uint32_t*)
c->prev;
344 src += ((
c->bx *
c->by * 2 + 3) & ~3);
347 for (y = 0; y <
c->height; y +=
c->bh) {
348 bh2 = ((
c->height - y) >
c->bh) ?
c->bh : (
c->height - y);
349 for (x = 0; x <
c->width; x +=
c->bw) {
350 uint32_t *
out, *tprev;
353 dx = mvec[
block] >> 1;
354 dy = mvec[
block + 1] >> 1;
357 bw2 = ((
c->width - x) >
c->bw) ?
c->bw : (
c->width - x);
361 tprev =
prev + x + dx + dy *
c->width;
364 for (j = 0; j < bh2; j++) {
365 if (my + j < 0 || my + j >=
c->height) {
366 memset(
out, 0, bw2 * 4);
367 }
else if (mx >= 0 && mx + bw2 <= c->
width){
368 memcpy(
out, tprev,
sizeof(*
out) * bw2);
370 for (
i = 0;
i < bw2;
i++){
371 if (mx + i < 0 || mx + i >=
c->width)
382 if (
c->decomp_len - (
src -
c->decomp_buf) < bw2 * bh2 * 4)
385 for (j = 0; j < bh2; j++){
386 for (
i = 0;
i < bw2;
i++) {
394 output +=
c->width *
c->bh;
397 if (
src -
c->decomp_buf !=
c->decomp_len)
399 src-
c->decomp_buf,
c->decomp_len);
412 memcpy(
c->pal,
src, 768);
416 memcpy(
c->cur,
src,
c->width *
c->height * (
c->bpp / 8));
424 int buf_size = avpkt->
size;
428 int hi_ver, lo_ver, ret;
447 c->decode_xor =
NULL;
452 "Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\n",
453 c->flags,hi_ver,lo_ver,
c->comp,
c->fmt,
c->bw,
c->bh);
454 if (hi_ver != 0 || lo_ver != 1) {
458 if (
c->bw == 0 ||
c->bh == 0) {
462 if (
c->comp != 0 &&
c->comp != 1) {
472 c->stride =
c->width;
482 c->stride =
c->width * 2;
484 #ifdef ZMBV_ENABLE_24BPP
487 c->decode_xor = zmbv_decode_xor_24;
489 c->stride =
c->width * 3;
496 c->stride =
c->width * 4;
499 c->decode_xor =
NULL;
504 zret = inflateReset(&
c->zstream);
510 if (
c->alloc_bpp <
c->bpp) {
513 c->alloc_bpp =
c->bpp;
515 c->bx = (
c->width +
c->bw - 1) /
c->bw;
516 c->by = (
c->height+
c->bh - 1) /
c->bh;
517 if (!
c->cur || !
c->prev) {
528 expected_size = (
c->bx *
c->by * 2 + 3) & ~3;
532 expected_size += 768;
534 if (!
c->got_keyframe) {
540 if (
c->decomp_size <
len) {
544 memcpy(
c->decomp_buf, buf,
len);
547 c->zstream.total_in =
c->zstream.total_out = 0;
548 c->zstream.next_in = buf;
549 c->zstream.avail_in =
len;
550 c->zstream.next_out =
c->decomp_buf;
551 c->zstream.avail_out =
c->decomp_size;
552 zret =
inflate(&
c->zstream, Z_SYNC_FLUSH);
553 if (zret != Z_OK && zret != Z_STREAM_END) {
557 c->decomp_len =
c->zstream.total_out;
559 if (expected_size >
c->decomp_len ||
574 if (
c->decomp_len < 2LL * ((
c->width +
c->bw - 1) /
c->bw) * ((
c->height +
c->bh - 1) /
c->bh))
577 if ((ret =
c->decode_xor(
c)) < 0)
591 for (j = 0; j < 256; j++)
595 #ifdef ZMBV_ENABLE_24BPP
600 c->stride,
c->height);
634 if (!
c->decomp_buf) {
636 "Can't allocate decompression buffer.\n");
640 c->zstream.zalloc = Z_NULL;
641 c->zstream.zfree = Z_NULL;
642 c->zstream.opaque = Z_NULL;
643 zret = inflateInit(&
c->zstream);
662 inflateEnd(&
c->zstream);
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
common internal and external API header
#define FFSWAP(type, a, b)
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.
#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_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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.
#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 API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define PTRDIFF_SPECIFIER
@ 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).
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 key_frame
1 -> keyframe, 0-> not
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
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)
static int zmbv_decode_xor_16(ZmbvContext *c)
Decode XOR'ed frame - 15bpp and 16bpp version.
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 decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int zmbv_decode_xor_8(ZmbvContext *c)
Decode XOR'ed frame - 8bpp version.
static int zmbv_decode_intra(ZmbvContext *c)
Decode intraframe.