libavcodec/dwt.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at>
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #ifndef AVCODEC_DWT_H
00022 #define AVCODEC_DWT_H
00023 
00024 #include <stdint.h>
00025 
00026 typedef int DWTELEM;
00027 typedef short IDWTELEM;
00028 
00029 #define MAX_DWT_SUPPORT 8
00030 #define MAX_DECOMPOSITIONS 8
00031 
00032 typedef struct {
00033     IDWTELEM *b[MAX_DWT_SUPPORT];
00034 
00035     IDWTELEM *b0;
00036     IDWTELEM *b1;
00037     IDWTELEM *b2;
00038     IDWTELEM *b3;
00039     int y;
00040 } DWTCompose;
00041 
00043 typedef struct slice_buffer_s {
00044     IDWTELEM * * line; 
00045     IDWTELEM * * data_stack; 
00046     int data_stack_top;
00047     int line_count;
00048     int line_width;
00049     int data_count;
00050     IDWTELEM * base_buffer; 
00051 } slice_buffer;
00052 
00053 struct DWTContext;
00054 
00055 // Possible prototypes for vertical_compose functions
00056 typedef void (*vertical_compose_2tap)(IDWTELEM *b0, IDWTELEM *b1, int width);
00057 typedef void (*vertical_compose_3tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width);
00058 typedef void (*vertical_compose_5tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, int width);
00059 typedef void (*vertical_compose_9tap)(IDWTELEM *dst, IDWTELEM *b[8], int width);
00060 
00061 typedef struct DWTContext {
00062     IDWTELEM *buffer;
00063     IDWTELEM *temp;
00064     int width;
00065     int height;
00066     int stride;
00067     int decomposition_count;
00068     int support;
00069 
00070     void (*spatial_compose)(struct DWTContext *cs, int level, int width, int height, int stride);
00071     void (*vertical_compose_l0)(void);
00072     void (*vertical_compose_h0)(void);
00073     void (*vertical_compose_l1)(void);
00074     void (*vertical_compose_h1)(void);
00075     void (*vertical_compose)(void);     
00076     void (*horizontal_compose)(IDWTELEM *b, IDWTELEM *tmp, int width);
00077 
00078     void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width);
00079     void (*horizontal_compose97i)(IDWTELEM *b, int width);
00080     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);
00081 
00082     DWTCompose cs[MAX_DECOMPOSITIONS];
00083 } DWTContext;
00084 
00085 enum dwt_type {
00086     DWT_SNOW_DAUB9_7,
00087     DWT_SNOW_LEGALL5_3,
00088     DWT_DIRAC_DD9_7,
00089     DWT_DIRAC_LEGALL5_3,
00090     DWT_DIRAC_DD13_7,
00091     DWT_DIRAC_HAAR0,
00092     DWT_DIRAC_HAAR1,
00093     DWT_DIRAC_FIDELITY,
00094     DWT_DIRAC_DAUB9_7,
00095     DWT_NUM_TYPES
00096 };
00097 
00098 // -1 if an error occurred, e.g. the dwt_type isn't recognized
00099 int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height,
00100                           int stride, enum dwt_type type, int decomposition_count,
00101                           IDWTELEM *temp);
00102 
00103 int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride,
00104                      enum dwt_type type, int decomposition_count, IDWTELEM *temp);
00105 
00106 void ff_spatial_idwt_slice2(DWTContext *d, int y);
00107 
00108 // shared stuff for simd optimiztions
00109 #define COMPOSE_53iL0(b0, b1, b2)\
00110     (b1 - ((b0 + b2 + 2) >> 2))
00111 
00112 #define COMPOSE_DIRAC53iH0(b0, b1, b2)\
00113     (b1 + ((b0 + b2 + 1) >> 1))
00114 
00115 #define COMPOSE_DD97iH0(b0, b1, b2, b3, b4)\
00116     (b2 + ((-b0 + 9*b1 + 9*b3 - b4 + 8) >> 4))
00117 
00118 #define COMPOSE_DD137iL0(b0, b1, b2, b3, b4)\
00119     (b2 - ((-b0 + 9*b1 + 9*b3 - b4 + 16) >> 5))
00120 
00121 #define COMPOSE_HAARiL0(b0, b1)\
00122     (b0 - ((b1 + 1) >> 1))
00123 
00124 #define COMPOSE_HAARiH0(b0, b1)\
00125     (b0 + b1)
00126 
00127 #define COMPOSE_FIDELITYiL0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\
00128     (b4 - ((-8*(b0+b8) + 21*(b1+b7) - 46*(b2+b6) + 161*(b3+b5) + 128) >> 8))
00129 
00130 #define COMPOSE_FIDELITYiH0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\
00131     (b4 + ((-2*(b0+b8) + 10*(b1+b7) - 25*(b2+b6) + 81*(b3+b5) + 128) >> 8))
00132 
00133 #define COMPOSE_DAUB97iL1(b0, b1, b2)\
00134     (b1 - ((1817*(b0 + b2) + 2048) >> 12))
00135 
00136 #define COMPOSE_DAUB97iH1(b0, b1, b2)\
00137     (b1 - (( 113*(b0 + b2) + 64) >> 7))
00138 
00139 #define COMPOSE_DAUB97iL0(b0, b1, b2)\
00140     (b1 + (( 217*(b0 + b2) + 2048) >> 12))
00141 
00142 #define COMPOSE_DAUB97iH0(b0, b1, b2)\
00143     (b1 + ((6497*(b0 + b2) + 2048) >> 12))
00144 
00145 
00146 
00147 #define DWT_97 0
00148 #define DWT_53 1
00149 
00150 #define liftS lift
00151 #if 1
00152 #define W_AM 3
00153 #define W_AO 0
00154 #define W_AS 1
00155 
00156 #undef liftS
00157 #define W_BM 1
00158 #define W_BO 8
00159 #define W_BS 4
00160 
00161 #define W_CM 1
00162 #define W_CO 0
00163 #define W_CS 0
00164 
00165 #define W_DM 3
00166 #define W_DO 4
00167 #define W_DS 3
00168 #elif 0
00169 #define W_AM 55
00170 #define W_AO 16
00171 #define W_AS 5
00172 
00173 #define W_BM 3
00174 #define W_BO 32
00175 #define W_BS 6
00176 
00177 #define W_CM 127
00178 #define W_CO 64
00179 #define W_CS 7
00180 
00181 #define W_DM 7
00182 #define W_DO 8
00183 #define W_DS 4
00184 #elif 0
00185 #define W_AM 97
00186 #define W_AO 32
00187 #define W_AS 6
00188 
00189 #define W_BM 63
00190 #define W_BO 512
00191 #define W_BS 10
00192 
00193 #define W_CM 13
00194 #define W_CO 8
00195 #define W_CS 4
00196 
00197 #define W_DM 15
00198 #define W_DO 16
00199 #define W_DS 5
00200 
00201 #else
00202 
00203 #define W_AM 203
00204 #define W_AO 64
00205 #define W_AS 7
00206 
00207 #define W_BM 217
00208 #define W_BO 2048
00209 #define W_BS 12
00210 
00211 #define W_CM 113
00212 #define W_CO 64
00213 #define W_CS 7
00214 
00215 #define W_DM 227
00216 #define W_DO 128
00217 #define W_DS 9
00218 #endif
00219 
00220 #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)))
00221 //#define slice_buffer_get_line(slice_buf, line_num) (ff_slice_buffer_load_line((slice_buf), (line_num)))
00222 
00223 void ff_slice_buffer_init(slice_buffer * buf, int line_count, int max_allocated_lines, int line_width, IDWTELEM * base_buffer);
00224 void ff_slice_buffer_release(slice_buffer * buf, int line);
00225 void ff_slice_buffer_flush(slice_buffer * buf);
00226 void ff_slice_buffer_destroy(slice_buffer * buf);
00227 IDWTELEM * ff_slice_buffer_load_line(slice_buffer * buf, int line);
00228 
00229 void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width);
00230 void ff_snow_horizontal_compose97i(IDWTELEM *b, int width);
00231 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);
00232 
00233 int ff_w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h);
00234 int ff_w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h);
00235 
00236 void ff_spatial_dwt(int *buffer, int width, int height, int stride, int type, int decomposition_count);
00237 
00238 void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line, int type, int decomposition_count);
00239 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);
00240 void ff_spatial_idwt(IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count);
00241 
00242 void ff_dwt_init(DWTContext *c);
00243 void ff_dwt_init_x86(DWTContext *c);
00244 
00245 #endif /* AVCODEC_DWT_H */