annotate lcl.c @ 3014:959b8ad880dc libavcodec

Dual mono stereo strems sound ok now, added sanity checks and removed some unused variables and redundant memsets. Patch by Benjamin Larsson
author rtognimp
date Fri, 06 Jan 2006 12:41:57 +0000
parents bfabfdf9ce55
children 0b546eab515d
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 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
9 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
13 * Lesser General Public License for more details.
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
14 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
18 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
19 */
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 * @file lcl.c
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
23 * LCL (LossLess Codec Library) Video Codec
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
24 * Decoder for MSZH and ZLIB codecs
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
25 * Experimental encoder for ZLIB RGB24
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
26 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
27 * Fourcc: MSZH, ZLIB
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
28 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
29 * Original Win32 dll:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
30 * Ver2.23 By Kenji Oshima 2000.09.20
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
31 * avimszh.dll, avizlib.dll
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
32 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
33 * A description of the decoding algorithm can be found here:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
34 * http://www.pcisys.net/~melanson/codecs
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
35 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
36 * Supports: BGR24 (RGB 24bpp)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
37 *
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 #include <stdio.h>
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
41 #include <stdlib.h>
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
42
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
43 #include "common.h"
2398
582e635cfa08 common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents: 2250
diff changeset
44 #include "bitstream.h"
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
45 #include "avcodec.h"
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
46
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
47 #ifdef CONFIG_ZLIB
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
48 #include <zlib.h>
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
49 #endif
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
50
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
51
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
52 #define BMPTYPE_YUV 1
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
53 #define BMPTYPE_RGB 2
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
54
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
55 #define IMGTYPE_YUV111 0
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
56 #define IMGTYPE_YUV422 1
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
57 #define IMGTYPE_RGB24 2
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
58 #define IMGTYPE_YUV411 3
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
59 #define IMGTYPE_YUV211 4
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
60 #define IMGTYPE_YUV420 5
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
61
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
62 #define COMP_MSZH 0
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
63 #define COMP_MSZH_NOCOMP 1
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
64 #define COMP_ZLIB_HISPEED 1
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
65 #define COMP_ZLIB_HICOMP 9
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
66 #define COMP_ZLIB_NORMAL -1
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
67
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
68 #define FLAG_MULTITHREAD 1
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
69 #define FLAG_NULLFRAME 2
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
70 #define FLAG_PNGFILTER 4
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
71 #define FLAGMASK_UNUSED 0xf8
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
72
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
73 #define CODEC_MSZH 1
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
74 #define CODEC_ZLIB 3
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
75
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
76 #define FOURCC_MSZH mmioFOURCC('M','S','Z','H')
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
77 #define FOURCC_ZLIB mmioFOURCC('Z','L','I','B')
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
78
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
79 /*
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
80 * Decoder context
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
81 */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
82 typedef struct LclContext {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
83
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
84 AVCodecContext *avctx;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
85 AVFrame pic;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
86 PutBitContext pb;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
87
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
88 // Image type
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
89 int imgtype;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
90 // Compression type
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
91 int compression;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
92 // Flags
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
93 int flags;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
94 // Decompressed data size
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
95 unsigned int decomp_size;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
96 // Decompression buffer
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
97 unsigned char* decomp_buf;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
98 // Maximum compressed data size
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
99 unsigned int max_comp_size;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
100 // Compression buffer
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
101 unsigned char* comp_buf;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
102 #ifdef CONFIG_ZLIB
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
103 z_stream zstream;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
104 #endif
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
105 } LclContext;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
106
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
107
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
108 /*
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
109 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
110 * Helper functions
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
111 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
112 */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
113 static inline unsigned char fix (int pix14)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
114 {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
115 int tmp;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
116
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
117 tmp = (pix14 + 0x80000) >> 20;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
118 if (tmp < 0)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
119 return 0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
120 if (tmp > 255)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
121 return 255;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
122 return tmp;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
123 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
124
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
125
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
126
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
127 static inline unsigned char get_b (unsigned char yq, signed char bq)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
128 {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
129 return fix((yq << 20) + bq * 1858076);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
130 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
131
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
132
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
133
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
134 static inline unsigned char get_g (unsigned char yq, signed char bq, signed char rq)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
135 {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
136 return fix((yq << 20) - bq * 360857 - rq * 748830);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
137 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
138
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
139
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
140
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
141 static inline unsigned char get_r (unsigned char yq, signed char rq)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
142 {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
143 return fix((yq << 20) + rq * 1470103);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
144 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
145
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
146
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
147
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
148 static unsigned int mszh_decomp(unsigned char * srcptr, int srclen, unsigned char * destptr, unsigned int destsize)
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
149 {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
150 unsigned char *destptr_bak = destptr;
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
151 unsigned char *destptr_end = destptr + destsize;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
152 unsigned char mask = 0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
153 unsigned char maskbit = 0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
154 unsigned int ofs, cnt;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
155
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
156 while ((srclen > 0) && (destptr < destptr_end)) {
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
157 if (maskbit == 0) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
158 mask = *(srcptr++);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
159 maskbit = 8;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
160 srclen--;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
161 continue;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
162 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
163 if ((mask & (1 << (--maskbit))) == 0) {
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
164 if (destptr + 4 > destptr_end)
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
165 break;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
166 *(int*)destptr = *(int*)srcptr;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
167 srclen -= 4;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
168 destptr += 4;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
169 srcptr += 4;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
170 } else {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
171 ofs = *(srcptr++);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
172 cnt = *(srcptr++);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
173 ofs += cnt * 256;;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
174 cnt = ((cnt >> 3) & 0x1f) + 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
175 ofs &= 0x7ff;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
176 srclen -= 2;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
177 cnt *= 4;
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
178 if (destptr + cnt > destptr_end) {
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
179 cnt = destptr_end - destptr;
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
180 }
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
181 for (; cnt > 0; cnt--) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
182 *(destptr) = *(destptr - ofs);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
183 destptr++;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
184 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
185 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
186 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
187
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
188 return (destptr - destptr_bak);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
189 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
190
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
191
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
192
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
193
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
194 /*
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
195 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
196 * Decode a frame
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
197 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
198 */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
199 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
200 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
201 LclContext * const c = (LclContext *)avctx->priv_data;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
202 unsigned char *encoded = (unsigned char *)buf;
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
203 unsigned int pixel_ptr;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
204 int row, col;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
205 unsigned char *outptr;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
206 unsigned int width = avctx->width; // Real image width
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
207 unsigned int height = avctx->height; // Real image height
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
208 unsigned int mszh_dlen;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
209 unsigned char yq, y1q, uq, vq;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
210 int uqvq;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
211 unsigned int mthread_inlen, mthread_outlen;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
212 #ifdef CONFIG_ZLIB
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
213 int zret; // Zlib return code
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
214 #endif
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
215 unsigned int len = buf_size;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
216
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
217 if(c->pic.data[0])
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
218 avctx->release_buffer(avctx, &c->pic);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
219
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
220 c->pic.reference = 0;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
221 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
222 if(avctx->get_buffer(avctx, &c->pic) < 0){
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
223 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
224 return -1;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
225 }
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
226
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
227 outptr = c->pic.data[0]; // Output image pointer
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
228
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
229 /* Decompress frame */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
230 switch (avctx->codec_id) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
231 case CODEC_ID_MSZH:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
232 switch (c->compression) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
233 case COMP_MSZH:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
234 if (c->flags & FLAG_MULTITHREAD) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
235 mthread_inlen = *((unsigned int*)encoded);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
236 mthread_outlen = *((unsigned int*)(encoded+4));
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
237 if (mthread_outlen > c->decomp_size) // this should not happen
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
238 mthread_outlen = c->decomp_size;
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
239 mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf, c->decomp_size);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
240 if (mthread_outlen != mszh_dlen) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
241 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n",
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
242 mthread_outlen, mszh_dlen);
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
243 return -1;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
244 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
245 mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - mthread_inlen,
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
246 c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen);
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
247 if (mthread_outlen != mszh_dlen) {
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
248 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n",
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
249 mthread_outlen, mszh_dlen);
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
250 return -1;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
251 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
252 encoded = c->decomp_buf;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
253 len = c->decomp_size;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
254 } else {
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
255 mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf, c->decomp_size);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
256 if (c->decomp_size != mszh_dlen) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
257 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n",
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
258 c->decomp_size, mszh_dlen);
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
259 return -1;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
260 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
261 encoded = c->decomp_buf;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
262 len = mszh_dlen;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
263 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
264 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
265 case COMP_MSZH_NOCOMP:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
266 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
267 default:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
268 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
269 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
270 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
271 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
272 case CODEC_ID_ZLIB:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
273 #ifdef CONFIG_ZLIB
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
274 /* Using the original dll with normal compression (-1) and RGB format
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
275 * gives a file with ZLIB fourcc, but frame is really uncompressed.
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
276 * To be sure that's true check also frame size */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
277 if ((c->compression == COMP_ZLIB_NORMAL) && (c->imgtype == IMGTYPE_RGB24) &&
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
278 (len == width * height * 3))
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
279 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
280 zret = inflateReset(&(c->zstream));
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
281 if (zret != Z_OK) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
282 av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
283 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
284 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
285 if (c->flags & FLAG_MULTITHREAD) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
286 mthread_inlen = *((unsigned int*)encoded);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
287 mthread_outlen = *((unsigned int*)(encoded+4));
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
288 if (mthread_outlen > c->decomp_size)
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
289 mthread_outlen = c->decomp_size;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
290 c->zstream.next_in = encoded + 8;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
291 c->zstream.avail_in = mthread_inlen;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
292 c->zstream.next_out = c->decomp_buf;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
293 c->zstream.avail_out = c->decomp_size;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
294 zret = inflate(&(c->zstream), Z_FINISH);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
295 if ((zret != Z_OK) && (zret != Z_STREAM_END)) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
296 av_log(avctx, AV_LOG_ERROR, "Mthread1 inflate error: %d\n", zret);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
297 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
298 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
299 if (mthread_outlen != (unsigned int)(c->zstream.total_out)) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
300 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%u != %lu)\n",
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
301 mthread_outlen, c->zstream.total_out);
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
302 return -1;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
303 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
304 zret = inflateReset(&(c->zstream));
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
305 if (zret != Z_OK) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
306 av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate reset error: %d\n", zret);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
307 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
308 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
309 c->zstream.next_in = encoded + 8 + mthread_inlen;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
310 c->zstream.avail_in = len - mthread_inlen;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
311 c->zstream.next_out = c->decomp_buf + mthread_outlen;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
312 c->zstream.avail_out = c->decomp_size - mthread_outlen;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
313 zret = inflate(&(c->zstream), Z_FINISH);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
314 if ((zret != Z_OK) && (zret != Z_STREAM_END)) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
315 av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate error: %d\n", zret);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
316 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
317 }
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
318 if (mthread_outlen != (unsigned int)(c->zstream.total_out)) {
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
319 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %lu)\n",
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
320 mthread_outlen, c->zstream.total_out);
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
321 return -1;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
322 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
323 } else {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
324 c->zstream.next_in = encoded;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
325 c->zstream.avail_in = len;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
326 c->zstream.next_out = c->decomp_buf;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
327 c->zstream.avail_out = c->decomp_size;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
328 zret = inflate(&(c->zstream), Z_FINISH);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
329 if ((zret != Z_OK) && (zret != Z_STREAM_END)) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
330 av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
331 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
332 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
333 if (c->decomp_size != (unsigned int)(c->zstream.total_out)) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
334 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n",
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
335 c->decomp_size, c->zstream.total_out);
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
336 return -1;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
337 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
338 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
339 encoded = c->decomp_buf;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
340 len = c->decomp_size;;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
341 #else
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
342 av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
343 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
344 #endif
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
345 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
346 default:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
347 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
348 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
349 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
350
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
351
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
352 /* Apply PNG filter */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
353 if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
354 switch (c->imgtype) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
355 case IMGTYPE_YUV111:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
356 case IMGTYPE_RGB24:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
357 for (row = 0; row < height; row++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
358 pixel_ptr = row * width * 3;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
359 yq = encoded[pixel_ptr++];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
360 uqvq = encoded[pixel_ptr++];
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
361 uqvq+=(encoded[pixel_ptr++] << 8);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
362 for (col = 1; col < width; col++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
363 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
364 uqvq -= (encoded[pixel_ptr+1] | (encoded[pixel_ptr+2]<<8));
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
365 encoded[pixel_ptr+1] = (uqvq) & 0xff;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
366 encoded[pixel_ptr+2] = ((uqvq)>>8) & 0xff;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
367 pixel_ptr += 3;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
368 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
369 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
370 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
371 case IMGTYPE_YUV422:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
372 for (row = 0; row < height; row++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
373 pixel_ptr = row * width * 2;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
374 yq = uq = vq =0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
375 for (col = 0; col < width/4; col++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
376 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
377 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
378 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
379 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
380 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
381 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
382 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
383 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
384 pixel_ptr += 8;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
385 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
386 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
387 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
388 case IMGTYPE_YUV411:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
389 for (row = 0; row < height; row++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
390 pixel_ptr = row * width / 2 * 3;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
391 yq = uq = vq =0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
392 for (col = 0; col < width/4; col++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
393 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
394 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
395 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
396 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
397 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
398 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
399 pixel_ptr += 6;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
400 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
401 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
402 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
403 case IMGTYPE_YUV211:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
404 for (row = 0; row < height; row++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
405 pixel_ptr = row * width * 2;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
406 yq = uq = vq =0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
407 for (col = 0; col < width/2; col++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
408 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
409 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
410 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
411 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
412 pixel_ptr += 4;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
413 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
414 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
415 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
416 case IMGTYPE_YUV420:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
417 for (row = 0; row < height/2; row++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
418 pixel_ptr = row * width * 3;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
419 yq = y1q = uq = vq =0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
420 for (col = 0; col < width/2; col++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
421 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
422 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
423 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
424 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
425 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
426 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
427 pixel_ptr += 6;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
428 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
429 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
430 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
431 default:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
432 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
433 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
434 }
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 /* Convert colorspace */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
438 switch (c->imgtype) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
439 case IMGTYPE_YUV111:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
440 for (row = height - 1; row >= 0; row--) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
441 pixel_ptr = row * c->pic.linesize[0];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
442 for (col = 0; col < width; col++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
443 outptr[pixel_ptr++] = get_b(encoded[0], encoded[1]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
444 outptr[pixel_ptr++] = get_g(encoded[0], encoded[1], encoded[2]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
445 outptr[pixel_ptr++] = get_r(encoded[0], encoded[2]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
446 encoded += 3;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
447 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
448 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
449 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
450 case IMGTYPE_YUV422:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
451 for (row = height - 1; row >= 0; row--) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
452 pixel_ptr = row * c->pic.linesize[0];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
453 for (col = 0; col < width/4; col++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
454 outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
455 outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[6]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
456 outptr[pixel_ptr++] = get_r(encoded[0], encoded[6]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
457 outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
458 outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[6]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
459 outptr[pixel_ptr++] = get_r(encoded[1], encoded[6]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
460 outptr[pixel_ptr++] = get_b(encoded[2], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
461 outptr[pixel_ptr++] = get_g(encoded[2], encoded[5], encoded[7]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
462 outptr[pixel_ptr++] = get_r(encoded[2], encoded[7]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
463 outptr[pixel_ptr++] = get_b(encoded[3], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
464 outptr[pixel_ptr++] = get_g(encoded[3], encoded[5], encoded[7]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
465 outptr[pixel_ptr++] = get_r(encoded[3], encoded[7]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
466 encoded += 8;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
467 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
468 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
469 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
470 case IMGTYPE_RGB24:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
471 for (row = height - 1; row >= 0; row--) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
472 pixel_ptr = row * c->pic.linesize[0];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
473 for (col = 0; col < width; col++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
474 outptr[pixel_ptr++] = encoded[0];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
475 outptr[pixel_ptr++] = encoded[1];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
476 outptr[pixel_ptr++] = encoded[2];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
477 encoded += 3;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
478 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
479 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
480 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
481 case IMGTYPE_YUV411:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
482 for (row = height - 1; row >= 0; row--) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
483 pixel_ptr = row * c->pic.linesize[0];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
484 for (col = 0; col < width/4; col++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
485 outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
486 outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
487 outptr[pixel_ptr++] = get_r(encoded[0], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
488 outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
489 outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
490 outptr[pixel_ptr++] = get_r(encoded[1], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
491 outptr[pixel_ptr++] = get_b(encoded[2], encoded[4]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
492 outptr[pixel_ptr++] = get_g(encoded[2], encoded[4], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
493 outptr[pixel_ptr++] = get_r(encoded[2], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
494 outptr[pixel_ptr++] = get_b(encoded[3], encoded[4]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
495 outptr[pixel_ptr++] = get_g(encoded[3], encoded[4], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
496 outptr[pixel_ptr++] = get_r(encoded[3], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
497 encoded += 6;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
498 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
499 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
500 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
501 case IMGTYPE_YUV211:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
502 for (row = height - 1; row >= 0; row--) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
503 pixel_ptr = row * c->pic.linesize[0];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
504 for (col = 0; col < width/2; col++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
505 outptr[pixel_ptr++] = get_b(encoded[0], encoded[2]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
506 outptr[pixel_ptr++] = get_g(encoded[0], encoded[2], encoded[3]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
507 outptr[pixel_ptr++] = get_r(encoded[0], encoded[3]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
508 outptr[pixel_ptr++] = get_b(encoded[1], encoded[2]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
509 outptr[pixel_ptr++] = get_g(encoded[1], encoded[2], encoded[3]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
510 outptr[pixel_ptr++] = get_r(encoded[1], encoded[3]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
511 encoded += 4;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
512 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
513 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
514 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
515 case IMGTYPE_YUV420:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
516 for (row = height / 2 - 1; row >= 0; row--) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
517 pixel_ptr = 2 * row * c->pic.linesize[0];
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
518 for (col = 0; col < width/2; col++) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
519 outptr[pixel_ptr] = get_b(encoded[0], encoded[4]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
520 outptr[pixel_ptr+1] = get_g(encoded[0], encoded[4], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
521 outptr[pixel_ptr+2] = get_r(encoded[0], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
522 outptr[pixel_ptr+3] = get_b(encoded[1], encoded[4]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
523 outptr[pixel_ptr+4] = get_g(encoded[1], encoded[4], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
524 outptr[pixel_ptr+5] = get_r(encoded[1], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
525 outptr[pixel_ptr-c->pic.linesize[0]] = get_b(encoded[2], encoded[4]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
526 outptr[pixel_ptr-c->pic.linesize[0]+1] = get_g(encoded[2], encoded[4], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
527 outptr[pixel_ptr-c->pic.linesize[0]+2] = get_r(encoded[2], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
528 outptr[pixel_ptr-c->pic.linesize[0]+3] = get_b(encoded[3], encoded[4]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
529 outptr[pixel_ptr-c->pic.linesize[0]+4] = get_g(encoded[3], encoded[4], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
530 outptr[pixel_ptr-c->pic.linesize[0]+5] = get_r(encoded[3], encoded[5]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
531 pixel_ptr += 6;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
532 encoded += 6;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
533 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
534 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
535 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
536 default:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
537 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
538 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
539 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
540
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
541 *data_size = sizeof(AVFrame);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
542 *(AVFrame*)data = c->pic;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
543
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
544 /* always report that the buffer was completely consumed */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
545 return buf_size;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
546 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
547
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
548
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
549
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
550 /*
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
551 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
552 * Encode a frame
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
553 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
554 */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
555 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
556 LclContext *c = avctx->priv_data;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
557 AVFrame *pict = data;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
558 AVFrame * const p = &c->pic;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
559 int i;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
560 int zret; // Zlib return code
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
561
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
562 #ifndef CONFIG_ZLIB
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
563 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled in.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
564 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
565 #else
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
566
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
567 init_put_bits(&c->pb, buf, buf_size);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
568
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
569 *p = *pict;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
570 p->pict_type= FF_I_TYPE;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
571 p->key_frame= 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
572
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
573 if(avctx->pix_fmt != PIX_FMT_BGR24){
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
574 av_log(avctx, AV_LOG_ERROR, "Format not supported!\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
575 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
576 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
577
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
578 zret = deflateReset(&(c->zstream));
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
579 if (zret != Z_OK) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
580 av_log(avctx, AV_LOG_ERROR, "Deflate reset error: %d\n", zret);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
581 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
582 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
583 c->zstream.next_out = c->comp_buf;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
584 c->zstream.avail_out = c->max_comp_size;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
585
2250
902caf560c43 Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents: 2248
diff changeset
586 for(i = avctx->height - 1; i >= 0; i--) {
902caf560c43 Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents: 2248
diff changeset
587 c->zstream.next_in = p->data[0]+p->linesize[0]*i;
902caf560c43 Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents: 2248
diff changeset
588 c->zstream.avail_in = avctx->width*3;
902caf560c43 Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents: 2248
diff changeset
589 zret = deflate(&(c->zstream), Z_NO_FLUSH);
902caf560c43 Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents: 2248
diff changeset
590 if (zret != Z_OK) {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
591 av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
592 return -1;
2250
902caf560c43 Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents: 2248
diff changeset
593 }
902caf560c43 Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents: 2248
diff changeset
594 }
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
595 zret = deflate(&(c->zstream), Z_FINISH);
2250
902caf560c43 Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents: 2248
diff changeset
596 if (zret != Z_STREAM_END) {
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
597 av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
598 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
599 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
600
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
601 for (i = 0; i < c->zstream.total_out; i++)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
602 put_bits(&c->pb, 8, c->comp_buf[i]);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
603 flush_put_bits(&c->pb);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
604
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
605 return c->zstream.total_out;
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 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
608
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
609
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
610
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
611 /*
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
612 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
613 * Init lcl decoder
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
614 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
615 */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
616 static int decode_init(AVCodecContext *avctx)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
617 {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
618 LclContext * const c = (LclContext *)avctx->priv_data;
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
619 unsigned int basesize = avctx->width * avctx->height;
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
620 unsigned int max_basesize = ((avctx->width + 3) & ~3) * ((avctx->height + 3) & ~3);
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
621 unsigned int max_decomp_size;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
622 int zret; // Zlib return code
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
623
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
624 c->avctx = avctx;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
625 avctx->has_b_frames = 0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
626
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
627 c->pic.data[0] = NULL;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
628
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
629 #ifdef CONFIG_ZLIB
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
630 // Needed if zlib unused or init aborted before inflateInit
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
631 memset(&(c->zstream), 0, sizeof(z_stream));
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
632 #endif
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
633
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
634 if (avctx->extradata_size < 8) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
635 av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
636 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
637 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
638
2429
4b350cc506a7 Use avcodec_check_dimensions instead of custom hack
rtognimp
parents: 2418
diff changeset
639 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
640 return 1;
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
641 }
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
642
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
643 /* Check codec type */
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
644 if (((avctx->codec_id == CODEC_ID_MSZH) && (*((char *)avctx->extradata + 7) != CODEC_MSZH)) ||
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
645 ((avctx->codec_id == CODEC_ID_ZLIB) && (*((char *)avctx->extradata + 7) != CODEC_ZLIB))) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
646 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
647 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
648
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
649 /* Detect image type */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
650 switch (c->imgtype = *((char *)avctx->extradata + 4)) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
651 case IMGTYPE_YUV111:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
652 c->decomp_size = basesize * 3;
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
653 max_decomp_size = max_basesize * 3;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
654 av_log(avctx, AV_LOG_INFO, "Image type is YUV 1:1:1.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
655 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
656 case IMGTYPE_YUV422:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
657 c->decomp_size = basesize * 2;
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
658 max_decomp_size = max_basesize * 2;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
659 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:2.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
660 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
661 case IMGTYPE_RGB24:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
662 c->decomp_size = basesize * 3;
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
663 max_decomp_size = max_basesize * 3;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
664 av_log(avctx, AV_LOG_INFO, "Image type is RGB 24.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
665 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
666 case IMGTYPE_YUV411:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
667 c->decomp_size = basesize / 2 * 3;
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
668 max_decomp_size = max_basesize / 2 * 3;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
669 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:1:1.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
670 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
671 case IMGTYPE_YUV211:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
672 c->decomp_size = basesize * 2;
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
673 max_decomp_size = max_basesize * 2;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
674 av_log(avctx, AV_LOG_INFO, "Image type is YUV 2:1:1.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
675 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
676 case IMGTYPE_YUV420:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
677 c->decomp_size = basesize / 2 * 3;
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
678 max_decomp_size = max_basesize / 2 * 3;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
679 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:0.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
680 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
681 default:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
682 av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
683 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
684 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
685
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
686 /* Detect compression method */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
687 c->compression = *((char *)avctx->extradata + 5);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
688 switch (avctx->codec_id) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
689 case CODEC_ID_MSZH:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
690 switch (c->compression) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
691 case COMP_MSZH:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
692 av_log(avctx, AV_LOG_INFO, "Compression enabled.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
693 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
694 case COMP_MSZH_NOCOMP:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
695 c->decomp_size = 0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
696 av_log(avctx, AV_LOG_INFO, "No compression.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
697 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
698 default:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
699 av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
700 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
701 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
702 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
703 case CODEC_ID_ZLIB:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
704 #ifdef CONFIG_ZLIB
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
705 switch (c->compression) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
706 case COMP_ZLIB_HISPEED:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
707 av_log(avctx, AV_LOG_INFO, "High speed compression.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
708 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
709 case COMP_ZLIB_HICOMP:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
710 av_log(avctx, AV_LOG_INFO, "High compression.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
711 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
712 case COMP_ZLIB_NORMAL:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
713 av_log(avctx, AV_LOG_INFO, "Normal compression.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
714 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
715 default:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
716 if ((c->compression < Z_NO_COMPRESSION) || (c->compression > Z_BEST_COMPRESSION)) {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
717 av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
718 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
719 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
720 av_log(avctx, AV_LOG_INFO, "Compression level for ZLIB: (%d).\n", c->compression);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
721 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
722 #else
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
723 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
724 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
725 #endif
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
726 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
727 default:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
728 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
729 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
730 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
731
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
732 /* Allocate decompression buffer */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
733 if (c->decomp_size) {
2418
82af834636c2 Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents: 2398
diff changeset
734 if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) {
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
735 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
736 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
737 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
738 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
739
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
740 /* Detect flags */
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
741 c->flags = *((char *)avctx->extradata + 6);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
742 if (c->flags & FLAG_MULTITHREAD)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
743 av_log(avctx, AV_LOG_INFO, "Multithread encoder flag set.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
744 if (c->flags & FLAG_NULLFRAME)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
745 av_log(avctx, AV_LOG_INFO, "Nullframe insertion flag set.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
746 if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER))
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
747 av_log(avctx, AV_LOG_INFO, "PNG filter flag set.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
748 if (c->flags & FLAGMASK_UNUSED)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
749 av_log(avctx, AV_LOG_ERROR, "Unknown flag set (%d).\n", c->flags);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
750
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
751 /* If needed init zlib */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
752 if (avctx->codec_id == CODEC_ID_ZLIB) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
753 #ifdef CONFIG_ZLIB
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
754 c->zstream.zalloc = Z_NULL;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
755 c->zstream.zfree = Z_NULL;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
756 c->zstream.opaque = Z_NULL;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
757 zret = inflateInit(&(c->zstream));
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
758 if (zret != Z_OK) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
759 av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
760 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
761 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
762 #else
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
763 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
764 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
765 #endif
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
766 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
767
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
768 avctx->pix_fmt = PIX_FMT_BGR24;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
769
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
770 return 0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
771 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
772
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
773
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
774
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
775 /*
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
776 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
777 * Init lcl encoder
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
778 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
779 */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
780 static int encode_init(AVCodecContext *avctx)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
781 {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
782 LclContext *c = avctx->priv_data;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
783 int zret; // Zlib return code
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
784
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
785 #ifndef CONFIG_ZLIB
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
786 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
787 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
788 #else
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
789
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
790 c->avctx= avctx;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
791
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
792 assert(avctx->width && avctx->height);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
793
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
794 avctx->extradata= av_mallocz(8);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
795 avctx->coded_frame= &c->pic;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
796
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
797 // Will be user settable someday
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
798 c->compression = 6;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
799 c->flags = 0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
800
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
801 switch(avctx->pix_fmt){
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
802 case PIX_FMT_BGR24:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
803 c->imgtype = IMGTYPE_RGB24;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
804 c->decomp_size = avctx->width * avctx->height * 3;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
805 avctx->bits_per_sample= 24;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
806 break;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
807 default:
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
808 av_log(avctx, AV_LOG_ERROR, "Format %d not supported\n", avctx->pix_fmt);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
809 return -1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
810 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
811
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
812 ((uint8_t*)avctx->extradata)[0]= 4;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
813 ((uint8_t*)avctx->extradata)[1]= 0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
814 ((uint8_t*)avctx->extradata)[2]= 0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
815 ((uint8_t*)avctx->extradata)[3]= 0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
816 ((uint8_t*)avctx->extradata)[4]= c->imgtype;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
817 ((uint8_t*)avctx->extradata)[5]= c->compression;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
818 ((uint8_t*)avctx->extradata)[6]= c->flags;
2250
902caf560c43 Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents: 2248
diff changeset
819 ((uint8_t*)avctx->extradata)[7]= CODEC_ZLIB;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
820 c->avctx->extradata_size= 8;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
821
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
822 c->zstream.zalloc = Z_NULL;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
823 c->zstream.zfree = Z_NULL;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
824 c->zstream.opaque = Z_NULL;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
825 zret = deflateInit(&(c->zstream), c->compression);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
826 if (zret != Z_OK) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
827 av_log(avctx, AV_LOG_ERROR, "Deflate init error: %d\n", zret);
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
828 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
829 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
830
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
831 /* Conservative upper bound taken from zlib v1.2.1 source */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
832 c->max_comp_size = c->decomp_size + ((c->decomp_size + 7) >> 3) +
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
833 ((c->decomp_size + 63) >> 6) + 11;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
834 if ((c->comp_buf = av_malloc(c->max_comp_size)) == NULL) {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
835 av_log(avctx, AV_LOG_ERROR, "Can't allocate compression buffer.\n");
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
836 return 1;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
837 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
838
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
839 return 0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
840 #endif
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
841 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
842
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
843
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
844
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
845
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
846
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
847 /*
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
848 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
849 * Uninit lcl decoder
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
850 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
851 */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
852 static int decode_end(AVCodecContext *avctx)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
853 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
854 LclContext * const c = (LclContext *)avctx->priv_data;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
855
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
856 if (c->pic.data[0])
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
857 avctx->release_buffer(avctx, &c->pic);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
858 #ifdef CONFIG_ZLIB
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
859 inflateEnd(&(c->zstream));
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
860 #endif
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
861
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
862 return 0;
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
863 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
864
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
865
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
866
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
867 /*
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
868 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
869 * Uninit lcl encoder
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
870 *
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
871 */
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
872 static int encode_end(AVCodecContext *avctx)
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
873 {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
874 LclContext *c = avctx->priv_data;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
875
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
876 av_freep(&avctx->extradata);
2248
e4e1b4f31db6 segfault fix by (Kostya <cannonball at bw-team dot com>)
michael
parents: 1744
diff changeset
877 av_freep(&c->comp_buf);
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
878 #ifdef CONFIG_ZLIB
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
879 deflateEnd(&(c->zstream));
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
880 #endif
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
881
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
882 return 0;
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
883 }
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
884
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
885 AVCodec mszh_decoder = {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
886 "mszh",
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
887 CODEC_TYPE_VIDEO,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
888 CODEC_ID_MSZH,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
889 sizeof(LclContext),
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
890 decode_init,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
891 NULL,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
892 decode_end,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
893 decode_frame,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
894 CODEC_CAP_DR1,
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
895 };
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
896
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
897
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
898 AVCodec zlib_decoder = {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
899 "zlib",
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
900 CODEC_TYPE_VIDEO,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
901 CODEC_ID_ZLIB,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
902 sizeof(LclContext),
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
903 decode_init,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
904 NULL,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
905 decode_end,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
906 decode_frame,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
907 CODEC_CAP_DR1,
1743
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
908 };
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
909
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
910 #ifdef CONFIG_ENCODERS
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
911
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
912 AVCodec zlib_encoder = {
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
913 "zlib",
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
914 CODEC_TYPE_VIDEO,
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
915 CODEC_ID_ZLIB,
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
916 sizeof(LclContext),
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
917 encode_init,
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
918 encode_frame,
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
919 encode_end,
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
920 };
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
921
fa06a4a448f7 Fix for older version of zlib
rtognimp
parents:
diff changeset
922 #endif //CONFIG_ENCODERS