annotate lcldec.c @ 11384:ba57caf45845 libavcodec

When tracking non-zero coefficients during Indeo 5 decoding, make sure it does not ignore coefficient value = 256. Patch by Maxim ((!min)_pole \at gmx dot/ de)
author kostya
date Sun, 07 Mar 2010 06:03:45 +0000
parents d7ed9dcc78e3
children 8a4984c5cacc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
1 /*
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
2 * LCL (LossLess Codec Library) Codec
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
3 * Copyright (c) 2002-2004 Roberto Togni
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
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
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
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
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
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
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
15 * Lesser General Public License for more details.
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
16 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
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
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
20 */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
21
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
22 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8673
diff changeset
23 * @file libavcodec/lcldec.c
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
24 * LCL (LossLess Codec Library) Video Codec
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
25 * Decoder for MSZH and ZLIB codecs
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
26 * Experimental encoder for ZLIB RGB24
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
27 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
28 * Fourcc: MSZH, ZLIB
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
29 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
30 * Original Win32 dll:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
31 * Ver2.23 By Kenji Oshima 2000.09.20
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
32 * avimszh.dll, avizlib.dll
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
33 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
34 * A description of the decoding algorithm can be found here:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
35 * http://www.pcisys.net/~melanson/codecs
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
36 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
37 * Supports: BGR24 (RGB 24bpp)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
38 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
39 */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
40
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
41 #include <stdio.h>
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
42 #include <stdlib.h>
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
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
e21873a1c00b split lcl.c into lcldec.c, lclenc.c, lcl.h
mru
parents: 5215
diff changeset
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
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
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
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
50 #include <zlib.h>
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
51 #endif
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
52
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
53 /*
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
54 * Decoder context
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
55 */
5294
e21873a1c00b split lcl.c into lcldec.c, lclenc.c, lcl.h
mru
parents: 5215
diff changeset
56 typedef struct LclDecContext {
5297
mru
parents: 5296
diff changeset
57 AVFrame pic;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
58
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
59 // Image type
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
60 int imgtype;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
61 // Compression type
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
62 int compression;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
63 // Flags
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
64 int flags;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
65 // Decompressed data size
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
66 unsigned int decomp_size;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
67 // Decompression buffer
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
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
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
70 z_stream zstream;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
71 #endif
5294
e21873a1c00b split lcl.c into lcldec.c, lclenc.c, lcl.h
mru
parents: 5215
diff changeset
72 } LclDecContext;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
73
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
74
9765
350826aae685 Document padding requirements of mszh_decomp srcptr buffer
reimar
parents: 9764
diff changeset
75 /**
9775
3fd46320ab12 Take advantage of available input padding to optimize mszh_decomp
reimar
parents: 9774
diff changeset
76 * \param srcptr compressed source buffer, must be padded with at least 5 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
6efef56e20b3 Mark srcptr as const in mszh_decomp
reimar
parents: 9768
diff changeset
79 static unsigned int mszh_decomp(const unsigned char * srcptr, int srclen, unsigned char * destptr, unsigned int destsize)
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
80 {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
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
6efef56e20b3 Mark srcptr as const in mszh_decomp
reimar
parents: 9768
diff changeset
83 const unsigned char *srcptr_end = srcptr + srclen;
9776
18d149e8fc7f Use int-size types instead of char where it makes no difference.
reimar
parents: 9775
diff changeset
84 unsigned mask = *srcptr++;
18d149e8fc7f Use int-size types instead of char where it makes no difference.
reimar
parents: 9775
diff changeset
85 unsigned maskbit = 0x80;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
86
9764
dd6bcbec3c24 Use srcptr_end variable to avoid having to update both srcptr and srclen.
reimar
parents: 9763
diff changeset
87 while (srcptr < srcptr_end && destptr < destptr_end) {
9774
69395e6a4d03 Change maskbit variable to contain (1 << maskbit)
reimar
parents: 9773
diff changeset
88 if (!(mask & maskbit)) {
9762
3242ae563430 Simply use memcpy instead of AV_RN32/AV_WN32 combination.
reimar
parents: 9761
diff changeset
89 memcpy(destptr, srcptr, 4);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
90 destptr += 4;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
91 srcptr += 4;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
92 } else {
9777
77fd9731dea5 Merge variable declaration and initialization.
reimar
parents: 9776
diff changeset
93 unsigned ofs = bytestream_get_le16(&srcptr);
77fd9731dea5 Merge variable declaration and initialization.
reimar
parents: 9776
diff changeset
94 unsigned cnt = (ofs >> 11) + 1;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
95 ofs &= 0x7ff;
9781
05b6cba2c95b lcldec: ensure that the offset for av_memcpy_backptr is valid.
reimar
parents: 9780
diff changeset
96 ofs = FFMIN(ofs, destptr - destptr_bak);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
97 cnt *= 4;
9771
85c99c1335bc One more use for FFMIN.
reimar
parents: 9770
diff changeset
98 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
99 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
100 destptr += cnt;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
101 }
9774
69395e6a4d03 Change maskbit variable to contain (1 << maskbit)
reimar
parents: 9773
diff changeset
102 maskbit >>= 1;
9775
3fd46320ab12 Take advantage of available input padding to optimize mszh_decomp
reimar
parents: 9774
diff changeset
103 if (!maskbit) {
3fd46320ab12 Take advantage of available input padding to optimize mszh_decomp
reimar
parents: 9774
diff changeset
104 mask = *srcptr++;
9782
66922728d7f7 mszh decompression: add a special case for an all-0 mask, i.e. 32 uncompressed
reimar
parents: 9781
diff changeset
105 while (!mask) {
66922728d7f7 mszh decompression: add a special case for an all-0 mask, i.e. 32 uncompressed
reimar
parents: 9781
diff changeset
106 if (destptr_end - destptr < 32 || srcptr_end - srcptr < 32) break;
66922728d7f7 mszh decompression: add a special case for an all-0 mask, i.e. 32 uncompressed
reimar
parents: 9781
diff changeset
107 memcpy(destptr, srcptr, 32);
66922728d7f7 mszh decompression: add a special case for an all-0 mask, i.e. 32 uncompressed
reimar
parents: 9781
diff changeset
108 destptr += 32;
66922728d7f7 mszh decompression: add a special case for an all-0 mask, i.e. 32 uncompressed
reimar
parents: 9781
diff changeset
109 srcptr += 32;
66922728d7f7 mszh decompression: add a special case for an all-0 mask, i.e. 32 uncompressed
reimar
parents: 9781
diff changeset
110 mask = *srcptr++;
66922728d7f7 mszh decompression: add a special case for an all-0 mask, i.e. 32 uncompressed
reimar
parents: 9781
diff changeset
111 }
9775
3fd46320ab12 Take advantage of available input padding to optimize mszh_decomp
reimar
parents: 9774
diff changeset
112 maskbit = 0x80;
3fd46320ab12 Take advantage of available input padding to optimize mszh_decomp
reimar
parents: 9774
diff changeset
113 }
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
114 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
115
9736
405cbc435997 Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents: 9730
diff changeset
116 return destptr - destptr_bak;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
117 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
118
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
119
9756
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 * \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
122 * \param src compressed input buffer
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
123 * \param src_len data length in input buffer
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
124 * \param offset offset in decomp_buf
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
125 * \param expected expected decompressed length
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
126 */
9783
21f3bbb20e42 add #if CONFIG_ZLIB_DECODER around zlib_decomp function.
reimar
parents: 9782
diff changeset
127 #if CONFIG_ZLIB_DECODER
9756
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
128 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
129 {
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
130 LclDecContext *c = avctx->priv_data;
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
131 int zret = inflateReset(&c->zstream);
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
132 if (zret != Z_OK) {
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
133 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
134 return -1;
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
135 }
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
136 c->zstream.next_in = src;
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
137 c->zstream.avail_in = src_len;
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
138 c->zstream.next_out = c->decomp_buf + offset;
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
139 c->zstream.avail_out = c->decomp_size - offset;
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
140 zret = inflate(&c->zstream, Z_FINISH);
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
141 if (zret != Z_OK && zret != Z_STREAM_END) {
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
142 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
143 return -1;
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 if (expected != (unsigned int)c->zstream.total_out) {
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
146 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
147 expected, c->zstream.total_out);
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
148 return -1;
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
149 }
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
150 return c->zstream.total_out;
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
151 }
9783
21f3bbb20e42 add #if CONFIG_ZLIB_DECODER around zlib_decomp function.
reimar
parents: 9782
diff changeset
152 #endif
9756
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
153
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
154
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
155 /*
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
156 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
157 * Decode a frame
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
158 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
159 */
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
160 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
161 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
162 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
163 int buf_size = avpkt->size;
5297
mru
parents: 5296
diff changeset
164 LclDecContext * const c = avctx->priv_data;
mru
parents: 5296
diff changeset
165 unsigned char *encoded = (unsigned char *)buf;
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
166 unsigned int pixel_ptr;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
167 int row, col;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
168 unsigned char *outptr;
9749
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
169 uint8_t *y_out, *u_out, *v_out;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
170 unsigned int width = avctx->width; // Real image width
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
171 unsigned int height = avctx->height; // Real image height
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
172 unsigned int mszh_dlen;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
173 unsigned char yq, y1q, uq, vq;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
174 int uqvq;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
175 unsigned int mthread_inlen, mthread_outlen;
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
176 unsigned int len = buf_size;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
177
5297
mru
parents: 5296
diff changeset
178 if(c->pic.data[0])
mru
parents: 5296
diff changeset
179 avctx->release_buffer(avctx, &c->pic);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
180
5297
mru
parents: 5296
diff changeset
181 c->pic.reference = 0;
mru
parents: 5296
diff changeset
182 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
mru
parents: 5296
diff changeset
183 if(avctx->get_buffer(avctx, &c->pic) < 0){
mru
parents: 5296
diff changeset
184 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
mru
parents: 5296
diff changeset
185 return -1;
mru
parents: 5296
diff changeset
186 }
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
187
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
188 outptr = c->pic.data[0]; // Output image pointer
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
189
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
190 /* Decompress frame */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
191 switch (avctx->codec_id) {
5297
mru
parents: 5296
diff changeset
192 case CODEC_ID_MSZH:
mru
parents: 5296
diff changeset
193 switch (c->compression) {
mru
parents: 5296
diff changeset
194 case COMP_MSZH:
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
195 if (c->flags & FLAG_MULTITHREAD) {
9761
b69de727fd7c Fix decoding of multithread-encoded lcl files on big-endian.
reimar
parents: 9760
diff changeset
196 mthread_inlen = AV_RL32(encoded);
9758
8ebcc162db3d Add sanity check for mthread_inlen, avoids crashes due to invalid reads.
reimar
parents: 9757
diff changeset
197 mthread_inlen = FFMIN(mthread_inlen, len - 8);
9761
b69de727fd7c Fix decoding of multithread-encoded lcl files on big-endian.
reimar
parents: 9760
diff changeset
198 mthread_outlen = AV_RL32(encoded+4);
9757
8e4d442554b3 Use FFMIN
reimar
parents: 9756
diff changeset
199 mthread_outlen = FFMIN(mthread_outlen, c->decomp_size);
5297
mru
parents: 5296
diff changeset
200 mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf, c->decomp_size);
mru
parents: 5296
diff changeset
201 if (mthread_outlen != mszh_dlen) {
mru
parents: 5296
diff changeset
202 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n",
mru
parents: 5296
diff changeset
203 mthread_outlen, mszh_dlen);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
204 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
205 }
9759
5968a9f15535 Correct calculation of compressed input length.
reimar
parents: 9758
diff changeset
206 mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
5297
mru
parents: 5296
diff changeset
207 c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen);
mru
parents: 5296
diff changeset
208 if (mthread_outlen != mszh_dlen) {
mru
parents: 5296
diff changeset
209 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n",
mru
parents: 5296
diff changeset
210 mthread_outlen, mszh_dlen);
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
211 return -1;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
212 }
5297
mru
parents: 5296
diff changeset
213 encoded = c->decomp_buf;
mru
parents: 5296
diff changeset
214 len = c->decomp_size;
mru
parents: 5296
diff changeset
215 } else {
mru
parents: 5296
diff changeset
216 mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf, c->decomp_size);
mru
parents: 5296
diff changeset
217 if (c->decomp_size != mszh_dlen) {
mru
parents: 5296
diff changeset
218 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n",
mru
parents: 5296
diff changeset
219 c->decomp_size, mszh_dlen);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
220 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
221 }
5297
mru
parents: 5296
diff changeset
222 encoded = c->decomp_buf;
mru
parents: 5296
diff changeset
223 len = mszh_dlen;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
224 }
5297
mru
parents: 5296
diff changeset
225 break;
mru
parents: 5296
diff changeset
226 case COMP_MSZH_NOCOMP:
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
227 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
228 default:
5297
mru
parents: 5296
diff changeset
229 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n");
mru
parents: 5296
diff changeset
230 return -1;
mru
parents: 5296
diff changeset
231 }
mru
parents: 5296
diff changeset
232 break;
9752
f52c5d54ede5 Get rid of unreachable code: avctx->codec_id == CODEC_ID_ZLIB is not possible
reimar
parents: 9751
diff changeset
233 #if CONFIG_ZLIB_DECODER
5297
mru
parents: 5296
diff changeset
234 case CODEC_ID_ZLIB:
mru
parents: 5296
diff changeset
235 /* Using the original dll with normal compression (-1) and RGB format
mru
parents: 5296
diff changeset
236 * gives a file with ZLIB fourcc, but frame is really uncompressed.
mru
parents: 5296
diff changeset
237 * 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
238 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
239 len == width * height * 3)
5297
mru
parents: 5296
diff changeset
240 break;
mru
parents: 5296
diff changeset
241 if (c->flags & FLAG_MULTITHREAD) {
9756
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
242 int ret;
9761
b69de727fd7c Fix decoding of multithread-encoded lcl files on big-endian.
reimar
parents: 9760
diff changeset
243 mthread_inlen = AV_RL32(encoded);
9758
8ebcc162db3d Add sanity check for mthread_inlen, avoids crashes due to invalid reads.
reimar
parents: 9757
diff changeset
244 mthread_inlen = FFMIN(mthread_inlen, len - 8);
9761
b69de727fd7c Fix decoding of multithread-encoded lcl files on big-endian.
reimar
parents: 9760
diff changeset
245 mthread_outlen = AV_RL32(encoded+4);
9757
8e4d442554b3 Use FFMIN
reimar
parents: 9756
diff changeset
246 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
247 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
248 if (ret < 0) return ret;
9759
5968a9f15535 Correct calculation of compressed input length.
reimar
parents: 9758
diff changeset
249 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
250 mthread_outlen, mthread_outlen);
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
251 if (ret < 0) return ret;
5297
mru
parents: 5296
diff changeset
252 } else {
9756
ed55b61c8e45 Factor out zlib decompression code to avoid massive code duplication,
reimar
parents: 9755
diff changeset
253 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
254 if (ret < 0) return ret;
5297
mru
parents: 5296
diff changeset
255 }
mru
parents: 5296
diff changeset
256 encoded = c->decomp_buf;
6375
551232d0fa74 Remove duplicate ;
reimar
parents: 6218
diff changeset
257 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
258 break;
5297
mru
parents: 5296
diff changeset
259 #endif
mru
parents: 5296
diff changeset
260 default:
mru
parents: 5296
diff changeset
261 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n");
mru
parents: 5296
diff changeset
262 return -1;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
263 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
264
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
265
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
266 /* Apply PNG filter */
9736
405cbc435997 Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents: 9730
diff changeset
267 if (avctx->codec_id == CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER)) {
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
268 switch (c->imgtype) {
5297
mru
parents: 5296
diff changeset
269 case IMGTYPE_YUV111:
mru
parents: 5296
diff changeset
270 case IMGTYPE_RGB24:
mru
parents: 5296
diff changeset
271 for (row = 0; row < height; row++) {
mru
parents: 5296
diff changeset
272 pixel_ptr = row * width * 3;
mru
parents: 5296
diff changeset
273 yq = encoded[pixel_ptr++];
mru
parents: 5296
diff changeset
274 uqvq = AV_RL16(encoded+pixel_ptr);
mru
parents: 5296
diff changeset
275 pixel_ptr += 2;
mru
parents: 5296
diff changeset
276 for (col = 1; col < width; col++) {
mru
parents: 5296
diff changeset
277 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
mru
parents: 5296
diff changeset
278 uqvq -= AV_RL16(encoded+pixel_ptr+1);
mru
parents: 5296
diff changeset
279 AV_WL16(encoded+pixel_ptr+1, uqvq);
mru
parents: 5296
diff changeset
280 pixel_ptr += 3;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
281 }
5297
mru
parents: 5296
diff changeset
282 }
mru
parents: 5296
diff changeset
283 break;
mru
parents: 5296
diff changeset
284 case IMGTYPE_YUV422:
mru
parents: 5296
diff changeset
285 for (row = 0; row < height; row++) {
mru
parents: 5296
diff changeset
286 pixel_ptr = row * width * 2;
mru
parents: 5296
diff changeset
287 yq = uq = vq =0;
mru
parents: 5296
diff changeset
288 for (col = 0; col < width/4; col++) {
mru
parents: 5296
diff changeset
289 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
mru
parents: 5296
diff changeset
290 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
mru
parents: 5296
diff changeset
291 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
mru
parents: 5296
diff changeset
292 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
mru
parents: 5296
diff changeset
293 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
mru
parents: 5296
diff changeset
294 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
mru
parents: 5296
diff changeset
295 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
mru
parents: 5296
diff changeset
296 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
mru
parents: 5296
diff changeset
297 pixel_ptr += 8;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
298 }
5297
mru
parents: 5296
diff changeset
299 }
mru
parents: 5296
diff changeset
300 break;
mru
parents: 5296
diff changeset
301 case IMGTYPE_YUV411:
mru
parents: 5296
diff changeset
302 for (row = 0; row < height; row++) {
mru
parents: 5296
diff changeset
303 pixel_ptr = row * width / 2 * 3;
mru
parents: 5296
diff changeset
304 yq = uq = vq =0;
mru
parents: 5296
diff changeset
305 for (col = 0; col < width/4; col++) {
mru
parents: 5296
diff changeset
306 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
mru
parents: 5296
diff changeset
307 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
mru
parents: 5296
diff changeset
308 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
mru
parents: 5296
diff changeset
309 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
mru
parents: 5296
diff changeset
310 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
mru
parents: 5296
diff changeset
311 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
mru
parents: 5296
diff changeset
312 pixel_ptr += 6;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
313 }
5297
mru
parents: 5296
diff changeset
314 }
mru
parents: 5296
diff changeset
315 break;
mru
parents: 5296
diff changeset
316 case IMGTYPE_YUV211:
mru
parents: 5296
diff changeset
317 for (row = 0; row < height; row++) {
mru
parents: 5296
diff changeset
318 pixel_ptr = row * width * 2;
mru
parents: 5296
diff changeset
319 yq = uq = vq =0;
mru
parents: 5296
diff changeset
320 for (col = 0; col < width/2; col++) {
mru
parents: 5296
diff changeset
321 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
mru
parents: 5296
diff changeset
322 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
mru
parents: 5296
diff changeset
323 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
mru
parents: 5296
diff changeset
324 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
mru
parents: 5296
diff changeset
325 pixel_ptr += 4;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
326 }
5297
mru
parents: 5296
diff changeset
327 }
mru
parents: 5296
diff changeset
328 break;
mru
parents: 5296
diff changeset
329 case IMGTYPE_YUV420:
mru
parents: 5296
diff changeset
330 for (row = 0; row < height/2; row++) {
mru
parents: 5296
diff changeset
331 pixel_ptr = row * width * 3;
mru
parents: 5296
diff changeset
332 yq = y1q = uq = vq =0;
mru
parents: 5296
diff changeset
333 for (col = 0; col < width/2; col++) {
mru
parents: 5296
diff changeset
334 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
mru
parents: 5296
diff changeset
335 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
mru
parents: 5296
diff changeset
336 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
mru
parents: 5296
diff changeset
337 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
mru
parents: 5296
diff changeset
338 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
mru
parents: 5296
diff changeset
339 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
mru
parents: 5296
diff changeset
340 pixel_ptr += 6;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
341 }
5297
mru
parents: 5296
diff changeset
342 }
mru
parents: 5296
diff changeset
343 break;
mru
parents: 5296
diff changeset
344 default:
mru
parents: 5296
diff changeset
345 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n");
mru
parents: 5296
diff changeset
346 return -1;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
347 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
348 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
349
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
350 /* Convert colorspace */
9749
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
351 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
352 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
353 v_out = c->pic.data[2] + (height - 1) * c->pic.linesize[2];
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
354 switch (c->imgtype) {
5297
mru
parents: 5296
diff changeset
355 case IMGTYPE_YUV111:
9749
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
356 for (row = 0; row < height; row++) {
5297
mru
parents: 5296
diff changeset
357 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
358 y_out[col] = *encoded++;
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
359 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
360 v_out[col] = *encoded++ + 128;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
361 }
9749
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
362 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
363 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
364 v_out -= c->pic.linesize[2];
5297
mru
parents: 5296
diff changeset
365 }
mru
parents: 5296
diff changeset
366 break;
mru
parents: 5296
diff changeset
367 case IMGTYPE_YUV422:
9749
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
368 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
369 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
370 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
371 encoded += 4;
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
372 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
373 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
374 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
375 v_out[(col >> 1) + 1] = *encoded++ + 128;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
376 }
9749
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
377 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
378 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
379 v_out -= c->pic.linesize[2];
5297
mru
parents: 5296
diff changeset
380 }
mru
parents: 5296
diff changeset
381 break;
mru
parents: 5296
diff changeset
382 case IMGTYPE_RGB24:
mru
parents: 5296
diff changeset
383 for (row = height - 1; row >= 0; row--) {
mru
parents: 5296
diff changeset
384 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
385 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
386 encoded += 3 * width;
5297
mru
parents: 5296
diff changeset
387 }
mru
parents: 5296
diff changeset
388 break;
mru
parents: 5296
diff changeset
389 case IMGTYPE_YUV411:
9749
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
390 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
391 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
392 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
393 encoded += 4;
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
394 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
395 v_out[col >> 2] = *encoded++ + 128;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
396 }
9749
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
397 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
398 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
399 v_out -= c->pic.linesize[2];
5297
mru
parents: 5296
diff changeset
400 }
mru
parents: 5296
diff changeset
401 break;
mru
parents: 5296
diff changeset
402 case IMGTYPE_YUV211:
9749
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
403 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
404 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
405 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
406 encoded += 2;
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
407 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
408 v_out[col >> 1] = *encoded++ + 128;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
409 }
9749
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
410 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
411 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
412 v_out -= c->pic.linesize[2];
5297
mru
parents: 5296
diff changeset
413 }
mru
parents: 5296
diff changeset
414 break;
mru
parents: 5296
diff changeset
415 case IMGTYPE_YUV420:
9749
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
416 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
417 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
418 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
419 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
420 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
421 encoded += 2;
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
422 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
423 encoded += 2;
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
424 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
425 v_out[col >> 1] = *encoded++ + 128;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
426 }
9749
4a4192578b60 Make lcldec produce YUV output when the input file is coded like that, instead
reimar
parents: 9738
diff changeset
427 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
428 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
429 v_out -= c->pic.linesize[2];
5297
mru
parents: 5296
diff changeset
430 }
mru
parents: 5296
diff changeset
431 break;
mru
parents: 5296
diff changeset
432 default:
mru
parents: 5296
diff changeset
433 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n");
mru
parents: 5296
diff changeset
434 return -1;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
435 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
436
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
437 *data_size = sizeof(AVFrame);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
438 *(AVFrame*)data = c->pic;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
439
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
440 /* always report that the buffer was completely consumed */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
441 return buf_size;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
442 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
443
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
444 /*
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
445 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
446 * Init lcl decoder
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
447 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
448 */
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6375
diff changeset
449 static av_cold int decode_init(AVCodecContext *avctx)
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
450 {
5294
e21873a1c00b split lcl.c into lcldec.c, lclenc.c, lcl.h
mru
parents: 5215
diff changeset
451 LclDecContext * const c = avctx->priv_data;
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
452 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
453 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
454 unsigned int max_decomp_size;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
455
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
456 if (avctx->extradata_size < 8) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
457 av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
458 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
459 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
460
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
461 /* Check codec type */
9750
a87706453840 Get rid of extradata casts, it already has the right uint8_t * type
reimar
parents: 9749
diff changeset
462 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
463 (avctx->codec_id == CODEC_ID_ZLIB && avctx->extradata[7] != CODEC_ZLIB)) {
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
464 av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
465 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
466
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
467 /* Detect image type */
9750
a87706453840 Get rid of extradata casts, it already has the right uint8_t * type
reimar
parents: 9749
diff changeset
468 switch (c->imgtype = avctx->extradata[4]) {
5297
mru
parents: 5296
diff changeset
469 case IMGTYPE_YUV111:
mru
parents: 5296
diff changeset
470 c->decomp_size = basesize * 3;
mru
parents: 5296
diff changeset
471 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
472 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
473 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 1:1:1.\n");
5297
mru
parents: 5296
diff changeset
474 break;
mru
parents: 5296
diff changeset
475 case IMGTYPE_YUV422:
mru
parents: 5296
diff changeset
476 c->decomp_size = basesize * 2;
mru
parents: 5296
diff changeset
477 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
478 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
479 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:2.\n");
5297
mru
parents: 5296
diff changeset
480 break;
mru
parents: 5296
diff changeset
481 case IMGTYPE_RGB24:
mru
parents: 5296
diff changeset
482 c->decomp_size = basesize * 3;
mru
parents: 5296
diff changeset
483 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
484 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
485 av_log(avctx, AV_LOG_DEBUG, "Image type is RGB 24.\n");
5297
mru
parents: 5296
diff changeset
486 break;
mru
parents: 5296
diff changeset
487 case IMGTYPE_YUV411:
mru
parents: 5296
diff changeset
488 c->decomp_size = basesize / 2 * 3;
mru
parents: 5296
diff changeset
489 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
490 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
491 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:1:1.\n");
5297
mru
parents: 5296
diff changeset
492 break;
mru
parents: 5296
diff changeset
493 case IMGTYPE_YUV211:
mru
parents: 5296
diff changeset
494 c->decomp_size = basesize * 2;
mru
parents: 5296
diff changeset
495 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
496 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
497 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 2:1:1.\n");
5297
mru
parents: 5296
diff changeset
498 break;
mru
parents: 5296
diff changeset
499 case IMGTYPE_YUV420:
mru
parents: 5296
diff changeset
500 c->decomp_size = basesize / 2 * 3;
mru
parents: 5296
diff changeset
501 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
502 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
503 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:0.\n");
5297
mru
parents: 5296
diff changeset
504 break;
mru
parents: 5296
diff changeset
505 default:
mru
parents: 5296
diff changeset
506 av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype);
mru
parents: 5296
diff changeset
507 return 1;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
508 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
509
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
510 /* Detect compression method */
9772
2771fff83016 100l, the compression field in lcl extradata must be interpreted as
reimar
parents: 9771
diff changeset
511 c->compression = (int8_t)avctx->extradata[5];
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
512 switch (avctx->codec_id) {
5297
mru
parents: 5296
diff changeset
513 case CODEC_ID_MSZH:
mru
parents: 5296
diff changeset
514 switch (c->compression) {
mru
parents: 5296
diff changeset
515 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
516 av_log(avctx, AV_LOG_DEBUG, "Compression enabled.\n");
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
517 break;
5297
mru
parents: 5296
diff changeset
518 case COMP_MSZH_NOCOMP:
mru
parents: 5296
diff changeset
519 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
520 av_log(avctx, AV_LOG_DEBUG, "No compression.\n");
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
521 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
522 default:
5297
mru
parents: 5296
diff changeset
523 av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
524 return 1;
5297
mru
parents: 5296
diff changeset
525 }
mru
parents: 5296
diff changeset
526 break;
9752
f52c5d54ede5 Get rid of unreachable code: avctx->codec_id == CODEC_ID_ZLIB is not possible
reimar
parents: 9751
diff changeset
527 #if CONFIG_ZLIB_DECODER
5297
mru
parents: 5296
diff changeset
528 case CODEC_ID_ZLIB:
mru
parents: 5296
diff changeset
529 switch (c->compression) {
mru
parents: 5296
diff changeset
530 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
531 av_log(avctx, AV_LOG_DEBUG, "High speed compression.\n");
5297
mru
parents: 5296
diff changeset
532 break;
mru
parents: 5296
diff changeset
533 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
534 av_log(avctx, AV_LOG_DEBUG, "High compression.\n");
5297
mru
parents: 5296
diff changeset
535 break;
mru
parents: 5296
diff changeset
536 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
537 av_log(avctx, AV_LOG_DEBUG, "Normal compression.\n");
5297
mru
parents: 5296
diff changeset
538 break;
mru
parents: 5296
diff changeset
539 default:
9736
405cbc435997 Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents: 9730
diff changeset
540 if (c->compression < Z_NO_COMPRESSION || c->compression > Z_BEST_COMPRESSION) {
5297
mru
parents: 5296
diff changeset
541 av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression);
mru
parents: 5296
diff changeset
542 return 1;
mru
parents: 5296
diff changeset
543 }
9753
ddd880ab64c6 Make lcldec less annoyingly verbose, move messages from AV_LOG_INFO to AV_LOG_DEBUG.
reimar
parents: 9752
diff changeset
544 av_log(avctx, AV_LOG_DEBUG, "Compression level for ZLIB: (%d).\n", c->compression);
5297
mru
parents: 5296
diff changeset
545 }
9752
f52c5d54ede5 Get rid of unreachable code: avctx->codec_id == CODEC_ID_ZLIB is not possible
reimar
parents: 9751
diff changeset
546 break;
5297
mru
parents: 5296
diff changeset
547 #endif
mru
parents: 5296
diff changeset
548 default:
mru
parents: 5296
diff changeset
549 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n");
mru
parents: 5296
diff changeset
550 return 1;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
551 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
552
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
553 /* Allocate decompression buffer */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
554 if (c->decomp_size) {
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
555 if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) {
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
556 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
557 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
558 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
559 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
560
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
561 /* Detect flags */
9750
a87706453840 Get rid of extradata casts, it already has the right uint8_t * type
reimar
parents: 9749
diff changeset
562 c->flags = avctx->extradata[6];
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
563 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
564 av_log(avctx, AV_LOG_DEBUG, "Multithread encoder flag set.\n");
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
565 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
566 av_log(avctx, AV_LOG_DEBUG, "Nullframe insertion flag set.\n");
9760
14b65c693625 Remove another useless ()
reimar
parents: 9759
diff changeset
567 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
568 av_log(avctx, AV_LOG_DEBUG, "PNG filter flag set.\n");
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
569 if (c->flags & FLAGMASK_UNUSED)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
570 av_log(avctx, AV_LOG_ERROR, "Unknown flag set (%d).\n", c->flags);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
571
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
572 /* 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
573 #if CONFIG_ZLIB_DECODER
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
574 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
575 int zret;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
576 c->zstream.zalloc = Z_NULL;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
577 c->zstream.zfree = Z_NULL;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
578 c->zstream.opaque = Z_NULL;
9736
405cbc435997 Remove useless () from lcldec for more consistency with "normal" FFmpeg coding style.
reimar
parents: 9730
diff changeset
579 zret = inflateInit(&c->zstream);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
580 if (zret != Z_OK) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
581 av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
9780
9f3ef4eea41a Fix memleak due to c->decomp_buf never being freed.
reimar
parents: 9779
diff changeset
582 av_freep(&c->decomp_buf);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
583 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
584 }
9752
f52c5d54ede5 Get rid of unreachable code: avctx->codec_id == CODEC_ID_ZLIB is not possible
reimar
parents: 9751
diff changeset
585 }
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
586 #endif
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
587
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
588 return 0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
589 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
590
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
591 /*
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
592 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
593 * Uninit lcl decoder
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
594 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
595 */
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6375
diff changeset
596 static av_cold int decode_end(AVCodecContext *avctx)
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
597 {
5297
mru
parents: 5296
diff changeset
598 LclDecContext * const c = avctx->priv_data;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
599
9780
9f3ef4eea41a Fix memleak due to c->decomp_buf never being freed.
reimar
parents: 9779
diff changeset
600 av_freep(&c->decomp_buf);
5297
mru
parents: 5296
diff changeset
601 if (c->pic.data[0])
mru
parents: 5296
diff changeset
602 avctx->release_buffer(avctx, &c->pic);
9751
705efd6ddaab lcldec.c: change #if CONFIG_ZLIB to #if CONFIG_ZLIB_DECODER.
reimar
parents: 9750
diff changeset
603 #if CONFIG_ZLIB_DECODER
9779
4605c1f6e877 Only call inflateEnd when we were actually using the zlib code.
reimar
parents: 9778
diff changeset
604 if (avctx->codec_id == CODEC_ID_ZLIB)
4605c1f6e877 Only call inflateEnd when we were actually using the zlib code.
reimar
parents: 9778
diff changeset
605 inflateEnd(&c->zstream);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
606 #endif
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
607
5297
mru
parents: 5296
diff changeset
608 return 0;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
609 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
610
8590
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 7040
diff changeset
611 #if CONFIG_MSZH_DECODER
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
612 AVCodec mszh_decoder = {
5297
mru
parents: 5296
diff changeset
613 "mszh",
mru
parents: 5296
diff changeset
614 CODEC_TYPE_VIDEO,
mru
parents: 5296
diff changeset
615 CODEC_ID_MSZH,
mru
parents: 5296
diff changeset
616 sizeof(LclDecContext),
mru
parents: 5296
diff changeset
617 decode_init,
mru
parents: 5296
diff changeset
618 NULL,
mru
parents: 5296
diff changeset
619 decode_end,
mru
parents: 5296
diff changeset
620 decode_frame,
mru
parents: 5296
diff changeset
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
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
623 };
3777
20545fbb6f7c add some #ifdef CONFIG_ENCODERS/DECODERS
mru
parents: 3036
diff changeset
624 #endif
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
625
8590
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 7040
diff changeset
626 #if CONFIG_ZLIB_DECODER
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
627 AVCodec zlib_decoder = {
5297
mru
parents: 5296
diff changeset
628 "zlib",
mru
parents: 5296
diff changeset
629 CODEC_TYPE_VIDEO,
mru
parents: 5296
diff changeset
630 CODEC_ID_ZLIB,
mru
parents: 5296
diff changeset
631 sizeof(LclDecContext),
mru
parents: 5296
diff changeset
632 decode_init,
mru
parents: 5296
diff changeset
633 NULL,
mru
parents: 5296
diff changeset
634 decode_end,
mru
parents: 5296
diff changeset
635 decode_frame,
mru
parents: 5296
diff changeset
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
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
638 };
3777
20545fbb6f7c add some #ifdef CONFIG_ENCODERS/DECODERS
mru
parents: 3036
diff changeset
639 #endif