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