Mercurial > libavcodec.hg
annotate lcldec.c @ 9758:8ebcc162db3d libavcodec
Add sanity check for mthread_inlen, avoids crashes due to invalid reads.
author | reimar |
---|---|
date | Sun, 31 May 2009 09:59:46 +0000 |
parents | 8e4d442554b3 |
children | 5968a9f15535 |
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 | |
9756
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
118 /** |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
119 * \brief decompress a zlib-compressed data block into decomp_buf |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
120 * \param src compressed input buffer |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
121 * \param src_len data length in input buffer |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
122 * \param offset offset in decomp_buf |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
123 * \param expected expected decompressed length |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
124 */ |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
125 static int zlib_decomp(AVCodecContext *avctx, const uint8_t *src, int src_len, int offset, int expected) |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
126 { |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
127 LclDecContext *c = avctx->priv_data; |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
128 int zret = inflateReset(&c->zstream); |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
129 if (zret != Z_OK) { |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
130 av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
131 return -1; |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
132 } |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
133 c->zstream.next_in = src; |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
134 c->zstream.avail_in = src_len; |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
135 c->zstream.next_out = c->decomp_buf + offset; |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
136 c->zstream.avail_out = c->decomp_size - offset; |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
137 zret = inflate(&c->zstream, Z_FINISH); |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
138 if (zret != Z_OK && zret != Z_STREAM_END) { |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
139 av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
140 return -1; |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
141 } |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
142 if (expected != (unsigned int)c->zstream.total_out) { |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
143 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
144 expected, c->zstream.total_out); |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
145 return -1; |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
146 } |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
147 return c->zstream.total_out; |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
148 } |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
149 |
1743 | 150 |
151 /* | |
152 * | |
153 * Decode a frame | |
154 * | |
155 */ | |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
156 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) |
1743 | 157 { |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
158 const uint8_t *buf = avpkt->data; |
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
159 int buf_size = avpkt->size; |
5297 | 160 LclDecContext * const c = avctx->priv_data; |
161 unsigned char *encoded = (unsigned char *)buf; | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
162 unsigned int pixel_ptr; |
1743 | 163 int row, col; |
164 unsigned char *outptr; | |
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
165 uint8_t *y_out, *u_out, *v_out; |
1743 | 166 unsigned int width = avctx->width; // Real image width |
167 unsigned int height = avctx->height; // Real image height | |
168 unsigned int mszh_dlen; | |
169 unsigned char yq, y1q, uq, vq; | |
170 int uqvq; | |
171 unsigned int mthread_inlen, mthread_outlen; | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
172 unsigned int len = buf_size; |
1743 | 173 |
5297 | 174 if(c->pic.data[0]) |
175 avctx->release_buffer(avctx, &c->pic); | |
1743 | 176 |
5297 | 177 c->pic.reference = 0; |
178 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; | |
179 if(avctx->get_buffer(avctx, &c->pic) < 0){ | |
180 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | |
181 return -1; | |
182 } | |
1743 | 183 |
184 outptr = c->pic.data[0]; // Output image pointer | |
185 | |
186 /* Decompress frame */ | |
187 switch (avctx->codec_id) { | |
5297 | 188 case CODEC_ID_MSZH: |
189 switch (c->compression) { | |
190 case COMP_MSZH: | |
1743 | 191 if (c->flags & FLAG_MULTITHREAD) { |
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
192 mthread_inlen = *(unsigned int*)encoded; |
9758
8ebcc162db3d
Add sanity check for mthread_inlen, avoids crashes due to invalid reads.
reimar
parents:
9757
diff
changeset
|
193 mthread_inlen = FFMIN(mthread_inlen, len - 8); |
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
194 mthread_outlen = *(unsigned int*)(encoded+4); |
9757 | 195 mthread_outlen = FFMIN(mthread_outlen, c->decomp_size); |
5297 | 196 mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf, c->decomp_size); |
197 if (mthread_outlen != mszh_dlen) { | |
198 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n", | |
199 mthread_outlen, mszh_dlen); | |
1743 | 200 return -1; |
201 } | |
5297 | 202 mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - mthread_inlen, |
203 c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen); | |
204 if (mthread_outlen != mszh_dlen) { | |
205 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n", | |
206 mthread_outlen, mszh_dlen); | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
207 return -1; |
1743 | 208 } |
5297 | 209 encoded = c->decomp_buf; |
210 len = c->decomp_size; | |
211 } else { | |
212 mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf, c->decomp_size); | |
213 if (c->decomp_size != mszh_dlen) { | |
214 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n", | |
215 c->decomp_size, mszh_dlen); | |
1743 | 216 return -1; |
217 } | |
5297 | 218 encoded = c->decomp_buf; |
219 len = mszh_dlen; | |
1743 | 220 } |
5297 | 221 break; |
222 case COMP_MSZH_NOCOMP: | |
1743 | 223 break; |
224 default: | |
5297 | 225 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n"); |
226 return -1; | |
227 } | |
228 break; | |
9752
f52c5d54ede5
Get rid of unreachable code: avctx->codec_id == CODEC_ID_ZLIB is not possible
reimar
parents:
9751
diff
changeset
|
229 #if CONFIG_ZLIB_DECODER |
5297 | 230 case CODEC_ID_ZLIB: |
231 /* Using the original dll with normal compression (-1) and RGB format | |
232 * gives a file with ZLIB fourcc, but frame is really uncompressed. | |
233 * 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
|
234 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
|
235 len == width * height * 3) |
5297 | 236 break; |
237 if (c->flags & FLAG_MULTITHREAD) { | |
9756
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
238 int ret; |
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
239 mthread_inlen = *(unsigned int*)encoded; |
9758
8ebcc162db3d
Add sanity check for mthread_inlen, avoids crashes due to invalid reads.
reimar
parents:
9757
diff
changeset
|
240 mthread_inlen = FFMIN(mthread_inlen, len - 8); |
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
241 mthread_outlen = *(unsigned int*)(encoded+4); |
9757 | 242 mthread_outlen = FFMIN(mthread_outlen, c->decomp_size); |
9756
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
243 ret = zlib_decomp(avctx, encoded + 8, mthread_inlen, 0, mthread_outlen); |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
244 if (ret < 0) return ret; |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
245 ret = zlib_decomp(avctx, encoded + 8 + mthread_inlen, len - mthread_inlen, |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
246 mthread_outlen, mthread_outlen); |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
247 if (ret < 0) return ret; |
5297 | 248 } else { |
9756
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
249 int ret = zlib_decomp(avctx, encoded, len, 0, c->decomp_size); |
ed55b61c8e45
Factor out zlib decompression code to avoid massive code duplication,
reimar
parents:
9755
diff
changeset
|
250 if (ret < 0) return ret; |
5297 | 251 } |
252 encoded = c->decomp_buf; | |
6375 | 253 len = c->decomp_size; |
9752
f52c5d54ede5
Get rid of unreachable code: avctx->codec_id == CODEC_ID_ZLIB is not possible
reimar
parents:
9751
diff
changeset
|
254 break; |
5297 | 255 #endif |
256 default: | |
257 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n"); | |
258 return -1; | |
1743 | 259 } |
260 | |
261 | |
262 /* Apply PNG filter */ | |
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
263 if (avctx->codec_id == CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER)) { |
1743 | 264 switch (c->imgtype) { |
5297 | 265 case IMGTYPE_YUV111: |
266 case IMGTYPE_RGB24: | |
267 for (row = 0; row < height; row++) { | |
268 pixel_ptr = row * width * 3; | |
269 yq = encoded[pixel_ptr++]; | |
270 uqvq = AV_RL16(encoded+pixel_ptr); | |
271 pixel_ptr += 2; | |
272 for (col = 1; col < width; col++) { | |
273 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
274 uqvq -= AV_RL16(encoded+pixel_ptr+1); | |
275 AV_WL16(encoded+pixel_ptr+1, uqvq); | |
276 pixel_ptr += 3; | |
1743 | 277 } |
5297 | 278 } |
279 break; | |
280 case IMGTYPE_YUV422: | |
281 for (row = 0; row < height; row++) { | |
282 pixel_ptr = row * width * 2; | |
283 yq = uq = vq =0; | |
284 for (col = 0; col < width/4; col++) { | |
285 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
286 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | |
287 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; | |
288 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; | |
289 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; | |
290 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5]; | |
291 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6]; | |
292 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7]; | |
293 pixel_ptr += 8; | |
1743 | 294 } |
5297 | 295 } |
296 break; | |
297 case IMGTYPE_YUV411: | |
298 for (row = 0; row < height; row++) { | |
299 pixel_ptr = row * width / 2 * 3; | |
300 yq = uq = vq =0; | |
301 for (col = 0; col < width/4; col++) { | |
302 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
303 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | |
304 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; | |
305 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; | |
306 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; | |
307 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; | |
308 pixel_ptr += 6; | |
1743 | 309 } |
5297 | 310 } |
311 break; | |
312 case IMGTYPE_YUV211: | |
313 for (row = 0; row < height; row++) { | |
314 pixel_ptr = row * width * 2; | |
315 yq = uq = vq =0; | |
316 for (col = 0; col < width/2; col++) { | |
317 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
318 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | |
319 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2]; | |
320 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3]; | |
321 pixel_ptr += 4; | |
1743 | 322 } |
5297 | 323 } |
324 break; | |
325 case IMGTYPE_YUV420: | |
326 for (row = 0; row < height/2; row++) { | |
327 pixel_ptr = row * width * 3; | |
328 yq = y1q = uq = vq =0; | |
329 for (col = 0; col < width/2; col++) { | |
330 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
331 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | |
332 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2]; | |
333 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3]; | |
334 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; | |
335 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; | |
336 pixel_ptr += 6; | |
1743 | 337 } |
5297 | 338 } |
339 break; | |
340 default: | |
341 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n"); | |
342 return -1; | |
1743 | 343 } |
344 } | |
345 | |
346 /* Convert colorspace */ | |
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
347 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
|
348 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
|
349 v_out = c->pic.data[2] + (height - 1) * c->pic.linesize[2]; |
1743 | 350 switch (c->imgtype) { |
5297 | 351 case IMGTYPE_YUV111: |
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
352 for (row = 0; row < height; row++) { |
5297 | 353 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
|
354 y_out[col] = *encoded++; |
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
355 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
|
356 v_out[col] = *encoded++ + 128; |
1743 | 357 } |
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
358 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
|
359 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
|
360 v_out -= c->pic.linesize[2]; |
5297 | 361 } |
362 break; | |
363 case IMGTYPE_YUV422: | |
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
364 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
|
365 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
|
366 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
|
367 encoded += 4; |
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
368 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
|
369 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
|
370 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
|
371 v_out[(col >> 1) + 1] = *encoded++ + 128; |
1743 | 372 } |
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
373 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
|
374 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
|
375 v_out -= c->pic.linesize[2]; |
5297 | 376 } |
377 break; | |
378 case IMGTYPE_RGB24: | |
379 for (row = height - 1; row >= 0; row--) { | |
380 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
|
381 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
|
382 encoded += 3 * width; |
5297 | 383 } |
384 break; | |
385 case IMGTYPE_YUV411: | |
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
386 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
|
387 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
|
388 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
|
389 encoded += 4; |
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
390 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
|
391 v_out[col >> 2] = *encoded++ + 128; |
1743 | 392 } |
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
393 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
|
394 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
|
395 v_out -= c->pic.linesize[2]; |
5297 | 396 } |
397 break; | |
398 case IMGTYPE_YUV211: | |
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
399 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
|
400 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
|
401 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
|
402 encoded += 2; |
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
403 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
|
404 v_out[col >> 1] = *encoded++ + 128; |
1743 | 405 } |
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
406 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
|
407 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
|
408 v_out -= c->pic.linesize[2]; |
5297 | 409 } |
410 break; | |
411 case IMGTYPE_YUV420: | |
9749
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.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
|
413 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
|
414 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
|
415 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
|
416 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
|
417 encoded += 2; |
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
418 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
|
419 encoded += 2; |
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
420 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
|
421 v_out[col >> 1] = *encoded++ + 128; |
1743 | 422 } |
9749
4a4192578b60
Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents:
9738
diff
changeset
|
423 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
|
424 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
|
425 v_out -= c->pic.linesize[2]; |
5297 | 426 } |
427 break; | |
428 default: | |
429 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n"); | |
430 return -1; | |
1743 | 431 } |
432 | |
433 *data_size = sizeof(AVFrame); | |
434 *(AVFrame*)data = c->pic; | |
435 | |
436 /* always report that the buffer was completely consumed */ | |
437 return buf_size; | |
438 } | |
439 | |
440 /* | |
441 * | |
442 * Init lcl decoder | |
443 * | |
444 */ | |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6375
diff
changeset
|
445 static av_cold int decode_init(AVCodecContext *avctx) |
1743 | 446 { |
5294 | 447 LclDecContext * const c = avctx->priv_data; |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
448 unsigned int basesize = avctx->width * avctx->height; |
9755 | 449 unsigned int max_basesize = FFALIGN(avctx->width, 4) * FFALIGN(avctx->height, 4); |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
450 unsigned int max_decomp_size; |
1743 | 451 |
452 c->pic.data[0] = NULL; | |
453 | |
9751
705efd6ddaab
lcldec.c: change #if CONFIG_ZLIB to #if CONFIG_ZLIB_DECODER.
reimar
parents:
9750
diff
changeset
|
454 #if CONFIG_ZLIB_DECODER |
1743 | 455 // 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
|
456 memset(&c->zstream, 0, sizeof(z_stream)); |
1743 | 457 #endif |
458 | |
459 if (avctx->extradata_size < 8) { | |
460 av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n"); | |
461 return 1; | |
462 } | |
463 | |
2429
4b350cc506a7
Use avcodec_check_dimensions instead of custom hack
rtognimp
parents:
2418
diff
changeset
|
464 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
|
465 return 1; |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
466 } |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
467 |
2967 | 468 /* Check codec type */ |
9750
a87706453840
Get rid of extradata casts, it already has the right uint8_t * type
reimar
parents:
9749
diff
changeset
|
469 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
|
470 (avctx->codec_id == CODEC_ID_ZLIB && avctx->extradata[7] != CODEC_ZLIB)) { |
1743 | 471 av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n"); |
472 } | |
473 | |
474 /* Detect image type */ | |
9750
a87706453840
Get rid of extradata casts, it already has the right uint8_t * type
reimar
parents:
9749
diff
changeset
|
475 switch (c->imgtype = avctx->extradata[4]) { |
5297 | 476 case IMGTYPE_YUV111: |
477 c->decomp_size = basesize * 3; | |
478 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
|
479 avctx->pix_fmt = PIX_FMT_YUV444P; |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
480 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 1:1:1.\n"); |
5297 | 481 break; |
482 case IMGTYPE_YUV422: | |
483 c->decomp_size = basesize * 2; | |
484 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
|
485 avctx->pix_fmt = PIX_FMT_YUV422P; |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
486 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:2.\n"); |
5297 | 487 break; |
488 case IMGTYPE_RGB24: | |
489 c->decomp_size = basesize * 3; | |
490 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
|
491 avctx->pix_fmt = PIX_FMT_BGR24; |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
492 av_log(avctx, AV_LOG_DEBUG, "Image type is RGB 24.\n"); |
5297 | 493 break; |
494 case IMGTYPE_YUV411: | |
495 c->decomp_size = basesize / 2 * 3; | |
496 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
|
497 avctx->pix_fmt = PIX_FMT_YUV411P; |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
498 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:1:1.\n"); |
5297 | 499 break; |
500 case IMGTYPE_YUV211: | |
501 c->decomp_size = basesize * 2; | |
502 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
|
503 avctx->pix_fmt = PIX_FMT_YUV422P; |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
504 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 2:1:1.\n"); |
5297 | 505 break; |
506 case IMGTYPE_YUV420: | |
507 c->decomp_size = basesize / 2 * 3; | |
508 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
|
509 avctx->pix_fmt = PIX_FMT_YUV420P; |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
510 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:0.\n"); |
5297 | 511 break; |
512 default: | |
513 av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype); | |
514 return 1; | |
1743 | 515 } |
516 | |
517 /* Detect compression method */ | |
9750
a87706453840
Get rid of extradata casts, it already has the right uint8_t * type
reimar
parents:
9749
diff
changeset
|
518 c->compression = avctx->extradata[5]; |
1743 | 519 switch (avctx->codec_id) { |
5297 | 520 case CODEC_ID_MSZH: |
521 switch (c->compression) { | |
522 case COMP_MSZH: | |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
523 av_log(avctx, AV_LOG_DEBUG, "Compression enabled.\n"); |
1743 | 524 break; |
5297 | 525 case COMP_MSZH_NOCOMP: |
526 c->decomp_size = 0; | |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
527 av_log(avctx, AV_LOG_DEBUG, "No compression.\n"); |
1743 | 528 break; |
529 default: | |
5297 | 530 av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression); |
1743 | 531 return 1; |
5297 | 532 } |
533 break; | |
9752
f52c5d54ede5
Get rid of unreachable code: avctx->codec_id == CODEC_ID_ZLIB is not possible
reimar
parents:
9751
diff
changeset
|
534 #if CONFIG_ZLIB_DECODER |
5297 | 535 case CODEC_ID_ZLIB: |
536 switch (c->compression) { | |
537 case COMP_ZLIB_HISPEED: | |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
538 av_log(avctx, AV_LOG_DEBUG, "High speed compression.\n"); |
5297 | 539 break; |
540 case COMP_ZLIB_HICOMP: | |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
541 av_log(avctx, AV_LOG_DEBUG, "High compression.\n"); |
5297 | 542 break; |
543 case COMP_ZLIB_NORMAL: | |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
544 av_log(avctx, AV_LOG_DEBUG, "Normal compression.\n"); |
5297 | 545 break; |
546 default: | |
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
547 if (c->compression < Z_NO_COMPRESSION || c->compression > Z_BEST_COMPRESSION) { |
5297 | 548 av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression); |
549 return 1; | |
550 } | |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
551 av_log(avctx, AV_LOG_DEBUG, "Compression level for ZLIB: (%d).\n", c->compression); |
5297 | 552 } |
9752
f52c5d54ede5
Get rid of unreachable code: avctx->codec_id == CODEC_ID_ZLIB is not possible
reimar
parents:
9751
diff
changeset
|
553 break; |
5297 | 554 #endif |
555 default: | |
556 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n"); | |
557 return 1; | |
1743 | 558 } |
559 | |
560 /* Allocate decompression buffer */ | |
561 if (c->decomp_size) { | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
562 if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) { |
1743 | 563 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); |
564 return 1; | |
565 } | |
566 } | |
2967 | 567 |
568 /* Detect flags */ | |
9750
a87706453840
Get rid of extradata casts, it already has the right uint8_t * type
reimar
parents:
9749
diff
changeset
|
569 c->flags = avctx->extradata[6]; |
1743 | 570 if (c->flags & FLAG_MULTITHREAD) |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
571 av_log(avctx, AV_LOG_DEBUG, "Multithread encoder flag set.\n"); |
1743 | 572 if (c->flags & FLAG_NULLFRAME) |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
573 av_log(avctx, AV_LOG_DEBUG, "Nullframe insertion flag set.\n"); |
1743 | 574 if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) |
9753
ddd880ab64c6
Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents:
9752
diff
changeset
|
575 av_log(avctx, AV_LOG_DEBUG, "PNG filter flag set.\n"); |
1743 | 576 if (c->flags & FLAGMASK_UNUSED) |
577 av_log(avctx, AV_LOG_ERROR, "Unknown flag set (%d).\n", c->flags); | |
578 | |
579 /* If needed init zlib */ | |
9752
f52c5d54ede5
Get rid of unreachable code: avctx->codec_id == CODEC_ID_ZLIB is not possible
reimar
parents:
9751
diff
changeset
|
580 #if CONFIG_ZLIB_DECODER |
1743 | 581 if (avctx->codec_id == CODEC_ID_ZLIB) { |
9754
269e16268683
Move variable into block where it is used, avoiding a unused variable
reimar
parents:
9753
diff
changeset
|
582 int zret; |
1743 | 583 c->zstream.zalloc = Z_NULL; |
584 c->zstream.zfree = Z_NULL; | |
585 c->zstream.opaque = Z_NULL; | |
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
586 zret = inflateInit(&c->zstream); |
1743 | 587 if (zret != Z_OK) { |
588 av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); | |
589 return 1; | |
590 } | |
9752
f52c5d54ede5
Get rid of unreachable code: avctx->codec_id == CODEC_ID_ZLIB is not possible
reimar
parents:
9751
diff
changeset
|
591 } |
1743 | 592 #endif |
593 | |
594 return 0; | |
595 } | |
596 | |
597 /* | |
598 * | |
599 * Uninit lcl decoder | |
600 * | |
601 */ | |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6375
diff
changeset
|
602 static av_cold int decode_end(AVCodecContext *avctx) |
1743 | 603 { |
5297 | 604 LclDecContext * const c = avctx->priv_data; |
1743 | 605 |
5297 | 606 if (c->pic.data[0]) |
607 avctx->release_buffer(avctx, &c->pic); | |
9751
705efd6ddaab
lcldec.c: change #if CONFIG_ZLIB to #if CONFIG_ZLIB_DECODER.
reimar
parents:
9750
diff
changeset
|
608 #if CONFIG_ZLIB_DECODER |
9736
405cbc435997
Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents:
9730
diff
changeset
|
609 inflateEnd(&c->zstream); |
1743 | 610 #endif |
611 | |
5297 | 612 return 0; |
1743 | 613 } |
614 | |
8590 | 615 #if CONFIG_MSZH_DECODER |
1743 | 616 AVCodec mszh_decoder = { |
5297 | 617 "mszh", |
618 CODEC_TYPE_VIDEO, | |
619 CODEC_ID_MSZH, | |
620 sizeof(LclDecContext), | |
621 decode_init, | |
622 NULL, | |
623 decode_end, | |
624 decode_frame, | |
625 CODEC_CAP_DR1, | |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6712
diff
changeset
|
626 .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) MSZH"), |
1743 | 627 }; |
3777 | 628 #endif |
1743 | 629 |
8590 | 630 #if CONFIG_ZLIB_DECODER |
1743 | 631 AVCodec zlib_decoder = { |
5297 | 632 "zlib", |
633 CODEC_TYPE_VIDEO, | |
634 CODEC_ID_ZLIB, | |
635 sizeof(LclDecContext), | |
636 decode_init, | |
637 NULL, | |
638 decode_end, | |
639 decode_frame, | |
640 CODEC_CAP_DR1, | |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6712
diff
changeset
|
641 .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"), |
1743 | 642 }; |
3777 | 643 #endif |