Snow is a toy codec with no real-world use and horrible code.
Diego Biurrun authored on 2012/09/25 00:57:14... | ... |
@@ -123,7 +123,6 @@ Component options: |
123 | 123 |
--enable-x11grab enable X11 grabbing [no] |
124 | 124 |
--disable-network disable network support [no] |
125 | 125 |
--disable-dct disable DCT code |
126 |
- --disable-dwt disable DWT code |
|
127 | 126 |
--disable-lsp disable LSP code |
128 | 127 |
--disable-lzo disable LZO decoder code |
129 | 128 |
--disable-mdct disable MDCT code |
... | ... |
@@ -1023,7 +1022,6 @@ CONFIG_LIST=" |
1023 | 1023 |
bzlib |
1024 | 1024 |
dct |
1025 | 1025 |
doc |
1026 |
- dwt |
|
1027 | 1026 |
dxva2 |
1028 | 1027 |
fft |
1029 | 1028 |
frei0r |
... | ... |
@@ -1559,8 +1557,6 @@ rv30_decoder_select="error_resilience golomb h264chroma h264pred h264qpel mpegvi |
1559 | 1559 |
rv40_decoder_select="error_resilience golomb h264chroma h264pred h264qpel mpegvideo" |
1560 | 1560 |
shorten_decoder_select="golomb" |
1561 | 1561 |
sipr_decoder_select="lsp" |
1562 |
-snow_decoder_select="dwt rangecoder" |
|
1563 |
-snow_encoder_select="aandcttables dwt error_resilience mpegvideoenc rangecoder" |
|
1564 | 1562 |
svq1_decoder_select="error_resilience mpegvideo" |
1565 | 1563 |
svq1_encoder_select="aandcttables error_resilience mpegvideoenc" |
1566 | 1564 |
svq3_decoder_select="error_resilience golomb h264chroma h264dsp h264pred h264qpel mpegvideo" |
... | ... |
@@ -1934,8 +1930,6 @@ for n in $COMPONENT_LIST; do |
1934 | 1934 |
eval ${n}_if_any="\$$v" |
1935 | 1935 |
done |
1936 | 1936 |
|
1937 |
-disable snow_decoder snow_encoder |
|
1938 |
- |
|
1939 | 1937 |
enable $ARCH_EXT_LIST |
1940 | 1938 |
|
1941 | 1939 |
die_unknown(){ |
... | ... |
@@ -606,8 +606,6 @@ following image formats are supported: |
606 | 606 |
@item Smacker video @tab @tab X |
607 | 607 |
@tab Video encoding used in Smacker. |
608 | 608 |
@item SMPTE VC-1 @tab @tab X |
609 |
-@item Snow @tab X @tab X |
|
610 |
- @tab experimental wavelet codec (fourcc: SNOW) |
|
611 | 609 |
@item Sony PlayStation MDEC (Motion DECoder) @tab @tab X |
612 | 610 |
@item Sorenson Vector Quantizer 1 @tab X @tab X |
613 | 611 |
@tab fourcc: SVQ1 |
... | ... |
@@ -109,7 +109,6 @@ PFD[32] would for example be signed 32 bit little-endian IEEE float |
109 | 109 |
@item RV20 @tab RealVideo 2.0 |
110 | 110 |
@item RV30 @tab RealVideo 3.0 |
111 | 111 |
@item RV40 @tab RealVideo 4.0 |
112 |
-@item SNOW @tab FFmpeg Snow |
|
113 | 112 |
@item SVQ1 @tab Sorenson Video 1 |
114 | 113 |
@item SVQ3 @tab Sorenson Video 3 |
115 | 114 |
@item theo @tab Xiph Theora |
116 | 115 |
deleted file mode 100644 |
... | ... |
@@ -1,630 +0,0 @@ |
1 |
-============================================= |
|
2 |
-Snow Video Codec Specification Draft 20080110 |
|
3 |
-============================================= |
|
4 |
- |
|
5 |
-Introduction: |
|
6 |
-============= |
|
7 |
-This specification describes the Snow bitstream syntax and semantics as |
|
8 |
-well as the formal Snow decoding process. |
|
9 |
- |
|
10 |
-The decoding process is described precisely and any compliant decoder |
|
11 |
-MUST produce the exact same output for a spec-conformant Snow stream. |
|
12 |
-For encoding, though, any process which generates a stream compliant to |
|
13 |
-the syntactical and semantic requirements and which is decodable by |
|
14 |
-the process described in this spec shall be considered a conformant |
|
15 |
-Snow encoder. |
|
16 |
- |
|
17 |
-Definitions: |
|
18 |
-============ |
|
19 |
- |
|
20 |
-MUST the specific part must be done to conform to this standard |
|
21 |
-SHOULD it is recommended to be done that way, but not strictly required |
|
22 |
- |
|
23 |
-ilog2(x) is the rounded down logarithm of x with basis 2 |
|
24 |
-ilog2(0) = 0 |
|
25 |
- |
|
26 |
-Type definitions: |
|
27 |
-================= |
|
28 |
- |
|
29 |
-b 1-bit range coded |
|
30 |
-u unsigned scalar value range coded |
|
31 |
-s signed scalar value range coded |
|
32 |
- |
|
33 |
- |
|
34 |
-Bitstream syntax: |
|
35 |
-================= |
|
36 |
- |
|
37 |
-frame: |
|
38 |
- header |
|
39 |
- prediction |
|
40 |
- residual |
|
41 |
- |
|
42 |
-header: |
|
43 |
- keyframe b MID_STATE |
|
44 |
- if(keyframe || always_reset) |
|
45 |
- reset_contexts |
|
46 |
- if(keyframe){ |
|
47 |
- version u header_state |
|
48 |
- always_reset b header_state |
|
49 |
- temporal_decomposition_type u header_state |
|
50 |
- temporal_decomposition_count u header_state |
|
51 |
- spatial_decomposition_count u header_state |
|
52 |
- colorspace_type u header_state |
|
53 |
- chroma_h_shift u header_state |
|
54 |
- chroma_v_shift u header_state |
|
55 |
- spatial_scalability b header_state |
|
56 |
- max_ref_frames-1 u header_state |
|
57 |
- qlogs |
|
58 |
- } |
|
59 |
- if(!keyframe){ |
|
60 |
- update_mc b header_state |
|
61 |
- if(update_mc){ |
|
62 |
- for(plane=0; plane<2; plane++){ |
|
63 |
- diag_mc b header_state |
|
64 |
- htaps/2-1 u header_state |
|
65 |
- for(i= p->htaps/2; i; i--) |
|
66 |
- |hcoeff[i]| u header_state |
|
67 |
- } |
|
68 |
- } |
|
69 |
- update_qlogs b header_state |
|
70 |
- if(update_qlogs){ |
|
71 |
- spatial_decomposition_count u header_state |
|
72 |
- qlogs |
|
73 |
- } |
|
74 |
- } |
|
75 |
- |
|
76 |
- spatial_decomposition_type s header_state |
|
77 |
- qlog s header_state |
|
78 |
- mv_scale s header_state |
|
79 |
- qbias s header_state |
|
80 |
- block_max_depth s header_state |
|
81 |
- |
|
82 |
-qlogs: |
|
83 |
- for(plane=0; plane<2; plane++){ |
|
84 |
- quant_table[plane][0][0] s header_state |
|
85 |
- for(level=0; level < spatial_decomposition_count; level++){ |
|
86 |
- quant_table[plane][level][1]s header_state |
|
87 |
- quant_table[plane][level][3]s header_state |
|
88 |
- } |
|
89 |
- } |
|
90 |
- |
|
91 |
-reset_contexts |
|
92 |
- *_state[*]= MID_STATE |
|
93 |
- |
|
94 |
-prediction: |
|
95 |
- for(y=0; y<block_count_vertical; y++) |
|
96 |
- for(x=0; x<block_count_horizontal; x++) |
|
97 |
- block(0) |
|
98 |
- |
|
99 |
-block(level): |
|
100 |
- mvx_diff=mvy_diff=y_diff=cb_diff=cr_diff=0 |
|
101 |
- if(keyframe){ |
|
102 |
- intra=1 |
|
103 |
- }else{ |
|
104 |
- if(level!=max_block_depth){ |
|
105 |
- s_context= 2*left->level + 2*top->level + topleft->level + topright->level |
|
106 |
- leaf b block_state[4 + s_context] |
|
107 |
- } |
|
108 |
- if(level==max_block_depth || leaf){ |
|
109 |
- intra b block_state[1 + left->intra + top->intra] |
|
110 |
- if(intra){ |
|
111 |
- y_diff s block_state[32] |
|
112 |
- cb_diff s block_state[64] |
|
113 |
- cr_diff s block_state[96] |
|
114 |
- }else{ |
|
115 |
- ref_context= ilog2(2*left->ref) + ilog2(2*top->ref) |
|
116 |
- if(ref_frames > 1) |
|
117 |
- ref u block_state[128 + 1024 + 32*ref_context] |
|
118 |
- mx_context= ilog2(2*abs(left->mx - top->mx)) |
|
119 |
- my_context= ilog2(2*abs(left->my - top->my)) |
|
120 |
- mvx_diff s block_state[128 + 32*(mx_context + 16*!!ref)] |
|
121 |
- mvy_diff s block_state[128 + 32*(my_context + 16*!!ref)] |
|
122 |
- } |
|
123 |
- }else{ |
|
124 |
- block(level+1) |
|
125 |
- block(level+1) |
|
126 |
- block(level+1) |
|
127 |
- block(level+1) |
|
128 |
- } |
|
129 |
- } |
|
130 |
- |
|
131 |
- |
|
132 |
-residual: |
|
133 |
- residual2(luma) |
|
134 |
- residual2(chroma_cr) |
|
135 |
- residual2(chroma_cb) |
|
136 |
- |
|
137 |
-residual2: |
|
138 |
- for(level=0; level<spatial_decomposition_count; level++){ |
|
139 |
- if(level==0) |
|
140 |
- subband(LL, 0) |
|
141 |
- subband(HL, level) |
|
142 |
- subband(LH, level) |
|
143 |
- subband(HH, level) |
|
144 |
- } |
|
145 |
- |
|
146 |
-subband: |
|
147 |
- FIXME |
|
148 |
- |
|
149 |
- |
|
150 |
- |
|
151 |
-Tag description: |
|
152 |
- |
|
153 |
-version |
|
154 |
- 0 |
|
155 |
- this MUST NOT change within a bitstream |
|
156 |
- |
|
157 |
-always_reset |
|
158 |
- if 1 then the range coder contexts will be reset after each frame |
|
159 |
- |
|
160 |
-temporal_decomposition_type |
|
161 |
- 0 |
|
162 |
- |
|
163 |
-temporal_decomposition_count |
|
164 |
- 0 |
|
165 |
- |
|
166 |
-spatial_decomposition_count |
|
167 |
- FIXME |
|
168 |
- |
|
169 |
-colorspace_type |
|
170 |
- 0 |
|
171 |
- this MUST NOT change within a bitstream |
|
172 |
- |
|
173 |
-chroma_h_shift |
|
174 |
- log2(luma.width / chroma.width) |
|
175 |
- this MUST NOT change within a bitstream |
|
176 |
- |
|
177 |
-chroma_v_shift |
|
178 |
- log2(luma.height / chroma.height) |
|
179 |
- this MUST NOT change within a bitstream |
|
180 |
- |
|
181 |
-spatial_scalability |
|
182 |
- 0 |
|
183 |
- |
|
184 |
-max_ref_frames |
|
185 |
- maximum number of reference frames |
|
186 |
- this MUST NOT change within a bitstream |
|
187 |
- |
|
188 |
-update_mc |
|
189 |
- indicates that motion compensation filter parameters are stored in the |
|
190 |
- header |
|
191 |
- |
|
192 |
-diag_mc |
|
193 |
- flag to enable faster diagonal interpolation |
|
194 |
- this SHOULD be 1 unless it turns out to be covered by a valid patent |
|
195 |
- |
|
196 |
-htaps |
|
197 |
- number of half pel interpolation filter taps, MUST be even, >0 and <10 |
|
198 |
- |
|
199 |
-hcoeff |
|
200 |
- half pel interpolation filter coefficients, hcoeff[0] are the 2 middle |
|
201 |
- coefficients [1] are the next outer ones and so on, resulting in a filter |
|
202 |
- like: ...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... |
|
203 |
- the sign of the coefficients is not explicitly stored but alternates |
|
204 |
- after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... |
|
205 |
- hcoeff[0] is not explicitly stored but found by subtracting the sum |
|
206 |
- of all stored coefficients with signs from 32 |
|
207 |
- hcoeff[0]= 32 - hcoeff[1] - hcoeff[2] - ... |
|
208 |
- a good choice for hcoeff and htaps is |
|
209 |
- htaps= 6 |
|
210 |
- hcoeff={40,-10,2} |
|
211 |
- an alternative which requires more computations at both encoder and |
|
212 |
- decoder side and may or may not be better is |
|
213 |
- htaps= 8 |
|
214 |
- hcoeff={42,-14,6,-2} |
|
215 |
- |
|
216 |
- |
|
217 |
-ref_frames |
|
218 |
- minimum of the number of available reference frames and max_ref_frames |
|
219 |
- for example the first frame after a key frame always has ref_frames=1 |
|
220 |
- |
|
221 |
-spatial_decomposition_type |
|
222 |
- wavelet type |
|
223 |
- 0 is a 9/7 symmetric compact integer wavelet |
|
224 |
- 1 is a 5/3 symmetric compact integer wavelet |
|
225 |
- others are reserved |
|
226 |
- stored as delta from last, last is reset to 0 if always_reset || keyframe |
|
227 |
- |
|
228 |
-qlog |
|
229 |
- quality (logarthmic quantizer scale) |
|
230 |
- stored as delta from last, last is reset to 0 if always_reset || keyframe |
|
231 |
- |
|
232 |
-mv_scale |
|
233 |
- stored as delta from last, last is reset to 0 if always_reset || keyframe |
|
234 |
- FIXME check that everything works fine if this changes between frames |
|
235 |
- |
|
236 |
-qbias |
|
237 |
- dequantization bias |
|
238 |
- stored as delta from last, last is reset to 0 if always_reset || keyframe |
|
239 |
- |
|
240 |
-block_max_depth |
|
241 |
- maximum depth of the block tree |
|
242 |
- stored as delta from last, last is reset to 0 if always_reset || keyframe |
|
243 |
- |
|
244 |
-quant_table |
|
245 |
- quantiztation table |
|
246 |
- |
|
247 |
- |
|
248 |
-Highlevel bitstream structure: |
|
249 |
-============================= |
|
250 |
- -------------------------------------------- |
|
251 |
-| Header | |
|
252 |
- -------------------------------------------- |
|
253 |
-| ------------------------------------ | |
|
254 |
-| | Block0 | | |
|
255 |
-| | split? | | |
|
256 |
-| | yes no | | |
|
257 |
-| | ......... intra? | | |
|
258 |
-| | : Block01 : yes no | | |
|
259 |
-| | : Block02 : ....... .......... | | |
|
260 |
-| | : Block03 : : y DC : : ref index: | | |
|
261 |
-| | : Block04 : : cb DC : : motion x : | | |
|
262 |
-| | ......... : cr DC : : motion y : | | |
|
263 |
-| | ....... .......... | | |
|
264 |
-| ------------------------------------ | |
|
265 |
-| ------------------------------------ | |
|
266 |
-| | Block1 | | |
|
267 |
-| ... | |
|
268 |
- -------------------------------------------- |
|
269 |
-| ------------ ------------ ------------ | |
|
270 |
-|| Y subbands | | Cb subbands| | Cr subbands|| |
|
271 |
-|| --- --- | | --- --- | | --- --- || |
|
272 |
-|| |LL0||HL0| | | |LL0||HL0| | | |LL0||HL0| || |
|
273 |
-|| --- --- | | --- --- | | --- --- || |
|
274 |
-|| --- --- | | --- --- | | --- --- || |
|
275 |
-|| |LH0||HH0| | | |LH0||HH0| | | |LH0||HH0| || |
|
276 |
-|| --- --- | | --- --- | | --- --- || |
|
277 |
-|| --- --- | | --- --- | | --- --- || |
|
278 |
-|| |HL1||LH1| | | |HL1||LH1| | | |HL1||LH1| || |
|
279 |
-|| --- --- | | --- --- | | --- --- || |
|
280 |
-|| --- --- | | --- --- | | --- --- || |
|
281 |
-|| |HH1||HL2| | | |HH1||HL2| | | |HH1||HL2| || |
|
282 |
-|| ... | | ... | | ... || |
|
283 |
-| ------------ ------------ ------------ | |
|
284 |
- -------------------------------------------- |
|
285 |
- |
|
286 |
-Decoding process: |
|
287 |
-================= |
|
288 |
- |
|
289 |
- ------------ |
|
290 |
- | | |
|
291 |
- | Subbands | |
|
292 |
- ------------ | | |
|
293 |
- | | ------------ |
|
294 |
- | Intra DC | | |
|
295 |
- | | LL0 subband prediction |
|
296 |
- ------------ | |
|
297 |
- \ Dequantizaton |
|
298 |
- ------------------- \ | |
|
299 |
-| Reference frames | \ IDWT |
|
300 |
-| ------- ------- | Motion \ | |
|
301 |
-||Frame 0| |Frame 1|| Compensation . OBMC v ------- |
|
302 |
-| ------- ------- | --------------. \------> + --->|Frame n|-->output |
|
303 |
-| ------- ------- | ------- |
|
304 |
-||Frame 2| |Frame 3||<----------------------------------/ |
|
305 |
-| ... | |
|
306 |
- ------------------- |
|
307 |
- |
|
308 |
- |
|
309 |
-Range Coder: |
|
310 |
-============ |
|
311 |
- |
|
312 |
-Binary Range Coder: |
|
313 |
-The implemented range coder is an adapted version based upon "Range encoding: |
|
314 |
-an algorithm for removing redundancy from a digitised message." by G. N. N. |
|
315 |
-Martin. |
|
316 |
-The symbols encoded by the Snow range coder are bits (0|1). The |
|
317 |
-associated probabilities are not fix but change depending on the symbol mix |
|
318 |
-seen so far. |
|
319 |
- |
|
320 |
- |
|
321 |
-bit seen | new state |
|
322 |
- 0 | 256 - state_transition_table[256 - old_state]; |
|
323 |
- 1 | state_transition_table[ old_state]; |
|
324 |
- |
|
325 |
-state_transition_table = { |
|
326 |
- 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, |
|
327 |
- 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, |
|
328 |
- 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, |
|
329 |
- 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, |
|
330 |
- 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, |
|
331 |
- 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, |
|
332 |
-104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, |
|
333 |
-119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, |
|
334 |
-134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, |
|
335 |
-150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, |
|
336 |
-165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, |
|
337 |
-180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, |
|
338 |
-195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, |
|
339 |
-210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, |
|
340 |
-226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, |
|
341 |
-241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0}; |
|
342 |
- |
|
343 |
-FIXME |
|
344 |
- |
|
345 |
- |
|
346 |
-Range Coding of integers: |
|
347 |
-FIXME |
|
348 |
- |
|
349 |
- |
|
350 |
-Neighboring Blocks: |
|
351 |
-=================== |
|
352 |
-left and top are set to the respective blocks unless they are outside of |
|
353 |
-the image in which case they are set to the Null block |
|
354 |
- |
|
355 |
-top-left is set to the top left block unless it is outside of the image in |
|
356 |
-which case it is set to the left block |
|
357 |
- |
|
358 |
-if this block has no larger parent block or it is at the left side of its |
|
359 |
-parent block and the top right block is not outside of the image then the |
|
360 |
-top right block is used for top-right else the top-left block is used |
|
361 |
- |
|
362 |
-Null block |
|
363 |
-y,cb,cr are 128 |
|
364 |
-level, ref, mx and my are 0 |
|
365 |
- |
|
366 |
- |
|
367 |
-Motion Vector Prediction: |
|
368 |
-========================= |
|
369 |
-1. the motion vectors of all the neighboring blocks are scaled to |
|
370 |
-compensate for the difference of reference frames |
|
371 |
- |
|
372 |
-scaled_mv= (mv * (256 * (current_reference+1) / (mv.reference+1)) + 128)>>8 |
|
373 |
- |
|
374 |
-2. the median of the scaled left, top and top-right vectors is used as |
|
375 |
-motion vector prediction |
|
376 |
- |
|
377 |
-3. the used motion vector is the sum of the predictor and |
|
378 |
- (mvx_diff, mvy_diff)*mv_scale |
|
379 |
- |
|
380 |
- |
|
381 |
-Intra DC Predicton: |
|
382 |
-====================== |
|
383 |
-the luma and chroma values of the left block are used as predictors |
|
384 |
- |
|
385 |
-the used luma and chroma is the sum of the predictor and y_diff, cb_diff, cr_diff |
|
386 |
-to reverse this in the decoder apply the following: |
|
387 |
-block[y][x].dc[0] = block[y][x-1].dc[0] + y_diff; |
|
388 |
-block[y][x].dc[1] = block[y][x-1].dc[1] + cb_diff; |
|
389 |
-block[y][x].dc[2] = block[y][x-1].dc[2] + cr_diff; |
|
390 |
-block[*][-1].dc[*]= 128; |
|
391 |
- |
|
392 |
- |
|
393 |
-Motion Compensation: |
|
394 |
-==================== |
|
395 |
- |
|
396 |
-Halfpel interpolation: |
|
397 |
-halfpel interpolation is done by convolution with the halfpel filter stored |
|
398 |
-in the header: |
|
399 |
- |
|
400 |
-horizontal halfpel samples are found by |
|
401 |
-H1[y][x] = hcoeff[0]*(F[y][x ] + F[y][x+1]) |
|
402 |
- + hcoeff[1]*(F[y][x-1] + F[y][x+2]) |
|
403 |
- + hcoeff[2]*(F[y][x-2] + F[y][x+3]) |
|
404 |
- + ... |
|
405 |
-h1[y][x] = (H1[y][x] + 32)>>6; |
|
406 |
- |
|
407 |
-vertical halfpel samples are found by |
|
408 |
-H2[y][x] = hcoeff[0]*(F[y ][x] + F[y+1][x]) |
|
409 |
- + hcoeff[1]*(F[y-1][x] + F[y+2][x]) |
|
410 |
- + ... |
|
411 |
-h2[y][x] = (H2[y][x] + 32)>>6; |
|
412 |
- |
|
413 |
-vertical+horizontal halfpel samples are found by |
|
414 |
-H3[y][x] = hcoeff[0]*(H2[y][x ] + H2[y][x+1]) |
|
415 |
- + hcoeff[1]*(H2[y][x-1] + H2[y][x+2]) |
|
416 |
- + ... |
|
417 |
-H3[y][x] = hcoeff[0]*(H1[y ][x] + H1[y+1][x]) |
|
418 |
- + hcoeff[1]*(H1[y+1][x] + H1[y+2][x]) |
|
419 |
- + ... |
|
420 |
-h3[y][x] = (H3[y][x] + 2048)>>12; |
|
421 |
- |
|
422 |
- |
|
423 |
- F H1 F |
|
424 |
- | | | |
|
425 |
- | | | |
|
426 |
- | | | |
|
427 |
- F H1 F |
|
428 |
- | | | |
|
429 |
- | | | |
|
430 |
- | | | |
|
431 |
- F-------F-------F-> H1<-F-------F-------F |
|
432 |
- v v v |
|
433 |
- H2 H3 H2 |
|
434 |
- ^ ^ ^ |
|
435 |
- F-------F-------F-> H1<-F-------F-------F |
|
436 |
- | | | |
|
437 |
- | | | |
|
438 |
- | | | |
|
439 |
- F H1 F |
|
440 |
- | | | |
|
441 |
- | | | |
|
442 |
- | | | |
|
443 |
- F H1 F |
|
444 |
- |
|
445 |
- |
|
446 |
-unavailable fullpel samples (outside the picture for example) shall be equal |
|
447 |
-to the closest available fullpel sample |
|
448 |
- |
|
449 |
- |
|
450 |
-Smaller pel interpolation: |
|
451 |
-if diag_mc is set then points which lie on a line between 2 vertically, |
|
452 |
-horiziontally or diagonally adjacent halfpel points shall be interpolated |
|
453 |
-linearls with rounding to nearest and halfway values rounded up. |
|
454 |
-points which lie on 2 diagonals at the same time should only use the one |
|
455 |
-diagonal not containing the fullpel point |
|
456 |
- |
|
457 |
- |
|
458 |
- |
|
459 |
- F-->O---q---O<--h1->O---q---O<--F |
|
460 |
- v \ / v \ / v |
|
461 |
- O O O O O O O |
|
462 |
- | / | \ | |
|
463 |
- q q q q q |
|
464 |
- | / | \ | |
|
465 |
- O O O O O O O |
|
466 |
- ^ / \ ^ / \ ^ |
|
467 |
- h2-->O---q---O<--h3->O---q---O<--h2 |
|
468 |
- v \ / v \ / v |
|
469 |
- O O O O O O O |
|
470 |
- | \ | / | |
|
471 |
- q q q q q |
|
472 |
- | \ | / | |
|
473 |
- O O O O O O O |
|
474 |
- ^ / \ ^ / \ ^ |
|
475 |
- F-->O---q---O<--h1->O---q---O<--F |
|
476 |
- |
|
477 |
- |
|
478 |
- |
|
479 |
-the remaining points shall be bilinearly interpolated from the |
|
480 |
-up to 4 surrounding halfpel and fullpel points, again rounding should be to |
|
481 |
-nearest and halfway values rounded up |
|
482 |
- |
|
483 |
-compliant Snow decoders MUST support 1-1/8 pel luma and 1/2-1/16 pel chroma |
|
484 |
-interpolation at least |
|
485 |
- |
|
486 |
- |
|
487 |
-Overlapped block motion compensation: |
|
488 |
-FIXME |
|
489 |
- |
|
490 |
-LL band prediction: |
|
491 |
-=================== |
|
492 |
-Each sample in the LL0 subband is predicted by the median of the left, top and |
|
493 |
-left+top-topleft samples, samples outside the subband shall be considered to |
|
494 |
-be 0. To reverse this prediction in the decoder apply the following. |
|
495 |
-for(y=0; y<height; y++){ |
|
496 |
- for(x=0; x<width; x++){ |
|
497 |
- sample[y][x] += median(sample[y-1][x], |
|
498 |
- sample[y][x-1], |
|
499 |
- sample[y-1][x]+sample[y][x-1]-sample[y-1][x-1]); |
|
500 |
- } |
|
501 |
-} |
|
502 |
-sample[-1][*]=sample[*][-1]= 0; |
|
503 |
-width,height here are the width and height of the LL0 subband not of the final |
|
504 |
-video |
|
505 |
- |
|
506 |
- |
|
507 |
-Dequantizaton: |
|
508 |
-============== |
|
509 |
-FIXME |
|
510 |
- |
|
511 |
-Wavelet Transform: |
|
512 |
-================== |
|
513 |
- |
|
514 |
-Snow supports 2 wavelet transforms, the symmetric biorthogonal 5/3 integer |
|
515 |
-transform and a integer approximation of the symmetric biorthogonal 9/7 |
|
516 |
-daubechies wavelet. |
|
517 |
- |
|
518 |
-2D IDWT (inverse discrete wavelet transform) |
|
519 |
-The 2D IDWT applies a 2D filter recursively, each time combining the |
|
520 |
-4 lowest frequency subbands into a single subband until only 1 subband |
|
521 |
-remains. |
|
522 |
-The 2D filter is done by first applying a 1D filter in the vertical direction |
|
523 |
-and then applying it in the horizontal one. |
|
524 |
- --------------- --------------- --------------- --------------- |
|
525 |
-|LL0|HL0| | | | | | | | | | | | |
|
526 |
-|---+---| HL1 | | L0|H0 | HL1 | | LL1 | HL1 | | | | |
|
527 |
-|LH0|HH0| | | | | | | | | | | | |
|
528 |
-|-------+-------|->|-------+-------|->|-------+-------|->| L1 | H1 |->... |
|
529 |
-| | | | | | | | | | | | |
|
530 |
-| LH1 | HH1 | | LH1 | HH1 | | LH1 | HH1 | | | | |
|
531 |
-| | | | | | | | | | | | |
|
532 |
- --------------- --------------- --------------- --------------- |
|
533 |
- |
|
534 |
- |
|
535 |
-1D Filter: |
|
536 |
-1. interleave the samples of the low and high frequency subbands like |
|
537 |
-s={L0, H0, L1, H1, L2, H2, L3, H3, ... } |
|
538 |
-note, this can end with a L or a H, the number of elements shall be w |
|
539 |
-s[-1] shall be considered equivalent to s[1 ] |
|
540 |
-s[w ] shall be considered equivalent to s[w-2] |
|
541 |
- |
|
542 |
-2. perform the lifting steps in order as described below |
|
543 |
- |
|
544 |
-5/3 Integer filter: |
|
545 |
-1. s[i] -= (s[i-1] + s[i+1] + 2)>>2; for all even i < w |
|
546 |
-2. s[i] += (s[i-1] + s[i+1] )>>1; for all odd i < w |
|
547 |
- |
|
548 |
-\ | /|\ | /|\ | /|\ | /|\ |
|
549 |
- \|/ | \|/ | \|/ | \|/ | |
|
550 |
- + | + | + | + | -1/4 |
|
551 |
- /|\ | /|\ | /|\ | /|\ | |
|
552 |
-/ | \|/ | \|/ | \|/ | \|/ |
|
553 |
- | + | + | + | + +1/2 |
|
554 |
- |
|
555 |
- |
|
556 |
-Snow's 9/7 Integer filter: |
|
557 |
-1. s[i] -= (3*(s[i-1] + s[i+1]) + 4)>>3; for all even i < w |
|
558 |
-2. s[i] -= s[i-1] + s[i+1] ; for all odd i < w |
|
559 |
-3. s[i] += ( s[i-1] + s[i+1] + 4*s[i] + 8)>>4; for all even i < w |
|
560 |
-4. s[i] += (3*(s[i-1] + s[i+1]) )>>1; for all odd i < w |
|
561 |
- |
|
562 |
-\ | /|\ | /|\ | /|\ | /|\ |
|
563 |
- \|/ | \|/ | \|/ | \|/ | |
|
564 |
- + | + | + | + | -3/8 |
|
565 |
- /|\ | /|\ | /|\ | /|\ | |
|
566 |
-/ | \|/ | \|/ | \|/ | \|/ |
|
567 |
- (| + (| + (| + (| + -1 |
|
568 |
-\ + /|\ + /|\ + /|\ + /|\ +1/4 |
|
569 |
- \|/ | \|/ | \|/ | \|/ | |
|
570 |
- + | + | + | + | +1/16 |
|
571 |
- /|\ | /|\ | /|\ | /|\ | |
|
572 |
-/ | \|/ | \|/ | \|/ | \|/ |
|
573 |
- | + | + | + | + +3/2 |
|
574 |
- |
|
575 |
-optimization tips: |
|
576 |
-following are exactly identical |
|
577 |
-(3a)>>1 == a + (a>>1) |
|
578 |
-(a + 4b + 8)>>4 == ((a>>2) + b + 2)>>2 |
|
579 |
- |
|
580 |
-16bit implementation note: |
|
581 |
-The IDWT can be implemented with 16bits, but this requires some care to |
|
582 |
-prevent overflows, the following list, lists the minimum number of bits needed |
|
583 |
-for some terms |
|
584 |
-1. lifting step |
|
585 |
-A= s[i-1] + s[i+1] 16bit |
|
586 |
-3*A + 4 18bit |
|
587 |
-A + (A>>1) + 2 17bit |
|
588 |
- |
|
589 |
-3. lifting step |
|
590 |
-s[i-1] + s[i+1] 17bit |
|
591 |
- |
|
592 |
-4. lifiting step |
|
593 |
-3*(s[i-1] + s[i+1]) 17bit |
|
594 |
- |
|
595 |
- |
|
596 |
-TODO: |
|
597 |
-===== |
|
598 |
-Important: |
|
599 |
-finetune initial contexts |
|
600 |
-flip wavelet? |
|
601 |
-try to use the wavelet transformed predicted image (motion compensated image) as context for coding the residual coefficients |
|
602 |
-try the MV length as context for coding the residual coefficients |
|
603 |
-use extradata for stuff which is in the keyframes now? |
|
604 |
-the MV median predictor is patented IIRC |
|
605 |
-implement per picture halfpel interpolation |
|
606 |
-try different range coder state transition tables for different contexts |
|
607 |
- |
|
608 |
-Not Important: |
|
609 |
-compare the 6 tap and 8 tap hpel filters (psnr/bitrate and subjective quality) |
|
610 |
-spatial_scalability b vs u (!= 0 breaks syntax anyway so we can add a u later) |
|
611 |
- |
|
612 |
- |
|
613 |
-Credits: |
|
614 |
-======== |
|
615 |
-Michael Niedermayer |
|
616 |
-Loren Merritt |
|
617 |
- |
|
618 |
- |
|
619 |
-Copyright: |
|
620 |
-========== |
|
621 |
-GPL + GFDL + whatever is needed to make this a RFC |
... | ... |
@@ -37,7 +37,6 @@ OBJS = allcodecs.o \ |
37 | 37 |
OBJS-$(CONFIG_AANDCTTABLES) += aandcttab.o |
38 | 38 |
OBJS-$(CONFIG_AC3DSP) += ac3dsp.o |
39 | 39 |
OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o |
40 |
-OBJS-$(CONFIG_DWT) += dwt.o |
|
41 | 40 |
OBJS-$(CONFIG_DXVA2) += dxva2.o |
42 | 41 |
OBJS-$(CONFIG_ENCODERS) += faandct.o jfdctfst.o jfdctint.o |
43 | 42 |
OBJS-$(CONFIG_ERROR_RESILIENCE) += error_resilience.o |
... | ... |
@@ -335,9 +334,6 @@ OBJS-$(CONFIG_SIPR_DECODER) += sipr.o acelp_pitch_delay.o \ |
335 | 335 |
OBJS-$(CONFIG_SMACKAUD_DECODER) += smacker.o |
336 | 336 |
OBJS-$(CONFIG_SMACKER_DECODER) += smacker.o |
337 | 337 |
OBJS-$(CONFIG_SMC_DECODER) += smc.o |
338 |
-OBJS-$(CONFIG_SNOW_DECODER) += snowdec.o snow.o |
|
339 |
-OBJS-$(CONFIG_SNOW_ENCODER) += snowenc.o snow.o \ |
|
340 |
- h263.o ituh263enc.o |
|
341 | 338 |
OBJS-$(CONFIG_SOL_DPCM_DECODER) += dpcm.o |
342 | 339 |
OBJS-$(CONFIG_SP5X_DECODER) += sp5xdec.o mjpegdec.o mjpeg.o |
343 | 340 |
OBJS-$(CONFIG_SRT_DECODER) += srtdec.o ass.o |
... | ... |
@@ -212,7 +212,6 @@ void avcodec_register_all(void) |
212 | 212 |
REGISTER_ENCDEC (SGI, sgi); |
213 | 213 |
REGISTER_DECODER(SMACKER, smacker); |
214 | 214 |
REGISTER_DECODER(SMC, smc); |
215 |
- REGISTER_ENCDEC (SNOW, snow); |
|
216 | 215 |
REGISTER_DECODER(SP5X, sp5x); |
217 | 216 |
REGISTER_ENCDEC (SUNRAST, sunrast); |
218 | 217 |
REGISTER_ENCDEC (SVQ1, svq1); |
... | ... |
@@ -152,7 +152,9 @@ enum AVCodecID { |
152 | 152 |
AV_CODEC_ID_MSZH, |
153 | 153 |
AV_CODEC_ID_ZLIB, |
154 | 154 |
AV_CODEC_ID_QTRLE, |
155 |
+#if FF_API_SNOW |
|
155 | 156 |
AV_CODEC_ID_SNOW, |
157 |
+#endif |
|
156 | 158 |
AV_CODEC_ID_TSCC, |
157 | 159 |
AV_CODEC_ID_ULTI, |
158 | 160 |
AV_CODEC_ID_QDRAW, |
... | ... |
@@ -518,7 +520,9 @@ enum Motion_Est_ID { |
518 | 518 |
ME_X1, ///< reserved for experiments |
519 | 519 |
ME_HEX, ///< hexagon based search |
520 | 520 |
ME_UMH, ///< uneven multi-hexagon search |
521 |
+#if FF_API_SNOW |
|
521 | 522 |
ME_ITER, ///< iterative search |
523 |
+#endif |
|
522 | 524 |
ME_TESA, ///< transformed exhaustive search algorithm |
523 | 525 |
}; |
524 | 526 |
|
... | ... |
@@ -1535,7 +1539,7 @@ typedef struct AVCodecContext { |
1535 | 1535 |
/** |
1536 | 1536 |
* Motion estimation algorithm used for video coding. |
1537 | 1537 |
* 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex), |
1538 |
- * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific] |
|
1538 |
+ * 8 (umh), 10 (tesa) [7, 8, 10 are x264 specific] |
|
1539 | 1539 |
* - encoding: MUST be set by user. |
1540 | 1540 |
* - decoding: unused |
1541 | 1541 |
*/ |
... | ... |
@@ -1758,8 +1762,10 @@ typedef struct AVCodecContext { |
1758 | 1758 |
#define FF_CMP_VSAD 8 |
1759 | 1759 |
#define FF_CMP_VSSE 9 |
1760 | 1760 |
#define FF_CMP_NSSE 10 |
1761 |
+#if FF_API_SNOW |
|
1761 | 1762 |
#define FF_CMP_W53 11 |
1762 | 1763 |
#define FF_CMP_W97 12 |
1764 |
+#endif |
|
1763 | 1765 |
#define FF_CMP_DCTMAX 13 |
1764 | 1766 |
#define FF_CMP_DCT264 14 |
1765 | 1767 |
#define FF_CMP_CHROMA 256 |
... | ... |
@@ -419,13 +419,6 @@ static const AVCodecDescriptor codec_descriptors[] = { |
419 | 419 |
.props = AV_CODEC_PROP_LOSSLESS, |
420 | 420 |
}, |
421 | 421 |
{ |
422 |
- .id = AV_CODEC_ID_SNOW, |
|
423 |
- .type = AVMEDIA_TYPE_VIDEO, |
|
424 |
- .name = "snow", |
|
425 |
- .long_name = NULL_IF_CONFIG_SMALL("Snow"), |
|
426 |
- .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_LOSSLESS, |
|
427 |
- }, |
|
428 |
- { |
|
429 | 422 |
.id = AV_CODEC_ID_TSCC, |
430 | 423 |
.type = AVMEDIA_TYPE_VIDEO, |
431 | 424 |
.name = "tscc", |
... | ... |
@@ -1784,14 +1784,6 @@ void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){ |
1784 | 1784 |
case FF_CMP_NSSE: |
1785 | 1785 |
cmp[i]= c->nsse[i]; |
1786 | 1786 |
break; |
1787 |
-#if CONFIG_DWT |
|
1788 |
- case FF_CMP_W53: |
|
1789 |
- cmp[i]= c->w53[i]; |
|
1790 |
- break; |
|
1791 |
- case FF_CMP_W97: |
|
1792 |
- cmp[i]= c->w97[i]; |
|
1793 |
- break; |
|
1794 |
-#endif |
|
1795 | 1787 |
default: |
1796 | 1788 |
av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n"); |
1797 | 1789 |
} |
... | ... |
@@ -2820,9 +2812,6 @@ av_cold void ff_dsputil_init(DSPContext* c, AVCodecContext *avctx) |
2820 | 2820 |
c->vsse[5]= vsse_intra8_c; |
2821 | 2821 |
c->nsse[0]= nsse16_c; |
2822 | 2822 |
c->nsse[1]= nsse8_c; |
2823 |
-#if CONFIG_DWT |
|
2824 |
- ff_dsputil_init_dwt(c); |
|
2825 |
-#endif |
|
2826 | 2823 |
|
2827 | 2824 |
c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c; |
2828 | 2825 |
|
... | ... |
@@ -231,8 +231,6 @@ typedef struct DSPContext { |
231 | 231 |
me_cmp_func vsad[6]; |
232 | 232 |
me_cmp_func vsse[6]; |
233 | 233 |
me_cmp_func nsse[6]; |
234 |
- me_cmp_func w53[6]; |
|
235 |
- me_cmp_func w97[6]; |
|
236 | 234 |
me_cmp_func dct_max[6]; |
237 | 235 |
me_cmp_func dct264_sad[6]; |
238 | 236 |
|
... | ... |
@@ -543,10 +541,6 @@ static inline int get_penalty_factor(int lambda, int lambda2, int type){ |
543 | 543 |
return lambda>>FF_LAMBDA_SHIFT; |
544 | 544 |
case FF_CMP_DCT: |
545 | 545 |
return (3*lambda)>>(FF_LAMBDA_SHIFT+1); |
546 |
- case FF_CMP_W53: |
|
547 |
- return (4*lambda)>>(FF_LAMBDA_SHIFT); |
|
548 |
- case FF_CMP_W97: |
|
549 |
- return (2*lambda)>>(FF_LAMBDA_SHIFT); |
|
550 | 546 |
case FF_CMP_SATD: |
551 | 547 |
case FF_CMP_DCT264: |
552 | 548 |
return (2*lambda)>>FF_LAMBDA_SHIFT; |
... | ... |
@@ -568,8 +562,6 @@ void ff_dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx); |
568 | 568 |
void ff_dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx); |
569 | 569 |
void ff_dsputil_init_vis(DSPContext* c, AVCodecContext *avctx); |
570 | 570 |
|
571 |
-void ff_dsputil_init_dwt(DSPContext *c); |
|
572 |
- |
|
573 | 571 |
#if (ARCH_ARM && HAVE_NEON) || ARCH_PPC || HAVE_MMX |
574 | 572 |
# define STRIDE_ALIGN 16 |
575 | 573 |
#else |
576 | 574 |
deleted file mode 100644 |
... | ... |
@@ -1,861 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at> |
|
3 |
- * |
|
4 |
- * This file is part of Libav. |
|
5 |
- * |
|
6 |
- * Libav 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.1 of the License, or (at your option) any later version. |
|
10 |
- * |
|
11 |
- * Libav 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 Libav; if not, write to the Free Software |
|
18 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
- */ |
|
20 |
- |
|
21 |
-#include "libavutil/attributes.h" |
|
22 |
-#include "libavutil/common.h" |
|
23 |
-#include "dsputil.h" |
|
24 |
-#include "dwt.h" |
|
25 |
- |
|
26 |
-int ff_slice_buffer_init(slice_buffer *buf, int line_count, |
|
27 |
- int max_allocated_lines, int line_width, |
|
28 |
- IDWTELEM *base_buffer) |
|
29 |
-{ |
|
30 |
- int i; |
|
31 |
- |
|
32 |
- buf->base_buffer = base_buffer; |
|
33 |
- buf->line_count = line_count; |
|
34 |
- buf->line_width = line_width; |
|
35 |
- buf->data_count = max_allocated_lines; |
|
36 |
- buf->line = av_mallocz(sizeof(IDWTELEM *) * line_count); |
|
37 |
- if (!buf->line) |
|
38 |
- return AVERROR(ENOMEM); |
|
39 |
- buf->data_stack = av_malloc(sizeof(IDWTELEM *) * max_allocated_lines); |
|
40 |
- if (!buf->data_stack) { |
|
41 |
- av_free(buf->line); |
|
42 |
- return AVERROR(ENOMEM); |
|
43 |
- } |
|
44 |
- |
|
45 |
- for (i = 0; i < max_allocated_lines; i++) { |
|
46 |
- buf->data_stack[i] = av_malloc(sizeof(IDWTELEM) * line_width); |
|
47 |
- if (!buf->data_stack[i]) { |
|
48 |
- for (i--; i >=0; i--) |
|
49 |
- av_free(buf->data_stack[i]); |
|
50 |
- av_free(buf->data_stack); |
|
51 |
- av_free(buf->line); |
|
52 |
- return AVERROR(ENOMEM); |
|
53 |
- } |
|
54 |
- } |
|
55 |
- |
|
56 |
- buf->data_stack_top = max_allocated_lines - 1; |
|
57 |
- return 0; |
|
58 |
-} |
|
59 |
- |
|
60 |
-IDWTELEM *ff_slice_buffer_load_line(slice_buffer *buf, int line) |
|
61 |
-{ |
|
62 |
- IDWTELEM *buffer; |
|
63 |
- |
|
64 |
- assert(buf->data_stack_top >= 0); |
|
65 |
-// assert(!buf->line[line]); |
|
66 |
- if (buf->line[line]) |
|
67 |
- return buf->line[line]; |
|
68 |
- |
|
69 |
- buffer = buf->data_stack[buf->data_stack_top]; |
|
70 |
- buf->data_stack_top--; |
|
71 |
- buf->line[line] = buffer; |
|
72 |
- |
|
73 |
- return buffer; |
|
74 |
-} |
|
75 |
- |
|
76 |
-void ff_slice_buffer_release(slice_buffer *buf, int line) |
|
77 |
-{ |
|
78 |
- IDWTELEM *buffer; |
|
79 |
- |
|
80 |
- assert(line >= 0 && line < buf->line_count); |
|
81 |
- assert(buf->line[line]); |
|
82 |
- |
|
83 |
- buffer = buf->line[line]; |
|
84 |
- buf->data_stack_top++; |
|
85 |
- buf->data_stack[buf->data_stack_top] = buffer; |
|
86 |
- buf->line[line] = NULL; |
|
87 |
-} |
|
88 |
- |
|
89 |
-void ff_slice_buffer_flush(slice_buffer *buf) |
|
90 |
-{ |
|
91 |
- int i; |
|
92 |
- for (i = 0; i < buf->line_count; i++) |
|
93 |
- if (buf->line[i]) |
|
94 |
- ff_slice_buffer_release(buf, i); |
|
95 |
-} |
|
96 |
- |
|
97 |
-void ff_slice_buffer_destroy(slice_buffer *buf) |
|
98 |
-{ |
|
99 |
- int i; |
|
100 |
- ff_slice_buffer_flush(buf); |
|
101 |
- |
|
102 |
- for (i = buf->data_count - 1; i >= 0; i--) |
|
103 |
- av_freep(&buf->data_stack[i]); |
|
104 |
- av_freep(&buf->data_stack); |
|
105 |
- av_freep(&buf->line); |
|
106 |
-} |
|
107 |
- |
|
108 |
-static inline int mirror(int v, int m) |
|
109 |
-{ |
|
110 |
- while ((unsigned)v > (unsigned)m) { |
|
111 |
- v = -v; |
|
112 |
- if (v < 0) |
|
113 |
- v += 2 * m; |
|
114 |
- } |
|
115 |
- return v; |
|
116 |
-} |
|
117 |
- |
|
118 |
-static av_always_inline void lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, |
|
119 |
- int dst_step, int src_step, int ref_step, |
|
120 |
- int width, int mul, int add, int shift, |
|
121 |
- int highpass, int inverse) |
|
122 |
-{ |
|
123 |
- const int mirror_left = !highpass; |
|
124 |
- const int mirror_right = (width & 1) ^ highpass; |
|
125 |
- const int w = (width >> 1) - 1 + (highpass & width); |
|
126 |
- int i; |
|
127 |
- |
|
128 |
-#define LIFT(src, ref, inv) ((src) + ((inv) ? -(ref) : +(ref))) |
|
129 |
- if (mirror_left) { |
|
130 |
- dst[0] = LIFT(src[0], ((mul * 2 * ref[0] + add) >> shift), inverse); |
|
131 |
- dst += dst_step; |
|
132 |
- src += src_step; |
|
133 |
- } |
|
134 |
- |
|
135 |
- for (i = 0; i < w; i++) |
|
136 |
- dst[i * dst_step] = LIFT(src[i * src_step], |
|
137 |
- ((mul * (ref[i * ref_step] + |
|
138 |
- ref[(i + 1) * ref_step]) + |
|
139 |
- add) >> shift), |
|
140 |
- inverse); |
|
141 |
- |
|
142 |
- if (mirror_right) |
|
143 |
- dst[w * dst_step] = LIFT(src[w * src_step], |
|
144 |
- ((mul * 2 * ref[w * ref_step] + add) >> shift), |
|
145 |
- inverse); |
|
146 |
-} |
|
147 |
- |
|
148 |
-static av_always_inline void liftS(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, |
|
149 |
- int dst_step, int src_step, int ref_step, |
|
150 |
- int width, int mul, int add, int shift, |
|
151 |
- int highpass, int inverse) |
|
152 |
-{ |
|
153 |
- const int mirror_left = !highpass; |
|
154 |
- const int mirror_right = (width & 1) ^ highpass; |
|
155 |
- const int w = (width >> 1) - 1 + (highpass & width); |
|
156 |
- int i; |
|
157 |
- |
|
158 |
- assert(shift == 4); |
|
159 |
-#define LIFTS(src, ref, inv) \ |
|
160 |
- ((inv) ? (src) + (((ref) + 4 * (src)) >> shift) \ |
|
161 |
- : -((-16 * (src) + (ref) + add / \ |
|
162 |
- 4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23))) |
|
163 |
- if (mirror_left) { |
|
164 |
- dst[0] = LIFTS(src[0], mul * 2 * ref[0] + add, inverse); |
|
165 |
- dst += dst_step; |
|
166 |
- src += src_step; |
|
167 |
- } |
|
168 |
- |
|
169 |
- for (i = 0; i < w; i++) |
|
170 |
- dst[i * dst_step] = LIFTS(src[i * src_step], |
|
171 |
- mul * (ref[i * ref_step] + |
|
172 |
- ref[(i + 1) * ref_step]) + add, |
|
173 |
- inverse); |
|
174 |
- |
|
175 |
- if (mirror_right) |
|
176 |
- dst[w * dst_step] = LIFTS(src[w * src_step], |
|
177 |
- mul * 2 * ref[w * ref_step] + add, |
|
178 |
- inverse); |
|
179 |
-} |
|
180 |
- |
|
181 |
-static void horizontal_decompose53i(DWTELEM *b, DWTELEM *temp, int width) |
|
182 |
-{ |
|
183 |
- const int width2 = width >> 1; |
|
184 |
- int x; |
|
185 |
- const int w2 = (width + 1) >> 1; |
|
186 |
- |
|
187 |
- for (x = 0; x < width2; x++) { |
|
188 |
- temp[x] = b[2 * x]; |
|
189 |
- temp[x + w2] = b[2 * x + 1]; |
|
190 |
- } |
|
191 |
- if (width & 1) |
|
192 |
- temp[x] = b[2 * x]; |
|
193 |
- lift(b + w2, temp + w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0); |
|
194 |
- lift(b, temp, b + w2, 1, 1, 1, width, 1, 2, 2, 0, 0); |
|
195 |
-} |
|
196 |
- |
|
197 |
-static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, |
|
198 |
- int width) |
|
199 |
-{ |
|
200 |
- int i; |
|
201 |
- |
|
202 |
- for (i = 0; i < width; i++) |
|
203 |
- b1[i] -= (b0[i] + b2[i]) >> 1; |
|
204 |
-} |
|
205 |
- |
|
206 |
-static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, |
|
207 |
- int width) |
|
208 |
-{ |
|
209 |
- int i; |
|
210 |
- |
|
211 |
- for (i = 0; i < width; i++) |
|
212 |
- b1[i] += (b0[i] + b2[i] + 2) >> 2; |
|
213 |
-} |
|
214 |
- |
|
215 |
-static void spatial_decompose53i(DWTELEM *buffer, DWTELEM *temp, |
|
216 |
- int width, int height, int stride) |
|
217 |
-{ |
|
218 |
- int y; |
|
219 |
- DWTELEM *b0 = buffer + mirror(-2 - 1, height - 1) * stride; |
|
220 |
- DWTELEM *b1 = buffer + mirror(-2, height - 1) * stride; |
|
221 |
- |
|
222 |
- for (y = -2; y < height; y += 2) { |
|
223 |
- DWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride; |
|
224 |
- DWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride; |
|
225 |
- |
|
226 |
- if (y + 1 < (unsigned)height) |
|
227 |
- horizontal_decompose53i(b2, temp, width); |
|
228 |
- if (y + 2 < (unsigned)height) |
|
229 |
- horizontal_decompose53i(b3, temp, width); |
|
230 |
- |
|
231 |
- if (y + 1 < (unsigned)height) |
|
232 |
- vertical_decompose53iH0(b1, b2, b3, width); |
|
233 |
- if (y + 0 < (unsigned)height) |
|
234 |
- vertical_decompose53iL0(b0, b1, b2, width); |
|
235 |
- |
|
236 |
- b0 = b2; |
|
237 |
- b1 = b3; |
|
238 |
- } |
|
239 |
-} |
|
240 |
- |
|
241 |
-static void horizontal_decompose97i(DWTELEM *b, DWTELEM *temp, int width) |
|
242 |
-{ |
|
243 |
- const int w2 = (width + 1) >> 1; |
|
244 |
- |
|
245 |
- lift(temp + w2, b + 1, b, 1, 2, 2, width, W_AM, W_AO, W_AS, 1, 1); |
|
246 |
- liftS(temp, b, temp + w2, 1, 2, 1, width, W_BM, W_BO, W_BS, 0, 0); |
|
247 |
- lift(b + w2, temp + w2, temp, 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0); |
|
248 |
- lift(b, temp, b + w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 0); |
|
249 |
-} |
|
250 |
- |
|
251 |
-static void vertical_decompose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, |
|
252 |
- int width) |
|
253 |
-{ |
|
254 |
- int i; |
|
255 |
- |
|
256 |
- for (i = 0; i < width; i++) |
|
257 |
- b1[i] -= (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS; |
|
258 |
-} |
|
259 |
- |
|
260 |
-static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, |
|
261 |
- int width) |
|
262 |
-{ |
|
263 |
- int i; |
|
264 |
- |
|
265 |
- for (i = 0; i < width; i++) |
|
266 |
- b1[i] += (W_CM * (b0[i] + b2[i]) + W_CO) >> W_CS; |
|
267 |
-} |
|
268 |
- |
|
269 |
-static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, |
|
270 |
- int width) |
|
271 |
-{ |
|
272 |
- int i; |
|
273 |
- |
|
274 |
- for (i = 0; i < width; i++) |
|
275 |
- b1[i] = (16 * 4 * b1[i] - 4 * (b0[i] + b2[i]) + W_BO * 5 + (5 << 27)) / |
|
276 |
- (5 * 16) - (1 << 23); |
|
277 |
-} |
|
278 |
- |
|
279 |
-static void vertical_decompose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, |
|
280 |
- int width) |
|
281 |
-{ |
|
282 |
- int i; |
|
283 |
- |
|
284 |
- for (i = 0; i < width; i++) |
|
285 |
- b1[i] += (W_DM * (b0[i] + b2[i]) + W_DO) >> W_DS; |
|
286 |
-} |
|
287 |
- |
|
288 |
-static void spatial_decompose97i(DWTELEM *buffer, DWTELEM *temp, |
|
289 |
- int width, int height, int stride) |
|
290 |
-{ |
|
291 |
- int y; |
|
292 |
- DWTELEM *b0 = buffer + mirror(-4 - 1, height - 1) * stride; |
|
293 |
- DWTELEM *b1 = buffer + mirror(-4, height - 1) * stride; |
|
294 |
- DWTELEM *b2 = buffer + mirror(-4 + 1, height - 1) * stride; |
|
295 |
- DWTELEM *b3 = buffer + mirror(-4 + 2, height - 1) * stride; |
|
296 |
- |
|
297 |
- for (y = -4; y < height; y += 2) { |
|
298 |
- DWTELEM *b4 = buffer + mirror(y + 3, height - 1) * stride; |
|
299 |
- DWTELEM *b5 = buffer + mirror(y + 4, height - 1) * stride; |
|
300 |
- |
|
301 |
- if (y + 3 < (unsigned)height) |
|
302 |
- horizontal_decompose97i(b4, temp, width); |
|
303 |
- if (y + 4 < (unsigned)height) |
|
304 |
- horizontal_decompose97i(b5, temp, width); |
|
305 |
- |
|
306 |
- if (y + 3 < (unsigned)height) |
|
307 |
- vertical_decompose97iH0(b3, b4, b5, width); |
|
308 |
- if (y + 2 < (unsigned)height) |
|
309 |
- vertical_decompose97iL0(b2, b3, b4, width); |
|
310 |
- if (y + 1 < (unsigned)height) |
|
311 |
- vertical_decompose97iH1(b1, b2, b3, width); |
|
312 |
- if (y + 0 < (unsigned)height) |
|
313 |
- vertical_decompose97iL1(b0, b1, b2, width); |
|
314 |
- |
|
315 |
- b0 = b2; |
|
316 |
- b1 = b3; |
|
317 |
- b2 = b4; |
|
318 |
- b3 = b5; |
|
319 |
- } |
|
320 |
-} |
|
321 |
- |
|
322 |
-void ff_spatial_dwt(DWTELEM *buffer, DWTELEM *temp, int width, int height, |
|
323 |
- int stride, int type, int decomposition_count) |
|
324 |
-{ |
|
325 |
- int level; |
|
326 |
- |
|
327 |
- for (level = 0; level < decomposition_count; level++) { |
|
328 |
- switch (type) { |
|
329 |
- case DWT_97: |
|
330 |
- spatial_decompose97i(buffer, temp, |
|
331 |
- width >> level, height >> level, |
|
332 |
- stride << level); |
|
333 |
- break; |
|
334 |
- case DWT_53: |
|
335 |
- spatial_decompose53i(buffer, temp, |
|
336 |
- width >> level, height >> level, |
|
337 |
- stride << level); |
|
338 |
- break; |
|
339 |
- } |
|
340 |
- } |
|
341 |
-} |
|
342 |
- |
|
343 |
-static void horizontal_compose53i(IDWTELEM *b, IDWTELEM *temp, int width) |
|
344 |
-{ |
|
345 |
- const int width2 = width >> 1; |
|
346 |
- const int w2 = (width + 1) >> 1; |
|
347 |
- int x; |
|
348 |
- |
|
349 |
- for (x = 0; x < width2; x++) { |
|
350 |
- temp[2 * x] = b[x]; |
|
351 |
- temp[2 * x + 1] = b[x + w2]; |
|
352 |
- } |
|
353 |
- if (width & 1) |
|
354 |
- temp[2 * x] = b[x]; |
|
355 |
- |
|
356 |
- b[0] = temp[0] - ((temp[1] + 1) >> 1); |
|
357 |
- for (x = 2; x < width - 1; x += 2) { |
|
358 |
- b[x] = temp[x] - ((temp[x - 1] + temp[x + 1] + 2) >> 2); |
|
359 |
- b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1); |
|
360 |
- } |
|
361 |
- if (width & 1) { |
|
362 |
- b[x] = temp[x] - ((temp[x - 1] + 1) >> 1); |
|
363 |
- b[x - 1] = temp[x - 1] + ((b[x - 2] + b[x] + 1) >> 1); |
|
364 |
- } else |
|
365 |
- b[x - 1] = temp[x - 1] + b[x - 2]; |
|
366 |
-} |
|
367 |
- |
|
368 |
-static void vertical_compose53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, |
|
369 |
- int width) |
|
370 |
-{ |
|
371 |
- int i; |
|
372 |
- |
|
373 |
- for (i = 0; i < width; i++) |
|
374 |
- b1[i] += (b0[i] + b2[i]) >> 1; |
|
375 |
-} |
|
376 |
- |
|
377 |
-static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, |
|
378 |
- int width) |
|
379 |
-{ |
|
380 |
- int i; |
|
381 |
- |
|
382 |
- for (i = 0; i < width; i++) |
|
383 |
- b1[i] -= (b0[i] + b2[i] + 2) >> 2; |
|
384 |
-} |
|
385 |
- |
|
386 |
-static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer *sb, |
|
387 |
- int height, int stride_line) |
|
388 |
-{ |
|
389 |
- cs->b0 = slice_buffer_get_line(sb, |
|
390 |
- mirror(-1 - 1, height - 1) * stride_line); |
|
391 |
- cs->b1 = slice_buffer_get_line(sb, mirror(-1, height - 1) * stride_line); |
|
392 |
- cs->y = -1; |
|
393 |
-} |
|
394 |
- |
|
395 |
-static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer, |
|
396 |
- int height, int stride) |
|
397 |
-{ |
|
398 |
- cs->b0 = buffer + mirror(-1 - 1, height - 1) * stride; |
|
399 |
- cs->b1 = buffer + mirror(-1, height - 1) * stride; |
|
400 |
- cs->y = -1; |
|
401 |
-} |
|
402 |
- |
|
403 |
-static void spatial_compose53i_dy_buffered(DWTCompose *cs, slice_buffer *sb, |
|
404 |
- IDWTELEM *temp, |
|
405 |
- int width, int height, |
|
406 |
- int stride_line) |
|
407 |
-{ |
|
408 |
- int y = cs->y; |
|
409 |
- |
|
410 |
- IDWTELEM *b0 = cs->b0; |
|
411 |
- IDWTELEM *b1 = cs->b1; |
|
412 |
- IDWTELEM *b2 = slice_buffer_get_line(sb, |
|
413 |
- mirror(y + 1, height - 1) * |
|
414 |
- stride_line); |
|
415 |
- IDWTELEM *b3 = slice_buffer_get_line(sb, |
|
416 |
- mirror(y + 2, height - 1) * |
|
417 |
- stride_line); |
|
418 |
- |
|
419 |
- if (y + 1 < (unsigned)height && y < (unsigned)height) { |
|
420 |
- int x; |
|
421 |
- |
|
422 |
- for (x = 0; x < width; x++) { |
|
423 |
- b2[x] -= (b1[x] + b3[x] + 2) >> 2; |
|
424 |
- b1[x] += (b0[x] + b2[x]) >> 1; |
|
425 |
- } |
|
426 |
- } else { |
|
427 |
- if (y + 1 < (unsigned)height) |
|
428 |
- vertical_compose53iL0(b1, b2, b3, width); |
|
429 |
- if (y + 0 < (unsigned)height) |
|
430 |
- vertical_compose53iH0(b0, b1, b2, width); |
|
431 |
- } |
|
432 |
- |
|
433 |
- if (y - 1 < (unsigned)height) |
|
434 |
- horizontal_compose53i(b0, temp, width); |
|
435 |
- if (y + 0 < (unsigned)height) |
|
436 |
- horizontal_compose53i(b1, temp, width); |
|
437 |
- |
|
438 |
- cs->b0 = b2; |
|
439 |
- cs->b1 = b3; |
|
440 |
- cs->y += 2; |
|
441 |
-} |
|
442 |
- |
|
443 |
-static void spatial_compose53i_dy(DWTCompose *cs, IDWTELEM *buffer, |
|
444 |
- IDWTELEM *temp, int width, int height, |
|
445 |
- int stride) |
|
446 |
-{ |
|
447 |
- int y = cs->y; |
|
448 |
- IDWTELEM *b0 = cs->b0; |
|
449 |
- IDWTELEM *b1 = cs->b1; |
|
450 |
- IDWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride; |
|
451 |
- IDWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride; |
|
452 |
- |
|
453 |
- if (y + 1 < (unsigned)height) |
|
454 |
- vertical_compose53iL0(b1, b2, b3, width); |
|
455 |
- if (y + 0 < (unsigned)height) |
|
456 |
- vertical_compose53iH0(b0, b1, b2, width); |
|
457 |
- |
|
458 |
- if (y - 1 < (unsigned)height) |
|
459 |
- horizontal_compose53i(b0, temp, width); |
|
460 |
- if (y + 0 < (unsigned)height) |
|
461 |
- horizontal_compose53i(b1, temp, width); |
|
462 |
- |
|
463 |
- cs->b0 = b2; |
|
464 |
- cs->b1 = b3; |
|
465 |
- cs->y += 2; |
|
466 |
-} |
|
467 |
- |
|
468 |
-void ff_snow_horizontal_compose97i(IDWTELEM *b, IDWTELEM *temp, int width) |
|
469 |
-{ |
|
470 |
- const int w2 = (width + 1) >> 1; |
|
471 |
- int x; |
|
472 |
- |
|
473 |
- temp[0] = b[0] - ((3 * b[w2] + 2) >> 2); |
|
474 |
- for (x = 1; x < (width >> 1); x++) { |
|
475 |
- temp[2 * x] = b[x] - ((3 * (b[x + w2 - 1] + b[x + w2]) + 4) >> 3); |
|
476 |
- temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x]; |
|
477 |
- } |
|
478 |
- if (width & 1) { |
|
479 |
- temp[2 * x] = b[x] - ((3 * b[x + w2 - 1] + 2) >> 2); |
|
480 |
- temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x]; |
|
481 |
- } else |
|
482 |
- temp[2 * x - 1] = b[x + w2 - 1] - 2 * temp[2 * x - 2]; |
|
483 |
- |
|
484 |
- b[0] = temp[0] + ((2 * temp[0] + temp[1] + 4) >> 3); |
|
485 |
- for (x = 2; x < width - 1; x += 2) { |
|
486 |
- b[x] = temp[x] + ((4 * temp[x] + temp[x - 1] + temp[x + 1] + 8) >> 4); |
|
487 |
- b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1); |
|
488 |
- } |
|
489 |
- if (width & 1) { |
|
490 |
- b[x] = temp[x] + ((2 * temp[x] + temp[x - 1] + 4) >> 3); |
|
491 |
- b[x - 1] = temp[x - 1] + ((3 * (b[x - 2] + b[x])) >> 1); |
|
492 |
- } else |
|
493 |
- b[x - 1] = temp[x - 1] + 3 * b[x - 2]; |
|
494 |
-} |
|
495 |
- |
|
496 |
-static void vertical_compose97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, |
|
497 |
- int width) |
|
498 |
-{ |
|
499 |
- int i; |
|
500 |
- |
|
501 |
- for (i = 0; i < width; i++) |
|
502 |
- b1[i] += (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS; |
|
503 |
-} |
|
504 |
- |
|
505 |
-static void vertical_compose97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, |
|
506 |
- int width) |
|
507 |
-{ |
|
508 |
- int i; |
|
509 |
- |
|
510 |
- for (i = 0; i < width; i++) |
|
511 |
- b1[i] -= (W_CM * (b0[i] + b2[i]) + W_CO) >> W_CS; |
|
512 |
-} |
|
513 |
- |
|
514 |
-static void vertical_compose97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, |
|
515 |
- int width) |
|
516 |
-{ |
|
517 |
- int i; |
|
518 |
- |
|
519 |
- for (i = 0; i < width; i++) |
|
520 |
- b1[i] += (W_BM * (b0[i] + b2[i]) + 4 * b1[i] + W_BO) >> W_BS; |
|
521 |
-} |
|
522 |
- |
|
523 |
-static void vertical_compose97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, |
|
524 |
- int width) |
|
525 |
-{ |
|
526 |
- int i; |
|
527 |
- |
|
528 |
- for (i = 0; i < width; i++) |
|
529 |
- b1[i] -= (W_DM * (b0[i] + b2[i]) + W_DO) >> W_DS; |
|
530 |
-} |
|
531 |
- |
|
532 |
-void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, |
|
533 |
- IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, |
|
534 |
- int width) |
|
535 |
-{ |
|
536 |
- int i; |
|
537 |
- |
|
538 |
- for (i = 0; i < width; i++) { |
|
539 |
- b4[i] -= (W_DM * (b3[i] + b5[i]) + W_DO) >> W_DS; |
|
540 |
- b3[i] -= (W_CM * (b2[i] + b4[i]) + W_CO) >> W_CS; |
|
541 |
- b2[i] += (W_BM * (b1[i] + b3[i]) + 4 * b2[i] + W_BO) >> W_BS; |
|
542 |
- b1[i] += (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS; |
|
543 |
- } |
|
544 |
-} |
|
545 |
- |
|
546 |
-static void spatial_compose97i_buffered_init(DWTCompose *cs, slice_buffer *sb, |
|
547 |
- int height, int stride_line) |
|
548 |
-{ |
|
549 |
- cs->b0 = slice_buffer_get_line(sb, mirror(-3 - 1, height - 1) * stride_line); |
|
550 |
- cs->b1 = slice_buffer_get_line(sb, mirror(-3, height - 1) * stride_line); |
|
551 |
- cs->b2 = slice_buffer_get_line(sb, mirror(-3 + 1, height - 1) * stride_line); |
|
552 |
- cs->b3 = slice_buffer_get_line(sb, mirror(-3 + 2, height - 1) * stride_line); |
|
553 |
- cs->y = -3; |
|
554 |
-} |
|
555 |
- |
|
556 |
-static void spatial_compose97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, |
|
557 |
- int stride) |
|
558 |
-{ |
|
559 |
- cs->b0 = buffer + mirror(-3 - 1, height - 1) * stride; |
|
560 |
- cs->b1 = buffer + mirror(-3, height - 1) * stride; |
|
561 |
- cs->b2 = buffer + mirror(-3 + 1, height - 1) * stride; |
|
562 |
- cs->b3 = buffer + mirror(-3 + 2, height - 1) * stride; |
|
563 |
- cs->y = -3; |
|
564 |
-} |
|
565 |
- |
|
566 |
-static void spatial_compose97i_dy_buffered(DWTContext *dsp, DWTCompose *cs, |
|
567 |
- slice_buffer * sb, IDWTELEM *temp, |
|
568 |
- int width, int height, |
|
569 |
- int stride_line) |
|
570 |
-{ |
|
571 |
- int y = cs->y; |
|
572 |
- |
|
573 |
- IDWTELEM *b0 = cs->b0; |
|
574 |
- IDWTELEM *b1 = cs->b1; |
|
575 |
- IDWTELEM *b2 = cs->b2; |
|
576 |
- IDWTELEM *b3 = cs->b3; |
|
577 |
- IDWTELEM *b4 = slice_buffer_get_line(sb, |
|
578 |
- mirror(y + 3, height - 1) * |
|
579 |
- stride_line); |
|
580 |
- IDWTELEM *b5 = slice_buffer_get_line(sb, |
|
581 |
- mirror(y + 4, height - 1) * |
|
582 |
- stride_line); |
|
583 |
- |
|
584 |
- if (y > 0 && y + 4 < height) { |
|
585 |
- dsp->vertical_compose97i(b0, b1, b2, b3, b4, b5, width); |
|
586 |
- } else { |
|
587 |
- if (y + 3 < (unsigned)height) |
|
588 |
- vertical_compose97iL1(b3, b4, b5, width); |
|
589 |
- if (y + 2 < (unsigned)height) |
|
590 |
- vertical_compose97iH1(b2, b3, b4, width); |
|
591 |
- if (y + 1 < (unsigned)height) |
|
592 |
- vertical_compose97iL0(b1, b2, b3, width); |
|
593 |
- if (y + 0 < (unsigned)height) |
|
594 |
- vertical_compose97iH0(b0, b1, b2, width); |
|
595 |
- } |
|
596 |
- |
|
597 |
- if (y - 1 < (unsigned)height) |
|
598 |
- dsp->horizontal_compose97i(b0, temp, width); |
|
599 |
- if (y + 0 < (unsigned)height) |
|
600 |
- dsp->horizontal_compose97i(b1, temp, width); |
|
601 |
- |
|
602 |
- cs->b0 = b2; |
|
603 |
- cs->b1 = b3; |
|
604 |
- cs->b2 = b4; |
|
605 |
- cs->b3 = b5; |
|
606 |
- cs->y += 2; |
|
607 |
-} |
|
608 |
- |
|
609 |
-static void spatial_compose97i_dy(DWTCompose *cs, IDWTELEM *buffer, |
|
610 |
- IDWTELEM *temp, int width, int height, |
|
611 |
- int stride) |
|
612 |
-{ |
|
613 |
- int y = cs->y; |
|
614 |
- IDWTELEM *b0 = cs->b0; |
|
615 |
- IDWTELEM *b1 = cs->b1; |
|
616 |
- IDWTELEM *b2 = cs->b2; |
|
617 |
- IDWTELEM *b3 = cs->b3; |
|
618 |
- IDWTELEM *b4 = buffer + mirror(y + 3, height - 1) * stride; |
|
619 |
- IDWTELEM *b5 = buffer + mirror(y + 4, height - 1) * stride; |
|
620 |
- |
|
621 |
- if (y + 3 < (unsigned)height) |
|
622 |
- vertical_compose97iL1(b3, b4, b5, width); |
|
623 |
- if (y + 2 < (unsigned)height) |
|
624 |
- vertical_compose97iH1(b2, b3, b4, width); |
|
625 |
- if (y + 1 < (unsigned)height) |
|
626 |
- vertical_compose97iL0(b1, b2, b3, width); |
|
627 |
- if (y + 0 < (unsigned)height) |
|
628 |
- vertical_compose97iH0(b0, b1, b2, width); |
|
629 |
- |
|
630 |
- if (y - 1 < (unsigned)height) |
|
631 |
- ff_snow_horizontal_compose97i(b0, temp, width); |
|
632 |
- if (y + 0 < (unsigned)height) |
|
633 |
- ff_snow_horizontal_compose97i(b1, temp, width); |
|
634 |
- |
|
635 |
- cs->b0 = b2; |
|
636 |
- cs->b1 = b3; |
|
637 |
- cs->b2 = b4; |
|
638 |
- cs->b3 = b5; |
|
639 |
- cs->y += 2; |
|
640 |
-} |
|
641 |
- |
|
642 |
-void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width, |
|
643 |
- int height, int stride_line, int type, |
|
644 |
- int decomposition_count) |
|
645 |
-{ |
|
646 |
- int level; |
|
647 |
- for (level = decomposition_count - 1; level >= 0; level--) { |
|
648 |
- switch (type) { |
|
649 |
- case DWT_97: |
|
650 |
- spatial_compose97i_buffered_init(cs + level, sb, height >> level, |
|
651 |
- stride_line << level); |
|
652 |
- break; |
|
653 |
- case DWT_53: |
|
654 |
- spatial_compose53i_buffered_init(cs + level, sb, height >> level, |
|
655 |
- stride_line << level); |
|
656 |
- break; |
|
657 |
- } |
|
658 |
- } |
|
659 |
-} |
|
660 |
- |
|
661 |
-void ff_spatial_idwt_buffered_slice(DWTContext *dsp, DWTCompose *cs, |
|
662 |
- slice_buffer *slice_buf, IDWTELEM *temp, |
|
663 |
- int width, int height, int stride_line, |
|
664 |
- int type, int decomposition_count, int y) |
|
665 |
-{ |
|
666 |
- const int support = type == 1 ? 3 : 5; |
|
667 |
- int level; |
|
668 |
- if (type == 2) |
|
669 |
- return; |
|
670 |
- |
|
671 |
- for (level = decomposition_count - 1; level >= 0; level--) |
|
672 |
- while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) { |
|
673 |
- switch (type) { |
|
674 |
- case DWT_97: |
|
675 |
- spatial_compose97i_dy_buffered(dsp, cs + level, slice_buf, temp, |
|
676 |
- width >> level, |
|
677 |
- height >> level, |
|
678 |
- stride_line << level); |
|
679 |
- break; |
|
680 |
- case DWT_53: |
|
681 |
- spatial_compose53i_dy_buffered(cs + level, slice_buf, temp, |
|
682 |
- width >> level, |
|
683 |
- height >> level, |
|
684 |
- stride_line << level); |
|
685 |
- break; |
|
686 |
- } |
|
687 |
- } |
|
688 |
-} |
|
689 |
- |
|
690 |
-static void ff_spatial_idwt_init(DWTCompose *cs, IDWTELEM *buffer, int width, |
|
691 |
- int height, int stride, int type, |
|
692 |
- int decomposition_count) |
|
693 |
-{ |
|
694 |
- int level; |
|
695 |
- for (level = decomposition_count - 1; level >= 0; level--) { |
|
696 |
- switch (type) { |
|
697 |
- case DWT_97: |
|
698 |
- spatial_compose97i_init(cs + level, buffer, height >> level, |
|
699 |
- stride << level); |
|
700 |
- break; |
|
701 |
- case DWT_53: |
|
702 |
- spatial_compose53i_init(cs + level, buffer, height >> level, |
|
703 |
- stride << level); |
|
704 |
- break; |
|
705 |
- } |
|
706 |
- } |
|
707 |
-} |
|
708 |
- |
|
709 |
-static void ff_spatial_idwt_slice(DWTCompose *cs, IDWTELEM *buffer, |
|
710 |
- IDWTELEM *temp, int width, int height, |
|
711 |
- int stride, int type, |
|
712 |
- int decomposition_count, int y) |
|
713 |
-{ |
|
714 |
- const int support = type == 1 ? 3 : 5; |
|
715 |
- int level; |
|
716 |
- if (type == 2) |
|
717 |
- return; |
|
718 |
- |
|
719 |
- for (level = decomposition_count - 1; level >= 0; level--) |
|
720 |
- while (cs[level].y <= FFMIN((y >> level) + support, height >> level)) { |
|
721 |
- switch (type) { |
|
722 |
- case DWT_97: |
|
723 |
- spatial_compose97i_dy(cs + level, buffer, temp, width >> level, |
|
724 |
- height >> level, stride << level); |
|
725 |
- break; |
|
726 |
- case DWT_53: |
|
727 |
- spatial_compose53i_dy(cs + level, buffer, temp, width >> level, |
|
728 |
- height >> level, stride << level); |
|
729 |
- break; |
|
730 |
- } |
|
731 |
- } |
|
732 |
-} |
|
733 |
- |
|
734 |
-void ff_spatial_idwt(IDWTELEM *buffer, IDWTELEM *temp, int width, int height, |
|
735 |
- int stride, int type, int decomposition_count) |
|
736 |
-{ |
|
737 |
- DWTCompose cs[MAX_DECOMPOSITIONS]; |
|
738 |
- int y; |
|
739 |
- ff_spatial_idwt_init(cs, buffer, width, height, stride, type, |
|
740 |
- decomposition_count); |
|
741 |
- for (y = 0; y < height; y += 4) |
|
742 |
- ff_spatial_idwt_slice(cs, buffer, temp, width, height, stride, type, |
|
743 |
- decomposition_count, y); |
|
744 |
-} |
|
745 |
- |
|
746 |
-static inline int w_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, |
|
747 |
- int w, int h, int type) |
|
748 |
-{ |
|
749 |
- int s, i, j; |
|
750 |
- const int dec_count = w == 8 ? 3 : 4; |
|
751 |
- int tmp[32 * 32], tmp2[32]; |
|
752 |
- int level, ori; |
|
753 |
- static const int scale[2][2][4][4] = { |
|
754 |
- { |
|
755 |
- { // 9/7 8x8 dec=3 |
|
756 |
- { 268, 239, 239, 213 }, |
|
757 |
- { 0, 224, 224, 152 }, |
|
758 |
- { 0, 135, 135, 110 }, |
|
759 |
- }, |
|
760 |
- { // 9/7 16x16 or 32x32 dec=4 |
|
761 |
- { 344, 310, 310, 280 }, |
|
762 |
- { 0, 320, 320, 228 }, |
|
763 |
- { 0, 175, 175, 136 }, |
|
764 |
- { 0, 129, 129, 102 }, |
|
765 |
- } |
|
766 |
- }, |
|
767 |
- { |
|
768 |
- { // 5/3 8x8 dec=3 |
|
769 |
- { 275, 245, 245, 218 }, |
|
770 |
- { 0, 230, 230, 156 }, |
|
771 |
- { 0, 138, 138, 113 }, |
|
772 |
- }, |
|
773 |
- { // 5/3 16x16 or 32x32 dec=4 |
|
774 |
- { 352, 317, 317, 286 }, |
|
775 |
- { 0, 328, 328, 233 }, |
|
776 |
- { 0, 180, 180, 140 }, |
|
777 |
- { 0, 132, 132, 105 }, |
|
778 |
- } |
|
779 |
- } |
|
780 |
- }; |
|
781 |
- |
|
782 |
- for (i = 0; i < h; i++) { |
|
783 |
- for (j = 0; j < w; j += 4) { |
|
784 |
- tmp[32 * i + j + 0] = (pix1[j + 0] - pix2[j + 0]) << 4; |
|
785 |
- tmp[32 * i + j + 1] = (pix1[j + 1] - pix2[j + 1]) << 4; |
|
786 |
- tmp[32 * i + j + 2] = (pix1[j + 2] - pix2[j + 2]) << 4; |
|
787 |
- tmp[32 * i + j + 3] = (pix1[j + 3] - pix2[j + 3]) << 4; |
|
788 |
- } |
|
789 |
- pix1 += line_size; |
|
790 |
- pix2 += line_size; |
|
791 |
- } |
|
792 |
- |
|
793 |
- ff_spatial_dwt(tmp, tmp2, w, h, 32, type, dec_count); |
|
794 |
- |
|
795 |
- s = 0; |
|
796 |
- assert(w == h); |
|
797 |
- for (level = 0; level < dec_count; level++) |
|
798 |
- for (ori = level ? 1 : 0; ori < 4; ori++) { |
|
799 |
- int size = w >> (dec_count - level); |
|
800 |
- int sx = (ori & 1) ? size : 0; |
|
801 |
- int stride = 32 << (dec_count - level); |
|
802 |
- int sy = (ori & 2) ? stride >> 1 : 0; |
|
803 |
- |
|
804 |
- for (i = 0; i < size; i++) |
|
805 |
- for (j = 0; j < size; j++) { |
|
806 |
- int v = tmp[sx + sy + i * stride + j] * |
|
807 |
- scale[type][dec_count - 3][level][ori]; |
|
808 |
- s += FFABS(v); |
|
809 |
- } |
|
810 |
- } |
|
811 |
- assert(s >= 0); |
|
812 |
- return s >> 9; |
|
813 |
-} |
|
814 |
- |
|
815 |
-static int w53_8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) |
|
816 |
-{ |
|
817 |
- return w_c(v, pix1, pix2, line_size, 8, h, 1); |
|
818 |
-} |
|
819 |
- |
|
820 |
-static int w97_8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) |
|
821 |
-{ |
|
822 |
- return w_c(v, pix1, pix2, line_size, 8, h, 0); |
|
823 |
-} |
|
824 |
- |
|
825 |
-static int w53_16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) |
|
826 |
-{ |
|
827 |
- return w_c(v, pix1, pix2, line_size, 16, h, 1); |
|
828 |
-} |
|
829 |
- |
|
830 |
-static int w97_16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) |
|
831 |
-{ |
|
832 |
- return w_c(v, pix1, pix2, line_size, 16, h, 0); |
|
833 |
-} |
|
834 |
- |
|
835 |
-int ff_w53_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) |
|
836 |
-{ |
|
837 |
- return w_c(v, pix1, pix2, line_size, 32, h, 1); |
|
838 |
-} |
|
839 |
- |
|
840 |
-int ff_w97_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) |
|
841 |
-{ |
|
842 |
- return w_c(v, pix1, pix2, line_size, 32, h, 0); |
|
843 |
-} |
|
844 |
- |
|
845 |
-void ff_dsputil_init_dwt(DSPContext *c) |
|
846 |
-{ |
|
847 |
- c->w53[0] = w53_16_c; |
|
848 |
- c->w53[1] = w53_8_c; |
|
849 |
- c->w97[0] = w97_16_c; |
|
850 |
- c->w97[1] = w97_8_c; |
|
851 |
-} |
|
852 |
- |
|
853 |
-void ff_dwt_init(DWTContext *c) |
|
854 |
-{ |
|
855 |
- c->vertical_compose97i = ff_snow_vertical_compose97i; |
|
856 |
- c->horizontal_compose97i = ff_snow_horizontal_compose97i; |
|
857 |
- c->inner_add_yblock = ff_snow_inner_add_yblock; |
|
858 |
- |
|
859 |
- if (HAVE_MMX) |
|
860 |
- ff_dwt_init_x86(c); |
|
861 |
-} |
862 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,124 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at> |
|
3 |
- * |
|
4 |
- * This file is part of Libav. |
|
5 |
- * |
|
6 |
- * Libav 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.1 of the License, or (at your option) any later version. |
|
10 |
- * |
|
11 |
- * Libav 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 Libav; if not, write to the Free Software |
|
18 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
- */ |
|
20 |
- |
|
21 |
-#ifndef AVCODEC_DWT_H |
|
22 |
-#define AVCODEC_DWT_H |
|
23 |
- |
|
24 |
-#include <stdint.h> |
|
25 |
- |
|
26 |
-typedef int DWTELEM; |
|
27 |
-typedef short IDWTELEM; |
|
28 |
- |
|
29 |
-typedef struct DWTCompose { |
|
30 |
- IDWTELEM *b0; |
|
31 |
- IDWTELEM *b1; |
|
32 |
- IDWTELEM *b2; |
|
33 |
- IDWTELEM *b3; |
|
34 |
- int y; |
|
35 |
-} DWTCompose; |
|
36 |
- |
|
37 |
-/** Used to minimize the amount of memory used in order to |
|
38 |
- * optimize cache performance. **/ |
|
39 |
-typedef struct slice_buffer_s { |
|
40 |
- IDWTELEM **line; ///< For use by idwt and predict_slices. |
|
41 |
- IDWTELEM **data_stack; ///< Used for internal purposes. |
|
42 |
- int data_stack_top; |
|
43 |
- int line_count; |
|
44 |
- int line_width; |
|
45 |
- int data_count; |
|
46 |
- IDWTELEM *base_buffer; ///< Buffer that this structure is caching. |
|
47 |
-} slice_buffer; |
|
48 |
- |
|
49 |
-typedef struct DWTContext { |
|
50 |
- void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, |
|
51 |
- IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, |
|
52 |
- int width); |
|
53 |
- void (*horizontal_compose97i)(IDWTELEM *b, IDWTELEM *temp, int width); |
|
54 |
- void (*inner_add_yblock)(const uint8_t *obmc, const int obmc_stride, |
|
55 |
- uint8_t **block, int b_w, int b_h, int src_x, |
|
56 |
- int src_y, int src_stride, slice_buffer *sb, |
|
57 |
- int add, uint8_t *dst8); |
|
58 |
-} DWTContext; |
|
59 |
- |
|
60 |
-#define MAX_DECOMPOSITIONS 8 |
|
61 |
- |
|
62 |
-#define DWT_97 0 |
|
63 |
-#define DWT_53 1 |
|
64 |
- |
|
65 |
-#define liftS lift |
|
66 |
-#define W_AM 3 |
|
67 |
-#define W_AO 0 |
|
68 |
-#define W_AS 1 |
|
69 |
- |
|
70 |
-#undef liftS |
|
71 |
-#define W_BM 1 |
|
72 |
-#define W_BO 8 |
|
73 |
-#define W_BS 4 |
|
74 |
- |
|
75 |
-#define W_CM 1 |
|
76 |
-#define W_CO 0 |
|
77 |
-#define W_CS 0 |
|
78 |
- |
|
79 |
-#define W_DM 3 |
|
80 |
-#define W_DO 4 |
|
81 |
-#define W_DS 3 |
|
82 |
- |
|
83 |
-#define slice_buffer_get_line(slice_buf, line_num) \ |
|
84 |
- ((slice_buf)->line[line_num] ? (slice_buf)->line[line_num] \ |
|
85 |
- : ff_slice_buffer_load_line((slice_buf), \ |
|
86 |
- (line_num))) |
|
87 |
- |
|
88 |
-int ff_slice_buffer_init(slice_buffer *buf, int line_count, |
|
89 |
- int max_allocated_lines, int line_width, |
|
90 |
- IDWTELEM *base_buffer); |
|
91 |
-void ff_slice_buffer_release(slice_buffer *buf, int line); |
|
92 |
-void ff_slice_buffer_flush(slice_buffer *buf); |
|
93 |
-void ff_slice_buffer_destroy(slice_buffer *buf); |
|
94 |
-IDWTELEM *ff_slice_buffer_load_line(slice_buffer *buf, int line); |
|
95 |
- |
|
96 |
-void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, |
|
97 |
- IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, |
|
98 |
- int width); |
|
99 |
-void ff_snow_horizontal_compose97i(IDWTELEM *b, IDWTELEM *temp, int width); |
|
100 |
-void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, |
|
101 |
- uint8_t **block, int b_w, int b_h, int src_x, |
|
102 |
- int src_y, int src_stride, slice_buffer *sb, |
|
103 |
- int add, uint8_t *dst8); |
|
104 |
- |
|
105 |
-int ff_w53_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h); |
|
106 |
-int ff_w97_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h); |
|
107 |
- |
|
108 |
-void ff_spatial_dwt(int *buffer, int *temp, int width, int height, int stride, |
|
109 |
- int type, int decomposition_count); |
|
110 |
- |
|
111 |
-void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width, |
|
112 |
- int height, int stride_line, int type, |
|
113 |
- int decomposition_count); |
|
114 |
-void ff_spatial_idwt_buffered_slice(DWTContext *dsp, DWTCompose *cs, |
|
115 |
- slice_buffer *slice_buf, IDWTELEM *temp, |
|
116 |
- int width, int height, int stride_line, |
|
117 |
- int type, int decomposition_count, int y); |
|
118 |
-void ff_spatial_idwt(IDWTELEM *buffer, IDWTELEM *temp, int width, int height, |
|
119 |
- int stride, int type, int decomposition_count); |
|
120 |
- |
|
121 |
-void ff_dwt_init(DWTContext *c); |
|
122 |
-void ff_dwt_init_x86(DWTContext *c); |
|
123 |
- |
|
124 |
-#endif /* AVCODEC_DWT_H */ |
... | ... |
@@ -28,7 +28,6 @@ |
28 | 28 |
|
29 | 29 |
#include "avcodec.h" |
30 | 30 |
#include "dsputil.h" |
31 |
-#include "dwt.h" |
|
32 | 31 |
#include "ivi_common.h" |
33 | 32 |
#include "ivi_dsp.h" |
34 | 33 |
|
... | ... |
@@ -40,7 +39,7 @@ void ff_ivi_recompose53(const IVIPlaneDesc *plane, uint8_t *dst, |
40 | 40 |
int32_t b0_1, b0_2, b1_1, b1_2, b1_3, b2_1, b2_2, b2_3, b2_4, b2_5, b2_6; |
41 | 41 |
int32_t b3_1, b3_2, b3_3, b3_4, b3_5, b3_6, b3_7, b3_8, b3_9; |
42 | 42 |
int32_t pitch, back_pitch; |
43 |
- const IDWTELEM *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr; |
|
43 |
+ const short *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr; |
|
44 | 44 |
const int num_bands = 4; |
45 | 45 |
|
46 | 46 |
/* all bands should have the same pitch */ |
... | ... |
@@ -183,7 +182,7 @@ void ff_ivi_recompose_haar(const IVIPlaneDesc *plane, uint8_t *dst, |
183 | 183 |
const int dst_pitch) |
184 | 184 |
{ |
185 | 185 |
int x, y, indx, b0, b1, b2, b3, p0, p1, p2, p3; |
186 |
- const IDWTELEM *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr; |
|
186 |
+ const short *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr; |
|
187 | 187 |
int32_t pitch; |
188 | 188 |
|
189 | 189 |
/* all bands should have the same pitch */ |
... | ... |
@@ -302,8 +302,9 @@ int ff_init_me(MpegEncContext *s){ |
302 | 302 |
av_log(s->avctx, AV_LOG_ERROR, "ME_MAP size is too small for SAB diamond\n"); |
303 | 303 |
return -1; |
304 | 304 |
} |
305 |
- //special case of snow is needed because snow uses its own iterative ME code |
|
306 |
- if(s->me_method!=ME_ZERO && s->me_method!=ME_EPZS && s->me_method!=ME_X1 && s->avctx->codec_id != AV_CODEC_ID_SNOW){ |
|
305 |
+ if (s->me_method != ME_ZERO && |
|
306 |
+ s->me_method != ME_EPZS && |
|
307 |
+ s->me_method != ME_X1) { |
|
307 | 308 |
av_log(s->avctx, AV_LOG_ERROR, "me_method is only allowed to be set to zero and epzs; for hex,umh,full and others see dia_size\n"); |
308 | 309 |
return -1; |
309 | 310 |
} |
... | ... |
@@ -354,16 +355,14 @@ int ff_init_me(MpegEncContext *s){ |
354 | 354 |
/* 8x8 fullpel search would need a 4x4 chroma compare, which we do |
355 | 355 |
* not have yet, and even if we had, the motion estimation code |
356 | 356 |
* does not expect it. */ |
357 |
- if(s->codec_id != AV_CODEC_ID_SNOW){ |
|
358 |
- if((c->avctx->me_cmp&FF_CMP_CHROMA)/* && !s->dsp.me_cmp[2]*/){ |
|
359 |
- s->dsp.me_cmp[2]= zero_cmp; |
|
360 |
- } |
|
361 |
- if((c->avctx->me_sub_cmp&FF_CMP_CHROMA) && !s->dsp.me_sub_cmp[2]){ |
|
362 |
- s->dsp.me_sub_cmp[2]= zero_cmp; |
|
363 |
- } |
|
364 |
- c->hpel_put[2][0]= c->hpel_put[2][1]= |
|
365 |
- c->hpel_put[2][2]= c->hpel_put[2][3]= zero_hpel; |
|
357 |
+ if((c->avctx->me_cmp&FF_CMP_CHROMA)/* && !s->dsp.me_cmp[2]*/){ |
|
358 |
+ s->dsp.me_cmp[2]= zero_cmp; |
|
359 |
+ } |
|
360 |
+ if((c->avctx->me_sub_cmp&FF_CMP_CHROMA) && !s->dsp.me_sub_cmp[2]){ |
|
361 |
+ s->dsp.me_sub_cmp[2]= zero_cmp; |
|
366 | 362 |
} |
363 |
+ c->hpel_put[2][0]= c->hpel_put[2][1]= |
|
364 |
+ c->hpel_put[2][2]= c->hpel_put[2][3]= zero_hpel; |
|
367 | 365 |
|
368 | 366 |
if(s->codec_id == AV_CODEC_ID_H261){ |
369 | 367 |
c->sub_motion_search= no_sub_motion_search; |
... | ... |
@@ -92,7 +92,9 @@ static const AVOption options[]={ |
92 | 92 |
{"x1", "X1 motion estimation", 0, AV_OPT_TYPE_CONST, {.i64 = ME_X1 }, INT_MIN, INT_MAX, V|E, "me_method" }, |
93 | 93 |
{"hex", "hex motion estimation", 0, AV_OPT_TYPE_CONST, {.i64 = ME_HEX }, INT_MIN, INT_MAX, V|E, "me_method" }, |
94 | 94 |
{"umh", "umh motion estimation", 0, AV_OPT_TYPE_CONST, {.i64 = ME_UMH }, INT_MIN, INT_MAX, V|E, "me_method" }, |
95 |
+#if FF_API_SNOW |
|
95 | 96 |
{"iter", "iter motion estimation", 0, AV_OPT_TYPE_CONST, {.i64 = ME_ITER }, INT_MIN, INT_MAX, V|E, "me_method" }, |
97 |
+#endif |
|
96 | 98 |
{"extradata_size", NULL, OFFSET(extradata_size), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX}, |
97 | 99 |
{"time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, INT_MIN, INT_MAX}, |
98 | 100 |
{"g", "set the group of picture (GOP) size", OFFSET(gop_size), AV_OPT_TYPE_INT, {.i64 = 12 }, INT_MIN, INT_MAX, V|E}, |
... | ... |
@@ -261,10 +263,6 @@ static const AVOption options[]={ |
261 | 261 |
{"vsad", "sum of absolute vertical differences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_VSAD }, INT_MIN, INT_MAX, V|E, "cmp_func"}, |
262 | 262 |
{"vsse", "sum of squared vertical differences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_VSSE }, INT_MIN, INT_MAX, V|E, "cmp_func"}, |
263 | 263 |
{"nsse", "noise preserving sum of squared differences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_NSSE }, INT_MIN, INT_MAX, V|E, "cmp_func"}, |
264 |
-#if CONFIG_SNOW_ENCODER |
|
265 |
-{"w53", "5/3 wavelet, only used in snow", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_W53 }, INT_MIN, INT_MAX, V|E, "cmp_func"}, |
|
266 |
-{"w97", "9/7 wavelet, only used in snow", 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_W97 }, INT_MIN, INT_MAX, V|E, "cmp_func"}, |
|
267 |
-#endif |
|
268 | 264 |
{"dctmax", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, V|E, "cmp_func"}, |
269 | 265 |
{"chroma", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_CMP_CHROMA }, INT_MIN, INT_MAX, V|E, "cmp_func"}, |
270 | 266 |
{"pre_dia_size", "diamond type & size for motion estimation pre-pass", OFFSET(pre_dia_size), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E}, |
271 | 267 |
deleted file mode 100644 |
... | ... |
@@ -1,678 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at> |
|
3 |
- * |
|
4 |
- * This file is part of Libav. |
|
5 |
- * |
|
6 |
- * Libav 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.1 of the License, or (at your option) any later version. |
|
10 |
- * |
|
11 |
- * Libav 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 Libav; if not, write to the Free Software |
|
18 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
- */ |
|
20 |
- |
|
21 |
-#include "libavutil/intmath.h" |
|
22 |
-#include "libavutil/log.h" |
|
23 |
-#include "libavutil/opt.h" |
|
24 |
-#include "avcodec.h" |
|
25 |
-#include "dsputil.h" |
|
26 |
-#include "dwt.h" |
|
27 |
-#include "internal.h" |
|
28 |
-#include "snow.h" |
|
29 |
-#include "snowdata.h" |
|
30 |
- |
|
31 |
-#include "rangecoder.h" |
|
32 |
-#include "mathops.h" |
|
33 |
-#include "h263.h" |
|
34 |
- |
|
35 |
-#undef NDEBUG |
|
36 |
-#include <assert.h> |
|
37 |
- |
|
38 |
- |
|
39 |
-void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, |
|
40 |
- int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){ |
|
41 |
- int y, x; |
|
42 |
- IDWTELEM * dst; |
|
43 |
- for(y=0; y<b_h; y++){ |
|
44 |
- //FIXME ugly misuse of obmc_stride |
|
45 |
- const uint8_t *obmc1= obmc + y*obmc_stride; |
|
46 |
- const uint8_t *obmc2= obmc1+ (obmc_stride>>1); |
|
47 |
- const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1); |
|
48 |
- const uint8_t *obmc4= obmc3+ (obmc_stride>>1); |
|
49 |
- dst = slice_buffer_get_line(sb, src_y + y); |
|
50 |
- for(x=0; x<b_w; x++){ |
|
51 |
- int v= obmc1[x] * block[3][x + y*src_stride] |
|
52 |
- +obmc2[x] * block[2][x + y*src_stride] |
|
53 |
- +obmc3[x] * block[1][x + y*src_stride] |
|
54 |
- +obmc4[x] * block[0][x + y*src_stride]; |
|
55 |
- |
|
56 |
- v <<= 8 - LOG2_OBMC_MAX; |
|
57 |
- if(FRAC_BITS != 8){ |
|
58 |
- v >>= 8 - FRAC_BITS; |
|
59 |
- } |
|
60 |
- if(add){ |
|
61 |
- v += dst[x + src_x]; |
|
62 |
- v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS; |
|
63 |
- if(v&(~255)) v= ~(v>>31); |
|
64 |
- dst8[x + y*src_stride] = v; |
|
65 |
- }else{ |
|
66 |
- dst[x + src_x] -= v; |
|
67 |
- } |
|
68 |
- } |
|
69 |
- } |
|
70 |
-} |
|
71 |
- |
|
72 |
-void ff_snow_reset_contexts(SnowContext *s){ //FIXME better initial contexts |
|
73 |
- int plane_index, level, orientation; |
|
74 |
- |
|
75 |
- for(plane_index=0; plane_index<3; plane_index++){ |
|
76 |
- for(level=0; level<MAX_DECOMPOSITIONS; level++){ |
|
77 |
- for(orientation=level ? 1:0; orientation<4; orientation++){ |
|
78 |
- memset(s->plane[plane_index].band[level][orientation].state, MID_STATE, sizeof(s->plane[plane_index].band[level][orientation].state)); |
|
79 |
- } |
|
80 |
- } |
|
81 |
- } |
|
82 |
- memset(s->header_state, MID_STATE, sizeof(s->header_state)); |
|
83 |
- memset(s->block_state, MID_STATE, sizeof(s->block_state)); |
|
84 |
-} |
|
85 |
- |
|
86 |
-int ff_snow_alloc_blocks(SnowContext *s){ |
|
87 |
- int w= -((-s->avctx->width )>>LOG2_MB_SIZE); |
|
88 |
- int h= -((-s->avctx->height)>>LOG2_MB_SIZE); |
|
89 |
- |
|
90 |
- s->b_width = w; |
|
91 |
- s->b_height= h; |
|
92 |
- |
|
93 |
- av_free(s->block); |
|
94 |
- s->block= av_mallocz(w * h * sizeof(BlockNode) << (s->block_max_depth*2)); |
|
95 |
- return 0; |
|
96 |
-} |
|
97 |
- |
|
98 |
-static void init_qexp(void){ |
|
99 |
- int i; |
|
100 |
- double v=128; |
|
101 |
- |
|
102 |
- for(i=0; i<QROOT; i++){ |
|
103 |
- ff_qexp[i]= lrintf(v); |
|
104 |
- v *= pow(2, 1.0 / QROOT); |
|
105 |
- } |
|
106 |
-} |
|
107 |
-static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int b_w, int b_h, int dx, int dy){ |
|
108 |
- static const uint8_t weight[64]={ |
|
109 |
- 8,7,6,5,4,3,2,1, |
|
110 |
- 7,7,0,0,0,0,0,1, |
|
111 |
- 6,0,6,0,0,0,2,0, |
|
112 |
- 5,0,0,5,0,3,0,0, |
|
113 |
- 4,0,0,0,4,0,0,0, |
|
114 |
- 3,0,0,5,0,3,0,0, |
|
115 |
- 2,0,6,0,0,0,2,0, |
|
116 |
- 1,7,0,0,0,0,0,1, |
|
117 |
- }; |
|
118 |
- |
|
119 |
- static const uint8_t brane[256]={ |
|
120 |
- 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x11,0x12,0x12,0x12,0x12,0x12,0x12,0x12, |
|
121 |
- 0x04,0x05,0xcc,0xcc,0xcc,0xcc,0xcc,0x41,0x15,0x16,0xcc,0xcc,0xcc,0xcc,0xcc,0x52, |
|
122 |
- 0x04,0xcc,0x05,0xcc,0xcc,0xcc,0x41,0xcc,0x15,0xcc,0x16,0xcc,0xcc,0xcc,0x52,0xcc, |
|
123 |
- 0x04,0xcc,0xcc,0x05,0xcc,0x41,0xcc,0xcc,0x15,0xcc,0xcc,0x16,0xcc,0x52,0xcc,0xcc, |
|
124 |
- 0x04,0xcc,0xcc,0xcc,0x41,0xcc,0xcc,0xcc,0x15,0xcc,0xcc,0xcc,0x16,0xcc,0xcc,0xcc, |
|
125 |
- 0x04,0xcc,0xcc,0x41,0xcc,0x05,0xcc,0xcc,0x15,0xcc,0xcc,0x52,0xcc,0x16,0xcc,0xcc, |
|
126 |
- 0x04,0xcc,0x41,0xcc,0xcc,0xcc,0x05,0xcc,0x15,0xcc,0x52,0xcc,0xcc,0xcc,0x16,0xcc, |
|
127 |
- 0x04,0x41,0xcc,0xcc,0xcc,0xcc,0xcc,0x05,0x15,0x52,0xcc,0xcc,0xcc,0xcc,0xcc,0x16, |
|
128 |
- 0x44,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x55,0x56,0x56,0x56,0x56,0x56,0x56,0x56, |
|
129 |
- 0x48,0x49,0xcc,0xcc,0xcc,0xcc,0xcc,0x85,0x59,0x5A,0xcc,0xcc,0xcc,0xcc,0xcc,0x96, |
|
130 |
- 0x48,0xcc,0x49,0xcc,0xcc,0xcc,0x85,0xcc,0x59,0xcc,0x5A,0xcc,0xcc,0xcc,0x96,0xcc, |
|
131 |
- 0x48,0xcc,0xcc,0x49,0xcc,0x85,0xcc,0xcc,0x59,0xcc,0xcc,0x5A,0xcc,0x96,0xcc,0xcc, |
|
132 |
- 0x48,0xcc,0xcc,0xcc,0x49,0xcc,0xcc,0xcc,0x59,0xcc,0xcc,0xcc,0x96,0xcc,0xcc,0xcc, |
|
133 |
- 0x48,0xcc,0xcc,0x85,0xcc,0x49,0xcc,0xcc,0x59,0xcc,0xcc,0x96,0xcc,0x5A,0xcc,0xcc, |
|
134 |
- 0x48,0xcc,0x85,0xcc,0xcc,0xcc,0x49,0xcc,0x59,0xcc,0x96,0xcc,0xcc,0xcc,0x5A,0xcc, |
|
135 |
- 0x48,0x85,0xcc,0xcc,0xcc,0xcc,0xcc,0x49,0x59,0x96,0xcc,0xcc,0xcc,0xcc,0xcc,0x5A, |
|
136 |
- }; |
|
137 |
- |
|
138 |
- static const uint8_t needs[16]={ |
|
139 |
- 0,1,0,0, |
|
140 |
- 2,4,2,0, |
|
141 |
- 0,1,0,0, |
|
142 |
- 15 |
|
143 |
- }; |
|
144 |
- |
|
145 |
- int x, y, b, r, l; |
|
146 |
- int16_t tmpIt [64*(32+HTAPS_MAX)]; |
|
147 |
- uint8_t tmp2t[3][64*(32+HTAPS_MAX)]; |
|
148 |
- int16_t *tmpI= tmpIt; |
|
149 |
- uint8_t *tmp2= tmp2t[0]; |
|
150 |
- const uint8_t *hpel[11]; |
|
151 |
- assert(dx<16 && dy<16); |
|
152 |
- r= brane[dx + 16*dy]&15; |
|
153 |
- l= brane[dx + 16*dy]>>4; |
|
154 |
- |
|
155 |
- b= needs[l] | needs[r]; |
|
156 |
- if(p && !p->diag_mc) |
|
157 |
- b= 15; |
|
158 |
- |
|
159 |
- if(b&5){ |
|
160 |
- for(y=0; y < b_h+HTAPS_MAX-1; y++){ |
|
161 |
- for(x=0; x < b_w; x++){ |
|
162 |
- int a_1=src[x + HTAPS_MAX/2-4]; |
|
163 |
- int a0= src[x + HTAPS_MAX/2-3]; |
|
164 |
- int a1= src[x + HTAPS_MAX/2-2]; |
|
165 |
- int a2= src[x + HTAPS_MAX/2-1]; |
|
166 |
- int a3= src[x + HTAPS_MAX/2+0]; |
|
167 |
- int a4= src[x + HTAPS_MAX/2+1]; |
|
168 |
- int a5= src[x + HTAPS_MAX/2+2]; |
|
169 |
- int a6= src[x + HTAPS_MAX/2+3]; |
|
170 |
- int am=0; |
|
171 |
- if(!p || p->fast_mc){ |
|
172 |
- am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5); |
|
173 |
- tmpI[x]= am; |
|
174 |
- am= (am+16)>>5; |
|
175 |
- }else{ |
|
176 |
- am= p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6); |
|
177 |
- tmpI[x]= am; |
|
178 |
- am= (am+32)>>6; |
|
179 |
- } |
|
180 |
- |
|
181 |
- if(am&(~255)) am= ~(am>>31); |
|
182 |
- tmp2[x]= am; |
|
183 |
- } |
|
184 |
- tmpI+= 64; |
|
185 |
- tmp2+= 64; |
|
186 |
- src += stride; |
|
187 |
- } |
|
188 |
- src -= stride*y; |
|
189 |
- } |
|
190 |
- src += HTAPS_MAX/2 - 1; |
|
191 |
- tmp2= tmp2t[1]; |
|
192 |
- |
|
193 |
- if(b&2){ |
|
194 |
- for(y=0; y < b_h; y++){ |
|
195 |
- for(x=0; x < b_w+1; x++){ |
|
196 |
- int a_1=src[x + (HTAPS_MAX/2-4)*stride]; |
|
197 |
- int a0= src[x + (HTAPS_MAX/2-3)*stride]; |
|
198 |
- int a1= src[x + (HTAPS_MAX/2-2)*stride]; |
|
199 |
- int a2= src[x + (HTAPS_MAX/2-1)*stride]; |
|
200 |
- int a3= src[x + (HTAPS_MAX/2+0)*stride]; |
|
201 |
- int a4= src[x + (HTAPS_MAX/2+1)*stride]; |
|
202 |
- int a5= src[x + (HTAPS_MAX/2+2)*stride]; |
|
203 |
- int a6= src[x + (HTAPS_MAX/2+3)*stride]; |
|
204 |
- int am=0; |
|
205 |
- if(!p || p->fast_mc) |
|
206 |
- am= (20*(a2+a3) - 5*(a1+a4) + (a0+a5) + 16)>>5; |
|
207 |
- else |
|
208 |
- am= (p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6) + 32)>>6; |
|
209 |
- |
|
210 |
- if(am&(~255)) am= ~(am>>31); |
|
211 |
- tmp2[x]= am; |
|
212 |
- } |
|
213 |
- src += stride; |
|
214 |
- tmp2+= 64; |
|
215 |
- } |
|
216 |
- src -= stride*y; |
|
217 |
- } |
|
218 |
- src += stride*(HTAPS_MAX/2 - 1); |
|
219 |
- tmp2= tmp2t[2]; |
|
220 |
- tmpI= tmpIt; |
|
221 |
- if(b&4){ |
|
222 |
- for(y=0; y < b_h; y++){ |
|
223 |
- for(x=0; x < b_w; x++){ |
|
224 |
- int a_1=tmpI[x + (HTAPS_MAX/2-4)*64]; |
|
225 |
- int a0= tmpI[x + (HTAPS_MAX/2-3)*64]; |
|
226 |
- int a1= tmpI[x + (HTAPS_MAX/2-2)*64]; |
|
227 |
- int a2= tmpI[x + (HTAPS_MAX/2-1)*64]; |
|
228 |
- int a3= tmpI[x + (HTAPS_MAX/2+0)*64]; |
|
229 |
- int a4= tmpI[x + (HTAPS_MAX/2+1)*64]; |
|
230 |
- int a5= tmpI[x + (HTAPS_MAX/2+2)*64]; |
|
231 |
- int a6= tmpI[x + (HTAPS_MAX/2+3)*64]; |
|
232 |
- int am=0; |
|
233 |
- if(!p || p->fast_mc) |
|
234 |
- am= (20*(a2+a3) - 5*(a1+a4) + (a0+a5) + 512)>>10; |
|
235 |
- else |
|
236 |
- am= (p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6) + 2048)>>12; |
|
237 |
- if(am&(~255)) am= ~(am>>31); |
|
238 |
- tmp2[x]= am; |
|
239 |
- } |
|
240 |
- tmpI+= 64; |
|
241 |
- tmp2+= 64; |
|
242 |
- } |
|
243 |
- } |
|
244 |
- |
|
245 |
- hpel[ 0]= src; |
|
246 |
- hpel[ 1]= tmp2t[0] + 64*(HTAPS_MAX/2-1); |
|
247 |
- hpel[ 2]= src + 1; |
|
248 |
- |
|
249 |
- hpel[ 4]= tmp2t[1]; |
|
250 |
- hpel[ 5]= tmp2t[2]; |
|
251 |
- hpel[ 6]= tmp2t[1] + 1; |
|
252 |
- |
|
253 |
- hpel[ 8]= src + stride; |
|
254 |
- hpel[ 9]= hpel[1] + 64; |
|
255 |
- hpel[10]= hpel[8] + 1; |
|
256 |
- |
|
257 |
-#define MC_STRIDE(x) (needs[x] ? 64 : stride) |
|
258 |
- |
|
259 |
- if(b==15){ |
|
260 |
- int dxy = dx / 8 + dy / 8 * 4; |
|
261 |
- const uint8_t *src1 = hpel[dxy ]; |
|
262 |
- const uint8_t *src2 = hpel[dxy + 1]; |
|
263 |
- const uint8_t *src3 = hpel[dxy + 4]; |
|
264 |
- const uint8_t *src4 = hpel[dxy + 5]; |
|
265 |
- int stride1 = MC_STRIDE(dxy); |
|
266 |
- int stride2 = MC_STRIDE(dxy + 1); |
|
267 |
- int stride3 = MC_STRIDE(dxy + 4); |
|
268 |
- int stride4 = MC_STRIDE(dxy + 5); |
|
269 |
- dx&=7; |
|
270 |
- dy&=7; |
|
271 |
- for(y=0; y < b_h; y++){ |
|
272 |
- for(x=0; x < b_w; x++){ |
|
273 |
- dst[x]= ((8-dx)*(8-dy)*src1[x] + dx*(8-dy)*src2[x]+ |
|
274 |
- (8-dx)* dy *src3[x] + dx* dy *src4[x]+32)>>6; |
|
275 |
- } |
|
276 |
- src1+=stride1; |
|
277 |
- src2+=stride2; |
|
278 |
- src3+=stride3; |
|
279 |
- src4+=stride4; |
|
280 |
- dst +=stride; |
|
281 |
- } |
|
282 |
- }else{ |
|
283 |
- const uint8_t *src1= hpel[l]; |
|
284 |
- const uint8_t *src2= hpel[r]; |
|
285 |
- int stride1 = MC_STRIDE(l); |
|
286 |
- int stride2 = MC_STRIDE(r); |
|
287 |
- int a= weight[((dx&7) + (8*(dy&7)))]; |
|
288 |
- int b= 8-a; |
|
289 |
- for(y=0; y < b_h; y++){ |
|
290 |
- for(x=0; x < b_w; x++){ |
|
291 |
- dst[x]= (a*src1[x] + b*src2[x] + 4)>>3; |
|
292 |
- } |
|
293 |
- src1+=stride1; |
|
294 |
- src2+=stride2; |
|
295 |
- dst +=stride; |
|
296 |
- } |
|
297 |
- } |
|
298 |
-} |
|
299 |
- |
|
300 |
-void ff_snow_pred_block(SnowContext *s, uint8_t *dst, uint8_t *tmp, int stride, int sx, int sy, int b_w, int b_h, BlockNode *block, int plane_index, int w, int h){ |
|
301 |
- if(block->type & BLOCK_INTRA){ |
|
302 |
- int x, y; |
|
303 |
- const unsigned color = block->color[plane_index]; |
|
304 |
- const unsigned color4 = color*0x01010101; |
|
305 |
- if(b_w==32){ |
|
306 |
- for(y=0; y < b_h; y++){ |
|
307 |
- *(uint32_t*)&dst[0 + y*stride]= color4; |
|
308 |
- *(uint32_t*)&dst[4 + y*stride]= color4; |
|
309 |
- *(uint32_t*)&dst[8 + y*stride]= color4; |
|
310 |
- *(uint32_t*)&dst[12+ y*stride]= color4; |
|
311 |
- *(uint32_t*)&dst[16+ y*stride]= color4; |
|
312 |
- *(uint32_t*)&dst[20+ y*stride]= color4; |
|
313 |
- *(uint32_t*)&dst[24+ y*stride]= color4; |
|
314 |
- *(uint32_t*)&dst[28+ y*stride]= color4; |
|
315 |
- } |
|
316 |
- }else if(b_w==16){ |
|
317 |
- for(y=0; y < b_h; y++){ |
|
318 |
- *(uint32_t*)&dst[0 + y*stride]= color4; |
|
319 |
- *(uint32_t*)&dst[4 + y*stride]= color4; |
|
320 |
- *(uint32_t*)&dst[8 + y*stride]= color4; |
|
321 |
- *(uint32_t*)&dst[12+ y*stride]= color4; |
|
322 |
- } |
|
323 |
- }else if(b_w==8){ |
|
324 |
- for(y=0; y < b_h; y++){ |
|
325 |
- *(uint32_t*)&dst[0 + y*stride]= color4; |
|
326 |
- *(uint32_t*)&dst[4 + y*stride]= color4; |
|
327 |
- } |
|
328 |
- }else if(b_w==4){ |
|
329 |
- for(y=0; y < b_h; y++){ |
|
330 |
- *(uint32_t*)&dst[0 + y*stride]= color4; |
|
331 |
- } |
|
332 |
- }else{ |
|
333 |
- for(y=0; y < b_h; y++){ |
|
334 |
- for(x=0; x < b_w; x++){ |
|
335 |
- dst[x + y*stride]= color; |
|
336 |
- } |
|
337 |
- } |
|
338 |
- } |
|
339 |
- }else{ |
|
340 |
- uint8_t *src= s->last_picture[block->ref].data[plane_index]; |
|
341 |
- const int scale= plane_index ? s->mv_scale : 2*s->mv_scale; |
|
342 |
- int mx= block->mx*scale; |
|
343 |
- int my= block->my*scale; |
|
344 |
- const int dx= mx&15; |
|
345 |
- const int dy= my&15; |
|
346 |
- const int tab_index= 3 - (b_w>>2) + (b_w>>4); |
|
347 |
- sx += (mx>>4) - (HTAPS_MAX/2-1); |
|
348 |
- sy += (my>>4) - (HTAPS_MAX/2-1); |
|
349 |
- src += sx + sy*stride; |
|
350 |
- if( (unsigned)sx >= w - b_w - (HTAPS_MAX-2) |
|
351 |
- || (unsigned)sy >= h - b_h - (HTAPS_MAX-2)){ |
|
352 |
- s->vdsp.emulated_edge_mc(tmp + MB_SIZE, src, stride, b_w+HTAPS_MAX-1, b_h+HTAPS_MAX-1, sx, sy, w, h); |
|
353 |
- src= tmp + MB_SIZE; |
|
354 |
- } |
|
355 |
-// assert(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h); |
|
356 |
-// assert(!(b_w&(b_w-1))); |
|
357 |
- assert(b_w>1 && b_h>1); |
|
358 |
- assert((tab_index>=0 && tab_index<4) || b_w==32); |
|
359 |
- if((dx&3) || (dy&3) || !(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h) || (b_w&(b_w-1)) || !s->plane[plane_index].fast_mc ) |
|
360 |
- mc_block(&s->plane[plane_index], dst, src, stride, b_w, b_h, dx, dy); |
|
361 |
- else if(b_w==32){ |
|
362 |
- int y; |
|
363 |
- for(y=0; y<b_h; y+=16){ |
|
364 |
- s->dsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + y*stride, src + 3 + (y+3)*stride,stride); |
|
365 |
- s->dsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + 16 + y*stride, src + 19 + (y+3)*stride,stride); |
|
366 |
- } |
|
367 |
- }else if(b_w==b_h) |
|
368 |
- s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst,src + 3 + 3*stride,stride); |
|
369 |
- else if(b_w==2*b_h){ |
|
370 |
- s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst ,src + 3 + 3*stride,stride); |
|
371 |
- s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst+b_h,src + 3 + b_h + 3*stride,stride); |
|
372 |
- }else{ |
|
373 |
- assert(2*b_w==b_h); |
|
374 |
- s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst ,src + 3 + 3*stride ,stride); |
|
375 |
- s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst+b_w*stride,src + 3 + 3*stride+b_w*stride,stride); |
|
376 |
- } |
|
377 |
- } |
|
378 |
-} |
|
379 |
- |
|
380 |
-#define mca(dx,dy,b_w)\ |
|
381 |
-static void mc_block_hpel ## dx ## dy ## b_w(uint8_t *dst, const uint8_t *src, int stride, int h){\ |
|
382 |
- assert(h==b_w);\ |
|
383 |
- mc_block(NULL, dst, src-(HTAPS_MAX/2-1)-(HTAPS_MAX/2-1)*stride, stride, b_w, b_w, dx, dy);\ |
|
384 |
-} |
|
385 |
- |
|
386 |
-mca( 0, 0,16) |
|
387 |
-mca( 8, 0,16) |
|
388 |
-mca( 0, 8,16) |
|
389 |
-mca( 8, 8,16) |
|
390 |
-mca( 0, 0,8) |
|
391 |
-mca( 8, 0,8) |
|
392 |
-mca( 0, 8,8) |
|
393 |
-mca( 8, 8,8) |
|
394 |
- |
|
395 |
-av_cold int ff_snow_common_init(AVCodecContext *avctx){ |
|
396 |
- SnowContext *s = avctx->priv_data; |
|
397 |
- int width, height; |
|
398 |
- int i, j, ret; |
|
399 |
- int emu_buf_size; |
|
400 |
- |
|
401 |
- s->avctx= avctx; |
|
402 |
- s->max_ref_frames=1; //just make sure its not an invalid value in case of no initial keyframe |
|
403 |
- |
|
404 |
- ff_dsputil_init(&s->dsp, avctx); |
|
405 |
- ff_videodsp_init(&s->vdsp, 8); |
|
406 |
- ff_dwt_init(&s->dwt); |
|
407 |
- |
|
408 |
-#define mcf(dx,dy)\ |
|
409 |
- s->dsp.put_qpel_pixels_tab [0][dy+dx/4]=\ |
|
410 |
- s->dsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\ |
|
411 |
- s->dsp.put_h264_qpel_pixels_tab[0][dy+dx/4];\ |
|
412 |
- s->dsp.put_qpel_pixels_tab [1][dy+dx/4]=\ |
|
413 |
- s->dsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\ |
|
414 |
- s->dsp.put_h264_qpel_pixels_tab[1][dy+dx/4]; |
|
415 |
- |
|
416 |
- mcf( 0, 0) |
|
417 |
- mcf( 4, 0) |
|
418 |
- mcf( 8, 0) |
|
419 |
- mcf(12, 0) |
|
420 |
- mcf( 0, 4) |
|
421 |
- mcf( 4, 4) |
|
422 |
- mcf( 8, 4) |
|
423 |
- mcf(12, 4) |
|
424 |
- mcf( 0, 8) |
|
425 |
- mcf( 4, 8) |
|
426 |
- mcf( 8, 8) |
|
427 |
- mcf(12, 8) |
|
428 |
- mcf( 0,12) |
|
429 |
- mcf( 4,12) |
|
430 |
- mcf( 8,12) |
|
431 |
- mcf(12,12) |
|
432 |
- |
|
433 |
-#define mcfh(dx,dy)\ |
|
434 |
- s->dsp.put_pixels_tab [0][dy/4+dx/8]=\ |
|
435 |
- s->dsp.put_no_rnd_pixels_tab[0][dy/4+dx/8]=\ |
|
436 |
- mc_block_hpel ## dx ## dy ## 16;\ |
|
437 |
- s->dsp.put_pixels_tab [1][dy/4+dx/8]=\ |
|
438 |
- s->dsp.put_no_rnd_pixels_tab[1][dy/4+dx/8]=\ |
|
439 |
- mc_block_hpel ## dx ## dy ## 8; |
|
440 |
- |
|
441 |
- mcfh(0, 0) |
|
442 |
- mcfh(8, 0) |
|
443 |
- mcfh(0, 8) |
|
444 |
- mcfh(8, 8) |
|
445 |
- |
|
446 |
- init_qexp(); |
|
447 |
- |
|
448 |
-// dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift); |
|
449 |
- |
|
450 |
- width= s->avctx->width; |
|
451 |
- height= s->avctx->height; |
|
452 |
- |
|
453 |
- FF_ALLOCZ_OR_GOTO(avctx, s->spatial_idwt_buffer, width * height * sizeof(IDWTELEM), fail); |
|
454 |
- FF_ALLOCZ_OR_GOTO(avctx, s->spatial_dwt_buffer, width * height * sizeof(DWTELEM), fail); //FIXME this does not belong here |
|
455 |
- FF_ALLOCZ_OR_GOTO(avctx, s->temp_dwt_buffer, width * sizeof(DWTELEM), fail); |
|
456 |
- FF_ALLOCZ_OR_GOTO(avctx, s->temp_idwt_buffer, width * sizeof(IDWTELEM), fail); |
|
457 |
- FF_ALLOC_OR_GOTO(avctx, s->run_buffer, ((width + 1) >> 1) * ((height + 1) >> 1) * sizeof(*s->run_buffer), fail); |
|
458 |
- |
|
459 |
- for(i=0; i<MAX_REF_FRAMES; i++) |
|
460 |
- for(j=0; j<MAX_REF_FRAMES; j++) |
|
461 |
- ff_scale_mv_ref[i][j] = 256*(i+1)/(j+1); |
|
462 |
- |
|
463 |
- if ((ret = ff_get_buffer(s->avctx, &s->mconly_picture)) < 0) { |
|
464 |
- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
|
465 |
- return ret; |
|
466 |
- } |
|
467 |
- FF_ALLOC_OR_GOTO(avctx, s->scratchbuf, s->mconly_picture.linesize[0]*7*MB_SIZE, fail); |
|
468 |
- emu_buf_size = s->mconly_picture.linesize[0] * (2 * MB_SIZE + HTAPS_MAX - 1); |
|
469 |
- FF_ALLOC_OR_GOTO(avctx, s->emu_edge_buffer, emu_buf_size, fail); |
|
470 |
- |
|
471 |
- return 0; |
|
472 |
-fail: |
|
473 |
- return AVERROR(ENOMEM); |
|
474 |
-} |
|
475 |
- |
|
476 |
-int ff_snow_common_init_after_header(AVCodecContext *avctx) { |
|
477 |
- SnowContext *s = avctx->priv_data; |
|
478 |
- int plane_index, level, orientation; |
|
479 |
- |
|
480 |
- for(plane_index=0; plane_index<3; plane_index++){ |
|
481 |
- int w= s->avctx->width; |
|
482 |
- int h= s->avctx->height; |
|
483 |
- |
|
484 |
- if(plane_index){ |
|
485 |
- w>>= s->chroma_h_shift; |
|
486 |
- h>>= s->chroma_v_shift; |
|
487 |
- } |
|
488 |
- s->plane[plane_index].width = w; |
|
489 |
- s->plane[plane_index].height= h; |
|
490 |
- |
|
491 |
- for(level=s->spatial_decomposition_count-1; level>=0; level--){ |
|
492 |
- for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
|
493 |
- SubBand *b= &s->plane[plane_index].band[level][orientation]; |
|
494 |
- |
|
495 |
- b->buf= s->spatial_dwt_buffer; |
|
496 |
- b->level= level; |
|
497 |
- b->stride= s->plane[plane_index].width << (s->spatial_decomposition_count - level); |
|
498 |
- b->width = (w + !(orientation&1))>>1; |
|
499 |
- b->height= (h + !(orientation>1))>>1; |
|
500 |
- |
|
501 |
- b->stride_line = 1 << (s->spatial_decomposition_count - level); |
|
502 |
- b->buf_x_offset = 0; |
|
503 |
- b->buf_y_offset = 0; |
|
504 |
- |
|
505 |
- if(orientation&1){ |
|
506 |
- b->buf += (w+1)>>1; |
|
507 |
- b->buf_x_offset = (w+1)>>1; |
|
508 |
- } |
|
509 |
- if(orientation>1){ |
|
510 |
- b->buf += b->stride>>1; |
|
511 |
- b->buf_y_offset = b->stride_line >> 1; |
|
512 |
- } |
|
513 |
- b->ibuf= s->spatial_idwt_buffer + (b->buf - s->spatial_dwt_buffer); |
|
514 |
- |
|
515 |
- if(level) |
|
516 |
- b->parent= &s->plane[plane_index].band[level-1][orientation]; |
|
517 |
- //FIXME avoid this realloc |
|
518 |
- av_freep(&b->x_coeff); |
|
519 |
- b->x_coeff=av_mallocz(((b->width+1) * b->height+1)*sizeof(x_and_coeff)); |
|
520 |
- } |
|
521 |
- w= (w+1)>>1; |
|
522 |
- h= (h+1)>>1; |
|
523 |
- } |
|
524 |
- } |
|
525 |
- |
|
526 |
- return 0; |
|
527 |
-} |
|
528 |
- |
|
529 |
-#define USE_HALFPEL_PLANE 0 |
|
530 |
- |
|
531 |
-static void halfpel_interpol(SnowContext *s, uint8_t *halfpel[4][4], AVFrame *frame){ |
|
532 |
- int p,x,y; |
|
533 |
- |
|
534 |
- for(p=0; p<3; p++){ |
|
535 |
- int is_chroma= !!p; |
|
536 |
- int w= s->avctx->width >>is_chroma; |
|
537 |
- int h= s->avctx->height >>is_chroma; |
|
538 |
- int ls= frame->linesize[p]; |
|
539 |
- uint8_t *src= frame->data[p]; |
|
540 |
- |
|
541 |
- halfpel[1][p] = (uint8_t*) av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls); |
|
542 |
- halfpel[2][p] = (uint8_t*) av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls); |
|
543 |
- halfpel[3][p] = (uint8_t*) av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls); |
|
544 |
- |
|
545 |
- halfpel[0][p]= src; |
|
546 |
- for(y=0; y<h; y++){ |
|
547 |
- for(x=0; x<w; x++){ |
|
548 |
- int i= y*ls + x; |
|
549 |
- |
|
550 |
- halfpel[1][p][i]= (20*(src[i] + src[i+1]) - 5*(src[i-1] + src[i+2]) + (src[i-2] + src[i+3]) + 16 )>>5; |
|
551 |
- } |
|
552 |
- } |
|
553 |
- for(y=0; y<h; y++){ |
|
554 |
- for(x=0; x<w; x++){ |
|
555 |
- int i= y*ls + x; |
|
556 |
- |
|
557 |
- halfpel[2][p][i]= (20*(src[i] + src[i+ls]) - 5*(src[i-ls] + src[i+2*ls]) + (src[i-2*ls] + src[i+3*ls]) + 16 )>>5; |
|
558 |
- } |
|
559 |
- } |
|
560 |
- src= halfpel[1][p]; |
|
561 |
- for(y=0; y<h; y++){ |
|
562 |
- for(x=0; x<w; x++){ |
|
563 |
- int i= y*ls + x; |
|
564 |
- |
|
565 |
- halfpel[3][p][i]= (20*(src[i] + src[i+ls]) - 5*(src[i-ls] + src[i+2*ls]) + (src[i-2*ls] + src[i+3*ls]) + 16 )>>5; |
|
566 |
- } |
|
567 |
- } |
|
568 |
- |
|
569 |
-//FIXME border! |
|
570 |
- } |
|
571 |
-} |
|
572 |
- |
|
573 |
-void ff_snow_release_buffer(AVCodecContext *avctx) |
|
574 |
-{ |
|
575 |
- SnowContext *s = avctx->priv_data; |
|
576 |
- int i; |
|
577 |
- |
|
578 |
- if(s->last_picture[s->max_ref_frames-1].data[0]){ |
|
579 |
- avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]); |
|
580 |
- for(i=0; i<9; i++) |
|
581 |
- if(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3]) |
|
582 |
- av_free(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3] - EDGE_WIDTH*(1+s->current_picture.linesize[i%3])); |
|
583 |
- } |
|
584 |
-} |
|
585 |
- |
|
586 |
-int ff_snow_frame_start(SnowContext *s){ |
|
587 |
- AVFrame tmp; |
|
588 |
- int w= s->avctx->width; //FIXME round up to x16 ? |
|
589 |
- int h= s->avctx->height; |
|
590 |
- |
|
591 |
- if (s->current_picture.data[0] && !(s->avctx->flags&CODEC_FLAG_EMU_EDGE)) { |
|
592 |
- s->dsp.draw_edges(s->current_picture.data[0], |
|
593 |
- s->current_picture.linesize[0], w , h , |
|
594 |
- EDGE_WIDTH , EDGE_WIDTH , EDGE_TOP | EDGE_BOTTOM); |
|
595 |
- s->dsp.draw_edges(s->current_picture.data[1], |
|
596 |
- s->current_picture.linesize[1], w>>1, h>>1, |
|
597 |
- EDGE_WIDTH/2, EDGE_WIDTH/2, EDGE_TOP | EDGE_BOTTOM); |
|
598 |
- s->dsp.draw_edges(s->current_picture.data[2], |
|
599 |
- s->current_picture.linesize[2], w>>1, h>>1, |
|
600 |
- EDGE_WIDTH/2, EDGE_WIDTH/2, EDGE_TOP | EDGE_BOTTOM); |
|
601 |
- } |
|
602 |
- |
|
603 |
- ff_snow_release_buffer(s->avctx); |
|
604 |
- |
|
605 |
- tmp= s->last_picture[s->max_ref_frames-1]; |
|
606 |
- memmove(s->last_picture+1, s->last_picture, (s->max_ref_frames-1)*sizeof(AVFrame)); |
|
607 |
- memmove(s->halfpel_plane+1, s->halfpel_plane, (s->max_ref_frames-1)*sizeof(void*)*4*4); |
|
608 |
- if(USE_HALFPEL_PLANE && s->current_picture.data[0]) |
|
609 |
- halfpel_interpol(s, s->halfpel_plane[0], &s->current_picture); |
|
610 |
- s->last_picture[0]= s->current_picture; |
|
611 |
- s->current_picture= tmp; |
|
612 |
- |
|
613 |
- if(s->keyframe){ |
|
614 |
- s->ref_frames= 0; |
|
615 |
- }else{ |
|
616 |
- int i; |
|
617 |
- for(i=0; i<s->max_ref_frames && s->last_picture[i].data[0]; i++) |
|
618 |
- if(i && s->last_picture[i-1].key_frame) |
|
619 |
- break; |
|
620 |
- s->ref_frames= i; |
|
621 |
- if(s->ref_frames==0){ |
|
622 |
- av_log(s->avctx,AV_LOG_ERROR, "No reference frames\n"); |
|
623 |
- return -1; |
|
624 |
- } |
|
625 |
- } |
|
626 |
- |
|
627 |
- s->current_picture.reference= 1; |
|
628 |
- if(ff_get_buffer(s->avctx, &s->current_picture) < 0){ |
|
629 |
- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
|
630 |
- return -1; |
|
631 |
- } |
|
632 |
- |
|
633 |
- s->current_picture.key_frame= s->keyframe; |
|
634 |
- |
|
635 |
- return 0; |
|
636 |
-} |
|
637 |
- |
|
638 |
-av_cold void ff_snow_common_end(SnowContext *s) |
|
639 |
-{ |
|
640 |
- int plane_index, level, orientation, i; |
|
641 |
- |
|
642 |
- av_freep(&s->spatial_dwt_buffer); |
|
643 |
- av_freep(&s->temp_dwt_buffer); |
|
644 |
- av_freep(&s->spatial_idwt_buffer); |
|
645 |
- av_freep(&s->temp_idwt_buffer); |
|
646 |
- av_freep(&s->run_buffer); |
|
647 |
- |
|
648 |
- s->m.me.temp= NULL; |
|
649 |
- av_freep(&s->m.me.scratchpad); |
|
650 |
- av_freep(&s->m.me.map); |
|
651 |
- av_freep(&s->m.me.score_map); |
|
652 |
- av_freep(&s->m.obmc_scratchpad); |
|
653 |
- |
|
654 |
- av_freep(&s->block); |
|
655 |
- av_freep(&s->scratchbuf); |
|
656 |
- av_freep(&s->emu_edge_buffer); |
|
657 |
- |
|
658 |
- for(i=0; i<MAX_REF_FRAMES; i++){ |
|
659 |
- av_freep(&s->ref_mvs[i]); |
|
660 |
- av_freep(&s->ref_scores[i]); |
|
661 |
- if(s->last_picture[i].data[0]) |
|
662 |
- s->avctx->release_buffer(s->avctx, &s->last_picture[i]); |
|
663 |
- } |
|
664 |
- |
|
665 |
- for(plane_index=0; plane_index<3; plane_index++){ |
|
666 |
- for(level=s->spatial_decomposition_count-1; level>=0; level--){ |
|
667 |
- for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
|
668 |
- SubBand *b= &s->plane[plane_index].band[level][orientation]; |
|
669 |
- |
|
670 |
- av_freep(&b->x_coeff); |
|
671 |
- } |
|
672 |
- } |
|
673 |
- } |
|
674 |
- if (s->mconly_picture.data[0]) |
|
675 |
- s->avctx->release_buffer(s->avctx, &s->mconly_picture); |
|
676 |
- if (s->current_picture.data[0]) |
|
677 |
- s->avctx->release_buffer(s->avctx, &s->current_picture); |
|
678 |
-} |
679 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,693 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at> |
|
3 |
- * Copyright (C) 2006 Robert Edele <yartrebo@earthlink.net> |
|
4 |
- * |
|
5 |
- * This file is part of Libav. |
|
6 |
- * |
|
7 |
- * Libav is free software; you can redistribute it and/or |
|
8 |
- * modify it under the terms of the GNU Lesser General Public |
|
9 |
- * License as published by the Free Software Foundation; either |
|
10 |
- * version 2.1 of the License, or (at your option) any later version. |
|
11 |
- * |
|
12 |
- * Libav is distributed in the hope that it will be useful, |
|
13 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 |
- * Lesser General Public License for more details. |
|
16 |
- * |
|
17 |
- * You should have received a copy of the GNU Lesser General Public |
|
18 |
- * License along with Libav; if not, write to the Free Software |
|
19 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
20 |
- */ |
|
21 |
- |
|
22 |
-#ifndef AVCODEC_SNOW_H |
|
23 |
-#define AVCODEC_SNOW_H |
|
24 |
- |
|
25 |
-#include "dsputil.h" |
|
26 |
-#include "dwt.h" |
|
27 |
- |
|
28 |
-#include "rangecoder.h" |
|
29 |
-#include "mathops.h" |
|
30 |
-#include "mpegvideo.h" |
|
31 |
- |
|
32 |
-#define MID_STATE 128 |
|
33 |
- |
|
34 |
-#define MAX_PLANES 4 |
|
35 |
-#define QSHIFT 5 |
|
36 |
-#define QROOT (1<<QSHIFT) |
|
37 |
-#define LOSSLESS_QLOG -128 |
|
38 |
-#define FRAC_BITS 4 |
|
39 |
-#define MAX_REF_FRAMES 8 |
|
40 |
- |
|
41 |
-#define LOG2_OBMC_MAX 8 |
|
42 |
-#define OBMC_MAX (1<<(LOG2_OBMC_MAX)) |
|
43 |
-typedef struct BlockNode{ |
|
44 |
- int16_t mx; |
|
45 |
- int16_t my; |
|
46 |
- uint8_t ref; |
|
47 |
- uint8_t color[3]; |
|
48 |
- uint8_t type; |
|
49 |
-//#define TYPE_SPLIT 1 |
|
50 |
-#define BLOCK_INTRA 1 |
|
51 |
-#define BLOCK_OPT 2 |
|
52 |
-//#define TYPE_NOCOLOR 4 |
|
53 |
- uint8_t level; //FIXME merge into type? |
|
54 |
-}BlockNode; |
|
55 |
- |
|
56 |
-static const BlockNode null_block= { //FIXME add border maybe |
|
57 |
- .color= {128,128,128}, |
|
58 |
- .mx= 0, |
|
59 |
- .my= 0, |
|
60 |
- .ref= 0, |
|
61 |
- .type= 0, |
|
62 |
- .level= 0, |
|
63 |
-}; |
|
64 |
- |
|
65 |
-#define LOG2_MB_SIZE 4 |
|
66 |
-#define MB_SIZE (1<<LOG2_MB_SIZE) |
|
67 |
-#define ENCODER_EXTRA_BITS 4 |
|
68 |
-#define HTAPS_MAX 8 |
|
69 |
- |
|
70 |
-typedef struct x_and_coeff{ |
|
71 |
- int16_t x; |
|
72 |
- uint16_t coeff; |
|
73 |
-} x_and_coeff; |
|
74 |
- |
|
75 |
-typedef struct SubBand{ |
|
76 |
- int level; |
|
77 |
- int stride; |
|
78 |
- int width; |
|
79 |
- int height; |
|
80 |
- int qlog; ///< log(qscale)/log[2^(1/6)] |
|
81 |
- DWTELEM *buf; |
|
82 |
- IDWTELEM *ibuf; |
|
83 |
- int buf_x_offset; |
|
84 |
- int buf_y_offset; |
|
85 |
- int stride_line; ///< Stride measured in lines, not pixels. |
|
86 |
- x_and_coeff * x_coeff; |
|
87 |
- struct SubBand *parent; |
|
88 |
- uint8_t state[/*7*2*/ 7 + 512][32]; |
|
89 |
-}SubBand; |
|
90 |
- |
|
91 |
-typedef struct Plane{ |
|
92 |
- int width; |
|
93 |
- int height; |
|
94 |
- SubBand band[MAX_DECOMPOSITIONS][4]; |
|
95 |
- |
|
96 |
- int htaps; |
|
97 |
- int8_t hcoeff[HTAPS_MAX/2]; |
|
98 |
- int diag_mc; |
|
99 |
- int fast_mc; |
|
100 |
- |
|
101 |
- int last_htaps; |
|
102 |
- int8_t last_hcoeff[HTAPS_MAX/2]; |
|
103 |
- int last_diag_mc; |
|
104 |
-}Plane; |
|
105 |
- |
|
106 |
-typedef struct SnowContext{ |
|
107 |
- AVClass *class; |
|
108 |
- AVCodecContext *avctx; |
|
109 |
- RangeCoder c; |
|
110 |
- DSPContext dsp; |
|
111 |
- VideoDSPContext vdsp; |
|
112 |
- DWTContext dwt; |
|
113 |
- AVFrame new_picture; |
|
114 |
- AVFrame input_picture; ///< new_picture with the internal linesizes |
|
115 |
- AVFrame current_picture; |
|
116 |
- AVFrame last_picture[MAX_REF_FRAMES]; |
|
117 |
- uint8_t *halfpel_plane[MAX_REF_FRAMES][4][4]; |
|
118 |
- AVFrame mconly_picture; |
|
119 |
-// uint8_t q_context[16]; |
|
120 |
- uint8_t header_state[32]; |
|
121 |
- uint8_t block_state[128 + 32*128]; |
|
122 |
- int keyframe; |
|
123 |
- int always_reset; |
|
124 |
- int version; |
|
125 |
- int spatial_decomposition_type; |
|
126 |
- int last_spatial_decomposition_type; |
|
127 |
- int temporal_decomposition_type; |
|
128 |
- int spatial_decomposition_count; |
|
129 |
- int last_spatial_decomposition_count; |
|
130 |
- int temporal_decomposition_count; |
|
131 |
- int max_ref_frames; |
|
132 |
- int ref_frames; |
|
133 |
- int16_t (*ref_mvs[MAX_REF_FRAMES])[2]; |
|
134 |
- uint32_t *ref_scores[MAX_REF_FRAMES]; |
|
135 |
- DWTELEM *spatial_dwt_buffer; |
|
136 |
- DWTELEM *temp_dwt_buffer; |
|
137 |
- IDWTELEM *spatial_idwt_buffer; |
|
138 |
- IDWTELEM *temp_idwt_buffer; |
|
139 |
- int *run_buffer; |
|
140 |
- int colorspace_type; |
|
141 |
- int chroma_h_shift; |
|
142 |
- int chroma_v_shift; |
|
143 |
- int spatial_scalability; |
|
144 |
- int qlog; |
|
145 |
- int last_qlog; |
|
146 |
- int lambda; |
|
147 |
- int lambda2; |
|
148 |
- int pass1_rc; |
|
149 |
- int mv_scale; |
|
150 |
- int last_mv_scale; |
|
151 |
- int qbias; |
|
152 |
- int last_qbias; |
|
153 |
-#define QBIAS_SHIFT 3 |
|
154 |
- int b_width; |
|
155 |
- int b_height; |
|
156 |
- int block_max_depth; |
|
157 |
- int last_block_max_depth; |
|
158 |
- Plane plane[MAX_PLANES]; |
|
159 |
- BlockNode *block; |
|
160 |
-#define ME_CACHE_SIZE 1024 |
|
161 |
- unsigned me_cache[ME_CACHE_SIZE]; |
|
162 |
- unsigned me_cache_generation; |
|
163 |
- slice_buffer sb; |
|
164 |
- int memc_only; |
|
165 |
- |
|
166 |
- MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to eventually make the motion estimation independent of MpegEncContext, so this will be removed then (FIXME/XXX) |
|
167 |
- |
|
168 |
- uint8_t *scratchbuf; |
|
169 |
- uint8_t *emu_edge_buffer; |
|
170 |
-}SnowContext; |
|
171 |
- |
|
172 |
-/* Tables */ |
|
173 |
-extern const uint8_t * const ff_obmc_tab[4]; |
|
174 |
-extern uint8_t ff_qexp[QROOT]; |
|
175 |
-extern int ff_scale_mv_ref[MAX_REF_FRAMES][MAX_REF_FRAMES]; |
|
176 |
- |
|
177 |
-/* C bits used by mmx/sse2/altivec */ |
|
178 |
- |
|
179 |
-static av_always_inline void snow_interleave_line_header(int * i, int width, IDWTELEM * low, IDWTELEM * high){ |
|
180 |
- (*i) = (width) - 2; |
|
181 |
- |
|
182 |
- if (width & 1){ |
|
183 |
- low[(*i)+1] = low[((*i)+1)>>1]; |
|
184 |
- (*i)--; |
|
185 |
- } |
|
186 |
-} |
|
187 |
- |
|
188 |
-static av_always_inline void snow_interleave_line_footer(int * i, IDWTELEM * low, IDWTELEM * high){ |
|
189 |
- for (; (*i)>=0; (*i)-=2){ |
|
190 |
- low[(*i)+1] = high[(*i)>>1]; |
|
191 |
- low[*i] = low[(*i)>>1]; |
|
192 |
- } |
|
193 |
-} |
|
194 |
- |
|
195 |
-static av_always_inline void snow_horizontal_compose_lift_lead_out(int i, IDWTELEM * dst, IDWTELEM * src, IDWTELEM * ref, int width, int w, int lift_high, int mul, int add, int shift){ |
|
196 |
- for(; i<w; i++){ |
|
197 |
- dst[i] = src[i] - ((mul * (ref[i] + ref[i + 1]) + add) >> shift); |
|
198 |
- } |
|
199 |
- |
|
200 |
- if((width^lift_high)&1){ |
|
201 |
- dst[w] = src[w] - ((mul * 2 * ref[w] + add) >> shift); |
|
202 |
- } |
|
203 |
-} |
|
204 |
- |
|
205 |
-static av_always_inline void snow_horizontal_compose_liftS_lead_out(int i, IDWTELEM * dst, IDWTELEM * src, IDWTELEM * ref, int width, int w){ |
|
206 |
- for(; i<w; i++){ |
|
207 |
- dst[i] = src[i] + ((ref[i] + ref[(i+1)]+W_BO + 4 * src[i]) >> W_BS); |
|
208 |
- } |
|
209 |
- |
|
210 |
- if(width&1){ |
|
211 |
- dst[w] = src[w] + ((2 * ref[w] + W_BO + 4 * src[w]) >> W_BS); |
|
212 |
- } |
|
213 |
-} |
|
214 |
- |
|
215 |
-/* common code */ |
|
216 |
- |
|
217 |
-int ff_snow_common_init(AVCodecContext *avctx); |
|
218 |
-int ff_snow_common_init_after_header(AVCodecContext *avctx); |
|
219 |
-void ff_snow_common_end(SnowContext *s); |
|
220 |
-void ff_snow_release_buffer(AVCodecContext *avctx); |
|
221 |
-void ff_snow_reset_contexts(SnowContext *s); |
|
222 |
-int ff_snow_alloc_blocks(SnowContext *s); |
|
223 |
-int ff_snow_frame_start(SnowContext *s); |
|
224 |
-void ff_snow_pred_block(SnowContext *s, uint8_t *dst, uint8_t *tmp, int stride, |
|
225 |
- int sx, int sy, int b_w, int b_h, BlockNode *block, |
|
226 |
- int plane_index, int w, int h); |
|
227 |
-/* common inline functions */ |
|
228 |
-//XXX doublecheck all of them should stay inlined |
|
229 |
- |
|
230 |
-static inline void snow_set_blocks(SnowContext *s, int level, int x, int y, int l, int cb, int cr, int mx, int my, int ref, int type){ |
|
231 |
- const int w= s->b_width << s->block_max_depth; |
|
232 |
- const int rem_depth= s->block_max_depth - level; |
|
233 |
- const int index= (x + y*w) << rem_depth; |
|
234 |
- const int block_w= 1<<rem_depth; |
|
235 |
- BlockNode block; |
|
236 |
- int i,j; |
|
237 |
- |
|
238 |
- block.color[0]= l; |
|
239 |
- block.color[1]= cb; |
|
240 |
- block.color[2]= cr; |
|
241 |
- block.mx= mx; |
|
242 |
- block.my= my; |
|
243 |
- block.ref= ref; |
|
244 |
- block.type= type; |
|
245 |
- block.level= level; |
|
246 |
- |
|
247 |
- for(j=0; j<block_w; j++){ |
|
248 |
- for(i=0; i<block_w; i++){ |
|
249 |
- s->block[index + i + j*w]= block; |
|
250 |
- } |
|
251 |
- } |
|
252 |
-} |
|
253 |
- |
|
254 |
-static inline void pred_mv(SnowContext *s, int *mx, int *my, int ref, |
|
255 |
- const BlockNode *left, const BlockNode *top, const BlockNode *tr){ |
|
256 |
- if(s->ref_frames == 1){ |
|
257 |
- *mx = mid_pred(left->mx, top->mx, tr->mx); |
|
258 |
- *my = mid_pred(left->my, top->my, tr->my); |
|
259 |
- }else{ |
|
260 |
- const int *scale = ff_scale_mv_ref[ref]; |
|
261 |
- *mx = mid_pred((left->mx * scale[left->ref] + 128) >>8, |
|
262 |
- (top ->mx * scale[top ->ref] + 128) >>8, |
|
263 |
- (tr ->mx * scale[tr ->ref] + 128) >>8); |
|
264 |
- *my = mid_pred((left->my * scale[left->ref] + 128) >>8, |
|
265 |
- (top ->my * scale[top ->ref] + 128) >>8, |
|
266 |
- (tr ->my * scale[tr ->ref] + 128) >>8); |
|
267 |
- } |
|
268 |
-} |
|
269 |
- |
|
270 |
-static av_always_inline int same_block(BlockNode *a, BlockNode *b){ |
|
271 |
- if((a->type&BLOCK_INTRA) && (b->type&BLOCK_INTRA)){ |
|
272 |
- return !((a->color[0] - b->color[0]) | (a->color[1] - b->color[1]) | (a->color[2] - b->color[2])); |
|
273 |
- }else{ |
|
274 |
- return !((a->mx - b->mx) | (a->my - b->my) | (a->ref - b->ref) | ((a->type ^ b->type)&BLOCK_INTRA)); |
|
275 |
- } |
|
276 |
-} |
|
277 |
- |
|
278 |
-//FIXME name cleanup (b_w, block_w, b_width stuff) |
|
279 |
-//XXX should we really inline it? |
|
280 |
-static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer *sb, IDWTELEM *dst, uint8_t *dst8, const uint8_t *obmc, int src_x, int src_y, int b_w, int b_h, int w, int h, int dst_stride, int src_stride, int obmc_stride, int b_x, int b_y, int add, int offset_dst, int plane_index){ |
|
281 |
- const int b_width = s->b_width << s->block_max_depth; |
|
282 |
- const int b_height= s->b_height << s->block_max_depth; |
|
283 |
- const int b_stride= b_width; |
|
284 |
- BlockNode *lt= &s->block[b_x + b_y*b_stride]; |
|
285 |
- BlockNode *rt= lt+1; |
|
286 |
- BlockNode *lb= lt+b_stride; |
|
287 |
- BlockNode *rb= lb+1; |
|
288 |
- uint8_t *block[4]; |
|
289 |
- int tmp_step= src_stride >= 7*MB_SIZE ? MB_SIZE : MB_SIZE*src_stride; |
|
290 |
- uint8_t *tmp = s->scratchbuf; |
|
291 |
- uint8_t *ptmp; |
|
292 |
- int x,y; |
|
293 |
- |
|
294 |
- if(b_x<0){ |
|
295 |
- lt= rt; |
|
296 |
- lb= rb; |
|
297 |
- }else if(b_x + 1 >= b_width){ |
|
298 |
- rt= lt; |
|
299 |
- rb= lb; |
|
300 |
- } |
|
301 |
- if(b_y<0){ |
|
302 |
- lt= lb; |
|
303 |
- rt= rb; |
|
304 |
- }else if(b_y + 1 >= b_height){ |
|
305 |
- lb= lt; |
|
306 |
- rb= rt; |
|
307 |
- } |
|
308 |
- |
|
309 |
- if(src_x<0){ //FIXME merge with prev & always round internal width up to *16 |
|
310 |
- obmc -= src_x; |
|
311 |
- b_w += src_x; |
|
312 |
- if(!sliced && !offset_dst) |
|
313 |
- dst -= src_x; |
|
314 |
- src_x=0; |
|
315 |
- }else if(src_x + b_w > w){ |
|
316 |
- b_w = w - src_x; |
|
317 |
- } |
|
318 |
- if(src_y<0){ |
|
319 |
- obmc -= src_y*obmc_stride; |
|
320 |
- b_h += src_y; |
|
321 |
- if(!sliced && !offset_dst) |
|
322 |
- dst -= src_y*dst_stride; |
|
323 |
- src_y=0; |
|
324 |
- }else if(src_y + b_h> h){ |
|
325 |
- b_h = h - src_y; |
|
326 |
- } |
|
327 |
- |
|
328 |
- if(b_w<=0 || b_h<=0) return; |
|
329 |
- |
|
330 |
- assert(src_stride > 2*MB_SIZE + 5); |
|
331 |
- |
|
332 |
- if(!sliced && offset_dst) |
|
333 |
- dst += src_x + src_y*dst_stride; |
|
334 |
- dst8+= src_x + src_y*src_stride; |
|
335 |
-// src += src_x + src_y*src_stride; |
|
336 |
- |
|
337 |
- ptmp= tmp + 3*tmp_step; |
|
338 |
- block[0]= ptmp; |
|
339 |
- ptmp+=tmp_step; |
|
340 |
- ff_snow_pred_block(s, block[0], tmp, src_stride, src_x, src_y, b_w, b_h, lt, plane_index, w, h); |
|
341 |
- |
|
342 |
- if(same_block(lt, rt)){ |
|
343 |
- block[1]= block[0]; |
|
344 |
- }else{ |
|
345 |
- block[1]= ptmp; |
|
346 |
- ptmp+=tmp_step; |
|
347 |
- ff_snow_pred_block(s, block[1], tmp, src_stride, src_x, src_y, b_w, b_h, rt, plane_index, w, h); |
|
348 |
- } |
|
349 |
- |
|
350 |
- if(same_block(lt, lb)){ |
|
351 |
- block[2]= block[0]; |
|
352 |
- }else if(same_block(rt, lb)){ |
|
353 |
- block[2]= block[1]; |
|
354 |
- }else{ |
|
355 |
- block[2]= ptmp; |
|
356 |
- ptmp+=tmp_step; |
|
357 |
- ff_snow_pred_block(s, block[2], tmp, src_stride, src_x, src_y, b_w, b_h, lb, plane_index, w, h); |
|
358 |
- } |
|
359 |
- |
|
360 |
- if(same_block(lt, rb) ){ |
|
361 |
- block[3]= block[0]; |
|
362 |
- }else if(same_block(rt, rb)){ |
|
363 |
- block[3]= block[1]; |
|
364 |
- }else if(same_block(lb, rb)){ |
|
365 |
- block[3]= block[2]; |
|
366 |
- }else{ |
|
367 |
- block[3]= ptmp; |
|
368 |
- ff_snow_pred_block(s, block[3], tmp, src_stride, src_x, src_y, b_w, b_h, rb, plane_index, w, h); |
|
369 |
- } |
|
370 |
- if(sliced){ |
|
371 |
- s->dwt.inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); |
|
372 |
- }else{ |
|
373 |
- for(y=0; y<b_h; y++){ |
|
374 |
- //FIXME ugly misuse of obmc_stride |
|
375 |
- const uint8_t *obmc1= obmc + y*obmc_stride; |
|
376 |
- const uint8_t *obmc2= obmc1+ (obmc_stride>>1); |
|
377 |
- const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1); |
|
378 |
- const uint8_t *obmc4= obmc3+ (obmc_stride>>1); |
|
379 |
- for(x=0; x<b_w; x++){ |
|
380 |
- int v= obmc1[x] * block[3][x + y*src_stride] |
|
381 |
- +obmc2[x] * block[2][x + y*src_stride] |
|
382 |
- +obmc3[x] * block[1][x + y*src_stride] |
|
383 |
- +obmc4[x] * block[0][x + y*src_stride]; |
|
384 |
- |
|
385 |
- v <<= 8 - LOG2_OBMC_MAX; |
|
386 |
- if(FRAC_BITS != 8){ |
|
387 |
- v >>= 8 - FRAC_BITS; |
|
388 |
- } |
|
389 |
- if(add){ |
|
390 |
- v += dst[x + y*dst_stride]; |
|
391 |
- v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS; |
|
392 |
- if(v&(~255)) v= ~(v>>31); |
|
393 |
- dst8[x + y*src_stride] = v; |
|
394 |
- }else{ |
|
395 |
- dst[x + y*dst_stride] -= v; |
|
396 |
- } |
|
397 |
- } |
|
398 |
- } |
|
399 |
- } |
|
400 |
-} |
|
401 |
- |
|
402 |
-static av_always_inline void predict_slice(SnowContext *s, IDWTELEM *buf, int plane_index, int add, int mb_y){ |
|
403 |
- Plane *p= &s->plane[plane_index]; |
|
404 |
- const int mb_w= s->b_width << s->block_max_depth; |
|
405 |
- const int mb_h= s->b_height << s->block_max_depth; |
|
406 |
- int x, y, mb_x; |
|
407 |
- int block_size = MB_SIZE >> s->block_max_depth; |
|
408 |
- int block_w = plane_index ? block_size/2 : block_size; |
|
409 |
- const uint8_t *obmc = plane_index ? ff_obmc_tab[s->block_max_depth+1] : ff_obmc_tab[s->block_max_depth]; |
|
410 |
- const int obmc_stride= plane_index ? block_size : 2*block_size; |
|
411 |
- int ref_stride= s->current_picture.linesize[plane_index]; |
|
412 |
- uint8_t *dst8= s->current_picture.data[plane_index]; |
|
413 |
- int w= p->width; |
|
414 |
- int h= p->height; |
|
415 |
- |
|
416 |
- if(s->keyframe || (s->avctx->debug&512)){ |
|
417 |
- if(mb_y==mb_h) |
|
418 |
- return; |
|
419 |
- |
|
420 |
- if(add){ |
|
421 |
- for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){ |
|
422 |
- for(x=0; x<w; x++){ |
|
423 |
- int v= buf[x + y*w] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1)); |
|
424 |
- v >>= FRAC_BITS; |
|
425 |
- if(v&(~255)) v= ~(v>>31); |
|
426 |
- dst8[x + y*ref_stride]= v; |
|
427 |
- } |
|
428 |
- } |
|
429 |
- }else{ |
|
430 |
- for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){ |
|
431 |
- for(x=0; x<w; x++){ |
|
432 |
- buf[x + y*w]-= 128<<FRAC_BITS; |
|
433 |
- } |
|
434 |
- } |
|
435 |
- } |
|
436 |
- |
|
437 |
- return; |
|
438 |
- } |
|
439 |
- |
|
440 |
- for(mb_x=0; mb_x<=mb_w; mb_x++){ |
|
441 |
- add_yblock(s, 0, NULL, buf, dst8, obmc, |
|
442 |
- block_w*mb_x - block_w/2, |
|
443 |
- block_w*mb_y - block_w/2, |
|
444 |
- block_w, block_w, |
|
445 |
- w, h, |
|
446 |
- w, ref_stride, obmc_stride, |
|
447 |
- mb_x - 1, mb_y - 1, |
|
448 |
- add, 1, plane_index); |
|
449 |
- } |
|
450 |
-} |
|
451 |
- |
|
452 |
-static av_always_inline void predict_plane(SnowContext *s, IDWTELEM *buf, int plane_index, int add){ |
|
453 |
- const int mb_h= s->b_height << s->block_max_depth; |
|
454 |
- int mb_y; |
|
455 |
- for(mb_y=0; mb_y<=mb_h; mb_y++) |
|
456 |
- predict_slice(s, buf, plane_index, add, mb_y); |
|
457 |
-} |
|
458 |
- |
|
459 |
-static inline void set_blocks(SnowContext *s, int level, int x, int y, int l, int cb, int cr, int mx, int my, int ref, int type){ |
|
460 |
- const int w= s->b_width << s->block_max_depth; |
|
461 |
- const int rem_depth= s->block_max_depth - level; |
|
462 |
- const int index= (x + y*w) << rem_depth; |
|
463 |
- const int block_w= 1<<rem_depth; |
|
464 |
- BlockNode block; |
|
465 |
- int i,j; |
|
466 |
- |
|
467 |
- block.color[0]= l; |
|
468 |
- block.color[1]= cb; |
|
469 |
- block.color[2]= cr; |
|
470 |
- block.mx= mx; |
|
471 |
- block.my= my; |
|
472 |
- block.ref= ref; |
|
473 |
- block.type= type; |
|
474 |
- block.level= level; |
|
475 |
- |
|
476 |
- for(j=0; j<block_w; j++){ |
|
477 |
- for(i=0; i<block_w; i++){ |
|
478 |
- s->block[index + i + j*w]= block; |
|
479 |
- } |
|
480 |
- } |
|
481 |
-} |
|
482 |
- |
|
483 |
-static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){ |
|
484 |
- const int offset[3]= { |
|
485 |
- y*c-> stride + x, |
|
486 |
- ((y*c->uvstride + x)>>1), |
|
487 |
- ((y*c->uvstride + x)>>1), |
|
488 |
- }; |
|
489 |
- int i; |
|
490 |
- for(i=0; i<3; i++){ |
|
491 |
- c->src[0][i]= src [i]; |
|
492 |
- c->ref[0][i]= ref [i] + offset[i]; |
|
493 |
- } |
|
494 |
- assert(!ref_index); |
|
495 |
-} |
|
496 |
- |
|
497 |
- |
|
498 |
-/* bitstream functions */ |
|
499 |
- |
|
500 |
-extern const int8_t ff_quant3bA[256]; |
|
501 |
- |
|
502 |
-#define QEXPSHIFT (7-FRAC_BITS+8) //FIXME try to change this to 0 |
|
503 |
- |
|
504 |
-static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed){ |
|
505 |
- int i; |
|
506 |
- |
|
507 |
- if(v){ |
|
508 |
- const int a= FFABS(v); |
|
509 |
- const int e= av_log2(a); |
|
510 |
- const int el= FFMIN(e, 10); |
|
511 |
- put_rac(c, state+0, 0); |
|
512 |
- |
|
513 |
- for(i=0; i<el; i++){ |
|
514 |
- put_rac(c, state+1+i, 1); //1..10 |
|
515 |
- } |
|
516 |
- for(; i<e; i++){ |
|
517 |
- put_rac(c, state+1+9, 1); //1..10 |
|
518 |
- } |
|
519 |
- put_rac(c, state+1+FFMIN(i,9), 0); |
|
520 |
- |
|
521 |
- for(i=e-1; i>=el; i--){ |
|
522 |
- put_rac(c, state+22+9, (a>>i)&1); //22..31 |
|
523 |
- } |
|
524 |
- for(; i>=0; i--){ |
|
525 |
- put_rac(c, state+22+i, (a>>i)&1); //22..31 |
|
526 |
- } |
|
527 |
- |
|
528 |
- if(is_signed) |
|
529 |
- put_rac(c, state+11 + el, v < 0); //11..21 |
|
530 |
- }else{ |
|
531 |
- put_rac(c, state+0, 1); |
|
532 |
- } |
|
533 |
-} |
|
534 |
- |
|
535 |
-static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){ |
|
536 |
- if(get_rac(c, state+0)) |
|
537 |
- return 0; |
|
538 |
- else{ |
|
539 |
- int i, e, a; |
|
540 |
- e= 0; |
|
541 |
- while(get_rac(c, state+1 + FFMIN(e,9))){ //1..10 |
|
542 |
- e++; |
|
543 |
- } |
|
544 |
- |
|
545 |
- a= 1; |
|
546 |
- for(i=e-1; i>=0; i--){ |
|
547 |
- a += a + get_rac(c, state+22 + FFMIN(i,9)); //22..31 |
|
548 |
- } |
|
549 |
- |
|
550 |
- e= -(is_signed && get_rac(c, state+11 + FFMIN(e,10))); //11..21 |
|
551 |
- return (a^e)-e; |
|
552 |
- } |
|
553 |
-} |
|
554 |
- |
|
555 |
-static inline void put_symbol2(RangeCoder *c, uint8_t *state, int v, int log2){ |
|
556 |
- int i; |
|
557 |
- int r= log2>=0 ? 1<<log2 : 1; |
|
558 |
- |
|
559 |
- assert(v>=0); |
|
560 |
- assert(log2>=-4); |
|
561 |
- |
|
562 |
- while(v >= r){ |
|
563 |
- put_rac(c, state+4+log2, 1); |
|
564 |
- v -= r; |
|
565 |
- log2++; |
|
566 |
- if(log2>0) r+=r; |
|
567 |
- } |
|
568 |
- put_rac(c, state+4+log2, 0); |
|
569 |
- |
|
570 |
- for(i=log2-1; i>=0; i--){ |
|
571 |
- put_rac(c, state+31-i, (v>>i)&1); |
|
572 |
- } |
|
573 |
-} |
|
574 |
- |
|
575 |
-static inline int get_symbol2(RangeCoder *c, uint8_t *state, int log2){ |
|
576 |
- int i; |
|
577 |
- int r= log2>=0 ? 1<<log2 : 1; |
|
578 |
- int v=0; |
|
579 |
- |
|
580 |
- assert(log2>=-4); |
|
581 |
- |
|
582 |
- while(get_rac(c, state+4+log2)){ |
|
583 |
- v+= r; |
|
584 |
- log2++; |
|
585 |
- if(log2>0) r+=r; |
|
586 |
- } |
|
587 |
- |
|
588 |
- for(i=log2-1; i>=0; i--){ |
|
589 |
- v+= get_rac(c, state+31-i)<<i; |
|
590 |
- } |
|
591 |
- |
|
592 |
- return v; |
|
593 |
-} |
|
594 |
- |
|
595 |
-static inline void unpack_coeffs(SnowContext *s, SubBand *b, SubBand * parent, int orientation){ |
|
596 |
- const int w= b->width; |
|
597 |
- const int h= b->height; |
|
598 |
- int x,y; |
|
599 |
- |
|
600 |
- int run, runs; |
|
601 |
- x_and_coeff *xc= b->x_coeff; |
|
602 |
- x_and_coeff *prev_xc= NULL; |
|
603 |
- x_and_coeff *prev2_xc= xc; |
|
604 |
- x_and_coeff *parent_xc= parent ? parent->x_coeff : NULL; |
|
605 |
- x_and_coeff *prev_parent_xc= parent_xc; |
|
606 |
- |
|
607 |
- runs= get_symbol2(&s->c, b->state[30], 0); |
|
608 |
- if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3); |
|
609 |
- else run= INT_MAX; |
|
610 |
- |
|
611 |
- for(y=0; y<h; y++){ |
|
612 |
- int v=0; |
|
613 |
- int lt=0, t=0, rt=0; |
|
614 |
- |
|
615 |
- if(y && prev_xc->x == 0){ |
|
616 |
- rt= prev_xc->coeff; |
|
617 |
- } |
|
618 |
- for(x=0; x<w; x++){ |
|
619 |
- int p=0; |
|
620 |
- const int l= v; |
|
621 |
- |
|
622 |
- lt= t; t= rt; |
|
623 |
- |
|
624 |
- if(y){ |
|
625 |
- if(prev_xc->x <= x) |
|
626 |
- prev_xc++; |
|
627 |
- if(prev_xc->x == x + 1) |
|
628 |
- rt= prev_xc->coeff; |
|
629 |
- else |
|
630 |
- rt=0; |
|
631 |
- } |
|
632 |
- if(parent_xc){ |
|
633 |
- if(x>>1 > parent_xc->x){ |
|
634 |
- parent_xc++; |
|
635 |
- } |
|
636 |
- if(x>>1 == parent_xc->x){ |
|
637 |
- p= parent_xc->coeff; |
|
638 |
- } |
|
639 |
- } |
|
640 |
- if(/*ll|*/l|lt|t|rt|p){ |
|
641 |
- int context= av_log2(/*FFABS(ll) + */3*(l>>1) + (lt>>1) + (t&~1) + (rt>>1) + (p>>1)); |
|
642 |
- |
|
643 |
- v=get_rac(&s->c, &b->state[0][context]); |
|
644 |
- if(v){ |
|
645 |
- v= 2*(get_symbol2(&s->c, b->state[context + 2], context-4) + 1); |
|
646 |
- v+=get_rac(&s->c, &b->state[0][16 + 1 + 3 + ff_quant3bA[l&0xFF] + 3*ff_quant3bA[t&0xFF]]); |
|
647 |
- |
|
648 |
- xc->x=x; |
|
649 |
- (xc++)->coeff= v; |
|
650 |
- } |
|
651 |
- }else{ |
|
652 |
- if(!run){ |
|
653 |
- if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3); |
|
654 |
- else run= INT_MAX; |
|
655 |
- v= 2*(get_symbol2(&s->c, b->state[0 + 2], 0-4) + 1); |
|
656 |
- v+=get_rac(&s->c, &b->state[0][16 + 1 + 3]); |
|
657 |
- |
|
658 |
- xc->x=x; |
|
659 |
- (xc++)->coeff= v; |
|
660 |
- }else{ |
|
661 |
- int max_run; |
|
662 |
- run--; |
|
663 |
- v=0; |
|
664 |
- |
|
665 |
- if(y) max_run= FFMIN(run, prev_xc->x - x - 2); |
|
666 |
- else max_run= FFMIN(run, w-x-1); |
|
667 |
- if(parent_xc) |
|
668 |
- max_run= FFMIN(max_run, 2*parent_xc->x - x - 1); |
|
669 |
- x+= max_run; |
|
670 |
- run-= max_run; |
|
671 |
- } |
|
672 |
- } |
|
673 |
- } |
|
674 |
- (xc++)->x= w+1; //end marker |
|
675 |
- prev_xc= prev2_xc; |
|
676 |
- prev2_xc= xc; |
|
677 |
- |
|
678 |
- if(parent_xc){ |
|
679 |
- if(y&1){ |
|
680 |
- while(parent_xc->x != parent->width+1) |
|
681 |
- parent_xc++; |
|
682 |
- parent_xc++; |
|
683 |
- prev_parent_xc= parent_xc; |
|
684 |
- }else{ |
|
685 |
- parent_xc= prev_parent_xc; |
|
686 |
- } |
|
687 |
- } |
|
688 |
- } |
|
689 |
- |
|
690 |
- (xc++)->x= w+1; //end marker |
|
691 |
-} |
|
692 |
- |
|
693 |
-#endif /* AVCODEC_SNOW_H */ |
694 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,132 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at> |
|
3 |
- * Copyright (C) 2006 Robert Edele <yartrebo@earthlink.net> |
|
4 |
- * |
|
5 |
- * This file is part of Libav. |
|
6 |
- * |
|
7 |
- * Libav is free software; you can redistribute it and/or |
|
8 |
- * modify it under the terms of the GNU Lesser General Public |
|
9 |
- * License as published by the Free Software Foundation; either |
|
10 |
- * version 2.1 of the License, or (at your option) any later version. |
|
11 |
- * |
|
12 |
- * Libav is distributed in the hope that it will be useful, |
|
13 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 |
- * Lesser General Public License for more details. |
|
16 |
- * |
|
17 |
- * You should have received a copy of the GNU Lesser General Public |
|
18 |
- * License along with Libav; if not, write to the Free Software |
|
19 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
20 |
- */ |
|
21 |
- |
|
22 |
-#ifndef AVCODEC_SNOWDATA_H |
|
23 |
-#define AVCODEC_SNOWDATA_H |
|
24 |
- |
|
25 |
-#include "snow.h" |
|
26 |
- |
|
27 |
-static const uint8_t obmc32[1024]={ |
|
28 |
- 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, |
|
29 |
- 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0, |
|
30 |
- 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0, |
|
31 |
- 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0, |
|
32 |
- 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4, |
|
33 |
- 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4, |
|
34 |
- 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4, |
|
35 |
- 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4, |
|
36 |
- 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4, |
|
37 |
- 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4, |
|
38 |
- 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4, |
|
39 |
- 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4, |
|
40 |
- 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8, |
|
41 |
- 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8, |
|
42 |
- 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8, |
|
43 |
- 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8, |
|
44 |
- 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8, |
|
45 |
- 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8, |
|
46 |
- 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8, |
|
47 |
- 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8, |
|
48 |
- 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4, |
|
49 |
- 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4, |
|
50 |
- 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4, |
|
51 |
- 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4, |
|
52 |
- 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4, |
|
53 |
- 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4, |
|
54 |
- 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4, |
|
55 |
- 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4, |
|
56 |
- 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0, |
|
57 |
- 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0, |
|
58 |
- 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0, |
|
59 |
- 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, |
|
60 |
- //error:0.000020 |
|
61 |
-}; |
|
62 |
-static const uint8_t obmc16[256]={ |
|
63 |
- 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0, |
|
64 |
- 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4, |
|
65 |
- 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4, |
|
66 |
- 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8, |
|
67 |
- 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8, |
|
68 |
- 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12, |
|
69 |
- 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12, |
|
70 |
- 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16, |
|
71 |
- 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16, |
|
72 |
- 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12, |
|
73 |
- 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12, |
|
74 |
- 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8, |
|
75 |
- 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8, |
|
76 |
- 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4, |
|
77 |
- 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4, |
|
78 |
- 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0, |
|
79 |
-//error:0.000015 |
|
80 |
-}; |
|
81 |
- |
|
82 |
-//linear *64 |
|
83 |
-static const uint8_t obmc8[64]={ |
|
84 |
- 4, 12, 20, 28, 28, 20, 12, 4, |
|
85 |
- 12, 36, 60, 84, 84, 60, 36, 12, |
|
86 |
- 20, 60,100,140,140,100, 60, 20, |
|
87 |
- 28, 84,140,196,196,140, 84, 28, |
|
88 |
- 28, 84,140,196,196,140, 84, 28, |
|
89 |
- 20, 60,100,140,140,100, 60, 20, |
|
90 |
- 12, 36, 60, 84, 84, 60, 36, 12, |
|
91 |
- 4, 12, 20, 28, 28, 20, 12, 4, |
|
92 |
-//error:0.000000 |
|
93 |
-}; |
|
94 |
- |
|
95 |
-//linear *64 |
|
96 |
-static const uint8_t obmc4[16]={ |
|
97 |
- 16, 48, 48, 16, |
|
98 |
- 48,144,144, 48, |
|
99 |
- 48,144,144, 48, |
|
100 |
- 16, 48, 48, 16, |
|
101 |
-//error:0.000000 |
|
102 |
-}; |
|
103 |
- |
|
104 |
-const int8_t ff_quant3bA[256]={ |
|
105 |
- 0, 0, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
106 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
107 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
108 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
109 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
110 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
111 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
112 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
113 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
114 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
115 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
116 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
117 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
118 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
119 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
120 |
- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, |
|
121 |
-}; |
|
122 |
- |
|
123 |
-const uint8_t * const ff_obmc_tab[4]= { |
|
124 |
- obmc32, obmc16, obmc8, obmc4 |
|
125 |
-}; |
|
126 |
- |
|
127 |
-/* runtime generated tables */ |
|
128 |
-uint8_t ff_qexp[QROOT]; |
|
129 |
-int ff_scale_mv_ref[MAX_REF_FRAMES][MAX_REF_FRAMES]; |
|
130 |
- |
|
131 |
- |
|
132 |
-#endif /* AVCODEC_SNOW_H */ |
133 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,576 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at> |
|
3 |
- * |
|
4 |
- * This file is part of Libav. |
|
5 |
- * |
|
6 |
- * Libav 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.1 of the License, or (at your option) any later version. |
|
10 |
- * |
|
11 |
- * Libav 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 Libav; if not, write to the Free Software |
|
18 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
- */ |
|
20 |
- |
|
21 |
-#include "libavutil/intmath.h" |
|
22 |
-#include "libavutil/log.h" |
|
23 |
-#include "libavutil/opt.h" |
|
24 |
-#include "avcodec.h" |
|
25 |
-#include "dsputil.h" |
|
26 |
-#include "dwt.h" |
|
27 |
-#include "internal.h" |
|
28 |
-#include "snow.h" |
|
29 |
- |
|
30 |
-#include "rangecoder.h" |
|
31 |
-#include "mathops.h" |
|
32 |
- |
|
33 |
-#include "mpegvideo.h" |
|
34 |
-#include "h263.h" |
|
35 |
- |
|
36 |
-#undef NDEBUG |
|
37 |
-#include <assert.h> |
|
38 |
- |
|
39 |
-static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer * sb, IDWTELEM * old_buffer, int plane_index, int add, int mb_y){ |
|
40 |
- Plane *p= &s->plane[plane_index]; |
|
41 |
- const int mb_w= s->b_width << s->block_max_depth; |
|
42 |
- const int mb_h= s->b_height << s->block_max_depth; |
|
43 |
- int x, y, mb_x; |
|
44 |
- int block_size = MB_SIZE >> s->block_max_depth; |
|
45 |
- int block_w = plane_index ? block_size/2 : block_size; |
|
46 |
- const uint8_t *obmc = plane_index ? ff_obmc_tab[s->block_max_depth+1] : ff_obmc_tab[s->block_max_depth]; |
|
47 |
- int obmc_stride= plane_index ? block_size : 2*block_size; |
|
48 |
- int ref_stride= s->current_picture.linesize[plane_index]; |
|
49 |
- uint8_t *dst8= s->current_picture.data[plane_index]; |
|
50 |
- int w= p->width; |
|
51 |
- int h= p->height; |
|
52 |
- |
|
53 |
- if(s->keyframe || (s->avctx->debug&512)){ |
|
54 |
- if(mb_y==mb_h) |
|
55 |
- return; |
|
56 |
- |
|
57 |
- if(add){ |
|
58 |
- for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){ |
|
59 |
-// DWTELEM * line = slice_buffer_get_line(sb, y); |
|
60 |
- IDWTELEM * line = sb->line[y]; |
|
61 |
- for(x=0; x<w; x++){ |
|
62 |
-// int v= buf[x + y*w] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1)); |
|
63 |
- int v= line[x] + (128<<FRAC_BITS) + (1<<(FRAC_BITS-1)); |
|
64 |
- v >>= FRAC_BITS; |
|
65 |
- if(v&(~255)) v= ~(v>>31); |
|
66 |
- dst8[x + y*ref_stride]= v; |
|
67 |
- } |
|
68 |
- } |
|
69 |
- }else{ |
|
70 |
- for(y=block_w*mb_y; y<FFMIN(h,block_w*(mb_y+1)); y++){ |
|
71 |
-// DWTELEM * line = slice_buffer_get_line(sb, y); |
|
72 |
- IDWTELEM * line = sb->line[y]; |
|
73 |
- for(x=0; x<w; x++){ |
|
74 |
- line[x] -= 128 << FRAC_BITS; |
|
75 |
-// buf[x + y*w]-= 128<<FRAC_BITS; |
|
76 |
- } |
|
77 |
- } |
|
78 |
- } |
|
79 |
- |
|
80 |
- return; |
|
81 |
- } |
|
82 |
- |
|
83 |
- for(mb_x=0; mb_x<=mb_w; mb_x++){ |
|
84 |
- add_yblock(s, 1, sb, old_buffer, dst8, obmc, |
|
85 |
- block_w*mb_x - block_w/2, |
|
86 |
- block_w*mb_y - block_w/2, |
|
87 |
- block_w, block_w, |
|
88 |
- w, h, |
|
89 |
- w, ref_stride, obmc_stride, |
|
90 |
- mb_x - 1, mb_y - 1, |
|
91 |
- add, 0, plane_index); |
|
92 |
- } |
|
93 |
-} |
|
94 |
- |
|
95 |
-static inline void decode_subband_slice_buffered(SnowContext *s, SubBand *b, slice_buffer * sb, int start_y, int h, int save_state[1]){ |
|
96 |
- const int w= b->width; |
|
97 |
- int y; |
|
98 |
- const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); |
|
99 |
- int qmul= ff_qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); |
|
100 |
- int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; |
|
101 |
- int new_index = 0; |
|
102 |
- |
|
103 |
- if(b->ibuf == s->spatial_idwt_buffer || s->qlog == LOSSLESS_QLOG){ |
|
104 |
- qadd= 0; |
|
105 |
- qmul= 1<<QEXPSHIFT; |
|
106 |
- } |
|
107 |
- |
|
108 |
- /* If we are on the second or later slice, restore our index. */ |
|
109 |
- if (start_y != 0) |
|
110 |
- new_index = save_state[0]; |
|
111 |
- |
|
112 |
- |
|
113 |
- for(y=start_y; y<h; y++){ |
|
114 |
- int x = 0; |
|
115 |
- int v; |
|
116 |
- IDWTELEM * line = slice_buffer_get_line(sb, y * b->stride_line + b->buf_y_offset) + b->buf_x_offset; |
|
117 |
- memset(line, 0, b->width*sizeof(IDWTELEM)); |
|
118 |
- v = b->x_coeff[new_index].coeff; |
|
119 |
- x = b->x_coeff[new_index++].x; |
|
120 |
- while(x < w){ |
|
121 |
- register int t= ( (v>>1)*qmul + qadd)>>QEXPSHIFT; |
|
122 |
- register int u= -(v&1); |
|
123 |
- line[x] = (t^u) - u; |
|
124 |
- |
|
125 |
- v = b->x_coeff[new_index].coeff; |
|
126 |
- x = b->x_coeff[new_index++].x; |
|
127 |
- } |
|
128 |
- } |
|
129 |
- |
|
130 |
- /* Save our variables for the next slice. */ |
|
131 |
- save_state[0] = new_index; |
|
132 |
- |
|
133 |
- return; |
|
134 |
-} |
|
135 |
- |
|
136 |
-static int decode_q_branch(SnowContext *s, int level, int x, int y){ |
|
137 |
- const int w= s->b_width << s->block_max_depth; |
|
138 |
- const int rem_depth= s->block_max_depth - level; |
|
139 |
- const int index= (x + y*w) << rem_depth; |
|
140 |
- int trx= (x+1)<<rem_depth; |
|
141 |
- const BlockNode *left = x ? &s->block[index-1] : &null_block; |
|
142 |
- const BlockNode *top = y ? &s->block[index-w] : &null_block; |
|
143 |
- const BlockNode *tl = y && x ? &s->block[index-w-1] : left; |
|
144 |
- const BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt |
|
145 |
- int s_context= 2*left->level + 2*top->level + tl->level + tr->level; |
|
146 |
- int res; |
|
147 |
- |
|
148 |
- if(s->keyframe){ |
|
149 |
- set_blocks(s, level, x, y, null_block.color[0], null_block.color[1], null_block.color[2], null_block.mx, null_block.my, null_block.ref, BLOCK_INTRA); |
|
150 |
- return 0; |
|
151 |
- } |
|
152 |
- |
|
153 |
- if(level==s->block_max_depth || get_rac(&s->c, &s->block_state[4 + s_context])){ |
|
154 |
- int type, mx, my; |
|
155 |
- int l = left->color[0]; |
|
156 |
- int cb= left->color[1]; |
|
157 |
- int cr= left->color[2]; |
|
158 |
- int ref = 0; |
|
159 |
- int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); |
|
160 |
- int mx_context= av_log2(2*FFABS(left->mx - top->mx)) + 0*av_log2(2*FFABS(tr->mx - top->mx)); |
|
161 |
- int my_context= av_log2(2*FFABS(left->my - top->my)) + 0*av_log2(2*FFABS(tr->my - top->my)); |
|
162 |
- |
|
163 |
- type= get_rac(&s->c, &s->block_state[1 + left->type + top->type]) ? BLOCK_INTRA : 0; |
|
164 |
- |
|
165 |
- if(type){ |
|
166 |
- pred_mv(s, &mx, &my, 0, left, top, tr); |
|
167 |
- l += get_symbol(&s->c, &s->block_state[32], 1); |
|
168 |
- cb+= get_symbol(&s->c, &s->block_state[64], 1); |
|
169 |
- cr+= get_symbol(&s->c, &s->block_state[96], 1); |
|
170 |
- }else{ |
|
171 |
- if(s->ref_frames > 1) |
|
172 |
- ref= get_symbol(&s->c, &s->block_state[128 + 1024 + 32*ref_context], 0); |
|
173 |
- if (ref >= s->ref_frames) { |
|
174 |
- av_log(s->avctx, AV_LOG_ERROR, "Invalid ref\n"); |
|
175 |
- return AVERROR_INVALIDDATA; |
|
176 |
- } |
|
177 |
- pred_mv(s, &mx, &my, ref, left, top, tr); |
|
178 |
- mx+= get_symbol(&s->c, &s->block_state[128 + 32*(mx_context + 16*!!ref)], 1); |
|
179 |
- my+= get_symbol(&s->c, &s->block_state[128 + 32*(my_context + 16*!!ref)], 1); |
|
180 |
- } |
|
181 |
- set_blocks(s, level, x, y, l, cb, cr, mx, my, ref, type); |
|
182 |
- }else{ |
|
183 |
- if ((res = decode_q_branch(s, level+1, 2*x+0, 2*y+0)) < 0 || |
|
184 |
- (res = decode_q_branch(s, level+1, 2*x+1, 2*y+0)) < 0 || |
|
185 |
- (res = decode_q_branch(s, level+1, 2*x+0, 2*y+1)) < 0 || |
|
186 |
- (res = decode_q_branch(s, level+1, 2*x+1, 2*y+1)) < 0) |
|
187 |
- return res; |
|
188 |
- } |
|
189 |
- return 0; |
|
190 |
-} |
|
191 |
- |
|
192 |
-static void dequantize_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int start_y, int end_y){ |
|
193 |
- const int w= b->width; |
|
194 |
- const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); |
|
195 |
- const int qmul= ff_qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); |
|
196 |
- const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; |
|
197 |
- int x,y; |
|
198 |
- |
|
199 |
- if(s->qlog == LOSSLESS_QLOG) return; |
|
200 |
- |
|
201 |
- for(y=start_y; y<end_y; y++){ |
|
202 |
-// DWTELEM * line = slice_buffer_get_line_from_address(sb, src + (y * stride)); |
|
203 |
- IDWTELEM * line = slice_buffer_get_line(sb, (y * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; |
|
204 |
- for(x=0; x<w; x++){ |
|
205 |
- int i= line[x]; |
|
206 |
- if(i<0){ |
|
207 |
- line[x]= -((-i*qmul + qadd)>>(QEXPSHIFT)); //FIXME try different bias |
|
208 |
- }else if(i>0){ |
|
209 |
- line[x]= (( i*qmul + qadd)>>(QEXPSHIFT)); |
|
210 |
- } |
|
211 |
- } |
|
212 |
- } |
|
213 |
-} |
|
214 |
- |
|
215 |
-static void correlate_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median, int start_y, int end_y){ |
|
216 |
- const int w= b->width; |
|
217 |
- int x,y; |
|
218 |
- |
|
219 |
- IDWTELEM * line=0; // silence silly "could be used without having been initialized" warning |
|
220 |
- IDWTELEM * prev; |
|
221 |
- |
|
222 |
- if (start_y != 0) |
|
223 |
- line = slice_buffer_get_line(sb, ((start_y - 1) * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; |
|
224 |
- |
|
225 |
- for(y=start_y; y<end_y; y++){ |
|
226 |
- prev = line; |
|
227 |
-// line = slice_buffer_get_line_from_address(sb, src + (y * stride)); |
|
228 |
- line = slice_buffer_get_line(sb, (y * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; |
|
229 |
- for(x=0; x<w; x++){ |
|
230 |
- if(x){ |
|
231 |
- if(use_median){ |
|
232 |
- if(y && x+1<w) line[x] += mid_pred(line[x - 1], prev[x], prev[x + 1]); |
|
233 |
- else line[x] += line[x - 1]; |
|
234 |
- }else{ |
|
235 |
- if(y) line[x] += mid_pred(line[x - 1], prev[x], line[x - 1] + prev[x] - prev[x - 1]); |
|
236 |
- else line[x] += line[x - 1]; |
|
237 |
- } |
|
238 |
- }else{ |
|
239 |
- if(y) line[x] += prev[x]; |
|
240 |
- } |
|
241 |
- } |
|
242 |
- } |
|
243 |
-} |
|
244 |
- |
|
245 |
-static void decode_qlogs(SnowContext *s){ |
|
246 |
- int plane_index, level, orientation; |
|
247 |
- |
|
248 |
- for(plane_index=0; plane_index<3; plane_index++){ |
|
249 |
- for(level=0; level<s->spatial_decomposition_count; level++){ |
|
250 |
- for(orientation=level ? 1:0; orientation<4; orientation++){ |
|
251 |
- int q; |
|
252 |
- if (plane_index==2) q= s->plane[1].band[level][orientation].qlog; |
|
253 |
- else if(orientation==2) q= s->plane[plane_index].band[level][1].qlog; |
|
254 |
- else q= get_symbol(&s->c, s->header_state, 1); |
|
255 |
- s->plane[plane_index].band[level][orientation].qlog= q; |
|
256 |
- } |
|
257 |
- } |
|
258 |
- } |
|
259 |
-} |
|
260 |
- |
|
261 |
-#define GET_S(dst, check) \ |
|
262 |
- tmp= get_symbol(&s->c, s->header_state, 0);\ |
|
263 |
- if(!(check)){\ |
|
264 |
- av_log(s->avctx, AV_LOG_ERROR, "Error " #dst " is %d\n", tmp);\ |
|
265 |
- return -1;\ |
|
266 |
- }\ |
|
267 |
- dst= tmp; |
|
268 |
- |
|
269 |
-static int decode_header(SnowContext *s){ |
|
270 |
- int plane_index, tmp; |
|
271 |
- uint8_t kstate[32]; |
|
272 |
- |
|
273 |
- memset(kstate, MID_STATE, sizeof(kstate)); |
|
274 |
- |
|
275 |
- s->keyframe= get_rac(&s->c, kstate); |
|
276 |
- if(s->keyframe || s->always_reset){ |
|
277 |
- ff_snow_reset_contexts(s); |
|
278 |
- s->spatial_decomposition_type= |
|
279 |
- s->qlog= |
|
280 |
- s->qbias= |
|
281 |
- s->mv_scale= |
|
282 |
- s->block_max_depth= 0; |
|
283 |
- } |
|
284 |
- if(s->keyframe){ |
|
285 |
- GET_S(s->version, tmp <= 0U) |
|
286 |
- s->always_reset= get_rac(&s->c, s->header_state); |
|
287 |
- s->temporal_decomposition_type= get_symbol(&s->c, s->header_state, 0); |
|
288 |
- s->temporal_decomposition_count= get_symbol(&s->c, s->header_state, 0); |
|
289 |
- GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS) |
|
290 |
- s->colorspace_type= get_symbol(&s->c, s->header_state, 0); |
|
291 |
- s->chroma_h_shift= get_symbol(&s->c, s->header_state, 0); |
|
292 |
- s->chroma_v_shift= get_symbol(&s->c, s->header_state, 0); |
|
293 |
- s->spatial_scalability= get_rac(&s->c, s->header_state); |
|
294 |
-// s->rate_scalability= get_rac(&s->c, s->header_state); |
|
295 |
- GET_S(s->max_ref_frames, tmp < (unsigned)MAX_REF_FRAMES) |
|
296 |
- s->max_ref_frames++; |
|
297 |
- |
|
298 |
- decode_qlogs(s); |
|
299 |
- } |
|
300 |
- |
|
301 |
- if(!s->keyframe){ |
|
302 |
- if(get_rac(&s->c, s->header_state)){ |
|
303 |
- for(plane_index=0; plane_index<2; plane_index++){ |
|
304 |
- int htaps, i, sum=0; |
|
305 |
- Plane *p= &s->plane[plane_index]; |
|
306 |
- p->diag_mc= get_rac(&s->c, s->header_state); |
|
307 |
- htaps= get_symbol(&s->c, s->header_state, 0)*2 + 2; |
|
308 |
- if((unsigned)htaps > HTAPS_MAX || htaps==0) |
|
309 |
- return -1; |
|
310 |
- p->htaps= htaps; |
|
311 |
- for(i= htaps/2; i; i--){ |
|
312 |
- p->hcoeff[i]= get_symbol(&s->c, s->header_state, 0) * (1-2*(i&1)); |
|
313 |
- sum += p->hcoeff[i]; |
|
314 |
- } |
|
315 |
- p->hcoeff[0]= 32-sum; |
|
316 |
- } |
|
317 |
- s->plane[2].diag_mc= s->plane[1].diag_mc; |
|
318 |
- s->plane[2].htaps = s->plane[1].htaps; |
|
319 |
- memcpy(s->plane[2].hcoeff, s->plane[1].hcoeff, sizeof(s->plane[1].hcoeff)); |
|
320 |
- } |
|
321 |
- if(get_rac(&s->c, s->header_state)){ |
|
322 |
- GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS) |
|
323 |
- decode_qlogs(s); |
|
324 |
- } |
|
325 |
- } |
|
326 |
- |
|
327 |
- s->spatial_decomposition_type+= get_symbol(&s->c, s->header_state, 1); |
|
328 |
- if(s->spatial_decomposition_type > 1U){ |
|
329 |
- av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported", s->spatial_decomposition_type); |
|
330 |
- return -1; |
|
331 |
- } |
|
332 |
- if(FFMIN(s->avctx-> width>>s->chroma_h_shift, |
|
333 |
- s->avctx->height>>s->chroma_v_shift) >> (s->spatial_decomposition_count-1) <= 0){ |
|
334 |
- av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_count %d too large for size", s->spatial_decomposition_count); |
|
335 |
- return -1; |
|
336 |
- } |
|
337 |
- |
|
338 |
- if (s->chroma_h_shift != 1 || s->chroma_v_shift != 1) { |
|
339 |
- av_log(s->avctx, AV_LOG_ERROR, "Invalid chroma shift\n"); |
|
340 |
- return AVERROR_PATCHWELCOME; |
|
341 |
- } |
|
342 |
- |
|
343 |
- s->qlog += get_symbol(&s->c, s->header_state, 1); |
|
344 |
- s->mv_scale += get_symbol(&s->c, s->header_state, 1); |
|
345 |
- s->qbias += get_symbol(&s->c, s->header_state, 1); |
|
346 |
- s->block_max_depth+= get_symbol(&s->c, s->header_state, 1); |
|
347 |
- if(s->block_max_depth > 1 || s->block_max_depth < 0){ |
|
348 |
- av_log(s->avctx, AV_LOG_ERROR, "block_max_depth= %d is too large", s->block_max_depth); |
|
349 |
- s->block_max_depth= 0; |
|
350 |
- return -1; |
|
351 |
- } |
|
352 |
- |
|
353 |
- return 0; |
|
354 |
-} |
|
355 |
- |
|
356 |
-static av_cold int decode_init(AVCodecContext *avctx) |
|
357 |
-{ |
|
358 |
- int ret; |
|
359 |
- |
|
360 |
- avctx->pix_fmt= AV_PIX_FMT_YUV420P; |
|
361 |
- |
|
362 |
- if ((ret = ff_snow_common_init(avctx)) < 0) { |
|
363 |
- ff_snow_common_end(avctx->priv_data); |
|
364 |
- return ret; |
|
365 |
- } |
|
366 |
- |
|
367 |
- return 0; |
|
368 |
-} |
|
369 |
- |
|
370 |
-static int decode_blocks(SnowContext *s){ |
|
371 |
- int x, y; |
|
372 |
- int w= s->b_width; |
|
373 |
- int h= s->b_height; |
|
374 |
- int res; |
|
375 |
- |
|
376 |
- for(y=0; y<h; y++){ |
|
377 |
- for(x=0; x<w; x++){ |
|
378 |
- if ((res = decode_q_branch(s, 0, x, y)) < 0) |
|
379 |
- return res; |
|
380 |
- } |
|
381 |
- } |
|
382 |
- return 0; |
|
383 |
-} |
|
384 |
- |
|
385 |
-static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, |
|
386 |
- AVPacket *avpkt) |
|
387 |
-{ |
|
388 |
- const uint8_t *buf = avpkt->data; |
|
389 |
- int buf_size = avpkt->size; |
|
390 |
- SnowContext *s = avctx->priv_data; |
|
391 |
- RangeCoder * const c= &s->c; |
|
392 |
- int bytes_read; |
|
393 |
- AVFrame *picture = data; |
|
394 |
- int level, orientation, plane_index; |
|
395 |
- int res; |
|
396 |
- |
|
397 |
- ff_init_range_decoder(c, buf, buf_size); |
|
398 |
- ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); |
|
399 |
- |
|
400 |
- s->current_picture.pict_type= AV_PICTURE_TYPE_I; //FIXME I vs. P |
|
401 |
- if(decode_header(s)<0) |
|
402 |
- return -1; |
|
403 |
- ff_snow_common_init_after_header(avctx); |
|
404 |
- |
|
405 |
- // realloc slice buffer for the case that spatial_decomposition_count changed |
|
406 |
- ff_slice_buffer_destroy(&s->sb); |
|
407 |
- if ((res = ff_slice_buffer_init(&s->sb, s->plane[0].height, |
|
408 |
- (MB_SIZE >> s->block_max_depth) + |
|
409 |
- s->spatial_decomposition_count * 8 + 1, |
|
410 |
- s->plane[0].width, |
|
411 |
- s->spatial_idwt_buffer)) < 0) |
|
412 |
- return res; |
|
413 |
- |
|
414 |
- for(plane_index=0; plane_index<3; plane_index++){ |
|
415 |
- Plane *p= &s->plane[plane_index]; |
|
416 |
- p->fast_mc= p->diag_mc && p->htaps==6 && p->hcoeff[0]==40 |
|
417 |
- && p->hcoeff[1]==-10 |
|
418 |
- && p->hcoeff[2]==2; |
|
419 |
- } |
|
420 |
- |
|
421 |
- ff_snow_alloc_blocks(s); |
|
422 |
- |
|
423 |
- if(ff_snow_frame_start(s) < 0) |
|
424 |
- return -1; |
|
425 |
- //keyframe flag duplication mess FIXME |
|
426 |
- if(avctx->debug&FF_DEBUG_PICT_INFO) |
|
427 |
- av_log(avctx, AV_LOG_ERROR, "keyframe:%d qlog:%d\n", s->keyframe, s->qlog); |
|
428 |
- |
|
429 |
- if ((res = decode_blocks(s)) < 0) |
|
430 |
- return res; |
|
431 |
- |
|
432 |
- for(plane_index=0; plane_index<3; plane_index++){ |
|
433 |
- Plane *p= &s->plane[plane_index]; |
|
434 |
- int w= p->width; |
|
435 |
- int h= p->height; |
|
436 |
- int x, y; |
|
437 |
- int decode_state[MAX_DECOMPOSITIONS][4][1]; /* Stored state info for unpack_coeffs. 1 variable per instance. */ |
|
438 |
- |
|
439 |
- if(s->avctx->debug&2048){ |
|
440 |
- memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h); |
|
441 |
- predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); |
|
442 |
- |
|
443 |
- for(y=0; y<h; y++){ |
|
444 |
- for(x=0; x<w; x++){ |
|
445 |
- int v= s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]; |
|
446 |
- s->mconly_picture.data[plane_index][y*s->mconly_picture.linesize[plane_index] + x]= v; |
|
447 |
- } |
|
448 |
- } |
|
449 |
- } |
|
450 |
- |
|
451 |
- { |
|
452 |
- for(level=0; level<s->spatial_decomposition_count; level++){ |
|
453 |
- for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
|
454 |
- SubBand *b= &p->band[level][orientation]; |
|
455 |
- unpack_coeffs(s, b, b->parent, orientation); |
|
456 |
- } |
|
457 |
- } |
|
458 |
- } |
|
459 |
- |
|
460 |
- { |
|
461 |
- const int mb_h= s->b_height << s->block_max_depth; |
|
462 |
- const int block_size = MB_SIZE >> s->block_max_depth; |
|
463 |
- const int block_w = plane_index ? block_size/2 : block_size; |
|
464 |
- int mb_y; |
|
465 |
- DWTCompose cs[MAX_DECOMPOSITIONS]; |
|
466 |
- int yd=0, yq=0; |
|
467 |
- int y; |
|
468 |
- int end_y; |
|
469 |
- |
|
470 |
- ff_spatial_idwt_buffered_init(cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count); |
|
471 |
- for(mb_y=0; mb_y<=mb_h; mb_y++){ |
|
472 |
- |
|
473 |
- int slice_starty = block_w*mb_y; |
|
474 |
- int slice_h = block_w*(mb_y+1); |
|
475 |
- if (!(s->keyframe || s->avctx->debug&512)){ |
|
476 |
- slice_starty = FFMAX(0, slice_starty - (block_w >> 1)); |
|
477 |
- slice_h -= (block_w >> 1); |
|
478 |
- } |
|
479 |
- |
|
480 |
- for(level=0; level<s->spatial_decomposition_count; level++){ |
|
481 |
- for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
|
482 |
- SubBand *b= &p->band[level][orientation]; |
|
483 |
- int start_y; |
|
484 |
- int end_y; |
|
485 |
- int our_mb_start = mb_y; |
|
486 |
- int our_mb_end = (mb_y + 1); |
|
487 |
- const int extra= 3; |
|
488 |
- start_y = (mb_y ? ((block_w * our_mb_start) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra: 0); |
|
489 |
- end_y = (((block_w * our_mb_end) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra); |
|
490 |
- if (!(s->keyframe || s->avctx->debug&512)){ |
|
491 |
- start_y = FFMAX(0, start_y - (block_w >> (1+s->spatial_decomposition_count - level))); |
|
492 |
- end_y = FFMAX(0, end_y - (block_w >> (1+s->spatial_decomposition_count - level))); |
|
493 |
- } |
|
494 |
- start_y = FFMIN(b->height, start_y); |
|
495 |
- end_y = FFMIN(b->height, end_y); |
|
496 |
- |
|
497 |
- if (start_y != end_y){ |
|
498 |
- if (orientation == 0){ |
|
499 |
- SubBand * correlate_band = &p->band[0][0]; |
|
500 |
- int correlate_end_y = FFMIN(b->height, end_y + 1); |
|
501 |
- int correlate_start_y = FFMIN(b->height, (start_y ? start_y + 1 : 0)); |
|
502 |
- decode_subband_slice_buffered(s, correlate_band, &s->sb, correlate_start_y, correlate_end_y, decode_state[0][0]); |
|
503 |
- correlate_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, 1, 0, correlate_start_y, correlate_end_y); |
|
504 |
- dequantize_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, start_y, end_y); |
|
505 |
- } |
|
506 |
- else |
|
507 |
- decode_subband_slice_buffered(s, b, &s->sb, start_y, end_y, decode_state[level][orientation]); |
|
508 |
- } |
|
509 |
- } |
|
510 |
- } |
|
511 |
- |
|
512 |
- for(; yd<slice_h; yd+=4){ |
|
513 |
- ff_spatial_idwt_buffered_slice(&s->dwt, cs, &s->sb, s->temp_idwt_buffer, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count, yd); |
|
514 |
- } |
|
515 |
- |
|
516 |
- if(s->qlog == LOSSLESS_QLOG){ |
|
517 |
- for(; yq<slice_h && yq<h; yq++){ |
|
518 |
- IDWTELEM * line = slice_buffer_get_line(&s->sb, yq); |
|
519 |
- for(x=0; x<w; x++){ |
|
520 |
- line[x] <<= FRAC_BITS; |
|
521 |
- } |
|
522 |
- } |
|
523 |
- } |
|
524 |
- |
|
525 |
- predict_slice_buffered(s, &s->sb, s->spatial_idwt_buffer, plane_index, 1, mb_y); |
|
526 |
- |
|
527 |
- y = FFMIN(p->height, slice_starty); |
|
528 |
- end_y = FFMIN(p->height, slice_h); |
|
529 |
- while(y < end_y) |
|
530 |
- ff_slice_buffer_release(&s->sb, y++); |
|
531 |
- } |
|
532 |
- |
|
533 |
- ff_slice_buffer_flush(&s->sb); |
|
534 |
- } |
|
535 |
- |
|
536 |
- } |
|
537 |
- |
|
538 |
- emms_c(); |
|
539 |
- |
|
540 |
- ff_snow_release_buffer(avctx); |
|
541 |
- |
|
542 |
- if(!(s->avctx->debug&2048)) |
|
543 |
- *picture= s->current_picture; |
|
544 |
- else |
|
545 |
- *picture= s->mconly_picture; |
|
546 |
- |
|
547 |
- *got_frame = 1; |
|
548 |
- |
|
549 |
- bytes_read= c->bytestream - c->bytestream_start; |
|
550 |
- if(bytes_read ==0) av_log(s->avctx, AV_LOG_ERROR, "error at end of frame\n"); //FIXME |
|
551 |
- |
|
552 |
- return bytes_read; |
|
553 |
-} |
|
554 |
- |
|
555 |
-static av_cold int decode_end(AVCodecContext *avctx) |
|
556 |
-{ |
|
557 |
- SnowContext *s = avctx->priv_data; |
|
558 |
- |
|
559 |
- ff_slice_buffer_destroy(&s->sb); |
|
560 |
- |
|
561 |
- ff_snow_common_end(s); |
|
562 |
- |
|
563 |
- return 0; |
|
564 |
-} |
|
565 |
- |
|
566 |
-AVCodec ff_snow_decoder = { |
|
567 |
- .name = "snow", |
|
568 |
- .type = AVMEDIA_TYPE_VIDEO, |
|
569 |
- .id = AV_CODEC_ID_SNOW, |
|
570 |
- .priv_data_size = sizeof(SnowContext), |
|
571 |
- .init = decode_init, |
|
572 |
- .close = decode_end, |
|
573 |
- .decode = decode_frame, |
|
574 |
- .capabilities = CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/, |
|
575 |
- .long_name = NULL_IF_CONFIG_SMALL("Snow"), |
|
576 |
-}; |
577 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,1939 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at> |
|
3 |
- * |
|
4 |
- * This file is part of Libav. |
|
5 |
- * |
|
6 |
- * Libav 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.1 of the License, or (at your option) any later version. |
|
10 |
- * |
|
11 |
- * Libav 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 Libav; if not, write to the Free Software |
|
18 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
- */ |
|
20 |
- |
|
21 |
-#include "libavutil/intmath.h" |
|
22 |
-#include "libavutil/log.h" |
|
23 |
-#include "libavutil/opt.h" |
|
24 |
-#include "avcodec.h" |
|
25 |
-#include "dsputil.h" |
|
26 |
-#include "internal.h" |
|
27 |
-#include "dwt.h" |
|
28 |
-#include "snow.h" |
|
29 |
- |
|
30 |
-#include "rangecoder.h" |
|
31 |
-#include "mathops.h" |
|
32 |
- |
|
33 |
-#include "mpegvideo.h" |
|
34 |
-#include "h263.h" |
|
35 |
- |
|
36 |
-#undef NDEBUG |
|
37 |
-#include <assert.h> |
|
38 |
- |
|
39 |
-#define QUANTIZE2 0 |
|
40 |
- |
|
41 |
-#if QUANTIZE2==1 |
|
42 |
-#define Q2_STEP 8 |
|
43 |
- |
|
44 |
-static void find_sse(SnowContext *s, Plane *p, int *score, int score_stride, IDWTELEM *r0, IDWTELEM *r1, int level, int orientation){ |
|
45 |
- SubBand *b= &p->band[level][orientation]; |
|
46 |
- int x, y; |
|
47 |
- int xo=0; |
|
48 |
- int yo=0; |
|
49 |
- int step= 1 << (s->spatial_decomposition_count - level); |
|
50 |
- |
|
51 |
- if(orientation&1) |
|
52 |
- xo= step>>1; |
|
53 |
- if(orientation&2) |
|
54 |
- yo= step>>1; |
|
55 |
- |
|
56 |
- //FIXME bias for nonzero ? |
|
57 |
- //FIXME optimize |
|
58 |
- memset(score, 0, sizeof(*score)*score_stride*((p->height + Q2_STEP-1)/Q2_STEP)); |
|
59 |
- for(y=0; y<p->height; y++){ |
|
60 |
- for(x=0; x<p->width; x++){ |
|
61 |
- int sx= (x-xo + step/2) / step / Q2_STEP; |
|
62 |
- int sy= (y-yo + step/2) / step / Q2_STEP; |
|
63 |
- int v= r0[x + y*p->width] - r1[x + y*p->width]; |
|
64 |
- assert(sx>=0 && sy>=0 && sx < score_stride); |
|
65 |
- v= ((v+8)>>4)<<4; |
|
66 |
- score[sx + sy*score_stride] += v*v; |
|
67 |
- assert(score[sx + sy*score_stride] >= 0); |
|
68 |
- } |
|
69 |
- } |
|
70 |
-} |
|
71 |
- |
|
72 |
-static void dequantize_all(SnowContext *s, Plane *p, IDWTELEM *buffer, int width, int height){ |
|
73 |
- int level, orientation; |
|
74 |
- |
|
75 |
- for(level=0; level<s->spatial_decomposition_count; level++){ |
|
76 |
- for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
|
77 |
- SubBand *b= &p->band[level][orientation]; |
|
78 |
- IDWTELEM *dst= buffer + (b->ibuf - s->spatial_idwt_buffer); |
|
79 |
- |
|
80 |
- dequantize(s, b, dst, b->stride); |
|
81 |
- } |
|
82 |
- } |
|
83 |
-} |
|
84 |
- |
|
85 |
-static void dwt_quantize(SnowContext *s, Plane *p, DWTELEM *buffer, int width, int height, int stride, int type){ |
|
86 |
- int level, orientation, ys, xs, x, y, pass; |
|
87 |
- IDWTELEM best_dequant[height * stride]; |
|
88 |
- IDWTELEM idwt2_buffer[height * stride]; |
|
89 |
- const int score_stride= (width + 10)/Q2_STEP; |
|
90 |
- int best_score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size |
|
91 |
- int score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size |
|
92 |
- int threshold= (s->m.lambda * s->m.lambda) >> 6; |
|
93 |
- |
|
94 |
- //FIXME pass the copy cleanly ? |
|
95 |
- |
|
96 |
-// memcpy(dwt_buffer, buffer, height * stride * sizeof(DWTELEM)); |
|
97 |
- ff_spatial_dwt(buffer, s->temp_dwt_buffer, width, height, stride, type, s->spatial_decomposition_count); |
|
98 |
- |
|
99 |
- for(level=0; level<s->spatial_decomposition_count; level++){ |
|
100 |
- for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
|
101 |
- SubBand *b= &p->band[level][orientation]; |
|
102 |
- IDWTELEM *dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); |
|
103 |
- DWTELEM *src= buffer + (b-> buf - s->spatial_dwt_buffer); |
|
104 |
- assert(src == b->buf); // code does not depend on this but it is true currently |
|
105 |
- |
|
106 |
- quantize(s, b, dst, src, b->stride, s->qbias); |
|
107 |
- } |
|
108 |
- } |
|
109 |
- for(pass=0; pass<1; pass++){ |
|
110 |
- if(s->qbias == 0) //keyframe |
|
111 |
- continue; |
|
112 |
- for(level=0; level<s->spatial_decomposition_count; level++){ |
|
113 |
- for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
|
114 |
- SubBand *b= &p->band[level][orientation]; |
|
115 |
- IDWTELEM *dst= idwt2_buffer + (b->ibuf - s->spatial_idwt_buffer); |
|
116 |
- IDWTELEM *best_dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); |
|
117 |
- |
|
118 |
- for(ys= 0; ys<Q2_STEP; ys++){ |
|
119 |
- for(xs= 0; xs<Q2_STEP; xs++){ |
|
120 |
- memcpy(idwt2_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); |
|
121 |
- dequantize_all(s, p, idwt2_buffer, width, height); |
|
122 |
- ff_spatial_idwt(idwt2_buffer, s->temp_idwt_buffer, width, height, stride, type, s->spatial_decomposition_count); |
|
123 |
- find_sse(s, p, best_score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); |
|
124 |
- memcpy(idwt2_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); |
|
125 |
- for(y=ys; y<b->height; y+= Q2_STEP){ |
|
126 |
- for(x=xs; x<b->width; x+= Q2_STEP){ |
|
127 |
- if(dst[x + y*b->stride]<0) dst[x + y*b->stride]++; |
|
128 |
- if(dst[x + y*b->stride]>0) dst[x + y*b->stride]--; |
|
129 |
- //FIXME try more than just -- |
|
130 |
- } |
|
131 |
- } |
|
132 |
- dequantize_all(s, p, idwt2_buffer, width, height); |
|
133 |
- ff_spatial_idwt(idwt2_buffer, s->temp_idwt_buffer, width, height, stride, type, s->spatial_decomposition_count); |
|
134 |
- find_sse(s, p, score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); |
|
135 |
- for(y=ys; y<b->height; y+= Q2_STEP){ |
|
136 |
- for(x=xs; x<b->width; x+= Q2_STEP){ |
|
137 |
- int score_idx= x/Q2_STEP + (y/Q2_STEP)*score_stride; |
|
138 |
- if(score[score_idx] <= best_score[score_idx] + threshold){ |
|
139 |
- best_score[score_idx]= score[score_idx]; |
|
140 |
- if(best_dst[x + y*b->stride]<0) best_dst[x + y*b->stride]++; |
|
141 |
- if(best_dst[x + y*b->stride]>0) best_dst[x + y*b->stride]--; |
|
142 |
- //FIXME copy instead |
|
143 |
- } |
|
144 |
- } |
|
145 |
- } |
|
146 |
- } |
|
147 |
- } |
|
148 |
- } |
|
149 |
- } |
|
150 |
- } |
|
151 |
- memcpy(s->spatial_idwt_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); //FIXME work with that directly instead of copy at the end |
|
152 |
-} |
|
153 |
- |
|
154 |
-#endif /* QUANTIZE2==1 */ |
|
155 |
- |
|
156 |
-static av_cold int encode_init(AVCodecContext *avctx) |
|
157 |
-{ |
|
158 |
- SnowContext *s = avctx->priv_data; |
|
159 |
- int plane_index, ret; |
|
160 |
- |
|
161 |
- if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ |
|
162 |
- av_log(avctx, AV_LOG_ERROR, "This codec is under development, files encoded with it may not be decodable with future versions!!!\n" |
|
163 |
- "Use vstrict=-2 / -strict -2 to use it anyway.\n"); |
|
164 |
- return -1; |
|
165 |
- } |
|
166 |
- |
|
167 |
- if(avctx->prediction_method == DWT_97 |
|
168 |
- && (avctx->flags & CODEC_FLAG_QSCALE) |
|
169 |
- && avctx->global_quality == 0){ |
|
170 |
- av_log(avctx, AV_LOG_ERROR, "The 9/7 wavelet is incompatible with lossless mode.\n"); |
|
171 |
- return -1; |
|
172 |
- } |
|
173 |
- |
|
174 |
- s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type |
|
175 |
- |
|
176 |
- s->mv_scale = (avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; |
|
177 |
- s->block_max_depth= (avctx->flags & CODEC_FLAG_4MV ) ? 1 : 0; |
|
178 |
- |
|
179 |
- for(plane_index=0; plane_index<3; plane_index++){ |
|
180 |
- s->plane[plane_index].diag_mc= 1; |
|
181 |
- s->plane[plane_index].htaps= 6; |
|
182 |
- s->plane[plane_index].hcoeff[0]= 40; |
|
183 |
- s->plane[plane_index].hcoeff[1]= -10; |
|
184 |
- s->plane[plane_index].hcoeff[2]= 2; |
|
185 |
- s->plane[plane_index].fast_mc= 1; |
|
186 |
- } |
|
187 |
- |
|
188 |
- if ((ret = ff_snow_common_init(avctx)) < 0) { |
|
189 |
- ff_snow_common_end(avctx->priv_data); |
|
190 |
- return ret; |
|
191 |
- } |
|
192 |
- ff_snow_alloc_blocks(s); |
|
193 |
- |
|
194 |
- s->version=0; |
|
195 |
- |
|
196 |
- s->m.avctx = avctx; |
|
197 |
- s->m.flags = avctx->flags; |
|
198 |
- s->m.bit_rate= avctx->bit_rate; |
|
199 |
- |
|
200 |
- s->m.me.temp = |
|
201 |
- s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t)); |
|
202 |
- s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); |
|
203 |
- s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); |
|
204 |
- s->m.obmc_scratchpad= av_mallocz(MB_SIZE*MB_SIZE*12*sizeof(uint32_t)); |
|
205 |
- ff_h263_encode_init(&s->m); //mv_penalty |
|
206 |
- |
|
207 |
- s->max_ref_frames = FFMAX(FFMIN(avctx->refs, MAX_REF_FRAMES), 1); |
|
208 |
- |
|
209 |
- if(avctx->flags&CODEC_FLAG_PASS1){ |
|
210 |
- if(!avctx->stats_out) |
|
211 |
- avctx->stats_out = av_mallocz(256); |
|
212 |
- } |
|
213 |
- if((avctx->flags&CODEC_FLAG_PASS2) || !(avctx->flags&CODEC_FLAG_QSCALE)){ |
|
214 |
- if(ff_rate_control_init(&s->m) < 0) |
|
215 |
- return -1; |
|
216 |
- } |
|
217 |
- s->pass1_rc= !(avctx->flags & (CODEC_FLAG_QSCALE|CODEC_FLAG_PASS2)); |
|
218 |
- |
|
219 |
- avctx->coded_frame= &s->current_picture; |
|
220 |
- switch(avctx->pix_fmt){ |
|
221 |
-// case AV_PIX_FMT_YUV444P: |
|
222 |
-// case AV_PIX_FMT_YUV422P: |
|
223 |
- case AV_PIX_FMT_YUV420P: |
|
224 |
- case AV_PIX_FMT_GRAY8: |
|
225 |
-// case AV_PIX_FMT_YUV411P: |
|
226 |
-// case AV_PIX_FMT_YUV410P: |
|
227 |
- s->colorspace_type= 0; |
|
228 |
- break; |
|
229 |
-/* case AV_PIX_FMT_RGB32: |
|
230 |
- s->colorspace= 1; |
|
231 |
- break;*/ |
|
232 |
- default: |
|
233 |
- av_log(avctx, AV_LOG_ERROR, "pixel format not supported\n"); |
|
234 |
- return -1; |
|
235 |
- } |
|
236 |
-// avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift); |
|
237 |
- s->chroma_h_shift= 1; |
|
238 |
- s->chroma_v_shift= 1; |
|
239 |
- |
|
240 |
- ff_set_cmp(&s->dsp, s->dsp.me_cmp, s->avctx->me_cmp); |
|
241 |
- ff_set_cmp(&s->dsp, s->dsp.me_sub_cmp, s->avctx->me_sub_cmp); |
|
242 |
- |
|
243 |
- ff_get_buffer(s->avctx, &s->input_picture); |
|
244 |
- |
|
245 |
- if(s->avctx->me_method == ME_ITER){ |
|
246 |
- int i; |
|
247 |
- int size= s->b_width * s->b_height << 2*s->block_max_depth; |
|
248 |
- for(i=0; i<s->max_ref_frames; i++){ |
|
249 |
- s->ref_mvs[i]= av_mallocz(size*sizeof(int16_t[2])); |
|
250 |
- s->ref_scores[i]= av_mallocz(size*sizeof(uint32_t)); |
|
251 |
- } |
|
252 |
- } |
|
253 |
- |
|
254 |
- return 0; |
|
255 |
-} |
|
256 |
- |
|
257 |
-//near copy & paste from dsputil, FIXME |
|
258 |
-static int pix_sum(uint8_t * pix, int line_size, int w) |
|
259 |
-{ |
|
260 |
- int s, i, j; |
|
261 |
- |
|
262 |
- s = 0; |
|
263 |
- for (i = 0; i < w; i++) { |
|
264 |
- for (j = 0; j < w; j++) { |
|
265 |
- s += pix[0]; |
|
266 |
- pix ++; |
|
267 |
- } |
|
268 |
- pix += line_size - w; |
|
269 |
- } |
|
270 |
- return s; |
|
271 |
-} |
|
272 |
- |
|
273 |
-//near copy & paste from dsputil, FIXME |
|
274 |
-static int pix_norm1(uint8_t * pix, int line_size, int w) |
|
275 |
-{ |
|
276 |
- int s, i, j; |
|
277 |
- uint32_t *sq = ff_squareTbl + 256; |
|
278 |
- |
|
279 |
- s = 0; |
|
280 |
- for (i = 0; i < w; i++) { |
|
281 |
- for (j = 0; j < w; j ++) { |
|
282 |
- s += sq[pix[0]]; |
|
283 |
- pix ++; |
|
284 |
- } |
|
285 |
- pix += line_size - w; |
|
286 |
- } |
|
287 |
- return s; |
|
288 |
-} |
|
289 |
- |
|
290 |
-//FIXME copy&paste |
|
291 |
-#define P_LEFT P[1] |
|
292 |
-#define P_TOP P[2] |
|
293 |
-#define P_TOPRIGHT P[3] |
|
294 |
-#define P_MEDIAN P[4] |
|
295 |
-#define P_MV1 P[9] |
|
296 |
-#define FLAG_QPEL 1 //must be 1 |
|
297 |
- |
|
298 |
-static int encode_q_branch(SnowContext *s, int level, int x, int y){ |
|
299 |
- uint8_t p_buffer[1024]; |
|
300 |
- uint8_t i_buffer[1024]; |
|
301 |
- uint8_t p_state[sizeof(s->block_state)]; |
|
302 |
- uint8_t i_state[sizeof(s->block_state)]; |
|
303 |
- RangeCoder pc, ic; |
|
304 |
- uint8_t *pbbak= s->c.bytestream; |
|
305 |
- uint8_t *pbbak_start= s->c.bytestream_start; |
|
306 |
- int score, score2, iscore, i_len, p_len, block_s, sum, base_bits; |
|
307 |
- const int w= s->b_width << s->block_max_depth; |
|
308 |
- const int h= s->b_height << s->block_max_depth; |
|
309 |
- const int rem_depth= s->block_max_depth - level; |
|
310 |
- const int index= (x + y*w) << rem_depth; |
|
311 |
- const int block_w= 1<<(LOG2_MB_SIZE - level); |
|
312 |
- int trx= (x+1)<<rem_depth; |
|
313 |
- int try= (y+1)<<rem_depth; |
|
314 |
- const BlockNode *left = x ? &s->block[index-1] : &null_block; |
|
315 |
- const BlockNode *top = y ? &s->block[index-w] : &null_block; |
|
316 |
- const BlockNode *right = trx<w ? &s->block[index+1] : &null_block; |
|
317 |
- const BlockNode *bottom= try<h ? &s->block[index+w] : &null_block; |
|
318 |
- const BlockNode *tl = y && x ? &s->block[index-w-1] : left; |
|
319 |
- const BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt |
|
320 |
- int pl = left->color[0]; |
|
321 |
- int pcb= left->color[1]; |
|
322 |
- int pcr= left->color[2]; |
|
323 |
- int pmx, pmy; |
|
324 |
- int mx=0, my=0; |
|
325 |
- int l,cr,cb; |
|
326 |
- const int stride= s->current_picture.linesize[0]; |
|
327 |
- const int uvstride= s->current_picture.linesize[1]; |
|
328 |
- uint8_t *current_data[3]= { s->input_picture.data[0] + (x + y* stride)*block_w, |
|
329 |
- s->input_picture.data[1] + (x + y*uvstride)*block_w/2, |
|
330 |
- s->input_picture.data[2] + (x + y*uvstride)*block_w/2}; |
|
331 |
- int P[10][2]; |
|
332 |
- int16_t last_mv[3][2]; |
|
333 |
- int qpel= !!(s->avctx->flags & CODEC_FLAG_QPEL); //unused |
|
334 |
- const int shift= 1+qpel; |
|
335 |
- MotionEstContext *c= &s->m.me; |
|
336 |
- int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); |
|
337 |
- int mx_context= av_log2(2*FFABS(left->mx - top->mx)); |
|
338 |
- int my_context= av_log2(2*FFABS(left->my - top->my)); |
|
339 |
- int s_context= 2*left->level + 2*top->level + tl->level + tr->level; |
|
340 |
- int ref, best_ref, ref_score, ref_mx, ref_my; |
|
341 |
- |
|
342 |
- assert(sizeof(s->block_state) >= 256); |
|
343 |
- if(s->keyframe){ |
|
344 |
- set_blocks(s, level, x, y, pl, pcb, pcr, 0, 0, 0, BLOCK_INTRA); |
|
345 |
- return 0; |
|
346 |
- } |
|
347 |
- |
|
348 |
-// clip predictors / edge ? |
|
349 |
- |
|
350 |
- P_LEFT[0]= left->mx; |
|
351 |
- P_LEFT[1]= left->my; |
|
352 |
- P_TOP [0]= top->mx; |
|
353 |
- P_TOP [1]= top->my; |
|
354 |
- P_TOPRIGHT[0]= tr->mx; |
|
355 |
- P_TOPRIGHT[1]= tr->my; |
|
356 |
- |
|
357 |
- last_mv[0][0]= s->block[index].mx; |
|
358 |
- last_mv[0][1]= s->block[index].my; |
|
359 |
- last_mv[1][0]= right->mx; |
|
360 |
- last_mv[1][1]= right->my; |
|
361 |
- last_mv[2][0]= bottom->mx; |
|
362 |
- last_mv[2][1]= bottom->my; |
|
363 |
- |
|
364 |
- s->m.mb_stride=2; |
|
365 |
- s->m.mb_x= |
|
366 |
- s->m.mb_y= 0; |
|
367 |
- c->skip= 0; |
|
368 |
- |
|
369 |
- assert(c-> stride == stride); |
|
370 |
- assert(c->uvstride == uvstride); |
|
371 |
- |
|
372 |
- c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); |
|
373 |
- c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); |
|
374 |
- c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); |
|
375 |
- c->current_mv_penalty= c->mv_penalty[s->m.f_code=1] + MAX_MV; |
|
376 |
- |
|
377 |
- c->xmin = - x*block_w - 16+3; |
|
378 |
- c->ymin = - y*block_w - 16+3; |
|
379 |
- c->xmax = - (x+1)*block_w + (w<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; |
|
380 |
- c->ymax = - (y+1)*block_w + (h<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; |
|
381 |
- |
|
382 |
- if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift); |
|
383 |
- if(P_LEFT[1] > (c->ymax<<shift)) P_LEFT[1] = (c->ymax<<shift); |
|
384 |
- if(P_TOP[0] > (c->xmax<<shift)) P_TOP[0] = (c->xmax<<shift); |
|
385 |
- if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1] = (c->ymax<<shift); |
|
386 |
- if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift); |
|
387 |
- if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift); //due to pmx no clip |
|
388 |
- if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift); |
|
389 |
- |
|
390 |
- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); |
|
391 |
- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); |
|
392 |
- |
|
393 |
- if (!y) { |
|
394 |
- c->pred_x= P_LEFT[0]; |
|
395 |
- c->pred_y= P_LEFT[1]; |
|
396 |
- } else { |
|
397 |
- c->pred_x = P_MEDIAN[0]; |
|
398 |
- c->pred_y = P_MEDIAN[1]; |
|
399 |
- } |
|
400 |
- |
|
401 |
- score= INT_MAX; |
|
402 |
- best_ref= 0; |
|
403 |
- for(ref=0; ref<s->ref_frames; ref++){ |
|
404 |
- init_ref(c, current_data, s->last_picture[ref].data, NULL, block_w*x, block_w*y, 0); |
|
405 |
- |
|
406 |
- ref_score= ff_epzs_motion_search(&s->m, &ref_mx, &ref_my, P, 0, /*ref_index*/ 0, last_mv, |
|
407 |
- (1<<16)>>shift, level-LOG2_MB_SIZE+4, block_w); |
|
408 |
- |
|
409 |
- assert(ref_mx >= c->xmin); |
|
410 |
- assert(ref_mx <= c->xmax); |
|
411 |
- assert(ref_my >= c->ymin); |
|
412 |
- assert(ref_my <= c->ymax); |
|
413 |
- |
|
414 |
- ref_score= c->sub_motion_search(&s->m, &ref_mx, &ref_my, ref_score, 0, 0, level-LOG2_MB_SIZE+4, block_w); |
|
415 |
- ref_score= ff_get_mb_score(&s->m, ref_mx, ref_my, 0, 0, level-LOG2_MB_SIZE+4, block_w, 0); |
|
416 |
- ref_score+= 2*av_log2(2*ref)*c->penalty_factor; |
|
417 |
- if(s->ref_mvs[ref]){ |
|
418 |
- s->ref_mvs[ref][index][0]= ref_mx; |
|
419 |
- s->ref_mvs[ref][index][1]= ref_my; |
|
420 |
- s->ref_scores[ref][index]= ref_score; |
|
421 |
- } |
|
422 |
- if(score > ref_score){ |
|
423 |
- score= ref_score; |
|
424 |
- best_ref= ref; |
|
425 |
- mx= ref_mx; |
|
426 |
- my= ref_my; |
|
427 |
- } |
|
428 |
- } |
|
429 |
- //FIXME if mb_cmp != SSE then intra cannot be compared currently and mb_penalty vs. lambda2 |
|
430 |
- |
|
431 |
- // subpel search |
|
432 |
- base_bits= get_rac_count(&s->c) - 8*(s->c.bytestream - s->c.bytestream_start); |
|
433 |
- pc= s->c; |
|
434 |
- pc.bytestream_start= |
|
435 |
- pc.bytestream= p_buffer; //FIXME end/start? and at the other stoo |
|
436 |
- memcpy(p_state, s->block_state, sizeof(s->block_state)); |
|
437 |
- |
|
438 |
- if(level!=s->block_max_depth) |
|
439 |
- put_rac(&pc, &p_state[4 + s_context], 1); |
|
440 |
- put_rac(&pc, &p_state[1 + left->type + top->type], 0); |
|
441 |
- if(s->ref_frames > 1) |
|
442 |
- put_symbol(&pc, &p_state[128 + 1024 + 32*ref_context], best_ref, 0); |
|
443 |
- pred_mv(s, &pmx, &pmy, best_ref, left, top, tr); |
|
444 |
- put_symbol(&pc, &p_state[128 + 32*(mx_context + 16*!!best_ref)], mx - pmx, 1); |
|
445 |
- put_symbol(&pc, &p_state[128 + 32*(my_context + 16*!!best_ref)], my - pmy, 1); |
|
446 |
- p_len= pc.bytestream - pc.bytestream_start; |
|
447 |
- score += (s->lambda2*(get_rac_count(&pc)-base_bits))>>FF_LAMBDA_SHIFT; |
|
448 |
- |
|
449 |
- block_s= block_w*block_w; |
|
450 |
- sum = pix_sum(current_data[0], stride, block_w); |
|
451 |
- l= (sum + block_s/2)/block_s; |
|
452 |
- iscore = pix_norm1(current_data[0], stride, block_w) - 2*l*sum + l*l*block_s; |
|
453 |
- |
|
454 |
- block_s= block_w*block_w>>2; |
|
455 |
- sum = pix_sum(current_data[1], uvstride, block_w>>1); |
|
456 |
- cb= (sum + block_s/2)/block_s; |
|
457 |
-// iscore += pix_norm1(¤t_mb[1][0], uvstride, block_w>>1) - 2*cb*sum + cb*cb*block_s; |
|
458 |
- sum = pix_sum(current_data[2], uvstride, block_w>>1); |
|
459 |
- cr= (sum + block_s/2)/block_s; |
|
460 |
-// iscore += pix_norm1(¤t_mb[2][0], uvstride, block_w>>1) - 2*cr*sum + cr*cr*block_s; |
|
461 |
- |
|
462 |
- ic= s->c; |
|
463 |
- ic.bytestream_start= |
|
464 |
- ic.bytestream= i_buffer; //FIXME end/start? and at the other stoo |
|
465 |
- memcpy(i_state, s->block_state, sizeof(s->block_state)); |
|
466 |
- if(level!=s->block_max_depth) |
|
467 |
- put_rac(&ic, &i_state[4 + s_context], 1); |
|
468 |
- put_rac(&ic, &i_state[1 + left->type + top->type], 1); |
|
469 |
- put_symbol(&ic, &i_state[32], l-pl , 1); |
|
470 |
- put_symbol(&ic, &i_state[64], cb-pcb, 1); |
|
471 |
- put_symbol(&ic, &i_state[96], cr-pcr, 1); |
|
472 |
- i_len= ic.bytestream - ic.bytestream_start; |
|
473 |
- iscore += (s->lambda2*(get_rac_count(&ic)-base_bits))>>FF_LAMBDA_SHIFT; |
|
474 |
- |
|
475 |
-// assert(score==256*256*256*64-1); |
|
476 |
- assert(iscore < 255*255*256 + s->lambda2*10); |
|
477 |
- assert(iscore >= 0); |
|
478 |
- assert(l>=0 && l<=255); |
|
479 |
- assert(pl>=0 && pl<=255); |
|
480 |
- |
|
481 |
- if(level==0){ |
|
482 |
- int varc= iscore >> 8; |
|
483 |
- int vard= score >> 8; |
|
484 |
- if (vard <= 64 || vard < varc) |
|
485 |
- c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); |
|
486 |
- else |
|
487 |
- c->scene_change_score+= s->m.qscale; |
|
488 |
- } |
|
489 |
- |
|
490 |
- if(level!=s->block_max_depth){ |
|
491 |
- put_rac(&s->c, &s->block_state[4 + s_context], 0); |
|
492 |
- score2 = encode_q_branch(s, level+1, 2*x+0, 2*y+0); |
|
493 |
- score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+0); |
|
494 |
- score2+= encode_q_branch(s, level+1, 2*x+0, 2*y+1); |
|
495 |
- score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+1); |
|
496 |
- score2+= s->lambda2>>FF_LAMBDA_SHIFT; //FIXME exact split overhead |
|
497 |
- |
|
498 |
- if(score2 < score && score2 < iscore) |
|
499 |
- return score2; |
|
500 |
- } |
|
501 |
- |
|
502 |
- if(iscore < score){ |
|
503 |
- pred_mv(s, &pmx, &pmy, 0, left, top, tr); |
|
504 |
- memcpy(pbbak, i_buffer, i_len); |
|
505 |
- s->c= ic; |
|
506 |
- s->c.bytestream_start= pbbak_start; |
|
507 |
- s->c.bytestream= pbbak + i_len; |
|
508 |
- set_blocks(s, level, x, y, l, cb, cr, pmx, pmy, 0, BLOCK_INTRA); |
|
509 |
- memcpy(s->block_state, i_state, sizeof(s->block_state)); |
|
510 |
- return iscore; |
|
511 |
- }else{ |
|
512 |
- memcpy(pbbak, p_buffer, p_len); |
|
513 |
- s->c= pc; |
|
514 |
- s->c.bytestream_start= pbbak_start; |
|
515 |
- s->c.bytestream= pbbak + p_len; |
|
516 |
- set_blocks(s, level, x, y, pl, pcb, pcr, mx, my, best_ref, 0); |
|
517 |
- memcpy(s->block_state, p_state, sizeof(s->block_state)); |
|
518 |
- return score; |
|
519 |
- } |
|
520 |
-} |
|
521 |
- |
|
522 |
-static void encode_q_branch2(SnowContext *s, int level, int x, int y){ |
|
523 |
- const int w= s->b_width << s->block_max_depth; |
|
524 |
- const int rem_depth= s->block_max_depth - level; |
|
525 |
- const int index= (x + y*w) << rem_depth; |
|
526 |
- int trx= (x+1)<<rem_depth; |
|
527 |
- BlockNode *b= &s->block[index]; |
|
528 |
- const BlockNode *left = x ? &s->block[index-1] : &null_block; |
|
529 |
- const BlockNode *top = y ? &s->block[index-w] : &null_block; |
|
530 |
- const BlockNode *tl = y && x ? &s->block[index-w-1] : left; |
|
531 |
- const BlockNode *tr = y && trx<w && ((x&1)==0 || level==0) ? &s->block[index-w+(1<<rem_depth)] : tl; //FIXME use lt |
|
532 |
- int pl = left->color[0]; |
|
533 |
- int pcb= left->color[1]; |
|
534 |
- int pcr= left->color[2]; |
|
535 |
- int pmx, pmy; |
|
536 |
- int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); |
|
537 |
- int mx_context= av_log2(2*FFABS(left->mx - top->mx)) + 16*!!b->ref; |
|
538 |
- int my_context= av_log2(2*FFABS(left->my - top->my)) + 16*!!b->ref; |
|
539 |
- int s_context= 2*left->level + 2*top->level + tl->level + tr->level; |
|
540 |
- |
|
541 |
- if(s->keyframe){ |
|
542 |
- set_blocks(s, level, x, y, pl, pcb, pcr, 0, 0, 0, BLOCK_INTRA); |
|
543 |
- return; |
|
544 |
- } |
|
545 |
- |
|
546 |
- if(level!=s->block_max_depth){ |
|
547 |
- if(same_block(b,b+1) && same_block(b,b+w) && same_block(b,b+w+1)){ |
|
548 |
- put_rac(&s->c, &s->block_state[4 + s_context], 1); |
|
549 |
- }else{ |
|
550 |
- put_rac(&s->c, &s->block_state[4 + s_context], 0); |
|
551 |
- encode_q_branch2(s, level+1, 2*x+0, 2*y+0); |
|
552 |
- encode_q_branch2(s, level+1, 2*x+1, 2*y+0); |
|
553 |
- encode_q_branch2(s, level+1, 2*x+0, 2*y+1); |
|
554 |
- encode_q_branch2(s, level+1, 2*x+1, 2*y+1); |
|
555 |
- return; |
|
556 |
- } |
|
557 |
- } |
|
558 |
- if(b->type & BLOCK_INTRA){ |
|
559 |
- pred_mv(s, &pmx, &pmy, 0, left, top, tr); |
|
560 |
- put_rac(&s->c, &s->block_state[1 + (left->type&1) + (top->type&1)], 1); |
|
561 |
- put_symbol(&s->c, &s->block_state[32], b->color[0]-pl , 1); |
|
562 |
- put_symbol(&s->c, &s->block_state[64], b->color[1]-pcb, 1); |
|
563 |
- put_symbol(&s->c, &s->block_state[96], b->color[2]-pcr, 1); |
|
564 |
- set_blocks(s, level, x, y, b->color[0], b->color[1], b->color[2], pmx, pmy, 0, BLOCK_INTRA); |
|
565 |
- }else{ |
|
566 |
- pred_mv(s, &pmx, &pmy, b->ref, left, top, tr); |
|
567 |
- put_rac(&s->c, &s->block_state[1 + (left->type&1) + (top->type&1)], 0); |
|
568 |
- if(s->ref_frames > 1) |
|
569 |
- put_symbol(&s->c, &s->block_state[128 + 1024 + 32*ref_context], b->ref, 0); |
|
570 |
- put_symbol(&s->c, &s->block_state[128 + 32*mx_context], b->mx - pmx, 1); |
|
571 |
- put_symbol(&s->c, &s->block_state[128 + 32*my_context], b->my - pmy, 1); |
|
572 |
- set_blocks(s, level, x, y, pl, pcb, pcr, b->mx, b->my, b->ref, 0); |
|
573 |
- } |
|
574 |
-} |
|
575 |
- |
|
576 |
-static int get_dc(SnowContext *s, int mb_x, int mb_y, int plane_index){ |
|
577 |
- int i, x2, y2; |
|
578 |
- Plane *p= &s->plane[plane_index]; |
|
579 |
- const int block_size = MB_SIZE >> s->block_max_depth; |
|
580 |
- const int block_w = plane_index ? block_size/2 : block_size; |
|
581 |
- const uint8_t *obmc = plane_index ? ff_obmc_tab[s->block_max_depth+1] : ff_obmc_tab[s->block_max_depth]; |
|
582 |
- const int obmc_stride= plane_index ? block_size : 2*block_size; |
|
583 |
- const int ref_stride= s->current_picture.linesize[plane_index]; |
|
584 |
- uint8_t *src= s-> input_picture.data[plane_index]; |
|
585 |
- IDWTELEM *dst= (IDWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4; //FIXME change to unsigned |
|
586 |
- const int b_stride = s->b_width << s->block_max_depth; |
|
587 |
- const int w= p->width; |
|
588 |
- const int h= p->height; |
|
589 |
- int index= mb_x + mb_y*b_stride; |
|
590 |
- BlockNode *b= &s->block[index]; |
|
591 |
- BlockNode backup= *b; |
|
592 |
- int ab=0; |
|
593 |
- int aa=0; |
|
594 |
- |
|
595 |
- b->type|= BLOCK_INTRA; |
|
596 |
- b->color[plane_index]= 0; |
|
597 |
- memset(dst, 0, obmc_stride*obmc_stride*sizeof(IDWTELEM)); |
|
598 |
- |
|
599 |
- for(i=0; i<4; i++){ |
|
600 |
- int mb_x2= mb_x + (i &1) - 1; |
|
601 |
- int mb_y2= mb_y + (i>>1) - 1; |
|
602 |
- int x= block_w*mb_x2 + block_w/2; |
|
603 |
- int y= block_w*mb_y2 + block_w/2; |
|
604 |
- |
|
605 |
- add_yblock(s, 0, NULL, dst + ((i&1)+(i>>1)*obmc_stride)*block_w, NULL, obmc, |
|
606 |
- x, y, block_w, block_w, w, h, obmc_stride, ref_stride, obmc_stride, mb_x2, mb_y2, 0, 0, plane_index); |
|
607 |
- |
|
608 |
- for(y2= FFMAX(y, 0); y2<FFMIN(h, y+block_w); y2++){ |
|
609 |
- for(x2= FFMAX(x, 0); x2<FFMIN(w, x+block_w); x2++){ |
|
610 |
- int index= x2-(block_w*mb_x - block_w/2) + (y2-(block_w*mb_y - block_w/2))*obmc_stride; |
|
611 |
- int obmc_v= obmc[index]; |
|
612 |
- int d; |
|
613 |
- if(y<0) obmc_v += obmc[index + block_w*obmc_stride]; |
|
614 |
- if(x<0) obmc_v += obmc[index + block_w]; |
|
615 |
- if(y+block_w>h) obmc_v += obmc[index - block_w*obmc_stride]; |
|
616 |
- if(x+block_w>w) obmc_v += obmc[index - block_w]; |
|
617 |
- //FIXME precalculate this or simplify it somehow else |
|
618 |
- |
|
619 |
- d = -dst[index] + (1<<(FRAC_BITS-1)); |
|
620 |
- dst[index] = d; |
|
621 |
- ab += (src[x2 + y2*ref_stride] - (d>>FRAC_BITS)) * obmc_v; |
|
622 |
- aa += obmc_v * obmc_v; //FIXME precalculate this |
|
623 |
- } |
|
624 |
- } |
|
625 |
- } |
|
626 |
- *b= backup; |
|
627 |
- |
|
628 |
- return av_clip(((ab<<LOG2_OBMC_MAX) + aa/2)/aa, 0, 255); //FIXME we should not need clipping |
|
629 |
-} |
|
630 |
- |
|
631 |
-static inline int get_block_bits(SnowContext *s, int x, int y, int w){ |
|
632 |
- const int b_stride = s->b_width << s->block_max_depth; |
|
633 |
- const int b_height = s->b_height<< s->block_max_depth; |
|
634 |
- int index= x + y*b_stride; |
|
635 |
- const BlockNode *b = &s->block[index]; |
|
636 |
- const BlockNode *left = x ? &s->block[index-1] : &null_block; |
|
637 |
- const BlockNode *top = y ? &s->block[index-b_stride] : &null_block; |
|
638 |
- const BlockNode *tl = y && x ? &s->block[index-b_stride-1] : left; |
|
639 |
- const BlockNode *tr = y && x+w<b_stride ? &s->block[index-b_stride+w] : tl; |
|
640 |
- int dmx, dmy; |
|
641 |
-// int mx_context= av_log2(2*FFABS(left->mx - top->mx)); |
|
642 |
-// int my_context= av_log2(2*FFABS(left->my - top->my)); |
|
643 |
- |
|
644 |
- if(x<0 || x>=b_stride || y>=b_height) |
|
645 |
- return 0; |
|
646 |
-/* |
|
647 |
-1 0 0 |
|
648 |
-01X 1-2 1 |
|
649 |
-001XX 3-6 2-3 |
|
650 |
-0001XXX 7-14 4-7 |
|
651 |
-00001XXXX 15-30 8-15 |
|
652 |
-*/ |
|
653 |
-//FIXME try accurate rate |
|
654 |
-//FIXME intra and inter predictors if surrounding blocks are not the same type |
|
655 |
- if(b->type & BLOCK_INTRA){ |
|
656 |
- return 3+2*( av_log2(2*FFABS(left->color[0] - b->color[0])) |
|
657 |
- + av_log2(2*FFABS(left->color[1] - b->color[1])) |
|
658 |
- + av_log2(2*FFABS(left->color[2] - b->color[2]))); |
|
659 |
- }else{ |
|
660 |
- pred_mv(s, &dmx, &dmy, b->ref, left, top, tr); |
|
661 |
- dmx-= b->mx; |
|
662 |
- dmy-= b->my; |
|
663 |
- return 2*(1 + av_log2(2*FFABS(dmx)) //FIXME kill the 2* can be merged in lambda |
|
664 |
- + av_log2(2*FFABS(dmy)) |
|
665 |
- + av_log2(2*b->ref)); |
|
666 |
- } |
|
667 |
-} |
|
668 |
- |
|
669 |
-static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, uint8_t (*obmc_edged)[MB_SIZE * 2]){ |
|
670 |
- Plane *p= &s->plane[plane_index]; |
|
671 |
- const int block_size = MB_SIZE >> s->block_max_depth; |
|
672 |
- const int block_w = plane_index ? block_size/2 : block_size; |
|
673 |
- const int obmc_stride= plane_index ? block_size : 2*block_size; |
|
674 |
- const int ref_stride= s->current_picture.linesize[plane_index]; |
|
675 |
- uint8_t *dst= s->current_picture.data[plane_index]; |
|
676 |
- uint8_t *src= s-> input_picture.data[plane_index]; |
|
677 |
- IDWTELEM *pred= (IDWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4; |
|
678 |
- uint8_t *cur = s->scratchbuf; |
|
679 |
- uint8_t *tmp = s->emu_edge_buffer; |
|
680 |
- const int b_stride = s->b_width << s->block_max_depth; |
|
681 |
- const int b_height = s->b_height<< s->block_max_depth; |
|
682 |
- const int w= p->width; |
|
683 |
- const int h= p->height; |
|
684 |
- int distortion; |
|
685 |
- int rate= 0; |
|
686 |
- const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp); |
|
687 |
- int sx= block_w*mb_x - block_w/2; |
|
688 |
- int sy= block_w*mb_y - block_w/2; |
|
689 |
- int x0= FFMAX(0,-sx); |
|
690 |
- int y0= FFMAX(0,-sy); |
|
691 |
- int x1= FFMIN(block_w*2, w-sx); |
|
692 |
- int y1= FFMIN(block_w*2, h-sy); |
|
693 |
- int i,x,y; |
|
694 |
- |
|
695 |
- ff_snow_pred_block(s, cur, tmp, ref_stride, sx, sy, block_w*2, block_w*2, &s->block[mb_x + mb_y*b_stride], plane_index, w, h); |
|
696 |
- |
|
697 |
- for(y=y0; y<y1; y++){ |
|
698 |
- const uint8_t *obmc1= obmc_edged[y]; |
|
699 |
- const IDWTELEM *pred1 = pred + y*obmc_stride; |
|
700 |
- uint8_t *cur1 = cur + y*ref_stride; |
|
701 |
- uint8_t *dst1 = dst + sx + (sy+y)*ref_stride; |
|
702 |
- for(x=x0; x<x1; x++){ |
|
703 |
-#if FRAC_BITS >= LOG2_OBMC_MAX |
|
704 |
- int v = (cur1[x] * obmc1[x]) << (FRAC_BITS - LOG2_OBMC_MAX); |
|
705 |
-#else |
|
706 |
- int v = (cur1[x] * obmc1[x] + (1<<(LOG2_OBMC_MAX - FRAC_BITS-1))) >> (LOG2_OBMC_MAX - FRAC_BITS); |
|
707 |
-#endif |
|
708 |
- v = (v + pred1[x]) >> FRAC_BITS; |
|
709 |
- if(v&(~255)) v= ~(v>>31); |
|
710 |
- dst1[x] = v; |
|
711 |
- } |
|
712 |
- } |
|
713 |
- |
|
714 |
- /* copy the regions where obmc[] = (uint8_t)256 */ |
|
715 |
- if(LOG2_OBMC_MAX == 8 |
|
716 |
- && (mb_x == 0 || mb_x == b_stride-1) |
|
717 |
- && (mb_y == 0 || mb_y == b_height-1)){ |
|
718 |
- if(mb_x == 0) |
|
719 |
- x1 = block_w; |
|
720 |
- else |
|
721 |
- x0 = block_w; |
|
722 |
- if(mb_y == 0) |
|
723 |
- y1 = block_w; |
|
724 |
- else |
|
725 |
- y0 = block_w; |
|
726 |
- for(y=y0; y<y1; y++) |
|
727 |
- memcpy(dst + sx+x0 + (sy+y)*ref_stride, cur + x0 + y*ref_stride, x1-x0); |
|
728 |
- } |
|
729 |
- |
|
730 |
- if(block_w==16){ |
|
731 |
- /* FIXME rearrange dsputil to fit 32x32 cmp functions */ |
|
732 |
- /* FIXME check alignment of the cmp wavelet vs the encoding wavelet */ |
|
733 |
- /* FIXME cmps overlap but do not cover the wavelet's whole support. |
|
734 |
- * So improving the score of one block is not strictly guaranteed |
|
735 |
- * to improve the score of the whole frame, thus iterative motion |
|
736 |
- * estimation does not always converge. */ |
|
737 |
- if(s->avctx->me_cmp == FF_CMP_W97) |
|
738 |
- distortion = ff_w97_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); |
|
739 |
- else if(s->avctx->me_cmp == FF_CMP_W53) |
|
740 |
- distortion = ff_w53_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); |
|
741 |
- else{ |
|
742 |
- distortion = 0; |
|
743 |
- for(i=0; i<4; i++){ |
|
744 |
- int off = sx+16*(i&1) + (sy+16*(i>>1))*ref_stride; |
|
745 |
- distortion += s->dsp.me_cmp[0](&s->m, src + off, dst + off, ref_stride, 16); |
|
746 |
- } |
|
747 |
- } |
|
748 |
- }else{ |
|
749 |
- assert(block_w==8); |
|
750 |
- distortion = s->dsp.me_cmp[0](&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, block_w*2); |
|
751 |
- } |
|
752 |
- |
|
753 |
- if(plane_index==0){ |
|
754 |
- for(i=0; i<4; i++){ |
|
755 |
-/* ..RRr |
|
756 |
- * .RXx. |
|
757 |
- * rxx.. |
|
758 |
- */ |
|
759 |
- rate += get_block_bits(s, mb_x + (i&1) - (i>>1), mb_y + (i>>1), 1); |
|
760 |
- } |
|
761 |
- if(mb_x == b_stride-2) |
|
762 |
- rate += get_block_bits(s, mb_x + 1, mb_y + 1, 1); |
|
763 |
- } |
|
764 |
- return distortion + rate*penalty_factor; |
|
765 |
-} |
|
766 |
- |
|
767 |
-static int get_4block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index){ |
|
768 |
- int i, y2; |
|
769 |
- Plane *p= &s->plane[plane_index]; |
|
770 |
- const int block_size = MB_SIZE >> s->block_max_depth; |
|
771 |
- const int block_w = plane_index ? block_size/2 : block_size; |
|
772 |
- const uint8_t *obmc = plane_index ? ff_obmc_tab[s->block_max_depth+1] : ff_obmc_tab[s->block_max_depth]; |
|
773 |
- const int obmc_stride= plane_index ? block_size : 2*block_size; |
|
774 |
- const int ref_stride= s->current_picture.linesize[plane_index]; |
|
775 |
- uint8_t *dst= s->current_picture.data[plane_index]; |
|
776 |
- uint8_t *src= s-> input_picture.data[plane_index]; |
|
777 |
- //FIXME zero_dst is const but add_yblock changes dst if add is 0 (this is never the case for dst=zero_dst |
|
778 |
- // const has only been removed from zero_dst to suppress a warning |
|
779 |
- static IDWTELEM zero_dst[4096]; //FIXME |
|
780 |
- const int b_stride = s->b_width << s->block_max_depth; |
|
781 |
- const int w= p->width; |
|
782 |
- const int h= p->height; |
|
783 |
- int distortion= 0; |
|
784 |
- int rate= 0; |
|
785 |
- const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp); |
|
786 |
- |
|
787 |
- for(i=0; i<9; i++){ |
|
788 |
- int mb_x2= mb_x + (i%3) - 1; |
|
789 |
- int mb_y2= mb_y + (i/3) - 1; |
|
790 |
- int x= block_w*mb_x2 + block_w/2; |
|
791 |
- int y= block_w*mb_y2 + block_w/2; |
|
792 |
- |
|
793 |
- add_yblock(s, 0, NULL, zero_dst, dst, obmc, |
|
794 |
- x, y, block_w, block_w, w, h, /*dst_stride*/0, ref_stride, obmc_stride, mb_x2, mb_y2, 1, 1, plane_index); |
|
795 |
- |
|
796 |
- //FIXME find a cleaner/simpler way to skip the outside stuff |
|
797 |
- for(y2= y; y2<0; y2++) |
|
798 |
- memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, block_w); |
|
799 |
- for(y2= h; y2<y+block_w; y2++) |
|
800 |
- memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, block_w); |
|
801 |
- if(x<0){ |
|
802 |
- for(y2= y; y2<y+block_w; y2++) |
|
803 |
- memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, -x); |
|
804 |
- } |
|
805 |
- if(x+block_w > w){ |
|
806 |
- for(y2= y; y2<y+block_w; y2++) |
|
807 |
- memcpy(dst + w + y2*ref_stride, src + w + y2*ref_stride, x+block_w - w); |
|
808 |
- } |
|
809 |
- |
|
810 |
- assert(block_w== 8 || block_w==16); |
|
811 |
- distortion += s->dsp.me_cmp[block_w==8](&s->m, src + x + y*ref_stride, dst + x + y*ref_stride, ref_stride, block_w); |
|
812 |
- } |
|
813 |
- |
|
814 |
- if(plane_index==0){ |
|
815 |
- BlockNode *b= &s->block[mb_x+mb_y*b_stride]; |
|
816 |
- int merged= same_block(b,b+1) && same_block(b,b+b_stride) && same_block(b,b+b_stride+1); |
|
817 |
- |
|
818 |
-/* ..RRRr |
|
819 |
- * .RXXx. |
|
820 |
- * .RXXx. |
|
821 |
- * rxxx. |
|
822 |
- */ |
|
823 |
- if(merged) |
|
824 |
- rate = get_block_bits(s, mb_x, mb_y, 2); |
|
825 |
- for(i=merged?4:0; i<9; i++){ |
|
826 |
- static const int dxy[9][2] = {{0,0},{1,0},{0,1},{1,1},{2,0},{2,1},{-1,2},{0,2},{1,2}}; |
|
827 |
- rate += get_block_bits(s, mb_x + dxy[i][0], mb_y + dxy[i][1], 1); |
|
828 |
- } |
|
829 |
- } |
|
830 |
- return distortion + rate*penalty_factor; |
|
831 |
-} |
|
832 |
- |
|
833 |
-static int encode_subband_c0run(SnowContext *s, SubBand *b, IDWTELEM *src, IDWTELEM *parent, int stride, int orientation){ |
|
834 |
- const int w= b->width; |
|
835 |
- const int h= b->height; |
|
836 |
- int x, y; |
|
837 |
- |
|
838 |
- if(1){ |
|
839 |
- int run=0; |
|
840 |
- int *runs = s->run_buffer; |
|
841 |
- int run_index=0; |
|
842 |
- int max_index; |
|
843 |
- |
|
844 |
- for(y=0; y<h; y++){ |
|
845 |
- for(x=0; x<w; x++){ |
|
846 |
- int v, p=0; |
|
847 |
- int /*ll=0, */l=0, lt=0, t=0, rt=0; |
|
848 |
- v= src[x + y*stride]; |
|
849 |
- |
|
850 |
- if(y){ |
|
851 |
- t= src[x + (y-1)*stride]; |
|
852 |
- if(x){ |
|
853 |
- lt= src[x - 1 + (y-1)*stride]; |
|
854 |
- } |
|
855 |
- if(x + 1 < w){ |
|
856 |
- rt= src[x + 1 + (y-1)*stride]; |
|
857 |
- } |
|
858 |
- } |
|
859 |
- if(x){ |
|
860 |
- l= src[x - 1 + y*stride]; |
|
861 |
- /*if(x > 1){ |
|
862 |
- if(orientation==1) ll= src[y + (x-2)*stride]; |
|
863 |
- else ll= src[x - 2 + y*stride]; |
|
864 |
- }*/ |
|
865 |
- } |
|
866 |
- if(parent){ |
|
867 |
- int px= x>>1; |
|
868 |
- int py= y>>1; |
|
869 |
- if(px<b->parent->width && py<b->parent->height) |
|
870 |
- p= parent[px + py*2*stride]; |
|
871 |
- } |
|
872 |
- if(!(/*ll|*/l|lt|t|rt|p)){ |
|
873 |
- if(v){ |
|
874 |
- runs[run_index++]= run; |
|
875 |
- run=0; |
|
876 |
- }else{ |
|
877 |
- run++; |
|
878 |
- } |
|
879 |
- } |
|
880 |
- } |
|
881 |
- } |
|
882 |
- max_index= run_index; |
|
883 |
- runs[run_index++]= run; |
|
884 |
- run_index=0; |
|
885 |
- run= runs[run_index++]; |
|
886 |
- |
|
887 |
- put_symbol2(&s->c, b->state[30], max_index, 0); |
|
888 |
- if(run_index <= max_index) |
|
889 |
- put_symbol2(&s->c, b->state[1], run, 3); |
|
890 |
- |
|
891 |
- for(y=0; y<h; y++){ |
|
892 |
- if(s->c.bytestream_end - s->c.bytestream < w*40){ |
|
893 |
- av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); |
|
894 |
- return -1; |
|
895 |
- } |
|
896 |
- for(x=0; x<w; x++){ |
|
897 |
- int v, p=0; |
|
898 |
- int /*ll=0, */l=0, lt=0, t=0, rt=0; |
|
899 |
- v= src[x + y*stride]; |
|
900 |
- |
|
901 |
- if(y){ |
|
902 |
- t= src[x + (y-1)*stride]; |
|
903 |
- if(x){ |
|
904 |
- lt= src[x - 1 + (y-1)*stride]; |
|
905 |
- } |
|
906 |
- if(x + 1 < w){ |
|
907 |
- rt= src[x + 1 + (y-1)*stride]; |
|
908 |
- } |
|
909 |
- } |
|
910 |
- if(x){ |
|
911 |
- l= src[x - 1 + y*stride]; |
|
912 |
- /*if(x > 1){ |
|
913 |
- if(orientation==1) ll= src[y + (x-2)*stride]; |
|
914 |
- else ll= src[x - 2 + y*stride]; |
|
915 |
- }*/ |
|
916 |
- } |
|
917 |
- if(parent){ |
|
918 |
- int px= x>>1; |
|
919 |
- int py= y>>1; |
|
920 |
- if(px<b->parent->width && py<b->parent->height) |
|
921 |
- p= parent[px + py*2*stride]; |
|
922 |
- } |
|
923 |
- if(/*ll|*/l|lt|t|rt|p){ |
|
924 |
- int context= av_log2(/*FFABS(ll) + */3*FFABS(l) + FFABS(lt) + 2*FFABS(t) + FFABS(rt) + FFABS(p)); |
|
925 |
- |
|
926 |
- put_rac(&s->c, &b->state[0][context], !!v); |
|
927 |
- }else{ |
|
928 |
- if(!run){ |
|
929 |
- run= runs[run_index++]; |
|
930 |
- |
|
931 |
- if(run_index <= max_index) |
|
932 |
- put_symbol2(&s->c, b->state[1], run, 3); |
|
933 |
- assert(v); |
|
934 |
- }else{ |
|
935 |
- run--; |
|
936 |
- assert(!v); |
|
937 |
- } |
|
938 |
- } |
|
939 |
- if(v){ |
|
940 |
- int context= av_log2(/*FFABS(ll) + */3*FFABS(l) + FFABS(lt) + 2*FFABS(t) + FFABS(rt) + FFABS(p)); |
|
941 |
- int l2= 2*FFABS(l) + (l<0); |
|
942 |
- int t2= 2*FFABS(t) + (t<0); |
|
943 |
- |
|
944 |
- put_symbol2(&s->c, b->state[context + 2], FFABS(v)-1, context-4); |
|
945 |
- put_rac(&s->c, &b->state[0][16 + 1 + 3 + ff_quant3bA[l2&0xFF] + 3*ff_quant3bA[t2&0xFF]], v<0); |
|
946 |
- } |
|
947 |
- } |
|
948 |
- } |
|
949 |
- } |
|
950 |
- return 0; |
|
951 |
-} |
|
952 |
- |
|
953 |
-static int encode_subband(SnowContext *s, SubBand *b, IDWTELEM *src, IDWTELEM *parent, int stride, int orientation){ |
|
954 |
-// encode_subband_qtree(s, b, src, parent, stride, orientation); |
|
955 |
-// encode_subband_z0run(s, b, src, parent, stride, orientation); |
|
956 |
- return encode_subband_c0run(s, b, src, parent, stride, orientation); |
|
957 |
-// encode_subband_dzr(s, b, src, parent, stride, orientation); |
|
958 |
-} |
|
959 |
- |
|
960 |
-static av_always_inline int check_block(SnowContext *s, int mb_x, int mb_y, int p[3], int intra, uint8_t (*obmc_edged)[MB_SIZE * 2], int *best_rd){ |
|
961 |
- const int b_stride= s->b_width << s->block_max_depth; |
|
962 |
- BlockNode *block= &s->block[mb_x + mb_y * b_stride]; |
|
963 |
- BlockNode backup= *block; |
|
964 |
- unsigned value; |
|
965 |
- int rd, index; |
|
966 |
- |
|
967 |
- assert(mb_x>=0 && mb_y>=0); |
|
968 |
- assert(mb_x<b_stride); |
|
969 |
- |
|
970 |
- if(intra){ |
|
971 |
- block->color[0] = p[0]; |
|
972 |
- block->color[1] = p[1]; |
|
973 |
- block->color[2] = p[2]; |
|
974 |
- block->type |= BLOCK_INTRA; |
|
975 |
- }else{ |
|
976 |
- index= (p[0] + 31*p[1]) & (ME_CACHE_SIZE-1); |
|
977 |
- value= s->me_cache_generation + (p[0]>>10) + (p[1]<<6) + (block->ref<<12); |
|
978 |
- if(s->me_cache[index] == value) |
|
979 |
- return 0; |
|
980 |
- s->me_cache[index]= value; |
|
981 |
- |
|
982 |
- block->mx= p[0]; |
|
983 |
- block->my= p[1]; |
|
984 |
- block->type &= ~BLOCK_INTRA; |
|
985 |
- } |
|
986 |
- |
|
987 |
- rd= get_block_rd(s, mb_x, mb_y, 0, obmc_edged); |
|
988 |
- |
|
989 |
-//FIXME chroma |
|
990 |
- if(rd < *best_rd){ |
|
991 |
- *best_rd= rd; |
|
992 |
- return 1; |
|
993 |
- }else{ |
|
994 |
- *block= backup; |
|
995 |
- return 0; |
|
996 |
- } |
|
997 |
-} |
|
998 |
- |
|
999 |
-/* special case for int[2] args we discard afterwards, |
|
1000 |
- * fixes compilation problem with gcc 2.95 */ |
|
1001 |
-static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, uint8_t (*obmc_edged)[MB_SIZE * 2], int *best_rd){ |
|
1002 |
- int p[2] = {p0, p1}; |
|
1003 |
- return check_block(s, mb_x, mb_y, p, 0, obmc_edged, best_rd); |
|
1004 |
-} |
|
1005 |
- |
|
1006 |
-static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, int ref, int *best_rd){ |
|
1007 |
- const int b_stride= s->b_width << s->block_max_depth; |
|
1008 |
- BlockNode *block= &s->block[mb_x + mb_y * b_stride]; |
|
1009 |
- BlockNode backup[4]; |
|
1010 |
- unsigned value; |
|
1011 |
- int rd, index; |
|
1012 |
- |
|
1013 |
- /* We don't initialize backup[] during variable declaration, because |
|
1014 |
- * that fails to compile on MSVC: "cannot convert from 'BlockNode' to |
|
1015 |
- * 'int16_t'". */ |
|
1016 |
- backup[0] = block[0]; |
|
1017 |
- backup[1] = block[1]; |
|
1018 |
- backup[2] = block[b_stride]; |
|
1019 |
- backup[3] = block[b_stride + 1]; |
|
1020 |
- |
|
1021 |
- assert(mb_x>=0 && mb_y>=0); |
|
1022 |
- assert(mb_x<b_stride); |
|
1023 |
- assert(((mb_x|mb_y)&1) == 0); |
|
1024 |
- |
|
1025 |
- index= (p0 + 31*p1) & (ME_CACHE_SIZE-1); |
|
1026 |
- value= s->me_cache_generation + (p0>>10) + (p1<<6) + (block->ref<<12); |
|
1027 |
- if(s->me_cache[index] == value) |
|
1028 |
- return 0; |
|
1029 |
- s->me_cache[index]= value; |
|
1030 |
- |
|
1031 |
- block->mx= p0; |
|
1032 |
- block->my= p1; |
|
1033 |
- block->ref= ref; |
|
1034 |
- block->type &= ~BLOCK_INTRA; |
|
1035 |
- block[1]= block[b_stride]= block[b_stride+1]= *block; |
|
1036 |
- |
|
1037 |
- rd= get_4block_rd(s, mb_x, mb_y, 0); |
|
1038 |
- |
|
1039 |
-//FIXME chroma |
|
1040 |
- if(rd < *best_rd){ |
|
1041 |
- *best_rd= rd; |
|
1042 |
- return 1; |
|
1043 |
- }else{ |
|
1044 |
- block[0]= backup[0]; |
|
1045 |
- block[1]= backup[1]; |
|
1046 |
- block[b_stride]= backup[2]; |
|
1047 |
- block[b_stride+1]= backup[3]; |
|
1048 |
- return 0; |
|
1049 |
- } |
|
1050 |
-} |
|
1051 |
- |
|
1052 |
-static void iterative_me(SnowContext *s){ |
|
1053 |
- int pass, mb_x, mb_y; |
|
1054 |
- const int b_width = s->b_width << s->block_max_depth; |
|
1055 |
- const int b_height= s->b_height << s->block_max_depth; |
|
1056 |
- const int b_stride= b_width; |
|
1057 |
- int color[3]; |
|
1058 |
- |
|
1059 |
- { |
|
1060 |
- RangeCoder r = s->c; |
|
1061 |
- uint8_t state[sizeof(s->block_state)]; |
|
1062 |
- memcpy(state, s->block_state, sizeof(s->block_state)); |
|
1063 |
- for(mb_y= 0; mb_y<s->b_height; mb_y++) |
|
1064 |
- for(mb_x= 0; mb_x<s->b_width; mb_x++) |
|
1065 |
- encode_q_branch(s, 0, mb_x, mb_y); |
|
1066 |
- s->c = r; |
|
1067 |
- memcpy(s->block_state, state, sizeof(s->block_state)); |
|
1068 |
- } |
|
1069 |
- |
|
1070 |
- for(pass=0; pass<25; pass++){ |
|
1071 |
- int change= 0; |
|
1072 |
- |
|
1073 |
- for(mb_y= 0; mb_y<b_height; mb_y++){ |
|
1074 |
- for(mb_x= 0; mb_x<b_width; mb_x++){ |
|
1075 |
- int dia_change, i, j, ref; |
|
1076 |
- int best_rd= INT_MAX, ref_rd; |
|
1077 |
- BlockNode backup, ref_b; |
|
1078 |
- const int index= mb_x + mb_y * b_stride; |
|
1079 |
- BlockNode *block= &s->block[index]; |
|
1080 |
- BlockNode *tb = mb_y ? &s->block[index-b_stride ] : NULL; |
|
1081 |
- BlockNode *lb = mb_x ? &s->block[index -1] : NULL; |
|
1082 |
- BlockNode *rb = mb_x+1<b_width ? &s->block[index +1] : NULL; |
|
1083 |
- BlockNode *bb = mb_y+1<b_height ? &s->block[index+b_stride ] : NULL; |
|
1084 |
- BlockNode *tlb= mb_x && mb_y ? &s->block[index-b_stride-1] : NULL; |
|
1085 |
- BlockNode *trb= mb_x+1<b_width && mb_y ? &s->block[index-b_stride+1] : NULL; |
|
1086 |
- BlockNode *blb= mb_x && mb_y+1<b_height ? &s->block[index+b_stride-1] : NULL; |
|
1087 |
- BlockNode *brb= mb_x+1<b_width && mb_y+1<b_height ? &s->block[index+b_stride+1] : NULL; |
|
1088 |
- const int b_w= (MB_SIZE >> s->block_max_depth); |
|
1089 |
- uint8_t obmc_edged[MB_SIZE * 2][MB_SIZE * 2]; |
|
1090 |
- |
|
1091 |
- if(pass && (block->type & BLOCK_OPT)) |
|
1092 |
- continue; |
|
1093 |
- block->type |= BLOCK_OPT; |
|
1094 |
- |
|
1095 |
- backup= *block; |
|
1096 |
- |
|
1097 |
- if(!s->me_cache_generation) |
|
1098 |
- memset(s->me_cache, 0, sizeof(s->me_cache)); |
|
1099 |
- s->me_cache_generation += 1<<22; |
|
1100 |
- |
|
1101 |
- //FIXME precalculate |
|
1102 |
- { |
|
1103 |
- int x, y; |
|
1104 |
- for (y = 0; y < b_w * 2; y++) |
|
1105 |
- memcpy(obmc_edged[y], ff_obmc_tab[s->block_max_depth] + y * b_w * 2, b_w * 2); |
|
1106 |
- if(mb_x==0) |
|
1107 |
- for(y=0; y<b_w*2; y++) |
|
1108 |
- memset(obmc_edged[y], obmc_edged[y][0] + obmc_edged[y][b_w-1], b_w); |
|
1109 |
- if(mb_x==b_stride-1) |
|
1110 |
- for(y=0; y<b_w*2; y++) |
|
1111 |
- memset(obmc_edged[y]+b_w, obmc_edged[y][b_w] + obmc_edged[y][b_w*2-1], b_w); |
|
1112 |
- if(mb_y==0){ |
|
1113 |
- for(x=0; x<b_w*2; x++) |
|
1114 |
- obmc_edged[0][x] += obmc_edged[b_w-1][x]; |
|
1115 |
- for(y=1; y<b_w; y++) |
|
1116 |
- memcpy(obmc_edged[y], obmc_edged[0], b_w*2); |
|
1117 |
- } |
|
1118 |
- if(mb_y==b_height-1){ |
|
1119 |
- for(x=0; x<b_w*2; x++) |
|
1120 |
- obmc_edged[b_w*2-1][x] += obmc_edged[b_w][x]; |
|
1121 |
- for(y=b_w; y<b_w*2-1; y++) |
|
1122 |
- memcpy(obmc_edged[y], obmc_edged[b_w*2-1], b_w*2); |
|
1123 |
- } |
|
1124 |
- } |
|
1125 |
- |
|
1126 |
- //skip stuff outside the picture |
|
1127 |
- if(mb_x==0 || mb_y==0 || mb_x==b_width-1 || mb_y==b_height-1){ |
|
1128 |
- uint8_t *src= s-> input_picture.data[0]; |
|
1129 |
- uint8_t *dst= s->current_picture.data[0]; |
|
1130 |
- const int stride= s->current_picture.linesize[0]; |
|
1131 |
- const int block_w= MB_SIZE >> s->block_max_depth; |
|
1132 |
- const int sx= block_w*mb_x - block_w/2; |
|
1133 |
- const int sy= block_w*mb_y - block_w/2; |
|
1134 |
- const int w= s->plane[0].width; |
|
1135 |
- const int h= s->plane[0].height; |
|
1136 |
- int y; |
|
1137 |
- |
|
1138 |
- for(y=sy; y<0; y++) |
|
1139 |
- memcpy(dst + sx + y*stride, src + sx + y*stride, block_w*2); |
|
1140 |
- for(y=h; y<sy+block_w*2; y++) |
|
1141 |
- memcpy(dst + sx + y*stride, src + sx + y*stride, block_w*2); |
|
1142 |
- if(sx<0){ |
|
1143 |
- for(y=sy; y<sy+block_w*2; y++) |
|
1144 |
- memcpy(dst + sx + y*stride, src + sx + y*stride, -sx); |
|
1145 |
- } |
|
1146 |
- if(sx+block_w*2 > w){ |
|
1147 |
- for(y=sy; y<sy+block_w*2; y++) |
|
1148 |
- memcpy(dst + w + y*stride, src + w + y*stride, sx+block_w*2 - w); |
|
1149 |
- } |
|
1150 |
- } |
|
1151 |
- |
|
1152 |
- // intra(black) = neighbors' contribution to the current block |
|
1153 |
- for(i=0; i<3; i++) |
|
1154 |
- color[i]= get_dc(s, mb_x, mb_y, i); |
|
1155 |
- |
|
1156 |
- // get previous score (cannot be cached due to OBMC) |
|
1157 |
- if(pass > 0 && (block->type&BLOCK_INTRA)){ |
|
1158 |
- int color0[3]= {block->color[0], block->color[1], block->color[2]}; |
|
1159 |
- check_block(s, mb_x, mb_y, color0, 1, obmc_edged, &best_rd); |
|
1160 |
- }else |
|
1161 |
- check_block_inter(s, mb_x, mb_y, block->mx, block->my, obmc_edged, &best_rd); |
|
1162 |
- |
|
1163 |
- ref_b= *block; |
|
1164 |
- ref_rd= best_rd; |
|
1165 |
- for(ref=0; ref < s->ref_frames; ref++){ |
|
1166 |
- int16_t (*mvr)[2]= &s->ref_mvs[ref][index]; |
|
1167 |
- if(s->ref_scores[ref][index] > s->ref_scores[ref_b.ref][index]*3/2) //FIXME tune threshold |
|
1168 |
- continue; |
|
1169 |
- block->ref= ref; |
|
1170 |
- best_rd= INT_MAX; |
|
1171 |
- |
|
1172 |
- check_block_inter(s, mb_x, mb_y, mvr[0][0], mvr[0][1], obmc_edged, &best_rd); |
|
1173 |
- check_block_inter(s, mb_x, mb_y, 0, 0, obmc_edged, &best_rd); |
|
1174 |
- if(tb) |
|
1175 |
- check_block_inter(s, mb_x, mb_y, mvr[-b_stride][0], mvr[-b_stride][1], obmc_edged, &best_rd); |
|
1176 |
- if(lb) |
|
1177 |
- check_block_inter(s, mb_x, mb_y, mvr[-1][0], mvr[-1][1], obmc_edged, &best_rd); |
|
1178 |
- if(rb) |
|
1179 |
- check_block_inter(s, mb_x, mb_y, mvr[1][0], mvr[1][1], obmc_edged, &best_rd); |
|
1180 |
- if(bb) |
|
1181 |
- check_block_inter(s, mb_x, mb_y, mvr[b_stride][0], mvr[b_stride][1], obmc_edged, &best_rd); |
|
1182 |
- |
|
1183 |
- /* fullpel ME */ |
|
1184 |
- //FIXME avoid subpel interpolation / round to nearest integer |
|
1185 |
- do{ |
|
1186 |
- dia_change=0; |
|
1187 |
- for(i=0; i<FFMAX(s->avctx->dia_size, 1); i++){ |
|
1188 |
- for(j=0; j<i; j++){ |
|
1189 |
- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my+(4*j), obmc_edged, &best_rd); |
|
1190 |
- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my-(4*j), obmc_edged, &best_rd); |
|
1191 |
- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my-(4*j), obmc_edged, &best_rd); |
|
1192 |
- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my+(4*j), obmc_edged, &best_rd); |
|
1193 |
- } |
|
1194 |
- } |
|
1195 |
- }while(dia_change); |
|
1196 |
- /* subpel ME */ |
|
1197 |
- do{ |
|
1198 |
- static const int square[8][2]= {{+1, 0},{-1, 0},{ 0,+1},{ 0,-1},{+1,+1},{-1,-1},{+1,-1},{-1,+1},}; |
|
1199 |
- dia_change=0; |
|
1200 |
- for(i=0; i<8; i++) |
|
1201 |
- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+square[i][0], block->my+square[i][1], obmc_edged, &best_rd); |
|
1202 |
- }while(dia_change); |
|
1203 |
- //FIXME or try the standard 2 pass qpel or similar |
|
1204 |
- |
|
1205 |
- mvr[0][0]= block->mx; |
|
1206 |
- mvr[0][1]= block->my; |
|
1207 |
- if(ref_rd > best_rd){ |
|
1208 |
- ref_rd= best_rd; |
|
1209 |
- ref_b= *block; |
|
1210 |
- } |
|
1211 |
- } |
|
1212 |
- best_rd= ref_rd; |
|
1213 |
- *block= ref_b; |
|
1214 |
- check_block(s, mb_x, mb_y, color, 1, obmc_edged, &best_rd); |
|
1215 |
- //FIXME RD style color selection |
|
1216 |
- if(!same_block(block, &backup)){ |
|
1217 |
- if(tb ) tb ->type &= ~BLOCK_OPT; |
|
1218 |
- if(lb ) lb ->type &= ~BLOCK_OPT; |
|
1219 |
- if(rb ) rb ->type &= ~BLOCK_OPT; |
|
1220 |
- if(bb ) bb ->type &= ~BLOCK_OPT; |
|
1221 |
- if(tlb) tlb->type &= ~BLOCK_OPT; |
|
1222 |
- if(trb) trb->type &= ~BLOCK_OPT; |
|
1223 |
- if(blb) blb->type &= ~BLOCK_OPT; |
|
1224 |
- if(brb) brb->type &= ~BLOCK_OPT; |
|
1225 |
- change ++; |
|
1226 |
- } |
|
1227 |
- } |
|
1228 |
- } |
|
1229 |
- av_log(s->avctx, AV_LOG_ERROR, "pass:%d changed:%d\n", pass, change); |
|
1230 |
- if(!change) |
|
1231 |
- break; |
|
1232 |
- } |
|
1233 |
- |
|
1234 |
- if(s->block_max_depth == 1){ |
|
1235 |
- int change= 0; |
|
1236 |
- for(mb_y= 0; mb_y<b_height; mb_y+=2){ |
|
1237 |
- for(mb_x= 0; mb_x<b_width; mb_x+=2){ |
|
1238 |
- int i; |
|
1239 |
- int best_rd, init_rd; |
|
1240 |
- const int index= mb_x + mb_y * b_stride; |
|
1241 |
- BlockNode *b[4]; |
|
1242 |
- |
|
1243 |
- b[0]= &s->block[index]; |
|
1244 |
- b[1]= b[0]+1; |
|
1245 |
- b[2]= b[0]+b_stride; |
|
1246 |
- b[3]= b[2]+1; |
|
1247 |
- if(same_block(b[0], b[1]) && |
|
1248 |
- same_block(b[0], b[2]) && |
|
1249 |
- same_block(b[0], b[3])) |
|
1250 |
- continue; |
|
1251 |
- |
|
1252 |
- if(!s->me_cache_generation) |
|
1253 |
- memset(s->me_cache, 0, sizeof(s->me_cache)); |
|
1254 |
- s->me_cache_generation += 1<<22; |
|
1255 |
- |
|
1256 |
- init_rd= best_rd= get_4block_rd(s, mb_x, mb_y, 0); |
|
1257 |
- |
|
1258 |
- //FIXME more multiref search? |
|
1259 |
- check_4block_inter(s, mb_x, mb_y, |
|
1260 |
- (b[0]->mx + b[1]->mx + b[2]->mx + b[3]->mx + 2) >> 2, |
|
1261 |
- (b[0]->my + b[1]->my + b[2]->my + b[3]->my + 2) >> 2, 0, &best_rd); |
|
1262 |
- |
|
1263 |
- for(i=0; i<4; i++) |
|
1264 |
- if(!(b[i]->type&BLOCK_INTRA)) |
|
1265 |
- check_4block_inter(s, mb_x, mb_y, b[i]->mx, b[i]->my, b[i]->ref, &best_rd); |
|
1266 |
- |
|
1267 |
- if(init_rd != best_rd) |
|
1268 |
- change++; |
|
1269 |
- } |
|
1270 |
- } |
|
1271 |
- av_log(s->avctx, AV_LOG_ERROR, "pass:4mv changed:%d\n", change*4); |
|
1272 |
- } |
|
1273 |
-} |
|
1274 |
- |
|
1275 |
-static void encode_blocks(SnowContext *s, int search){ |
|
1276 |
- int x, y; |
|
1277 |
- int w= s->b_width; |
|
1278 |
- int h= s->b_height; |
|
1279 |
- |
|
1280 |
- if(s->avctx->me_method == ME_ITER && !s->keyframe && search) |
|
1281 |
- iterative_me(s); |
|
1282 |
- |
|
1283 |
- for(y=0; y<h; y++){ |
|
1284 |
- if(s->c.bytestream_end - s->c.bytestream < w*MB_SIZE*MB_SIZE*3){ //FIXME nicer limit |
|
1285 |
- av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); |
|
1286 |
- return; |
|
1287 |
- } |
|
1288 |
- for(x=0; x<w; x++){ |
|
1289 |
- if(s->avctx->me_method == ME_ITER || !search) |
|
1290 |
- encode_q_branch2(s, 0, x, y); |
|
1291 |
- else |
|
1292 |
- encode_q_branch (s, 0, x, y); |
|
1293 |
- } |
|
1294 |
- } |
|
1295 |
-} |
|
1296 |
- |
|
1297 |
-static void quantize(SnowContext *s, SubBand *b, IDWTELEM *dst, DWTELEM *src, int stride, int bias){ |
|
1298 |
- const int w= b->width; |
|
1299 |
- const int h= b->height; |
|
1300 |
- const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); |
|
1301 |
- const int qmul= ff_qexp[qlog&(QROOT-1)]<<((qlog>>QSHIFT) + ENCODER_EXTRA_BITS); |
|
1302 |
- int x,y, thres1, thres2; |
|
1303 |
- |
|
1304 |
- if(s->qlog == LOSSLESS_QLOG){ |
|
1305 |
- for(y=0; y<h; y++) |
|
1306 |
- for(x=0; x<w; x++) |
|
1307 |
- dst[x + y*stride]= src[x + y*stride]; |
|
1308 |
- return; |
|
1309 |
- } |
|
1310 |
- |
|
1311 |
- bias= bias ? 0 : (3*qmul)>>3; |
|
1312 |
- thres1= ((qmul - bias)>>QEXPSHIFT) - 1; |
|
1313 |
- thres2= 2*thres1; |
|
1314 |
- |
|
1315 |
- if(!bias){ |
|
1316 |
- for(y=0; y<h; y++){ |
|
1317 |
- for(x=0; x<w; x++){ |
|
1318 |
- int i= src[x + y*stride]; |
|
1319 |
- |
|
1320 |
- if((unsigned)(i+thres1) > thres2){ |
|
1321 |
- if(i>=0){ |
|
1322 |
- i<<= QEXPSHIFT; |
|
1323 |
- i/= qmul; //FIXME optimize |
|
1324 |
- dst[x + y*stride]= i; |
|
1325 |
- }else{ |
|
1326 |
- i= -i; |
|
1327 |
- i<<= QEXPSHIFT; |
|
1328 |
- i/= qmul; //FIXME optimize |
|
1329 |
- dst[x + y*stride]= -i; |
|
1330 |
- } |
|
1331 |
- }else |
|
1332 |
- dst[x + y*stride]= 0; |
|
1333 |
- } |
|
1334 |
- } |
|
1335 |
- }else{ |
|
1336 |
- for(y=0; y<h; y++){ |
|
1337 |
- for(x=0; x<w; x++){ |
|
1338 |
- int i= src[x + y*stride]; |
|
1339 |
- |
|
1340 |
- if((unsigned)(i+thres1) > thres2){ |
|
1341 |
- if(i>=0){ |
|
1342 |
- i<<= QEXPSHIFT; |
|
1343 |
- i= (i + bias) / qmul; //FIXME optimize |
|
1344 |
- dst[x + y*stride]= i; |
|
1345 |
- }else{ |
|
1346 |
- i= -i; |
|
1347 |
- i<<= QEXPSHIFT; |
|
1348 |
- i= (i + bias) / qmul; //FIXME optimize |
|
1349 |
- dst[x + y*stride]= -i; |
|
1350 |
- } |
|
1351 |
- }else |
|
1352 |
- dst[x + y*stride]= 0; |
|
1353 |
- } |
|
1354 |
- } |
|
1355 |
- } |
|
1356 |
-} |
|
1357 |
- |
|
1358 |
-static void dequantize(SnowContext *s, SubBand *b, IDWTELEM *src, int stride){ |
|
1359 |
- const int w= b->width; |
|
1360 |
- const int h= b->height; |
|
1361 |
- const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); |
|
1362 |
- const int qmul= ff_qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); |
|
1363 |
- const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; |
|
1364 |
- int x,y; |
|
1365 |
- |
|
1366 |
- if(s->qlog == LOSSLESS_QLOG) return; |
|
1367 |
- |
|
1368 |
- for(y=0; y<h; y++){ |
|
1369 |
- for(x=0; x<w; x++){ |
|
1370 |
- int i= src[x + y*stride]; |
|
1371 |
- if(i<0){ |
|
1372 |
- src[x + y*stride]= -((-i*qmul + qadd)>>(QEXPSHIFT)); //FIXME try different bias |
|
1373 |
- }else if(i>0){ |
|
1374 |
- src[x + y*stride]= (( i*qmul + qadd)>>(QEXPSHIFT)); |
|
1375 |
- } |
|
1376 |
- } |
|
1377 |
- } |
|
1378 |
-} |
|
1379 |
- |
|
1380 |
-static void decorrelate(SnowContext *s, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median){ |
|
1381 |
- const int w= b->width; |
|
1382 |
- const int h= b->height; |
|
1383 |
- int x,y; |
|
1384 |
- |
|
1385 |
- for(y=h-1; y>=0; y--){ |
|
1386 |
- for(x=w-1; x>=0; x--){ |
|
1387 |
- int i= x + y*stride; |
|
1388 |
- |
|
1389 |
- if(x){ |
|
1390 |
- if(use_median){ |
|
1391 |
- if(y && x+1<w) src[i] -= mid_pred(src[i - 1], src[i - stride], src[i - stride + 1]); |
|
1392 |
- else src[i] -= src[i - 1]; |
|
1393 |
- }else{ |
|
1394 |
- if(y) src[i] -= mid_pred(src[i - 1], src[i - stride], src[i - 1] + src[i - stride] - src[i - 1 - stride]); |
|
1395 |
- else src[i] -= src[i - 1]; |
|
1396 |
- } |
|
1397 |
- }else{ |
|
1398 |
- if(y) src[i] -= src[i - stride]; |
|
1399 |
- } |
|
1400 |
- } |
|
1401 |
- } |
|
1402 |
-} |
|
1403 |
- |
|
1404 |
-static void correlate(SnowContext *s, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median){ |
|
1405 |
- const int w= b->width; |
|
1406 |
- const int h= b->height; |
|
1407 |
- int x,y; |
|
1408 |
- |
|
1409 |
- for(y=0; y<h; y++){ |
|
1410 |
- for(x=0; x<w; x++){ |
|
1411 |
- int i= x + y*stride; |
|
1412 |
- |
|
1413 |
- if(x){ |
|
1414 |
- if(use_median){ |
|
1415 |
- if(y && x+1<w) src[i] += mid_pred(src[i - 1], src[i - stride], src[i - stride + 1]); |
|
1416 |
- else src[i] += src[i - 1]; |
|
1417 |
- }else{ |
|
1418 |
- if(y) src[i] += mid_pred(src[i - 1], src[i - stride], src[i - 1] + src[i - stride] - src[i - 1 - stride]); |
|
1419 |
- else src[i] += src[i - 1]; |
|
1420 |
- } |
|
1421 |
- }else{ |
|
1422 |
- if(y) src[i] += src[i - stride]; |
|
1423 |
- } |
|
1424 |
- } |
|
1425 |
- } |
|
1426 |
-} |
|
1427 |
- |
|
1428 |
-static void encode_qlogs(SnowContext *s){ |
|
1429 |
- int plane_index, level, orientation; |
|
1430 |
- |
|
1431 |
- for(plane_index=0; plane_index<2; plane_index++){ |
|
1432 |
- for(level=0; level<s->spatial_decomposition_count; level++){ |
|
1433 |
- for(orientation=level ? 1:0; orientation<4; orientation++){ |
|
1434 |
- if(orientation==2) continue; |
|
1435 |
- put_symbol(&s->c, s->header_state, s->plane[plane_index].band[level][orientation].qlog, 1); |
|
1436 |
- } |
|
1437 |
- } |
|
1438 |
- } |
|
1439 |
-} |
|
1440 |
- |
|
1441 |
-static void encode_header(SnowContext *s){ |
|
1442 |
- int plane_index, i; |
|
1443 |
- uint8_t kstate[32]; |
|
1444 |
- |
|
1445 |
- memset(kstate, MID_STATE, sizeof(kstate)); |
|
1446 |
- |
|
1447 |
- put_rac(&s->c, kstate, s->keyframe); |
|
1448 |
- if(s->keyframe || s->always_reset){ |
|
1449 |
- ff_snow_reset_contexts(s); |
|
1450 |
- s->last_spatial_decomposition_type= |
|
1451 |
- s->last_qlog= |
|
1452 |
- s->last_qbias= |
|
1453 |
- s->last_mv_scale= |
|
1454 |
- s->last_block_max_depth= 0; |
|
1455 |
- for(plane_index=0; plane_index<2; plane_index++){ |
|
1456 |
- Plane *p= &s->plane[plane_index]; |
|
1457 |
- p->last_htaps=0; |
|
1458 |
- p->last_diag_mc=0; |
|
1459 |
- memset(p->last_hcoeff, 0, sizeof(p->last_hcoeff)); |
|
1460 |
- } |
|
1461 |
- } |
|
1462 |
- if(s->keyframe){ |
|
1463 |
- put_symbol(&s->c, s->header_state, s->version, 0); |
|
1464 |
- put_rac(&s->c, s->header_state, s->always_reset); |
|
1465 |
- put_symbol(&s->c, s->header_state, s->temporal_decomposition_type, 0); |
|
1466 |
- put_symbol(&s->c, s->header_state, s->temporal_decomposition_count, 0); |
|
1467 |
- put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0); |
|
1468 |
- put_symbol(&s->c, s->header_state, s->colorspace_type, 0); |
|
1469 |
- put_symbol(&s->c, s->header_state, s->chroma_h_shift, 0); |
|
1470 |
- put_symbol(&s->c, s->header_state, s->chroma_v_shift, 0); |
|
1471 |
- put_rac(&s->c, s->header_state, s->spatial_scalability); |
|
1472 |
-// put_rac(&s->c, s->header_state, s->rate_scalability); |
|
1473 |
- put_symbol(&s->c, s->header_state, s->max_ref_frames-1, 0); |
|
1474 |
- |
|
1475 |
- encode_qlogs(s); |
|
1476 |
- } |
|
1477 |
- |
|
1478 |
- if(!s->keyframe){ |
|
1479 |
- int update_mc=0; |
|
1480 |
- for(plane_index=0; plane_index<2; plane_index++){ |
|
1481 |
- Plane *p= &s->plane[plane_index]; |
|
1482 |
- update_mc |= p->last_htaps != p->htaps; |
|
1483 |
- update_mc |= p->last_diag_mc != p->diag_mc; |
|
1484 |
- update_mc |= !!memcmp(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff)); |
|
1485 |
- } |
|
1486 |
- put_rac(&s->c, s->header_state, update_mc); |
|
1487 |
- if(update_mc){ |
|
1488 |
- for(plane_index=0; plane_index<2; plane_index++){ |
|
1489 |
- Plane *p= &s->plane[plane_index]; |
|
1490 |
- put_rac(&s->c, s->header_state, p->diag_mc); |
|
1491 |
- put_symbol(&s->c, s->header_state, p->htaps/2-1, 0); |
|
1492 |
- for(i= p->htaps/2; i; i--) |
|
1493 |
- put_symbol(&s->c, s->header_state, FFABS(p->hcoeff[i]), 0); |
|
1494 |
- } |
|
1495 |
- } |
|
1496 |
- if(s->last_spatial_decomposition_count != s->spatial_decomposition_count){ |
|
1497 |
- put_rac(&s->c, s->header_state, 1); |
|
1498 |
- put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0); |
|
1499 |
- encode_qlogs(s); |
|
1500 |
- }else |
|
1501 |
- put_rac(&s->c, s->header_state, 0); |
|
1502 |
- } |
|
1503 |
- |
|
1504 |
- put_symbol(&s->c, s->header_state, s->spatial_decomposition_type - s->last_spatial_decomposition_type, 1); |
|
1505 |
- put_symbol(&s->c, s->header_state, s->qlog - s->last_qlog , 1); |
|
1506 |
- put_symbol(&s->c, s->header_state, s->mv_scale - s->last_mv_scale, 1); |
|
1507 |
- put_symbol(&s->c, s->header_state, s->qbias - s->last_qbias , 1); |
|
1508 |
- put_symbol(&s->c, s->header_state, s->block_max_depth - s->last_block_max_depth, 1); |
|
1509 |
- |
|
1510 |
-} |
|
1511 |
- |
|
1512 |
-static void update_last_header_values(SnowContext *s){ |
|
1513 |
- int plane_index; |
|
1514 |
- |
|
1515 |
- if(!s->keyframe){ |
|
1516 |
- for(plane_index=0; plane_index<2; plane_index++){ |
|
1517 |
- Plane *p= &s->plane[plane_index]; |
|
1518 |
- p->last_diag_mc= p->diag_mc; |
|
1519 |
- p->last_htaps = p->htaps; |
|
1520 |
- memcpy(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff)); |
|
1521 |
- } |
|
1522 |
- } |
|
1523 |
- |
|
1524 |
- s->last_spatial_decomposition_type = s->spatial_decomposition_type; |
|
1525 |
- s->last_qlog = s->qlog; |
|
1526 |
- s->last_qbias = s->qbias; |
|
1527 |
- s->last_mv_scale = s->mv_scale; |
|
1528 |
- s->last_block_max_depth = s->block_max_depth; |
|
1529 |
- s->last_spatial_decomposition_count = s->spatial_decomposition_count; |
|
1530 |
-} |
|
1531 |
- |
|
1532 |
-static int qscale2qlog(int qscale){ |
|
1533 |
- return rint(QROOT*log2(qscale / (float)FF_QP2LAMBDA)) |
|
1534 |
- + 61*QROOT/8; ///< 64 > 60 |
|
1535 |
-} |
|
1536 |
- |
|
1537 |
-static int ratecontrol_1pass(SnowContext *s, AVFrame *pict) |
|
1538 |
-{ |
|
1539 |
- /* Estimate the frame's complexity as a sum of weighted dwt coefficients. |
|
1540 |
- * FIXME we know exact mv bits at this point, |
|
1541 |
- * but ratecontrol isn't set up to include them. */ |
|
1542 |
- uint32_t coef_sum= 0; |
|
1543 |
- int level, orientation, delta_qlog; |
|
1544 |
- |
|
1545 |
- for(level=0; level<s->spatial_decomposition_count; level++){ |
|
1546 |
- for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
|
1547 |
- SubBand *b= &s->plane[0].band[level][orientation]; |
|
1548 |
- IDWTELEM *buf= b->ibuf; |
|
1549 |
- const int w= b->width; |
|
1550 |
- const int h= b->height; |
|
1551 |
- const int stride= b->stride; |
|
1552 |
- const int qlog= av_clip(2*QROOT + b->qlog, 0, QROOT*16); |
|
1553 |
- const int qmul= ff_qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); |
|
1554 |
- const int qdiv= (1<<16)/qmul; |
|
1555 |
- int x, y; |
|
1556 |
- //FIXME this is ugly |
|
1557 |
- for(y=0; y<h; y++) |
|
1558 |
- for(x=0; x<w; x++) |
|
1559 |
- buf[x+y*stride]= b->buf[x+y*stride]; |
|
1560 |
- if(orientation==0) |
|
1561 |
- decorrelate(s, b, buf, stride, 1, 0); |
|
1562 |
- for(y=0; y<h; y++) |
|
1563 |
- for(x=0; x<w; x++) |
|
1564 |
- coef_sum+= abs(buf[x+y*stride]) * qdiv >> 16; |
|
1565 |
- } |
|
1566 |
- } |
|
1567 |
- |
|
1568 |
- /* ugly, ratecontrol just takes a sqrt again */ |
|
1569 |
- coef_sum = (uint64_t)coef_sum * coef_sum >> 16; |
|
1570 |
- assert(coef_sum < INT_MAX); |
|
1571 |
- |
|
1572 |
- if(pict->pict_type == AV_PICTURE_TYPE_I){ |
|
1573 |
- s->m.current_picture.mb_var_sum= coef_sum; |
|
1574 |
- s->m.current_picture.mc_mb_var_sum= 0; |
|
1575 |
- }else{ |
|
1576 |
- s->m.current_picture.mc_mb_var_sum= coef_sum; |
|
1577 |
- s->m.current_picture.mb_var_sum= 0; |
|
1578 |
- } |
|
1579 |
- |
|
1580 |
- pict->quality= ff_rate_estimate_qscale(&s->m, 1); |
|
1581 |
- if (pict->quality < 0) |
|
1582 |
- return INT_MIN; |
|
1583 |
- s->lambda= pict->quality * 3/2; |
|
1584 |
- delta_qlog= qscale2qlog(pict->quality) - s->qlog; |
|
1585 |
- s->qlog+= delta_qlog; |
|
1586 |
- return delta_qlog; |
|
1587 |
-} |
|
1588 |
- |
|
1589 |
-static void calculate_visual_weight(SnowContext *s, Plane *p){ |
|
1590 |
- int width = p->width; |
|
1591 |
- int height= p->height; |
|
1592 |
- int level, orientation, x, y; |
|
1593 |
- |
|
1594 |
- for(level=0; level<s->spatial_decomposition_count; level++){ |
|
1595 |
- for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
|
1596 |
- SubBand *b= &p->band[level][orientation]; |
|
1597 |
- IDWTELEM *ibuf= b->ibuf; |
|
1598 |
- int64_t error=0; |
|
1599 |
- |
|
1600 |
- memset(s->spatial_idwt_buffer, 0, sizeof(*s->spatial_idwt_buffer)*width*height); |
|
1601 |
- ibuf[b->width/2 + b->height/2*b->stride]= 256*16; |
|
1602 |
- ff_spatial_idwt(s->spatial_idwt_buffer, s->temp_idwt_buffer, width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); |
|
1603 |
- for(y=0; y<height; y++){ |
|
1604 |
- for(x=0; x<width; x++){ |
|
1605 |
- int64_t d= s->spatial_idwt_buffer[x + y*width]*16; |
|
1606 |
- error += d*d; |
|
1607 |
- } |
|
1608 |
- } |
|
1609 |
- |
|
1610 |
- b->qlog= (int)(log(352256.0/sqrt(error)) / log(pow(2.0, 1.0/QROOT))+0.5); |
|
1611 |
- } |
|
1612 |
- } |
|
1613 |
-} |
|
1614 |
- |
|
1615 |
-static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
|
1616 |
- const AVFrame *pict, int *got_packet) |
|
1617 |
-{ |
|
1618 |
- SnowContext *s = avctx->priv_data; |
|
1619 |
- RangeCoder * const c= &s->c; |
|
1620 |
- AVFrame *pic = &s->new_picture; |
|
1621 |
- const int width= s->avctx->width; |
|
1622 |
- const int height= s->avctx->height; |
|
1623 |
- int level, orientation, plane_index, i, y, ret; |
|
1624 |
- uint8_t rc_header_bak[sizeof(s->header_state)]; |
|
1625 |
- uint8_t rc_block_bak[sizeof(s->block_state)]; |
|
1626 |
- |
|
1627 |
- if (!pkt->data && |
|
1628 |
- (ret = av_new_packet(pkt, s->b_width*s->b_height*MB_SIZE*MB_SIZE*3 + FF_MIN_BUFFER_SIZE)) < 0) { |
|
1629 |
- av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n"); |
|
1630 |
- return ret; |
|
1631 |
- } |
|
1632 |
- |
|
1633 |
- ff_init_range_encoder(c, pkt->data, pkt->size); |
|
1634 |
- ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); |
|
1635 |
- |
|
1636 |
- for(i=0; i<3; i++){ |
|
1637 |
- int shift= !!i; |
|
1638 |
- for(y=0; y<(height>>shift); y++) |
|
1639 |
- memcpy(&s->input_picture.data[i][y * s->input_picture.linesize[i]], |
|
1640 |
- &pict->data[i][y * pict->linesize[i]], |
|
1641 |
- width>>shift); |
|
1642 |
- } |
|
1643 |
- s->new_picture = *pict; |
|
1644 |
- |
|
1645 |
- s->m.picture_number= avctx->frame_number; |
|
1646 |
- if(avctx->flags&CODEC_FLAG_PASS2){ |
|
1647 |
- s->m.pict_type = pic->pict_type = s->m.rc_context.entry[avctx->frame_number].new_pict_type; |
|
1648 |
- s->keyframe = pic->pict_type == AV_PICTURE_TYPE_I; |
|
1649 |
- if(!(avctx->flags&CODEC_FLAG_QSCALE)) { |
|
1650 |
- pic->quality = ff_rate_estimate_qscale(&s->m, 0); |
|
1651 |
- if (pic->quality < 0) |
|
1652 |
- return -1; |
|
1653 |
- } |
|
1654 |
- }else{ |
|
1655 |
- s->keyframe= avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0; |
|
1656 |
- s->m.pict_type = pic->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; |
|
1657 |
- } |
|
1658 |
- |
|
1659 |
- if(s->pass1_rc && avctx->frame_number == 0) |
|
1660 |
- pic->quality = 2*FF_QP2LAMBDA; |
|
1661 |
- if (pic->quality) { |
|
1662 |
- s->qlog = qscale2qlog(pic->quality); |
|
1663 |
- s->lambda = pic->quality * 3/2; |
|
1664 |
- } |
|
1665 |
- if (s->qlog < 0 || (!pic->quality && (avctx->flags & CODEC_FLAG_QSCALE))) { |
|
1666 |
- s->qlog= LOSSLESS_QLOG; |
|
1667 |
- s->lambda = 0; |
|
1668 |
- }//else keep previous frame's qlog until after motion estimation |
|
1669 |
- |
|
1670 |
- ff_snow_frame_start(s); |
|
1671 |
- |
|
1672 |
- s->m.current_picture_ptr= &s->m.current_picture; |
|
1673 |
- s->m.last_picture.f.pts = s->m.current_picture.f.pts; |
|
1674 |
- s->m.current_picture.f.pts = pict->pts; |
|
1675 |
- if(pic->pict_type == AV_PICTURE_TYPE_P){ |
|
1676 |
- int block_width = (width +15)>>4; |
|
1677 |
- int block_height= (height+15)>>4; |
|
1678 |
- int stride= s->current_picture.linesize[0]; |
|
1679 |
- |
|
1680 |
- assert(s->current_picture.data[0]); |
|
1681 |
- assert(s->last_picture[0].data[0]); |
|
1682 |
- |
|
1683 |
- s->m.avctx= s->avctx; |
|
1684 |
- s->m.current_picture.f.data[0] = s->current_picture.data[0]; |
|
1685 |
- s->m. last_picture.f.data[0] = s->last_picture[0].data[0]; |
|
1686 |
- s->m. new_picture.f.data[0] = s-> input_picture.data[0]; |
|
1687 |
- s->m. last_picture_ptr= &s->m. last_picture; |
|
1688 |
- s->m.linesize= |
|
1689 |
- s->m. last_picture.f.linesize[0] = |
|
1690 |
- s->m. new_picture.f.linesize[0] = |
|
1691 |
- s->m.current_picture.f.linesize[0] = stride; |
|
1692 |
- s->m.uvlinesize= s->current_picture.linesize[1]; |
|
1693 |
- s->m.width = width; |
|
1694 |
- s->m.height= height; |
|
1695 |
- s->m.mb_width = block_width; |
|
1696 |
- s->m.mb_height= block_height; |
|
1697 |
- s->m.mb_stride= s->m.mb_width+1; |
|
1698 |
- s->m.b8_stride= 2*s->m.mb_width+1; |
|
1699 |
- s->m.f_code=1; |
|
1700 |
- s->m.pict_type = pic->pict_type; |
|
1701 |
- s->m.me_method= s->avctx->me_method; |
|
1702 |
- s->m.me.scene_change_score=0; |
|
1703 |
- s->m.flags= s->avctx->flags; |
|
1704 |
- s->m.quarter_sample= (s->avctx->flags & CODEC_FLAG_QPEL)!=0; |
|
1705 |
- s->m.out_format= FMT_H263; |
|
1706 |
- s->m.unrestricted_mv= 1; |
|
1707 |
- |
|
1708 |
- s->m.lambda = s->lambda; |
|
1709 |
- s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); |
|
1710 |
- s->lambda2= s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; |
|
1711 |
- |
|
1712 |
- s->m.dsp= s->dsp; //move |
|
1713 |
- ff_init_me(&s->m); |
|
1714 |
- s->dsp= s->m.dsp; |
|
1715 |
- } |
|
1716 |
- |
|
1717 |
- if(s->pass1_rc){ |
|
1718 |
- memcpy(rc_header_bak, s->header_state, sizeof(s->header_state)); |
|
1719 |
- memcpy(rc_block_bak, s->block_state, sizeof(s->block_state)); |
|
1720 |
- } |
|
1721 |
- |
|
1722 |
-redo_frame: |
|
1723 |
- |
|
1724 |
- if (pic->pict_type == AV_PICTURE_TYPE_I) |
|
1725 |
- s->spatial_decomposition_count= 5; |
|
1726 |
- else |
|
1727 |
- s->spatial_decomposition_count= 5; |
|
1728 |
- |
|
1729 |
- s->m.pict_type = pic->pict_type; |
|
1730 |
- s->qbias = pic->pict_type == AV_PICTURE_TYPE_P ? 2 : 0; |
|
1731 |
- |
|
1732 |
- ff_snow_common_init_after_header(avctx); |
|
1733 |
- |
|
1734 |
- if(s->last_spatial_decomposition_count != s->spatial_decomposition_count){ |
|
1735 |
- for(plane_index=0; plane_index<3; plane_index++){ |
|
1736 |
- calculate_visual_weight(s, &s->plane[plane_index]); |
|
1737 |
- } |
|
1738 |
- } |
|
1739 |
- |
|
1740 |
- encode_header(s); |
|
1741 |
- s->m.misc_bits = 8*(s->c.bytestream - s->c.bytestream_start); |
|
1742 |
- encode_blocks(s, 1); |
|
1743 |
- s->m.mv_bits = 8*(s->c.bytestream - s->c.bytestream_start) - s->m.misc_bits; |
|
1744 |
- |
|
1745 |
- for(plane_index=0; plane_index<3; plane_index++){ |
|
1746 |
- Plane *p= &s->plane[plane_index]; |
|
1747 |
- int w= p->width; |
|
1748 |
- int h= p->height; |
|
1749 |
- int x, y; |
|
1750 |
-// int bits= put_bits_count(&s->c.pb); |
|
1751 |
- |
|
1752 |
- if (!s->memc_only) { |
|
1753 |
- //FIXME optimize |
|
1754 |
- if(pict->data[plane_index]) //FIXME gray hack |
|
1755 |
- for(y=0; y<h; y++){ |
|
1756 |
- for(x=0; x<w; x++){ |
|
1757 |
- s->spatial_idwt_buffer[y*w + x]= pict->data[plane_index][y*pict->linesize[plane_index] + x]<<FRAC_BITS; |
|
1758 |
- } |
|
1759 |
- } |
|
1760 |
- predict_plane(s, s->spatial_idwt_buffer, plane_index, 0); |
|
1761 |
- |
|
1762 |
- if( plane_index==0 |
|
1763 |
- && pic->pict_type == AV_PICTURE_TYPE_P |
|
1764 |
- && !(avctx->flags&CODEC_FLAG_PASS2) |
|
1765 |
- && s->m.me.scene_change_score > s->avctx->scenechange_threshold){ |
|
1766 |
- ff_init_range_encoder(c, pkt->data, pkt->size); |
|
1767 |
- ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); |
|
1768 |
- pic->pict_type= AV_PICTURE_TYPE_I; |
|
1769 |
- s->keyframe=1; |
|
1770 |
- s->current_picture.key_frame=1; |
|
1771 |
- goto redo_frame; |
|
1772 |
- } |
|
1773 |
- |
|
1774 |
- if(s->qlog == LOSSLESS_QLOG){ |
|
1775 |
- for(y=0; y<h; y++){ |
|
1776 |
- for(x=0; x<w; x++){ |
|
1777 |
- s->spatial_dwt_buffer[y*w + x]= (s->spatial_idwt_buffer[y*w + x] + (1<<(FRAC_BITS-1))-1)>>FRAC_BITS; |
|
1778 |
- } |
|
1779 |
- } |
|
1780 |
- }else{ |
|
1781 |
- for(y=0; y<h; y++){ |
|
1782 |
- for(x=0; x<w; x++){ |
|
1783 |
- s->spatial_dwt_buffer[y*w + x]=s->spatial_idwt_buffer[y*w + x]<<ENCODER_EXTRA_BITS; |
|
1784 |
- } |
|
1785 |
- } |
|
1786 |
- } |
|
1787 |
- |
|
1788 |
- /* if(QUANTIZE2) |
|
1789 |
- dwt_quantize(s, p, s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type); |
|
1790 |
- else*/ |
|
1791 |
- ff_spatial_dwt(s->spatial_dwt_buffer, s->temp_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); |
|
1792 |
- |
|
1793 |
- if(s->pass1_rc && plane_index==0){ |
|
1794 |
- int delta_qlog = ratecontrol_1pass(s, pic); |
|
1795 |
- if (delta_qlog <= INT_MIN) |
|
1796 |
- return -1; |
|
1797 |
- if(delta_qlog){ |
|
1798 |
- //reordering qlog in the bitstream would eliminate this reset |
|
1799 |
- ff_init_range_encoder(c, pkt->data, pkt->size); |
|
1800 |
- memcpy(s->header_state, rc_header_bak, sizeof(s->header_state)); |
|
1801 |
- memcpy(s->block_state, rc_block_bak, sizeof(s->block_state)); |
|
1802 |
- encode_header(s); |
|
1803 |
- encode_blocks(s, 0); |
|
1804 |
- } |
|
1805 |
- } |
|
1806 |
- |
|
1807 |
- for(level=0; level<s->spatial_decomposition_count; level++){ |
|
1808 |
- for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
|
1809 |
- SubBand *b= &p->band[level][orientation]; |
|
1810 |
- |
|
1811 |
- if(!QUANTIZE2) |
|
1812 |
- quantize(s, b, b->ibuf, b->buf, b->stride, s->qbias); |
|
1813 |
- if(orientation==0) |
|
1814 |
- decorrelate(s, b, b->ibuf, b->stride, pic->pict_type == AV_PICTURE_TYPE_P, 0); |
|
1815 |
- encode_subband(s, b, b->ibuf, b->parent ? b->parent->ibuf : NULL, b->stride, orientation); |
|
1816 |
- assert(b->parent==NULL || b->parent->stride == b->stride*2); |
|
1817 |
- if(orientation==0) |
|
1818 |
- correlate(s, b, b->ibuf, b->stride, 1, 0); |
|
1819 |
- } |
|
1820 |
- } |
|
1821 |
- |
|
1822 |
- for(level=0; level<s->spatial_decomposition_count; level++){ |
|
1823 |
- for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
|
1824 |
- SubBand *b= &p->band[level][orientation]; |
|
1825 |
- |
|
1826 |
- dequantize(s, b, b->ibuf, b->stride); |
|
1827 |
- } |
|
1828 |
- } |
|
1829 |
- |
|
1830 |
- ff_spatial_idwt(s->spatial_idwt_buffer, s->temp_idwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); |
|
1831 |
- if(s->qlog == LOSSLESS_QLOG){ |
|
1832 |
- for(y=0; y<h; y++){ |
|
1833 |
- for(x=0; x<w; x++){ |
|
1834 |
- s->spatial_idwt_buffer[y*w + x]<<=FRAC_BITS; |
|
1835 |
- } |
|
1836 |
- } |
|
1837 |
- } |
|
1838 |
- predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); |
|
1839 |
- }else{ |
|
1840 |
- //ME/MC only |
|
1841 |
- if(pic->pict_type == AV_PICTURE_TYPE_I){ |
|
1842 |
- for(y=0; y<h; y++){ |
|
1843 |
- for(x=0; x<w; x++){ |
|
1844 |
- s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]= |
|
1845 |
- pict->data[plane_index][y*pict->linesize[plane_index] + x]; |
|
1846 |
- } |
|
1847 |
- } |
|
1848 |
- }else{ |
|
1849 |
- memset(s->spatial_idwt_buffer, 0, sizeof(IDWTELEM)*w*h); |
|
1850 |
- predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); |
|
1851 |
- } |
|
1852 |
- } |
|
1853 |
- if(s->avctx->flags&CODEC_FLAG_PSNR){ |
|
1854 |
- int64_t error= 0; |
|
1855 |
- |
|
1856 |
- if(pict->data[plane_index]) //FIXME gray hack |
|
1857 |
- for(y=0; y<h; y++){ |
|
1858 |
- for(x=0; x<w; x++){ |
|
1859 |
- int d= s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x] - pict->data[plane_index][y*pict->linesize[plane_index] + x]; |
|
1860 |
- error += d*d; |
|
1861 |
- } |
|
1862 |
- } |
|
1863 |
- s->avctx->error[plane_index] += error; |
|
1864 |
- s->current_picture.error[plane_index] = error; |
|
1865 |
- } |
|
1866 |
- |
|
1867 |
- } |
|
1868 |
- |
|
1869 |
- update_last_header_values(s); |
|
1870 |
- |
|
1871 |
- ff_snow_release_buffer(avctx); |
|
1872 |
- |
|
1873 |
- s->current_picture.coded_picture_number = avctx->frame_number; |
|
1874 |
- s->current_picture.pict_type = pict->pict_type; |
|
1875 |
- s->current_picture.quality = pict->quality; |
|
1876 |
- s->m.frame_bits = 8*(s->c.bytestream - s->c.bytestream_start); |
|
1877 |
- s->m.p_tex_bits = s->m.frame_bits - s->m.misc_bits - s->m.mv_bits; |
|
1878 |
- s->m.current_picture.f.display_picture_number = |
|
1879 |
- s->m.current_picture.f.coded_picture_number = avctx->frame_number; |
|
1880 |
- s->m.current_picture.f.quality = pic->quality; |
|
1881 |
- s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start); |
|
1882 |
- if(s->pass1_rc) |
|
1883 |
- if (ff_rate_estimate_qscale(&s->m, 0) < 0) |
|
1884 |
- return -1; |
|
1885 |
- if(avctx->flags&CODEC_FLAG_PASS1) |
|
1886 |
- ff_write_pass1_stats(&s->m); |
|
1887 |
- s->m.last_pict_type = s->m.pict_type; |
|
1888 |
- avctx->frame_bits = s->m.frame_bits; |
|
1889 |
- avctx->mv_bits = s->m.mv_bits; |
|
1890 |
- avctx->misc_bits = s->m.misc_bits; |
|
1891 |
- avctx->p_tex_bits = s->m.p_tex_bits; |
|
1892 |
- |
|
1893 |
- emms_c(); |
|
1894 |
- |
|
1895 |
- pkt->size = ff_rac_terminate(c); |
|
1896 |
- if (avctx->coded_frame->key_frame) |
|
1897 |
- pkt->flags |= AV_PKT_FLAG_KEY; |
|
1898 |
- *got_packet = 1; |
|
1899 |
- |
|
1900 |
- return 0; |
|
1901 |
-} |
|
1902 |
- |
|
1903 |
-static av_cold int encode_end(AVCodecContext *avctx) |
|
1904 |
-{ |
|
1905 |
- SnowContext *s = avctx->priv_data; |
|
1906 |
- |
|
1907 |
- ff_snow_common_end(s); |
|
1908 |
- if (s->input_picture.data[0]) |
|
1909 |
- avctx->release_buffer(avctx, &s->input_picture); |
|
1910 |
- av_free(avctx->stats_out); |
|
1911 |
- |
|
1912 |
- return 0; |
|
1913 |
-} |
|
1914 |
- |
|
1915 |
-#define OFFSET(x) offsetof(SnowContext, x) |
|
1916 |
-#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM |
|
1917 |
-static const AVOption options[] = { |
|
1918 |
- { "memc_only", "Only do ME/MC (I frames -> ref, P frame -> ME+MC).", OFFSET(memc_only), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, |
|
1919 |
- { NULL }, |
|
1920 |
-}; |
|
1921 |
- |
|
1922 |
-static const AVClass snowenc_class = { |
|
1923 |
- .class_name = "snow encoder", |
|
1924 |
- .item_name = av_default_item_name, |
|
1925 |
- .option = options, |
|
1926 |
- .version = LIBAVUTIL_VERSION_INT, |
|
1927 |
-}; |
|
1928 |
- |
|
1929 |
-AVCodec ff_snow_encoder = { |
|
1930 |
- .name = "snow", |
|
1931 |
- .type = AVMEDIA_TYPE_VIDEO, |
|
1932 |
- .id = AV_CODEC_ID_SNOW, |
|
1933 |
- .priv_data_size = sizeof(SnowContext), |
|
1934 |
- .init = encode_init, |
|
1935 |
- .encode2 = encode_frame, |
|
1936 |
- .close = encode_end, |
|
1937 |
- .long_name = NULL_IF_CONFIG_SMALL("Snow"), |
|
1938 |
- .priv_class = &snowenc_class, |
|
1939 |
-}; |
... | ... |
@@ -32,7 +32,6 @@ MMX-OBJS += x86/dsputil_mmx.o \ |
32 | 32 |
x86/idct_sse2_xvid.o \ |
33 | 33 |
x86/simple_idct.o \ |
34 | 34 |
|
35 |
-MMX-OBJS-$(CONFIG_DWT) += x86/snowdsp.o |
|
36 | 35 |
MMX-OBJS-$(CONFIG_ENCODERS) += x86/dsputilenc_mmx.o \ |
37 | 36 |
x86/motion_est.o |
38 | 37 |
MMX-OBJS-$(CONFIG_VC1_DECODER) += x86/vc1dsp_mmx.o |
... | ... |
@@ -466,7 +466,7 @@ void ff_dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx) |
466 | 466 |
c->pix_abs[1][3] = sad8_xy2_mmxext; |
467 | 467 |
} |
468 | 468 |
} |
469 |
- if ((mm_flags & AV_CPU_FLAG_SSE2) && !(mm_flags & AV_CPU_FLAG_3DNOW) && avctx->codec_id != AV_CODEC_ID_SNOW) { |
|
469 |
+ if ((mm_flags & AV_CPU_FLAG_SSE2) && !(mm_flags & AV_CPU_FLAG_3DNOW)) { |
|
470 | 470 |
c->sad[0]= sad16_sse2; |
471 | 471 |
} |
472 | 472 |
#endif /* HAVE_INLINE_ASM */ |
473 | 473 |
deleted file mode 100644 |
... | ... |
@@ -1,902 +0,0 @@ |
1 |
-/* |
|
2 |
- * MMX and SSE2 optimized snow DSP utils |
|
3 |
- * Copyright (c) 2005-2006 Robert Edele <yartrebo@earthlink.net> |
|
4 |
- * |
|
5 |
- * This file is part of Libav. |
|
6 |
- * |
|
7 |
- * Libav is free software; you can redistribute it and/or |
|
8 |
- * modify it under the terms of the GNU Lesser General Public |
|
9 |
- * License as published by the Free Software Foundation; either |
|
10 |
- * version 2.1 of the License, or (at your option) any later version. |
|
11 |
- * |
|
12 |
- * Libav is distributed in the hope that it will be useful, |
|
13 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 |
- * Lesser General Public License for more details. |
|
16 |
- * |
|
17 |
- * You should have received a copy of the GNU Lesser General Public |
|
18 |
- * License along with Libav; if not, write to the Free Software |
|
19 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
20 |
- */ |
|
21 |
- |
|
22 |
-#include "libavutil/cpu.h" |
|
23 |
-#include "libavutil/x86/asm.h" |
|
24 |
-#include "libavcodec/avcodec.h" |
|
25 |
-#include "libavcodec/snow.h" |
|
26 |
-#include "libavcodec/dwt.h" |
|
27 |
-#include "dsputil_mmx.h" |
|
28 |
- |
|
29 |
-#if HAVE_INLINE_ASM |
|
30 |
- |
|
31 |
-static void ff_snow_horizontal_compose97i_sse2(IDWTELEM *b, IDWTELEM *temp, int width){ |
|
32 |
- const int w2= (width+1)>>1; |
|
33 |
- const int w_l= (width>>1); |
|
34 |
- const int w_r= w2 - 1; |
|
35 |
- int i; |
|
36 |
- |
|
37 |
- { // Lift 0 |
|
38 |
- IDWTELEM * const ref = b + w2 - 1; |
|
39 |
- IDWTELEM b_0 = b[0]; //By allowing the first entry in b[0] to be calculated twice |
|
40 |
- // (the first time erroneously), we allow the SSE2 code to run an extra pass. |
|
41 |
- // The savings in code and time are well worth having to store this value and |
|
42 |
- // calculate b[0] correctly afterwards. |
|
43 |
- |
|
44 |
- i = 0; |
|
45 |
- __asm__ volatile( |
|
46 |
- "pcmpeqd %%xmm7, %%xmm7 \n\t" |
|
47 |
- "pcmpeqd %%xmm3, %%xmm3 \n\t" |
|
48 |
- "psllw $1, %%xmm3 \n\t" |
|
49 |
- "paddw %%xmm7, %%xmm3 \n\t" |
|
50 |
- "psllw $13, %%xmm3 \n\t" |
|
51 |
- ::); |
|
52 |
- for(; i<w_l-15; i+=16){ |
|
53 |
- __asm__ volatile( |
|
54 |
- "movdqu (%1), %%xmm1 \n\t" |
|
55 |
- "movdqu 16(%1), %%xmm5 \n\t" |
|
56 |
- "movdqu 2(%1), %%xmm2 \n\t" |
|
57 |
- "movdqu 18(%1), %%xmm6 \n\t" |
|
58 |
- "paddw %%xmm1, %%xmm2 \n\t" |
|
59 |
- "paddw %%xmm5, %%xmm6 \n\t" |
|
60 |
- "paddw %%xmm7, %%xmm2 \n\t" |
|
61 |
- "paddw %%xmm7, %%xmm6 \n\t" |
|
62 |
- "pmulhw %%xmm3, %%xmm2 \n\t" |
|
63 |
- "pmulhw %%xmm3, %%xmm6 \n\t" |
|
64 |
- "paddw (%0), %%xmm2 \n\t" |
|
65 |
- "paddw 16(%0), %%xmm6 \n\t" |
|
66 |
- "movdqa %%xmm2, (%0) \n\t" |
|
67 |
- "movdqa %%xmm6, 16(%0) \n\t" |
|
68 |
- :: "r"(&b[i]), "r"(&ref[i]) |
|
69 |
- : "memory" |
|
70 |
- ); |
|
71 |
- } |
|
72 |
- snow_horizontal_compose_lift_lead_out(i, b, b, ref, width, w_l, 0, W_DM, W_DO, W_DS); |
|
73 |
- b[0] = b_0 - ((W_DM * 2 * ref[1]+W_DO)>>W_DS); |
|
74 |
- } |
|
75 |
- |
|
76 |
- { // Lift 1 |
|
77 |
- IDWTELEM * const dst = b+w2; |
|
78 |
- |
|
79 |
- i = 0; |
|
80 |
- for(; (((x86_reg)&dst[i]) & 0x1F) && i<w_r; i++){ |
|
81 |
- dst[i] = dst[i] - (b[i] + b[i + 1]); |
|
82 |
- } |
|
83 |
- for(; i<w_r-15; i+=16){ |
|
84 |
- __asm__ volatile( |
|
85 |
- "movdqu (%1), %%xmm1 \n\t" |
|
86 |
- "movdqu 16(%1), %%xmm5 \n\t" |
|
87 |
- "movdqu 2(%1), %%xmm2 \n\t" |
|
88 |
- "movdqu 18(%1), %%xmm6 \n\t" |
|
89 |
- "paddw %%xmm1, %%xmm2 \n\t" |
|
90 |
- "paddw %%xmm5, %%xmm6 \n\t" |
|
91 |
- "movdqa (%0), %%xmm0 \n\t" |
|
92 |
- "movdqa 16(%0), %%xmm4 \n\t" |
|
93 |
- "psubw %%xmm2, %%xmm0 \n\t" |
|
94 |
- "psubw %%xmm6, %%xmm4 \n\t" |
|
95 |
- "movdqa %%xmm0, (%0) \n\t" |
|
96 |
- "movdqa %%xmm4, 16(%0) \n\t" |
|
97 |
- :: "r"(&dst[i]), "r"(&b[i]) |
|
98 |
- : "memory" |
|
99 |
- ); |
|
100 |
- } |
|
101 |
- snow_horizontal_compose_lift_lead_out(i, dst, dst, b, width, w_r, 1, W_CM, W_CO, W_CS); |
|
102 |
- } |
|
103 |
- |
|
104 |
- { // Lift 2 |
|
105 |
- IDWTELEM * const ref = b+w2 - 1; |
|
106 |
- IDWTELEM b_0 = b[0]; |
|
107 |
- |
|
108 |
- i = 0; |
|
109 |
- __asm__ volatile( |
|
110 |
- "psllw $15, %%xmm7 \n\t" |
|
111 |
- "pcmpeqw %%xmm6, %%xmm6 \n\t" |
|
112 |
- "psrlw $13, %%xmm6 \n\t" |
|
113 |
- "paddw %%xmm7, %%xmm6 \n\t" |
|
114 |
- ::); |
|
115 |
- for(; i<w_l-15; i+=16){ |
|
116 |
- __asm__ volatile( |
|
117 |
- "movdqu (%1), %%xmm0 \n\t" |
|
118 |
- "movdqu 16(%1), %%xmm4 \n\t" |
|
119 |
- "movdqu 2(%1), %%xmm1 \n\t" |
|
120 |
- "movdqu 18(%1), %%xmm5 \n\t" //FIXME try aligned reads and shifts |
|
121 |
- "paddw %%xmm6, %%xmm0 \n\t" |
|
122 |
- "paddw %%xmm6, %%xmm4 \n\t" |
|
123 |
- "paddw %%xmm7, %%xmm1 \n\t" |
|
124 |
- "paddw %%xmm7, %%xmm5 \n\t" |
|
125 |
- "pavgw %%xmm1, %%xmm0 \n\t" |
|
126 |
- "pavgw %%xmm5, %%xmm4 \n\t" |
|
127 |
- "psubw %%xmm7, %%xmm0 \n\t" |
|
128 |
- "psubw %%xmm7, %%xmm4 \n\t" |
|
129 |
- "psraw $1, %%xmm0 \n\t" |
|
130 |
- "psraw $1, %%xmm4 \n\t" |
|
131 |
- "movdqa (%0), %%xmm1 \n\t" |
|
132 |
- "movdqa 16(%0), %%xmm5 \n\t" |
|
133 |
- "paddw %%xmm1, %%xmm0 \n\t" |
|
134 |
- "paddw %%xmm5, %%xmm4 \n\t" |
|
135 |
- "psraw $2, %%xmm0 \n\t" |
|
136 |
- "psraw $2, %%xmm4 \n\t" |
|
137 |
- "paddw %%xmm1, %%xmm0 \n\t" |
|
138 |
- "paddw %%xmm5, %%xmm4 \n\t" |
|
139 |
- "movdqa %%xmm0, (%0) \n\t" |
|
140 |
- "movdqa %%xmm4, 16(%0) \n\t" |
|
141 |
- :: "r"(&b[i]), "r"(&ref[i]) |
|
142 |
- : "memory" |
|
143 |
- ); |
|
144 |
- } |
|
145 |
- snow_horizontal_compose_liftS_lead_out(i, b, b, ref, width, w_l); |
|
146 |
- b[0] = b_0 + ((2 * ref[1] + W_BO-1 + 4 * b_0) >> W_BS); |
|
147 |
- } |
|
148 |
- |
|
149 |
- { // Lift 3 |
|
150 |
- IDWTELEM * const src = b+w2; |
|
151 |
- |
|
152 |
- i = 0; |
|
153 |
- for(; (((x86_reg)&temp[i]) & 0x1F) && i<w_r; i++){ |
|
154 |
- temp[i] = src[i] - ((-W_AM*(b[i] + b[i+1]))>>W_AS); |
|
155 |
- } |
|
156 |
- for(; i<w_r-7; i+=8){ |
|
157 |
- __asm__ volatile( |
|
158 |
- "movdqu 2(%1), %%xmm2 \n\t" |
|
159 |
- "movdqu 18(%1), %%xmm6 \n\t" |
|
160 |
- "paddw (%1), %%xmm2 \n\t" |
|
161 |
- "paddw 16(%1), %%xmm6 \n\t" |
|
162 |
- "movdqu (%0), %%xmm0 \n\t" |
|
163 |
- "movdqu 16(%0), %%xmm4 \n\t" |
|
164 |
- "paddw %%xmm2, %%xmm0 \n\t" |
|
165 |
- "paddw %%xmm6, %%xmm4 \n\t" |
|
166 |
- "psraw $1, %%xmm2 \n\t" |
|
167 |
- "psraw $1, %%xmm6 \n\t" |
|
168 |
- "paddw %%xmm0, %%xmm2 \n\t" |
|
169 |
- "paddw %%xmm4, %%xmm6 \n\t" |
|
170 |
- "movdqa %%xmm2, (%2) \n\t" |
|
171 |
- "movdqa %%xmm6, 16(%2) \n\t" |
|
172 |
- :: "r"(&src[i]), "r"(&b[i]), "r"(&temp[i]) |
|
173 |
- : "memory" |
|
174 |
- ); |
|
175 |
- } |
|
176 |
- snow_horizontal_compose_lift_lead_out(i, temp, src, b, width, w_r, 1, -W_AM, W_AO+1, W_AS); |
|
177 |
- } |
|
178 |
- |
|
179 |
- { |
|
180 |
- snow_interleave_line_header(&i, width, b, temp); |
|
181 |
- |
|
182 |
- for (; (i & 0x3E) != 0x3E; i-=2){ |
|
183 |
- b[i+1] = temp[i>>1]; |
|
184 |
- b[i] = b[i>>1]; |
|
185 |
- } |
|
186 |
- for (i-=62; i>=0; i-=64){ |
|
187 |
- __asm__ volatile( |
|
188 |
- "movdqa (%1), %%xmm0 \n\t" |
|
189 |
- "movdqa 16(%1), %%xmm2 \n\t" |
|
190 |
- "movdqa 32(%1), %%xmm4 \n\t" |
|
191 |
- "movdqa 48(%1), %%xmm6 \n\t" |
|
192 |
- "movdqa (%1), %%xmm1 \n\t" |
|
193 |
- "movdqa 16(%1), %%xmm3 \n\t" |
|
194 |
- "movdqa 32(%1), %%xmm5 \n\t" |
|
195 |
- "movdqa 48(%1), %%xmm7 \n\t" |
|
196 |
- "punpcklwd (%2), %%xmm0 \n\t" |
|
197 |
- "punpcklwd 16(%2), %%xmm2 \n\t" |
|
198 |
- "punpcklwd 32(%2), %%xmm4 \n\t" |
|
199 |
- "punpcklwd 48(%2), %%xmm6 \n\t" |
|
200 |
- "movdqa %%xmm0, (%0) \n\t" |
|
201 |
- "movdqa %%xmm2, 32(%0) \n\t" |
|
202 |
- "movdqa %%xmm4, 64(%0) \n\t" |
|
203 |
- "movdqa %%xmm6, 96(%0) \n\t" |
|
204 |
- "punpckhwd (%2), %%xmm1 \n\t" |
|
205 |
- "punpckhwd 16(%2), %%xmm3 \n\t" |
|
206 |
- "punpckhwd 32(%2), %%xmm5 \n\t" |
|
207 |
- "punpckhwd 48(%2), %%xmm7 \n\t" |
|
208 |
- "movdqa %%xmm1, 16(%0) \n\t" |
|
209 |
- "movdqa %%xmm3, 48(%0) \n\t" |
|
210 |
- "movdqa %%xmm5, 80(%0) \n\t" |
|
211 |
- "movdqa %%xmm7, 112(%0) \n\t" |
|
212 |
- :: "r"(&(b)[i]), "r"(&(b)[i>>1]), "r"(&(temp)[i>>1]) |
|
213 |
- : "memory" |
|
214 |
- ); |
|
215 |
- } |
|
216 |
- } |
|
217 |
-} |
|
218 |
- |
|
219 |
-static void ff_snow_horizontal_compose97i_mmx(IDWTELEM *b, IDWTELEM *temp, int width){ |
|
220 |
- const int w2= (width+1)>>1; |
|
221 |
- const int w_l= (width>>1); |
|
222 |
- const int w_r= w2 - 1; |
|
223 |
- int i; |
|
224 |
- |
|
225 |
- { // Lift 0 |
|
226 |
- IDWTELEM * const ref = b + w2 - 1; |
|
227 |
- |
|
228 |
- i = 1; |
|
229 |
- b[0] = b[0] - ((W_DM * 2 * ref[1]+W_DO)>>W_DS); |
|
230 |
- __asm__ volatile( |
|
231 |
- "pcmpeqw %%mm7, %%mm7 \n\t" |
|
232 |
- "pcmpeqw %%mm3, %%mm3 \n\t" |
|
233 |
- "psllw $1, %%mm3 \n\t" |
|
234 |
- "paddw %%mm7, %%mm3 \n\t" |
|
235 |
- "psllw $13, %%mm3 \n\t" |
|
236 |
- ::); |
|
237 |
- for(; i<w_l-7; i+=8){ |
|
238 |
- __asm__ volatile( |
|
239 |
- "movq (%1), %%mm2 \n\t" |
|
240 |
- "movq 8(%1), %%mm6 \n\t" |
|
241 |
- "paddw 2(%1), %%mm2 \n\t" |
|
242 |
- "paddw 10(%1), %%mm6 \n\t" |
|
243 |
- "paddw %%mm7, %%mm2 \n\t" |
|
244 |
- "paddw %%mm7, %%mm6 \n\t" |
|
245 |
- "pmulhw %%mm3, %%mm2 \n\t" |
|
246 |
- "pmulhw %%mm3, %%mm6 \n\t" |
|
247 |
- "paddw (%0), %%mm2 \n\t" |
|
248 |
- "paddw 8(%0), %%mm6 \n\t" |
|
249 |
- "movq %%mm2, (%0) \n\t" |
|
250 |
- "movq %%mm6, 8(%0) \n\t" |
|
251 |
- :: "r"(&b[i]), "r"(&ref[i]) |
|
252 |
- : "memory" |
|
253 |
- ); |
|
254 |
- } |
|
255 |
- snow_horizontal_compose_lift_lead_out(i, b, b, ref, width, w_l, 0, W_DM, W_DO, W_DS); |
|
256 |
- } |
|
257 |
- |
|
258 |
- { // Lift 1 |
|
259 |
- IDWTELEM * const dst = b+w2; |
|
260 |
- |
|
261 |
- i = 0; |
|
262 |
- for(; i<w_r-7; i+=8){ |
|
263 |
- __asm__ volatile( |
|
264 |
- "movq (%1), %%mm2 \n\t" |
|
265 |
- "movq 8(%1), %%mm6 \n\t" |
|
266 |
- "paddw 2(%1), %%mm2 \n\t" |
|
267 |
- "paddw 10(%1), %%mm6 \n\t" |
|
268 |
- "movq (%0), %%mm0 \n\t" |
|
269 |
- "movq 8(%0), %%mm4 \n\t" |
|
270 |
- "psubw %%mm2, %%mm0 \n\t" |
|
271 |
- "psubw %%mm6, %%mm4 \n\t" |
|
272 |
- "movq %%mm0, (%0) \n\t" |
|
273 |
- "movq %%mm4, 8(%0) \n\t" |
|
274 |
- :: "r"(&dst[i]), "r"(&b[i]) |
|
275 |
- : "memory" |
|
276 |
- ); |
|
277 |
- } |
|
278 |
- snow_horizontal_compose_lift_lead_out(i, dst, dst, b, width, w_r, 1, W_CM, W_CO, W_CS); |
|
279 |
- } |
|
280 |
- |
|
281 |
- { // Lift 2 |
|
282 |
- IDWTELEM * const ref = b+w2 - 1; |
|
283 |
- |
|
284 |
- i = 1; |
|
285 |
- b[0] = b[0] + (((2 * ref[1] + W_BO) + 4 * b[0]) >> W_BS); |
|
286 |
- __asm__ volatile( |
|
287 |
- "psllw $15, %%mm7 \n\t" |
|
288 |
- "pcmpeqw %%mm6, %%mm6 \n\t" |
|
289 |
- "psrlw $13, %%mm6 \n\t" |
|
290 |
- "paddw %%mm7, %%mm6 \n\t" |
|
291 |
- ::); |
|
292 |
- for(; i<w_l-7; i+=8){ |
|
293 |
- __asm__ volatile( |
|
294 |
- "movq (%1), %%mm0 \n\t" |
|
295 |
- "movq 8(%1), %%mm4 \n\t" |
|
296 |
- "movq 2(%1), %%mm1 \n\t" |
|
297 |
- "movq 10(%1), %%mm5 \n\t" |
|
298 |
- "paddw %%mm6, %%mm0 \n\t" |
|
299 |
- "paddw %%mm6, %%mm4 \n\t" |
|
300 |
- "paddw %%mm7, %%mm1 \n\t" |
|
301 |
- "paddw %%mm7, %%mm5 \n\t" |
|
302 |
- "pavgw %%mm1, %%mm0 \n\t" |
|
303 |
- "pavgw %%mm5, %%mm4 \n\t" |
|
304 |
- "psubw %%mm7, %%mm0 \n\t" |
|
305 |
- "psubw %%mm7, %%mm4 \n\t" |
|
306 |
- "psraw $1, %%mm0 \n\t" |
|
307 |
- "psraw $1, %%mm4 \n\t" |
|
308 |
- "movq (%0), %%mm1 \n\t" |
|
309 |
- "movq 8(%0), %%mm5 \n\t" |
|
310 |
- "paddw %%mm1, %%mm0 \n\t" |
|
311 |
- "paddw %%mm5, %%mm4 \n\t" |
|
312 |
- "psraw $2, %%mm0 \n\t" |
|
313 |
- "psraw $2, %%mm4 \n\t" |
|
314 |
- "paddw %%mm1, %%mm0 \n\t" |
|
315 |
- "paddw %%mm5, %%mm4 \n\t" |
|
316 |
- "movq %%mm0, (%0) \n\t" |
|
317 |
- "movq %%mm4, 8(%0) \n\t" |
|
318 |
- :: "r"(&b[i]), "r"(&ref[i]) |
|
319 |
- : "memory" |
|
320 |
- ); |
|
321 |
- } |
|
322 |
- snow_horizontal_compose_liftS_lead_out(i, b, b, ref, width, w_l); |
|
323 |
- } |
|
324 |
- |
|
325 |
- { // Lift 3 |
|
326 |
- IDWTELEM * const src = b+w2; |
|
327 |
- i = 0; |
|
328 |
- |
|
329 |
- for(; i<w_r-7; i+=8){ |
|
330 |
- __asm__ volatile( |
|
331 |
- "movq 2(%1), %%mm2 \n\t" |
|
332 |
- "movq 10(%1), %%mm6 \n\t" |
|
333 |
- "paddw (%1), %%mm2 \n\t" |
|
334 |
- "paddw 8(%1), %%mm6 \n\t" |
|
335 |
- "movq (%0), %%mm0 \n\t" |
|
336 |
- "movq 8(%0), %%mm4 \n\t" |
|
337 |
- "paddw %%mm2, %%mm0 \n\t" |
|
338 |
- "paddw %%mm6, %%mm4 \n\t" |
|
339 |
- "psraw $1, %%mm2 \n\t" |
|
340 |
- "psraw $1, %%mm6 \n\t" |
|
341 |
- "paddw %%mm0, %%mm2 \n\t" |
|
342 |
- "paddw %%mm4, %%mm6 \n\t" |
|
343 |
- "movq %%mm2, (%2) \n\t" |
|
344 |
- "movq %%mm6, 8(%2) \n\t" |
|
345 |
- :: "r"(&src[i]), "r"(&b[i]), "r"(&temp[i]) |
|
346 |
- : "memory" |
|
347 |
- ); |
|
348 |
- } |
|
349 |
- snow_horizontal_compose_lift_lead_out(i, temp, src, b, width, w_r, 1, -W_AM, W_AO+1, W_AS); |
|
350 |
- } |
|
351 |
- |
|
352 |
- { |
|
353 |
- snow_interleave_line_header(&i, width, b, temp); |
|
354 |
- |
|
355 |
- for (; (i & 0x1E) != 0x1E; i-=2){ |
|
356 |
- b[i+1] = temp[i>>1]; |
|
357 |
- b[i] = b[i>>1]; |
|
358 |
- } |
|
359 |
- for (i-=30; i>=0; i-=32){ |
|
360 |
- __asm__ volatile( |
|
361 |
- "movq (%1), %%mm0 \n\t" |
|
362 |
- "movq 8(%1), %%mm2 \n\t" |
|
363 |
- "movq 16(%1), %%mm4 \n\t" |
|
364 |
- "movq 24(%1), %%mm6 \n\t" |
|
365 |
- "movq (%1), %%mm1 \n\t" |
|
366 |
- "movq 8(%1), %%mm3 \n\t" |
|
367 |
- "movq 16(%1), %%mm5 \n\t" |
|
368 |
- "movq 24(%1), %%mm7 \n\t" |
|
369 |
- "punpcklwd (%2), %%mm0 \n\t" |
|
370 |
- "punpcklwd 8(%2), %%mm2 \n\t" |
|
371 |
- "punpcklwd 16(%2), %%mm4 \n\t" |
|
372 |
- "punpcklwd 24(%2), %%mm6 \n\t" |
|
373 |
- "movq %%mm0, (%0) \n\t" |
|
374 |
- "movq %%mm2, 16(%0) \n\t" |
|
375 |
- "movq %%mm4, 32(%0) \n\t" |
|
376 |
- "movq %%mm6, 48(%0) \n\t" |
|
377 |
- "punpckhwd (%2), %%mm1 \n\t" |
|
378 |
- "punpckhwd 8(%2), %%mm3 \n\t" |
|
379 |
- "punpckhwd 16(%2), %%mm5 \n\t" |
|
380 |
- "punpckhwd 24(%2), %%mm7 \n\t" |
|
381 |
- "movq %%mm1, 8(%0) \n\t" |
|
382 |
- "movq %%mm3, 24(%0) \n\t" |
|
383 |
- "movq %%mm5, 40(%0) \n\t" |
|
384 |
- "movq %%mm7, 56(%0) \n\t" |
|
385 |
- :: "r"(&b[i]), "r"(&b[i>>1]), "r"(&temp[i>>1]) |
|
386 |
- : "memory" |
|
387 |
- ); |
|
388 |
- } |
|
389 |
- } |
|
390 |
-} |
|
391 |
- |
|
392 |
-#if HAVE_7REGS |
|
393 |
-#define snow_vertical_compose_sse2_load_add(op,r,t0,t1,t2,t3)\ |
|
394 |
- ""op" ("r",%%"REG_d"), %%"t0" \n\t"\ |
|
395 |
- ""op" 16("r",%%"REG_d"), %%"t1" \n\t"\ |
|
396 |
- ""op" 32("r",%%"REG_d"), %%"t2" \n\t"\ |
|
397 |
- ""op" 48("r",%%"REG_d"), %%"t3" \n\t" |
|
398 |
- |
|
399 |
-#define snow_vertical_compose_sse2_load(r,t0,t1,t2,t3)\ |
|
400 |
- snow_vertical_compose_sse2_load_add("movdqa",r,t0,t1,t2,t3) |
|
401 |
- |
|
402 |
-#define snow_vertical_compose_sse2_add(r,t0,t1,t2,t3)\ |
|
403 |
- snow_vertical_compose_sse2_load_add("paddw",r,t0,t1,t2,t3) |
|
404 |
- |
|
405 |
-#define snow_vertical_compose_r2r_sub(s0,s1,s2,s3,t0,t1,t2,t3)\ |
|
406 |
- "psubw %%"s0", %%"t0" \n\t"\ |
|
407 |
- "psubw %%"s1", %%"t1" \n\t"\ |
|
408 |
- "psubw %%"s2", %%"t2" \n\t"\ |
|
409 |
- "psubw %%"s3", %%"t3" \n\t" |
|
410 |
- |
|
411 |
-#define snow_vertical_compose_sse2_store(w,s0,s1,s2,s3)\ |
|
412 |
- "movdqa %%"s0", ("w",%%"REG_d") \n\t"\ |
|
413 |
- "movdqa %%"s1", 16("w",%%"REG_d") \n\t"\ |
|
414 |
- "movdqa %%"s2", 32("w",%%"REG_d") \n\t"\ |
|
415 |
- "movdqa %%"s3", 48("w",%%"REG_d") \n\t" |
|
416 |
- |
|
417 |
-#define snow_vertical_compose_sra(n,t0,t1,t2,t3)\ |
|
418 |
- "psraw $"n", %%"t0" \n\t"\ |
|
419 |
- "psraw $"n", %%"t1" \n\t"\ |
|
420 |
- "psraw $"n", %%"t2" \n\t"\ |
|
421 |
- "psraw $"n", %%"t3" \n\t" |
|
422 |
- |
|
423 |
-#define snow_vertical_compose_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)\ |
|
424 |
- "paddw %%"s0", %%"t0" \n\t"\ |
|
425 |
- "paddw %%"s1", %%"t1" \n\t"\ |
|
426 |
- "paddw %%"s2", %%"t2" \n\t"\ |
|
427 |
- "paddw %%"s3", %%"t3" \n\t" |
|
428 |
- |
|
429 |
-#define snow_vertical_compose_r2r_pmulhw(s0,s1,s2,s3,t0,t1,t2,t3)\ |
|
430 |
- "pmulhw %%"s0", %%"t0" \n\t"\ |
|
431 |
- "pmulhw %%"s1", %%"t1" \n\t"\ |
|
432 |
- "pmulhw %%"s2", %%"t2" \n\t"\ |
|
433 |
- "pmulhw %%"s3", %%"t3" \n\t" |
|
434 |
- |
|
435 |
-#define snow_vertical_compose_sse2_move(s0,s1,s2,s3,t0,t1,t2,t3)\ |
|
436 |
- "movdqa %%"s0", %%"t0" \n\t"\ |
|
437 |
- "movdqa %%"s1", %%"t1" \n\t"\ |
|
438 |
- "movdqa %%"s2", %%"t2" \n\t"\ |
|
439 |
- "movdqa %%"s3", %%"t3" \n\t" |
|
440 |
- |
|
441 |
-static void ff_snow_vertical_compose97i_sse2(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){ |
|
442 |
- x86_reg i = width; |
|
443 |
- |
|
444 |
- while(i & 0x1F) |
|
445 |
- { |
|
446 |
- i--; |
|
447 |
- b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS; |
|
448 |
- b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS; |
|
449 |
- b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS; |
|
450 |
- b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS; |
|
451 |
- } |
|
452 |
- i+=i; |
|
453 |
- |
|
454 |
- __asm__ volatile ( |
|
455 |
- "jmp 2f \n\t" |
|
456 |
- "1: \n\t" |
|
457 |
- snow_vertical_compose_sse2_load("%4","xmm0","xmm2","xmm4","xmm6") |
|
458 |
- snow_vertical_compose_sse2_add("%6","xmm0","xmm2","xmm4","xmm6") |
|
459 |
- |
|
460 |
- |
|
461 |
- "pcmpeqw %%xmm0, %%xmm0 \n\t" |
|
462 |
- "pcmpeqw %%xmm2, %%xmm2 \n\t" |
|
463 |
- "paddw %%xmm2, %%xmm2 \n\t" |
|
464 |
- "paddw %%xmm0, %%xmm2 \n\t" |
|
465 |
- "psllw $13, %%xmm2 \n\t" |
|
466 |
- snow_vertical_compose_r2r_add("xmm0","xmm0","xmm0","xmm0","xmm1","xmm3","xmm5","xmm7") |
|
467 |
- snow_vertical_compose_r2r_pmulhw("xmm2","xmm2","xmm2","xmm2","xmm1","xmm3","xmm5","xmm7") |
|
468 |
- snow_vertical_compose_sse2_add("%5","xmm1","xmm3","xmm5","xmm7") |
|
469 |
- snow_vertical_compose_sse2_store("%5","xmm1","xmm3","xmm5","xmm7") |
|
470 |
- snow_vertical_compose_sse2_load("%4","xmm0","xmm2","xmm4","xmm6") |
|
471 |
- snow_vertical_compose_sse2_add("%3","xmm1","xmm3","xmm5","xmm7") |
|
472 |
- snow_vertical_compose_r2r_sub("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6") |
|
473 |
- snow_vertical_compose_sse2_store("%4","xmm0","xmm2","xmm4","xmm6") |
|
474 |
- |
|
475 |
- "pcmpeqw %%xmm7, %%xmm7 \n\t" |
|
476 |
- "pcmpeqw %%xmm5, %%xmm5 \n\t" |
|
477 |
- "psllw $15, %%xmm7 \n\t" |
|
478 |
- "psrlw $13, %%xmm5 \n\t" |
|
479 |
- "paddw %%xmm7, %%xmm5 \n\t" |
|
480 |
- snow_vertical_compose_r2r_add("xmm5","xmm5","xmm5","xmm5","xmm0","xmm2","xmm4","xmm6") |
|
481 |
- "movq (%2,%%"REG_d"), %%xmm1 \n\t" |
|
482 |
- "movq 8(%2,%%"REG_d"), %%xmm3 \n\t" |
|
483 |
- "paddw %%xmm7, %%xmm1 \n\t" |
|
484 |
- "paddw %%xmm7, %%xmm3 \n\t" |
|
485 |
- "pavgw %%xmm1, %%xmm0 \n\t" |
|
486 |
- "pavgw %%xmm3, %%xmm2 \n\t" |
|
487 |
- "movq 16(%2,%%"REG_d"), %%xmm1 \n\t" |
|
488 |
- "movq 24(%2,%%"REG_d"), %%xmm3 \n\t" |
|
489 |
- "paddw %%xmm7, %%xmm1 \n\t" |
|
490 |
- "paddw %%xmm7, %%xmm3 \n\t" |
|
491 |
- "pavgw %%xmm1, %%xmm4 \n\t" |
|
492 |
- "pavgw %%xmm3, %%xmm6 \n\t" |
|
493 |
- snow_vertical_compose_r2r_sub("xmm7","xmm7","xmm7","xmm7","xmm0","xmm2","xmm4","xmm6") |
|
494 |
- snow_vertical_compose_sra("1","xmm0","xmm2","xmm4","xmm6") |
|
495 |
- snow_vertical_compose_sse2_add("%3","xmm0","xmm2","xmm4","xmm6") |
|
496 |
- |
|
497 |
- snow_vertical_compose_sra("2","xmm0","xmm2","xmm4","xmm6") |
|
498 |
- snow_vertical_compose_sse2_add("%3","xmm0","xmm2","xmm4","xmm6") |
|
499 |
- snow_vertical_compose_sse2_store("%3","xmm0","xmm2","xmm4","xmm6") |
|
500 |
- snow_vertical_compose_sse2_add("%1","xmm0","xmm2","xmm4","xmm6") |
|
501 |
- snow_vertical_compose_sse2_move("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7") |
|
502 |
- snow_vertical_compose_sra("1","xmm0","xmm2","xmm4","xmm6") |
|
503 |
- snow_vertical_compose_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6") |
|
504 |
- snow_vertical_compose_sse2_add("%2","xmm0","xmm2","xmm4","xmm6") |
|
505 |
- snow_vertical_compose_sse2_store("%2","xmm0","xmm2","xmm4","xmm6") |
|
506 |
- |
|
507 |
- "2: \n\t" |
|
508 |
- "sub $64, %%"REG_d" \n\t" |
|
509 |
- "jge 1b \n\t" |
|
510 |
- :"+d"(i) |
|
511 |
- :"r"(b0),"r"(b1),"r"(b2),"r"(b3),"r"(b4),"r"(b5)); |
|
512 |
-} |
|
513 |
- |
|
514 |
-#define snow_vertical_compose_mmx_load_add(op,r,t0,t1,t2,t3)\ |
|
515 |
- ""op" ("r",%%"REG_d"), %%"t0" \n\t"\ |
|
516 |
- ""op" 8("r",%%"REG_d"), %%"t1" \n\t"\ |
|
517 |
- ""op" 16("r",%%"REG_d"), %%"t2" \n\t"\ |
|
518 |
- ""op" 24("r",%%"REG_d"), %%"t3" \n\t" |
|
519 |
- |
|
520 |
-#define snow_vertical_compose_mmx_load(r,t0,t1,t2,t3)\ |
|
521 |
- snow_vertical_compose_mmx_load_add("movq",r,t0,t1,t2,t3) |
|
522 |
- |
|
523 |
-#define snow_vertical_compose_mmx_add(r,t0,t1,t2,t3)\ |
|
524 |
- snow_vertical_compose_mmx_load_add("paddw",r,t0,t1,t2,t3) |
|
525 |
- |
|
526 |
-#define snow_vertical_compose_mmx_store(w,s0,s1,s2,s3)\ |
|
527 |
- "movq %%"s0", ("w",%%"REG_d") \n\t"\ |
|
528 |
- "movq %%"s1", 8("w",%%"REG_d") \n\t"\ |
|
529 |
- "movq %%"s2", 16("w",%%"REG_d") \n\t"\ |
|
530 |
- "movq %%"s3", 24("w",%%"REG_d") \n\t" |
|
531 |
- |
|
532 |
-#define snow_vertical_compose_mmx_move(s0,s1,s2,s3,t0,t1,t2,t3)\ |
|
533 |
- "movq %%"s0", %%"t0" \n\t"\ |
|
534 |
- "movq %%"s1", %%"t1" \n\t"\ |
|
535 |
- "movq %%"s2", %%"t2" \n\t"\ |
|
536 |
- "movq %%"s3", %%"t3" \n\t" |
|
537 |
- |
|
538 |
- |
|
539 |
-static void ff_snow_vertical_compose97i_mmx(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){ |
|
540 |
- x86_reg i = width; |
|
541 |
- while(i & 15) |
|
542 |
- { |
|
543 |
- i--; |
|
544 |
- b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS; |
|
545 |
- b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS; |
|
546 |
- b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS; |
|
547 |
- b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS; |
|
548 |
- } |
|
549 |
- i+=i; |
|
550 |
- __asm__ volatile( |
|
551 |
- "jmp 2f \n\t" |
|
552 |
- "1: \n\t" |
|
553 |
- |
|
554 |
- snow_vertical_compose_mmx_load("%4","mm1","mm3","mm5","mm7") |
|
555 |
- snow_vertical_compose_mmx_add("%6","mm1","mm3","mm5","mm7") |
|
556 |
- "pcmpeqw %%mm0, %%mm0 \n\t" |
|
557 |
- "pcmpeqw %%mm2, %%mm2 \n\t" |
|
558 |
- "paddw %%mm2, %%mm2 \n\t" |
|
559 |
- "paddw %%mm0, %%mm2 \n\t" |
|
560 |
- "psllw $13, %%mm2 \n\t" |
|
561 |
- snow_vertical_compose_r2r_add("mm0","mm0","mm0","mm0","mm1","mm3","mm5","mm7") |
|
562 |
- snow_vertical_compose_r2r_pmulhw("mm2","mm2","mm2","mm2","mm1","mm3","mm5","mm7") |
|
563 |
- snow_vertical_compose_mmx_add("%5","mm1","mm3","mm5","mm7") |
|
564 |
- snow_vertical_compose_mmx_store("%5","mm1","mm3","mm5","mm7") |
|
565 |
- snow_vertical_compose_mmx_load("%4","mm0","mm2","mm4","mm6") |
|
566 |
- snow_vertical_compose_mmx_add("%3","mm1","mm3","mm5","mm7") |
|
567 |
- snow_vertical_compose_r2r_sub("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6") |
|
568 |
- snow_vertical_compose_mmx_store("%4","mm0","mm2","mm4","mm6") |
|
569 |
- "pcmpeqw %%mm7, %%mm7 \n\t" |
|
570 |
- "pcmpeqw %%mm5, %%mm5 \n\t" |
|
571 |
- "psllw $15, %%mm7 \n\t" |
|
572 |
- "psrlw $13, %%mm5 \n\t" |
|
573 |
- "paddw %%mm7, %%mm5 \n\t" |
|
574 |
- snow_vertical_compose_r2r_add("mm5","mm5","mm5","mm5","mm0","mm2","mm4","mm6") |
|
575 |
- "movq (%2,%%"REG_d"), %%mm1 \n\t" |
|
576 |
- "movq 8(%2,%%"REG_d"), %%mm3 \n\t" |
|
577 |
- "paddw %%mm7, %%mm1 \n\t" |
|
578 |
- "paddw %%mm7, %%mm3 \n\t" |
|
579 |
- "pavgw %%mm1, %%mm0 \n\t" |
|
580 |
- "pavgw %%mm3, %%mm2 \n\t" |
|
581 |
- "movq 16(%2,%%"REG_d"), %%mm1 \n\t" |
|
582 |
- "movq 24(%2,%%"REG_d"), %%mm3 \n\t" |
|
583 |
- "paddw %%mm7, %%mm1 \n\t" |
|
584 |
- "paddw %%mm7, %%mm3 \n\t" |
|
585 |
- "pavgw %%mm1, %%mm4 \n\t" |
|
586 |
- "pavgw %%mm3, %%mm6 \n\t" |
|
587 |
- snow_vertical_compose_r2r_sub("mm7","mm7","mm7","mm7","mm0","mm2","mm4","mm6") |
|
588 |
- snow_vertical_compose_sra("1","mm0","mm2","mm4","mm6") |
|
589 |
- snow_vertical_compose_mmx_add("%3","mm0","mm2","mm4","mm6") |
|
590 |
- |
|
591 |
- snow_vertical_compose_sra("2","mm0","mm2","mm4","mm6") |
|
592 |
- snow_vertical_compose_mmx_add("%3","mm0","mm2","mm4","mm6") |
|
593 |
- snow_vertical_compose_mmx_store("%3","mm0","mm2","mm4","mm6") |
|
594 |
- snow_vertical_compose_mmx_add("%1","mm0","mm2","mm4","mm6") |
|
595 |
- snow_vertical_compose_mmx_move("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7") |
|
596 |
- snow_vertical_compose_sra("1","mm0","mm2","mm4","mm6") |
|
597 |
- snow_vertical_compose_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6") |
|
598 |
- snow_vertical_compose_mmx_add("%2","mm0","mm2","mm4","mm6") |
|
599 |
- snow_vertical_compose_mmx_store("%2","mm0","mm2","mm4","mm6") |
|
600 |
- |
|
601 |
- "2: \n\t" |
|
602 |
- "sub $32, %%"REG_d" \n\t" |
|
603 |
- "jge 1b \n\t" |
|
604 |
- :"+d"(i) |
|
605 |
- :"r"(b0),"r"(b1),"r"(b2),"r"(b3),"r"(b4),"r"(b5)); |
|
606 |
-} |
|
607 |
-#endif //HAVE_7REGS |
|
608 |
- |
|
609 |
-#define snow_inner_add_yblock_sse2_header \ |
|
610 |
- IDWTELEM * * dst_array = sb->line + src_y;\ |
|
611 |
- x86_reg tmp;\ |
|
612 |
- __asm__ volatile(\ |
|
613 |
- "mov %7, %%"REG_c" \n\t"\ |
|
614 |
- "mov %6, %2 \n\t"\ |
|
615 |
- "mov %4, %%"REG_S" \n\t"\ |
|
616 |
- "pxor %%xmm7, %%xmm7 \n\t" /* 0 */\ |
|
617 |
- "pcmpeqd %%xmm3, %%xmm3 \n\t"\ |
|
618 |
- "psllw $15, %%xmm3 \n\t"\ |
|
619 |
- "psrlw $12, %%xmm3 \n\t" /* FRAC_BITS >> 1 */\ |
|
620 |
- "1: \n\t"\ |
|
621 |
- "mov %1, %%"REG_D" \n\t"\ |
|
622 |
- "mov (%%"REG_D"), %%"REG_D" \n\t"\ |
|
623 |
- "add %3, %%"REG_D" \n\t" |
|
624 |
- |
|
625 |
-#define snow_inner_add_yblock_sse2_start_8(out_reg1, out_reg2, ptr_offset, s_offset)\ |
|
626 |
- "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\ |
|
627 |
- "movq (%%"REG_d"), %%"out_reg1" \n\t"\ |
|
628 |
- "movq (%%"REG_d", %%"REG_c"), %%"out_reg2" \n\t"\ |
|
629 |
- "punpcklbw %%xmm7, %%"out_reg1" \n\t"\ |
|
630 |
- "punpcklbw %%xmm7, %%"out_reg2" \n\t"\ |
|
631 |
- "movq "s_offset"(%%"REG_S"), %%xmm0 \n\t"\ |
|
632 |
- "movq "s_offset"+16(%%"REG_S"), %%xmm4 \n\t"\ |
|
633 |
- "punpcklbw %%xmm7, %%xmm0 \n\t"\ |
|
634 |
- "punpcklbw %%xmm7, %%xmm4 \n\t"\ |
|
635 |
- "pmullw %%xmm0, %%"out_reg1" \n\t"\ |
|
636 |
- "pmullw %%xmm4, %%"out_reg2" \n\t" |
|
637 |
- |
|
638 |
-#define snow_inner_add_yblock_sse2_start_16(out_reg1, out_reg2, ptr_offset, s_offset)\ |
|
639 |
- "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\ |
|
640 |
- "movq (%%"REG_d"), %%"out_reg1" \n\t"\ |
|
641 |
- "movq 8(%%"REG_d"), %%"out_reg2" \n\t"\ |
|
642 |
- "punpcklbw %%xmm7, %%"out_reg1" \n\t"\ |
|
643 |
- "punpcklbw %%xmm7, %%"out_reg2" \n\t"\ |
|
644 |
- "movq "s_offset"(%%"REG_S"), %%xmm0 \n\t"\ |
|
645 |
- "movq "s_offset"+8(%%"REG_S"), %%xmm4 \n\t"\ |
|
646 |
- "punpcklbw %%xmm7, %%xmm0 \n\t"\ |
|
647 |
- "punpcklbw %%xmm7, %%xmm4 \n\t"\ |
|
648 |
- "pmullw %%xmm0, %%"out_reg1" \n\t"\ |
|
649 |
- "pmullw %%xmm4, %%"out_reg2" \n\t" |
|
650 |
- |
|
651 |
-#define snow_inner_add_yblock_sse2_accum_8(ptr_offset, s_offset) \ |
|
652 |
- snow_inner_add_yblock_sse2_start_8("xmm2", "xmm6", ptr_offset, s_offset)\ |
|
653 |
- "paddusw %%xmm2, %%xmm1 \n\t"\ |
|
654 |
- "paddusw %%xmm6, %%xmm5 \n\t" |
|
655 |
- |
|
656 |
-#define snow_inner_add_yblock_sse2_accum_16(ptr_offset, s_offset) \ |
|
657 |
- snow_inner_add_yblock_sse2_start_16("xmm2", "xmm6", ptr_offset, s_offset)\ |
|
658 |
- "paddusw %%xmm2, %%xmm1 \n\t"\ |
|
659 |
- "paddusw %%xmm6, %%xmm5 \n\t" |
|
660 |
- |
|
661 |
-#define snow_inner_add_yblock_sse2_end_common1\ |
|
662 |
- "add $32, %%"REG_S" \n\t"\ |
|
663 |
- "add %%"REG_c", %0 \n\t"\ |
|
664 |
- "add %%"REG_c", "PTR_SIZE"*3(%%"REG_a");\n\t"\ |
|
665 |
- "add %%"REG_c", "PTR_SIZE"*2(%%"REG_a");\n\t"\ |
|
666 |
- "add %%"REG_c", "PTR_SIZE"*1(%%"REG_a");\n\t"\ |
|
667 |
- "add %%"REG_c", (%%"REG_a") \n\t" |
|
668 |
- |
|
669 |
-#define snow_inner_add_yblock_sse2_end_common2\ |
|
670 |
- "jnz 1b \n\t"\ |
|
671 |
- :"+m"(dst8),"+m"(dst_array),"=&r"(tmp)\ |
|
672 |
- :\ |
|
673 |
- "rm"((x86_reg)(src_x<<1)),"m"(obmc),"a"(block),"m"(b_h),"m"(src_stride):\ |
|
674 |
- "%"REG_c"","%"REG_S"","%"REG_D"","%"REG_d""); |
|
675 |
- |
|
676 |
-#define snow_inner_add_yblock_sse2_end_8\ |
|
677 |
- "sal $1, %%"REG_c" \n\t"\ |
|
678 |
- "addl $"PTR_SIZE"*2, %1 \n\t"\ |
|
679 |
- snow_inner_add_yblock_sse2_end_common1\ |
|
680 |
- "sar $1, %%"REG_c" \n\t"\ |
|
681 |
- "sub $2, %2 \n\t"\ |
|
682 |
- snow_inner_add_yblock_sse2_end_common2 |
|
683 |
- |
|
684 |
-#define snow_inner_add_yblock_sse2_end_16\ |
|
685 |
- "addl $"PTR_SIZE"*1, %1 \n\t"\ |
|
686 |
- snow_inner_add_yblock_sse2_end_common1\ |
|
687 |
- "dec %2 \n\t"\ |
|
688 |
- snow_inner_add_yblock_sse2_end_common2 |
|
689 |
- |
|
690 |
-static void inner_add_yblock_bw_8_obmc_16_bh_even_sse2(const uint8_t *obmc, const x86_reg obmc_stride, uint8_t * * block, int b_w, x86_reg b_h, |
|
691 |
- int src_x, int src_y, x86_reg src_stride, slice_buffer * sb, int add, uint8_t * dst8){ |
|
692 |
-snow_inner_add_yblock_sse2_header |
|
693 |
-snow_inner_add_yblock_sse2_start_8("xmm1", "xmm5", "3", "0") |
|
694 |
-snow_inner_add_yblock_sse2_accum_8("2", "8") |
|
695 |
-snow_inner_add_yblock_sse2_accum_8("1", "128") |
|
696 |
-snow_inner_add_yblock_sse2_accum_8("0", "136") |
|
697 |
- |
|
698 |
- "mov %0, %%"REG_d" \n\t" |
|
699 |
- "movdqa (%%"REG_D"), %%xmm0 \n\t" |
|
700 |
- "movdqa %%xmm1, %%xmm2 \n\t" |
|
701 |
- |
|
702 |
- "punpckhwd %%xmm7, %%xmm1 \n\t" |
|
703 |
- "punpcklwd %%xmm7, %%xmm2 \n\t" |
|
704 |
- "paddd %%xmm2, %%xmm0 \n\t" |
|
705 |
- "movdqa 16(%%"REG_D"), %%xmm2 \n\t" |
|
706 |
- "paddd %%xmm1, %%xmm2 \n\t" |
|
707 |
- "paddd %%xmm3, %%xmm0 \n\t" |
|
708 |
- "paddd %%xmm3, %%xmm2 \n\t" |
|
709 |
- |
|
710 |
- "mov %1, %%"REG_D" \n\t" |
|
711 |
- "mov "PTR_SIZE"(%%"REG_D"), %%"REG_D";\n\t" |
|
712 |
- "add %3, %%"REG_D" \n\t" |
|
713 |
- |
|
714 |
- "movdqa (%%"REG_D"), %%xmm4 \n\t" |
|
715 |
- "movdqa %%xmm5, %%xmm6 \n\t" |
|
716 |
- "punpckhwd %%xmm7, %%xmm5 \n\t" |
|
717 |
- "punpcklwd %%xmm7, %%xmm6 \n\t" |
|
718 |
- "paddd %%xmm6, %%xmm4 \n\t" |
|
719 |
- "movdqa 16(%%"REG_D"), %%xmm6 \n\t" |
|
720 |
- "paddd %%xmm5, %%xmm6 \n\t" |
|
721 |
- "paddd %%xmm3, %%xmm4 \n\t" |
|
722 |
- "paddd %%xmm3, %%xmm6 \n\t" |
|
723 |
- |
|
724 |
- "psrad $8, %%xmm0 \n\t" /* FRAC_BITS. */ |
|
725 |
- "psrad $8, %%xmm2 \n\t" /* FRAC_BITS. */ |
|
726 |
- "packssdw %%xmm2, %%xmm0 \n\t" |
|
727 |
- "packuswb %%xmm7, %%xmm0 \n\t" |
|
728 |
- "movq %%xmm0, (%%"REG_d") \n\t" |
|
729 |
- |
|
730 |
- "psrad $8, %%xmm4 \n\t" /* FRAC_BITS. */ |
|
731 |
- "psrad $8, %%xmm6 \n\t" /* FRAC_BITS. */ |
|
732 |
- "packssdw %%xmm6, %%xmm4 \n\t" |
|
733 |
- "packuswb %%xmm7, %%xmm4 \n\t" |
|
734 |
- "movq %%xmm4, (%%"REG_d",%%"REG_c");\n\t" |
|
735 |
-snow_inner_add_yblock_sse2_end_8 |
|
736 |
-} |
|
737 |
- |
|
738 |
-static void inner_add_yblock_bw_16_obmc_32_sse2(const uint8_t *obmc, const x86_reg obmc_stride, uint8_t * * block, int b_w, x86_reg b_h, |
|
739 |
- int src_x, int src_y, x86_reg src_stride, slice_buffer * sb, int add, uint8_t * dst8){ |
|
740 |
-snow_inner_add_yblock_sse2_header |
|
741 |
-snow_inner_add_yblock_sse2_start_16("xmm1", "xmm5", "3", "0") |
|
742 |
-snow_inner_add_yblock_sse2_accum_16("2", "16") |
|
743 |
-snow_inner_add_yblock_sse2_accum_16("1", "512") |
|
744 |
-snow_inner_add_yblock_sse2_accum_16("0", "528") |
|
745 |
- |
|
746 |
- "mov %0, %%"REG_d" \n\t" |
|
747 |
- "psrlw $4, %%xmm1 \n\t" |
|
748 |
- "psrlw $4, %%xmm5 \n\t" |
|
749 |
- "paddw (%%"REG_D"), %%xmm1 \n\t" |
|
750 |
- "paddw 16(%%"REG_D"), %%xmm5 \n\t" |
|
751 |
- "paddw %%xmm3, %%xmm1 \n\t" |
|
752 |
- "paddw %%xmm3, %%xmm5 \n\t" |
|
753 |
- "psraw $4, %%xmm1 \n\t" /* FRAC_BITS. */ |
|
754 |
- "psraw $4, %%xmm5 \n\t" /* FRAC_BITS. */ |
|
755 |
- "packuswb %%xmm5, %%xmm1 \n\t" |
|
756 |
- |
|
757 |
- "movdqu %%xmm1, (%%"REG_d") \n\t" |
|
758 |
- |
|
759 |
-snow_inner_add_yblock_sse2_end_16 |
|
760 |
-} |
|
761 |
- |
|
762 |
-#define snow_inner_add_yblock_mmx_header \ |
|
763 |
- IDWTELEM * * dst_array = sb->line + src_y;\ |
|
764 |
- x86_reg tmp;\ |
|
765 |
- __asm__ volatile(\ |
|
766 |
- "mov %7, %%"REG_c" \n\t"\ |
|
767 |
- "mov %6, %2 \n\t"\ |
|
768 |
- "mov %4, %%"REG_S" \n\t"\ |
|
769 |
- "pxor %%mm7, %%mm7 \n\t" /* 0 */\ |
|
770 |
- "pcmpeqd %%mm3, %%mm3 \n\t"\ |
|
771 |
- "psllw $15, %%mm3 \n\t"\ |
|
772 |
- "psrlw $12, %%mm3 \n\t" /* FRAC_BITS >> 1 */\ |
|
773 |
- "1: \n\t"\ |
|
774 |
- "mov %1, %%"REG_D" \n\t"\ |
|
775 |
- "mov (%%"REG_D"), %%"REG_D" \n\t"\ |
|
776 |
- "add %3, %%"REG_D" \n\t" |
|
777 |
- |
|
778 |
-#define snow_inner_add_yblock_mmx_start(out_reg1, out_reg2, ptr_offset, s_offset, d_offset)\ |
|
779 |
- "mov "PTR_SIZE"*"ptr_offset"(%%"REG_a"), %%"REG_d"; \n\t"\ |
|
780 |
- "movd "d_offset"(%%"REG_d"), %%"out_reg1" \n\t"\ |
|
781 |
- "movd "d_offset"+4(%%"REG_d"), %%"out_reg2" \n\t"\ |
|
782 |
- "punpcklbw %%mm7, %%"out_reg1" \n\t"\ |
|
783 |
- "punpcklbw %%mm7, %%"out_reg2" \n\t"\ |
|
784 |
- "movd "s_offset"(%%"REG_S"), %%mm0 \n\t"\ |
|
785 |
- "movd "s_offset"+4(%%"REG_S"), %%mm4 \n\t"\ |
|
786 |
- "punpcklbw %%mm7, %%mm0 \n\t"\ |
|
787 |
- "punpcklbw %%mm7, %%mm4 \n\t"\ |
|
788 |
- "pmullw %%mm0, %%"out_reg1" \n\t"\ |
|
789 |
- "pmullw %%mm4, %%"out_reg2" \n\t" |
|
790 |
- |
|
791 |
-#define snow_inner_add_yblock_mmx_accum(ptr_offset, s_offset, d_offset) \ |
|
792 |
- snow_inner_add_yblock_mmx_start("mm2", "mm6", ptr_offset, s_offset, d_offset)\ |
|
793 |
- "paddusw %%mm2, %%mm1 \n\t"\ |
|
794 |
- "paddusw %%mm6, %%mm5 \n\t" |
|
795 |
- |
|
796 |
-#define snow_inner_add_yblock_mmx_mix(read_offset, write_offset)\ |
|
797 |
- "mov %0, %%"REG_d" \n\t"\ |
|
798 |
- "psrlw $4, %%mm1 \n\t"\ |
|
799 |
- "psrlw $4, %%mm5 \n\t"\ |
|
800 |
- "paddw "read_offset"(%%"REG_D"), %%mm1 \n\t"\ |
|
801 |
- "paddw "read_offset"+8(%%"REG_D"), %%mm5 \n\t"\ |
|
802 |
- "paddw %%mm3, %%mm1 \n\t"\ |
|
803 |
- "paddw %%mm3, %%mm5 \n\t"\ |
|
804 |
- "psraw $4, %%mm1 \n\t"\ |
|
805 |
- "psraw $4, %%mm5 \n\t"\ |
|
806 |
- "packuswb %%mm5, %%mm1 \n\t"\ |
|
807 |
- "movq %%mm1, "write_offset"(%%"REG_d") \n\t" |
|
808 |
- |
|
809 |
-#define snow_inner_add_yblock_mmx_end(s_step)\ |
|
810 |
- "add $"s_step", %%"REG_S" \n\t"\ |
|
811 |
- "add %%"REG_c", "PTR_SIZE"*3(%%"REG_a");\n\t"\ |
|
812 |
- "add %%"REG_c", "PTR_SIZE"*2(%%"REG_a");\n\t"\ |
|
813 |
- "add %%"REG_c", "PTR_SIZE"*1(%%"REG_a");\n\t"\ |
|
814 |
- "add %%"REG_c", (%%"REG_a") \n\t"\ |
|
815 |
- "add"OPSIZE " $"PTR_SIZE"*1, %1 \n\t"\ |
|
816 |
- "add %%"REG_c", %0 \n\t"\ |
|
817 |
- "dec %2 \n\t"\ |
|
818 |
- "jnz 1b \n\t"\ |
|
819 |
- :"+m"(dst8),"+m"(dst_array),"=&r"(tmp)\ |
|
820 |
- :\ |
|
821 |
- "rm"((x86_reg)(src_x<<1)),"m"(obmc),"a"(block),"m"(b_h),"m"(src_stride):\ |
|
822 |
- "%"REG_c"","%"REG_S"","%"REG_D"","%"REG_d""); |
|
823 |
- |
|
824 |
-static void inner_add_yblock_bw_8_obmc_16_mmx(const uint8_t *obmc, const x86_reg obmc_stride, uint8_t * * block, int b_w, x86_reg b_h, |
|
825 |
- int src_x, int src_y, x86_reg src_stride, slice_buffer * sb, int add, uint8_t * dst8){ |
|
826 |
-snow_inner_add_yblock_mmx_header |
|
827 |
-snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "0", "0") |
|
828 |
-snow_inner_add_yblock_mmx_accum("2", "8", "0") |
|
829 |
-snow_inner_add_yblock_mmx_accum("1", "128", "0") |
|
830 |
-snow_inner_add_yblock_mmx_accum("0", "136", "0") |
|
831 |
-snow_inner_add_yblock_mmx_mix("0", "0") |
|
832 |
-snow_inner_add_yblock_mmx_end("16") |
|
833 |
-} |
|
834 |
- |
|
835 |
-static void inner_add_yblock_bw_16_obmc_32_mmx(const uint8_t *obmc, const x86_reg obmc_stride, uint8_t * * block, int b_w, x86_reg b_h, |
|
836 |
- int src_x, int src_y, x86_reg src_stride, slice_buffer * sb, int add, uint8_t * dst8){ |
|
837 |
-snow_inner_add_yblock_mmx_header |
|
838 |
-snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "0", "0") |
|
839 |
-snow_inner_add_yblock_mmx_accum("2", "16", "0") |
|
840 |
-snow_inner_add_yblock_mmx_accum("1", "512", "0") |
|
841 |
-snow_inner_add_yblock_mmx_accum("0", "528", "0") |
|
842 |
-snow_inner_add_yblock_mmx_mix("0", "0") |
|
843 |
- |
|
844 |
-snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "8", "8") |
|
845 |
-snow_inner_add_yblock_mmx_accum("2", "24", "8") |
|
846 |
-snow_inner_add_yblock_mmx_accum("1", "520", "8") |
|
847 |
-snow_inner_add_yblock_mmx_accum("0", "536", "8") |
|
848 |
-snow_inner_add_yblock_mmx_mix("16", "8") |
|
849 |
-snow_inner_add_yblock_mmx_end("32") |
|
850 |
-} |
|
851 |
- |
|
852 |
-static void ff_snow_inner_add_yblock_sse2(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, |
|
853 |
- int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){ |
|
854 |
- |
|
855 |
- if (b_w == 16) |
|
856 |
- inner_add_yblock_bw_16_obmc_32_sse2(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); |
|
857 |
- else if (b_w == 8 && obmc_stride == 16) { |
|
858 |
- if (!(b_h & 1)) |
|
859 |
- inner_add_yblock_bw_8_obmc_16_bh_even_sse2(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); |
|
860 |
- else |
|
861 |
- inner_add_yblock_bw_8_obmc_16_mmx(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); |
|
862 |
- } else |
|
863 |
- ff_snow_inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); |
|
864 |
-} |
|
865 |
- |
|
866 |
-static void ff_snow_inner_add_yblock_mmx(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, |
|
867 |
- int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){ |
|
868 |
- if (b_w == 16) |
|
869 |
- inner_add_yblock_bw_16_obmc_32_mmx(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); |
|
870 |
- else if (b_w == 8 && obmc_stride == 16) |
|
871 |
- inner_add_yblock_bw_8_obmc_16_mmx(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); |
|
872 |
- else |
|
873 |
- ff_snow_inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); |
|
874 |
-} |
|
875 |
- |
|
876 |
-#endif /* HAVE_INLINE_ASM */ |
|
877 |
- |
|
878 |
-void ff_dwt_init_x86(DWTContext *c) |
|
879 |
-{ |
|
880 |
-#if HAVE_INLINE_ASM |
|
881 |
- int mm_flags = av_get_cpu_flags(); |
|
882 |
- |
|
883 |
- if (mm_flags & AV_CPU_FLAG_MMX) { |
|
884 |
- if(mm_flags & AV_CPU_FLAG_SSE2 & 0){ |
|
885 |
- c->horizontal_compose97i = ff_snow_horizontal_compose97i_sse2; |
|
886 |
-#if HAVE_7REGS |
|
887 |
- c->vertical_compose97i = ff_snow_vertical_compose97i_sse2; |
|
888 |
-#endif |
|
889 |
- c->inner_add_yblock = ff_snow_inner_add_yblock_sse2; |
|
890 |
- } |
|
891 |
- else{ |
|
892 |
- if (mm_flags & AV_CPU_FLAG_MMXEXT) { |
|
893 |
- c->horizontal_compose97i = ff_snow_horizontal_compose97i_mmx; |
|
894 |
-#if HAVE_7REGS |
|
895 |
- c->vertical_compose97i = ff_snow_vertical_compose97i_mmx; |
|
896 |
-#endif |
|
897 |
- } |
|
898 |
- c->inner_add_yblock = ff_snow_inner_add_yblock_mmx; |
|
899 |
- } |
|
900 |
- } |
|
901 |
-#endif /* HAVE_INLINE_ASM */ |
|
902 |
-} |
... | ... |
@@ -76,7 +76,6 @@ const CodecTags ff_mkv_codec_tags[]={ |
76 | 76 |
{"V_REAL/RV20" , AV_CODEC_ID_RV20}, |
77 | 77 |
{"V_REAL/RV30" , AV_CODEC_ID_RV30}, |
78 | 78 |
{"V_REAL/RV40" , AV_CODEC_ID_RV40}, |
79 |
- {"V_SNOW" , AV_CODEC_ID_SNOW}, |
|
80 | 79 |
{"V_THEORA" , AV_CODEC_ID_THEORA}, |
81 | 80 |
{"V_UNCOMPRESSED" , AV_CODEC_ID_RAWVIDEO}, |
82 | 81 |
{"V_VP8" , AV_CODEC_ID_VP8}, |
... | ... |
@@ -231,7 +231,6 @@ const AVCodecTag ff_codec_bmp_tags[] = { |
231 | 231 |
{ AV_CODEC_ID_TRUEMOTION1, MKTAG('P', 'V', 'E', 'Z') }, |
232 | 232 |
{ AV_CODEC_ID_MSZH, MKTAG('M', 'S', 'Z', 'H') }, |
233 | 233 |
{ AV_CODEC_ID_ZLIB, MKTAG('Z', 'L', 'I', 'B') }, |
234 |
- { AV_CODEC_ID_SNOW, MKTAG('S', 'N', 'O', 'W') }, |
|
235 | 234 |
{ AV_CODEC_ID_4XM, MKTAG('4', 'X', 'M', 'V') }, |
236 | 235 |
{ AV_CODEC_ID_FLV1, MKTAG('F', 'L', 'V', '1') }, |
237 | 236 |
{ AV_CODEC_ID_FLASHSV, MKTAG('F', 'S', 'V', '1') }, |
... | ... |
@@ -89,8 +89,6 @@ FATE_SEEK_VSYNTH2-$(call ENCDEC, RAWVIDEO, AVI) += rgb |
89 | 89 |
FATE_SEEK_VSYNTH2-$(call ENCDEC, ROQ, ROQ) += roqvideo |
90 | 90 |
FATE_SEEK_VSYNTH2-$(call ENCDEC, RV10, RM) += rv10 |
91 | 91 |
FATE_SEEK_VSYNTH2-$(call ENCDEC, RV20, RM) += rv20 |
92 |
-FATE_SEEK_VSYNTH2-$(call ENCDEC, SNOW, AVI) += snow |
|
93 |
-FATE_SEEK_VSYNTH2-$(call ENCDEC, SNOW, AVI) += snow-ll |
|
94 | 92 |
FATE_SEEK_VSYNTH2-$(call ENCDEC, SVQ1, MOV) += svq1 |
95 | 93 |
FATE_SEEK_VSYNTH2-$(call ENCDEC, WMV1, AVI) += wmv1 |
96 | 94 |
FATE_SEEK_VSYNTH2-$(call ENCDEC, WMV2, AVI) += wmv2 |
... | ... |
@@ -208,18 +208,6 @@ FATE_VCODEC-$(call ENCDEC, RV20, RM) += rv20 |
208 | 208 |
fate-vsynth%-rv20: ENCOPTS = -qscale 10 |
209 | 209 |
fate-vsynth%-rv20: FMT = rm |
210 | 210 |
|
211 |
-FATE_VCODEC-$(call ENCDEC, SNOW, AVI) += snow snow-hpel snow-ll |
|
212 |
-fate-vsynth%-snow: ENCOPTS = -strict -2 -qscale 2 -flags +qpel \ |
|
213 |
- -me_method iter -dia_size 2 \ |
|
214 |
- -cmp 12 -subcmp 12 -s 128x64 |
|
215 |
- |
|
216 |
-fate-vsynth%-snow-hpel: ENCOPTS = -strict -2 -qscale 2 \ |
|
217 |
- -me_method iter -dia_size 2 \ |
|
218 |
- -cmp 12 -subcmp 12 -s 128x64 |
|
219 |
- |
|
220 |
-fate-vsynth%-snow-ll: ENCOPTS = -strict -2 -qscale .001 -pred 1 \ |
|
221 |
- -flags +mv4+qpel |
|
222 |
- |
|
223 | 211 |
FATE_VCODEC-$(call ENCDEC, SVQ1, MOV) += svq1 |
224 | 212 |
fate-vsynth%-svq1: ENCOPTS = -qscale 3 -pix_fmt yuv410p |
225 | 213 |
fate-vsynth%-svq1: FMT = mov |
226 | 214 |
deleted file mode 100644 |
... | ... |
@@ -1,46 +0,0 @@ |
1 |
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 5648 size: 3035 |
|
2 |
-ret: 0 st:-1 flags:0 ts:-1.000000 |
|
3 |
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 5648 size: 3035 |
|
4 |
-ret: 0 st:-1 flags:1 ts: 1.894167 |
|
5 |
-ret: 0 st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos: 39714 size: 3640 |
|
6 |
-ret: 0 st: 0 flags:0 ts: 0.800000 |
|
7 |
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 27434 size: 3494 |
|
8 |
-ret:-1 st: 0 flags:1 ts:-0.320000 |
|
9 |
-ret:-1 st:-1 flags:0 ts: 2.576668 |
|
10 |
-ret: 0 st:-1 flags:1 ts: 1.470835 |
|
11 |
-ret: 0 st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos: 39714 size: 3640 |
|
12 |
-ret: 0 st: 0 flags:0 ts: 0.360000 |
|
13 |
-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 16124 size: 3244 |
|
14 |
-ret:-1 st: 0 flags:1 ts:-0.760000 |
|
15 |
-ret:-1 st:-1 flags:0 ts: 2.153336 |
|
16 |
-ret: 0 st:-1 flags:1 ts: 1.047503 |
|
17 |
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 27434 size: 3494 |
|
18 |
-ret: 0 st: 0 flags:0 ts:-0.040000 |
|
19 |
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 5648 size: 3035 |
|
20 |
-ret: 0 st: 0 flags:1 ts: 2.840000 |
|
21 |
-ret: 0 st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 52604 size: 3582 |
|
22 |
-ret: 0 st:-1 flags:0 ts: 1.730004 |
|
23 |
-ret: 0 st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 52604 size: 3582 |
|
24 |
-ret: 0 st:-1 flags:1 ts: 0.624171 |
|
25 |
-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 16124 size: 3244 |
|
26 |
-ret: 0 st: 0 flags:0 ts:-0.480000 |
|
27 |
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 5648 size: 3035 |
|
28 |
-ret: 0 st: 0 flags:1 ts: 2.400000 |
|
29 |
-ret: 0 st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 52604 size: 3582 |
|
30 |
-ret: 0 st:-1 flags:0 ts: 1.306672 |
|
31 |
-ret: 0 st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos: 39714 size: 3640 |
|
32 |
-ret: 0 st:-1 flags:1 ts: 0.200839 |
|
33 |
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 5648 size: 3035 |
|
34 |
-ret: 0 st: 0 flags:0 ts:-0.920000 |
|
35 |
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 5648 size: 3035 |
|
36 |
-ret: 0 st: 0 flags:1 ts: 2.000000 |
|
37 |
-ret: 0 st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos: 52604 size: 3582 |
|
38 |
-ret: 0 st:-1 flags:0 ts: 0.883340 |
|
39 |
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 27434 size: 3494 |
|
40 |
-ret:-1 st:-1 flags:1 ts:-0.222493 |
|
41 |
-ret:-1 st: 0 flags:0 ts: 2.680000 |
|
42 |
-ret: 0 st: 0 flags:1 ts: 1.560000 |
|
43 |
-ret: 0 st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos: 39714 size: 3640 |
|
44 |
-ret: 0 st:-1 flags:0 ts: 0.460008 |
|
45 |
-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 16124 size: 3244 |
|
46 |
-ret:-1 st:-1 flags:1 ts:-0.645825 |
47 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,46 +0,0 @@ |
1 |
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 5648 size: 72476 |
|
2 |
-ret: 0 st:-1 flags:0 ts:-1.000000 |
|
3 |
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 5648 size: 72476 |
|
4 |
-ret: 0 st:-1 flags:1 ts: 1.894167 |
|
5 |
-ret: 0 st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos:1902788 size: 78837 |
|
6 |
-ret: 0 st: 0 flags:0 ts: 0.800000 |
|
7 |
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:1239090 size: 74994 |
|
8 |
-ret:-1 st: 0 flags:1 ts:-0.320000 |
|
9 |
-ret:-1 st:-1 flags:0 ts: 2.576668 |
|
10 |
-ret: 0 st:-1 flags:1 ts: 1.470835 |
|
11 |
-ret: 0 st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos:1902788 size: 78837 |
|
12 |
-ret: 0 st: 0 flags:0 ts: 0.360000 |
|
13 |
-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 605628 size: 71059 |
|
14 |
-ret:-1 st: 0 flags:1 ts:-0.760000 |
|
15 |
-ret:-1 st:-1 flags:0 ts: 2.153336 |
|
16 |
-ret: 0 st:-1 flags:1 ts: 1.047503 |
|
17 |
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:1239090 size: 74994 |
|
18 |
-ret: 0 st: 0 flags:0 ts:-0.040000 |
|
19 |
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 5648 size: 72476 |
|
20 |
-ret: 0 st: 0 flags:1 ts: 2.840000 |
|
21 |
-ret: 0 st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos:2585614 size: 79731 |
|
22 |
-ret: 0 st:-1 flags:0 ts: 1.730004 |
|
23 |
-ret: 0 st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos:2585614 size: 79731 |
|
24 |
-ret: 0 st:-1 flags:1 ts: 0.624171 |
|
25 |
-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 605628 size: 71059 |
|
26 |
-ret: 0 st: 0 flags:0 ts:-0.480000 |
|
27 |
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 5648 size: 72476 |
|
28 |
-ret: 0 st: 0 flags:1 ts: 2.400000 |
|
29 |
-ret: 0 st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos:2585614 size: 79731 |
|
30 |
-ret: 0 st:-1 flags:0 ts: 1.306672 |
|
31 |
-ret: 0 st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos:1902788 size: 78837 |
|
32 |
-ret: 0 st:-1 flags:1 ts: 0.200839 |
|
33 |
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 5648 size: 72476 |
|
34 |
-ret: 0 st: 0 flags:0 ts:-0.920000 |
|
35 |
-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 5648 size: 72476 |
|
36 |
-ret: 0 st: 0 flags:1 ts: 2.000000 |
|
37 |
-ret: 0 st: 0 flags:1 dts: 1.920000 pts: 1.920000 pos:2585614 size: 79731 |
|
38 |
-ret: 0 st:-1 flags:0 ts: 0.883340 |
|
39 |
-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:1239090 size: 74994 |
|
40 |
-ret:-1 st:-1 flags:1 ts:-0.222493 |
|
41 |
-ret:-1 st: 0 flags:0 ts: 2.680000 |
|
42 |
-ret: 0 st: 0 flags:1 ts: 1.560000 |
|
43 |
-ret: 0 st: 0 flags:1 dts: 1.440000 pts: 1.440000 pos:1902788 size: 78837 |
|
44 |
-ret: 0 st:-1 flags:0 ts: 0.460008 |
|
45 |
-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 605628 size: 71059 |
|
46 |
-ret:-1 st:-1 flags:1 ts:-0.645825 |
47 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,4 +0,0 @@ |
1 |
-44fed844eb715fba0cc2433e7d7713bb *tests/data/fate/vsynth1-snow.avi |
|
2 |
-136076 tests/data/fate/vsynth1-snow.avi |
|
3 |
-91021b7d6d7908648fe78cc1975af8c4 *tests/data/fate/vsynth1-snow.out.rawvideo |
|
4 |
-stddev: 22.77 PSNR: 20.98 MAXDIFF: 172 bytes: 7603200/ 7603200 |
5 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,4 +0,0 @@ |
1 |
-f60c8cb8f41b66bc38df87e9bdb84b34 *tests/data/fate/vsynth1-snow-hpel.avi |
|
2 |
-138700 tests/data/fate/vsynth1-snow-hpel.avi |
|
3 |
-d6845c8f1310e041afdcebc6bbfc449b *tests/data/fate/vsynth1-snow-hpel.out.rawvideo |
|
4 |
-stddev: 22.74 PSNR: 20.99 MAXDIFF: 171 bytes: 7603200/ 7603200 |
5 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,4 +0,0 @@ |
1 |
-bdc7a025cd306f3da0d377b06bbe909b *tests/data/fate/vsynth1-snow-ll.avi |
|
2 |
-3419968 tests/data/fate/vsynth1-snow-ll.avi |
|
3 |
-c5ccac874dbf808e9088bc3107860042 *tests/data/fate/vsynth1-snow-ll.out.rawvideo |
|
4 |
-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200 |
5 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,4 +0,0 @@ |
1 |
-4b6236e23ae4a52655f2c24c5a09380a *tests/data/fate/vsynth2-snow.avi |
|
2 |
-57688 tests/data/fate/vsynth2-snow.avi |
|
3 |
-8890189af71a0dd3447c4e8424c9a76b *tests/data/fate/vsynth2-snow.out.rawvideo |
|
4 |
-stddev: 10.47 PSNR: 27.72 MAXDIFF: 119 bytes: 7603200/ 7603200 |
5 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,4 +0,0 @@ |
1 |
-9872032345c33cf8e8fc26ab655be3d3 *tests/data/fate/vsynth2-snow-hpel.avi |
|
2 |
-61760 tests/data/fate/vsynth2-snow-hpel.avi |
|
3 |
-8680d40905f423999d65b996c4dcb984 *tests/data/fate/vsynth2-snow-hpel.out.rawvideo |
|
4 |
-stddev: 10.45 PSNR: 27.74 MAXDIFF: 123 bytes: 7603200/ 7603200 |
5 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,4 +0,0 @@ |
1 |
-30b40e0bf64f92b23d6f94056c0c6da5 *tests/data/fate/vsynth2-snow-ll.avi |
|
2 |
-2721746 tests/data/fate/vsynth2-snow-ll.avi |
|
3 |
-dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth2-snow-ll.out.rawvideo |
|
4 |
-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200 |