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.

133 lines
4.3KB

  1. /*
  2. * aligned/packed access motion
  3. *
  4. * Copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
  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. #include <assert.h>
  23. #include <stdint.h>
  24. #include "libavutil/attributes.h"
  25. #include "libavcodec/h264chroma.h"
  26. #define H264_CHROMA_MC(OPNAME, OP)\
  27. static void OPNAME ## h264_chroma_mc2_sh4(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
  28. const int A=(8-x)*(8-y);\
  29. const int B=( x)*(8-y);\
  30. const int C=(8-x)*( y);\
  31. const int D=( x)*( y);\
  32. \
  33. assert(x<8 && y<8 && x>=0 && y>=0);\
  34. \
  35. do {\
  36. int t0,t1,t2,t3; \
  37. uint8_t *s0 = src; \
  38. uint8_t *s1 = src+stride; \
  39. t0 = *s0++; t2 = *s1++; \
  40. t1 = *s0++; t3 = *s1++; \
  41. OP(dst[0], (A*t0 + B*t1 + C*t2 + D*t3));\
  42. t0 = *s0++; t2 = *s1++; \
  43. OP(dst[1], (A*t1 + B*t0 + C*t3 + D*t2));\
  44. dst+= stride;\
  45. src+= stride;\
  46. }while(--h);\
  47. }\
  48. \
  49. static void OPNAME ## h264_chroma_mc4_sh4(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
  50. const int A=(8-x)*(8-y);\
  51. const int B=( x)*(8-y);\
  52. const int C=(8-x)*( y);\
  53. const int D=( x)*( y);\
  54. \
  55. assert(x<8 && y<8 && x>=0 && y>=0);\
  56. \
  57. do {\
  58. int t0,t1,t2,t3; \
  59. uint8_t *s0 = src; \
  60. uint8_t *s1 = src+stride; \
  61. t0 = *s0++; t2 = *s1++; \
  62. t1 = *s0++; t3 = *s1++; \
  63. OP(dst[0], (A*t0 + B*t1 + C*t2 + D*t3));\
  64. t0 = *s0++; t2 = *s1++; \
  65. OP(dst[1], (A*t1 + B*t0 + C*t3 + D*t2));\
  66. t1 = *s0++; t3 = *s1++; \
  67. OP(dst[2], (A*t0 + B*t1 + C*t2 + D*t3));\
  68. t0 = *s0++; t2 = *s1++; \
  69. OP(dst[3], (A*t1 + B*t0 + C*t3 + D*t2));\
  70. dst+= stride;\
  71. src+= stride;\
  72. }while(--h);\
  73. }\
  74. \
  75. static void OPNAME ## h264_chroma_mc8_sh4(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
  76. const int A=(8-x)*(8-y);\
  77. const int B=( x)*(8-y);\
  78. const int C=(8-x)*( y);\
  79. const int D=( x)*( y);\
  80. \
  81. assert(x<8 && y<8 && x>=0 && y>=0);\
  82. \
  83. do {\
  84. int t0,t1,t2,t3; \
  85. uint8_t *s0 = src; \
  86. uint8_t *s1 = src+stride; \
  87. t0 = *s0++; t2 = *s1++; \
  88. t1 = *s0++; t3 = *s1++; \
  89. OP(dst[0], (A*t0 + B*t1 + C*t2 + D*t3));\
  90. t0 = *s0++; t2 = *s1++; \
  91. OP(dst[1], (A*t1 + B*t0 + C*t3 + D*t2));\
  92. t1 = *s0++; t3 = *s1++; \
  93. OP(dst[2], (A*t0 + B*t1 + C*t2 + D*t3));\
  94. t0 = *s0++; t2 = *s1++; \
  95. OP(dst[3], (A*t1 + B*t0 + C*t3 + D*t2));\
  96. t1 = *s0++; t3 = *s1++; \
  97. OP(dst[4], (A*t0 + B*t1 + C*t2 + D*t3));\
  98. t0 = *s0++; t2 = *s1++; \
  99. OP(dst[5], (A*t1 + B*t0 + C*t3 + D*t2));\
  100. t1 = *s0++; t3 = *s1++; \
  101. OP(dst[6], (A*t0 + B*t1 + C*t2 + D*t3));\
  102. t0 = *s0++; t2 = *s1++; \
  103. OP(dst[7], (A*t1 + B*t0 + C*t3 + D*t2));\
  104. dst+= stride;\
  105. src+= stride;\
  106. }while(--h);\
  107. }
  108. #define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
  109. #define op_put(a, b) a = (((b) + 32)>>6)
  110. H264_CHROMA_MC(put_ , op_put)
  111. H264_CHROMA_MC(avg_ , op_avg)
  112. #undef op_avg
  113. #undef op_put
  114. av_cold void ff_h264chroma_init_sh4(H264ChromaContext *c, int bit_depth)
  115. {
  116. const int high_bit_depth = bit_depth > 8;
  117. if (!high_bit_depth) {
  118. c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_sh4;
  119. c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_sh4;
  120. c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_sh4;
  121. c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_sh4;
  122. c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_sh4;
  123. c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_sh4;
  124. }
  125. }