38 #define ZMBV_KEYFRAME 1
39 #define ZMBV_DELTAPAL 2
87 int d, dx, dy, bw2, bh2;
96 for (
i = 0;
i < 768;
i++)
101 src += ((
c->bx *
c->by * 2 + 3) & ~3);
104 for (y = 0; y <
c->height; y +=
c->bh) {
105 bh2 = ((
c->height - y) >
c->bh) ?
c->bh : (
c->height - y);
106 for (x = 0; x <
c->width; x +=
c->bw) {
110 dx = mvec[
block] >> 1;
111 dy = mvec[
block + 1] >> 1;
114 bw2 = ((
c->width - x) >
c->bw) ?
c->bw : (
c->width - x);
118 tprev =
prev + x + dx + dy *
c->width;
121 for (j = 0; j < bh2; j++) {
122 if (my + j < 0 || my + j >=
c->height) {
124 }
else if (mx >= 0 && mx + bw2 <= c->
width){
125 memcpy(
out, tprev,
sizeof(*
out) * bw2);
127 for (
i = 0;
i < bw2;
i++) {
128 if (mx + i < 0 || mx + i >=
c->width)
140 for (j = 0; j < bh2; j++) {
141 for (
i = 0;
i < bw2;
i++)
147 output +=
c->width *
c->bh;
150 if (
src -
c->decomp_buf !=
c->decomp_len)
152 src-
c->decomp_buf,
c->decomp_len);
163 uint16_t *output, *
prev;
166 int d, dx, dy, bw2, bh2;
171 output = (uint16_t*)
c->cur;
172 prev = (uint16_t*)
c->prev;
175 src += ((
c->bx *
c->by * 2 + 3) & ~3);
178 for (y = 0; y <
c->height; y +=
c->bh) {
179 bh2 = ((
c->height - y) >
c->bh) ?
c->bh : (
c->height - y);
180 for (x = 0; x <
c->width; x +=
c->bw) {
181 uint16_t *
out, *tprev;
184 dx = mvec[
block] >> 1;
185 dy = mvec[
block + 1] >> 1;
188 bw2 = ((
c->width - x) >
c->bw) ?
c->bw : (
c->width - x);
192 tprev =
prev + x + dx + dy *
c->width;
195 for (j = 0; j < bh2; j++) {
196 if (my + j < 0 || my + j >=
c->height) {
197 memset(
out, 0, bw2 * 2);
198 }
else if (mx >= 0 && mx + bw2 <= c->
width){
199 memcpy(
out, tprev,
sizeof(*
out) * bw2);
201 for (
i = 0;
i < bw2;
i++) {
202 if (mx + i < 0 || mx + i >=
c->width)
214 for (j = 0; j < bh2; j++){
215 for (
i = 0;
i < bw2;
i++) {
223 output +=
c->width *
c->bh;
226 if (
src -
c->decomp_buf !=
c->decomp_len)
228 src-
c->decomp_buf,
c->decomp_len);
232 #ifdef ZMBV_ENABLE_24BPP
243 int d, dx, dy, bw2, bh2;
254 src += ((
c->bx *
c->by * 2 + 3) & ~3);
257 for (y = 0; y <
c->height; y +=
c->bh) {
258 bh2 = ((
c->height - y) >
c->bh) ?
c->bh : (
c->height - y);
259 for (x = 0; x <
c->width; x +=
c->bw) {
263 dx = mvec[
block] >> 1;
264 dy = mvec[
block + 1] >> 1;
267 bw2 = ((
c->width - x) >
c->bw) ?
c->bw : (
c->width - x);
270 out = output + x * 3;
274 for (j = 0; j < bh2; j++) {
275 if (my + j < 0 || my + j >=
c->height) {
276 memset(
out, 0, bw2 * 3);
277 }
else if (mx >= 0 && mx + bw2 <= c->
width){
278 memcpy(
out, tprev, 3 * bw2);
280 for (
i = 0;
i < bw2;
i++){
281 if (mx + i < 0 || mx + i >=
c->width) {
286 out[
i * 3 + 0] = tprev[
i * 3 + 0];
287 out[
i * 3 + 1] = tprev[
i * 3 + 1];
288 out[
i * 3 + 2] = tprev[
i * 3 + 2];
297 out = output + x * 3;
298 for (j = 0; j < bh2; j++) {
299 for (
i = 0;
i < bw2;
i++) {
311 if (
src -
c->decomp_buf !=
c->decomp_len)
313 src-
c->decomp_buf,
c->decomp_len);
325 uint32_t *output, *
prev;
328 int d, dx, dy, bw2, bh2;
333 output = (uint32_t*)
c->cur;
334 prev = (uint32_t*)
c->prev;
337 src += ((
c->bx *
c->by * 2 + 3) & ~3);
340 for (y = 0; y <
c->height; y +=
c->bh) {
341 bh2 = ((
c->height - y) >
c->bh) ?
c->bh : (
c->height - y);
342 for (x = 0; x <
c->width; x +=
c->bw) {
343 uint32_t *
out, *tprev;
346 dx = mvec[
block] >> 1;
347 dy = mvec[
block + 1] >> 1;
350 bw2 = ((
c->width - x) >
c->bw) ?
c->bw : (
c->width - x);
354 tprev =
prev + x + dx + dy *
c->width;
357 for (j = 0; j < bh2; j++) {
358 if (my + j < 0 || my + j >=
c->height) {
359 memset(
out, 0, bw2 * 4);
360 }
else if (mx >= 0 && mx + bw2 <= c->
width){
361 memcpy(
out, tprev,
sizeof(*
out) * bw2);
363 for (
i = 0;
i < bw2;
i++){
364 if (mx + i < 0 || mx + i >=
c->width)
376 for (j = 0; j < bh2; j++){
377 for (
i = 0;
i < bw2;
i++) {
385 output +=
c->width *
c->bh;
388 if (
src -
c->decomp_buf !=
c->decomp_len)
390 src-
c->decomp_buf,
c->decomp_len);
403 memcpy(
c->pal,
src, 768);
407 memcpy(
c->cur,
src,
c->width *
c->height * (
c->bpp / 8));
415 int buf_size = avpkt->
size;
419 int hi_ver, lo_ver, ret;
438 c->decode_xor =
NULL;
443 "Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\n",
444 c->flags,hi_ver,lo_ver,
c->comp,
c->fmt,
c->bw,
c->bh);
445 if (hi_ver != 0 || lo_ver != 1) {
449 if (
c->bw == 0 ||
c->bh == 0) {
453 if (
c->comp != 0 &&
c->comp != 1) {
463 c->stride =
c->width;
473 c->stride =
c->width * 2;
475 #ifdef ZMBV_ENABLE_24BPP
478 c->decode_xor = zmbv_decode_xor_24;
480 c->stride =
c->width * 3;
487 c->stride =
c->width * 4;
490 c->decode_xor =
NULL;
495 zret = inflateReset(&
c->zstream);
501 if (
c->alloc_bpp <
c->bpp) {
504 c->alloc_bpp =
c->bpp;
506 c->bx = (
c->width +
c->bw - 1) /
c->bw;
507 c->by = (
c->height+
c->bh - 1) /
c->bh;
508 if (!
c->cur || !
c->prev) {
519 expected_size = (
c->bx *
c->by * 2 + 3) & ~3;
523 expected_size += 768;
525 if (!
c->got_keyframe) {
531 if (
c->decomp_size <
len) {
535 memcpy(
c->decomp_buf, buf,
len);
538 c->zstream.total_in =
c->zstream.total_out = 0;
539 c->zstream.next_in = buf;
540 c->zstream.avail_in =
len;
541 c->zstream.next_out =
c->decomp_buf;
542 c->zstream.avail_out =
c->decomp_size;
543 zret =
inflate(&
c->zstream, Z_SYNC_FLUSH);
544 if (zret != Z_OK && zret != Z_STREAM_END) {
548 c->decomp_len =
c->zstream.total_out;
550 if (expected_size >
c->decomp_len ||
565 if (
c->decomp_len < 2LL * ((
c->width +
c->bw - 1) /
c->bw) * ((
c->height +
c->bh - 1) /
c->bh))
580 for (j = 0; j < 256; j++)
584 #ifdef ZMBV_ENABLE_24BPP
589 c->stride,
c->height);
615 memset(&
c->zstream, 0,
sizeof(z_stream));
626 if (!
c->decomp_buf) {
628 "Can't allocate decompression buffer.\n");
632 c->zstream.zalloc = Z_NULL;
633 c->zstream.zfree = Z_NULL;
634 c->zstream.opaque = Z_NULL;
635 zret = inflateInit(&
c->zstream);
650 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.