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