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