Libav
zmbv.c
Go to the documentation of this file.
1 /*
2  * Zip Motion Blocks Video (ZMBV) decoder
3  * Copyright (c) 2006 Konstantin Shishkov
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
27 #include <stdio.h>
28 #include <stdlib.h>
29 
30 #include "libavutil/common.h"
31 #include "libavutil/intreadwrite.h"
32 #include "avcodec.h"
33 #include "internal.h"
34 
35 #include <zlib.h>
36 
37 #define ZMBV_KEYFRAME 1
38 #define ZMBV_DELTAPAL 2
39 
40 enum ZmbvFormat {
50 };
51 
52 /*
53  * Decoder context
54  */
55 typedef struct ZmbvContext {
57 
58  int bpp;
59  unsigned int decomp_size;
61  uint8_t pal[768];
63  int width, height;
64  int fmt;
65  int comp;
66  int flags;
67  int bw, bh, bx, by;
69  z_stream zstream;
70  int (*decode_intra)(struct ZmbvContext *c);
71  int (*decode_xor)(struct ZmbvContext *c);
72 } ZmbvContext;
73 
79 {
80  uint8_t *src = c->decomp_buf;
81  uint8_t *output, *prev;
82  int8_t *mvec;
83  int x, y;
84  int d, dx, dy, bw2, bh2;
85  int block;
86  int i, j;
87  int mx, my;
88 
89  output = c->cur;
90  prev = c->prev;
91 
92  if (c->flags & ZMBV_DELTAPAL) {
93  for (i = 0; i < 768; i++)
94  c->pal[i] ^= *src++;
95  }
96 
97  mvec = (int8_t*)src;
98  src += ((c->bx * c->by * 2 + 3) & ~3);
99 
100  block = 0;
101  for (y = 0; y < c->height; y += c->bh) {
102  bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
103  for (x = 0; x < c->width; x += c->bw) {
104  uint8_t *out, *tprev;
105 
106  d = mvec[block] & 1;
107  dx = mvec[block] >> 1;
108  dy = mvec[block + 1] >> 1;
109  block += 2;
110 
111  bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
112 
113  /* copy block - motion vectors out of bounds are used to zero blocks */
114  out = output + x;
115  tprev = prev + x + dx + dy * c->width;
116  mx = x + dx;
117  my = y + dy;
118  for (j = 0; j < bh2; j++) {
119  if (my + j < 0 || my + j >= c->height) {
120  memset(out, 0, bw2);
121  } else {
122  for (i = 0; i < bw2; i++) {
123  if (mx + i < 0 || mx + i >= c->width)
124  out[i] = 0;
125  else
126  out[i] = tprev[i];
127  }
128  }
129  out += c->width;
130  tprev += c->width;
131  }
132 
133  if (d) { /* apply XOR'ed difference */
134  out = output + x;
135  for (j = 0; j < bh2; j++) {
136  for (i = 0; i < bw2; i++)
137  out[i] ^= *src++;
138  out += c->width;
139  }
140  }
141  }
142  output += c->width * c->bh;
143  prev += c->width * c->bh;
144  }
145  if (src - c->decomp_buf != c->decomp_len)
146  av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n",
147  src-c->decomp_buf, c->decomp_len);
148  return 0;
149 }
150 
156 {
157  uint8_t *src = c->decomp_buf;
158  uint16_t *output, *prev;
159  int8_t *mvec;
160  int x, y;
161  int d, dx, dy, bw2, bh2;
162  int block;
163  int i, j;
164  int mx, my;
165 
166  output = (uint16_t*)c->cur;
167  prev = (uint16_t*)c->prev;
168 
169  mvec = (int8_t*)src;
170  src += ((c->bx * c->by * 2 + 3) & ~3);
171 
172  block = 0;
173  for (y = 0; y < c->height; y += c->bh) {
174  bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
175  for (x = 0; x < c->width; x += c->bw) {
176  uint16_t *out, *tprev;
177 
178  d = mvec[block] & 1;
179  dx = mvec[block] >> 1;
180  dy = mvec[block + 1] >> 1;
181  block += 2;
182 
183  bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
184 
185  /* copy block - motion vectors out of bounds are used to zero blocks */
186  out = output + x;
187  tprev = prev + x + dx + dy * c->width;
188  mx = x + dx;
189  my = y + dy;
190  for (j = 0; j < bh2; j++) {
191  if (my + j < 0 || my + j >= c->height) {
192  memset(out, 0, bw2 * 2);
193  } else {
194  for (i = 0; i < bw2; i++) {
195  if (mx + i < 0 || mx + i >= c->width)
196  out[i] = 0;
197  else
198  out[i] = tprev[i];
199  }
200  }
201  out += c->width;
202  tprev += c->width;
203  }
204 
205  if (d) { /* apply XOR'ed difference */
206  out = output + x;
207  for (j = 0; j < bh2; j++){
208  for (i = 0; i < bw2; i++) {
209  out[i] ^= *((uint16_t*)src);
210  src += 2;
211  }
212  out += c->width;
213  }
214  }
215  }
216  output += c->width * c->bh;
217  prev += c->width * c->bh;
218  }
219  if (src - c->decomp_buf != c->decomp_len)
220  av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n",
221  src-c->decomp_buf, c->decomp_len);
222  return 0;
223 }
224 
225 #ifdef ZMBV_ENABLE_24BPP
226 
230 static int zmbv_decode_xor_24(ZmbvContext *c)
231 {
232  uint8_t *src = c->decomp_buf;
233  uint8_t *output, *prev;
234  int8_t *mvec;
235  int x, y;
236  int d, dx, dy, bw2, bh2;
237  int block;
238  int i, j;
239  int mx, my;
240  int stride;
241 
242  output = c->cur;
243  prev = c->prev;
244 
245  stride = c->width * 3;
246  mvec = (int8_t*)src;
247  src += ((c->bx * c->by * 2 + 3) & ~3);
248 
249  block = 0;
250  for (y = 0; y < c->height; y += c->bh) {
251  bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
252  for (x = 0; x < c->width; x += c->bw) {
253  uint8_t *out, *tprev;
254 
255  d = mvec[block] & 1;
256  dx = mvec[block] >> 1;
257  dy = mvec[block + 1] >> 1;
258  block += 2;
259 
260  bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
261 
262  /* copy block - motion vectors out of bounds are used to zero blocks */
263  out = output + x * 3;
264  tprev = prev + (x + dx) * 3 + dy * stride;
265  mx = x + dx;
266  my = y + dy;
267  for (j = 0; j < bh2; j++) {
268  if (my + j < 0 || my + j >= c->height) {
269  memset(out, 0, bw2 * 3);
270  } else {
271  for (i = 0; i < bw2; i++){
272  if (mx + i < 0 || mx + i >= c->width) {
273  out[i * 3 + 0] = 0;
274  out[i * 3 + 1] = 0;
275  out[i * 3 + 2] = 0;
276  } else {
277  out[i * 3 + 0] = tprev[i * 3 + 0];
278  out[i * 3 + 1] = tprev[i * 3 + 1];
279  out[i * 3 + 2] = tprev[i * 3 + 2];
280  }
281  }
282  }
283  out += stride;
284  tprev += stride;
285  }
286 
287  if (d) { /* apply XOR'ed difference */
288  out = output + x * 3;
289  for (j = 0; j < bh2; j++) {
290  for (i = 0; i < bw2; i++) {
291  out[i * 3 + 0] ^= *src++;
292  out[i * 3 + 1] ^= *src++;
293  out[i * 3 + 2] ^= *src++;
294  }
295  out += stride;
296  }
297  }
298  }
299  output += stride * c->bh;
300  prev += stride * c->bh;
301  }
302  if (src - c->decomp_buf != c->decomp_len)
303  av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n",
304  src-c->decomp_buf, c->decomp_len);
305  return 0;
306 }
307 #endif //ZMBV_ENABLE_24BPP
308 
314 {
315  uint8_t *src = c->decomp_buf;
316  uint32_t *output, *prev;
317  int8_t *mvec;
318  int x, y;
319  int d, dx, dy, bw2, bh2;
320  int block;
321  int i, j;
322  int mx, my;
323 
324  output = (uint32_t*)c->cur;
325  prev = (uint32_t*)c->prev;
326 
327  mvec = (int8_t*)src;
328  src += ((c->bx * c->by * 2 + 3) & ~3);
329 
330  block = 0;
331  for (y = 0; y < c->height; y += c->bh) {
332  bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
333  for (x = 0; x < c->width; x += c->bw) {
334  uint32_t *out, *tprev;
335 
336  d = mvec[block] & 1;
337  dx = mvec[block] >> 1;
338  dy = mvec[block + 1] >> 1;
339  block += 2;
340 
341  bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
342 
343  /* copy block - motion vectors out of bounds are used to zero blocks */
344  out = output + x;
345  tprev = prev + x + dx + dy * c->width;
346  mx = x + dx;
347  my = y + dy;
348  for (j = 0; j < bh2; j++) {
349  if (my + j < 0 || my + j >= c->height) {
350  memset(out, 0, bw2 * 4);
351  } else {
352  for (i = 0; i < bw2; i++){
353  if (mx + i < 0 || mx + i >= c->width)
354  out[i] = 0;
355  else
356  out[i] = tprev[i];
357  }
358  }
359  out += c->width;
360  tprev += c->width;
361  }
362 
363  if (d) { /* apply XOR'ed difference */
364  out = output + x;
365  for (j = 0; j < bh2; j++){
366  for (i = 0; i < bw2; i++) {
367  out[i] ^= *((uint32_t *) src);
368  src += 4;
369  }
370  out += c->width;
371  }
372  }
373  }
374  output += c->width * c->bh;
375  prev += c->width * c->bh;
376  }
377  if (src - c->decomp_buf != c->decomp_len)
378  av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n",
379  src-c->decomp_buf, c->decomp_len);
380  return 0;
381 }
382 
387 {
388  uint8_t *src = c->decomp_buf;
389 
390  /* make the palette available on the way out */
391  if (c->fmt == ZMBV_FMT_8BPP) {
392  memcpy(c->pal, src, 768);
393  src += 768;
394  }
395 
396  memcpy(c->cur, src, c->width * c->height * (c->bpp / 8));
397  return 0;
398 }
399 
400 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
401 {
402  AVFrame *frame = data;
403  const uint8_t *buf = avpkt->data;
404  int buf_size = avpkt->size;
405  ZmbvContext * const c = avctx->priv_data;
406  int zret = Z_OK; // Zlib return code
407  int len = buf_size;
408  int hi_ver, lo_ver, ret;
409  uint8_t *tmp;
410 
411  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
412  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
413  return ret;
414  }
415 
416  /* parse header */
417  c->flags = buf[0];
418  buf++; len--;
419  if (c->flags & ZMBV_KEYFRAME) {
420  hi_ver = buf[0];
421  lo_ver = buf[1];
422  c->comp = buf[2];
423  c->fmt = buf[3];
424  c->bw = buf[4];
425  c->bh = buf[5];
426  c->decode_intra = NULL;
427  c->decode_xor = NULL;
428 
429  buf += 6;
430  len -= 6;
431  av_log(avctx, AV_LOG_DEBUG,
432  "Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\n",
433  c->flags,hi_ver,lo_ver,c->comp,c->fmt,c->bw,c->bh);
434  if (hi_ver != 0 || lo_ver != 1) {
435  avpriv_request_sample(avctx, "Version %i.%i", hi_ver, lo_ver);
436  return AVERROR_PATCHWELCOME;
437  }
438  if (c->bw == 0 || c->bh == 0) {
439  avpriv_request_sample(avctx, "Block size %ix%i", c->bw, c->bh);
440  return AVERROR_PATCHWELCOME;
441  }
442  if (c->comp != 0 && c->comp != 1) {
443  avpriv_request_sample(avctx, "Compression type %i", c->comp);
444  return AVERROR_PATCHWELCOME;
445  }
446 
447  switch (c->fmt) {
448  case ZMBV_FMT_8BPP:
449  c->bpp = 8;
452  break;
453  case ZMBV_FMT_15BPP:
454  case ZMBV_FMT_16BPP:
455  c->bpp = 16;
458  break;
459 #ifdef ZMBV_ENABLE_24BPP
460  case ZMBV_FMT_24BPP:
461  c->bpp = 24;
463  c->decode_xor = zmbv_decode_xor_24;
464  break;
465 #endif //ZMBV_ENABLE_24BPP
466  case ZMBV_FMT_32BPP:
467  c->bpp = 32;
470  break;
471  default:
472  c->decode_intra = NULL;
473  c->decode_xor = NULL;
474  avpriv_request_sample(avctx, "Format %i", c->fmt);
475  return AVERROR_PATCHWELCOME;
476  }
477 
478  zret = inflateReset(&c->zstream);
479  if (zret != Z_OK) {
480  av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
481  return AVERROR_UNKNOWN;
482  }
483 
484  tmp = av_realloc(c->cur, avctx->width * avctx->height * (c->bpp / 8));
485  if (!tmp)
486  return AVERROR(ENOMEM);
487  c->cur = tmp;
488  tmp = av_realloc(c->prev, avctx->width * avctx->height * (c->bpp / 8));
489  if (!tmp)
490  return AVERROR(ENOMEM);
491  c->prev = tmp;
492  c->bx = (c->width + c->bw - 1) / c->bw;
493  c->by = (c->height + c->bh - 1) / c->bh;
494  }
495 
496  if (!c->decode_intra) {
497  av_log(avctx, AV_LOG_ERROR, "Error! Got no format or no keyframe!\n");
498  return AVERROR_INVALIDDATA;
499  }
500 
501  if (c->comp == 0) { //Uncompressed data
502  if (c->decomp_size < len) {
503  av_log(avctx, AV_LOG_ERROR, "Buffer too small\n");
504  return AVERROR_INVALIDDATA;
505  }
506  memcpy(c->decomp_buf, buf, len);
507  } else { // ZLIB-compressed data
508  c->zstream.total_in = c->zstream.total_out = 0;
509  c->zstream.next_in = buf;
510  c->zstream.avail_in = len;
511  c->zstream.next_out = c->decomp_buf;
512  c->zstream.avail_out = c->decomp_size;
513  zret = inflate(&c->zstream, Z_SYNC_FLUSH);
514  if (zret != Z_OK && zret != Z_STREAM_END) {
515  av_log(avctx, AV_LOG_ERROR, "inflate error %d\n", zret);
516  return AVERROR_INVALIDDATA;
517  }
518  c->decomp_len = c->zstream.total_out;
519  }
520  if (c->flags & ZMBV_KEYFRAME) {
521  frame->key_frame = 1;
522  frame->pict_type = AV_PICTURE_TYPE_I;
523  c->decode_intra(c);
524  } else {
525  frame->key_frame = 0;
526  frame->pict_type = AV_PICTURE_TYPE_P;
527  if (c->decomp_len)
528  c->decode_xor(c);
529  }
530 
531  /* update frames */
532  {
533  uint8_t *out, *src;
534  int i, j;
535 
536  out = frame->data[0];
537  src = c->cur;
538  switch (c->fmt) {
539  case ZMBV_FMT_8BPP:
540  for (j = 0; j < c->height; j++) {
541  for (i = 0; i < c->width; i++) {
542  out[i * 3 + 0] = c->pal[(*src) * 3 + 0];
543  out[i * 3 + 1] = c->pal[(*src) * 3 + 1];
544  out[i * 3 + 2] = c->pal[(*src) * 3 + 2];
545  src++;
546  }
547  out += frame->linesize[0];
548  }
549  break;
550  case ZMBV_FMT_15BPP:
551  for (j = 0; j < c->height; j++) {
552  for (i = 0; i < c->width; i++) {
553  uint16_t tmp = AV_RL16(src);
554  src += 2;
555  out[i * 3 + 0] = (tmp & 0x7C00) >> 7;
556  out[i * 3 + 1] = (tmp & 0x03E0) >> 2;
557  out[i * 3 + 2] = (tmp & 0x001F) << 3;
558  }
559  out += frame->linesize[0];
560  }
561  break;
562  case ZMBV_FMT_16BPP:
563  for (j = 0; j < c->height; j++) {
564  for (i = 0; i < c->width; i++) {
565  uint16_t tmp = AV_RL16(src);
566  src += 2;
567  out[i * 3 + 0] = (tmp & 0xF800) >> 8;
568  out[i * 3 + 1] = (tmp & 0x07E0) >> 3;
569  out[i * 3 + 2] = (tmp & 0x001F) << 3;
570  }
571  out += frame->linesize[0];
572  }
573  break;
574 #ifdef ZMBV_ENABLE_24BPP
575  case ZMBV_FMT_24BPP:
576  for (j = 0; j < c->height; j++) {
577  memcpy(out, src, c->width * 3);
578  src += c->width * 3;
579  out += frame->linesize[0];
580  }
581  break;
582 #endif //ZMBV_ENABLE_24BPP
583  case ZMBV_FMT_32BPP:
584  for (j = 0; j < c->height; j++) {
585  for (i = 0; i < c->width; i++) {
586  uint32_t tmp = AV_RL32(src);
587  src += 4;
588  AV_WB24(out+(i*3), tmp);
589  }
590  out += frame->linesize[0];
591  }
592  break;
593  default:
594  av_log(avctx, AV_LOG_ERROR, "Cannot handle format %i\n", c->fmt);
595  }
596  FFSWAP(uint8_t *, c->cur, c->prev);
597  }
598  *got_frame = 1;
599 
600  /* always report that the buffer was completely consumed */
601  return buf_size;
602 }
603 
605 {
606  ZmbvContext * const c = avctx->priv_data;
607  int zret; // Zlib return code
608 
609  c->avctx = avctx;
610 
611  c->width = avctx->width;
612  c->height = avctx->height;
613 
614  c->bpp = avctx->bits_per_coded_sample;
615 
616  // Needed if zlib unused or init aborted before inflateInit
617  memset(&c->zstream, 0, sizeof(z_stream));
618 
619  avctx->pix_fmt = AV_PIX_FMT_RGB24;
620  c->decomp_size = (avctx->width + 255) * 4 * (avctx->height + 64);
621 
622  /* Allocate decompression buffer */
623  if (c->decomp_size) {
624  if (!(c->decomp_buf = av_malloc(c->decomp_size))) {
625  av_log(avctx, AV_LOG_ERROR,
626  "Can't allocate decompression buffer.\n");
627  return AVERROR(ENOMEM);
628  }
629  }
630 
631  c->zstream.zalloc = Z_NULL;
632  c->zstream.zfree = Z_NULL;
633  c->zstream.opaque = Z_NULL;
634  zret = inflateInit(&c->zstream);
635  if (zret != Z_OK) {
636  av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
637  return AVERROR_UNKNOWN;
638  }
639 
640  return 0;
641 }
642 
644 {
645  ZmbvContext * const c = avctx->priv_data;
646 
647  av_freep(&c->decomp_buf);
648 
649  inflateEnd(&c->zstream);
650  av_freep(&c->cur);
651  av_freep(&c->prev);
652 
653  return 0;
654 }
655 
657  .name = "zmbv",
658  .long_name = NULL_IF_CONFIG_SMALL("Zip Motion Blocks Video"),
659  .type = AVMEDIA_TYPE_VIDEO,
660  .id = AV_CODEC_ID_ZMBV,
661  .priv_data_size = sizeof(ZmbvContext),
662  .init = decode_init,
663  .close = decode_end,
664  .decode = decode_frame,
665  .capabilities = CODEC_CAP_DR1,
666 };
int(* decode_xor)(struct ZmbvContext *c)
Definition: zmbv.c:71
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
uint8_t pal[768]
Definition: zmbv.c:61
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
int decomp_len
Definition: zmbv.c:68
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:67
static int zmbv_decode_xor_32(ZmbvContext *c)
Decode XOR'ed frame - 32bpp version.
Definition: zmbv.c:313
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: zmbv.c:400
int size
Definition: avcodec.h:974
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1270
#define AV_RL16
Definition: intreadwrite.h:42
AVCodecContext * avctx
Definition: zmbv.c:56
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:2812
AVCodec ff_zmbv_decoder
Definition: zmbv.c:656
int flags
Definition: zmbv.c:66
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:275
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t
#define av_cold
Definition: attributes.h:66
int comp
Definition: zmbv.c:65
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:684
const char data[16]
Definition: mxf.c:70
uint8_t * data
Definition: avcodec.h:973
static av_cold int decode_init(AVCodecContext *avctx)
Definition: zmbv.c:604
#define ZMBV_KEYFRAME
Definition: zmbv.c:37
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2523
static int zmbv_decode_xor_8(ZmbvContext *c)
Decode XOR'ed frame - 8bpp version.
Definition: zmbv.c:78
int by
Definition: zmbv.c:67
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
#define AVERROR(e)
Definition: error.h:43
int bx
Definition: zmbv.c:67
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:145
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
ZmbvFormat
Definition: zmbv.c:40
int bw
Definition: zmbv.c:67
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
const char * name
Name of the codec implementation.
Definition: avcodec.h:2819
static av_cold int decode_end(AVCodecContext *avctx)
Definition: zmbv.c:643
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:196
int width
picture width / height.
Definition: avcodec.h:1229
#define AV_WB24(p, d)
Definition: intreadwrite.h:412
#define AV_RL32
Definition: intreadwrite.h:146
uint8_t * decomp_buf
Definition: zmbv.c:60
int bh
Definition: zmbv.c:67
unsigned int decomp_size
Definition: zmbv.c:59
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
Definition: error.h:57
NULL
Definition: eval.c:55
Libavcodec external API header.
static int zmbv_decode_xor_16(ZmbvContext *c)
Decode XOR'ed frame - 15bpp and 16bpp version.
Definition: zmbv.c:155
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:153
main external API structure.
Definition: avcodec.h:1050
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:612
int height
Definition: zmbv.c:63
z_stream zstream
Definition: zmbv.c:69
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:141
int bpp
Definition: zmbv.c:58
int width
Definition: zmbv.c:63
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
common internal api header.
common internal and external API header
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:117
uint8_t * prev
Definition: zmbv.c:62
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:61
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
void * priv_data
Definition: avcodec.h:1092
int len
int fmt
Definition: zmbv.c:64
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:191
int(* decode_intra)(struct ZmbvContext *c)
Definition: zmbv.c:70
static int zmbv_decode_intra(ZmbvContext *c)
Decode intraframe.
Definition: zmbv.c:386
#define ZMBV_DELTAPAL
Definition: zmbv.c:38
uint8_t * cur
Definition: zmbv.c:62
#define FFSWAP(type, a, b)
Definition: common.h:60
This structure stores compressed data.
Definition: avcodec.h:950
Predicted.
Definition: avutil.h:254
static int16_t block[64]
Definition: dct-test.c:88