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.

179 lines
5.0KB

  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 <string.h>
  21. #include "config.h"
  22. #include "libavutil/attributes.h"
  23. #include "libavutil/imgutils.h"
  24. #include "avcodec.h"
  25. #include "imgconvert.h"
  26. #include "me_cmp.h"
  27. #include "mpegvideoencdsp.h"
  28. static int try_8x8basis_c(int16_t rem[64], int16_t weight[64],
  29. int16_t basis[64], int scale)
  30. {
  31. int i;
  32. unsigned int sum = 0;
  33. for (i = 0; i < 8 * 8; i++) {
  34. int b = rem[i] + ((basis[i] * scale +
  35. (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
  36. (BASIS_SHIFT - RECON_SHIFT));
  37. int w = weight[i];
  38. b >>= RECON_SHIFT;
  39. assert(-512 < b && b < 512);
  40. sum += (w * b) * (w * b) >> 4;
  41. }
  42. return sum >> 2;
  43. }
  44. static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale)
  45. {
  46. int i;
  47. for (i = 0; i < 8 * 8; i++)
  48. rem[i] += (basis[i] * scale +
  49. (1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
  50. (BASIS_SHIFT - RECON_SHIFT);
  51. }
  52. static int pix_sum_c(uint8_t *pix, int line_size)
  53. {
  54. int s = 0, i, j;
  55. for (i = 0; i < 16; i++) {
  56. for (j = 0; j < 16; j += 8) {
  57. s += pix[0];
  58. s += pix[1];
  59. s += pix[2];
  60. s += pix[3];
  61. s += pix[4];
  62. s += pix[5];
  63. s += pix[6];
  64. s += pix[7];
  65. pix += 8;
  66. }
  67. pix += line_size - 16;
  68. }
  69. return s;
  70. }
  71. static int pix_norm1_c(uint8_t *pix, int line_size)
  72. {
  73. int s = 0, i, j;
  74. uint32_t *sq = ff_square_tab + 256;
  75. for (i = 0; i < 16; i++) {
  76. for (j = 0; j < 16; j += 8) {
  77. #if 0
  78. s += sq[pix[0]];
  79. s += sq[pix[1]];
  80. s += sq[pix[2]];
  81. s += sq[pix[3]];
  82. s += sq[pix[4]];
  83. s += sq[pix[5]];
  84. s += sq[pix[6]];
  85. s += sq[pix[7]];
  86. #else
  87. #if HAVE_FAST_64BIT
  88. register uint64_t x = *(uint64_t *) pix;
  89. s += sq[x & 0xff];
  90. s += sq[(x >> 8) & 0xff];
  91. s += sq[(x >> 16) & 0xff];
  92. s += sq[(x >> 24) & 0xff];
  93. s += sq[(x >> 32) & 0xff];
  94. s += sq[(x >> 40) & 0xff];
  95. s += sq[(x >> 48) & 0xff];
  96. s += sq[(x >> 56) & 0xff];
  97. #else
  98. register uint32_t x = *(uint32_t *) pix;
  99. s += sq[x & 0xff];
  100. s += sq[(x >> 8) & 0xff];
  101. s += sq[(x >> 16) & 0xff];
  102. s += sq[(x >> 24) & 0xff];
  103. x = *(uint32_t *) (pix + 4);
  104. s += sq[x & 0xff];
  105. s += sq[(x >> 8) & 0xff];
  106. s += sq[(x >> 16) & 0xff];
  107. s += sq[(x >> 24) & 0xff];
  108. #endif
  109. #endif
  110. pix += 8;
  111. }
  112. pix += line_size - 16;
  113. }
  114. return s;
  115. }
  116. /* draw the edges of width 'w' of an image of size width, height */
  117. // FIXME: Check that this is OK for MPEG-4 interlaced.
  118. static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height,
  119. int w, int h, int sides)
  120. {
  121. uint8_t *ptr = buf, *last_line;
  122. int i;
  123. /* left and right */
  124. for (i = 0; i < height; i++) {
  125. memset(ptr - w, ptr[0], w);
  126. memset(ptr + width, ptr[width - 1], w);
  127. ptr += wrap;
  128. }
  129. /* top and bottom + corners */
  130. buf -= w;
  131. last_line = buf + (height - 1) * wrap;
  132. if (sides & EDGE_TOP)
  133. for (i = 0; i < h; i++)
  134. // top
  135. memcpy(buf - (i + 1) * wrap, buf, width + w + w);
  136. if (sides & EDGE_BOTTOM)
  137. for (i = 0; i < h; i++)
  138. // bottom
  139. memcpy(last_line + (i + 1) * wrap, last_line, width + w + w);
  140. }
  141. av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c,
  142. AVCodecContext *avctx)
  143. {
  144. c->try_8x8basis = try_8x8basis_c;
  145. c->add_8x8basis = add_8x8basis_c;
  146. c->shrink[0] = av_image_copy_plane;
  147. c->shrink[1] = ff_shrink22;
  148. c->shrink[2] = ff_shrink44;
  149. c->shrink[3] = ff_shrink88;
  150. c->pix_sum = pix_sum_c;
  151. c->pix_norm1 = pix_norm1_c;
  152. c->draw_edges = draw_edges_8_c;
  153. if (ARCH_ARM)
  154. ff_mpegvideoencdsp_init_arm(c, avctx);
  155. if (ARCH_PPC)
  156. ff_mpegvideoencdsp_init_ppc(c, avctx);
  157. if (ARCH_X86)
  158. ff_mpegvideoencdsp_init_x86(c, avctx);
  159. }