yuv2rgb.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * software YUV to RGB converter
  3. *
  4. * Copyright (C) 2009 Konstantin Shishkov
  5. *
  6. * MMX/MMXEXT template stuff (needed for fast movntq support),
  7. * 1,4,8bpp support and context / deglobalize stuff
  8. * by Michael Niedermayer (michaelni@gmx.at)
  9. *
  10. * This file is part of FFmpeg.
  11. *
  12. * FFmpeg is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Lesser General Public
  14. * License as published by the Free Software Foundation; either
  15. * version 2.1 of the License, or (at your option) any later version.
  16. *
  17. * FFmpeg is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public
  23. * License along with FFmpeg; if not, write to the Free Software
  24. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  25. */
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <inttypes.h>
  29. #include "config.h"
  30. #include "libswscale/rgb2rgb.h"
  31. #include "libswscale/swscale.h"
  32. #include "libswscale/swscale_internal.h"
  33. #include "libavutil/attributes.h"
  34. #include "libavutil/x86/asm.h"
  35. #include "libavutil/x86/cpu.h"
  36. #include "libavutil/cpu.h"
  37. #if HAVE_X86ASM
  38. #define DITHER1XBPP // only for MMX
  39. //MMX versions
  40. #if HAVE_MMX
  41. #undef RENAME
  42. #define COMPILE_TEMPLATE_MMX
  43. #define RENAME(a) a ## _mmx
  44. #include "yuv2rgb_template.c"
  45. #undef COMPILE_TEMPLATE_MMX
  46. #endif /* HAVE_MMX */
  47. // MMXEXT versions
  48. #undef RENAME
  49. #define COMPILE_TEMPLATE_MMXEXT
  50. #define RENAME(a) a ## _mmxext
  51. #include "yuv2rgb_template.c"
  52. #undef COMPILE_TEMPLATE_MMXEXT
  53. //SSSE3 versions
  54. #undef RENAME
  55. #define COMPILE_TEMPLATE_SSSE3
  56. #define RENAME(a) a ## _ssse3
  57. #include "yuv2rgb_template.c"
  58. #endif /* HAVE_X86ASM */
  59. av_cold SwsFunc ff_yuv2rgb_init_x86(SwsContext *c)
  60. {
  61. #if HAVE_X86ASM
  62. int cpu_flags = av_get_cpu_flags();
  63. if (EXTERNAL_SSSE3(cpu_flags)) {
  64. switch (c->dstFormat) {
  65. case AV_PIX_FMT_RGB32:
  66. if (c->srcFormat == AV_PIX_FMT_YUVA420P) {
  67. #if CONFIG_SWSCALE_ALPHA
  68. return yuva420_rgb32_ssse3;
  69. #endif
  70. break;
  71. } else
  72. return yuv420_rgb32_ssse3;
  73. case AV_PIX_FMT_BGR32:
  74. if (c->srcFormat == AV_PIX_FMT_YUVA420P) {
  75. #if CONFIG_SWSCALE_ALPHA
  76. return yuva420_bgr32_ssse3;
  77. #endif
  78. break;
  79. } else
  80. return yuv420_bgr32_ssse3;
  81. case AV_PIX_FMT_RGB24:
  82. return yuv420_rgb24_ssse3;
  83. case AV_PIX_FMT_BGR24:
  84. return yuv420_bgr24_ssse3;
  85. case AV_PIX_FMT_RGB565:
  86. return yuv420_rgb16_ssse3;
  87. case AV_PIX_FMT_RGB555:
  88. return yuv420_rgb15_ssse3;
  89. }
  90. }
  91. if (EXTERNAL_MMXEXT(cpu_flags)) {
  92. switch (c->dstFormat) {
  93. case AV_PIX_FMT_RGB24:
  94. return yuv420_rgb24_mmxext;
  95. case AV_PIX_FMT_BGR24:
  96. return yuv420_bgr24_mmxext;
  97. }
  98. }
  99. if (EXTERNAL_MMX(cpu_flags)) {
  100. switch (c->dstFormat) {
  101. case AV_PIX_FMT_RGB32:
  102. if (c->srcFormat == AV_PIX_FMT_YUVA420P) {
  103. #if CONFIG_SWSCALE_ALPHA
  104. return yuva420_rgb32_mmx;
  105. #endif
  106. break;
  107. } else
  108. return yuv420_rgb32_mmx;
  109. case AV_PIX_FMT_BGR32:
  110. if (c->srcFormat == AV_PIX_FMT_YUVA420P) {
  111. #if CONFIG_SWSCALE_ALPHA
  112. return yuva420_bgr32_mmx;
  113. #endif
  114. break;
  115. } else
  116. return yuv420_bgr32_mmx;
  117. case AV_PIX_FMT_RGB565:
  118. return yuv420_rgb16_mmx;
  119. case AV_PIX_FMT_RGB555:
  120. return yuv420_rgb15_mmx;
  121. }
  122. }
  123. #endif /* HAVE_X86ASM */
  124. return NULL;
  125. }