yuv2rgb_template.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. extern void RENAME(ff_yuv_420_rgb15)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  46. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  47. const uint8_t *py_2index);
  48. extern void RENAME(ff_yuv_420_rgb16)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  49. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  50. const uint8_t *py_2index);
  51. extern void RENAME(ff_yuv_420_rgb32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  52. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  53. const uint8_t *py_2index);
  54. extern void RENAME(ff_yuv_420_bgr32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  55. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  56. const uint8_t *py_2index);
  57. extern void RENAME(ff_yuva_420_rgb32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  58. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  59. const uint8_t *py_2index, const uint8_t *pa_2index);
  60. extern void RENAME(ff_yuva_420_bgr32)(x86_reg index, uint8_t *image, const uint8_t *pu_index,
  61. const uint8_t *pv_index, const uint64_t *pointer_c_dither,
  62. const uint8_t *py_2index, const uint8_t *pa_2index);
  63. static inline int RENAME(yuv420_rgb15)(SwsContext *c, const uint8_t *src[],
  64. int srcStride[],
  65. int srcSliceY, int srcSliceH,
  66. uint8_t *dst[], int dstStride[])
  67. {
  68. int y, h_size, vshift;
  69. YUV2RGB_LOOP(2)
  70. #ifdef DITHER1XBPP
  71. c->blueDither = ff_dither8[y & 1];
  72. c->greenDither = ff_dither8[y & 1];
  73. c->redDither = ff_dither8[(y + 1) & 1];
  74. #endif
  75. RENAME(ff_yuv_420_rgb15)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
  76. }
  77. return srcSliceH;
  78. }
  79. static inline int RENAME(yuv420_rgb16)(SwsContext *c, const uint8_t *src[],
  80. int srcStride[],
  81. int srcSliceY, int srcSliceH,
  82. uint8_t *dst[], int dstStride[])
  83. {
  84. int y, h_size, vshift;
  85. YUV2RGB_LOOP(2)
  86. #ifdef DITHER1XBPP
  87. c->blueDither = ff_dither8[y & 1];
  88. c->greenDither = ff_dither4[y & 1];
  89. c->redDither = ff_dither8[(y + 1) & 1];
  90. #endif
  91. RENAME(ff_yuv_420_rgb16)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
  92. }
  93. return srcSliceH;
  94. }
  95. static inline int RENAME(yuv420_rgb32)(SwsContext *c, const uint8_t *src[],
  96. int srcStride[],
  97. int srcSliceY, int srcSliceH,
  98. uint8_t *dst[], int dstStride[])
  99. {
  100. int y, h_size, vshift;
  101. YUV2RGB_LOOP(4)
  102. RENAME(ff_yuv_420_rgb32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
  103. }
  104. return srcSliceH;
  105. }
  106. static inline int RENAME(yuv420_bgr32)(SwsContext *c, const uint8_t *src[],
  107. int srcStride[],
  108. int srcSliceY, int srcSliceH,
  109. uint8_t *dst[], int dstStride[])
  110. {
  111. int y, h_size, vshift;
  112. YUV2RGB_LOOP(4)
  113. RENAME(ff_yuv_420_bgr32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
  114. }
  115. return srcSliceH;
  116. }
  117. static inline int RENAME(yuva420_rgb32)(SwsContext *c, const uint8_t *src[],
  118. int srcStride[],
  119. int srcSliceY, int srcSliceH,
  120. uint8_t *dst[], int dstStride[])
  121. {
  122. int y, h_size, vshift;
  123. YUV2RGB_LOOP(4)
  124. const uint8_t *pa = src[3] + y * srcStride[3];
  125. RENAME(ff_yuva_420_rgb32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index, pa - 2 * index);
  126. }
  127. return srcSliceH;
  128. }
  129. static inline int RENAME(yuva420_bgr32)(SwsContext *c, const uint8_t *src[],
  130. int srcStride[],
  131. int srcSliceY, int srcSliceH,
  132. uint8_t *dst[], int dstStride[])
  133. {
  134. int y, h_size, vshift;
  135. YUV2RGB_LOOP(4)
  136. const uint8_t *pa = src[3] + y * srcStride[3];
  137. RENAME(ff_yuva_420_bgr32)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index, pa - 2 * index);
  138. }
  139. return srcSliceH;
  140. }
  141. static inline int RENAME(yuv420_rgb24)(SwsContext *c, const uint8_t *src[],
  142. int srcStride[],
  143. int srcSliceY, int srcSliceH,
  144. uint8_t *dst[], int dstStride[])
  145. {
  146. int y, h_size, vshift;
  147. YUV2RGB_LOOP(3)
  148. RENAME(ff_yuv_420_rgb24)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
  149. }
  150. return srcSliceH;
  151. }
  152. static inline int RENAME(yuv420_bgr24)(SwsContext *c, const uint8_t *src[],
  153. int srcStride[],
  154. int srcSliceY, int srcSliceH,
  155. uint8_t *dst[], int dstStride[])
  156. {
  157. int y, h_size, vshift;
  158. YUV2RGB_LOOP(3)
  159. RENAME(ff_yuv_420_bgr24)(index, image, pu - index, pv - index, &(c->redDither), py - 2 * index);
  160. }
  161. return srcSliceH;
  162. }