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