Libav
lcldec.c
Go to the documentation of this file.
1 /*
2  * LCL (LossLess Codec Library) Codec
3  * Copyright (c) 2002-2004 Roberto Togni
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 
40 #include <stdio.h>
41 #include <stdlib.h>
42 
43 #include "libavutil/mem.h"
44 #include "avcodec.h"
45 #include "bytestream.h"
46 #include "internal.h"
47 #include "lcl.h"
48 
49 #if CONFIG_ZLIB_DECODER
50 #include <zlib.h>
51 #endif
52 
53 typedef struct LclDecContext {
54  // Image type
55  int imgtype;
56  // Compression type
58  // Flags
59  int flags;
60  // Decompressed data size
61  unsigned int decomp_size;
62  // Decompression buffer
63  unsigned char* decomp_buf;
64 #if CONFIG_ZLIB_DECODER
65  z_stream zstream;
66 #endif
68 
69 
74 static unsigned int mszh_decomp(const unsigned char * srcptr, int srclen, unsigned char * destptr, unsigned int destsize)
75 {
76  unsigned char *destptr_bak = destptr;
77  unsigned char *destptr_end = destptr + destsize;
78  const unsigned char *srcptr_end = srcptr + srclen;
79  unsigned mask = *srcptr++;
80  unsigned maskbit = 0x80;
81 
82  while (srcptr < srcptr_end && destptr < destptr_end) {
83  if (!(mask & maskbit)) {
84  memcpy(destptr, srcptr, 4);
85  destptr += 4;
86  srcptr += 4;
87  } else {
88  unsigned ofs = bytestream_get_le16(&srcptr);
89  unsigned cnt = (ofs >> 11) + 1;
90  ofs &= 0x7ff;
91  ofs = FFMIN(ofs, destptr - destptr_bak);
92  cnt *= 4;
93  cnt = FFMIN(cnt, destptr_end - destptr);
94  av_memcpy_backptr(destptr, ofs, cnt);
95  destptr += cnt;
96  }
97  maskbit >>= 1;
98  if (!maskbit) {
99  mask = *srcptr++;
100  while (!mask) {
101  if (destptr_end - destptr < 32 || srcptr_end - srcptr < 32) break;
102  memcpy(destptr, srcptr, 32);
103  destptr += 32;
104  srcptr += 32;
105  mask = *srcptr++;
106  }
107  maskbit = 0x80;
108  }
109  }
110 
111  return destptr - destptr_bak;
112 }
113 
114 
115 #if CONFIG_ZLIB_DECODER
116 
123 static int zlib_decomp(AVCodecContext *avctx, const uint8_t *src, int src_len, int offset, int expected)
124 {
125  LclDecContext *c = avctx->priv_data;
126  int zret = inflateReset(&c->zstream);
127  if (zret != Z_OK) {
128  av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
129  return AVERROR_UNKNOWN;
130  }
131  c->zstream.next_in = src;
132  c->zstream.avail_in = src_len;
133  c->zstream.next_out = c->decomp_buf + offset;
134  c->zstream.avail_out = c->decomp_size - offset;
135  zret = inflate(&c->zstream, Z_FINISH);
136  if (zret != Z_OK && zret != Z_STREAM_END) {
137  av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret);
138  return AVERROR_UNKNOWN;
139  }
140  if (expected != (unsigned int)c->zstream.total_out) {
141  av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n",
142  expected, c->zstream.total_out);
143  return AVERROR_UNKNOWN;
144  }
145  return c->zstream.total_out;
146 }
147 #endif
148 
149 
150 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
151 {
152  AVFrame *frame = data;
153  const uint8_t *buf = avpkt->data;
154  int buf_size = avpkt->size;
155  LclDecContext * const c = avctx->priv_data;
156  unsigned int pixel_ptr;
157  int row, col;
158  unsigned char *encoded, *outptr;
159  uint8_t *y_out, *u_out, *v_out;
160  unsigned int width = avctx->width; // Real image width
161  unsigned int height = avctx->height; // Real image height
162  unsigned int mszh_dlen;
163  unsigned char yq, y1q, uq, vq;
164  int uqvq, ret;
165  unsigned int mthread_inlen, mthread_outlen;
166  unsigned int len = buf_size;
167 
168  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
169  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
170  return ret;
171  }
172 
173  outptr = frame->data[0]; // Output image pointer
174 
175  /* Decompress frame */
176  switch (avctx->codec_id) {
177  case AV_CODEC_ID_MSZH:
178  switch (c->compression) {
179  case COMP_MSZH:
180  if (c->flags & FLAG_MULTITHREAD) {
181  mthread_inlen = AV_RL32(buf);
182  mthread_inlen = FFMIN(mthread_inlen, len - 8);
183  mthread_outlen = AV_RL32(buf + 4);
184  mthread_outlen = FFMIN(mthread_outlen, c->decomp_size);
185  mszh_dlen = mszh_decomp(buf + 8, mthread_inlen, c->decomp_buf, c->decomp_size);
186  if (mthread_outlen != mszh_dlen) {
187  av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n",
188  mthread_outlen, mszh_dlen);
189  return AVERROR_INVALIDDATA;
190  }
191  mszh_dlen = mszh_decomp(buf + 8 + mthread_inlen, len - 8 - mthread_inlen,
192  c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen);
193  if (mthread_outlen != mszh_dlen) {
194  av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n",
195  mthread_outlen, mszh_dlen);
196  return AVERROR_INVALIDDATA;
197  }
198  encoded = c->decomp_buf;
199  len = c->decomp_size;
200  } else {
201  mszh_dlen = mszh_decomp(buf, len, c->decomp_buf, c->decomp_size);
202  if (c->decomp_size != mszh_dlen) {
203  av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n",
204  c->decomp_size, mszh_dlen);
205  return AVERROR_INVALIDDATA;
206  }
207  encoded = c->decomp_buf;
208  len = mszh_dlen;
209  }
210  break;
211  case COMP_MSZH_NOCOMP: {
212  int bppx2;
213  switch (c->imgtype) {
214  case IMGTYPE_YUV111:
215  case IMGTYPE_RGB24:
216  bppx2 = 6;
217  break;
218  case IMGTYPE_YUV422:
219  case IMGTYPE_YUV211:
220  bppx2 = 4;
221  break;
222  case IMGTYPE_YUV411:
223  case IMGTYPE_YUV420:
224  bppx2 = 3;
225  break;
226  default:
227  bppx2 = 0; // will error out below
228  break;
229  }
230  if (len < ((width * height * bppx2) >> 1))
231  return AVERROR_INVALIDDATA;
232  break;
233  }
234  default:
235  av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n");
236  return AVERROR_INVALIDDATA;
237  }
238  break;
239 #if CONFIG_ZLIB_DECODER
240  case AV_CODEC_ID_ZLIB:
241  /* Using the original dll with normal compression (-1) and RGB format
242  * gives a file with ZLIB fourcc, but frame is really uncompressed.
243  * To be sure that's true check also frame size */
244  if (c->compression == COMP_ZLIB_NORMAL && c->imgtype == IMGTYPE_RGB24 &&
245  len == width * height * 3) {
246  if (c->flags & FLAG_PNGFILTER) {
247  memcpy(c->decomp_buf, buf, len);
248  encoded = c->decomp_buf;
249  } else {
250  break;
251  }
252  } else if (c->flags & FLAG_MULTITHREAD) {
253  mthread_inlen = AV_RL32(buf);
254  mthread_inlen = FFMIN(mthread_inlen, len - 8);
255  mthread_outlen = AV_RL32(buf + 4);
256  mthread_outlen = FFMIN(mthread_outlen, c->decomp_size);
257  ret = zlib_decomp(avctx, buf + 8, mthread_inlen, 0, mthread_outlen);
258  if (ret < 0) return ret;
259  ret = zlib_decomp(avctx, buf + 8 + mthread_inlen, len - 8 - mthread_inlen,
260  mthread_outlen, mthread_outlen);
261  if (ret < 0) return ret;
262  } else {
263  int ret = zlib_decomp(avctx, buf, len, 0, c->decomp_size);
264  if (ret < 0) return ret;
265  }
266  encoded = c->decomp_buf;
267  len = c->decomp_size;
268  break;
269 #endif
270  default:
271  av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n");
272  return AVERROR_INVALIDDATA;
273  }
274 
275 
276  /* Apply PNG filter */
277  if (avctx->codec_id == AV_CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER)) {
278  switch (c->imgtype) {
279  case IMGTYPE_YUV111:
280  case IMGTYPE_RGB24:
281  for (row = 0; row < height; row++) {
282  pixel_ptr = row * width * 3;
283  yq = encoded[pixel_ptr++];
284  uqvq = AV_RL16(encoded+pixel_ptr);
285  pixel_ptr += 2;
286  for (col = 1; col < width; col++) {
287  encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
288  uqvq -= AV_RL16(encoded+pixel_ptr+1);
289  AV_WL16(encoded+pixel_ptr+1, uqvq);
290  pixel_ptr += 3;
291  }
292  }
293  break;
294  case IMGTYPE_YUV422:
295  for (row = 0; row < height; row++) {
296  pixel_ptr = row * width * 2;
297  yq = uq = vq =0;
298  for (col = 0; col < width/4; col++) {
299  encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
300  encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
301  encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
302  encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
303  encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
304  encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
305  encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
306  encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
307  pixel_ptr += 8;
308  }
309  }
310  break;
311  case IMGTYPE_YUV411:
312  for (row = 0; row < height; row++) {
313  pixel_ptr = row * width / 2 * 3;
314  yq = uq = vq =0;
315  for (col = 0; col < width/4; col++) {
316  encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
317  encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
318  encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
319  encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
320  encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
321  encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
322  pixel_ptr += 6;
323  }
324  }
325  break;
326  case IMGTYPE_YUV211:
327  for (row = 0; row < height; row++) {
328  pixel_ptr = row * width * 2;
329  yq = uq = vq =0;
330  for (col = 0; col < width/2; col++) {
331  encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
332  encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
333  encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
334  encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
335  pixel_ptr += 4;
336  }
337  }
338  break;
339  case IMGTYPE_YUV420:
340  for (row = 0; row < height/2; row++) {
341  pixel_ptr = row * width * 3;
342  yq = y1q = uq = vq =0;
343  for (col = 0; col < width/2; col++) {
344  encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
345  encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
346  encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
347  encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
348  encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
349  encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
350  pixel_ptr += 6;
351  }
352  }
353  break;
354  default:
355  av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n");
356  return AVERROR_INVALIDDATA;
357  }
358  }
359 
360  /* Convert colorspace */
361  y_out = frame->data[0] + (height - 1) * frame->linesize[0];
362  u_out = frame->data[1] + (height - 1) * frame->linesize[1];
363  v_out = frame->data[2] + (height - 1) * frame->linesize[2];
364  switch (c->imgtype) {
365  case IMGTYPE_YUV111:
366  for (row = 0; row < height; row++) {
367  for (col = 0; col < width; col++) {
368  y_out[col] = *encoded++;
369  u_out[col] = *encoded++ + 128;
370  v_out[col] = *encoded++ + 128;
371  }
372  y_out -= frame->linesize[0];
373  u_out -= frame->linesize[1];
374  v_out -= frame->linesize[2];
375  }
376  break;
377  case IMGTYPE_YUV422:
378  for (row = 0; row < height; row++) {
379  for (col = 0; col < width - 3; col += 4) {
380  memcpy(y_out + col, encoded, 4);
381  encoded += 4;
382  u_out[ col >> 1 ] = *encoded++ + 128;
383  u_out[(col >> 1) + 1] = *encoded++ + 128;
384  v_out[ col >> 1 ] = *encoded++ + 128;
385  v_out[(col >> 1) + 1] = *encoded++ + 128;
386  }
387  y_out -= frame->linesize[0];
388  u_out -= frame->linesize[1];
389  v_out -= frame->linesize[2];
390  }
391  break;
392  case IMGTYPE_RGB24:
393  for (row = height - 1; row >= 0; row--) {
394  pixel_ptr = row * frame->linesize[0];
395  memcpy(outptr + pixel_ptr, encoded, 3 * width);
396  encoded += 3 * width;
397  }
398  break;
399  case IMGTYPE_YUV411:
400  for (row = 0; row < height; row++) {
401  for (col = 0; col < width - 3; col += 4) {
402  memcpy(y_out + col, encoded, 4);
403  encoded += 4;
404  u_out[col >> 2] = *encoded++ + 128;
405  v_out[col >> 2] = *encoded++ + 128;
406  }
407  y_out -= frame->linesize[0];
408  u_out -= frame->linesize[1];
409  v_out -= frame->linesize[2];
410  }
411  break;
412  case IMGTYPE_YUV211:
413  for (row = 0; row < height; row++) {
414  for (col = 0; col < width - 1; col += 2) {
415  memcpy(y_out + col, encoded, 2);
416  encoded += 2;
417  u_out[col >> 1] = *encoded++ + 128;
418  v_out[col >> 1] = *encoded++ + 128;
419  }
420  y_out -= frame->linesize[0];
421  u_out -= frame->linesize[1];
422  v_out -= frame->linesize[2];
423  }
424  break;
425  case IMGTYPE_YUV420:
426  u_out = frame->data[1] + ((height >> 1) - 1) * frame->linesize[1];
427  v_out = frame->data[2] + ((height >> 1) - 1) * frame->linesize[2];
428  for (row = 0; row < height - 1; row += 2) {
429  for (col = 0; col < width - 1; col += 2) {
430  memcpy(y_out + col, encoded, 2);
431  encoded += 2;
432  memcpy(y_out + col - frame->linesize[0], encoded, 2);
433  encoded += 2;
434  u_out[col >> 1] = *encoded++ + 128;
435  v_out[col >> 1] = *encoded++ + 128;
436  }
437  y_out -= frame->linesize[0] << 1;
438  u_out -= frame->linesize[1];
439  v_out -= frame->linesize[2];
440  }
441  break;
442  default:
443  av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n");
444  return AVERROR_INVALIDDATA;
445  }
446 
447  *got_frame = 1;
448 
449  /* always report that the buffer was completely consumed */
450  return buf_size;
451 }
452 
454 {
455  LclDecContext * const c = avctx->priv_data;
456  unsigned int basesize = avctx->width * avctx->height;
457  unsigned int max_basesize = FFALIGN(avctx->width, 4) *
458  FFALIGN(avctx->height, 4);
459  unsigned int max_decomp_size;
460 
461  if (avctx->extradata_size < 8) {
462  av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n");
463  return AVERROR_INVALIDDATA;
464  }
465 
466  /* Check codec type */
467  if ((avctx->codec_id == AV_CODEC_ID_MSZH && avctx->extradata[7] != CODEC_MSZH) ||
468  (avctx->codec_id == AV_CODEC_ID_ZLIB && avctx->extradata[7] != CODEC_ZLIB)) {
469  av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n");
470  }
471 
472  /* Detect image type */
473  switch (c->imgtype = avctx->extradata[4]) {
474  case IMGTYPE_YUV111:
475  c->decomp_size = basesize * 3;
476  max_decomp_size = max_basesize * 3;
477  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
478  av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 1:1:1.\n");
479  break;
480  case IMGTYPE_YUV422:
481  c->decomp_size = basesize * 2;
482  max_decomp_size = max_basesize * 2;
483  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
484  av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:2.\n");
485  break;
486  case IMGTYPE_RGB24:
487  c->decomp_size = basesize * 3;
488  max_decomp_size = max_basesize * 3;
489  avctx->pix_fmt = AV_PIX_FMT_BGR24;
490  av_log(avctx, AV_LOG_DEBUG, "Image type is RGB 24.\n");
491  break;
492  case IMGTYPE_YUV411:
493  c->decomp_size = basesize / 2 * 3;
494  max_decomp_size = max_basesize / 2 * 3;
495  avctx->pix_fmt = AV_PIX_FMT_YUV411P;
496  av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:1:1.\n");
497  break;
498  case IMGTYPE_YUV211:
499  c->decomp_size = basesize * 2;
500  max_decomp_size = max_basesize * 2;
501  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
502  av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 2:1:1.\n");
503  break;
504  case IMGTYPE_YUV420:
505  c->decomp_size = basesize / 2 * 3;
506  max_decomp_size = max_basesize / 2 * 3;
507  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
508  av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:0.\n");
509  break;
510  default:
511  av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype);
512  return AVERROR_INVALIDDATA;
513  }
514 
515  /* Detect compression method */
516  c->compression = (int8_t)avctx->extradata[5];
517  switch (avctx->codec_id) {
518  case AV_CODEC_ID_MSZH:
519  switch (c->compression) {
520  case COMP_MSZH:
521  av_log(avctx, AV_LOG_DEBUG, "Compression enabled.\n");
522  break;
523  case COMP_MSZH_NOCOMP:
524  c->decomp_size = 0;
525  av_log(avctx, AV_LOG_DEBUG, "No compression.\n");
526  break;
527  default:
528  av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression);
529  return AVERROR_INVALIDDATA;
530  }
531  break;
532 #if CONFIG_ZLIB_DECODER
533  case AV_CODEC_ID_ZLIB:
534  switch (c->compression) {
535  case COMP_ZLIB_HISPEED:
536  av_log(avctx, AV_LOG_DEBUG, "High speed compression.\n");
537  break;
538  case COMP_ZLIB_HICOMP:
539  av_log(avctx, AV_LOG_DEBUG, "High compression.\n");
540  break;
541  case COMP_ZLIB_NORMAL:
542  av_log(avctx, AV_LOG_DEBUG, "Normal compression.\n");
543  break;
544  default:
545  if (c->compression < Z_NO_COMPRESSION || c->compression > Z_BEST_COMPRESSION) {
546  av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression);
547  return AVERROR_INVALIDDATA;
548  }
549  av_log(avctx, AV_LOG_DEBUG, "Compression level for ZLIB: (%d).\n", c->compression);
550  }
551  break;
552 #endif
553  default:
554  av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n");
555  return AVERROR_INVALIDDATA;
556  }
557 
558  /* Allocate decompression buffer */
559  if (c->decomp_size) {
560  if (!(c->decomp_buf = av_malloc(max_decomp_size))) {
561  av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
562  return AVERROR(ENOMEM);
563  }
564  }
565 
566  /* Detect flags */
567  c->flags = avctx->extradata[6];
568  if (c->flags & FLAG_MULTITHREAD)
569  av_log(avctx, AV_LOG_DEBUG, "Multithread encoder flag set.\n");
570  if (c->flags & FLAG_NULLFRAME)
571  av_log(avctx, AV_LOG_DEBUG, "Nullframe insertion flag set.\n");
572  if (avctx->codec_id == AV_CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER))
573  av_log(avctx, AV_LOG_DEBUG, "PNG filter flag set.\n");
574  if (c->flags & FLAGMASK_UNUSED)
575  av_log(avctx, AV_LOG_ERROR, "Unknown flag set (%d).\n", c->flags);
576 
577  /* If needed init zlib */
578 #if CONFIG_ZLIB_DECODER
579  if (avctx->codec_id == AV_CODEC_ID_ZLIB) {
580  int zret;
581  c->zstream.zalloc = Z_NULL;
582  c->zstream.zfree = Z_NULL;
583  c->zstream.opaque = Z_NULL;
584  zret = inflateInit(&c->zstream);
585  if (zret != Z_OK) {
586  av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
587  av_freep(&c->decomp_buf);
588  return AVERROR_UNKNOWN;
589  }
590  }
591 #endif
592 
593  return 0;
594 }
595 
597 {
598  LclDecContext * const c = avctx->priv_data;
599 
600  av_freep(&c->decomp_buf);
601 #if CONFIG_ZLIB_DECODER
602  if (avctx->codec_id == AV_CODEC_ID_ZLIB)
603  inflateEnd(&c->zstream);
604 #endif
605 
606  return 0;
607 }
608 
609 #if CONFIG_MSZH_DECODER
610 AVCodec ff_mszh_decoder = {
611  .name = "mszh",
612  .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) MSZH"),
613  .type = AVMEDIA_TYPE_VIDEO,
614  .id = AV_CODEC_ID_MSZH,
615  .priv_data_size = sizeof(LclDecContext),
616  .init = decode_init,
617  .close = decode_end,
618  .decode = decode_frame,
619  .capabilities = AV_CODEC_CAP_DR1,
620 };
621 #endif
622 
623 #if CONFIG_ZLIB_DECODER
624 AVCodec ff_zlib_decoder = {
625  .name = "zlib",
626  .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"),
627  .type = AVMEDIA_TYPE_VIDEO,
628  .id = AV_CODEC_ID_ZLIB,
629  .priv_data_size = sizeof(LclDecContext),
630  .init = decode_init,
631  .close = decode_end,
632  .decode = decode_frame,
633  .capabilities = AV_CODEC_CAP_DR1,
634 };
635 #endif
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
#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:140
#define COMP_MSZH
Definition: lcl.h:35
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:64
memory handling functions
int size
Definition: avcodec.h:1347
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
#define COMP_ZLIB_HISPEED
Definition: lcl.h:37
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1621
#define AV_RL16
Definition: intreadwrite.h:42
unsigned int decomp_size
Definition: lcldec.c:61
AVCodec.
Definition: avcodec.h:3120
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:202
uint8_t
#define FLAG_PNGFILTER
Definition: lcl.h:43
#define av_cold
Definition: attributes.h:66
#define IMGTYPE_YUV211
Definition: lcl.h:32
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1523
#define COMP_ZLIB_NORMAL
Definition: lcl.h:39
const char data[16]
Definition: mxf.c:70
int imgtype
Definition: lcldec.c:55
uint8_t * data
Definition: avcodec.h:1346
#define IMGTYPE_YUV420
Definition: lcl.h:33
#define FFALIGN(x, a)
Definition: macros.h:48
#define AV_WL16(p, val)
Definition: intreadwrite.h:231
#define IMGTYPE_YUV422
Definition: lcl.h:29
#define src
Definition: vp8dsp.c:254
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: lcldec.c:150
static const uint16_t mask[17]
Definition: lzw.c:38
#define CODEC_ZLIB
Definition: lcl.h:47
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:145
#define IMGTYPE_RGB24
Definition: lcl.h:30
const char * name
Name of the codec implementation.
Definition: avcodec.h:3127
#define FLAGMASK_UNUSED
Definition: lcl.h:44
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:63
#define IMGTYPE_YUV111
Definition: lcl.h:28
#define FFMIN(a, b)
Definition: common.h:66
int width
picture width / height.
Definition: avcodec.h:1580
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: avconv.c:1288
int compression
Definition: lcldec.c:57
#define AV_RL32
Definition: intreadwrite.h:146
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:62
#define IMGTYPE_YUV411
Definition: lcl.h:31
#define CODEC_MSZH
Definition: lcl.h:46
static int width
Definition: utils.c:156
int flags
Definition: lcldec.c:59
unsigned char * decomp_buf
Definition: lcldec.c:63
Libavcodec external API header.
enum AVCodecID codec_id
Definition: avcodec.h:1426
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:158
main external API structure.
Definition: avcodec.h:1409
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:589
#define COMP_ZLIB_HICOMP
Definition: lcl.h:38
int extradata_size
Definition: avcodec.h:1524
#define FLAG_NULLFRAME
Definition: lcl.h:42
static av_cold int decode_end(AVCodecContext *avctx)
Definition: lcldec.c:596
static unsigned int mszh_decomp(const unsigned char *srcptr, int srclen, unsigned char *destptr, unsigned int destsize)
Definition: lcldec.c:74
static av_cold int decode_init(AVCodecContext *avctx)
Definition: lcldec.c:453
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:146
int height
Definition: gxfenc.c:72
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:59
common internal api header.
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:66
#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:582
void * priv_data
Definition: avcodec.h:1451
int len
#define FLAG_MULTITHREAD
Definition: lcl.h:41
#define COMP_MSZH_NOCOMP
Definition: lcl.h:36
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
deliberately overlapping memcpy implementation
Definition: mem.c:325
This structure stores compressed data.
Definition: avcodec.h:1323
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:838