yuv2rgb_template.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * software YUV to RGB converter
  3. *
  4. * Copyright (C) 2001-2007 Michael Niedermayer
  5. * (c) 2010 Konstantin Shishkov
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include <stdint.h>
  24. #include "libavutil/x86/asm.h"
  25. #include "libswscale/swscale_internal.h"
  26. #define YUV2RGB_LOOP(depth) \
  27. h_size = (c->dstW + 7) & ~7; \
  28. if (h_size * depth > FFABS(dstStride[0])) \
  29. h_size -= 8; \
  30. \
  31. vshift = c->srcFormat != AV_PIX_FMT_YUV422P; \
  32. \
  33. for (y = 0; y < srcSliceH; y++) { \
  34. uint8_t *image = dst[0] + (y + srcSliceY) * dstStride[0]; \
  35. const uint8_t *py = src[0] + y * srcStride[0]; \
  36. const uint8_t *pu = src[1] + (y >> vshift) * srcStride[1]; \
  37. const uint8_t *pv = src[2] + (y >> vshift) * srcStride[2]; \
  38. x86_reg index = -h_size / 2; \
  39. extern void RENAME(ff_yuv_420_rgb24)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  40. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  41. const uint8_t *py_2index);
  42. extern void RENAME(ff_yuv_420_bgr24)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  43. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  44. const uint8_t *py_2index);
  45. #ifndef COMPILE_TEMPLATE_MMXEXT
  46. extern void RENAME(ff_yuv_420_rgb15)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  47. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  48. const uint8_t *py_2index);
  49. extern void RENAME(ff_yuv_420_rgb16)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  50. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  51. const uint8_t *py_2index);
  52. extern void RENAME(ff_yuv_420_rgb32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  53. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  54. const uint8_t *py_2index);
  55. extern void RENAME(ff_yuv_420_bgr32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  56. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  57. const uint8_t *py_2index);
  58. extern void RENAME(ff_yuva_420_rgb32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  59. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  60. const uint8_t *py_2index, const uint8_t *pa_2index);
  61. extern void RENAME(ff_yuva_420_bgr32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  62. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  63. const uint8_t *py_2index, const uint8_t *pa_2index);
  64. static inline int RENAME(yuv420_rgb15)(SwsContext *c, const uint8_t *src[],
  65. int srcStride[],
  66. int srcSliceY, int srcSliceH,
  67. uint8_t *dst[], int dstStride[])
  68. {
  69. int y, h_size, vshift;
  70. YUV2RGB_LOOP(2)
  71. #ifdef DITHER1XBPP
  72. c->blueDither = ff_dither8[y & 1];
  73. c->greenDither = ff_dither8[y & 1];
  74. c->redDither = ff_dither8[(y + 1) & 1];
  75. #endif
  76. RENAME(ff_yuv_420_rgb15)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
  77. }
  78. return srcSliceH;
  79. }
  80. static inline int RENAME(yuv420_rgb16)(SwsContext *c, const uint8_t *src[],
  81. int srcStride[],
  82. int srcSliceY, int srcSliceH,
  83. uint8_t *dst[], int dstStride[])
  84. {
  85. int y, h_size, vshift;
  86. YUV2RGB_LOOP(2)
  87. #ifdef DITHER1XBPP
  88. c->blueDither = ff_dither8[y & 1];
  89. c->greenDither = ff_dither4[y & 1];
  90. c->redDither = ff_dither8[(y + 1) & 1];
  91. #endif
  92. RENAME(ff_yuv_420_rgb16)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
  93. }
  94. return srcSliceH;
  95. }
  96. static inline int RENAME(yuv420_rgb32)(SwsContext *c, const uint8_t *src[],
  97. int srcStride[],
  98. int srcSliceY, int srcSliceH,
  99. uint8_t *dst[], int dstStride[])
  100. {
  101. int y, h_size, vshift;
  102. YUV2RGB_LOOP(4)
  103. RENAME(ff_yuv_420_rgb32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
  104. }
  105. return srcSliceH;
  106. }
  107. static inline int RENAME(yuv420_bgr32)(SwsContext *c, const uint8_t *src[],
  108. int srcStride[],
  109. int srcSliceY, int srcSliceH,
  110. uint8_t *dst[], int dstStride[])
  111. {
  112. int y, h_size, vshift;
  113. YUV2RGB_LOOP(4)
  114. RENAME(ff_yuv_420_bgr32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
  115. }
  116. return srcSliceH;
  117. }
  118. static inline int RENAME(yuva420_rgb32)(SwsContext *c, const uint8_t *src[],
  119. int srcStride[],
  120. int srcSliceY, int srcSliceH,
  121. uint8_t *dst[], int dstStride[])
  122. {
  123. int y, h_size, vshift;
  124. YUV2RGB_LOOP(4)
  125. const uint8_t *pa = src[3] + y * srcStride[3];
  126. RENAME(ff_yuva_420_rgb32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index, pa - 2 * index);
  127. }
  128. return srcSliceH;
  129. }
  130. static inline int RENAME(yuva420_bgr32)(SwsContext *c, const uint8_t *src[],
  131. int srcStride[],
  132. int srcSliceY, int srcSliceH,
  133. uint8_t *dst[], int dstStride[])
  134. {
  135. int y, h_size, vshift;
  136. YUV2RGB_LOOP(4)
  137. const uint8_t *pa = src[3] + y * srcStride[3];
  138. RENAME(ff_yuva_420_bgr32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index, pa - 2 * index);
  139. }
  140. return srcSliceH;
  141. }
  142. #endif
  143. #if !defined(COMPILE_TEMPLATE_MMX)
  144. static inline int RENAME(yuv420_rgb24)(SwsContext *c, const uint8_t *src[],
  145. int srcStride[],
  146. int srcSliceY, int srcSliceH,
  147. uint8_t *dst[], int dstStride[])
  148. {
  149. int y, h_size, vshift;
  150. YUV2RGB_LOOP(3)
  151. RENAME(ff_yuv_420_rgb24)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
  152. }
  153. return srcSliceH;
  154. }
  155. static inline int RENAME(yuv420_bgr24)(SwsContext *c, const uint8_t *src[],
  156. int srcStride[],
  157. int srcSliceY, int srcSliceH,
  158. uint8_t *dst[], int dstStride[])
  159. {
  160. int y, h_size, vshift;
  161. YUV2RGB_LOOP(3)
  162. RENAME(ff_yuv_420_bgr24)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
  163. }
  164. return srcSliceH;
  165. }
  166. #endif