You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
7.3KB

  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. #ifndef AVCODEC_DWT_H
  21. #define AVCODEC_DWT_H
  22. #include <stdint.h>
  23. typedef int DWTELEM;
  24. typedef short IDWTELEM;
  25. #define MAX_DWT_SUPPORT 8
  26. #define MAX_DECOMPOSITIONS 8
  27. typedef struct {
  28. IDWTELEM *b[MAX_DWT_SUPPORT];
  29. IDWTELEM *b0;
  30. IDWTELEM *b1;
  31. IDWTELEM *b2;
  32. IDWTELEM *b3;
  33. int y;
  34. } DWTCompose;
  35. /** Used to minimize the amount of memory used in order to optimize cache performance. **/
  36. typedef struct slice_buffer_s {
  37. IDWTELEM * * line; ///< For use by idwt and predict_slices.
  38. IDWTELEM * * data_stack; ///< Used for internal purposes.
  39. int data_stack_top;
  40. int line_count;
  41. int line_width;
  42. int data_count;
  43. IDWTELEM * base_buffer; ///< Buffer that this structure is caching.
  44. } slice_buffer;
  45. struct DWTContext;
  46. // Possible prototypes for vertical_compose functions
  47. typedef void (*vertical_compose_2tap)(IDWTELEM *b0, IDWTELEM *b1, int width);
  48. typedef void (*vertical_compose_3tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width);
  49. typedef void (*vertical_compose_5tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, int width);
  50. typedef void (*vertical_compose_9tap)(IDWTELEM *dst, IDWTELEM *b[8], int width);
  51. typedef struct DWTContext {
  52. IDWTELEM *buffer;
  53. IDWTELEM *temp;
  54. int width;
  55. int height;
  56. int stride;
  57. int decomposition_count;
  58. int support;
  59. void (*spatial_compose)(struct DWTContext *cs, int level, int width, int height, int stride);
  60. void (*vertical_compose_l0)(void);
  61. void (*vertical_compose_h0)(void);
  62. void (*vertical_compose_l1)(void);
  63. void (*vertical_compose_h1)(void);
  64. void (*vertical_compose)(void); ///< one set of lowpass and highpass combined
  65. void (*horizontal_compose)(IDWTELEM *b, IDWTELEM *tmp, int width);
  66. void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width);
  67. void (*horizontal_compose97i)(IDWTELEM *b, int width);
  68. 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);
  69. DWTCompose cs[MAX_DECOMPOSITIONS];
  70. } DWTContext;
  71. enum dwt_type {
  72. DWT_SNOW_DAUB9_7,
  73. DWT_SNOW_LEGALL5_3,
  74. DWT_DIRAC_DD9_7,
  75. DWT_DIRAC_LEGALL5_3,
  76. DWT_DIRAC_DD13_7,
  77. DWT_DIRAC_HAAR0,
  78. DWT_DIRAC_HAAR1,
  79. DWT_DIRAC_FIDELITY,
  80. DWT_DIRAC_DAUB9_7,
  81. DWT_NUM_TYPES
  82. };
  83. // -1 if an error occurred, e.g. the dwt_type isn't recognized
  84. int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height,
  85. int stride, enum dwt_type type, int decomposition_count,
  86. IDWTELEM *temp);
  87. int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride,
  88. enum dwt_type type, int decomposition_count, IDWTELEM *temp);
  89. void ff_spatial_idwt_slice2(DWTContext *d, int y);
  90. // shared stuff for simd optimiztions
  91. #define COMPOSE_53iL0(b0, b1, b2)\
  92. (b1 - ((b0 + b2 + 2) >> 2))
  93. #define COMPOSE_DIRAC53iH0(b0, b1, b2)\
  94. (b1 + ((b0 + b2 + 1) >> 1))
  95. #define COMPOSE_DD97iH0(b0, b1, b2, b3, b4)\
  96. (b2 + ((-b0 + 9*b1 + 9*b3 - b4 + 8) >> 4))
  97. #define COMPOSE_DD137iL0(b0, b1, b2, b3, b4)\
  98. (b2 - ((-b0 + 9*b1 + 9*b3 - b4 + 16) >> 5))
  99. #define COMPOSE_HAARiL0(b0, b1)\
  100. (b0 - ((b1 + 1) >> 1))
  101. #define COMPOSE_HAARiH0(b0, b1)\
  102. (b0 + b1)
  103. #define COMPOSE_FIDELITYiL0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\
  104. (b4 - ((-8*(b0+b8) + 21*(b1+b7) - 46*(b2+b6) + 161*(b3+b5) + 128) >> 8))
  105. #define COMPOSE_FIDELITYiH0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\
  106. (b4 + ((-2*(b0+b8) + 10*(b1+b7) - 25*(b2+b6) + 81*(b3+b5) + 128) >> 8))
  107. #define COMPOSE_DAUB97iL1(b0, b1, b2)\
  108. (b1 - ((1817*(b0 + b2) + 2048) >> 12))
  109. #define COMPOSE_DAUB97iH1(b0, b1, b2)\
  110. (b1 - (( 113*(b0 + b2) + 64) >> 7))
  111. #define COMPOSE_DAUB97iL0(b0, b1, b2)\
  112. (b1 + (( 217*(b0 + b2) + 2048) >> 12))
  113. #define COMPOSE_DAUB97iH0(b0, b1, b2)\
  114. (b1 + ((6497*(b0 + b2) + 2048) >> 12))
  115. #define DWT_97 0
  116. #define DWT_53 1
  117. #define liftS lift
  118. #if 1
  119. #define W_AM 3
  120. #define W_AO 0
  121. #define W_AS 1
  122. #undef liftS
  123. #define W_BM 1
  124. #define W_BO 8
  125. #define W_BS 4
  126. #define W_CM 1
  127. #define W_CO 0
  128. #define W_CS 0
  129. #define W_DM 3
  130. #define W_DO 4
  131. #define W_DS 3
  132. #elif 0
  133. #define W_AM 55
  134. #define W_AO 16
  135. #define W_AS 5
  136. #define W_BM 3
  137. #define W_BO 32
  138. #define W_BS 6
  139. #define W_CM 127
  140. #define W_CO 64
  141. #define W_CS 7
  142. #define W_DM 7
  143. #define W_DO 8
  144. #define W_DS 4
  145. #elif 0
  146. #define W_AM 97
  147. #define W_AO 32
  148. #define W_AS 6
  149. #define W_BM 63
  150. #define W_BO 512
  151. #define W_BS 10
  152. #define W_CM 13
  153. #define W_CO 8
  154. #define W_CS 4
  155. #define W_DM 15
  156. #define W_DO 16
  157. #define W_DS 5
  158. #else
  159. #define W_AM 203
  160. #define W_AO 64
  161. #define W_AS 7
  162. #define W_BM 217
  163. #define W_BO 2048
  164. #define W_BS 12
  165. #define W_CM 113
  166. #define W_CO 64
  167. #define W_CS 7
  168. #define W_DM 227
  169. #define W_DO 128
  170. #define W_DS 9
  171. #endif
  172. #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)))
  173. //#define slice_buffer_get_line(slice_buf, line_num) (ff_slice_buffer_load_line((slice_buf), (line_num)))
  174. void ff_slice_buffer_init(slice_buffer * buf, int line_count, int max_allocated_lines, int line_width, IDWTELEM * base_buffer);
  175. void ff_slice_buffer_release(slice_buffer * buf, int line);
  176. void ff_slice_buffer_flush(slice_buffer * buf);
  177. void ff_slice_buffer_destroy(slice_buffer * buf);
  178. IDWTELEM * ff_slice_buffer_load_line(slice_buffer * buf, int line);
  179. void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width);
  180. void ff_snow_horizontal_compose97i(IDWTELEM *b, int width);
  181. 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);
  182. int ff_w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h);
  183. int ff_w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h);
  184. void ff_spatial_dwt(int *buffer, int width, int height, int stride, int type, int decomposition_count);
  185. void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line, int type, int decomposition_count);
  186. 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);
  187. void ff_spatial_idwt(IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count);
  188. void ff_dwt_init(DWTContext *c);
  189. void ff_dwt_init_x86(DWTContext *c);
  190. #endif /* AVCODEC_DWT_H */