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.

113 lines
3.4KB

  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/cpu.h"
  36. #if HAVE_INLINE_ASM
  37. #define DITHER1XBPP // only for MMX
  38. /* hope these constant values are cache line aligned */
  39. DECLARE_ASM_CONST(8, uint64_t, mmx_00ffw) = 0x00ff00ff00ff00ffULL;
  40. DECLARE_ASM_CONST(8, uint64_t, mmx_redmask) = 0xf8f8f8f8f8f8f8f8ULL;
  41. DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL;
  42. DECLARE_ASM_CONST(8, uint64_t, pb_e0) = 0xe0e0e0e0e0e0e0e0ULL;
  43. DECLARE_ASM_CONST(8, uint64_t, pb_03) = 0x0303030303030303ULL;
  44. DECLARE_ASM_CONST(8, uint64_t, pb_07) = 0x0707070707070707ULL;
  45. //MMX versions
  46. #if HAVE_MMX_INLINE
  47. #undef RENAME
  48. #undef COMPILE_TEMPLATE_MMXEXT
  49. #define COMPILE_TEMPLATE_MMXEXT 0
  50. #define RENAME(a) a ## _MMX
  51. #include "yuv2rgb_template.c"
  52. #endif /* HAVE_MMX_INLINE */
  53. // MMXEXT versions
  54. #if HAVE_MMXEXT_INLINE
  55. #undef RENAME
  56. #undef COMPILE_TEMPLATE_MMXEXT
  57. #define COMPILE_TEMPLATE_MMXEXT 1
  58. #define RENAME(a) a ## _MMXEXT
  59. #include "yuv2rgb_template.c"
  60. #endif /* HAVE_MMXEXT_INLINE */
  61. #endif /* HAVE_INLINE_ASM */
  62. av_cold SwsFunc ff_yuv2rgb_init_x86(SwsContext *c)
  63. {
  64. #if HAVE_MMX_INLINE
  65. int cpu_flags = av_get_cpu_flags();
  66. #if HAVE_MMXEXT_INLINE
  67. if (cpu_flags & AV_CPU_FLAG_MMXEXT) {
  68. switch (c->dstFormat) {
  69. case AV_PIX_FMT_RGB24:
  70. return yuv420_rgb24_MMXEXT;
  71. case AV_PIX_FMT_BGR24:
  72. return yuv420_bgr24_MMXEXT;
  73. }
  74. }
  75. #endif
  76. if (cpu_flags & AV_CPU_FLAG_MMX) {
  77. switch (c->dstFormat) {
  78. case AV_PIX_FMT_RGB32:
  79. if (c->srcFormat == AV_PIX_FMT_YUVA420P) {
  80. #if HAVE_7REGS && CONFIG_SWSCALE_ALPHA
  81. return yuva420_rgb32_MMX;
  82. #endif
  83. break;
  84. } else return yuv420_rgb32_MMX;
  85. case AV_PIX_FMT_BGR32:
  86. if (c->srcFormat == AV_PIX_FMT_YUVA420P) {
  87. #if HAVE_7REGS && CONFIG_SWSCALE_ALPHA
  88. return yuva420_bgr32_MMX;
  89. #endif
  90. break;
  91. } else return yuv420_bgr32_MMX;
  92. case AV_PIX_FMT_RGB24: return yuv420_rgb24_MMX;
  93. case AV_PIX_FMT_BGR24: return yuv420_bgr24_MMX;
  94. case AV_PIX_FMT_RGB565: return yuv420_rgb16_MMX;
  95. case AV_PIX_FMT_RGB555: return yuv420_rgb15_MMX;
  96. }
  97. }
  98. #endif /* HAVE_MMX_INLINE */
  99. return NULL;
  100. }