jcgray-mmi.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Loongson MMI optimizations for libjpeg-turbo
  3. *
  4. * Copyright (C) 2011, 2014, D. R. Commander. All Rights Reserved.
  5. * Copyright (C) 2016-2018, Loongson Technology Corporation Limited, BeiJing.
  6. * All Rights Reserved.
  7. * Authors: ZhangLixia <zhanglixia-hf@loongson.cn>
  8. *
  9. * This software is provided 'as-is', without any express or implied
  10. * warranty. In no event will the authors be held liable for any damages
  11. * arising from the use of this software.
  12. *
  13. * Permission is granted to anyone to use this software for any purpose,
  14. * including commercial applications, and to alter it and redistribute it
  15. * freely, subject to the following restrictions:
  16. *
  17. * 1. The origin of this software must not be misrepresented; you must not
  18. * claim that you wrote the original software. If you use this software
  19. * in a product, an acknowledgment in the product documentation would be
  20. * appreciated but is not required.
  21. * 2. Altered source versions must be plainly marked as such, and must not be
  22. * misrepresented as being the original software.
  23. * 3. This notice may not be removed or altered from any source distribution.
  24. */
  25. /* RGB --> GRAYSCALE CONVERSION */
  26. #include "jsimd_mmi.h"
  27. #define F_0_114 ((short)7471) /* FIX(0.11400) */
  28. #define F_0_250 ((short)16384) /* FIX(0.25000) */
  29. #define F_0_299 ((short)19595) /* FIX(0.29900) */
  30. #define F_0_587 ((short)38470) /* FIX(0.58700) */
  31. #define F_0_337 ((short)(F_0_587 - F_0_250)) /* FIX(0.58700) - FIX(0.25000) */
  32. enum const_index {
  33. index_PD_ONEHALF,
  34. index_PW_F0299_F0337,
  35. index_PW_F0114_F0250
  36. };
  37. static uint64_t const_value[] = {
  38. _uint64_set_pi32((int)(1 << (SCALEBITS - 1)), (int)(1 << (SCALEBITS - 1))),
  39. _uint64_set_pi16(F_0_337, F_0_299, F_0_337, F_0_299),
  40. _uint64_set_pi16(F_0_250, F_0_114, F_0_250, F_0_114)
  41. };
  42. #define get_const_value(index) (*(__m64 *)&const_value[index])
  43. #define PD_ONEHALF get_const_value(index_PD_ONEHALF)
  44. #define PW_F0299_F0337 get_const_value(index_PW_F0299_F0337)
  45. #define PW_F0114_F0250 get_const_value(index_PW_F0114_F0250)
  46. #include "jcgryext-mmi.c"
  47. #undef RGB_RED
  48. #undef RGB_GREEN
  49. #undef RGB_BLUE
  50. #undef RGB_PIXELSIZE
  51. #define RGB_RED EXT_RGB_RED
  52. #define RGB_GREEN EXT_RGB_GREEN
  53. #define RGB_BLUE EXT_RGB_BLUE
  54. #define RGB_PIXELSIZE EXT_RGB_PIXELSIZE
  55. #define jsimd_rgb_gray_convert_mmi jsimd_extrgb_gray_convert_mmi
  56. #include "jcgryext-mmi.c"
  57. #undef RGB_RED
  58. #undef RGB_GREEN
  59. #undef RGB_BLUE
  60. #undef RGB_PIXELSIZE
  61. #undef jsimd_rgb_gray_convert_mmi
  62. #define RGB_RED EXT_RGBX_RED
  63. #define RGB_GREEN EXT_RGBX_GREEN
  64. #define RGB_BLUE EXT_RGBX_BLUE
  65. #define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
  66. #define jsimd_rgb_gray_convert_mmi jsimd_extrgbx_gray_convert_mmi
  67. #include "jcgryext-mmi.c"
  68. #undef RGB_RED
  69. #undef RGB_GREEN
  70. #undef RGB_BLUE
  71. #undef RGB_PIXELSIZE
  72. #undef jsimd_rgb_gray_convert_mmi
  73. #define RGB_RED EXT_BGR_RED
  74. #define RGB_GREEN EXT_BGR_GREEN
  75. #define RGB_BLUE EXT_BGR_BLUE
  76. #define RGB_PIXELSIZE EXT_BGR_PIXELSIZE
  77. #define jsimd_rgb_gray_convert_mmi jsimd_extbgr_gray_convert_mmi
  78. #include "jcgryext-mmi.c"
  79. #undef RGB_RED
  80. #undef RGB_GREEN
  81. #undef RGB_BLUE
  82. #undef RGB_PIXELSIZE
  83. #undef jsimd_rgb_gray_convert_mmi
  84. #define RGB_RED EXT_BGRX_RED
  85. #define RGB_GREEN EXT_BGRX_GREEN
  86. #define RGB_BLUE EXT_BGRX_BLUE
  87. #define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
  88. #define jsimd_rgb_gray_convert_mmi jsimd_extbgrx_gray_convert_mmi
  89. #include "jcgryext-mmi.c"
  90. #undef RGB_RED
  91. #undef RGB_GREEN
  92. #undef RGB_BLUE
  93. #undef RGB_PIXELSIZE
  94. #undef jsimd_rgb_gray_convert_mmi
  95. #define RGB_RED EXT_XBGR_RED
  96. #define RGB_GREEN EXT_XBGR_GREEN
  97. #define RGB_BLUE EXT_XBGR_BLUE
  98. #define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
  99. #define jsimd_rgb_gray_convert_mmi jsimd_extxbgr_gray_convert_mmi
  100. #include "jcgryext-mmi.c"
  101. #undef RGB_RED
  102. #undef RGB_GREEN
  103. #undef RGB_BLUE
  104. #undef RGB_PIXELSIZE
  105. #undef jsimd_rgb_gray_convert_mmi
  106. #define RGB_RED EXT_XRGB_RED
  107. #define RGB_GREEN EXT_XRGB_GREEN
  108. #define RGB_BLUE EXT_XRGB_BLUE
  109. #define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
  110. #define jsimd_rgb_gray_convert_mmi jsimd_extxrgb_gray_convert_mmi
  111. #include "jcgryext-mmi.c"
  112. #undef RGB_RED
  113. #undef RGB_GREEN
  114. #undef RGB_BLUE
  115. #undef RGB_PIXELSIZE
  116. #undef jsimd_rgb_gray_convert_mmi