Mercurial > libavcodec.hg
annotate lcldec.c @ 9751:705efd6ddaab libavcodec
lcldec.c: change #if CONFIG_ZLIB to #if CONFIG_ZLIB_DECODER.
The zlib related code should not be compiled in when the decoder is disabled
and it thus will never be used, even if we have zlib available.
| author | reimar |
|---|---|
| date | Sun, 31 May 2009 09:16:06 +0000 |
| parents | a87706453840 |
| children | f52c5d54ede5 |
| rev | line source |
|---|---|
| 1743 | 1 /* |
| 2 * LCL (LossLess Codec Library) Codec | |
| 3 * Copyright (c) 2002-2004 Roberto Togni | |
| 4 * | |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3777
diff
changeset
|
5 * This file is part of FFmpeg. |
|
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3777
diff
changeset
|
6 * |
|
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3777
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
| 1743 | 8 * modify it under the terms of the GNU Lesser General Public |
| 9 * License as published by the Free Software Foundation; either | |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3777
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
| 1743 | 11 * |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3777
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
| 1743 | 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 | |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3777
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
|
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2979
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 1743 | 20 */ |
| 21 | |
| 22 /** | |
|
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
8673
diff
changeset
|
23 * @file libavcodec/lcldec.c |
| 1743 | 24 * LCL (LossLess Codec Library) Video Codec |
| 25 * Decoder for MSZH and ZLIB codecs | |
| 26 * Experimental encoder for ZLIB RGB24 | |
| 27 * | |
| 28 * Fourcc: MSZH, ZLIB | |
| 29 * | |
| 30 * Original Win32 dll: | |
| 31 * Ver2.23 By Kenji Oshima 2000.09.20 | |
| 32 * avimszh.dll, avizlib.dll | |
| 33 * | |
| 34 * A description of the decoding algorithm can be found here: | |
| 35 * http://www.pcisys.net/~melanson/codecs | |
| 36 * | |
| 37 * Supports: BGR24 (RGB 24bpp) | |
| 38 * | |
| 39 */ | |
| 40 | |
| 41 #include <stdio.h> | |
| 42 #include <stdlib.h> | |
| 43 | |
|
4962
f99e40a7155b
Remove redundant #inclusion of common.h, avcodec.h already #includes it.
diego
parents:
4827
diff
changeset
|
44 #include "avcodec.h" |
| 9428 | 45 #include "get_bits.h" |
| 5294 | 46 #include "lcl.h" |
| 1743 | 47 |
|
9751
705efd6ddaab
lcldec.c: change #if CONFIG_ZLIB to #if CONFIG_ZLIB_DECODER.
reimar
parents:
9750
diff
changeset
|
48 #if CONFIG_ZLIB_DECODER |
| 1743 | 49 #include <zlib.h> |
| 50 #endif | |
| 51 | |
| 52 /* | |
| 53 * Decoder context | |
| 54 */ | |
| 5294 | 55 typedef struct LclDecContext { |
| 5297 | 56 AVFrame pic; |
| 1743 | 57 |
| 58 // Image type | |
| 59 int imgtype; | |
| 60 // Compression type | |
| 61 int compression; | |
| 62 // Flags | |
| 63 int flags; | |
| 64 // Decompressed data size | |
| 65 unsigned int decomp_size; | |
| 66 // Decompression buffer | |
| 67 unsigned char* decomp_buf; | |
|
9751
705efd6ddaab
lcldec.c: change #if CONFIG_ZLIB to #if CONFIG_ZLIB_DECODER.
reimar
parents:
9750
diff
changeset
|
68 #if CONFIG_ZLIB_DECODER |
| 1743 | 69 z_stream zstream; |
| 70 #endif | |
| 5294 | 71 } LclDecContext; |
| 1743 | 72 |
| 73 | |
|
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
74 static unsigned int mszh_decomp(unsigned char * srcptr, int srclen, unsigned char * destptr, unsigned int destsize) |
| 1743 | 75 { |
| 76 unsigned char *destptr_bak = destptr; | |
|
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
77 unsigned char *destptr_end = destptr + destsize; |
| 1743 | 78 unsigned char mask = 0; |
| 79 unsigned char maskbit = 0; | |
| 80 unsigned int ofs, cnt; | |
| 2967 | 81 |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
82 while (srclen > 0 && destptr < destptr_end) { |
| 1743 | 83 if (maskbit == 0) { |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
84 mask = *srcptr++; |
| 1743 | 85 maskbit = 8; |
| 86 srclen--; | |
| 87 continue; | |
| 88 } | |
| 89 if ((mask & (1 << (--maskbit))) == 0) { | |
|
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
90 if (destptr + 4 > destptr_end) |
|
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
91 break; |
| 9720 | 92 AV_WN32(destptr, AV_RN32(srcptr)); |
| 1743 | 93 srclen -= 4; |
| 94 destptr += 4; | |
| 95 srcptr += 4; | |
| 96 } else { | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
97 ofs = *srcptr++; |
|
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
98 cnt = *srcptr++; |
| 6375 | 99 ofs += cnt * 256; |
| 1743 | 100 cnt = ((cnt >> 3) & 0x1f) + 1; |
| 101 ofs &= 0x7ff; | |
| 102 srclen -= 2; | |
| 103 cnt *= 4; | |
|
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
104 if (destptr + cnt > destptr_end) { |
|
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
105 cnt = destptr_end - destptr; |
|
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
106 } |
| 1743 | 107 for (; cnt > 0; cnt--) { |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
108 *destptr = *(destptr - ofs); |
| 1743 | 109 destptr++; |
| 110 } | |
| 111 } | |
| 112 } | |
| 113 | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
114 return destptr - destptr_bak; |
| 1743 | 115 } |
| 116 | |
| 117 | |
| 118 | |
| 119 /* | |
| 120 * | |
| 121 * Decode a frame | |
| 122 * | |
| 123 */ | |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
124 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) |
| 1743 | 125 { |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
126 const uint8_t *buf = avpkt->data; |
|
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
127 int buf_size = avpkt->size; |
| 5297 | 128 LclDecContext * const c = avctx->priv_data; |
| 129 unsigned char *encoded = (unsigned char *)buf; | |
|
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
130 unsigned int pixel_ptr; |
| 1743 | 131 int row, col; |
| 132 unsigned char *outptr; | |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
133 uint8_t *y_out, *u_out, *v_out; |
| 1743 | 134 unsigned int width = avctx->width; // Real image width |
| 135 unsigned int height = avctx->height; // Real image height | |
| 136 unsigned int mszh_dlen; | |
| 137 unsigned char yq, y1q, uq, vq; | |
| 138 int uqvq; | |
| 139 unsigned int mthread_inlen, mthread_outlen; | |
|
9751
705efd6ddaab
lcldec.c: change #if CONFIG_ZLIB to #if CONFIG_ZLIB_DECODER.
reimar
parents:
9750
diff
changeset
|
140 #if CONFIG_ZLIB_DECODER |
| 1743 | 141 int zret; // Zlib return code |
| 142 #endif | |
|
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
143 unsigned int len = buf_size; |
| 1743 | 144 |
| 5297 | 145 if(c->pic.data[0]) |
| 146 avctx->release_buffer(avctx, &c->pic); | |
| 1743 | 147 |
| 5297 | 148 c->pic.reference = 0; |
| 149 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; | |
| 150 if(avctx->get_buffer(avctx, &c->pic) < 0){ | |
| 151 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | |
| 152 return -1; | |
| 153 } | |
| 1743 | 154 |
| 155 outptr = c->pic.data[0]; // Output image pointer | |
| 156 | |
| 157 /* Decompress frame */ | |
| 158 switch (avctx->codec_id) { | |
| 5297 | 159 case CODEC_ID_MSZH: |
| 160 switch (c->compression) { | |
| 161 case COMP_MSZH: | |
| 1743 | 162 if (c->flags & FLAG_MULTITHREAD) { |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
163 mthread_inlen = *(unsigned int*)encoded; |
|
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
164 mthread_outlen = *(unsigned int*)(encoded+4); |
| 5297 | 165 if (mthread_outlen > c->decomp_size) // this should not happen |
|
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
166 mthread_outlen = c->decomp_size; |
| 5297 | 167 mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf, c->decomp_size); |
| 168 if (mthread_outlen != mszh_dlen) { | |
| 169 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n", | |
| 170 mthread_outlen, mszh_dlen); | |
| 1743 | 171 return -1; |
| 172 } | |
| 5297 | 173 mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - mthread_inlen, |
| 174 c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen); | |
| 175 if (mthread_outlen != mszh_dlen) { | |
| 176 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n", | |
| 177 mthread_outlen, mszh_dlen); | |
|
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
178 return -1; |
| 1743 | 179 } |
| 5297 | 180 encoded = c->decomp_buf; |
| 181 len = c->decomp_size; | |
| 182 } else { | |
| 183 mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf, c->decomp_size); | |
| 184 if (c->decomp_size != mszh_dlen) { | |
| 185 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n", | |
| 186 c->decomp_size, mszh_dlen); | |
| 1743 | 187 return -1; |
| 188 } | |
| 5297 | 189 encoded = c->decomp_buf; |
| 190 len = mszh_dlen; | |
| 1743 | 191 } |
| 5297 | 192 break; |
| 193 case COMP_MSZH_NOCOMP: | |
| 1743 | 194 break; |
| 195 default: | |
| 5297 | 196 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n"); |
| 197 return -1; | |
| 198 } | |
| 199 break; | |
| 200 case CODEC_ID_ZLIB: | |
|
9751
705efd6ddaab
lcldec.c: change #if CONFIG_ZLIB to #if CONFIG_ZLIB_DECODER.
reimar
parents:
9750
diff
changeset
|
201 #if CONFIG_ZLIB_DECODER |
| 5297 | 202 /* Using the original dll with normal compression (-1) and RGB format |
| 203 * gives a file with ZLIB fourcc, but frame is really uncompressed. | |
| 204 * To be sure that's true check also frame size */ | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
205 if (c->compression == COMP_ZLIB_NORMAL && c->imgtype == IMGTYPE_RGB24 && |
|
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
206 len == width * height * 3) |
| 5297 | 207 break; |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
208 zret = inflateReset(&c->zstream); |
| 5297 | 209 if (zret != Z_OK) { |
| 210 av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); | |
| 1743 | 211 return -1; |
| 5297 | 212 } |
| 213 if (c->flags & FLAG_MULTITHREAD) { | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
214 mthread_inlen = *(unsigned int*)encoded; |
|
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
215 mthread_outlen = *(unsigned int*)(encoded+4); |
| 5297 | 216 if (mthread_outlen > c->decomp_size) |
| 217 mthread_outlen = c->decomp_size; | |
| 218 c->zstream.next_in = encoded + 8; | |
| 219 c->zstream.avail_in = mthread_inlen; | |
| 220 c->zstream.next_out = c->decomp_buf; | |
| 221 c->zstream.avail_out = c->decomp_size; | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
222 zret = inflate(&c->zstream, Z_FINISH); |
|
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
223 if (zret != Z_OK && zret != Z_STREAM_END) { |
| 5297 | 224 av_log(avctx, AV_LOG_ERROR, "Mthread1 inflate error: %d\n", zret); |
| 225 return -1; | |
| 226 } | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
227 if (mthread_outlen != (unsigned int)c->zstream.total_out) { |
| 5297 | 228 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%u != %lu)\n", |
| 229 mthread_outlen, c->zstream.total_out); | |
| 230 return -1; | |
| 231 } | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
232 zret = inflateReset(&c->zstream); |
| 5297 | 233 if (zret != Z_OK) { |
| 234 av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate reset error: %d\n", zret); | |
| 235 return -1; | |
| 236 } | |
| 237 c->zstream.next_in = encoded + 8 + mthread_inlen; | |
| 238 c->zstream.avail_in = len - mthread_inlen; | |
| 239 c->zstream.next_out = c->decomp_buf + mthread_outlen; | |
| 240 c->zstream.avail_out = c->decomp_size - mthread_outlen; | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
241 zret = inflate(&c->zstream, Z_FINISH); |
|
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
242 if (zret != Z_OK && zret != Z_STREAM_END) { |
| 5297 | 243 av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate error: %d\n", zret); |
| 244 return -1; | |
| 245 } | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
246 if (mthread_outlen != (unsigned int)c->zstream.total_out) { |
| 5297 | 247 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %lu)\n", |
| 248 mthread_outlen, c->zstream.total_out); | |
| 249 return -1; | |
| 250 } | |
| 251 } else { | |
| 252 c->zstream.next_in = encoded; | |
| 253 c->zstream.avail_in = len; | |
| 254 c->zstream.next_out = c->decomp_buf; | |
| 255 c->zstream.avail_out = c->decomp_size; | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
256 zret = inflate(&c->zstream, Z_FINISH); |
|
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
257 if (zret != Z_OK && zret != Z_STREAM_END) { |
| 5297 | 258 av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); |
| 259 return -1; | |
| 260 } | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
261 if (c->decomp_size != (unsigned int)c->zstream.total_out) { |
| 5297 | 262 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", |
| 263 c->decomp_size, c->zstream.total_out); | |
| 264 return -1; | |
| 265 } | |
| 266 } | |
| 267 encoded = c->decomp_buf; | |
| 6375 | 268 len = c->decomp_size; |
| 5297 | 269 #else |
| 270 av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n"); | |
| 271 return -1; | |
| 272 #endif | |
| 273 break; | |
| 274 default: | |
| 275 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n"); | |
| 276 return -1; | |
| 1743 | 277 } |
| 278 | |
| 279 | |
| 280 /* Apply PNG filter */ | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
281 if (avctx->codec_id == CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER)) { |
| 1743 | 282 switch (c->imgtype) { |
| 5297 | 283 case IMGTYPE_YUV111: |
| 284 case IMGTYPE_RGB24: | |
| 285 for (row = 0; row < height; row++) { | |
| 286 pixel_ptr = row * width * 3; | |
| 287 yq = encoded[pixel_ptr++]; | |
| 288 uqvq = AV_RL16(encoded+pixel_ptr); | |
| 289 pixel_ptr += 2; | |
| 290 for (col = 1; col < width; col++) { | |
| 291 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
| 292 uqvq -= AV_RL16(encoded+pixel_ptr+1); | |
| 293 AV_WL16(encoded+pixel_ptr+1, uqvq); | |
| 294 pixel_ptr += 3; | |
| 1743 | 295 } |
| 5297 | 296 } |
| 297 break; | |
| 298 case IMGTYPE_YUV422: | |
| 299 for (row = 0; row < height; row++) { | |
| 300 pixel_ptr = row * width * 2; | |
| 301 yq = uq = vq =0; | |
| 302 for (col = 0; col < width/4; col++) { | |
| 303 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
| 304 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | |
| 305 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; | |
| 306 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; | |
| 307 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; | |
| 308 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5]; | |
| 309 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6]; | |
| 310 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7]; | |
| 311 pixel_ptr += 8; | |
| 1743 | 312 } |
| 5297 | 313 } |
| 314 break; | |
| 315 case IMGTYPE_YUV411: | |
| 316 for (row = 0; row < height; row++) { | |
| 317 pixel_ptr = row * width / 2 * 3; | |
| 318 yq = uq = vq =0; | |
| 319 for (col = 0; col < width/4; col++) { | |
| 320 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
| 321 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | |
| 322 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; | |
| 323 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; | |
| 324 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; | |
| 325 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; | |
| 326 pixel_ptr += 6; | |
| 1743 | 327 } |
| 5297 | 328 } |
| 329 break; | |
| 330 case IMGTYPE_YUV211: | |
| 331 for (row = 0; row < height; row++) { | |
| 332 pixel_ptr = row * width * 2; | |
| 333 yq = uq = vq =0; | |
| 334 for (col = 0; col < width/2; col++) { | |
| 335 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
| 336 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | |
| 337 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2]; | |
| 338 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3]; | |
| 339 pixel_ptr += 4; | |
| 1743 | 340 } |
| 5297 | 341 } |
| 342 break; | |
| 343 case IMGTYPE_YUV420: | |
| 344 for (row = 0; row < height/2; row++) { | |
| 345 pixel_ptr = row * width * 3; | |
| 346 yq = y1q = 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] = y1q -= encoded[pixel_ptr+2]; | |
| 351 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3]; | |
| 352 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; | |
| 353 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; | |
| 354 pixel_ptr += 6; | |
| 1743 | 355 } |
| 5297 | 356 } |
| 357 break; | |
| 358 default: | |
| 359 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n"); | |
| 360 return -1; | |
| 1743 | 361 } |
| 362 } | |
| 363 | |
| 364 /* Convert colorspace */ | |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
365 y_out = c->pic.data[0] + (height - 1) * c->pic.linesize[0]; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
366 u_out = c->pic.data[1] + (height - 1) * c->pic.linesize[1]; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
367 v_out = c->pic.data[2] + (height - 1) * c->pic.linesize[2]; |
| 1743 | 368 switch (c->imgtype) { |
| 5297 | 369 case IMGTYPE_YUV111: |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
370 for (row = 0; row < height; row++) { |
| 5297 | 371 for (col = 0; col < width; col++) { |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
372 y_out[col] = *encoded++; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
373 u_out[col] = *encoded++ + 128; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
374 v_out[col] = *encoded++ + 128; |
| 1743 | 375 } |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
376 y_out -= c->pic.linesize[0]; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
377 u_out -= c->pic.linesize[1]; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
378 v_out -= c->pic.linesize[2]; |
| 5297 | 379 } |
| 380 break; | |
| 381 case IMGTYPE_YUV422: | |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
382 for (row = 0; row < height; row++) { |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
383 for (col = 0; col < width - 3; col += 4) { |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
384 memcpy(y_out + col, encoded, 4); |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
385 encoded += 4; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
386 u_out[ col >> 1 ] = *encoded++ + 128; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
387 u_out[(col >> 1) + 1] = *encoded++ + 128; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
388 v_out[ col >> 1 ] = *encoded++ + 128; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
389 v_out[(col >> 1) + 1] = *encoded++ + 128; |
| 1743 | 390 } |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
391 y_out -= c->pic.linesize[0]; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
392 u_out -= c->pic.linesize[1]; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
393 v_out -= c->pic.linesize[2]; |
| 5297 | 394 } |
| 395 break; | |
| 396 case IMGTYPE_RGB24: | |
| 397 for (row = height - 1; row >= 0; row--) { | |
| 398 pixel_ptr = row * c->pic.linesize[0]; | |
|
9738
d5929e456b07
Use memcpy instead of per-pixel copy loop for rgb lcl format
reimar
parents:
9736
diff
changeset
|
399 memcpy(outptr + pixel_ptr, encoded, 3 * width); |
|
d5929e456b07
Use memcpy instead of per-pixel copy loop for rgb lcl format
reimar
parents:
9736
diff
changeset
|
400 encoded += 3 * width; |
| 5297 | 401 } |
| 402 break; | |
| 403 case IMGTYPE_YUV411: | |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
404 for (row = 0; row < height; row++) { |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
405 for (col = 0; col < width - 3; col += 4) { |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
406 memcpy(y_out + col, encoded, 4); |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
407 encoded += 4; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
408 u_out[col >> 2] = *encoded++ + 128; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
409 v_out[col >> 2] = *encoded++ + 128; |
| 1743 | 410 } |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
411 y_out -= c->pic.linesize[0]; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
412 u_out -= c->pic.linesize[1]; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
413 v_out -= c->pic.linesize[2]; |
| 5297 | 414 } |
| 415 break; | |
| 416 case IMGTYPE_YUV211: | |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
417 for (row = 0; row < height; row++) { |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
418 for (col = 0; col < width - 1; col += 2) { |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
419 memcpy(y_out + col, encoded, 2); |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
420 encoded += 2; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
421 u_out[col >> 1] = *encoded++ + 128; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
422 v_out[col >> 1] = *encoded++ + 128; |
| 1743 | 423 } |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
424 y_out -= c->pic.linesize[0]; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
425 u_out -= c->pic.linesize[1]; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
426 v_out -= c->pic.linesize[2]; |
| 5297 | 427 } |
| 428 break; | |
| 429 case IMGTYPE_YUV420: | |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
430 u_out = c->pic.data[1] + ((height >> 1) - 1) * c->pic.linesize[1]; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
431 v_out = c->pic.data[2] + ((height >> 1) - 1) * c->pic.linesize[2]; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
432 for (row = 0; row < height - 1; row += 2) { |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
433 for (col = 0; col < width - 1; col += 2) { |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
434 memcpy(y_out + col, encoded, 2); |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
435 encoded += 2; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
436 memcpy(y_out + col - c->pic.linesize[0], encoded, 2); |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
437 encoded += 2; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
438 u_out[col >> 1] = *encoded++ + 128; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
439 v_out[col >> 1] = *encoded++ + 128; |
| 1743 | 440 } |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
441 y_out -= c->pic.linesize[0] << 1; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
442 u_out -= c->pic.linesize[1]; |
|
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
443 v_out -= c->pic.linesize[2]; |
| 5297 | 444 } |
| 445 break; | |
| 446 default: | |
| 447 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n"); | |
| 448 return -1; | |
| 1743 | 449 } |
| 450 | |
| 451 *data_size = sizeof(AVFrame); | |
| 452 *(AVFrame*)data = c->pic; | |
| 453 | |
| 454 /* always report that the buffer was completely consumed */ | |
| 455 return buf_size; | |
| 456 } | |
| 457 | |
| 458 /* | |
| 459 * | |
| 460 * Init lcl decoder | |
| 461 * | |
| 462 */ | |
|
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6375
diff
changeset
|
463 static av_cold int decode_init(AVCodecContext *avctx) |
| 1743 | 464 { |
| 5294 | 465 LclDecContext * const c = avctx->priv_data; |
|
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
466 unsigned int basesize = avctx->width * avctx->height; |
|
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
467 unsigned int max_basesize = ((avctx->width + 3) & ~3) * ((avctx->height + 3) & ~3); |
|
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
468 unsigned int max_decomp_size; |
| 1743 | 469 int zret; // Zlib return code |
| 470 | |
| 471 c->pic.data[0] = NULL; | |
| 472 | |
|
9751
705efd6ddaab
lcldec.c: change #if CONFIG_ZLIB to #if CONFIG_ZLIB_DECODER.
reimar
parents:
9750
diff
changeset
|
473 #if CONFIG_ZLIB_DECODER |
| 1743 | 474 // Needed if zlib unused or init aborted before inflateInit |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
475 memset(&c->zstream, 0, sizeof(z_stream)); |
| 1743 | 476 #endif |
| 477 | |
| 478 if (avctx->extradata_size < 8) { | |
| 479 av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n"); | |
| 480 return 1; | |
| 481 } | |
| 482 | |
|
2429
4b350cc506a7
Use avcodec_check_dimensions instead of custom hack
rtognimp
parents:
2418
diff
changeset
|
483 if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { |
|
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
484 return 1; |
|
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
485 } |
|
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
486 |
| 2967 | 487 /* Check codec type */ |
|
9750
a87706453840
Get rid of extradata casts, it already has the right uint8_t * type
reimar
parents:
9749
diff
changeset
|
488 if ((avctx->codec_id == CODEC_ID_MSZH && avctx->extradata[7] != CODEC_MSZH) || |
|
a87706453840
Get rid of extradata casts, it already has the right uint8_t * type
reimar
parents:
9749
diff
changeset
|
489 (avctx->codec_id == CODEC_ID_ZLIB && avctx->extradata[7] != CODEC_ZLIB)) { |
| 1743 | 490 av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n"); |
| 491 } | |
| 492 | |
| 493 /* Detect image type */ | |
|
9750
a87706453840
Get rid of extradata casts, it already has the right uint8_t * type
reimar
parents:
9749
diff
changeset
|
494 switch (c->imgtype = avctx->extradata[4]) { |
| 5297 | 495 case IMGTYPE_YUV111: |
| 496 c->decomp_size = basesize * 3; | |
| 497 max_decomp_size = max_basesize * 3; | |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
498 avctx->pix_fmt = PIX_FMT_YUV444P; |
| 5297 | 499 av_log(avctx, AV_LOG_INFO, "Image type is YUV 1:1:1.\n"); |
| 500 break; | |
| 501 case IMGTYPE_YUV422: | |
| 502 c->decomp_size = basesize * 2; | |
| 503 max_decomp_size = max_basesize * 2; | |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
504 avctx->pix_fmt = PIX_FMT_YUV422P; |
| 5297 | 505 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:2.\n"); |
| 506 break; | |
| 507 case IMGTYPE_RGB24: | |
| 508 c->decomp_size = basesize * 3; | |
| 509 max_decomp_size = max_basesize * 3; | |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
510 avctx->pix_fmt = PIX_FMT_BGR24; |
| 5297 | 511 av_log(avctx, AV_LOG_INFO, "Image type is RGB 24.\n"); |
| 512 break; | |
| 513 case IMGTYPE_YUV411: | |
| 514 c->decomp_size = basesize / 2 * 3; | |
| 515 max_decomp_size = max_basesize / 2 * 3; | |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
516 avctx->pix_fmt = PIX_FMT_YUV411P; |
| 5297 | 517 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:1:1.\n"); |
| 518 break; | |
| 519 case IMGTYPE_YUV211: | |
| 520 c->decomp_size = basesize * 2; | |
| 521 max_decomp_size = max_basesize * 2; | |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
522 avctx->pix_fmt = PIX_FMT_YUV422P; |
| 5297 | 523 av_log(avctx, AV_LOG_INFO, "Image type is YUV 2:1:1.\n"); |
| 524 break; | |
| 525 case IMGTYPE_YUV420: | |
| 526 c->decomp_size = basesize / 2 * 3; | |
| 527 max_decomp_size = max_basesize / 2 * 3; | |
|
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
528 avctx->pix_fmt = PIX_FMT_YUV420P; |
| 5297 | 529 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:0.\n"); |
| 530 break; | |
| 531 default: | |
| 532 av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype); | |
| 533 return 1; | |
| 1743 | 534 } |
| 535 | |
| 536 /* Detect compression method */ | |
|
9750
a87706453840
Get rid of extradata casts, it already has the right uint8_t * type
reimar
parents:
9749
diff
changeset
|
537 c->compression = avctx->extradata[5]; |
| 1743 | 538 switch (avctx->codec_id) { |
| 5297 | 539 case CODEC_ID_MSZH: |
| 540 switch (c->compression) { | |
| 541 case COMP_MSZH: | |
| 542 av_log(avctx, AV_LOG_INFO, "Compression enabled.\n"); | |
| 1743 | 543 break; |
| 5297 | 544 case COMP_MSZH_NOCOMP: |
| 545 c->decomp_size = 0; | |
| 546 av_log(avctx, AV_LOG_INFO, "No compression.\n"); | |
| 1743 | 547 break; |
| 548 default: | |
| 5297 | 549 av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression); |
| 1743 | 550 return 1; |
| 5297 | 551 } |
| 552 break; | |
| 553 case CODEC_ID_ZLIB: | |
|
9751
705efd6ddaab
lcldec.c: change #if CONFIG_ZLIB to #if CONFIG_ZLIB_DECODER.
reimar
parents:
9750
diff
changeset
|
554 #if CONFIG_ZLIB_DECODER |
| 5297 | 555 switch (c->compression) { |
| 556 case COMP_ZLIB_HISPEED: | |
| 557 av_log(avctx, AV_LOG_INFO, "High speed compression.\n"); | |
| 558 break; | |
| 559 case COMP_ZLIB_HICOMP: | |
| 560 av_log(avctx, AV_LOG_INFO, "High compression.\n"); | |
| 561 break; | |
| 562 case COMP_ZLIB_NORMAL: | |
| 563 av_log(avctx, AV_LOG_INFO, "Normal compression.\n"); | |
| 564 break; | |
| 565 default: | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
566 if (c->compression < Z_NO_COMPRESSION || c->compression > Z_BEST_COMPRESSION) { |
| 5297 | 567 av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression); |
| 568 return 1; | |
| 569 } | |
| 570 av_log(avctx, AV_LOG_INFO, "Compression level for ZLIB: (%d).\n", c->compression); | |
| 571 } | |
| 572 #else | |
| 573 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); | |
| 574 return 1; | |
| 575 #endif | |
| 576 break; | |
| 577 default: | |
| 578 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n"); | |
| 579 return 1; | |
| 1743 | 580 } |
| 581 | |
| 582 /* Allocate decompression buffer */ | |
| 583 if (c->decomp_size) { | |
|
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
584 if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) { |
| 1743 | 585 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); |
| 586 return 1; | |
| 587 } | |
| 588 } | |
| 2967 | 589 |
| 590 /* Detect flags */ | |
|
9750
a87706453840
Get rid of extradata casts, it already has the right uint8_t * type
reimar
parents:
9749
diff
changeset
|
591 c->flags = avctx->extradata[6]; |
| 1743 | 592 if (c->flags & FLAG_MULTITHREAD) |
| 593 av_log(avctx, AV_LOG_INFO, "Multithread encoder flag set.\n"); | |
| 594 if (c->flags & FLAG_NULLFRAME) | |
| 595 av_log(avctx, AV_LOG_INFO, "Nullframe insertion flag set.\n"); | |
| 596 if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) | |
| 597 av_log(avctx, AV_LOG_INFO, "PNG filter flag set.\n"); | |
| 598 if (c->flags & FLAGMASK_UNUSED) | |
| 599 av_log(avctx, AV_LOG_ERROR, "Unknown flag set (%d).\n", c->flags); | |
| 600 | |
| 601 /* If needed init zlib */ | |
| 602 if (avctx->codec_id == CODEC_ID_ZLIB) { | |
|
9751
705efd6ddaab
lcldec.c: change #if CONFIG_ZLIB to #if CONFIG_ZLIB_DECODER.
reimar
parents:
9750
diff
changeset
|
603 #if CONFIG_ZLIB_DECODER |
| 1743 | 604 c->zstream.zalloc = Z_NULL; |
| 605 c->zstream.zfree = Z_NULL; | |
| 606 c->zstream.opaque = Z_NULL; | |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
607 zret = inflateInit(&c->zstream); |
| 1743 | 608 if (zret != Z_OK) { |
| 609 av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); | |
| 610 return 1; | |
| 611 } | |
| 612 #else | |
| 5297 | 613 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); |
| 614 return 1; | |
| 1743 | 615 #endif |
| 616 } | |
| 617 | |
| 618 return 0; | |
| 619 } | |
| 620 | |
| 621 /* | |
| 622 * | |
| 623 * Uninit lcl decoder | |
| 624 * | |
| 625 */ | |
|
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6375
diff
changeset
|
626 static av_cold int decode_end(AVCodecContext *avctx) |
| 1743 | 627 { |
| 5297 | 628 LclDecContext * const c = avctx->priv_data; |
| 1743 | 629 |
| 5297 | 630 if (c->pic.data[0]) |
| 631 avctx->release_buffer(avctx, &c->pic); | |
|
9751
705efd6ddaab
lcldec.c: change #if CONFIG_ZLIB to #if CONFIG_ZLIB_DECODER.
reimar
parents:
9750
diff
changeset
|
632 #if CONFIG_ZLIB_DECODER |
|
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
633 inflateEnd(&c->zstream); |
| 1743 | 634 #endif |
| 635 | |
| 5297 | 636 return 0; |
| 1743 | 637 } |
| 638 | |
| 8590 | 639 #if CONFIG_MSZH_DECODER |
| 1743 | 640 AVCodec mszh_decoder = { |
| 5297 | 641 "mszh", |
| 642 CODEC_TYPE_VIDEO, | |
| 643 CODEC_ID_MSZH, | |
| 644 sizeof(LclDecContext), | |
| 645 decode_init, | |
| 646 NULL, | |
| 647 decode_end, | |
| 648 decode_frame, | |
| 649 CODEC_CAP_DR1, | |
|
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6712
diff
changeset
|
650 .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) MSZH"), |
| 1743 | 651 }; |
| 3777 | 652 #endif |
| 1743 | 653 |
| 8590 | 654 #if CONFIG_ZLIB_DECODER |
| 1743 | 655 AVCodec zlib_decoder = { |
| 5297 | 656 "zlib", |
| 657 CODEC_TYPE_VIDEO, | |
| 658 CODEC_ID_ZLIB, | |
| 659 sizeof(LclDecContext), | |
| 660 decode_init, | |
| 661 NULL, | |
| 662 decode_end, | |
| 663 decode_frame, | |
| 664 CODEC_CAP_DR1, | |
|
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6712
diff
changeset
|
665 .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"), |
| 1743 | 666 }; |
| 3777 | 667 #endif |
