Mercurial > libavcodec.hg
annotate huffyuv.c @ 1447:7c73537bc994 libavcodec
changed my mind about CODEC_ID_MPEGVIDEO - CODEC_ID_MP3LAME is absolete
author | bellard |
---|---|
date | Mon, 08 Sep 2003 22:03:29 +0000 |
parents | 45d761c387cd |
children | 79dddc5cd990 |
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; | |
1368 | 676 int offset[4]; |
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 } | |
1368 | 689 |
690 offset[0] = s->picture.linesize[0]*y; | |
691 offset[1] = s->picture.linesize[1]*cy; | |
692 offset[2] = s->picture.linesize[2]*cy; | |
693 offset[3] = 0; | |
871 | 694 emms_c(); |
695 | |
1370 | 696 s->avctx->draw_horiz_band(s->avctx, &s->picture, offset, y, 3, h); |
871 | 697 |
698 s->last_slice_end= y + h; | |
699 } | |
700 | |
866 | 701 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){ |
702 HYuvContext *s = avctx->priv_data; | |
703 const int width= s->width; | |
704 const int width2= s->width>>1; | |
705 const int height= s->height; | |
870 | 706 int fake_ystride, fake_ustride, fake_vstride; |
925 | 707 AVFrame * const p= &s->picture; |
866 | 708 |
925 | 709 AVFrame *picture = data; |
866 | 710 |
711 *data_size = 0; | |
712 | |
713 /* no supplementary picture */ | |
714 if (buf_size == 0) | |
715 return 0; | |
716 | |
1273 | 717 s->dsp.bswap_buf((uint32_t*)s->bitstream_buffer, (uint32_t*)buf, buf_size/4); |
866 | 718 |
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
|
719 init_get_bits(&s->gb, s->bitstream_buffer, buf_size*8); |
870 | 720 |
1228 | 721 if(p->data[0]) |
722 avctx->release_buffer(avctx, p); | |
723 | |
903 | 724 p->reference= 0; |
725 if(avctx->get_buffer(avctx, p) < 0){ | |
726 fprintf(stderr, "get_buffer() failed\n"); | |
727 return -1; | |
728 } | |
870 | 729 |
903 | 730 fake_ystride= s->interlaced ? p->linesize[0]*2 : p->linesize[0]; |
731 fake_ustride= s->interlaced ? p->linesize[1]*2 : p->linesize[1]; | |
732 fake_vstride= s->interlaced ? p->linesize[2]*2 : p->linesize[2]; | |
871 | 733 |
734 s->last_slice_end= 0; | |
870 | 735 |
866 | 736 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
|
737 int y, cy; |
866 | 738 int lefty, leftu, leftv; |
739 int lefttopy, lefttopu, lefttopv; | |
740 | |
741 if(s->yuy2){ | |
903 | 742 p->data[0][3]= get_bits(&s->gb, 8); |
743 p->data[0][2]= get_bits(&s->gb, 8); | |
744 p->data[0][1]= get_bits(&s->gb, 8); | |
745 p->data[0][0]= get_bits(&s->gb, 8); | |
866 | 746 |
747 fprintf(stderr, "YUY2 output isnt implemenetd yet\n"); | |
748 return -1; | |
749 }else{ | |
750 | |
903 | 751 leftv= p->data[2][0]= get_bits(&s->gb, 8); |
752 lefty= p->data[0][1]= get_bits(&s->gb, 8); | |
753 leftu= p->data[1][0]= get_bits(&s->gb, 8); | |
754 p->data[0][0]= get_bits(&s->gb, 8); | |
866 | 755 |
756 switch(s->predictor){ | |
757 case LEFT: | |
758 case PLANE: | |
759 decode_422_bitstream(s, width-2); | |
903 | 760 lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); |
866 | 761 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 762 leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); |
763 leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); | |
866 | 764 } |
765 | |
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
|
766 for(cy=y=1; y<s->height; y++,cy++){ |
866 | 767 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
|
768 |
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 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
|
770 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
|
771 |
903 | 772 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
|
773 |
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 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
|
775 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
|
776 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
|
777 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
|
778 } |
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 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
|
780 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
|
781 } |
866 | 782 |
871 | 783 draw_slice(s, y); |
784 | |
903 | 785 ydst= p->data[0] + p->linesize[0]*y; |
786 udst= p->data[1] + p->linesize[1]*cy; | |
787 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
|
788 |
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
|
789 decode_422_bitstream(s, width); |
866 | 790 lefty= add_left_prediction(ydst, s->temp[0], width, lefty); |
791 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
792 leftu= add_left_prediction(udst, s->temp[1], width2, leftu); | |
793 leftv= add_left_prediction(vdst, s->temp[2], width2, leftv); | |
794 } | |
795 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
|
796 if(cy>s->interlaced){ |
866 | 797 s->dsp.add_bytes(ydst, ydst - fake_ystride, width); |
798 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
799 s->dsp.add_bytes(udst, udst - fake_ustride, width2); | |
800 s->dsp.add_bytes(vdst, vdst - fake_vstride, width2); | |
801 } | |
802 } | |
803 } | |
804 } | |
871 | 805 draw_slice(s, height); |
806 | |
866 | 807 break; |
808 case MEDIAN: | |
809 /* first line except first 2 pixels is left predicted */ | |
810 decode_422_bitstream(s, width-2); | |
903 | 811 lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); |
866 | 812 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 813 leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); |
814 leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); | |
866 | 815 } |
816 | |
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
|
817 cy=y=1; |
866 | 818 |
819 /* second line is left predicted for interlaced case */ | |
820 if(s->interlaced){ | |
821 decode_422_bitstream(s, width); | |
903 | 822 lefty= add_left_prediction(p->data[0] + p->linesize[0], s->temp[0], width, lefty); |
866 | 823 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 824 leftu= add_left_prediction(p->data[1] + p->linesize[2], s->temp[1], width2, leftu); |
825 leftv= add_left_prediction(p->data[2] + p->linesize[1], s->temp[2], width2, leftv); | |
866 | 826 } |
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
|
827 y++; cy++; |
866 | 828 } |
829 | |
830 /* next 4 pixels are left predicted too */ | |
831 decode_422_bitstream(s, 4); | |
903 | 832 lefty= add_left_prediction(p->data[0] + fake_ystride, s->temp[0], 4, lefty); |
866 | 833 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 834 leftu= add_left_prediction(p->data[1] + fake_ustride, s->temp[1], 2, leftu); |
835 leftv= add_left_prediction(p->data[2] + fake_vstride, s->temp[2], 2, leftv); | |
866 | 836 } |
837 | |
838 /* next line except the first 4 pixels is median predicted */ | |
903 | 839 lefttopy= p->data[0][3]; |
866 | 840 decode_422_bitstream(s, width-4); |
903 | 841 add_median_prediction(p->data[0] + fake_ystride+4, p->data[0]+4, s->temp[0], width-4, &lefty, &lefttopy); |
866 | 842 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 843 lefttopu= p->data[1][1]; |
844 lefttopv= p->data[2][1]; | |
845 add_median_prediction(p->data[1] + fake_ustride+2, p->data[1]+2, s->temp[1], width2-2, &leftu, &lefttopu); | |
846 add_median_prediction(p->data[2] + fake_vstride+2, p->data[2]+2, s->temp[2], width2-2, &leftv, &lefttopv); | |
866 | 847 } |
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
|
848 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
|
849 |
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 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
|
851 uint8_t *ydst, *udst, *vdst; |
866 | 852 |
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
|
853 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
|
854 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
|
855 decode_gray_bitstream(s, width); |
903 | 856 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
|
857 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
|
858 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
|
859 } |
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 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
|
861 } |
871 | 862 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
|
863 |
866 | 864 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
|
865 |
903 | 866 ydst= p->data[0] + p->linesize[0]*y; |
867 udst= p->data[1] + p->linesize[1]*cy; | |
868 vdst= p->data[2] + p->linesize[2]*cy; | |
866 | 869 |
870 add_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy); | |
871 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
872 add_median_prediction(udst, udst - fake_ustride, s->temp[1], width2, &leftu, &lefttopu); | |
873 add_median_prediction(vdst, vdst - fake_vstride, s->temp[2], width2, &leftv, &lefttopv); | |
874 } | |
875 } | |
871 | 876 |
877 draw_slice(s, height); | |
866 | 878 break; |
879 } | |
880 } | |
881 }else{ | |
882 int y; | |
883 int leftr, leftg, leftb; | |
903 | 884 const int last_line= (height-1)*p->linesize[0]; |
866 | 885 |
886 if(s->bitstream_bpp==32){ | |
903 | 887 p->data[0][last_line+3]= get_bits(&s->gb, 8); |
888 leftr= p->data[0][last_line+2]= get_bits(&s->gb, 8); | |
889 leftg= p->data[0][last_line+1]= get_bits(&s->gb, 8); | |
890 leftb= p->data[0][last_line+0]= get_bits(&s->gb, 8); | |
866 | 891 }else{ |
903 | 892 leftr= p->data[0][last_line+2]= get_bits(&s->gb, 8); |
893 leftg= p->data[0][last_line+1]= get_bits(&s->gb, 8); | |
894 leftb= p->data[0][last_line+0]= get_bits(&s->gb, 8); | |
866 | 895 skip_bits(&s->gb, 8); |
896 } | |
897 | |
898 if(s->bgr32){ | |
899 switch(s->predictor){ | |
900 case LEFT: | |
901 case PLANE: | |
902 decode_bgr_bitstream(s, width-1); | |
903 | 903 add_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width-1, &leftr, &leftg, &leftb); |
866 | 904 |
905 for(y=s->height-2; y>=0; y--){ //yes its stored upside down | |
906 decode_bgr_bitstream(s, width); | |
907 | |
903 | 908 add_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb); |
866 | 909 if(s->predictor == PLANE){ |
910 if((y&s->interlaced)==0){ | |
903 | 911 s->dsp.add_bytes(p->data[0] + p->linesize[0]*y, |
912 p->data[0] + p->linesize[0]*y + fake_ystride, fake_ystride); | |
866 | 913 } |
914 } | |
915 } | |
871 | 916 draw_slice(s, height); // just 1 large slice as this isnt possible in reverse order |
866 | 917 break; |
918 default: | |
919 fprintf(stderr, "prediction type not supported!\n"); | |
920 } | |
921 }else{ | |
922 | |
923 fprintf(stderr, "BGR24 output isnt implemenetd yet\n"); | |
924 return -1; | |
925 } | |
926 } | |
927 emms_c(); | |
928 | |
903 | 929 *picture= *p; |
925 | 930 *data_size = sizeof(AVFrame); |
866 | 931 |
1078
c55bffc3b84e
round readed bits up to next 32bits, as orginal huffyuv cant handle less then 32bit blocks
michaelni
parents:
1064
diff
changeset
|
932 return (get_bits_count(&s->gb)+31)/32*4; |
866 | 933 } |
934 | |
935 static int decode_end(AVCodecContext *avctx) | |
936 { | |
937 HYuvContext *s = avctx->priv_data; | |
938 int i; | |
939 | |
940 for(i=0; i<3; i++){ | |
903 | 941 free_vlc(&s->vlc[i]); |
942 } | |
1214 | 943 |
944 avcodec_default_free_buffers(avctx); | |
866 | 945 |
946 return 0; | |
947 } | |
948 | |
949 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ | |
950 HYuvContext *s = avctx->priv_data; | |
925 | 951 AVFrame *pict = data; |
866 | 952 const int width= s->width; |
953 const int width2= s->width>>1; | |
954 const int height= s->height; | |
955 const int fake_ystride= s->interlaced ? pict->linesize[0]*2 : pict->linesize[0]; | |
956 const int fake_ustride= s->interlaced ? pict->linesize[1]*2 : pict->linesize[1]; | |
957 const int fake_vstride= s->interlaced ? pict->linesize[2]*2 : pict->linesize[2]; | |
925 | 958 AVFrame * const p= &s->picture; |
866 | 959 int i, size; |
960 | |
961 init_put_bits(&s->pb, buf, buf_size, NULL, NULL); | |
962 | |
903 | 963 *p = *pict; |
1006 | 964 p->pict_type= FF_I_TYPE; |
965 p->key_frame= 1; | |
866 | 966 |
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
|
967 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
|
968 int lefty, leftu, leftv, y, cy; |
866 | 969 |
903 | 970 put_bits(&s->pb, 8, leftv= p->data[2][0]); |
971 put_bits(&s->pb, 8, lefty= p->data[0][1]); | |
972 put_bits(&s->pb, 8, leftu= p->data[1][0]); | |
973 put_bits(&s->pb, 8, p->data[0][0]); | |
866 | 974 |
903 | 975 lefty= sub_left_prediction(s, s->temp[0], p->data[0]+2, width-2 , lefty); |
976 leftu= sub_left_prediction(s, s->temp[1], p->data[1]+1, width2-1, leftu); | |
977 leftv= sub_left_prediction(s, s->temp[2], p->data[2]+1, width2-1, leftv); | |
866 | 978 |
979 encode_422_bitstream(s, width-2); | |
980 | |
981 if(s->predictor==MEDIAN){ | |
982 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
|
983 cy=y=1; |
866 | 984 if(s->interlaced){ |
903 | 985 lefty= sub_left_prediction(s, s->temp[0], p->data[0]+p->linesize[0], width , lefty); |
986 leftu= sub_left_prediction(s, s->temp[1], p->data[1]+p->linesize[1], width2, leftu); | |
987 leftv= sub_left_prediction(s, s->temp[2], p->data[2]+p->linesize[2], width2, leftv); | |
866 | 988 |
989 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
|
990 y++; cy++; |
866 | 991 } |
992 | |
903 | 993 lefty= sub_left_prediction(s, s->temp[0], p->data[0]+fake_ystride, 4, lefty); |
994 leftu= sub_left_prediction(s, s->temp[1], p->data[1]+fake_ystride, 2, leftu); | |
995 leftv= sub_left_prediction(s, s->temp[2], p->data[2]+fake_ystride, 2, leftv); | |
866 | 996 |
997 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
|
998 |
903 | 999 lefttopy= p->data[0][3]; |
1000 lefttopu= p->data[1][1]; | |
1001 lefttopv= p->data[2][1]; | |
1002 sub_median_prediction(s->temp[0], p->data[0]+4, p->data[0] + fake_ystride+4, width-4 , &lefty, &lefttopy); | |
1003 sub_median_prediction(s->temp[1], p->data[1]+2, p->data[1] + fake_ustride+2, width2-2, &leftu, &lefttopu); | |
1004 sub_median_prediction(s->temp[2], p->data[2]+2, p->data[2] + fake_vstride+2, width2-2, &leftv, &lefttopv); | |
866 | 1005 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
|
1006 y++; cy++; |
866 | 1007 |
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
|
1008 for(; y<height; y++,cy++){ |
866 | 1009 uint8_t *ydst, *udst, *vdst; |
1010 | |
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
|
1011 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
|
1012 while(2*cy > y){ |
903 | 1013 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
|
1014 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
|
1015 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
|
1016 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
|
1017 } |
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 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
|
1019 } |
903 | 1020 ydst= p->data[0] + p->linesize[0]*y; |
1021 udst= p->data[1] + p->linesize[1]*cy; | |
1022 vdst= p->data[2] + p->linesize[2]*cy; | |
866 | 1023 |
1024 sub_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy); | |
1025 sub_median_prediction(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu); | |
1026 sub_median_prediction(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv); | |
1027 | |
1028 encode_422_bitstream(s, width); | |
1029 } | |
1030 }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
|
1031 for(cy=y=1; y<height; y++,cy++){ |
866 | 1032 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
|
1033 |
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 /* 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
|
1035 if(s->bitstream_bpp==12){ |
903 | 1036 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
|
1037 |
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
|
1038 if(s->predictor == PLANE && s->interlaced < y){ |
871 | 1039 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
|
1040 |
871 | 1041 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
|
1042 }else{ |
871 | 1043 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
|
1044 } |
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 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
|
1046 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
|
1047 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
|
1048 } |
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
|
1049 |
903 | 1050 ydst= p->data[0] + p->linesize[0]*y; |
1051 udst= p->data[1] + p->linesize[1]*cy; | |
1052 vdst= p->data[2] + p->linesize[2]*cy; | |
866 | 1053 |
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
|
1054 if(s->predictor == PLANE && s->interlaced < cy){ |
871 | 1055 s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width); |
1056 s->dsp.diff_bytes(s->temp[2], udst, udst - fake_ustride, width2); | |
1057 s->dsp.diff_bytes(s->temp[3], vdst, vdst - fake_vstride, width2); | |
866 | 1058 |
871 | 1059 lefty= sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty); |
1060 leftu= sub_left_prediction(s, s->temp[1], s->temp[2], width2, leftu); | |
1061 leftv= sub_left_prediction(s, s->temp[2], s->temp[3], width2, leftv); | |
866 | 1062 }else{ |
871 | 1063 lefty= sub_left_prediction(s, s->temp[0], ydst, width , lefty); |
1064 leftu= sub_left_prediction(s, s->temp[1], udst, width2, leftu); | |
1065 leftv= sub_left_prediction(s, s->temp[2], vdst, width2, leftv); | |
866 | 1066 } |
1067 | |
1068 encode_422_bitstream(s, width); | |
1069 } | |
1070 } | |
1071 }else{ | |
1072 fprintf(stderr, "Format not supported!\n"); | |
1073 } | |
1074 emms_c(); | |
1075 | |
1076 size= (get_bit_count(&s->pb)+31)/32; | |
1077 | |
1078 if((s->flags&CODEC_FLAG_PASS1) && (s->picture_number&31)==0){ | |
1079 int j; | |
1080 char *p= avctx->stats_out; | |
1081 for(i=0; i<3; i++){ | |
1082 for(j=0; j<256; j++){ | |
1282 | 1083 sprintf(p, "%llu ", s->stats[i][j]); |
866 | 1084 p+= strlen(p); |
1085 s->stats[i][j]= 0; | |
1086 } | |
1087 sprintf(p, "\n"); | |
1088 p++; | |
1089 } | |
1090 }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
|
1091 flush_put_bits(&s->pb); |
1273 | 1092 s->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size); |
866 | 1093 } |
1094 | |
1095 s->picture_number++; | |
903 | 1096 |
866 | 1097 return size*4; |
1098 } | |
1099 | |
1100 static int encode_end(AVCodecContext *avctx) | |
1101 { | |
1102 // HYuvContext *s = avctx->priv_data; | |
1103 | |
1104 av_freep(&avctx->extradata); | |
1105 av_freep(&avctx->stats_out); | |
1106 | |
1107 return 0; | |
1108 } | |
1109 | |
1130 | 1110 static const AVOption huffyuv_options[] = |
1111 { | |
1112 AVOPTION_CODEC_INT("prediction_method", "prediction_method", prediction_method, 0, 2, 0), | |
1113 AVOPTION_END() | |
1114 }; | |
1115 | |
866 | 1116 AVCodec huffyuv_decoder = { |
1117 "huffyuv", | |
1118 CODEC_TYPE_VIDEO, | |
1119 CODEC_ID_HUFFYUV, | |
1120 sizeof(HYuvContext), | |
1121 decode_init, | |
1122 NULL, | |
1123 decode_end, | |
1124 decode_frame, | |
871 | 1125 CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND, |
866 | 1126 NULL |
1127 }; | |
1128 | |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
1129 #ifdef CONFIG_ENCODERS |
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
1130 |
866 | 1131 AVCodec huffyuv_encoder = { |
1132 "huffyuv", | |
1133 CODEC_TYPE_VIDEO, | |
1134 CODEC_ID_HUFFYUV, | |
1135 sizeof(HYuvContext), | |
1136 encode_init, | |
1137 encode_frame, | |
1138 encode_end, | |
1130 | 1139 .options = huffyuv_options, |
866 | 1140 }; |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
1141 |
1246 | 1142 #endif //CONFIG_ENCODERS |