Mercurial > libavcodec.hg
annotate huffyuv.c @ 1528:ca634e47065c libavcodec
alignment 10l
author | michael |
---|---|
date | Mon, 13 Oct 2003 18:17:58 +0000 |
parents | 8ffd0c00e6df |
children | cb523a2ca00f |
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; |
1528 | 60 uint8_t __align8 temp[3][2560]; |
866 | 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 static inline void add_left_prediction_bgr32(uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue){ |
157 int i; | |
158 int r,g,b; | |
159 r= *red; | |
160 g= *green; | |
161 b= *blue; | |
162 | |
163 for(i=0; i<w; i++){ | |
164 b+= src[4*i+0]; | |
165 g+= src[4*i+1]; | |
166 r+= src[4*i+2]; | |
167 | |
168 dst[4*i+0]= b; | |
169 dst[4*i+1]= g; | |
170 dst[4*i+2]= r; | |
171 } | |
172 | |
173 *red= r; | |
174 *green= g; | |
175 *blue= b; | |
176 } | |
177 | |
871 | 178 static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int left){ |
866 | 179 int i; |
871 | 180 if(w<32){ |
181 for(i=0; i<w; i++){ | |
182 const int temp= src[i]; | |
183 dst[i]= temp - left; | |
184 left= temp; | |
185 } | |
186 return left; | |
187 }else{ | |
188 for(i=0; i<16; i++){ | |
189 const int temp= src[i]; | |
190 dst[i]= temp - left; | |
191 left= temp; | |
192 } | |
193 s->dsp.diff_bytes(dst+16, src+16, src+15, w-16); | |
194 return src[w-1]; | |
866 | 195 } |
196 } | |
1325 | 197 |
866 | 198 static void read_len_table(uint8_t *dst, GetBitContext *gb){ |
199 int i, val, repeat; | |
200 | |
201 for(i=0; i<256;){ | |
202 repeat= get_bits(gb, 3); | |
203 val = get_bits(gb, 5); | |
204 if(repeat==0) | |
205 repeat= get_bits(gb, 8); | |
206 //printf("%d %d\n", val, repeat); | |
207 while (repeat--) | |
208 dst[i++] = val; | |
209 } | |
210 } | |
211 | |
212 static int generate_bits_table(uint32_t *dst, uint8_t *len_table){ | |
213 int len, index; | |
214 uint32_t bits=0; | |
215 | |
216 for(len=32; len>0; len--){ | |
217 for(index=0; index<256; index++){ | |
1279 | 218 if(len_table[index]==len) |
219 dst[index]= bits++; | |
866 | 220 } |
1279 | 221 if(bits & 1){ |
222 fprintf(stderr, "Error generating huffman table\n"); | |
223 return -1; | |
224 } | |
225 bits >>= 1; | |
866 | 226 } |
227 return 0; | |
228 } | |
229 | |
230 static void generate_len_table(uint8_t *dst, uint64_t *stats, int size){ | |
231 uint64_t counts[2*size]; | |
232 int up[2*size]; | |
233 int offset, i, next; | |
234 | |
235 for(offset=1; ; offset<<=1){ | |
236 for(i=0; i<size; i++){ | |
237 counts[i]= stats[i] + offset - 1; | |
238 } | |
239 | |
240 for(next=size; next<size*2; next++){ | |
241 uint64_t min1, min2; | |
242 int min1_i, min2_i; | |
243 | |
244 min1=min2= INT64_MAX; | |
245 min1_i= min2_i=-1; | |
246 | |
247 for(i=0; i<next; i++){ | |
248 if(min2 > counts[i]){ | |
249 if(min1 > counts[i]){ | |
250 min2= min1; | |
251 min2_i= min1_i; | |
252 min1= counts[i]; | |
253 min1_i= i; | |
254 }else{ | |
255 min2= counts[i]; | |
256 min2_i= i; | |
257 } | |
258 } | |
259 } | |
260 | |
261 if(min2==INT64_MAX) break; | |
262 | |
263 counts[next]= min1 + min2; | |
264 counts[min1_i]= | |
869 | 265 counts[min2_i]= INT64_MAX; |
866 | 266 up[min1_i]= |
267 up[min2_i]= next; | |
268 up[next]= -1; | |
269 } | |
270 | |
271 for(i=0; i<size; i++){ | |
272 int len; | |
273 int index=i; | |
274 | |
275 for(len=0; up[index] != -1; len++) | |
276 index= up[index]; | |
277 | |
278 if(len > 32) break; | |
279 | |
280 dst[i]= len; | |
281 } | |
282 if(i==size) break; | |
283 } | |
284 } | |
285 | |
286 static int read_huffman_tables(HYuvContext *s, uint8_t *src, int length){ | |
287 GetBitContext gb; | |
288 int i; | |
289 | |
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
|
290 init_get_bits(&gb, src, length*8); |
866 | 291 |
292 for(i=0; i<3; i++){ | |
293 read_len_table(s->len[i], &gb); | |
294 | |
295 if(generate_bits_table(s->bits[i], s->len[i])<0){ | |
296 return -1; | |
297 } | |
298 #if 0 | |
299 for(j=0; j<256; j++){ | |
300 printf("%6X, %2d, %3d\n", s->bits[i][j], s->len[i][j], j); | |
301 } | |
302 #endif | |
303 init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4); | |
304 } | |
305 | |
306 return 0; | |
307 } | |
308 | |
309 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
|
310 #if 1 |
866 | 311 GetBitContext gb; |
312 int i; | |
313 | |
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
|
314 init_get_bits(&gb, classic_shift_luma, sizeof(classic_shift_luma)*8); |
866 | 315 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
|
316 init_get_bits(&gb, classic_shift_chroma, sizeof(classic_shift_chroma)*8); |
866 | 317 read_len_table(s->len[1], &gb); |
318 | |
319 for(i=0; i<256; i++) s->bits[0][i] = classic_add_luma [i]; | |
320 for(i=0; i<256; i++) s->bits[1][i] = classic_add_chroma[i]; | |
321 | |
322 if(s->bitstream_bpp >= 24){ | |
323 memcpy(s->bits[1], s->bits[0], 256*sizeof(uint32_t)); | |
324 memcpy(s->len[1] , s->len [0], 256*sizeof(uint8_t)); | |
325 } | |
326 memcpy(s->bits[2], s->bits[1], 256*sizeof(uint32_t)); | |
327 memcpy(s->len[2] , s->len [1], 256*sizeof(uint8_t)); | |
328 | |
329 for(i=0; i<3; i++) | |
330 init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4); | |
331 | |
332 return 0; | |
333 #else | |
334 fprintf(stderr, "v1 huffyuv is not supported \n"); | |
335 return -1; | |
336 #endif | |
337 } | |
338 | |
339 static int decode_init(AVCodecContext *avctx) | |
340 { | |
341 HYuvContext *s = avctx->priv_data; | |
903 | 342 int width, height; |
866 | 343 |
344 s->avctx= avctx; | |
345 s->flags= avctx->flags; | |
346 | |
1097 | 347 dsputil_init(&s->dsp, avctx); |
866 | 348 |
349 width= s->width= avctx->width; | |
350 height= s->height= avctx->height; | |
925 | 351 avctx->coded_frame= &s->picture; |
903 | 352 |
866 | 353 s->bgr32=1; |
354 assert(width && height); | |
355 //if(avctx->extradata) | |
356 // printf("extradata:%X, extradata_size:%d\n", *(uint32_t*)avctx->extradata, avctx->extradata_size); | |
357 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
|
358 if((avctx->bits_per_sample&7) && avctx->bits_per_sample != 12) |
866 | 359 s->version=1; // do such files exist at all? |
360 else | |
361 s->version=2; | |
362 }else | |
363 s->version=0; | |
364 | |
365 if(s->version==2){ | |
366 int method; | |
367 | |
368 method= ((uint8_t*)avctx->extradata)[0]; | |
369 s->decorrelate= method&64 ? 1 : 0; | |
370 s->predictor= method&63; | |
371 s->bitstream_bpp= ((uint8_t*)avctx->extradata)[1]; | |
372 if(s->bitstream_bpp==0) | |
373 s->bitstream_bpp= avctx->bits_per_sample&~7; | |
374 | |
375 if(read_huffman_tables(s, ((uint8_t*)avctx->extradata)+4, avctx->extradata_size) < 0) | |
376 return -1; | |
377 }else{ | |
378 switch(avctx->bits_per_sample&7){ | |
379 case 1: | |
380 s->predictor= LEFT; | |
381 s->decorrelate= 0; | |
382 break; | |
383 case 2: | |
384 s->predictor= LEFT; | |
385 s->decorrelate= 1; | |
386 break; | |
387 case 3: | |
388 s->predictor= PLANE; | |
389 s->decorrelate= avctx->bits_per_sample >= 24; | |
390 break; | |
391 case 4: | |
392 s->predictor= MEDIAN; | |
393 s->decorrelate= 0; | |
394 break; | |
395 default: | |
396 s->predictor= LEFT; //OLD | |
397 s->decorrelate= 0; | |
398 break; | |
399 } | |
400 s->bitstream_bpp= avctx->bits_per_sample & ~7; | |
401 | |
402 if(read_old_huffman_tables(s) < 0) | |
403 return -1; | |
404 } | |
405 | |
406 s->interlaced= height > 288; | |
407 | |
408 switch(s->bitstream_bpp){ | |
409 case 12: | |
410 avctx->pix_fmt = PIX_FMT_YUV420P; | |
411 break; | |
412 case 16: | |
413 if(s->yuy2){ | |
414 avctx->pix_fmt = PIX_FMT_YUV422; | |
415 }else{ | |
416 avctx->pix_fmt = PIX_FMT_YUV422P; | |
417 } | |
418 break; | |
419 case 24: | |
420 case 32: | |
421 if(s->bgr32){ | |
990
165064f921ee
changed BGRA32 to RGBA32. XXX: clarify expected behaviour on big endian cpu
bellard
parents:
925
diff
changeset
|
422 avctx->pix_fmt = PIX_FMT_RGBA32; |
866 | 423 }else{ |
424 avctx->pix_fmt = PIX_FMT_BGR24; | |
425 } | |
426 break; | |
427 default: | |
428 assert(0); | |
429 } | |
430 | |
431 // printf("pred:%d bpp:%d hbpp:%d il:%d\n", s->predictor, s->bitstream_bpp, avctx->bits_per_sample, s->interlaced); | |
432 | |
433 return 0; | |
434 } | |
435 | |
436 static void store_table(HYuvContext *s, uint8_t *len){ | |
437 int i; | |
438 int index= s->avctx->extradata_size; | |
439 | |
440 for(i=0; i<256;){ | |
441 int cur=i; | |
442 int val= len[i]; | |
443 int repeat; | |
444 | |
445 for(; i<256 && len[i]==val; i++); | |
446 | |
447 repeat= i - cur; | |
448 | |
449 if(repeat>7){ | |
450 ((uint8_t*)s->avctx->extradata)[index++]= val; | |
451 ((uint8_t*)s->avctx->extradata)[index++]= repeat; | |
452 }else{ | |
453 ((uint8_t*)s->avctx->extradata)[index++]= val | (repeat<<5); | |
454 } | |
455 } | |
456 | |
457 s->avctx->extradata_size= index; | |
458 } | |
459 | |
460 static int encode_init(AVCodecContext *avctx) | |
461 { | |
462 HYuvContext *s = avctx->priv_data; | |
463 int i, j, width, height; | |
464 | |
465 s->avctx= avctx; | |
466 s->flags= avctx->flags; | |
467 | |
1097 | 468 dsputil_init(&s->dsp, avctx); |
866 | 469 |
470 width= s->width= avctx->width; | |
471 height= s->height= avctx->height; | |
472 | |
473 assert(width && height); | |
474 | |
1526 | 475 avctx->extradata= av_mallocz(1024*30); |
476 avctx->stats_out= av_mallocz(1024*30); | |
866 | 477 s->version=2; |
478 | |
925 | 479 avctx->coded_frame= &s->picture; |
903 | 480 |
866 | 481 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
|
482 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
|
483 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
|
484 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
|
485 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
|
486 } |
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
|
487 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
|
488 break; |
866 | 489 case PIX_FMT_YUV422P: |
490 s->bitstream_bpp= 16; | |
491 break; | |
492 default: | |
493 fprintf(stderr, "format not supported\n"); | |
494 return -1; | |
495 } | |
496 avctx->bits_per_sample= s->bitstream_bpp; | |
497 s->decorrelate= s->bitstream_bpp >= 24; | |
498 s->predictor= avctx->prediction_method; | |
499 | |
500 ((uint8_t*)avctx->extradata)[0]= s->predictor; | |
501 ((uint8_t*)avctx->extradata)[1]= s->bitstream_bpp; | |
502 ((uint8_t*)avctx->extradata)[2]= | |
503 ((uint8_t*)avctx->extradata)[3]= 0; | |
504 s->avctx->extradata_size= 4; | |
505 | |
506 if(avctx->stats_in){ | |
507 char *p= avctx->stats_in; | |
508 | |
509 for(i=0; i<3; i++) | |
510 for(j=0; j<256; j++) | |
511 s->stats[i][j]= 1; | |
512 | |
513 for(;;){ | |
514 for(i=0; i<3; i++){ | |
515 char *next; | |
516 | |
517 for(j=0; j<256; j++){ | |
518 s->stats[i][j]+= strtol(p, &next, 0); | |
519 if(next==p) return -1; | |
520 p=next; | |
521 } | |
522 } | |
523 if(p[0]==0 || p[1]==0 || p[2]==0) break; | |
524 } | |
525 }else{ | |
526 for(i=0; i<3; i++) | |
527 for(j=0; j<256; j++){ | |
528 int d= FFMIN(j, 256-j); | |
529 | |
530 s->stats[i][j]= 100000000/(d+1); | |
531 } | |
532 } | |
533 | |
534 for(i=0; i<3; i++){ | |
535 generate_len_table(s->len[i], s->stats[i], 256); | |
536 | |
537 if(generate_bits_table(s->bits[i], s->len[i])<0){ | |
538 return -1; | |
539 } | |
540 | |
541 store_table(s, s->len[i]); | |
542 } | |
543 | |
544 for(i=0; i<3; i++) | |
545 for(j=0; j<256; j++) | |
546 s->stats[i][j]= 0; | |
547 | |
548 s->interlaced= height > 288; | |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
549 |
866 | 550 // 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
|
551 |
866 | 552 s->picture_number=0; |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
553 |
866 | 554 return 0; |
555 } | |
556 | |
557 static void decode_422_bitstream(HYuvContext *s, int count){ | |
558 int i; | |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
559 |
866 | 560 count/=2; |
561 | |
562 for(i=0; i<count; i++){ | |
563 s->temp[0][2*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); | |
564 s->temp[1][ i ]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); | |
565 s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); | |
566 s->temp[2][ i ]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); | |
567 } | |
568 } | |
569 | |
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
|
570 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
|
571 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
|
572 |
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
|
573 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
|
574 |
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
|
575 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
|
576 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
|
577 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
|
578 } |
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
|
579 } |
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
|
580 |
866 | 581 static void encode_422_bitstream(HYuvContext *s, int count){ |
582 int i; | |
583 | |
584 count/=2; | |
585 if(s->flags&CODEC_FLAG_PASS1){ | |
586 for(i=0; i<count; i++){ | |
587 s->stats[0][ s->temp[0][2*i ] ]++; | |
588 s->stats[1][ s->temp[1][ i ] ]++; | |
589 s->stats[0][ s->temp[0][2*i+1] ]++; | |
590 s->stats[2][ s->temp[2][ i ] ]++; | |
591 } | |
592 }else{ | |
593 for(i=0; i<count; i++){ | |
594 put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]); | |
595 put_bits(&s->pb, s->len[1][ s->temp[1][ i ] ], s->bits[1][ s->temp[1][ i ] ]); | |
596 put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]); | |
597 put_bits(&s->pb, s->len[2][ s->temp[2][ i ] ], s->bits[2][ s->temp[2][ i ] ]); | |
598 } | |
599 } | |
600 } | |
601 | |
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
|
602 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
|
603 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
|
604 |
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
|
605 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
|
606 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
|
607 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
|
608 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
|
609 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
|
610 } |
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
|
611 }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
|
612 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
|
613 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
|
614 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
|
615 } |
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
|
616 } |
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
|
617 } |
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
|
618 |
866 | 619 static void decode_bgr_bitstream(HYuvContext *s, int count){ |
620 int i; | |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
621 |
866 | 622 if(s->decorrelate){ |
623 if(s->bitstream_bpp==24){ | |
624 for(i=0; i<count; i++){ | |
625 s->temp[0][4*i+1]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); | |
626 s->temp[0][4*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+1]; | |
627 s->temp[0][4*i+2]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+1]; | |
628 } | |
629 }else{ | |
630 for(i=0; i<count; i++){ | |
631 s->temp[0][4*i+1]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); | |
632 s->temp[0][4*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+1]; | |
633 s->temp[0][4*i+2]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+1]; | |
634 get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?! | |
635 } | |
636 } | |
637 }else{ | |
638 if(s->bitstream_bpp==24){ | |
639 for(i=0; i<count; i++){ | |
640 s->temp[0][4*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); | |
641 s->temp[0][4*i+1]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); | |
642 s->temp[0][4*i+2]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); | |
643 } | |
644 }else{ | |
645 for(i=0; i<count; i++){ | |
646 s->temp[0][4*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); | |
647 s->temp[0][4*i+1]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); | |
648 s->temp[0][4*i+2]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); | |
649 get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?! | |
650 } | |
651 } | |
652 } | |
653 } | |
654 | |
871 | 655 static void draw_slice(HYuvContext *s, int y){ |
656 int h, cy; | |
1368 | 657 int offset[4]; |
871 | 658 |
659 if(s->avctx->draw_horiz_band==NULL) | |
660 return; | |
661 | |
662 h= y - s->last_slice_end; | |
663 y -= h; | |
664 | |
665 if(s->bitstream_bpp==12){ | |
666 cy= y>>1; | |
667 }else{ | |
668 cy= y; | |
669 } | |
1368 | 670 |
671 offset[0] = s->picture.linesize[0]*y; | |
672 offset[1] = s->picture.linesize[1]*cy; | |
673 offset[2] = s->picture.linesize[2]*cy; | |
674 offset[3] = 0; | |
871 | 675 emms_c(); |
676 | |
1370 | 677 s->avctx->draw_horiz_band(s->avctx, &s->picture, offset, y, 3, h); |
871 | 678 |
679 s->last_slice_end= y + h; | |
680 } | |
681 | |
866 | 682 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){ |
683 HYuvContext *s = avctx->priv_data; | |
684 const int width= s->width; | |
685 const int width2= s->width>>1; | |
686 const int height= s->height; | |
870 | 687 int fake_ystride, fake_ustride, fake_vstride; |
925 | 688 AVFrame * const p= &s->picture; |
866 | 689 |
925 | 690 AVFrame *picture = data; |
866 | 691 |
692 *data_size = 0; | |
693 | |
694 /* no supplementary picture */ | |
695 if (buf_size == 0) | |
696 return 0; | |
697 | |
1273 | 698 s->dsp.bswap_buf((uint32_t*)s->bitstream_buffer, (uint32_t*)buf, buf_size/4); |
866 | 699 |
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
|
700 init_get_bits(&s->gb, s->bitstream_buffer, buf_size*8); |
870 | 701 |
1228 | 702 if(p->data[0]) |
703 avctx->release_buffer(avctx, p); | |
704 | |
903 | 705 p->reference= 0; |
706 if(avctx->get_buffer(avctx, p) < 0){ | |
707 fprintf(stderr, "get_buffer() failed\n"); | |
708 return -1; | |
709 } | |
870 | 710 |
903 | 711 fake_ystride= s->interlaced ? p->linesize[0]*2 : p->linesize[0]; |
712 fake_ustride= s->interlaced ? p->linesize[1]*2 : p->linesize[1]; | |
713 fake_vstride= s->interlaced ? p->linesize[2]*2 : p->linesize[2]; | |
871 | 714 |
715 s->last_slice_end= 0; | |
870 | 716 |
866 | 717 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
|
718 int y, cy; |
866 | 719 int lefty, leftu, leftv; |
720 int lefttopy, lefttopu, lefttopv; | |
721 | |
722 if(s->yuy2){ | |
903 | 723 p->data[0][3]= get_bits(&s->gb, 8); |
724 p->data[0][2]= get_bits(&s->gb, 8); | |
725 p->data[0][1]= get_bits(&s->gb, 8); | |
726 p->data[0][0]= get_bits(&s->gb, 8); | |
866 | 727 |
728 fprintf(stderr, "YUY2 output isnt implemenetd yet\n"); | |
729 return -1; | |
730 }else{ | |
731 | |
903 | 732 leftv= p->data[2][0]= get_bits(&s->gb, 8); |
733 lefty= p->data[0][1]= get_bits(&s->gb, 8); | |
734 leftu= p->data[1][0]= get_bits(&s->gb, 8); | |
735 p->data[0][0]= get_bits(&s->gb, 8); | |
866 | 736 |
737 switch(s->predictor){ | |
738 case LEFT: | |
739 case PLANE: | |
740 decode_422_bitstream(s, width-2); | |
903 | 741 lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); |
866 | 742 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 743 leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); |
744 leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); | |
866 | 745 } |
746 | |
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
|
747 for(cy=y=1; y<s->height; y++,cy++){ |
866 | 748 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
|
749 |
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
|
750 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
|
751 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
|
752 |
903 | 753 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
|
754 |
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
|
755 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
|
756 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
|
757 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
|
758 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
|
759 } |
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
|
760 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
|
761 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
|
762 } |
866 | 763 |
871 | 764 draw_slice(s, y); |
765 | |
903 | 766 ydst= p->data[0] + p->linesize[0]*y; |
767 udst= p->data[1] + p->linesize[1]*cy; | |
768 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
|
769 |
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_422_bitstream(s, width); |
866 | 771 lefty= add_left_prediction(ydst, s->temp[0], width, lefty); |
772 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
773 leftu= add_left_prediction(udst, s->temp[1], width2, leftu); | |
774 leftv= add_left_prediction(vdst, s->temp[2], width2, leftv); | |
775 } | |
776 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
|
777 if(cy>s->interlaced){ |
866 | 778 s->dsp.add_bytes(ydst, ydst - fake_ystride, width); |
779 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
780 s->dsp.add_bytes(udst, udst - fake_ustride, width2); | |
781 s->dsp.add_bytes(vdst, vdst - fake_vstride, width2); | |
782 } | |
783 } | |
784 } | |
785 } | |
871 | 786 draw_slice(s, height); |
787 | |
866 | 788 break; |
789 case MEDIAN: | |
790 /* first line except first 2 pixels is left predicted */ | |
791 decode_422_bitstream(s, width-2); | |
903 | 792 lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); |
866 | 793 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 794 leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); |
795 leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); | |
866 | 796 } |
797 | |
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
|
798 cy=y=1; |
866 | 799 |
800 /* second line is left predicted for interlaced case */ | |
801 if(s->interlaced){ | |
802 decode_422_bitstream(s, width); | |
903 | 803 lefty= add_left_prediction(p->data[0] + p->linesize[0], s->temp[0], width, lefty); |
866 | 804 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 805 leftu= add_left_prediction(p->data[1] + p->linesize[2], s->temp[1], width2, leftu); |
806 leftv= add_left_prediction(p->data[2] + p->linesize[1], s->temp[2], width2, leftv); | |
866 | 807 } |
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
|
808 y++; cy++; |
866 | 809 } |
810 | |
811 /* next 4 pixels are left predicted too */ | |
812 decode_422_bitstream(s, 4); | |
903 | 813 lefty= add_left_prediction(p->data[0] + fake_ystride, s->temp[0], 4, lefty); |
866 | 814 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 815 leftu= add_left_prediction(p->data[1] + fake_ustride, s->temp[1], 2, leftu); |
816 leftv= add_left_prediction(p->data[2] + fake_vstride, s->temp[2], 2, leftv); | |
866 | 817 } |
818 | |
819 /* next line except the first 4 pixels is median predicted */ | |
903 | 820 lefttopy= p->data[0][3]; |
866 | 821 decode_422_bitstream(s, width-4); |
903 | 822 add_median_prediction(p->data[0] + fake_ystride+4, p->data[0]+4, s->temp[0], width-4, &lefty, &lefttopy); |
866 | 823 if(!(s->flags&CODEC_FLAG_GRAY)){ |
903 | 824 lefttopu= p->data[1][1]; |
825 lefttopv= p->data[2][1]; | |
826 add_median_prediction(p->data[1] + fake_ustride+2, p->data[1]+2, s->temp[1], width2-2, &leftu, &lefttopu); | |
827 add_median_prediction(p->data[2] + fake_vstride+2, p->data[2]+2, s->temp[2], width2-2, &leftv, &lefttopv); | |
866 | 828 } |
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
|
829 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
|
830 |
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
|
831 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
|
832 uint8_t *ydst, *udst, *vdst; |
866 | 833 |
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
|
834 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
|
835 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
|
836 decode_gray_bitstream(s, width); |
903 | 837 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
|
838 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
|
839 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
|
840 } |
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
|
841 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
|
842 } |
871 | 843 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
|
844 |
866 | 845 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
|
846 |
903 | 847 ydst= p->data[0] + p->linesize[0]*y; |
848 udst= p->data[1] + p->linesize[1]*cy; | |
849 vdst= p->data[2] + p->linesize[2]*cy; | |
866 | 850 |
851 add_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy); | |
852 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
853 add_median_prediction(udst, udst - fake_ustride, s->temp[1], width2, &leftu, &lefttopu); | |
854 add_median_prediction(vdst, vdst - fake_vstride, s->temp[2], width2, &leftv, &lefttopv); | |
855 } | |
856 } | |
871 | 857 |
858 draw_slice(s, height); | |
866 | 859 break; |
860 } | |
861 } | |
862 }else{ | |
863 int y; | |
864 int leftr, leftg, leftb; | |
903 | 865 const int last_line= (height-1)*p->linesize[0]; |
866 | 866 |
867 if(s->bitstream_bpp==32){ | |
903 | 868 p->data[0][last_line+3]= get_bits(&s->gb, 8); |
869 leftr= p->data[0][last_line+2]= get_bits(&s->gb, 8); | |
870 leftg= p->data[0][last_line+1]= get_bits(&s->gb, 8); | |
871 leftb= p->data[0][last_line+0]= get_bits(&s->gb, 8); | |
866 | 872 }else{ |
903 | 873 leftr= p->data[0][last_line+2]= get_bits(&s->gb, 8); |
874 leftg= p->data[0][last_line+1]= get_bits(&s->gb, 8); | |
875 leftb= p->data[0][last_line+0]= get_bits(&s->gb, 8); | |
866 | 876 skip_bits(&s->gb, 8); |
877 } | |
878 | |
879 if(s->bgr32){ | |
880 switch(s->predictor){ | |
881 case LEFT: | |
882 case PLANE: | |
883 decode_bgr_bitstream(s, width-1); | |
903 | 884 add_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width-1, &leftr, &leftg, &leftb); |
866 | 885 |
886 for(y=s->height-2; y>=0; y--){ //yes its stored upside down | |
887 decode_bgr_bitstream(s, width); | |
888 | |
903 | 889 add_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb); |
866 | 890 if(s->predictor == PLANE){ |
891 if((y&s->interlaced)==0){ | |
903 | 892 s->dsp.add_bytes(p->data[0] + p->linesize[0]*y, |
893 p->data[0] + p->linesize[0]*y + fake_ystride, fake_ystride); | |
866 | 894 } |
895 } | |
896 } | |
871 | 897 draw_slice(s, height); // just 1 large slice as this isnt possible in reverse order |
866 | 898 break; |
899 default: | |
900 fprintf(stderr, "prediction type not supported!\n"); | |
901 } | |
902 }else{ | |
903 | |
904 fprintf(stderr, "BGR24 output isnt implemenetd yet\n"); | |
905 return -1; | |
906 } | |
907 } | |
908 emms_c(); | |
909 | |
903 | 910 *picture= *p; |
925 | 911 *data_size = sizeof(AVFrame); |
866 | 912 |
1078
c55bffc3b84e
round readed bits up to next 32bits, as orginal huffyuv cant handle less then 32bit blocks
michaelni
parents:
1064
diff
changeset
|
913 return (get_bits_count(&s->gb)+31)/32*4; |
866 | 914 } |
915 | |
916 static int decode_end(AVCodecContext *avctx) | |
917 { | |
918 HYuvContext *s = avctx->priv_data; | |
919 int i; | |
920 | |
921 for(i=0; i<3; i++){ | |
903 | 922 free_vlc(&s->vlc[i]); |
923 } | |
1214 | 924 |
925 avcodec_default_free_buffers(avctx); | |
866 | 926 |
927 return 0; | |
928 } | |
929 | |
930 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ | |
931 HYuvContext *s = avctx->priv_data; | |
925 | 932 AVFrame *pict = data; |
866 | 933 const int width= s->width; |
934 const int width2= s->width>>1; | |
935 const int height= s->height; | |
936 const int fake_ystride= s->interlaced ? pict->linesize[0]*2 : pict->linesize[0]; | |
937 const int fake_ustride= s->interlaced ? pict->linesize[1]*2 : pict->linesize[1]; | |
938 const int fake_vstride= s->interlaced ? pict->linesize[2]*2 : pict->linesize[2]; | |
925 | 939 AVFrame * const p= &s->picture; |
866 | 940 int i, size; |
941 | |
1522
79dddc5cd990
removed the obsolete and unused parameters of init_put_bits
alex
parents:
1370
diff
changeset
|
942 init_put_bits(&s->pb, buf, buf_size); |
866 | 943 |
903 | 944 *p = *pict; |
1006 | 945 p->pict_type= FF_I_TYPE; |
946 p->key_frame= 1; | |
866 | 947 |
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
|
948 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
|
949 int lefty, leftu, leftv, y, cy; |
866 | 950 |
903 | 951 put_bits(&s->pb, 8, leftv= p->data[2][0]); |
952 put_bits(&s->pb, 8, lefty= p->data[0][1]); | |
953 put_bits(&s->pb, 8, leftu= p->data[1][0]); | |
954 put_bits(&s->pb, 8, p->data[0][0]); | |
866 | 955 |
903 | 956 lefty= sub_left_prediction(s, s->temp[0], p->data[0]+2, width-2 , lefty); |
957 leftu= sub_left_prediction(s, s->temp[1], p->data[1]+1, width2-1, leftu); | |
958 leftv= sub_left_prediction(s, s->temp[2], p->data[2]+1, width2-1, leftv); | |
866 | 959 |
960 encode_422_bitstream(s, width-2); | |
961 | |
962 if(s->predictor==MEDIAN){ | |
963 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
|
964 cy=y=1; |
866 | 965 if(s->interlaced){ |
903 | 966 lefty= sub_left_prediction(s, s->temp[0], p->data[0]+p->linesize[0], width , lefty); |
967 leftu= sub_left_prediction(s, s->temp[1], p->data[1]+p->linesize[1], width2, leftu); | |
968 leftv= sub_left_prediction(s, s->temp[2], p->data[2]+p->linesize[2], width2, leftv); | |
866 | 969 |
970 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
|
971 y++; cy++; |
866 | 972 } |
973 | |
903 | 974 lefty= sub_left_prediction(s, s->temp[0], p->data[0]+fake_ystride, 4, lefty); |
975 leftu= sub_left_prediction(s, s->temp[1], p->data[1]+fake_ystride, 2, leftu); | |
976 leftv= sub_left_prediction(s, s->temp[2], p->data[2]+fake_ystride, 2, leftv); | |
866 | 977 |
978 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
|
979 |
903 | 980 lefttopy= p->data[0][3]; |
981 lefttopu= p->data[1][1]; | |
982 lefttopv= p->data[2][1]; | |
1527 | 983 s->dsp.sub_hfyu_median_prediction(s->temp[0], p->data[0]+4, p->data[0] + fake_ystride+4, width-4 , &lefty, &lefttopy); |
984 s->dsp.sub_hfyu_median_prediction(s->temp[1], p->data[1]+2, p->data[1] + fake_ustride+2, width2-2, &leftu, &lefttopu); | |
985 s->dsp.sub_hfyu_median_prediction(s->temp[2], p->data[2]+2, p->data[2] + fake_vstride+2, width2-2, &leftv, &lefttopv); | |
866 | 986 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
|
987 y++; cy++; |
866 | 988 |
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 for(; y<height; y++,cy++){ |
866 | 990 uint8_t *ydst, *udst, *vdst; |
991 | |
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
|
992 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
|
993 while(2*cy > y){ |
903 | 994 ydst= p->data[0] + p->linesize[0]*y; |
1527 | 995 s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy); |
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
|
996 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
|
997 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
|
998 } |
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
|
999 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
|
1000 } |
903 | 1001 ydst= p->data[0] + p->linesize[0]*y; |
1002 udst= p->data[1] + p->linesize[1]*cy; | |
1003 vdst= p->data[2] + p->linesize[2]*cy; | |
866 | 1004 |
1527 | 1005 s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy); |
1006 s->dsp.sub_hfyu_median_prediction(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu); | |
1007 s->dsp.sub_hfyu_median_prediction(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv); | |
866 | 1008 |
1009 encode_422_bitstream(s, width); | |
1010 } | |
1011 }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
|
1012 for(cy=y=1; y<height; y++,cy++){ |
866 | 1013 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
|
1014 |
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 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
|
1016 if(s->bitstream_bpp==12){ |
903 | 1017 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
|
1018 |
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 if(s->predictor == PLANE && s->interlaced < y){ |
871 | 1020 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
|
1021 |
871 | 1022 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
|
1023 }else{ |
871 | 1024 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
|
1025 } |
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
|
1026 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
|
1027 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
|
1028 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
|
1029 } |
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 |
903 | 1031 ydst= p->data[0] + p->linesize[0]*y; |
1032 udst= p->data[1] + p->linesize[1]*cy; | |
1033 vdst= p->data[2] + p->linesize[2]*cy; | |
866 | 1034 |
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
|
1035 if(s->predictor == PLANE && s->interlaced < cy){ |
871 | 1036 s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width); |
1037 s->dsp.diff_bytes(s->temp[2], udst, udst - fake_ustride, width2); | |
1526 | 1038 s->dsp.diff_bytes(s->temp[2] + 1250, vdst, vdst - fake_vstride, width2); |
866 | 1039 |
871 | 1040 lefty= sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty); |
1041 leftu= sub_left_prediction(s, s->temp[1], s->temp[2], width2, leftu); | |
1526 | 1042 leftv= sub_left_prediction(s, s->temp[2], s->temp[2] + 1250, width2, leftv); |
866 | 1043 }else{ |
871 | 1044 lefty= sub_left_prediction(s, s->temp[0], ydst, width , lefty); |
1045 leftu= sub_left_prediction(s, s->temp[1], udst, width2, leftu); | |
1046 leftv= sub_left_prediction(s, s->temp[2], vdst, width2, leftv); | |
866 | 1047 } |
1048 | |
1049 encode_422_bitstream(s, width); | |
1050 } | |
1051 } | |
1052 }else{ | |
1053 fprintf(stderr, "Format not supported!\n"); | |
1054 } | |
1055 emms_c(); | |
1056 | |
1057 size= (get_bit_count(&s->pb)+31)/32; | |
1058 | |
1059 if((s->flags&CODEC_FLAG_PASS1) && (s->picture_number&31)==0){ | |
1060 int j; | |
1061 char *p= avctx->stats_out; | |
1062 for(i=0; i<3; i++){ | |
1063 for(j=0; j<256; j++){ | |
1282 | 1064 sprintf(p, "%llu ", s->stats[i][j]); |
866 | 1065 p+= strlen(p); |
1066 s->stats[i][j]= 0; | |
1067 } | |
1068 sprintf(p, "\n"); | |
1069 p++; | |
1070 } | |
1071 }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
|
1072 flush_put_bits(&s->pb); |
1273 | 1073 s->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size); |
866 | 1074 } |
1075 | |
1076 s->picture_number++; | |
903 | 1077 |
866 | 1078 return size*4; |
1079 } | |
1080 | |
1081 static int encode_end(AVCodecContext *avctx) | |
1082 { | |
1083 // HYuvContext *s = avctx->priv_data; | |
1084 | |
1085 av_freep(&avctx->extradata); | |
1086 av_freep(&avctx->stats_out); | |
1087 | |
1088 return 0; | |
1089 } | |
1090 | |
1130 | 1091 static const AVOption huffyuv_options[] = |
1092 { | |
1093 AVOPTION_CODEC_INT("prediction_method", "prediction_method", prediction_method, 0, 2, 0), | |
1094 AVOPTION_END() | |
1095 }; | |
1096 | |
866 | 1097 AVCodec huffyuv_decoder = { |
1098 "huffyuv", | |
1099 CODEC_TYPE_VIDEO, | |
1100 CODEC_ID_HUFFYUV, | |
1101 sizeof(HYuvContext), | |
1102 decode_init, | |
1103 NULL, | |
1104 decode_end, | |
1105 decode_frame, | |
871 | 1106 CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND, |
866 | 1107 NULL |
1108 }; | |
1109 | |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
1110 #ifdef CONFIG_ENCODERS |
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
1111 |
866 | 1112 AVCodec huffyuv_encoder = { |
1113 "huffyuv", | |
1114 CODEC_TYPE_VIDEO, | |
1115 CODEC_ID_HUFFYUV, | |
1116 sizeof(HYuvContext), | |
1117 encode_init, | |
1118 encode_frame, | |
1119 encode_end, | |
1130 | 1120 .options = huffyuv_options, |
866 | 1121 }; |
1232
e88d3b1fb2a1
more #ifdef CONFIG_ENCODERS by (Wolfgang Hesseler <qv at multimediaware dot com>)
michaelni
parents:
1228
diff
changeset
|
1122 |
1246 | 1123 #endif //CONFIG_ENCODERS |