2 * Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
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.
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.
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
27 typedef short IDWTELEM;
29 #define MAX_DWT_SUPPORT 8
30 #define MAX_DECOMPOSITIONS 8
33 IDWTELEM *b[MAX_DWT_SUPPORT];
42 /** Used to minimize the amount of memory used in order to
43 * optimize cache performance. **/
44 typedef struct slice_buffer_s {
45 IDWTELEM **line; ///< For use by idwt and predict_slices.
46 IDWTELEM **data_stack; ///< Used for internal purposes.
51 IDWTELEM *base_buffer; ///< Buffer that this structure is caching.
56 // Possible prototypes for vertical_compose functions
57 typedef void (*vertical_compose_2tap)(IDWTELEM *b0, IDWTELEM *b1, int width);
58 typedef void (*vertical_compose_3tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width);
59 typedef void (*vertical_compose_5tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, int width);
60 typedef void (*vertical_compose_9tap)(IDWTELEM *dst, IDWTELEM *b[8], int width);
62 typedef struct DWTContext {
68 int decomposition_count;
71 void (*spatial_compose)(struct DWTContext *cs, int level, int width, int height, int stride);
72 void (*vertical_compose_l0)(void);
73 void (*vertical_compose_h0)(void);
74 void (*vertical_compose_l1)(void);
75 void (*vertical_compose_h1)(void);
76 void (*vertical_compose)(void); ///< one set of lowpass and highpass combined
77 void (*horizontal_compose)(IDWTELEM *b, IDWTELEM *tmp, int width);
79 void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
80 IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5,
82 void (*horizontal_compose97i)(IDWTELEM *b, IDWTELEM *temp, int width);
83 void (*inner_add_yblock)(const uint8_t *obmc, const int obmc_stride,
84 uint8_t **block, int b_w, int b_h, int src_x,
85 int src_y, int src_stride, slice_buffer *sb,
86 int add, uint8_t *dst8);
88 DWTCompose cs[MAX_DECOMPOSITIONS];
104 // -1 if an error occurred, e.g. the dwt_type isn't recognized
105 int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height,
106 int stride, enum dwt_type type, int decomposition_count,
109 int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride,
110 enum dwt_type type, int decomposition_count, IDWTELEM *temp);
112 void ff_spatial_idwt_slice2(DWTContext *d, int y);
114 // shared stuff for simd optimiztions
115 #define COMPOSE_53iL0(b0, b1, b2)\
116 (b1 - ((b0 + b2 + 2) >> 2))
118 #define COMPOSE_DIRAC53iH0(b0, b1, b2)\
119 (b1 + ((b0 + b2 + 1) >> 1))
121 #define COMPOSE_DD97iH0(b0, b1, b2, b3, b4)\
122 (b2 + ((-b0 + 9*b1 + 9*b3 - b4 + 8) >> 4))
124 #define COMPOSE_DD137iL0(b0, b1, b2, b3, b4)\
125 (b2 - ((-b0 + 9*b1 + 9*b3 - b4 + 16) >> 5))
127 #define COMPOSE_HAARiL0(b0, b1)\
128 (b0 - ((b1 + 1) >> 1))
130 #define COMPOSE_HAARiH0(b0, b1)\
133 #define COMPOSE_FIDELITYiL0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\
134 (b4 - ((-8*(b0+b8) + 21*(b1+b7) - 46*(b2+b6) + 161*(b3+b5) + 128) >> 8))
136 #define COMPOSE_FIDELITYiH0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\
137 (b4 + ((-2*(b0+b8) + 10*(b1+b7) - 25*(b2+b6) + 81*(b3+b5) + 128) >> 8))
139 #define COMPOSE_DAUB97iL1(b0, b1, b2)\
140 (b1 - ((1817*(b0 + b2) + 2048) >> 12))
142 #define COMPOSE_DAUB97iH1(b0, b1, b2)\
143 (b1 - (( 113*(b0 + b2) + 64) >> 7))
145 #define COMPOSE_DAUB97iL0(b0, b1, b2)\
146 (b1 + (( 217*(b0 + b2) + 2048) >> 12))
148 #define COMPOSE_DAUB97iH0(b0, b1, b2)\
149 (b1 + ((6497*(b0 + b2) + 2048) >> 12))
226 #define slice_buffer_get_line(slice_buf, line_num) \
227 ((slice_buf)->line[line_num] ? (slice_buf)->line[line_num] \
228 : ff_slice_buffer_load_line((slice_buf), \
231 int ff_slice_buffer_init(slice_buffer *buf, int line_count,
232 int max_allocated_lines, int line_width,
233 IDWTELEM *base_buffer);
234 void ff_slice_buffer_release(slice_buffer *buf, int line);
235 void ff_slice_buffer_flush(slice_buffer *buf);
236 void ff_slice_buffer_destroy(slice_buffer *buf);
237 IDWTELEM *ff_slice_buffer_load_line(slice_buffer *buf, int line);
239 void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2,
240 IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5,
242 void ff_snow_horizontal_compose97i(IDWTELEM *b, IDWTELEM *temp, int width);
243 void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride,
244 uint8_t **block, int b_w, int b_h, int src_x,
245 int src_y, int src_stride, slice_buffer *sb,
246 int add, uint8_t *dst8);
248 int ff_w53_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h);
249 int ff_w97_32_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h);
251 void ff_spatial_dwt(int *buffer, int *temp, int width, int height, int stride,
252 int type, int decomposition_count);
254 void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer *sb, int width,
255 int height, int stride_line, int type,
256 int decomposition_count);
257 void ff_spatial_idwt_buffered_slice(DWTContext *dsp, DWTCompose *cs,
258 slice_buffer *slice_buf, IDWTELEM *temp,
259 int width, int height, int stride_line,
260 int type, int decomposition_count, int y);
261 void ff_spatial_idwt(IDWTELEM *buffer, IDWTELEM *temp, int width, int height,
262 int stride, int type, int decomposition_count);
264 void ff_dwt_init(DWTContext *c);
265 void ff_dwt_init_x86(DWTContext *c);
267 #endif /* AVCODEC_DWT_H */