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.

185 lines
6.6KB

  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 Libav.
  7. *
  8. * Libav 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. * Libav 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 Libav; 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. struct MpegEncContext;
  33. /* Motion estimation:
  34. * h is limited to { width / 2, width, 2 * width },
  35. * but never larger than 16 and never smaller than 2.
  36. * Although currently h < 4 is not used as functions with
  37. * width < 8 are neither used nor implemented. */
  38. typedef int (*me_cmp_func)(struct MpegEncContext *c,
  39. uint8_t *blk1 /* align width (8 or 16) */,
  40. uint8_t *blk2 /* align 1 */, int line_size, int h);
  41. /**
  42. * Scantable.
  43. */
  44. typedef struct ScanTable {
  45. const uint8_t *scantable;
  46. uint8_t permutated[64];
  47. uint8_t raster_end[64];
  48. } ScanTable;
  49. void ff_init_scantable(uint8_t *permutation, ScanTable *st,
  50. const uint8_t *src_scantable);
  51. void ff_init_scantable_permutation(uint8_t *idct_permutation,
  52. int idct_permutation_type);
  53. int ff_init_scantable_permutation_x86(uint8_t *idct_permutation,
  54. int idct_permutation_type);
  55. /**
  56. * DSPContext.
  57. */
  58. typedef struct DSPContext {
  59. /* pixel ops : interface with DCT */
  60. void (*get_pixels)(int16_t *block /* align 16 */,
  61. const uint8_t *pixels /* align 8 */,
  62. int line_size);
  63. void (*diff_pixels)(int16_t *block /* align 16 */,
  64. const uint8_t *s1 /* align 8 */,
  65. const uint8_t *s2 /* align 8 */,
  66. int stride);
  67. void (*put_pixels_clamped)(const int16_t *block /* align 16 */,
  68. uint8_t *pixels /* align 8 */,
  69. int line_size);
  70. void (*put_signed_pixels_clamped)(const int16_t *block /* align 16 */,
  71. uint8_t *pixels /* align 8 */,
  72. int line_size);
  73. void (*add_pixels_clamped)(const int16_t *block /* align 16 */,
  74. uint8_t *pixels /* align 8 */,
  75. int line_size);
  76. int (*sum_abs_dctelem)(int16_t *block /* align 16 */);
  77. int (*pix_sum)(uint8_t *pix, int line_size);
  78. int (*pix_norm1)(uint8_t *pix, int line_size);
  79. me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */
  80. me_cmp_func sse[6];
  81. me_cmp_func hadamard8_diff[6];
  82. me_cmp_func dct_sad[6];
  83. me_cmp_func quant_psnr[6];
  84. me_cmp_func bit[6];
  85. me_cmp_func rd[6];
  86. me_cmp_func vsad[6];
  87. me_cmp_func vsse[6];
  88. me_cmp_func nsse[6];
  89. me_cmp_func dct_max[6];
  90. me_cmp_func dct264_sad[6];
  91. me_cmp_func me_pre_cmp[6];
  92. me_cmp_func me_cmp[6];
  93. me_cmp_func me_sub_cmp[6];
  94. me_cmp_func mb_cmp[6];
  95. me_cmp_func ildct_cmp[6]; // only width 16 used
  96. me_cmp_func frame_skip_cmp[6]; // only width 8 used
  97. me_cmp_func pix_abs[2][4];
  98. /* (I)DCT */
  99. void (*fdct)(int16_t *block /* align 16 */);
  100. void (*fdct248)(int16_t *block /* align 16 */);
  101. /* IDCT really */
  102. void (*idct)(int16_t *block /* align 16 */);
  103. /**
  104. * block -> idct -> clip to unsigned 8 bit -> dest.
  105. * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
  106. * @param line_size size in bytes of a horizontal line of dest
  107. */
  108. void (*idct_put)(uint8_t *dest /* align 8 */,
  109. int line_size, int16_t *block /* align 16 */);
  110. /**
  111. * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
  112. * @param line_size size in bytes of a horizontal line of dest
  113. */
  114. void (*idct_add)(uint8_t *dest /* align 8 */,
  115. int line_size, int16_t *block /* align 16 */);
  116. /**
  117. * IDCT input permutation.
  118. * Several optimized IDCTs need a permutated input (relative to the
  119. * normal order of the reference IDCT).
  120. * This permutation must be performed before the idct_put/add.
  121. * Note, normally this can be merged with the zigzag/alternate scan<br>
  122. * An example to avoid confusion:
  123. * - (->decode coeffs -> zigzag reorder -> dequant -> reference IDCT -> ...)
  124. * - (x -> reference DCT -> reference IDCT -> x)
  125. * - (x -> reference DCT -> simple_mmx_perm = idct_permutation
  126. * -> simple_idct_mmx -> x)
  127. * - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
  128. * -> simple_idct_mmx -> ...)
  129. */
  130. uint8_t idct_permutation[64];
  131. int idct_permutation_type;
  132. #define FF_NO_IDCT_PERM 1
  133. #define FF_LIBMPEG2_IDCT_PERM 2
  134. #define FF_SIMPLE_IDCT_PERM 3
  135. #define FF_TRANSPOSE_IDCT_PERM 4
  136. #define FF_PARTTRANS_IDCT_PERM 5
  137. #define FF_SSE2_IDCT_PERM 6
  138. int (*try_8x8basis)(int16_t rem[64], int16_t weight[64],
  139. int16_t basis[64], int scale);
  140. void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale);
  141. #define BASIS_SHIFT 16
  142. #define RECON_SHIFT 6
  143. void (*draw_edges)(uint8_t *buf, int wrap, int width, int height,
  144. int w, int h, int sides);
  145. #define EDGE_WIDTH 16
  146. #define EDGE_TOP 1
  147. #define EDGE_BOTTOM 2
  148. void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src,
  149. int src_wrap, int width, int height);
  150. } DSPContext;
  151. void ff_dsputil_static_init(void);
  152. void ff_dsputil_init(DSPContext *p, AVCodecContext *avctx);
  153. void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type);
  154. void ff_dsputil_init_arm(DSPContext *c, AVCodecContext *avctx,
  155. unsigned high_bit_depth);
  156. void ff_dsputil_init_ppc(DSPContext *c, AVCodecContext *avctx,
  157. unsigned high_bit_depth);
  158. void ff_dsputil_init_x86(DSPContext *c, AVCodecContext *avctx,
  159. unsigned high_bit_depth);
  160. #endif /* AVCODEC_DSPUTIL_H */