]> git.sesse.net Git - ffmpeg/blob - libavcodec/dwt.h
Merge remote-tracking branch 'shariman/wmall'
[ffmpeg] / libavcodec / dwt.h
1 /*
2  * Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 #define MAX_DWT_SUPPORT 8
30 #define MAX_DECOMPOSITIONS 8
31
32 typedef struct {
33     IDWTELEM *b[MAX_DWT_SUPPORT];
34
35     IDWTELEM *b0;
36     IDWTELEM *b1;
37     IDWTELEM *b2;
38     IDWTELEM *b3;
39     int y;
40 } DWTCompose;
41
42 /** Used to minimize the amount of memory used in order to optimize cache performance. **/
43 typedef struct slice_buffer_s {
44     IDWTELEM * * line; ///< For use by idwt and predict_slices.
45     IDWTELEM * * data_stack; ///< Used for internal purposes.
46     int data_stack_top;
47     int line_count;
48     int line_width;
49     int data_count;
50     IDWTELEM * base_buffer; ///< Buffer that this structure is caching.
51 } slice_buffer;
52
53 struct DWTContext;
54
55 // Possible prototypes for vertical_compose functions
56 typedef void (*vertical_compose_2tap)(IDWTELEM *b0, IDWTELEM *b1, int width);
57 typedef void (*vertical_compose_3tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width);
58 typedef void (*vertical_compose_5tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, int width);
59 typedef void (*vertical_compose_9tap)(IDWTELEM *dst, IDWTELEM *b[8], int width);
60
61 typedef struct DWTContext {
62     IDWTELEM *buffer;
63     IDWTELEM *temp;
64     int width;
65     int height;
66     int stride;
67     int decomposition_count;
68     int support;
69
70     void (*spatial_compose)(struct DWTContext *cs, int level, int width, int height, int stride);
71     void (*vertical_compose_l0)(void);
72     void (*vertical_compose_h0)(void);
73     void (*vertical_compose_l1)(void);
74     void (*vertical_compose_h1)(void);
75     void (*vertical_compose)(void);     ///< one set of lowpass and highpass combined
76     void (*horizontal_compose)(IDWTELEM *b, IDWTELEM *tmp, int width);
77
78     void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width);
79     void (*horizontal_compose97i)(IDWTELEM *b, int width);
80     void (*inner_add_yblock)(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8);
81
82     DWTCompose cs[MAX_DECOMPOSITIONS];
83 } DWTContext;
84
85 enum dwt_type {
86     DWT_SNOW_DAUB9_7,
87     DWT_SNOW_LEGALL5_3,
88     DWT_DIRAC_DD9_7,
89     DWT_DIRAC_LEGALL5_3,
90     DWT_DIRAC_DD13_7,
91     DWT_DIRAC_HAAR0,
92     DWT_DIRAC_HAAR1,
93     DWT_DIRAC_FIDELITY,
94     DWT_DIRAC_DAUB9_7,
95     DWT_NUM_TYPES
96 };
97
98 // -1 if an error occurred, e.g. the dwt_type isn't recognized
99 int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height,
100                           int stride, enum dwt_type type, int decomposition_count,
101                           IDWTELEM *temp);
102
103 int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride,
104                      enum dwt_type type, int decomposition_count, IDWTELEM *temp);
105
106 void ff_spatial_idwt_slice2(DWTContext *d, int y);
107
108 // shared stuff for simd optimiztions
109 #define COMPOSE_53iL0(b0, b1, b2)\
110     (b1 - ((b0 + b2 + 2) >> 2))
111
112 #define COMPOSE_DIRAC53iH0(b0, b1, b2)\
113     (b1 + ((b0 + b2 + 1) >> 1))
114
115 #define COMPOSE_DD97iH0(b0, b1, b2, b3, b4)\
116     (b2 + ((-b0 + 9*b1 + 9*b3 - b4 + 8) >> 4))
117
118 #define COMPOSE_DD137iL0(b0, b1, b2, b3, b4)\
119     (b2 - ((-b0 + 9*b1 + 9*b3 - b4 + 16) >> 5))
120
121 #define COMPOSE_HAARiL0(b0, b1)\
122     (b0 - ((b1 + 1) >> 1))
123
124 #define COMPOSE_HAARiH0(b0, b1)\
125     (b0 + b1)
126
127 #define COMPOSE_FIDELITYiL0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\
128     (b4 - ((-8*(b0+b8) + 21*(b1+b7) - 46*(b2+b6) + 161*(b3+b5) + 128) >> 8))
129
130 #define COMPOSE_FIDELITYiH0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\
131     (b4 + ((-2*(b0+b8) + 10*(b1+b7) - 25*(b2+b6) + 81*(b3+b5) + 128) >> 8))
132
133 #define COMPOSE_DAUB97iL1(b0, b1, b2)\
134     (b1 - ((1817*(b0 + b2) + 2048) >> 12))
135
136 #define COMPOSE_DAUB97iH1(b0, b1, b2)\
137     (b1 - (( 113*(b0 + b2) + 64) >> 7))
138
139 #define COMPOSE_DAUB97iL0(b0, b1, b2)\
140     (b1 + (( 217*(b0 + b2) + 2048) >> 12))
141
142 #define COMPOSE_DAUB97iH0(b0, b1, b2)\
143     (b1 + ((6497*(b0 + b2) + 2048) >> 12))
144
145
146
147 #define DWT_97 0
148 #define DWT_53 1
149
150 #define liftS lift
151 #if 1
152 #define W_AM 3
153 #define W_AO 0
154 #define W_AS 1
155
156 #undef liftS
157 #define W_BM 1
158 #define W_BO 8
159 #define W_BS 4
160
161 #define W_CM 1
162 #define W_CO 0
163 #define W_CS 0
164
165 #define W_DM 3
166 #define W_DO 4
167 #define W_DS 3
168 #elif 0
169 #define W_AM 55
170 #define W_AO 16
171 #define W_AS 5
172
173 #define W_BM 3
174 #define W_BO 32
175 #define W_BS 6
176
177 #define W_CM 127
178 #define W_CO 64
179 #define W_CS 7
180
181 #define W_DM 7
182 #define W_DO 8
183 #define W_DS 4
184 #elif 0
185 #define W_AM 97
186 #define W_AO 32
187 #define W_AS 6
188
189 #define W_BM 63
190 #define W_BO 512
191 #define W_BS 10
192
193 #define W_CM 13
194 #define W_CO 8
195 #define W_CS 4
196
197 #define W_DM 15
198 #define W_DO 16
199 #define W_DS 5
200
201 #else
202
203 #define W_AM 203
204 #define W_AO 64
205 #define W_AS 7
206
207 #define W_BM 217
208 #define W_BO 2048
209 #define W_BS 12
210
211 #define W_CM 113
212 #define W_CO 64
213 #define W_CS 7
214
215 #define W_DM 227
216 #define W_DO 128
217 #define W_DS 9
218 #endif
219
220 #define slice_buffer_get_line(slice_buf, line_num) ((slice_buf)->line[line_num] ? (slice_buf)->line[line_num] : ff_slice_buffer_load_line((slice_buf), (line_num)))
221 //#define slice_buffer_get_line(slice_buf, line_num) (ff_slice_buffer_load_line((slice_buf), (line_num)))
222
223 void ff_slice_buffer_init(slice_buffer * buf, int line_count, int max_allocated_lines, int line_width, IDWTELEM * base_buffer);
224 void ff_slice_buffer_release(slice_buffer * buf, int line);
225 void ff_slice_buffer_flush(slice_buffer * buf);
226 void ff_slice_buffer_destroy(slice_buffer * buf);
227 IDWTELEM * ff_slice_buffer_load_line(slice_buffer * buf, int line);
228
229 void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width);
230 void ff_snow_horizontal_compose97i(IDWTELEM *b, int width);
231 void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8);
232
233 int ff_w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h);
234 int ff_w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h);
235
236 void ff_spatial_dwt(int *buffer, int width, int height, int stride, int type, int decomposition_count);
237
238 void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line, int type, int decomposition_count);
239 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);
240 void ff_spatial_idwt(IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count);
241
242 void ff_dwt_init(DWTContext *c);
243 void ff_dwt_init_x86(DWTContext *c);
244
245 #endif /* AVCODEC_DWT_H */