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