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.

268 lines
8.0KB

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