yuv2rgb_mmx.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. //MMX versions
  41. #undef RENAME
  42. #undef HAVE_MMX2
  43. #undef HAVE_AMD3DNOW
  44. #define HAVE_MMX2 0
  45. #define HAVE_AMD3DNOW 0
  46. #define RENAME(a) a ## _MMX
  47. #include "yuv2rgb_template.c"
  48. //MMX2 versions
  49. #undef RENAME
  50. #undef HAVE_MMX2
  51. #define HAVE_MMX2 1
  52. #define RENAME(a) a ## _MMX2
  53. #include "yuv2rgb_template.c"
  54. SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c)
  55. {
  56. if (c->flags & SWS_CPU_CAPS_MMX2) {
  57. switch (c->dstFormat) {
  58. case PIX_FMT_RGB32:
  59. if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P){
  60. if (HAVE_7REGS) return yuva420_rgb32_MMX2;
  61. break;
  62. }else return yuv420_rgb32_MMX2;
  63. case PIX_FMT_BGR24: return yuv420_rgb24_MMX2;
  64. case PIX_FMT_RGB565: return yuv420_rgb16_MMX2;
  65. case PIX_FMT_RGB555: return yuv420_rgb15_MMX2;
  66. }
  67. }
  68. if (c->flags & SWS_CPU_CAPS_MMX) {
  69. switch (c->dstFormat) {
  70. case PIX_FMT_RGB32:
  71. if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P){
  72. if (HAVE_7REGS) return yuva420_rgb32_MMX;
  73. break;
  74. }else return yuv420_rgb32_MMX;
  75. case PIX_FMT_BGR24: return yuv420_rgb24_MMX;
  76. case PIX_FMT_RGB565: return yuv420_rgb16_MMX;
  77. case PIX_FMT_RGB555: return yuv420_rgb15_MMX;
  78. }
  79. }
  80. return NULL;
  81. }