yuv2rgb_mmx.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * software YUV to RGB converter
  3. *
  4. * Copyright (C) 2009 Konstantin Shishkov
  5. *
  6. * MMX/MMX2 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 <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/x86_cpu.h"
  35. #include "libavutil/cpu.h"
  36. #define DITHER1XBPP // only for MMX
  37. /* hope these constant values are cache line aligned */
  38. DECLARE_ASM_CONST(8, uint64_t, mmx_00ffw) = 0x00ff00ff00ff00ffULL;
  39. DECLARE_ASM_CONST(8, uint64_t, mmx_redmask) = 0xf8f8f8f8f8f8f8f8ULL;
  40. DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL;
  41. DECLARE_ASM_CONST(8, uint64_t, pb_e0) = 0xe0e0e0e0e0e0e0e0ULL;
  42. DECLARE_ASM_CONST(8, uint64_t, pb_03) = 0x0303030303030303ULL;
  43. DECLARE_ASM_CONST(8, uint64_t, pb_07) = 0x0707070707070707ULL;
  44. //MMX versions
  45. #if HAVE_MMX
  46. #undef RENAME
  47. #undef COMPILE_TEMPLATE_MMX2
  48. #define COMPILE_TEMPLATE_MMX2 0
  49. #define RENAME(a) a ## _MMX
  50. #include "yuv2rgb_template.c"
  51. #endif /* HAVE_MMX */
  52. //MMX2 versions
  53. #if HAVE_MMX2
  54. #undef RENAME
  55. #undef COMPILE_TEMPLATE_MMX2
  56. #define COMPILE_TEMPLATE_MMX2 1
  57. #define RENAME(a) a ## _MMX2
  58. #include "yuv2rgb_template.c"
  59. #endif /* HAVE_MMX2 */
  60. SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c)
  61. {
  62. int cpu_flags = av_get_cpu_flags();
  63. #if HAVE_MMX2
  64. if (cpu_flags & AV_CPU_FLAG_MMX2) {
  65. switch (c->dstFormat) {
  66. case PIX_FMT_RGB24: return yuv420_rgb24_MMX2;
  67. case PIX_FMT_BGR24: return yuv420_bgr24_MMX2;
  68. }
  69. }
  70. #endif
  71. if (cpu_flags & AV_CPU_FLAG_MMX) {
  72. switch (c->dstFormat) {
  73. case PIX_FMT_RGB32:
  74. if (c->srcFormat == PIX_FMT_YUVA420P) {
  75. #if HAVE_7REGS && CONFIG_SWSCALE_ALPHA
  76. return yuva420_rgb32_MMX;
  77. #endif
  78. break;
  79. } else return yuv420_rgb32_MMX;
  80. case PIX_FMT_BGR32:
  81. if (c->srcFormat == PIX_FMT_YUVA420P) {
  82. #if HAVE_7REGS && CONFIG_SWSCALE_ALPHA
  83. return yuva420_bgr32_MMX;
  84. #endif
  85. break;
  86. } else return yuv420_bgr32_MMX;
  87. case PIX_FMT_RGB24: return yuv420_rgb24_MMX;
  88. case PIX_FMT_BGR24: return yuv420_bgr24_MMX;
  89. case PIX_FMT_RGB565: return yuv420_rgb16_MMX;
  90. case PIX_FMT_RGB555: return yuv420_rgb15_MMX;
  91. }
  92. }
  93. return NULL;
  94. }