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.

148 lines
4.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 <assert.h>
  19. #include <stdint.h>
  20. #include "config.h"
  21. #include "libavutil/attributes.h"
  22. #include "libavutil/imgutils.h"
  23. #include "avcodec.h"
  24. #include "dsputil.h"
  25. #include "imgconvert.h"
  26. #include "mpegvideoencdsp.h"
  27. static int try_8x8basis_c(int16_t rem[64], int16_t weight[64],
  28. int16_t basis[64], int scale)
  29. {
  30. int i;
  31. unsigned int sum = 0;
  32. for (i = 0; i < 8 * 8; i++) {
  33. int b = rem[i] + ((basis[i] * scale +
  34. (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
  35. (BASIS_SHIFT - RECON_SHIFT));
  36. int w = weight[i];
  37. b >>= RECON_SHIFT;
  38. assert(-512 < b && b < 512);
  39. sum += (w * b) * (w * b) >> 4;
  40. }
  41. return sum >> 2;
  42. }
  43. static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale)
  44. {
  45. int i;
  46. for (i = 0; i < 8 * 8; i++)
  47. rem[i] += (basis[i] * scale +
  48. (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
  49. (BASIS_SHIFT - RECON_SHIFT);
  50. }
  51. static int pix_sum_c(uint8_t *pix, int line_size)
  52. {
  53. int s = 0, i, j;
  54. for (i = 0; i < 16; i++) {
  55. for (j = 0; j < 16; j += 8) {
  56. s += pix[0];
  57. s += pix[1];
  58. s += pix[2];
  59. s += pix[3];
  60. s += pix[4];
  61. s += pix[5];
  62. s += pix[6];
  63. s += pix[7];
  64. pix += 8;
  65. }
  66. pix += line_size - 16;
  67. }
  68. return s;
  69. }
  70. static int pix_norm1_c(uint8_t *pix, int line_size)
  71. {
  72. int s = 0, i, j;
  73. uint32_t *sq = ff_square_tab + 256;
  74. for (i = 0; i < 16; i++) {
  75. for (j = 0; j < 16; j += 8) {
  76. #if 0
  77. s += sq[pix[0]];
  78. s += sq[pix[1]];
  79. s += sq[pix[2]];
  80. s += sq[pix[3]];
  81. s += sq[pix[4]];
  82. s += sq[pix[5]];
  83. s += sq[pix[6]];
  84. s += sq[pix[7]];
  85. #else
  86. #if HAVE_FAST_64BIT
  87. register uint64_t x = *(uint64_t *) pix;
  88. s += sq[x & 0xff];
  89. s += sq[(x >> 8) & 0xff];
  90. s += sq[(x >> 16) & 0xff];
  91. s += sq[(x >> 24) & 0xff];
  92. s += sq[(x >> 32) & 0xff];
  93. s += sq[(x >> 40) & 0xff];
  94. s += sq[(x >> 48) & 0xff];
  95. s += sq[(x >> 56) & 0xff];
  96. #else
  97. register uint32_t x = *(uint32_t *) pix;
  98. s += sq[x & 0xff];
  99. s += sq[(x >> 8) & 0xff];
  100. s += sq[(x >> 16) & 0xff];
  101. s += sq[(x >> 24) & 0xff];
  102. x = *(uint32_t *) (pix + 4);
  103. s += sq[x & 0xff];
  104. s += sq[(x >> 8) & 0xff];
  105. s += sq[(x >> 16) & 0xff];
  106. s += sq[(x >> 24) & 0xff];
  107. #endif
  108. #endif
  109. pix += 8;
  110. }
  111. pix += line_size - 16;
  112. }
  113. return s;
  114. }
  115. av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c,
  116. AVCodecContext *avctx)
  117. {
  118. c->try_8x8basis = try_8x8basis_c;
  119. c->add_8x8basis = add_8x8basis_c;
  120. c->shrink[0] = av_image_copy_plane;
  121. c->shrink[1] = ff_shrink22;
  122. c->shrink[2] = ff_shrink44;
  123. c->shrink[3] = ff_shrink88;
  124. c->pix_sum = pix_sum_c;
  125. c->pix_norm1 = pix_norm1_c;
  126. if (ARCH_ARM)
  127. ff_mpegvideoencdsp_init_arm(c, avctx);
  128. if (ARCH_PPC)
  129. ff_mpegvideoencdsp_init_ppc(c, avctx);
  130. if (ARCH_X86)
  131. ff_mpegvideoencdsp_init_x86(c, avctx);
  132. }