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