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.

208 lines
7.5KB

  1. /*
  2. * DSP utils
  3. * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * DSP utils.
  25. * Note, many functions in here may use MMX which trashes the FPU state, it is
  26. * absolutely necessary to call emms_c() between DSP & float/double code.
  27. */
  28. #ifndef AVCODEC_DSPUTIL_H
  29. #define AVCODEC_DSPUTIL_H
  30. #include "avcodec.h"
  31. extern uint32_t ff_square_tab[512];
  32. /* minimum alignment rules ;)
  33. * If you notice errors in the align stuff, need more alignment for some ASM code
  34. * for some CPU or need to use a function with less aligned data then send a mail
  35. * to the ffmpeg-devel mailing list, ...
  36. *
  37. * !warning These alignments might not match reality, (missing attribute((align))
  38. * stuff somewhere possible).
  39. * I (Michael) did not check them, these are just the alignments which I think
  40. * could be reached easily ...
  41. *
  42. * !future video codecs might need functions with less strict alignment
  43. */
  44. struct MpegEncContext;
  45. /* Motion estimation:
  46. * h is limited to { width / 2, width, 2 * width },
  47. * but never larger than 16 and never smaller than 2.
  48. * Although currently h < 4 is not used as functions with
  49. * width < 8 are neither used nor implemented. */
  50. typedef int (*me_cmp_func)(struct MpegEncContext *c,
  51. uint8_t *blk1 /* align width (8 or 16) */,
  52. uint8_t *blk2 /* align 1 */, int line_size, int h);
  53. /**
  54. * Scantable.
  55. */
  56. typedef struct ScanTable {
  57. const uint8_t *scantable;
  58. uint8_t permutated[64];
  59. uint8_t raster_end[64];
  60. } ScanTable;
  61. void ff_init_scantable(uint8_t *permutation, ScanTable *st,
  62. const uint8_t *src_scantable);
  63. void ff_init_scantable_permutation(uint8_t *idct_permutation,
  64. int idct_permutation_type);
  65. int ff_init_scantable_permutation_x86(uint8_t *idct_permutation,
  66. int idct_permutation_type);
  67. /**
  68. * DSPContext.
  69. */
  70. typedef struct DSPContext {
  71. /* pixel ops : interface with DCT */
  72. void (*get_pixels)(int16_t *block /* align 16 */,
  73. const uint8_t *pixels /* align 8 */,
  74. int line_size);
  75. void (*diff_pixels)(int16_t *block /* align 16 */,
  76. const uint8_t *s1 /* align 8 */,
  77. const uint8_t *s2 /* align 8 */,
  78. int stride);
  79. void (*put_pixels_clamped)(const int16_t *block /* align 16 */,
  80. uint8_t *pixels /* align 8 */,
  81. int line_size);
  82. void (*put_signed_pixels_clamped)(const int16_t *block /* align 16 */,
  83. uint8_t *pixels /* align 8 */,
  84. int line_size);
  85. void (*add_pixels_clamped)(const int16_t *block /* align 16 */,
  86. uint8_t *pixels /* align 8 */,
  87. int line_size);
  88. int (*sum_abs_dctelem)(int16_t *block /* align 16 */);
  89. int (*pix_sum)(uint8_t *pix, int line_size);
  90. int (*pix_norm1)(uint8_t *pix, int line_size);
  91. me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
  92. me_cmp_func sse[6];
  93. me_cmp_func hadamard8_diff[6];
  94. me_cmp_func dct_sad[6];
  95. me_cmp_func quant_psnr[6];
  96. me_cmp_func bit[6];
  97. me_cmp_func rd[6];
  98. me_cmp_func vsad[6];
  99. me_cmp_func vsse[6];
  100. me_cmp_func nsse[6];
  101. me_cmp_func w53[6];
  102. me_cmp_func w97[6];
  103. me_cmp_func dct_max[6];
  104. me_cmp_func dct264_sad[6];
  105. me_cmp_func me_pre_cmp[6];
  106. me_cmp_func me_cmp[6];
  107. me_cmp_func me_sub_cmp[6];
  108. me_cmp_func mb_cmp[6];
  109. me_cmp_func ildct_cmp[6]; // only width 16 used
  110. me_cmp_func frame_skip_cmp[6]; // only width 8 used
  111. me_cmp_func pix_abs[2][4];
  112. /* (I)DCT */
  113. void (*fdct)(int16_t *block /* align 16 */);
  114. void (*fdct248)(int16_t *block /* align 16 */);
  115. /* IDCT really */
  116. void (*idct)(int16_t *block /* align 16 */);
  117. /**
  118. * block -> idct -> clip to unsigned 8 bit -> dest.
  119. * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
  120. * @param line_size size in bytes of a horizontal line of dest
  121. */
  122. void (*idct_put)(uint8_t *dest /* align 8 */,
  123. int line_size, int16_t *block /* align 16 */);
  124. /**
  125. * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
  126. * @param line_size size in bytes of a horizontal line of dest
  127. */
  128. void (*idct_add)(uint8_t *dest /* align 8 */,
  129. int line_size, int16_t *block /* align 16 */);
  130. /**
  131. * IDCT input permutation.
  132. * Several optimized IDCTs need a permutated input (relative to the
  133. * normal order of the reference IDCT).
  134. * This permutation must be performed before the idct_put/add.
  135. * Note, normally this can be merged with the zigzag/alternate scan<br>
  136. * An example to avoid confusion:
  137. * - (->decode coeffs -> zigzag reorder -> dequant -> reference IDCT -> ...)
  138. * - (x -> reference DCT -> reference IDCT -> x)
  139. * - (x -> reference DCT -> simple_mmx_perm = idct_permutation
  140. * -> simple_idct_mmx -> x)
  141. * - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
  142. * -> simple_idct_mmx -> ...)
  143. */
  144. uint8_t idct_permutation[64];
  145. int idct_permutation_type;
  146. #define FF_NO_IDCT_PERM 1
  147. #define FF_LIBMPEG2_IDCT_PERM 2
  148. #define FF_SIMPLE_IDCT_PERM 3
  149. #define FF_TRANSPOSE_IDCT_PERM 4
  150. #define FF_PARTTRANS_IDCT_PERM 5
  151. #define FF_SSE2_IDCT_PERM 6
  152. int (*try_8x8basis)(int16_t rem[64], int16_t weight[64],
  153. int16_t basis[64], int scale);
  154. void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
  155. #define BASIS_SHIFT 16
  156. #define RECON_SHIFT 6
  157. void (*draw_edges)(uint8_t *buf, int wrap, int width, int height,
  158. int w, int h, int sides);
  159. #define EDGE_WIDTH 16
  160. #define EDGE_TOP 1
  161. #define EDGE_BOTTOM 2
  162. void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src,
  163. int src_wrap, int width, int height);
  164. } DSPContext;
  165. void ff_dsputil_static_init(void);
  166. void ff_dsputil_init(DSPContext *p, AVCodecContext *avctx);
  167. void avpriv_dsputil_init(DSPContext* p, AVCodecContext *avctx);
  168. attribute_deprecated void dsputil_init(DSPContext* c, AVCodecContext *avctx);
  169. int ff_check_alignment(void);
  170. void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type);
  171. void ff_dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
  172. void ff_dsputil_init_arm(DSPContext *c, AVCodecContext *avctx,
  173. unsigned high_bit_depth);
  174. void ff_dsputil_init_ppc(DSPContext *c, AVCodecContext *avctx,
  175. unsigned high_bit_depth);
  176. void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx,
  177. unsigned high_bit_depth);
  178. void ff_dsputil_init_dwt(DSPContext *c);
  179. #endif /* AVCODEC_DSPUTIL_H */