annotate lcl.c @ 2282:e8d3609e89a5 libavcodec

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