• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
26 /* RGB --> GRAYSCALE CONVERSION */
27 
28 #include "jsimd_mmi.h"
29 
30 
31 #define F_0_114  ((short)7471)                /* FIX(0.11400) */
32 #define F_0_250  ((short)16384)               /* FIX(0.25000) */
33 #define F_0_299  ((short)19595)               /* FIX(0.29900) */
34 #define F_0_587  ((short)38470)               /* FIX(0.58700) */
35 #define F_0_337  ((short)(F_0_587 - F_0_250)) /* FIX(0.58700) - FIX(0.25000) */
36 
37 enum const_index {
38   index_PD_ONEHALF,
39   index_PW_F0299_F0337,
40   index_PW_F0114_F0250
41 };
42 
43 static uint64_t const_value[] = {
44   _uint64_set_pi32((int)(1 << (SCALEBITS - 1)), (int)(1 << (SCALEBITS - 1))),
45   _uint64_set_pi16(F_0_337, F_0_299, F_0_337, F_0_299),
46   _uint64_set_pi16(F_0_250, F_0_114, F_0_250, F_0_114)
47 };
48 
49 #define get_const_value(index)  (*(__m64 *)&const_value[index])
50 
51 #define PD_ONEHALF       get_const_value(index_PD_ONEHALF)
52 #define PW_F0299_F0337   get_const_value(index_PW_F0299_F0337)
53 #define PW_F0114_F0250   get_const_value(index_PW_F0114_F0250)
54 
55 
56 #include "jcgryext-mmi.c"
57 #undef RGB_RED
58 #undef RGB_GREEN
59 #undef RGB_BLUE
60 #undef RGB_PIXELSIZE
61 
62 #define RGB_RED  EXT_RGB_RED
63 #define RGB_GREEN  EXT_RGB_GREEN
64 #define RGB_BLUE  EXT_RGB_BLUE
65 #define RGB_PIXELSIZE  EXT_RGB_PIXELSIZE
66 #define jsimd_rgb_gray_convert_mmi  jsimd_extrgb_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 
74 #define RGB_RED  EXT_RGBX_RED
75 #define RGB_GREEN  EXT_RGBX_GREEN
76 #define RGB_BLUE  EXT_RGBX_BLUE
77 #define RGB_PIXELSIZE  EXT_RGBX_PIXELSIZE
78 #define jsimd_rgb_gray_convert_mmi  jsimd_extrgbx_gray_convert_mmi
79 #include "jcgryext-mmi.c"
80 #undef RGB_RED
81 #undef RGB_GREEN
82 #undef RGB_BLUE
83 #undef RGB_PIXELSIZE
84 #undef jsimd_rgb_gray_convert_mmi
85 
86 #define RGB_RED  EXT_BGR_RED
87 #define RGB_GREEN  EXT_BGR_GREEN
88 #define RGB_BLUE  EXT_BGR_BLUE
89 #define RGB_PIXELSIZE  EXT_BGR_PIXELSIZE
90 #define jsimd_rgb_gray_convert_mmi  jsimd_extbgr_gray_convert_mmi
91 #include "jcgryext-mmi.c"
92 #undef RGB_RED
93 #undef RGB_GREEN
94 #undef RGB_BLUE
95 #undef RGB_PIXELSIZE
96 #undef jsimd_rgb_gray_convert_mmi
97 
98 #define RGB_RED  EXT_BGRX_RED
99 #define RGB_GREEN  EXT_BGRX_GREEN
100 #define RGB_BLUE  EXT_BGRX_BLUE
101 #define RGB_PIXELSIZE  EXT_BGRX_PIXELSIZE
102 #define jsimd_rgb_gray_convert_mmi  jsimd_extbgrx_gray_convert_mmi
103 #include "jcgryext-mmi.c"
104 #undef RGB_RED
105 #undef RGB_GREEN
106 #undef RGB_BLUE
107 #undef RGB_PIXELSIZE
108 #undef jsimd_rgb_gray_convert_mmi
109 
110 #define RGB_RED  EXT_XBGR_RED
111 #define RGB_GREEN  EXT_XBGR_GREEN
112 #define RGB_BLUE  EXT_XBGR_BLUE
113 #define RGB_PIXELSIZE  EXT_XBGR_PIXELSIZE
114 #define jsimd_rgb_gray_convert_mmi  jsimd_extxbgr_gray_convert_mmi
115 #include "jcgryext-mmi.c"
116 #undef RGB_RED
117 #undef RGB_GREEN
118 #undef RGB_BLUE
119 #undef RGB_PIXELSIZE
120 #undef jsimd_rgb_gray_convert_mmi
121 
122 #define RGB_RED  EXT_XRGB_RED
123 #define RGB_GREEN  EXT_XRGB_GREEN
124 #define RGB_BLUE  EXT_XRGB_BLUE
125 #define RGB_PIXELSIZE  EXT_XRGB_PIXELSIZE
126 #define jsimd_rgb_gray_convert_mmi  jsimd_extxrgb_gray_convert_mmi
127 #include "jcgryext-mmi.c"
128 #undef RGB_RED
129 #undef RGB_GREEN
130 #undef RGB_BLUE
131 #undef RGB_PIXELSIZE
132 #undef jsimd_rgb_gray_convert_mmi
133