annotate dwt.c @ 12183:4fccdee316ea libavcodec

Add ff_draw_pc_font()
author pross
date Sun, 18 Jul 2010 07:44:38 +0000
parents c71384779e14
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11485
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
1 /*
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
2 * Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at>
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
3 *
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
4 * This file is part of FFmpeg.
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
5 *
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
10 *
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
14 * Lesser General Public License for more details.
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
15 *
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
19 */
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
20
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
21 #include "libavutil/attributes.h"
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
22 #include "dsputil.h"
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
23 #include "dwt.h"
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
24
11486
1bf7af4db35a Add ff_ prefix to dwt functions
mru
parents: 11485
diff changeset
25 void ff_slice_buffer_init(slice_buffer * buf, int line_count, int max_allocated_lines, int line_width, IDWTELEM * base_buffer)
11485
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
26 {
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
27 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
28
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
29 buf->base_buffer = base_buffer;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
30 buf->line_count = line_count;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
31 buf->line_width = line_width;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
32 buf->data_count = max_allocated_lines;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
33 buf->line = av_mallocz (sizeof(IDWTELEM *) * line_count);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
34 buf->data_stack = av_malloc (sizeof(IDWTELEM *) * max_allocated_lines);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
35
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
36 for(i = 0; i < max_allocated_lines; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
37 buf->data_stack[i] = av_malloc (sizeof(IDWTELEM) * line_width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
38 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
39
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
40 buf->data_stack_top = max_allocated_lines - 1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
41 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
42
11486
1bf7af4db35a Add ff_ prefix to dwt functions
mru
parents: 11485
diff changeset
43 IDWTELEM * ff_slice_buffer_load_line(slice_buffer * buf, int line)
11485
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
44 {
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
45 IDWTELEM * buffer;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
46
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
47 assert(buf->data_stack_top >= 0);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
48 // assert(!buf->line[line]);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
49 if (buf->line[line])
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
50 return buf->line[line];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
51
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
52 buffer = buf->data_stack[buf->data_stack_top];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
53 buf->data_stack_top--;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
54 buf->line[line] = buffer;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
55
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
56 return buffer;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
57 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
58
11486
1bf7af4db35a Add ff_ prefix to dwt functions
mru
parents: 11485
diff changeset
59 void ff_slice_buffer_release(slice_buffer * buf, int line)
11485
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
60 {
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
61 IDWTELEM * buffer;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
62
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
63 assert(line >= 0 && line < buf->line_count);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
64 assert(buf->line[line]);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
65
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
66 buffer = buf->line[line];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
67 buf->data_stack_top++;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
68 buf->data_stack[buf->data_stack_top] = buffer;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
69 buf->line[line] = NULL;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
70 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
71
11486
1bf7af4db35a Add ff_ prefix to dwt functions
mru
parents: 11485
diff changeset
72 void ff_slice_buffer_flush(slice_buffer * buf)
11485
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
73 {
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
74 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
75 for(i = 0; i < buf->line_count; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
76 if (buf->line[i])
11486
1bf7af4db35a Add ff_ prefix to dwt functions
mru
parents: 11485
diff changeset
77 ff_slice_buffer_release(buf, i);
11485
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
78 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
79 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
80
11486
1bf7af4db35a Add ff_ prefix to dwt functions
mru
parents: 11485
diff changeset
81 void ff_slice_buffer_destroy(slice_buffer * buf)
11485
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
82 {
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
83 int i;
11486
1bf7af4db35a Add ff_ prefix to dwt functions
mru
parents: 11485
diff changeset
84 ff_slice_buffer_flush(buf);
11485
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
85
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
86 for(i = buf->data_count - 1; i >= 0; i--){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
87 av_freep(&buf->data_stack[i]);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
88 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
89 av_freep(&buf->data_stack);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
90 av_freep(&buf->line);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
91 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
92
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
93 static inline int mirror(int v, int m){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
94 while((unsigned)v > (unsigned)m){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
95 v=-v;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
96 if(v<0) v+= 2*m;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
97 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
98 return v;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
99 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
100
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
101 static av_always_inline void
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
102 lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
103 int dst_step, int src_step, int ref_step,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
104 int width, int mul, int add, int shift,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
105 int highpass, int inverse){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
106 const int mirror_left= !highpass;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
107 const int mirror_right= (width&1) ^ highpass;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
108 const int w= (width>>1) - 1 + (highpass & width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
109 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
110
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
111 #define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref)))
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
112 if(mirror_left){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
113 dst[0] = LIFT(src[0], ((mul*2*ref[0]+add)>>shift), inverse);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
114 dst += dst_step;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
115 src += src_step;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
116 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
117
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
118 for(i=0; i<w; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
119 dst[i*dst_step] =
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
120 LIFT(src[i*src_step],
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
121 ((mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add)>>shift),
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
122 inverse);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
123 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
124
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
125 if(mirror_right){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
126 dst[w*dst_step] =
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
127 LIFT(src[w*src_step],
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
128 ((mul*2*ref[w*ref_step]+add)>>shift),
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
129 inverse);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
130 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
131 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
132
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
133 static av_always_inline void
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
134 inv_lift(IDWTELEM *dst, IDWTELEM *src, IDWTELEM *ref,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
135 int dst_step, int src_step, int ref_step,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
136 int width, int mul, int add, int shift,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
137 int highpass, int inverse){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
138 const int mirror_left= !highpass;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
139 const int mirror_right= (width&1) ^ highpass;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
140 const int w= (width>>1) - 1 + (highpass & width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
141 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
142
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
143 #define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref)))
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
144 if(mirror_left){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
145 dst[0] = LIFT(src[0], ((mul*2*ref[0]+add)>>shift), inverse);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
146 dst += dst_step;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
147 src += src_step;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
148 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
149
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
150 for(i=0; i<w; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
151 dst[i*dst_step] =
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
152 LIFT(src[i*src_step],
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
153 ((mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add)>>shift),
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
154 inverse);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
155 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
156
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
157 if(mirror_right){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
158 dst[w*dst_step] =
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
159 LIFT(src[w*src_step],
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
160 ((mul*2*ref[w*ref_step]+add)>>shift),
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
161 inverse);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
162 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
163 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
164
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
165 #ifndef liftS
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
166 static av_always_inline void
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
167 liftS(DWTELEM *dst, DWTELEM *src, DWTELEM *ref,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
168 int dst_step, int src_step, int ref_step,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
169 int width, int mul, int add, int shift,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
170 int highpass, int inverse){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
171 const int mirror_left= !highpass;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
172 const int mirror_right= (width&1) ^ highpass;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
173 const int w= (width>>1) - 1 + (highpass & width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
174 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
175
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
176 assert(shift == 4);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
177 #define LIFTS(src, ref, inv) \
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
178 ((inv) ? \
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
179 (src) + (((ref) + 4*(src))>>shift): \
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
180 -((-16*(src) + (ref) + add/4 + 1 + (5<<25))/(5*4) - (1<<23)))
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
181 if(mirror_left){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
182 dst[0] = LIFTS(src[0], mul*2*ref[0]+add, inverse);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
183 dst += dst_step;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
184 src += src_step;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
185 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
186
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
187 for(i=0; i<w; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
188 dst[i*dst_step] =
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
189 LIFTS(src[i*src_step],
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
190 mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
191 inverse);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
192 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
193
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
194 if(mirror_right){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
195 dst[w*dst_step] =
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
196 LIFTS(src[w*src_step], mul*2*ref[w*ref_step]+add, inverse);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
197 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
198 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
199 static av_always_inline void
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
200 inv_liftS(IDWTELEM *dst, IDWTELEM *src, IDWTELEM *ref,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
201 int dst_step, int src_step, int ref_step,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
202 int width, int mul, int add, int shift,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
203 int highpass, int inverse){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
204 const int mirror_left= !highpass;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
205 const int mirror_right= (width&1) ^ highpass;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
206 const int w= (width>>1) - 1 + (highpass & width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
207 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
208
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
209 assert(shift == 4);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
210 #define LIFTS(src, ref, inv) \
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
211 ((inv) ? \
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
212 (src) + (((ref) + 4*(src))>>shift): \
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
213 -((-16*(src) + (ref) + add/4 + 1 + (5<<25))/(5*4) - (1<<23)))
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
214 if(mirror_left){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
215 dst[0] = LIFTS(src[0], mul*2*ref[0]+add, inverse);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
216 dst += dst_step;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
217 src += src_step;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
218 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
219
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
220 for(i=0; i<w; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
221 dst[i*dst_step] =
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
222 LIFTS(src[i*src_step],
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
223 mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add,
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
224 inverse);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
225 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
226
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
227 if(mirror_right){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
228 dst[w*dst_step] =
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
229 LIFTS(src[w*src_step], mul*2*ref[w*ref_step]+add, inverse);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
230 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
231 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
232 #endif /* ! liftS */
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
233
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
234 static void horizontal_decompose53i(DWTELEM *b, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
235 DWTELEM temp[width];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
236 const int width2= width>>1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
237 int x;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
238 const int w2= (width+1)>>1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
239
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
240 for(x=0; x<width2; x++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
241 temp[x ]= b[2*x ];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
242 temp[x+w2]= b[2*x + 1];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
243 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
244 if(width&1)
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
245 temp[x ]= b[2*x ];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
246 #if 0
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
247 {
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
248 int A1,A2,A3,A4;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
249 A2= temp[1 ];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
250 A4= temp[0 ];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
251 A1= temp[0+width2];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
252 A1 -= (A2 + A4)>>1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
253 A4 += (A1 + 1)>>1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
254 b[0+width2] = A1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
255 b[0 ] = A4;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
256 for(x=1; x+1<width2; x+=2){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
257 A3= temp[x+width2];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
258 A4= temp[x+1 ];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
259 A3 -= (A2 + A4)>>1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
260 A2 += (A1 + A3 + 2)>>2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
261 b[x+width2] = A3;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
262 b[x ] = A2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
263
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
264 A1= temp[x+1+width2];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
265 A2= temp[x+2 ];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
266 A1 -= (A2 + A4)>>1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
267 A4 += (A1 + A3 + 2)>>2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
268 b[x+1+width2] = A1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
269 b[x+1 ] = A4;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
270 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
271 A3= temp[width-1];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
272 A3 -= A2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
273 A2 += (A1 + A3 + 2)>>2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
274 b[width -1] = A3;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
275 b[width2-1] = A2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
276 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
277 #else
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
278 lift(b+w2, temp+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
279 lift(b , temp , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 0);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
280 #endif /* 0 */
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
281 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
282
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
283 static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
284 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
285
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
286 for(i=0; i<width; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
287 b1[i] -= (b0[i] + b2[i])>>1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
288 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
289 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
290
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
291 static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
292 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
293
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
294 for(i=0; i<width; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
295 b1[i] += (b0[i] + b2[i] + 2)>>2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
296 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
297 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
298
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
299 static void spatial_decompose53i(DWTELEM *buffer, int width, int height, int stride){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
300 int y;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
301 DWTELEM *b0= buffer + mirror(-2-1, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
302 DWTELEM *b1= buffer + mirror(-2 , height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
303
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
304 for(y=-2; y<height; y+=2){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
305 DWTELEM *b2= buffer + mirror(y+1, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
306 DWTELEM *b3= buffer + mirror(y+2, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
307
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
308 if(y+1<(unsigned)height) horizontal_decompose53i(b2, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
309 if(y+2<(unsigned)height) horizontal_decompose53i(b3, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
310
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
311 if(y+1<(unsigned)height) vertical_decompose53iH0(b1, b2, b3, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
312 if(y+0<(unsigned)height) vertical_decompose53iL0(b0, b1, b2, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
313
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
314 b0=b2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
315 b1=b3;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
316 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
317 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
318
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
319 static void horizontal_decompose97i(DWTELEM *b, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
320 DWTELEM temp[width];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
321 const int w2= (width+1)>>1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
322
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
323 lift (temp+w2, b +1, b , 1, 2, 2, width, W_AM, W_AO, W_AS, 1, 1);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
324 liftS(temp , b , temp+w2, 1, 2, 1, width, W_BM, W_BO, W_BS, 0, 0);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
325 lift (b +w2, temp+w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
326 lift (b , temp , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 0);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
327 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
328
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
329
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
330 static void vertical_decompose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
331 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
332
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
333 for(i=0; i<width; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
334 b1[i] -= (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
335 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
336 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
337
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
338 static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
339 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
340
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
341 for(i=0; i<width; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
342 b1[i] += (W_CM*(b0[i] + b2[i])+W_CO)>>W_CS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
343 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
344 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
345
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
346 static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
347 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
348
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
349 for(i=0; i<width; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
350 #ifdef liftS
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
351 b1[i] -= (W_BM*(b0[i] + b2[i])+W_BO)>>W_BS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
352 #else
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
353 b1[i] = (16*4*b1[i] - 4*(b0[i] + b2[i]) + W_BO*5 + (5<<27)) / (5*16) - (1<<23);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
354 #endif
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
355 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
356 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
357
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
358 static void vertical_decompose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
359 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
360
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
361 for(i=0; i<width; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
362 b1[i] += (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
363 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
364 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
365
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
366 static void spatial_decompose97i(DWTELEM *buffer, int width, int height, int stride){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
367 int y;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
368 DWTELEM *b0= buffer + mirror(-4-1, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
369 DWTELEM *b1= buffer + mirror(-4 , height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
370 DWTELEM *b2= buffer + mirror(-4+1, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
371 DWTELEM *b3= buffer + mirror(-4+2, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
372
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
373 for(y=-4; y<height; y+=2){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
374 DWTELEM *b4= buffer + mirror(y+3, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
375 DWTELEM *b5= buffer + mirror(y+4, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
376
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
377 if(y+3<(unsigned)height) horizontal_decompose97i(b4, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
378 if(y+4<(unsigned)height) horizontal_decompose97i(b5, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
379
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
380 if(y+3<(unsigned)height) vertical_decompose97iH0(b3, b4, b5, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
381 if(y+2<(unsigned)height) vertical_decompose97iL0(b2, b3, b4, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
382 if(y+1<(unsigned)height) vertical_decompose97iH1(b1, b2, b3, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
383 if(y+0<(unsigned)height) vertical_decompose97iL1(b0, b1, b2, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
384
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
385 b0=b2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
386 b1=b3;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
387 b2=b4;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
388 b3=b5;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
389 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
390 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
391
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
392 void ff_spatial_dwt(DWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
393 int level;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
394
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
395 for(level=0; level<decomposition_count; level++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
396 switch(type){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
397 case DWT_97: spatial_decompose97i(buffer, width>>level, height>>level, stride<<level); break;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
398 case DWT_53: spatial_decompose53i(buffer, width>>level, height>>level, stride<<level); break;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
399 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
400 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
401 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
402
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
403 static void horizontal_compose53i(IDWTELEM *b, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
404 IDWTELEM temp[width];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
405 const int width2= width>>1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
406 const int w2= (width+1)>>1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
407 int x;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
408
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
409 for(x=0; x<width2; x++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
410 temp[2*x ]= b[x ];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
411 temp[2*x + 1]= b[x+w2];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
412 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
413 if(width&1)
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
414 temp[2*x ]= b[x ];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
415
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
416 b[0] = temp[0] - ((temp[1]+1)>>1);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
417 for(x=2; x<width-1; x+=2){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
418 b[x ] = temp[x ] - ((temp[x-1] + temp[x+1]+2)>>2);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
419 b[x-1] = temp[x-1] + ((b [x-2] + b [x ]+1)>>1);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
420 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
421 if(width&1){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
422 b[x ] = temp[x ] - ((temp[x-1]+1)>>1);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
423 b[x-1] = temp[x-1] + ((b [x-2] + b [x ]+1)>>1);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
424 }else
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
425 b[x-1] = temp[x-1] + b[x-2];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
426 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
427
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
428 static void vertical_compose53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
429 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
430
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
431 for(i=0; i<width; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
432 b1[i] += (b0[i] + b2[i])>>1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
433 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
434 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
435
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
436 static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
437 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
438
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
439 for(i=0; i<width; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
440 b1[i] -= (b0[i] + b2[i] + 2)>>2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
441 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
442 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
443
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
444 static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer * sb, int height, int stride_line){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
445 cs->b0 = slice_buffer_get_line(sb, mirror(-1-1, height-1) * stride_line);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
446 cs->b1 = slice_buffer_get_line(sb, mirror(-1 , height-1) * stride_line);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
447 cs->y = -1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
448 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
449
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
450 static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
451 cs->b0 = buffer + mirror(-1-1, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
452 cs->b1 = buffer + mirror(-1 , height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
453 cs->y = -1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
454 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
455
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
456 static void spatial_compose53i_dy_buffered(DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
457 int y= cs->y;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
458
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
459 IDWTELEM *b0= cs->b0;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
460 IDWTELEM *b1= cs->b1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
461 IDWTELEM *b2= slice_buffer_get_line(sb, mirror(y+1, height-1) * stride_line);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
462 IDWTELEM *b3= slice_buffer_get_line(sb, mirror(y+2, height-1) * stride_line);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
463
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
464 if(y+1<(unsigned)height && y<(unsigned)height){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
465 int x;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
466
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
467 for(x=0; x<width; x++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
468 b2[x] -= (b1[x] + b3[x] + 2)>>2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
469 b1[x] += (b0[x] + b2[x])>>1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
470 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
471 }else{
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
472 if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
473 if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
474 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
475
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
476 if(y-1<(unsigned)height) horizontal_compose53i(b0, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
477 if(y+0<(unsigned)height) horizontal_compose53i(b1, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
478
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
479 cs->b0 = b2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
480 cs->b1 = b3;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
481 cs->y += 2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
482 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
483
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
484 static void spatial_compose53i_dy(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
485 int y= cs->y;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
486 IDWTELEM *b0= cs->b0;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
487 IDWTELEM *b1= cs->b1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
488 IDWTELEM *b2= buffer + mirror(y+1, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
489 IDWTELEM *b3= buffer + mirror(y+2, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
490
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
491 if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
492 if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
493
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
494 if(y-1<(unsigned)height) horizontal_compose53i(b0, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
495 if(y+0<(unsigned)height) horizontal_compose53i(b1, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
496
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
497 cs->b0 = b2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
498 cs->b1 = b3;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
499 cs->y += 2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
500 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
501
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
502 static void av_unused spatial_compose53i(IDWTELEM *buffer, int width, int height, int stride){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
503 DWTCompose cs;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
504 spatial_compose53i_init(&cs, buffer, height, stride);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
505 while(cs.y <= height)
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
506 spatial_compose53i_dy(&cs, buffer, width, height, stride);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
507 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
508
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
509
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
510 void ff_snow_horizontal_compose97i(IDWTELEM *b, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
511 IDWTELEM temp[width];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
512 const int w2= (width+1)>>1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
513
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
514 #if 0 //maybe more understadable but slower
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
515 inv_lift (temp , b , b +w2, 2, 1, 1, width, W_DM, W_DO, W_DS, 0, 1);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
516 inv_lift (temp+1 , b +w2, temp , 2, 1, 2, width, W_CM, W_CO, W_CS, 1, 1);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
517
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
518 inv_liftS(b , temp , temp+1 , 2, 2, 2, width, W_BM, W_BO, W_BS, 0, 1);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
519 inv_lift (b+1 , temp+1 , b , 2, 2, 2, width, W_AM, W_AO, W_AS, 1, 0);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
520 #else
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
521 int x;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
522 temp[0] = b[0] - ((3*b[w2]+2)>>2);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
523 for(x=1; x<(width>>1); x++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
524 temp[2*x ] = b[x ] - ((3*(b [x+w2-1] + b[x+w2])+4)>>3);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
525 temp[2*x-1] = b[x+w2-1] - temp[2*x-2] - temp[2*x];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
526 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
527 if(width&1){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
528 temp[2*x ] = b[x ] - ((3*b [x+w2-1]+2)>>2);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
529 temp[2*x-1] = b[x+w2-1] - temp[2*x-2] - temp[2*x];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
530 }else
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
531 temp[2*x-1] = b[x+w2-1] - 2*temp[2*x-2];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
532
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
533 b[0] = temp[0] + ((2*temp[0] + temp[1]+4)>>3);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
534 for(x=2; x<width-1; x+=2){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
535 b[x ] = temp[x ] + ((4*temp[x ] + temp[x-1] + temp[x+1]+8)>>4);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
536 b[x-1] = temp[x-1] + ((3*(b [x-2] + b [x ] ))>>1);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
537 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
538 if(width&1){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
539 b[x ] = temp[x ] + ((2*temp[x ] + temp[x-1]+4)>>3);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
540 b[x-1] = temp[x-1] + ((3*(b [x-2] + b [x ] ))>>1);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
541 }else
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
542 b[x-1] = temp[x-1] + 3*b [x-2];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
543 #endif
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
544 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
545
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
546 static void vertical_compose97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
547 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
548
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
549 for(i=0; i<width; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
550 b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
551 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
552 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
553
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
554 static void vertical_compose97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
555 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
556
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
557 for(i=0; i<width; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
558 b1[i] -= (W_CM*(b0[i] + b2[i])+W_CO)>>W_CS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
559 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
560 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
561
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
562 static void vertical_compose97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
563 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
564
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
565 for(i=0; i<width; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
566 #ifdef liftS
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
567 b1[i] += (W_BM*(b0[i] + b2[i])+W_BO)>>W_BS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
568 #else
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
569 b1[i] += (W_BM*(b0[i] + b2[i])+4*b1[i]+W_BO)>>W_BS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
570 #endif
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
571 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
572 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
573
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
574 static void vertical_compose97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
575 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
576
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
577 for(i=0; i<width; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
578 b1[i] -= (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
579 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
580 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
581
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
582 void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
583 int i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
584
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
585 for(i=0; i<width; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
586 b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
587 b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
588 #ifdef liftS
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
589 b2[i] += (W_BM*(b1[i] + b3[i])+W_BO)>>W_BS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
590 #else
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
591 b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
592 #endif
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
593 b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
594 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
595 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
596
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
597 static void spatial_compose97i_buffered_init(DWTCompose *cs, slice_buffer * sb, int height, int stride_line){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
598 cs->b0 = slice_buffer_get_line(sb, mirror(-3-1, height-1) * stride_line);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
599 cs->b1 = slice_buffer_get_line(sb, mirror(-3 , height-1) * stride_line);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
600 cs->b2 = slice_buffer_get_line(sb, mirror(-3+1, height-1) * stride_line);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
601 cs->b3 = slice_buffer_get_line(sb, mirror(-3+2, height-1) * stride_line);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
602 cs->y = -3;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
603 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
604
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
605 static void spatial_compose97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
606 cs->b0 = buffer + mirror(-3-1, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
607 cs->b1 = buffer + mirror(-3 , height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
608 cs->b2 = buffer + mirror(-3+1, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
609 cs->b3 = buffer + mirror(-3+2, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
610 cs->y = -3;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
611 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
612
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
613 static void spatial_compose97i_dy_buffered(DWTContext *dsp, DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
614 int y = cs->y;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
615
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
616 IDWTELEM *b0= cs->b0;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
617 IDWTELEM *b1= cs->b1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
618 IDWTELEM *b2= cs->b2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
619 IDWTELEM *b3= cs->b3;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
620 IDWTELEM *b4= slice_buffer_get_line(sb, mirror(y + 3, height - 1) * stride_line);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
621 IDWTELEM *b5= slice_buffer_get_line(sb, mirror(y + 4, height - 1) * stride_line);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
622
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
623 if(y>0 && y+4<height){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
624 dsp->vertical_compose97i(b0, b1, b2, b3, b4, b5, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
625 }else{
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
626 if(y+3<(unsigned)height) vertical_compose97iL1(b3, b4, b5, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
627 if(y+2<(unsigned)height) vertical_compose97iH1(b2, b3, b4, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
628 if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
629 if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
630 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
631
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
632 if(y-1<(unsigned)height) dsp->horizontal_compose97i(b0, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
633 if(y+0<(unsigned)height) dsp->horizontal_compose97i(b1, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
634
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
635 cs->b0=b2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
636 cs->b1=b3;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
637 cs->b2=b4;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
638 cs->b3=b5;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
639 cs->y += 2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
640 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
641
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
642 static void spatial_compose97i_dy(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
643 int y = cs->y;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
644 IDWTELEM *b0= cs->b0;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
645 IDWTELEM *b1= cs->b1;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
646 IDWTELEM *b2= cs->b2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
647 IDWTELEM *b3= cs->b3;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
648 IDWTELEM *b4= buffer + mirror(y+3, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
649 IDWTELEM *b5= buffer + mirror(y+4, height-1)*stride;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
650
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
651 if(y+3<(unsigned)height) vertical_compose97iL1(b3, b4, b5, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
652 if(y+2<(unsigned)height) vertical_compose97iH1(b2, b3, b4, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
653 if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
654 if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
655
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
656 if(y-1<(unsigned)height) ff_snow_horizontal_compose97i(b0, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
657 if(y+0<(unsigned)height) ff_snow_horizontal_compose97i(b1, width);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
658
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
659 cs->b0=b2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
660 cs->b1=b3;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
661 cs->b2=b4;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
662 cs->b3=b5;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
663 cs->y += 2;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
664 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
665
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
666 static void av_unused spatial_compose97i(IDWTELEM *buffer, int width, int height, int stride){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
667 DWTCompose cs;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
668 spatial_compose97i_init(&cs, buffer, height, stride);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
669 while(cs.y <= height)
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
670 spatial_compose97i_dy(&cs, buffer, width, height, stride);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
671 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
672
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
673 void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line, int type, int decomposition_count){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
674 int level;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
675 for(level=decomposition_count-1; level>=0; level--){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
676 switch(type){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
677 case DWT_97: spatial_compose97i_buffered_init(cs+level, sb, height>>level, stride_line<<level); break;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
678 case DWT_53: spatial_compose53i_buffered_init(cs+level, sb, height>>level, stride_line<<level); break;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
679 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
680 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
681 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
682
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
683 void ff_spatial_idwt_buffered_slice(DWTContext *dsp, DWTCompose *cs, slice_buffer * slice_buf, int width, int height, int stride_line, int type, int decomposition_count, int y){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
684 const int support = type==1 ? 3 : 5;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
685 int level;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
686 if(type==2) return;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
687
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
688 for(level=decomposition_count-1; level>=0; level--){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
689 while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
690 switch(type){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
691 case DWT_97: spatial_compose97i_dy_buffered(dsp, cs+level, slice_buf, width>>level, height>>level, stride_line<<level);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
692 break;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
693 case DWT_53: spatial_compose53i_dy_buffered(cs+level, slice_buf, width>>level, height>>level, stride_line<<level);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
694 break;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
695 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
696 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
697 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
698 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
699
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
700 void ff_spatial_idwt_init(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
701 int level;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
702 for(level=decomposition_count-1; level>=0; level--){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
703 switch(type){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
704 case DWT_97: spatial_compose97i_init(cs+level, buffer, height>>level, stride<<level); break;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
705 case DWT_53: spatial_compose53i_init(cs+level, buffer, height>>level, stride<<level); break;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
706 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
707 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
708 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
709
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
710 void ff_spatial_idwt_slice(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count, int y){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
711 const int support = type==1 ? 3 : 5;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
712 int level;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
713 if(type==2) return;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
714
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
715 for(level=decomposition_count-1; level>=0; level--){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
716 while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
717 switch(type){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
718 case DWT_97: spatial_compose97i_dy(cs+level, buffer, width>>level, height>>level, stride<<level);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
719 break;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
720 case DWT_53: spatial_compose53i_dy(cs+level, buffer, width>>level, height>>level, stride<<level);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
721 break;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
722 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
723 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
724 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
725 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
726
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
727 void ff_spatial_idwt(IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
728 DWTCompose cs[MAX_DECOMPOSITIONS];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
729 int y;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
730 ff_spatial_idwt_init(cs, buffer, width, height, stride, type, decomposition_count);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
731 for(y=0; y<height; y+=4)
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
732 ff_spatial_idwt_slice(cs, buffer, width, height, stride, type, decomposition_count, y);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
733 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
734
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
735 static inline int w_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int w, int h, int type){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
736 int s, i, j;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
737 const int dec_count= w==8 ? 3 : 4;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
738 int tmp[32*32];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
739 int level, ori;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
740 static const int scale[2][2][4][4]={
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
741 {
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
742 {
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
743 // 9/7 8x8 dec=3
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
744 {268, 239, 239, 213},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
745 { 0, 224, 224, 152},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
746 { 0, 135, 135, 110},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
747 },{
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
748 // 9/7 16x16 or 32x32 dec=4
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
749 {344, 310, 310, 280},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
750 { 0, 320, 320, 228},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
751 { 0, 175, 175, 136},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
752 { 0, 129, 129, 102},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
753 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
754 },{
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
755 {
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
756 // 5/3 8x8 dec=3
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
757 {275, 245, 245, 218},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
758 { 0, 230, 230, 156},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
759 { 0, 138, 138, 113},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
760 },{
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
761 // 5/3 16x16 or 32x32 dec=4
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
762 {352, 317, 317, 286},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
763 { 0, 328, 328, 233},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
764 { 0, 180, 180, 140},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
765 { 0, 132, 132, 105},
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
766 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
767 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
768 };
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
769
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
770 for (i = 0; i < h; i++) {
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
771 for (j = 0; j < w; j+=4) {
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
772 tmp[32*i+j+0] = (pix1[j+0] - pix2[j+0])<<4;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
773 tmp[32*i+j+1] = (pix1[j+1] - pix2[j+1])<<4;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
774 tmp[32*i+j+2] = (pix1[j+2] - pix2[j+2])<<4;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
775 tmp[32*i+j+3] = (pix1[j+3] - pix2[j+3])<<4;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
776 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
777 pix1 += line_size;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
778 pix2 += line_size;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
779 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
780
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
781 ff_spatial_dwt(tmp, w, h, 32, type, dec_count);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
782
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
783 s=0;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
784 assert(w==h);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
785 for(level=0; level<dec_count; level++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
786 for(ori= level ? 1 : 0; ori<4; ori++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
787 int size= w>>(dec_count-level);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
788 int sx= (ori&1) ? size : 0;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
789 int stride= 32<<(dec_count-level);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
790 int sy= (ori&2) ? stride>>1 : 0;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
791
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
792 for(i=0; i<size; i++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
793 for(j=0; j<size; j++){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
794 int v= tmp[sx + sy + i*stride + j] * scale[type][dec_count-3][level][ori];
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
795 s += FFABS(v);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
796 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
797 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
798 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
799 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
800 assert(s>=0);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
801 return s>>9;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
802 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
803
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
804 static int w53_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
805 return w_c(v, pix1, pix2, line_size, 8, h, 1);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
806 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
807
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
808 static int w97_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
809 return w_c(v, pix1, pix2, line_size, 8, h, 0);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
810 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
811
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
812 static int w53_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
813 return w_c(v, pix1, pix2, line_size, 16, h, 1);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
814 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
815
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
816 static int w97_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
817 return w_c(v, pix1, pix2, line_size, 16, h, 0);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
818 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
819
11486
1bf7af4db35a Add ff_ prefix to dwt functions
mru
parents: 11485
diff changeset
820 int ff_w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
11485
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
821 return w_c(v, pix1, pix2, line_size, 32, h, 1);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
822 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
823
11486
1bf7af4db35a Add ff_ prefix to dwt functions
mru
parents: 11485
diff changeset
824 int ff_w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
11485
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
825 return w_c(v, pix1, pix2, line_size, 32, h, 0);
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
826 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
827
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
828 void ff_dsputil_init_dwt(DSPContext *c)
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
829 {
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
830 c->w53[0]= w53_16_c;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
831 c->w53[1]= w53_8_c;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
832 c->w97[0]= w97_16_c;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
833 c->w97[1]= w97_8_c;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
834 }
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
835
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
836 void ff_dwt_init(DWTContext *c)
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
837 {
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
838 c->vertical_compose97i = ff_snow_vertical_compose97i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
839 c->horizontal_compose97i = ff_snow_horizontal_compose97i;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
840 c->inner_add_yblock = ff_snow_inner_add_yblock;
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
841
11490
c71384779e14 DWT: x86 init should depend on HAVE_MMX
mru
parents: 11486
diff changeset
842 if (HAVE_MMX) ff_dwt_init_x86(c);
11485
0f0cd6b5791f Separate DWT from snow and dsputil
mru
parents:
diff changeset
843 }