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