Mercurial > libavcodec.hg
annotate huffyuv.c @ 1356:9e31b6bfb1a2 libavcodec
fix? flv escape codes
author | michaelni |
---|---|
date | Thu, 10 Jul 2003 10:24:47 +0000 |
parents | 1cbc2380d172 |
children | 0fd38b711f06 |
rev | line source |
---|---|
866 | 1 /* |
2 * huffyuv codec for libavcodec | |
3 * | |
1006 | 4 * Copyright (c) 2002-2003 Michael Niedermayer <michaelni@gmx.at> |
866 | 5 * |
6 * This library is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU Lesser General Public | |
8 * License as published by the Free Software Foundation; either | |
9 * version 2 of the License, or (at your option) any later version. | |
10 * | |
11 * This library is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Lesser General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Lesser General Public | |
17 * License along with this library; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 * see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of | |
21 * the algorithm used | |
22 */ | |
1106 | 23 |
24 /** | |
25 * @file huffyuv.c | |
26 * huffyuv codec for libavcodec. | |
27 */ | |
866 | 28 |
29 #include "common.h" | |
30 #include "avcodec.h" | |
31 #include "dsputil.h" | |
32 | |
869 | 33 #ifndef INT64_MAX |
34 #define INT64_MAX 9223372036854775807LL | |
866 | 35 #endif |
36 | |
37 #define VLC_BITS 11 | |
903 | 38 |
866 | 39 typedef enum Predictor{ |
40 LEFT= 0, | |
41 PLANE, | |
42 MEDIAN, | |
43 } Predictor; | |
44 | |
45 typedef struct HYuvContext{ | |
46 AVCodecContext *avctx; | |
47 Predictor predictor; | |
48 GetBitContext gb; | |
49 PutBitContext pb; | |
50 int interlaced; | |
51 int decorrelate; | |
52 int bitstream_bpp; | |
53 int version; | |
54 int yuy2; //use yuy2 instead of 422P | |
55 int bgr32; //use bgr32 instead of bgr24 | |
56 int width, height; | |
57 int flags; | |
58 int picture_number; | |
871 | 59 int last_slice_end; |
866 | 60 uint8_t __align8 temp[3][2500]; |
61 uint64_t stats[3][256]; | |
62 uint8_t len[3][256]; | |
63 uint32_t bits[3][256]; | |
64 VLC vlc[3]; | |
925 | 65 AVFrame picture; |
866 | 66 uint8_t __align8 bitstream_buffer[1024*1024*3]; //FIXME dynamic alloc or some other solution |
67 DSPContext dsp; | |
68 }HYuvContext; | |
69 | |
1082 | 70 static const unsigned char classic_shift_luma[] = { |
1080
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
71 34,36,35,69,135,232,9,16,10,24,11,23,12,16,13,10,14,8,15,8, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
72 16,8,17,20,16,10,207,206,205,236,11,8,10,21,9,23,8,8,199,70, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
73 69,68, 0 |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
74 }; |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
75 |
1082 | 76 static const unsigned char classic_shift_chroma[] = { |
1080
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
77 66,36,37,38,39,40,41,75,76,77,110,239,144,81,82,83,84,85,118,183, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
78 56,57,88,89,56,89,154,57,58,57,26,141,57,56,58,57,58,57,184,119, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
79 214,245,116,83,82,49,80,79,78,77,44,75,41,40,39,38,37,36,34, 0 |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
80 }; |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
81 |
1082 | 82 static const unsigned char classic_add_luma[256] = { |
1080
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
83 3, 9, 5, 12, 10, 35, 32, 29, 27, 50, 48, 45, 44, 41, 39, 37, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
84 73, 70, 68, 65, 64, 61, 58, 56, 53, 50, 49, 46, 44, 41, 38, 36, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
85 68, 65, 63, 61, 58, 55, 53, 51, 48, 46, 45, 43, 41, 39, 38, 36, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
86 35, 33, 32, 30, 29, 27, 26, 25, 48, 47, 46, 44, 43, 41, 40, 39, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
87 37, 36, 35, 34, 32, 31, 30, 28, 27, 26, 24, 23, 22, 20, 19, 37, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
88 35, 34, 33, 31, 30, 29, 27, 26, 24, 23, 21, 20, 18, 17, 15, 29, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
89 27, 26, 24, 22, 21, 19, 17, 16, 14, 26, 25, 23, 21, 19, 18, 16, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
90 15, 27, 25, 23, 21, 19, 17, 16, 14, 26, 25, 23, 21, 18, 17, 14, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
91 12, 17, 19, 13, 4, 9, 2, 11, 1, 7, 8, 0, 16, 3, 14, 6, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
92 12, 10, 5, 15, 18, 11, 10, 13, 15, 16, 19, 20, 22, 24, 27, 15, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
93 18, 20, 22, 24, 26, 14, 17, 20, 22, 24, 27, 15, 18, 20, 23, 25, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
94 28, 16, 19, 22, 25, 28, 32, 36, 21, 25, 29, 33, 38, 42, 45, 49, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
95 28, 31, 34, 37, 40, 42, 44, 47, 49, 50, 52, 54, 56, 57, 59, 60, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
96 62, 64, 66, 67, 69, 35, 37, 39, 40, 42, 43, 45, 47, 48, 51, 52, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
97 54, 55, 57, 59, 60, 62, 63, 66, 67, 69, 71, 72, 38, 40, 42, 43, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
98 46, 47, 49, 51, 26, 28, 30, 31, 33, 34, 18, 19, 11, 13, 7, 8, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
99 }; |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
100 |
1082 | 101 static const unsigned char classic_add_chroma[256] = { |
1080
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
102 3, 1, 2, 2, 2, 2, 3, 3, 7, 5, 7, 5, 8, 6, 11, 9, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
103 7, 13, 11, 10, 9, 8, 7, 5, 9, 7, 6, 4, 7, 5, 8, 7, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
104 11, 8, 13, 11, 19, 15, 22, 23, 20, 33, 32, 28, 27, 29, 51, 77, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
105 43, 45, 76, 81, 46, 82, 75, 55, 56,144, 58, 80, 60, 74,147, 63, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
106 143, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
107 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 27, 30, 21, 22, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
108 17, 14, 5, 6,100, 54, 47, 50, 51, 53,106,107,108,109,110,111, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
109 112,113,114,115, 4,117,118, 92, 94,121,122, 3,124,103, 2, 1, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
110 0,129,130,131,120,119,126,125,136,137,138,139,140,141,142,134, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
111 135,132,133,104, 64,101, 62, 57,102, 95, 93, 59, 61, 28, 97, 96, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
112 52, 49, 48, 29, 32, 25, 24, 46, 23, 98, 45, 44, 43, 20, 42, 41, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
113 19, 18, 99, 40, 15, 39, 38, 16, 13, 12, 11, 37, 10, 9, 8, 36, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
114 7,128,127,105,123,116, 35, 34, 33,145, 31, 79, 42,146, 78, 26, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
115 83, 48, 49, 50, 44, 47, 26, 31, 30, 18, 17, 19, 21, 24, 25, 13, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
116 14, 16, 17, 18, 20, 21, 12, 14, 15, 9, 10, 6, 9, 6, 5, 8, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
117 6, 12, 8, 10, 7, 9, 6, 4, 6, 2, 2, 3, 3, 3, 3, 2, |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
118 }; |
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
119 |
866 | 120 static inline int add_left_prediction(uint8_t *dst, uint8_t *src, int w, int acc){ |
121 int i; | |
122 | |
123 for(i=0; i<w-1; i++){ | |
124 acc+= src[i]; | |
125 dst[i]= acc; | |
126 i++; | |
127 acc+= src[i]; | |
128 dst[i]= acc; | |
129 } | |
130 | |
131 for(; i<w; i++){ | |
132 acc+= src[i]; | |
133 dst[i]= acc; | |
134 } | |
135 | |
136 return acc; | |
137 } | |
138 | |
139 static inline void add_median_prediction(uint8_t *dst, uint8_t *src1, uint8_t *diff, int w, int *left, int *left_top){ | |
140 int i; | |
141 uint8_t l, lt; | |
142 | |
143 l= *left; | |
144 lt= *left_top; | |
145 | |
146 for(i=0; i<w; i++){ | |
147 l= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF) + diff[i]; | |
148 lt= src1[i]; | |
149 dst[i]= l; | |
150 } | |
151 | |
152 *left= l; | |
153 *left_top= lt; | |
154 } | |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
155 |
866 | 156 //FIXME optimize |
157 static inline void sub_median_prediction(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){ | |
158 int i; | |
159 uint8_t l, lt; | |
160 | |
161 l= *left; | |
162 lt= *left_top; | |
163 | |
164 for(i=0; i<w; i++){ | |
165 const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF); | |
166 lt= src1[i]; | |
167 l= src2[i]; | |
168 dst[i]= l - pred; | |
169 } | |
170 | |
171 *left= l; | |
172 *left_top= lt; | |
173 } | |
174 | |
175 static inline void add_left_prediction_bgr32(uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue){ | |
176 int i; | |
177 int r,g,b; | |
178 r= *red; | |
179 g= *green; | |
180 b= *blue; | |
181 | |
182 for(i=0; i<w; i++){ | |
183 b+= src[4*i+0]; | |
184 g+= src[4*i+1]; | |
185 r+= src[4*i+2]; | |
186 | |
187 dst[4*i+0]= b; | |
188 dst[4*i+1]= g; | |
189 dst[4*i+2]= r; | |
190 } | |
191 | |
192 *red= r; | |
193 *green= g; | |
194 *blue= b; | |
195 } | |
196 | |
871 | 197 static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int left){ |
866 | 198 int i; |
871 | 199 if(w<32){ |
200 for(i=0; i<w; i++){ | |
201 const int temp= src[i]; | |
202 dst[i]= temp - left; | |
203 left= temp; | |
204 } | |
205 return left; | |
206 }else{ | |
207 for(i=0; i<16; i++){ | |
208 const int temp= src[i]; | |
209 dst[i]= temp - left; | |
210 left= temp; | |
211 } | |
212 s->dsp.diff_bytes(dst+16, src+16, src+15, w-16); | |
213 return src[w-1]; | |
866 | 214 } |
215 } | |
1325 | 216 |
866 | 217 static void read_len_table(uint8_t *dst, GetBitContext *gb){ |
218 int i, val, repeat; | |
219 | |
220 for(i=0; i<256;){ | |
221 repeat= get_bits(gb, 3); | |
222 val = get_bits(gb, 5); | |
223 if(repeat==0) | |
224 repeat= get_bits(gb, 8); | |
225 //printf("%d %d\n", val, repeat); | |
226 while (repeat--) | |
227 dst[i++] = val; | |
228 } | |
229 } | |
230 | |
231 static int generate_bits_table(uint32_t *dst, uint8_t *len_table){ | |
232 int len, index; | |
233 uint32_t bits=0; | |
234 | |
235 for(len=32; len>0; len--){ | |
236 for(index=0; index<256; index++){ | |
1279 | 237 if(len_table[index]==len) |
238 dst[index]= bits++; | |
866 | 239 } |
1279 | 240 if(bits & 1){ |
241 fprintf(stderr, "Error generating huffman table\n"); | |
242 return -1; | |
243 } | |
244 bits >>= 1; | |
866 | 245 } |
246 return 0; | |
247 } | |
248 | |
249 static void generate_len_table(uint8_t *dst, uint64_t *stats, int size){ | |
250 uint64_t counts[2*size]; | |
251 int up[2*size]; | |
252 int offset, i, next; | |
253 | |
254 for(offset=1; ; offset<<=1){ | |
255 for(i=0; i<size; i++){ | |
256 counts[i]= stats[i] + offset - 1; | |
257 } | |
258 | |
259 for(next=size; next<size*2; next++){ | |
260 uint64_t min1, min2; | |
261 int min1_i, min2_i; | |
262 | |
263 min1=min2= INT64_MAX; | |
264 min1_i= min2_i=-1; | |
265 | |
266 for(i=0; i<next; i++){ | |
267 if(min2 > counts[i]){ | |
268 if(min1 > counts[i]){ | |
269 min2= min1; | |
270 min2_i= min1_i; | |
271 min1= counts[i]; | |
272 min1_i= i; | |
273 }else{ | |
274 min2= counts[i]; | |
275 min2_i= i; | |
276 } | |
277 } | |
278 } | |
279 | |
280 if(min2==INT64_MAX) break; | |
281 | |
282 counts[next]= min1 + min2; | |
283 counts[min1_i]= | |
869 | 284 counts[min2_i]= INT64_MAX; |
866 | 285 up[min1_i]= |
286 up[min2_i]= next; | |
287 up[next]= -1; | |
288 } | |
289 | |
290 for(i=0; i<size; i++){ | |
291 int len; | |
292 int index=i; | |
293 | |
294 for(len=0; up[index] != -1; len++) | |
295 index= up[index]; | |
296 | |
297 if(len > 32) break; | |
298 | |
299 dst[i]= len; | |
300 } | |
301 if(i==size) break; | |
302 } | |
303 } | |
304 | |
305 static int read_huffman_tables(HYuvContext *s, uint8_t *src, int length){ | |
306 GetBitContext gb; | |
307 int i; | |
308 | |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1006
diff
changeset
|
309 init_get_bits(&gb, src, length*8); |
866 | 310 |
311 for(i=0; i<3; i++){ | |
312 read_len_table(s->len[i], &gb); | |
313 | |
314 if(generate_bits_table(s->bits[i], s->len[i])<0){ | |
315 return -1; | |
316 } | |
317 #if 0 | |
318 for(j=0; j<256; j++){ | |
319 printf("%6X, %2d, %3d\n", s->bits[i][j], s->len[i][j], j); | |
320 } | |
321 #endif | |
322 init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4); | |
323 } | |
324 | |
325 return 0; | |
326 } | |
327 | |
328 static int read_old_huffman_tables(HYuvContext *s){ | |
1080
a150aba978de
huffyuv v1 tables, as they are essential and the only possible way for decding of v1 files they very likely cant be copyrighted ...
michaelni
parents:
1078
diff
changeset
|
329 #if 1 |
866 | 330 GetBitContext gb; |
331 int i; | |
332 | |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1006
diff
changeset
|
333 init_get_bits(&gb, classic_shift_luma, sizeof(classic_shift_luma)*8); |
866 | 334 read_len_table(s->len[0], &gb); |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1006
diff
changeset
|
335 init_get_bits(&gb, classic_shift_chroma, sizeof(classic_shift_chroma)*8); |
866 | 336 read_len_table(s->len[1], &gb); |
337 | |
338 for(i=0; i<256; i++) s->bits[0][i] = classic_add_luma [i]; | |
339 for(i=0; i<256; i++) s->bits[1][i] = classic_add_chroma[i]; | |
340 | |
341 if(s->bitstream_bpp >= 24){ | |
342 memcpy(s->bits[1], s->bits[0], 256*sizeof(uint32_t)); | |
343 memcpy(s->len[1] , s->len [0], 256*sizeof(uint8_t)); | |
344 } | |
345 memcpy(s->bits[2], s->bits[1], 256*sizeof(uint32_t)); | |
346 memcpy(s->len[2] , s->len [1], 256*sizeof(uint8_t)); | |
347 | |
348 for(i=0; i<3; i++) | |
349 init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4); | |
350 | |
351 return 0; | |
352 #else | |
353 fprintf(stderr, "v1 huffyuv is not supported \n"); | |
354 return -1; | |
355 #endif | |
356 } | |
357 | |
358 static int decode_init(AVCodecContext *avctx) | |
359 { | |
360 HYuvContext *s = avctx->priv_data; | |
903 | 361 int width, height; |
866 | 362 |
363 s->avctx= avctx; | |
364 s->flags= avctx->flags; | |
365 | |
1097 | 366 dsputil_init(&s->dsp, avctx); |
866 | 367 |
368 width= s->width= avctx->width; | |
369 height= s->height= avctx->height; | |
925 | 370 avctx->coded_frame= &s->picture; |
903 | 371 |
866 | 372 s->bgr32=1; |
373 assert(width && height); | |
374 //if(avctx->extradata) | |
375 // printf("extradata:%X, extradata_size:%d\n", *(uint32_t*)avctx->extradata, avctx->extradata_size); | |
376 if(avctx->extradata_size){ | |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
377 if((avctx->bits_per_sample&7) && avctx->bits_per_sample != 12) |
866 | 378 s->version=1; // do such files exist at all? |
379 else | |
380 s->version=2; | |
381 }else | |
382 s->version=0; | |
383 | |
384 if(s->version==2){ | |
385 int method; | |
386 | |
387 method= ((uint8_t*)avctx->extradata)[0]; | |
388 s->decorrelate= method&64 ? 1 : 0; | |
389 s->predictor= method&63; | |
390 s->bitstream_bpp= ((uint8_t*)avctx->extradata)[1]; | |
391 if(s->bitstream_bpp==0) | |
392 s->bitstream_bpp= avctx->bits_per_sample&~7; | |
393 | |
394 if(read_huffman_tables(s, ((uint8_t*)avctx->extradata)+4, avctx->extradata_size) < 0) | |
395 return -1; | |
396 }else{ | |
397 switch(avctx->bits_per_sample&7){ | |
398 case 1: | |
399 s->predictor= LEFT; | |
400 s->decorrelate= 0; | |
401 break; | |
402 case 2: | |
403 s->predictor= LEFT; | |
404 s->decorrelate= 1; | |
405 break; | |
406 case 3: | |
407 s->predictor= PLANE; | |
408 s->decorrelate= avctx->bits_per_sample >= 24; | |
409 break; | |
410 case 4: | |
411 s->predictor= MEDIAN; | |
412 s->decorrelate= 0; | |
413 break; | |
414 default: | |
415 s->predictor= LEFT; //OLD | |
416 s->decorrelate= 0; | |
417 break; | |
418 } | |
419 s->bitstream_bpp= avctx->bits_per_sample & ~7; | |
420 | |
421 if(read_old_huffman_tables(s) < 0) | |
422 return -1; | |
423 } | |
424 | |
425 s->interlaced= height > 288; | |
426 | |
427 switch(s->bitstream_bpp){ | |
428 case 12: | |
429 avctx->pix_fmt = PIX_FMT_YUV420P; | |
430 break; | |
431 case 16: | |
432 if(s->yuy2){ | |
433 avctx->pix_fmt = PIX_FMT_YUV422; | |
434 }else{ | |
435 avctx->pix_fmt = PIX_FMT_YUV422P; | |
436 } | |
437 break; | |
438 case 24: | |
439 case 32: | |
440 if(s->bgr32){ | |
990
165064f921ee
changed BGRA32 to RGBA32. XXX: clarify expected behaviour on big endian cpu
bellard
parents:
925
diff
changeset
|
441 avctx->pix_fmt = PIX_FMT_RGBA32; |
866 | 442 }else{ |
443 avctx->pix_fmt = PIX_FMT_BGR24; | |
444 } | |
445 break; | |
446 default: | |
447 assert(0); | |
448 } | |
449 | |
450 // printf("pred:%d bpp:%d hbpp:%d il:%d\n", s->predictor, s->bitstream_bpp, avctx->bits_per_sample, s->interlaced); | |
451 | |
452 return 0; | |
453 } | |
454 | |
455 static void store_table(HYuvContext *s, uint8_t *len){ | |
456 int i; | |
457 int index= s->avctx->extradata_size; | |
458 | |
459 for(i=0; i<256;){ | |
460 int cur=i; | |
461 int val= len[i]; | |
462 int repeat; | |
463 | |
464 for(; i<256 && len[i]==val; i++); | |
465 | |
466 repeat= i - cur; | |
467 | |
468 if(repeat>7){ | |
469 ((uint8_t*)s->avctx->extradata)[index++]= val; | |
470 ((uint8_t*)s->avctx->extradata)[index++]= repeat; | |
471 }else{ | |
472 ((uint8_t*)s->avctx->extradata)[index++]= val | (repeat<<5); | |
473 } | |
474 } | |
475 | |
476 s->avctx->extradata_size= index; | |
477 } | |
478 | |
479 static int encode_init(AVCodecContext *avctx) | |
480 { | |
481 HYuvContext *s = avctx->priv_data; | |
482 int i, j, width, height; | |
483 | |
484 s->avctx= avctx; | |
485 s->flags= avctx->flags; | |
486 | |
1097 | 487 dsputil_init(&s->dsp, avctx); |
866 | 488 |
489 width= s->width= avctx->width; | |
490 height= s->height= avctx->height; | |
491 | |
492 assert(width && height); | |
493 | |
494 avctx->extradata= av_mallocz(1024*10); | |
495 avctx->stats_out= av_mallocz(1024*10); | |
496 s->version=2; | |
497 | |
925 | 498 avctx->coded_frame= &s->picture; |
903 | 499 |
866 | 500 switch(avctx->pix_fmt){ |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
501 case PIX_FMT_YUV420P: |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
502 if(avctx->strict_std_compliance>=0){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
503 fprintf(stderr, "YV12-huffyuv is experimental, there WILL be no compatbility! (use (v)strict=-1)\n"); |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
504 return -1; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
505 } |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
506 s->bitstream_bpp= 12; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
507 break; |
866 | 508 case PIX_FMT_YUV422P: |
509 s->bitstream_bpp= 16; | |
510 break; | |
511 default: | |
512 fprintf(stderr, "format not supported\n"); | |
513 return -1; | |
514 } | |
515 avctx->bits_per_sample= s->bitstream_bpp; | |
516 s->decorrelate= s->bitstream_bpp >= 24; | |
517 s->predictor= avctx->prediction_method; | |
518 | |
519 ((uint8_t*)avctx->extradata)[0]= s->predictor; | |
520 ((uint8_t*)avctx->extradata)[1]= s->bitstream_bpp; | |
521 ((uint8_t*)avctx->extradata)[2]= | |
522 ((uint8_t*)avctx->extradata)[3]= 0; | |
523 s->avctx->extradata_size= 4; | |
524 | |
525 if(avctx->stats_in){ | |
526 char *p= avctx->stats_in; | |
527 | |
528 for(i=0; i<3; i++) | |
529 for(j=0; j<256; j++) | |
530 s->stats[i][j]= 1; | |
531 | |
532 for(;;){ | |
533 for(i=0; i<3; i++){ | |
534 char *next; | |
535 | |
536 for(j=0; j<256; j++){ | |
537 s->stats[i][j]+= strtol(p, &next, 0); | |
538 if(next==p) return -1; | |
539 p=next; | |
540 } | |
541 } | |
542 if(p[0]==0 || p[1]==0 || p[2]==0) break; | |
543 } | |
544 }else{ | |
545 for(i=0; i<3; i++) | |
546 for(j=0; j<256; j++){ | |
547 int d= FFMIN(j, 256-j); | |
548 | |
549 s->stats[i][j]= 100000000/(d+1); | |
550 } | |
551 } | |
552 | |
553 for(i=0; i<3; i++){ | |
554 generate_len_table(s->len[i], s->stats[i], 256); | |
555 | |
556 if(generate_bits_table(s->bits[i], s->len[i])<0){ | |
557 return -1; | |
558 } | |
559 | |
560 store_table(s, s->len[i]); | |
561 } | |
562 | |
563 for(i=0; i<3; i++) | |
564 for(j=0; j<256; j++) | |
565 s->stats[i][j]= 0; | |
566 | |
567 s->interlaced= height > 288; | |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
568 |
866 | 569 // printf("pred:%d bpp:%d hbpp:%d il:%d\n", s->predictor, s->bitstream_bpp, avctx->bits_per_sample, s->interlaced); |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
570 |
866 | 571 s->picture_number=0; |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
572 |
866 | 573 return 0; |
574 } | |
575 | |
576 static void decode_422_bitstream(HYuvContext *s, int count){ | |
577 int i; | |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
578 |
866 | 579 count/=2; |
580 | |
581 for(i=0; i<count; i++){ | |
582 s->temp[0][2*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); | |
583 s->temp[1][ i ]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); | |
584 s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); | |
585 s->temp[2][ i ]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); | |
586 } | |
587 } | |
588 | |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
589 static void decode_gray_bitstream(HYuvContext *s, int count){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
590 int i; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
591 |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
592 count/=2; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
593 |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
594 for(i=0; i<count; i++){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
595 s->temp[0][2*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
596 s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
597 } |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
598 } |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
599 |
866 | 600 static void encode_422_bitstream(HYuvContext *s, int count){ |
601 int i; | |
602 | |
603 count/=2; | |
604 if(s->flags&CODEC_FLAG_PASS1){ | |
605 for(i=0; i<count; i++){ | |
606 s->stats[0][ s->temp[0][2*i ] ]++; | |
607 s->stats[1][ s->temp[1][ i ] ]++; | |
608 s->stats[0][ s->temp[0][2*i+1] ]++; | |
609 s->stats[2][ s->temp[2][ i ] ]++; | |
610 } | |
611 }else{ | |
612 for(i=0; i<count; i++){ | |
613 put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]); | |
614 put_bits(&s->pb, s->len[1][ s->temp[1][ i ] ], s->bits[1][ s->temp[1][ i ] ]); | |
615 put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]); | |
616 put_bits(&s->pb, s->len[2][ s->temp[2][ i ] ], s->bits[2][ s->temp[2][ i ] ]); | |
617 } | |
618 } | |
619 } | |
620 | |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
621 static void encode_gray_bitstream(HYuvContext *s, int count){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
622 int i; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
623 |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
624 count/=2; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
625 if(s->flags&CODEC_FLAG_PASS1){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
626 for(i=0; i<count; i++){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
627 s->stats[0][ s->temp[0][2*i ] ]++; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
628 s->stats[0][ s->temp[0][2*i+1] ]++; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
629 } |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
630 }else{ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
631 for(i=0; i<count; i++){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
632 put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]); |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
633 put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]); |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
634 } |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
635 } |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
636 } |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
637 |
866 | 638 static void decode_bgr_bitstream(HYuvContext *s, int count){ |
639 int i; | |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
640 |
866 | 641 if(s->decorrelate){ |
642 if(s->bitstream_bpp==24){ | |
643 for(i=0; i<count; i++){ | |
644 s->temp[0][4*i+1]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); | |
645 s->temp[0][4*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+1]; | |
646 s->temp[0][4*i+2]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+1]; | |
647 } | |
648 }else{ | |
649 for(i=0; i<count; i++){ | |
650 s->temp[0][4*i+1]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); | |
651 s->temp[0][4*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+1]; | |
652 s->temp[0][4*i+2]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+1]; | |
653 get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?! | |
654 } | |
655 } | |
656 }else{ | |
657 if(s->bitstream_bpp==24){ | |
658 for(i=0; i<count; i++){ | |
659 s->temp[0][4*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); | |
660 s->temp[0][4*i+1]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); | |
661 s->temp[0][4*i+2]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); | |
662 } | |
663 }else{ | |
664 for(i=0; i<count; i++){ | |
665 s->temp[0][4*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); | |
666 s->temp[0][4*i+1]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); | |
667 s->temp[0][4*i+2]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); | |
668 get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?! | |
669 } | |
670 } | |
671 } | |
672 } | |
673 | |
871 | 674 static void draw_slice(HYuvContext *s, int y){ |
675 int h, cy; | |
1064 | 676 uint8_t *src_ptr[3]; |
871 | 677 |
678 if(s->avctx->draw_horiz_band==NULL) | |
679 return; | |
680 | |
681 h= y - s->last_slice_end; | |
682 y -= h; | |
683 | |
684 if(s->bitstream_bpp==12){ | |
685 cy= y>>1; | |
686 }else{ | |
687 cy= y; | |
688 } | |
689 | |
903 | 690 src_ptr[0] = s->picture.data[0] + s->picture.linesize[0]*y; |
691 src_ptr[1] = s->picture.data[1] + s->picture.linesize[1]*cy; | |
692 src_ptr[2] = s->picture.data[2] + s->picture.linesize[2]*cy; | |
871 | 693 emms_c(); |
694 | |
903 | 695 s->avctx->draw_horiz_band(s->avctx, src_ptr, s->picture.linesize[0], y, s->width, h); |
871 | 696 |
697 s->last_slice_end= y + h; | |
698 } | |
699 | |
866 | 700 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){ |
701 HYuvContext *s = avctx->priv_data; | |
702 const int width= s->width; | |
703 const int width2= s->width>>1; | |
704 const int height= s->height; | |
870 | 705 int fake_ystride, fake_ustride, fake_vstride; |
925 | 706 AVFrame * const p= &s->picture; |
866 | 707 |
925 | 708 AVFrame *picture = data; |
866 | 709 |
710 *data_size = 0; | |
711 | |
712 /* no supplementary picture */ | |
713 if (buf_size == 0) | |
714 return 0; | |
715 | |
1273 | 716 s->dsp.bswap_buf((uint32_t*)s->bitstream_buffer, (uint32_t*)buf, buf_size/4); |
866 | 717 |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1006
diff
changeset
|
718 init_get_bits(&s->gb, s->bitstream_buffer, buf_size*8); |
870 | 719 |
1228 | 720 if(p->data[0]) |
721 avctx->release_buffer(avctx, p); | |
722 | |
903 | 723 p->reference= 0; |
724 if(avctx->get_buffer(avctx, p) < 0){ | |
725 fprintf(stderr, "get_buffer() failed\n"); | |
726 return -1; | |
727 } | |
870 | 728 |
903 | 729 fake_ystride= s->interlaced ? p->linesize[0]*2 : p->linesize[0]; |
730 fake_ustride= s->interlaced ? p->linesize[1]*2 : p->linesize[1]; | |
731 fake_vstride= s->interlaced ? p->linesize[2]*2 : p->linesize[2]; | |
871 | 732 |
733 s->last_slice_end= 0; | |
870 | 734 |
866 | 735 if(s->bitstream_bpp<24){ |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
736 int y, cy; |
866 | 737 int lefty, leftu, leftv; |
738 int lefttopy, lefttopu, lefttopv; | |
739 | |
740 if(s->yuy2){ | |
903 | 741 p->data[0][3]= get_bits(&s->gb, 8); |
742 p->data[0][2]= get_bits(&s->gb, 8); | |
743 p->data[0][1]= get_bits(&s->gb, 8); | |
744 p->data[0][0]= get_bits(&s->gb, 8); | |
866 | 745 |
746 fprintf(stderr, "YUY2 output isnt implemenetd yet\n"); | |
747 return -1; | |
748 }else{ | |
749 | |
903 | 750 leftv= p->data[2][0]= get_bits(&s->gb, 8); |
751 lefty= p->data[0][1]= get_bits(&s->gb, 8); | |
752 leftu= p->data[1][0]= get_bits(&s->gb, 8); | |
753 p->data[0][0]= get_bits(&s->gb, 8); | |
866 | 754 |
755 switch(s->predictor){ | |
756 case LEFT: | |
757 case PLANE: | |
758 decode_422_bitstream(s, width-2); | |
903 | 759 lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); |
866 | 760 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 761 leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); |
762 leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); | |
866 | 763 } |
764 | |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
765 for(cy=y=1; y<s->height; y++,cy++){ |
866 | 766 uint8_t *ydst, *udst, *vdst; |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
767 |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
768 if(s->bitstream_bpp==12){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
769 decode_gray_bitstream(s, width); |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
770 |
903 | 771 ydst= p->data[0] + p->linesize[0]*y; |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
772 |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
773 lefty= add_left_prediction(ydst, s->temp[0], width, lefty); |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
774 if(s->predictor == PLANE){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
775 if(y>s->interlaced) |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
776 s->dsp.add_bytes(ydst, ydst - fake_ystride, width); |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
777 } |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
778 y++; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
779 if(y>=s->height) break; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
780 } |
866 | 781 |
871 | 782 draw_slice(s, y); |
783 | |
903 | 784 ydst= p->data[0] + p->linesize[0]*y; |
785 udst= p->data[1] + p->linesize[1]*cy; | |
786 vdst= p->data[2] + p->linesize[2]*cy; | |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
787 |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
788 decode_422_bitstream(s, width); |
866 | 789 lefty= add_left_prediction(ydst, s->temp[0], width, lefty); |
790 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
791 leftu= add_left_prediction(udst, s->temp[1], width2, leftu); | |
792 leftv= add_left_prediction(vdst, s->temp[2], width2, leftv); | |
793 } | |
794 if(s->predictor == PLANE){ | |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
795 if(cy>s->interlaced){ |
866 | 796 s->dsp.add_bytes(ydst, ydst - fake_ystride, width); |
797 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
798 s->dsp.add_bytes(udst, udst - fake_ustride, width2); | |
799 s->dsp.add_bytes(vdst, vdst - fake_vstride, width2); | |
800 } | |
801 } | |
802 } | |
803 } | |
871 | 804 draw_slice(s, height); |
805 | |
866 | 806 break; |
807 case MEDIAN: | |
808 /* first line except first 2 pixels is left predicted */ | |
809 decode_422_bitstream(s, width-2); | |
903 | 810 lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); |
866 | 811 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 812 leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); |
813 leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); | |
866 | 814 } |
815 | |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
816 cy=y=1; |
866 | 817 |
818 /* second line is left predicted for interlaced case */ | |
819 if(s->interlaced){ | |
820 decode_422_bitstream(s, width); | |
903 | 821 lefty= add_left_prediction(p->data[0] + p->linesize[0], s->temp[0], width, lefty); |
866 | 822 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 823 leftu= add_left_prediction(p->data[1] + p->linesize[2], s->temp[1], width2, leftu); |
824 leftv= add_left_prediction(p->data[2] + p->linesize[1], s->temp[2], width2, leftv); | |
866 | 825 } |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
826 y++; cy++; |
866 | 827 } |
828 | |
829 /* next 4 pixels are left predicted too */ | |
830 decode_422_bitstream(s, 4); | |
903 | 831 lefty= add_left_prediction(p->data[0] + fake_ystride, s->temp[0], 4, lefty); |
866 | 832 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 833 leftu= add_left_prediction(p->data[1] + fake_ustride, s->temp[1], 2, leftu); |
834 leftv= add_left_prediction(p->data[2] + fake_vstride, s->temp[2], 2, leftv); | |
866 | 835 } |
836 | |
837 /* next line except the first 4 pixels is median predicted */ | |
903 | 838 lefttopy= p->data[0][3]; |
866 | 839 decode_422_bitstream(s, width-4); |
903 | 840 add_median_prediction(p->data[0] + fake_ystride+4, p->data[0]+4, s->temp[0], width-4, &lefty, &lefttopy); |
866 | 841 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 842 lefttopu= p->data[1][1]; |
843 lefttopv= p->data[2][1]; | |
844 add_median_prediction(p->data[1] + fake_ustride+2, p->data[1]+2, s->temp[1], width2-2, &leftu, &lefttopu); | |
845 add_median_prediction(p->data[2] + fake_vstride+2, p->data[2]+2, s->temp[2], width2-2, &leftv, &lefttopv); | |
866 | 846 } |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
847 y++; cy++; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
848 |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
849 for(; y<height; y++,cy++){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
850 uint8_t *ydst, *udst, *vdst; |
866 | 851 |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
852 if(s->bitstream_bpp==12){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
853 while(2*cy > y){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
854 decode_gray_bitstream(s, width); |
903 | 855 ydst= p->data[0] + p->linesize[0]*y; |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
856 add_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy); |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
857 y++; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
858 } |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
859 if(y>=height) break; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
860 } |
871 | 861 draw_slice(s, y); |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
862 |
866 | 863 decode_422_bitstream(s, width); |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
864 |
903 | 865 ydst= p->data[0] + p->linesize[0]*y; |
866 udst= p->data[1] + p->linesize[1]*cy; | |
867 vdst= p->data[2] + p->linesize[2]*cy; | |
866 | 868 |
869 add_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy); | |
870 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
871 add_median_prediction(udst, udst - fake_ustride, s->temp[1], width2, &leftu, &lefttopu); | |
872 add_median_prediction(vdst, vdst - fake_vstride, s->temp[2], width2, &leftv, &lefttopv); | |
873 } | |
874 } | |
871 | 875 |
876 draw_slice(s, height); | |
866 | 877 break; |
878 } | |
879 } | |
880 }else{ | |
881 int y; | |
882 int leftr, leftg, leftb; | |
903 | 883 const int last_line= (height-1)*p->linesize[0]; |
866 | 884 |
885 if(s->bitstream_bpp==32){ | |
903 | 886 p->data[0][last_line+3]= get_bits(&s->gb, 8); |
887 leftr= p->data[0][last_line+2]= get_bits(&s->gb, 8); | |
888 leftg= p->data[0][last_line+1]= get_bits(&s->gb, 8); | |
889 leftb= p->data[0][last_line+0]= get_bits(&s->gb, 8); | |
866 | 890 }else{ |
903 | 891 leftr= p->data[0][last_line+2]= get_bits(&s->gb, 8); |
892 leftg= p->data[0][last_line+1]= get_bits(&s->gb, 8); | |
893 leftb= p->data[0][last_line+0]= get_bits(&s->gb, 8); | |
866 | 894 skip_bits(&s->gb, 8); |
895 } | |
896 | |
897 if(s->bgr32){ | |
898 switch(s->predictor){ | |
899 case LEFT: | |
900 case PLANE: | |
901 decode_bgr_bitstream(s, width-1); | |
903 | 902 add_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width-1, &leftr, &leftg, &leftb); |
866 | 903 |
904 for(y=s->height-2; y>=0; y--){ //yes its stored upside down | |
905 decode_bgr_bitstream(s, width); | |
906 | |
903 | 907 add_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb); |
866 | 908 if(s->predictor == PLANE){ |
909 if((y&s->interlaced)==0){ | |
903 | 910 s->dsp.add_bytes(p->data[0] + p->linesize[0]*y, |
911 p->data[0] + p->linesize[0]*y + fake_ystride, fake_ystride); | |
866 | 912 } |
913 } | |
914 } | |
871 | 915 draw_slice(s, height); // just 1 large slice as this isnt possible in reverse order |
866 | 916 break; |
917 default: | |
918 fprintf(stderr, "prediction type not supported!\n"); | |
919 } | |
920 }else{ | |
921 | |
922 fprintf(stderr, "BGR24 output isnt implemenetd yet\n"); | |
923 return -1; | |
924 } | |
925 } | |
926 emms_c(); | |
927 | |
903 | 928 *picture= *p; |
925 | 929 *data_size = sizeof(AVFrame); |
866 | 930 |
1078
c55bffc3b84e
round readed bits up to next 32bits, as orginal huffyuv cant handle less then 32bit blocks
michaelni
parents:
1064
diff
changeset
|
931 return (get_bits_count(&s->gb)+31)/32*4; |
866 | 932 } |
933 | |
934 static int decode_end(AVCodecContext *avctx) | |
935 { | |
936 HYuvContext *s = avctx->priv_data; | |
937 int i; | |
938 | |
939 for(i=0; i<3; i++){ | |
903 | 940 free_vlc(&s->vlc[i]); |
941 } | |
1214 | 942 |
943 avcodec_default_free_buffers(avctx); | |
866 | 944 |
945 return 0; | |
946 } | |
947 | |
948 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ | |
949 HYuvContext *s = avctx->priv_data; | |
925 | 950 AVFrame *pict = data; |
866 | 951 const int width= s->width; |
952 const int width2= s->width>>1; | |
953 const int height= s->height; | |
954 const int fake_ystride= s->interlaced ? pict->linesize[0]*2 : pict->linesize[0]; | |
955 const int fake_ustride= s->interlaced ? pict->linesize[1]*2 : pict->linesize[1]; | |
956 const int fake_vstride= s->interlaced ? pict->linesize[2]*2 : pict->linesize[2]; | |
925 | 957 AVFrame * const p= &s->picture; |
866 | 958 int i, size; |
959 | |
960 init_put_bits(&s->pb, buf, buf_size, NULL, NULL); | |
961 | |
903 | 962 *p = *pict; |
1006 | 963 p->pict_type= FF_I_TYPE; |
964 p->key_frame= 1; | |
866 | 965 |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
966 if(avctx->pix_fmt == PIX_FMT_YUV422P || avctx->pix_fmt == PIX_FMT_YUV420P){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
967 int lefty, leftu, leftv, y, cy; |
866 | 968 |
903 | 969 put_bits(&s->pb, 8, leftv= p->data[2][0]); |
970 put_bits(&s->pb, 8, lefty= p->data[0][1]); | |
971 put_bits(&s->pb, 8, leftu= p->data[1][0]); | |
972 put_bits(&s->pb, 8, p->data[0][0]); | |
866 | 973 |
903 | 974 lefty= sub_left_prediction(s, s->temp[0], p->data[0]+2, width-2 , lefty); |
975 leftu= sub_left_prediction(s, s->temp[1], p->data[1]+1, width2-1, leftu); | |
976 leftv= sub_left_prediction(s, s->temp[2], p->data[2]+1, width2-1, leftv); | |
866 | 977 |
978 encode_422_bitstream(s, width-2); | |
979 | |
980 if(s->predictor==MEDIAN){ | |
981 int lefttopy, lefttopu, lefttopv; | |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
982 cy=y=1; |
866 | 983 if(s->interlaced){ |
903 | 984 lefty= sub_left_prediction(s, s->temp[0], p->data[0]+p->linesize[0], width , lefty); |
985 leftu= sub_left_prediction(s, s->temp[1], p->data[1]+p->linesize[1], width2, leftu); | |
986 leftv= sub_left_prediction(s, s->temp[2], p->data[2]+p->linesize[2], width2, leftv); | |
866 | 987 |
988 encode_422_bitstream(s, width); | |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
989 y++; cy++; |
866 | 990 } |
991 | |
903 | 992 lefty= sub_left_prediction(s, s->temp[0], p->data[0]+fake_ystride, 4, lefty); |
993 leftu= sub_left_prediction(s, s->temp[1], p->data[1]+fake_ystride, 2, leftu); | |
994 leftv= sub_left_prediction(s, s->temp[2], p->data[2]+fake_ystride, 2, leftv); | |
866 | 995 |
996 encode_422_bitstream(s, 4); | |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
997 |
903 | 998 lefttopy= p->data[0][3]; |
999 lefttopu= p->data[1][1]; | |
1000 lefttopv= p->data[2][1]; | |
1001 sub_median_prediction(s->temp[0], p->data[0]+4, p->data[0] + fake_ystride+4, width-4 , &lefty, &lefttopy); | |
1002 sub_median_prediction(s->temp[1], p->data[1]+2, p->data[1] + fake_ustride+2, width2-2, &leftu, &lefttopu); | |
1003 sub_median_prediction(s->temp[2], p->data[2]+2, p->data[2] + fake_vstride+2, width2-2, &leftv, &lefttopv); | |
866 | 1004 encode_422_bitstream(s, width-4); |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1005 y++; cy++; |
866 | 1006 |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1007 for(; y<height; y++,cy++){ |
866 | 1008 uint8_t *ydst, *udst, *vdst; |
1009 | |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1010 if(s->bitstream_bpp==12){ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1011 while(2*cy > y){ |
903 | 1012 ydst= p->data[0] + p->linesize[0]*y; |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1013 sub_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy); |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1014 encode_gray_bitstream(s, width); |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1015 y++; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1016 } |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1017 if(y>=height) break; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1018 } |
903 | 1019 ydst= p->data[0] + p->linesize[0]*y; |
1020 udst= p->data[1] + p->linesize[1]*cy; | |
1021 vdst= p->data[2] + p->linesize[2]*cy; | |
866 | 1022 |
1023 sub_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy); | |
1024 sub_median_prediction(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu); | |
1025 sub_median_prediction(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv); | |
1026 | |
1027 encode_422_bitstream(s, width); | |
1028 } | |
1029 }else{ | |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1030 for(cy=y=1; y<height; y++,cy++){ |
866 | 1031 uint8_t *ydst, *udst, *vdst; |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1032 |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1033 /* encode a luma only line & y++ */ |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1034 if(s->bitstream_bpp==12){ |
903 | 1035 ydst= p->data[0] + p->linesize[0]*y; |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1036 |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1037 if(s->predictor == PLANE && s->interlaced < y){ |
871 | 1038 s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width); |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1039 |
871 | 1040 lefty= sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty); |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1041 }else{ |
871 | 1042 lefty= sub_left_prediction(s, s->temp[0], ydst, width , lefty); |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1043 } |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1044 encode_gray_bitstream(s, width); |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1045 y++; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1046 if(y>=height) break; |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1047 } |
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1048 |
903 | 1049 ydst= p->data[0] + p->linesize[0]*y; |
1050 udst= p->data[1] + p->linesize[1]*cy; | |
1051 vdst= p->data[2] + p->linesize[2]*cy; | |
866 | 1052 |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1053 if(s->predictor == PLANE && s->interlaced < cy){ |
871 | 1054 s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width); |
1055 s->dsp.diff_bytes(s->temp[2], udst, udst - fake_ustride, width2); | |
1056 s->dsp.diff_bytes(s->temp[3], vdst, vdst - fake_vstride, width2); | |
866 | 1057 |
871 | 1058 lefty= sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty); |
1059 leftu= sub_left_prediction(s, s->temp[1], s->temp[2], width2, leftu); | |
1060 leftv= sub_left_prediction(s, s->temp[2], s->temp[3], width2, leftv); | |
866 | 1061 }else{ |
871 | 1062 lefty= sub_left_prediction(s, s->temp[0], ydst, width , lefty); |
1063 leftu= sub_left_prediction(s, s->temp[1], udst, width2, leftu); | |
1064 leftv= sub_left_prediction(s, s->temp[2], vdst, width2, leftv); | |
866 | 1065 } |
1066 | |
1067 encode_422_bitstream(s, width); | |
1068 } | |
1069 } | |
1070 }else{ | |
1071 fprintf(stderr, "Format not supported!\n"); | |
1072 } | |
1073 emms_c(); | |
1074 | |
1075 size= (get_bit_count(&s->pb)+31)/32; | |
1076 | |
1077 if((s->flags&CODEC_FLAG_PASS1) && (s->picture_number&31)==0){ | |
1078 int j; | |
1079 char *p= avctx->stats_out; | |
1080 for(i=0; i<3; i++){ | |
1081 for(j=0; j<256; j++){ | |
1282 | 1082 sprintf(p, "%llu ", s->stats[i][j]); |
866 | 1083 p+= strlen(p); |
1084 s->stats[i][j]= 0; | |
1085 } | |
1086 sprintf(p, "\n"); | |
1087 p++; | |
1088 } | |
1089 }else{ | |
868
dfe7d66da6f0
YV12 support (warning this is experimental & wont work with offical huffyuv but there is a approx. 20% speed & compression gain)
michaelni
parents:
866
diff
changeset
|
1090 flush_put_bits(&s->pb); |
1273 | 1091 s->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size); |
866 | 1092 } |
1093 | |
1094 s->picture_number++; | |
903 | 1095 |
866 | 1096 return size*4; |
1097 } | |
1098 | |
1099 static int encode_end(AVCodecContext *avctx) | |
1100 { | |
1101 // HYuvContext *s = avctx->priv_data; | |
1102 | |
1103 av_freep(&avctx->extradata); | |
1104 av_freep(&avctx->stats_out); | |
1105 | |
1106 return 0; | |
1107 } | |
1108 | |
1130 | 1109 static const AVOption huffyuv_options[] = |
1110 { | |
1111 AVOPTION_CODEC_INT("prediction_method", "prediction_method", prediction_method, 0, 2, 0), | |
1112 AVOPTION_END() | |
1113 }; | |
1114 | |
866 | 1115 AVCodec huffyuv_decoder = { |
1116 "huffyuv", | |
1117 CODEC_TYPE_VIDEO, | |
1118 CODEC_ID_HUFFYUV, | |
1119 sizeof(HYuvContext), | |
1120 decode_init, | |
1121 NULL, | |
1122 decode_end, | |
1123 decode_frame, | |
871 | 1124 CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND, |
866 | 1125 NULL |
1126 }; | |
1127 | |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
1128 #ifdef CONFIG_ENCODERS |
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
1129 |
866 | 1130 AVCodec huffyuv_encoder = { |
1131 "huffyuv", | |
1132 CODEC_TYPE_VIDEO, | |
1133 CODEC_ID_HUFFYUV, | |
1134 sizeof(HYuvContext), | |
1135 encode_init, | |
1136 encode_frame, | |
1137 encode_end, | |
1130 | 1138 .options = huffyuv_options, |
866 | 1139 }; |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
1140 |
1246 | 1141 #endif //CONFIG_ENCODERS |