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.

125 lines
3.7KB

  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 Libav.
  11. *
  12. * Libav 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. * Libav 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 Libav; 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 <assert.h>
  30. #include "config.h"
  31. #include "libswscale/rgb2rgb.h"
  32. #include "libswscale/swscale.h"
  33. #include "libswscale/swscale_internal.h"
  34. #include "libavutil/attributes.h"
  35. #include "libavutil/x86/asm.h"
  36. #include "libavutil/x86/cpu.h"
  37. #include "libavutil/cpu.h"
  38. #if HAVE_INLINE_ASM
  39. #define DITHER1XBPP // only for MMX
  40. /* hope these constant values are cache line aligned */
  41. DECLARE_ASM_CONST(8, uint64_t, mmx_00ffw) = 0x00ff00ff00ff00ffULL;
  42. DECLARE_ASM_CONST(8, uint64_t, mmx_redmask) = 0xf8f8f8f8f8f8f8f8ULL;
  43. DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL;
  44. DECLARE_ASM_CONST(8, uint64_t, pb_e0) = 0xe0e0e0e0e0e0e0e0ULL;
  45. DECLARE_ASM_CONST(8, uint64_t, pb_03) = 0x0303030303030303ULL;
  46. DECLARE_ASM_CONST(8, uint64_t, pb_07) = 0x0707070707070707ULL;
  47. //MMX versions
  48. #if HAVE_MMX_INLINE
  49. #undef RENAME
  50. #undef COMPILE_TEMPLATE_MMXEXT
  51. #define COMPILE_TEMPLATE_MMXEXT 0
  52. #define RENAME(a) a ## _mmx
  53. #include "yuv2rgb_template.c"
  54. #endif /* HAVE_MMX_INLINE */
  55. // MMXEXT versions
  56. #if HAVE_MMXEXT_INLINE
  57. #undef RENAME
  58. #undef COMPILE_TEMPLATE_MMXEXT
  59. #define COMPILE_TEMPLATE_MMXEXT 1
  60. #define RENAME(a) a ## _mmxext
  61. #include "yuv2rgb_template.c"
  62. #endif /* HAVE_MMXEXT_INLINE */
  63. #endif /* HAVE_INLINE_ASM */
  64. av_cold SwsFunc ff_yuv2rgb_init_x86(SwsContext *c)
  65. {
  66. #if HAVE_MMX_INLINE
  67. int cpu_flags = av_get_cpu_flags();
  68. if (c->srcFormat != AV_PIX_FMT_YUV420P &&
  69. c->srcFormat != AV_PIX_FMT_YUVA420P)
  70. return NULL;
  71. #if HAVE_MMXEXT_INLINE
  72. if (INLINE_MMXEXT(cpu_flags)) {
  73. switch (c->dstFormat) {
  74. case AV_PIX_FMT_RGB24:
  75. return yuv420_rgb24_mmxext;
  76. case AV_PIX_FMT_BGR24:
  77. return yuv420_bgr24_mmxext;
  78. }
  79. }
  80. #endif
  81. if (INLINE_MMX(cpu_flags)) {
  82. switch (c->dstFormat) {
  83. case AV_PIX_FMT_RGB32:
  84. if (c->srcFormat == AV_PIX_FMT_YUVA420P) {
  85. #if HAVE_7REGS && CONFIG_SWSCALE_ALPHA
  86. return yuva420_rgb32_mmx;
  87. #endif
  88. break;
  89. } else
  90. return yuv420_rgb32_mmx;
  91. case AV_PIX_FMT_BGR32:
  92. if (c->srcFormat == AV_PIX_FMT_YUVA420P) {
  93. #if HAVE_7REGS && CONFIG_SWSCALE_ALPHA
  94. return yuva420_bgr32_mmx;
  95. #endif
  96. break;
  97. } else
  98. return yuv420_bgr32_mmx;
  99. case AV_PIX_FMT_RGB24:
  100. return yuv420_rgb24_mmx;
  101. case AV_PIX_FMT_BGR24:
  102. return yuv420_bgr24_mmx;
  103. case AV_PIX_FMT_RGB565:
  104. return yuv420_rgb16_mmx;
  105. case AV_PIX_FMT_RGB555:
  106. return yuv420_rgb15_mmx;
  107. }
  108. }
  109. #endif /* HAVE_MMX_INLINE */
  110. return NULL;
  111. }