You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

644 lines
21KB

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