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