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.

192 lines
6.1KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #include "libavutil/attributes.h"
  20. #include "libavutil/common.h"
  21. #include "avcodec.h"
  22. #include "dct.h"
  23. #include "faanidct.h"
  24. #include "idctdsp.h"
  25. #include "simple_idct.h"
  26. av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st,
  27. const uint8_t *src_scantable)
  28. {
  29. int i, end;
  30. st->scantable = src_scantable;
  31. for (i = 0; i < 64; i++) {
  32. int j = src_scantable[i];
  33. st->permutated[i] = permutation[j];
  34. }
  35. end = -1;
  36. for (i = 0; i < 64; i++) {
  37. int j = st->permutated[i];
  38. if (j > end)
  39. end = j;
  40. st->raster_end[i] = end;
  41. }
  42. }
  43. av_cold void ff_init_scantable_permutation(uint8_t *idct_permutation,
  44. enum idct_permutation_type perm_type)
  45. {
  46. int i;
  47. if (ARCH_X86)
  48. if (ff_init_scantable_permutation_x86(idct_permutation,
  49. perm_type))
  50. return;
  51. switch (perm_type) {
  52. case FF_IDCT_PERM_NONE:
  53. for (i = 0; i < 64; i++)
  54. idct_permutation[i] = i;
  55. break;
  56. case FF_IDCT_PERM_LIBMPEG2:
  57. for (i = 0; i < 64; i++)
  58. idct_permutation[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
  59. break;
  60. case FF_IDCT_PERM_TRANSPOSE:
  61. for (i = 0; i < 64; i++)
  62. idct_permutation[i] = ((i & 7) << 3) | (i >> 3);
  63. break;
  64. case FF_IDCT_PERM_PARTTRANS:
  65. for (i = 0; i < 64; i++)
  66. idct_permutation[i] = (i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3);
  67. break;
  68. default:
  69. av_log(NULL, AV_LOG_ERROR,
  70. "Internal error, IDCT permutation not set\n");
  71. }
  72. }
  73. void (*ff_put_pixels_clamped)(const int16_t *block, uint8_t *pixels, ptrdiff_t line_size);
  74. void (*ff_add_pixels_clamped)(const int16_t *block, uint8_t *pixels, ptrdiff_t line_size);
  75. static void put_pixels_clamped_c(const int16_t *block, uint8_t *restrict pixels,
  76. ptrdiff_t line_size)
  77. {
  78. int i;
  79. /* read the pixels */
  80. for (i = 0; i < 8; i++) {
  81. pixels[0] = av_clip_uint8(block[0]);
  82. pixels[1] = av_clip_uint8(block[1]);
  83. pixels[2] = av_clip_uint8(block[2]);
  84. pixels[3] = av_clip_uint8(block[3]);
  85. pixels[4] = av_clip_uint8(block[4]);
  86. pixels[5] = av_clip_uint8(block[5]);
  87. pixels[6] = av_clip_uint8(block[6]);
  88. pixels[7] = av_clip_uint8(block[7]);
  89. pixels += line_size;
  90. block += 8;
  91. }
  92. }
  93. static void put_signed_pixels_clamped_c(const int16_t *block,
  94. uint8_t *restrict pixels,
  95. ptrdiff_t line_size)
  96. {
  97. int i, j;
  98. for (i = 0; i < 8; i++) {
  99. for (j = 0; j < 8; j++) {
  100. if (*block < -128)
  101. *pixels = 0;
  102. else if (*block > 127)
  103. *pixels = 255;
  104. else
  105. *pixels = (uint8_t) (*block + 128);
  106. block++;
  107. pixels++;
  108. }
  109. pixels += (line_size - 8);
  110. }
  111. }
  112. static void add_pixels_clamped_c(const int16_t *block, uint8_t *restrict pixels,
  113. ptrdiff_t line_size)
  114. {
  115. int i;
  116. /* read the pixels */
  117. for (i = 0; i < 8; i++) {
  118. pixels[0] = av_clip_uint8(pixels[0] + block[0]);
  119. pixels[1] = av_clip_uint8(pixels[1] + block[1]);
  120. pixels[2] = av_clip_uint8(pixels[2] + block[2]);
  121. pixels[3] = av_clip_uint8(pixels[3] + block[3]);
  122. pixels[4] = av_clip_uint8(pixels[4] + block[4]);
  123. pixels[5] = av_clip_uint8(pixels[5] + block[5]);
  124. pixels[6] = av_clip_uint8(pixels[6] + block[6]);
  125. pixels[7] = av_clip_uint8(pixels[7] + block[7]);
  126. pixels += line_size;
  127. block += 8;
  128. }
  129. }
  130. av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
  131. {
  132. const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8;
  133. if (avctx->bits_per_raw_sample == 10) {
  134. c->idct_put = ff_simple_idct_put_10;
  135. c->idct_add = ff_simple_idct_add_10;
  136. c->idct = ff_simple_idct_10;
  137. c->perm_type = FF_IDCT_PERM_NONE;
  138. } else if (avctx->idct_algo == FF_IDCT_INT) {
  139. c->idct_put = ff_jref_idct_put;
  140. c->idct_add = ff_jref_idct_add;
  141. c->idct = ff_j_rev_dct;
  142. c->perm_type = FF_IDCT_PERM_LIBMPEG2;
  143. #if CONFIG_FAANIDCT
  144. } else if (avctx->idct_algo == FF_IDCT_FAAN) {
  145. c->idct_put = ff_faanidct_put;
  146. c->idct_add = ff_faanidct_add;
  147. c->idct = ff_faanidct;
  148. c->perm_type = FF_IDCT_PERM_NONE;
  149. #endif /* CONFIG_FAANIDCT */
  150. } else { // accurate/default
  151. c->idct_put = ff_simple_idct_put_8;
  152. c->idct_add = ff_simple_idct_add_8;
  153. c->idct = ff_simple_idct_8;
  154. c->perm_type = FF_IDCT_PERM_NONE;
  155. }
  156. c->put_pixels_clamped = put_pixels_clamped_c;
  157. c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
  158. c->add_pixels_clamped = add_pixels_clamped_c;
  159. ff_put_pixels_clamped = c->put_pixels_clamped;
  160. ff_add_pixels_clamped = c->add_pixels_clamped;
  161. if (ARCH_ARM)
  162. ff_idctdsp_init_arm(c, avctx, high_bit_depth);
  163. if (ARCH_PPC)
  164. ff_idctdsp_init_ppc(c, avctx, high_bit_depth);
  165. if (ARCH_X86)
  166. ff_idctdsp_init_x86(c, avctx, high_bit_depth);
  167. ff_init_scantable_permutation(c->idct_permutation,
  168. c->perm_type);
  169. }