yuv2rgb_mmx.c 3.5 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. #define DITHER1XBPP // only for MMX
  36. /* hope these constant values are cache line aligned */
  37. DECLARE_ASM_CONST(8, uint64_t, mmx_00ffw) = 0x00ff00ff00ff00ffULL;
  38. DECLARE_ASM_CONST(8, uint64_t, mmx_redmask) = 0xf8f8f8f8f8f8f8f8ULL;
  39. DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL;
  40. DECLARE_ASM_CONST(8, uint64_t, pb_e0) = 0xe0e0e0e0e0e0e0e0ULL;
  41. DECLARE_ASM_CONST(8, uint64_t, pb_03) = 0x0303030303030303ULL;
  42. DECLARE_ASM_CONST(8, uint64_t, pb_07) = 0x0707070707070707ULL;
  43. //MMX versions
  44. #undef RENAME
  45. #undef HAVE_MMX2
  46. #undef HAVE_AMD3DNOW
  47. #define HAVE_MMX2 0
  48. #define HAVE_AMD3DNOW 0
  49. #define RENAME(a) a ## _MMX
  50. #include "yuv2rgb_template.c"
  51. //MMX2 versions
  52. #undef RENAME
  53. #undef HAVE_MMX2
  54. #define HAVE_MMX2 1
  55. #define RENAME(a) a ## _MMX2
  56. #include "yuv2rgb_template.c"
  57. SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c)
  58. {
  59. if (c->flags & SWS_CPU_CAPS_MMX2) {
  60. switch (c->dstFormat) {
  61. case PIX_FMT_RGB32:
  62. if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) {
  63. if (HAVE_7REGS) return yuva420_rgb32_MMX2;
  64. break;
  65. } else return yuv420_rgb32_MMX2;
  66. case PIX_FMT_BGR32:
  67. if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) {
  68. if (HAVE_7REGS) return yuva420_bgr32_MMX2;
  69. break;
  70. } else return yuv420_bgr32_MMX2;
  71. case PIX_FMT_RGB24: return yuv420_rgb24_MMX2;
  72. case PIX_FMT_BGR24: return yuv420_bgr24_MMX2;
  73. case PIX_FMT_RGB565: return yuv420_rgb16_MMX2;
  74. case PIX_FMT_RGB555: return yuv420_rgb15_MMX2;
  75. }
  76. }
  77. if (c->flags & SWS_CPU_CAPS_MMX) {
  78. switch (c->dstFormat) {
  79. case PIX_FMT_RGB32:
  80. if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) {
  81. if (HAVE_7REGS) return yuva420_rgb32_MMX;
  82. break;
  83. } else return yuv420_rgb32_MMX;
  84. case PIX_FMT_BGR32:
  85. if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) {
  86. if (HAVE_7REGS) return yuva420_bgr32_MMX;
  87. break;
  88. } else return yuv420_bgr32_MMX;
  89. case PIX_FMT_RGB24: return yuv420_rgb24_MMX;
  90. case PIX_FMT_BGR24: return yuv420_bgr24_MMX;
  91. case PIX_FMT_RGB565: return yuv420_rgb16_MMX;
  92. case PIX_FMT_RGB555: return yuv420_rgb15_MMX;
  93. }
  94. }
  95. return NULL;
  96. }