OLD | NEW |
1 // qcms | 1 // qcms |
2 // Copyright (C) 2009 Mozilla Foundation | 2 // Copyright (C) 2009 Mozilla Foundation |
3 // | 3 // |
4 // Permission is hereby granted, free of charge, to any person obtaining | 4 // Permission is hereby granted, free of charge, to any person obtaining |
5 // a copy of this software and associated documentation files (the "Software"), | 5 // a copy of this software and associated documentation files (the "Software"), |
6 // to deal in the Software without restriction, including without limitation | 6 // to deal in the Software without restriction, including without limitation |
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, | 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
8 // and/or sell copies of the Software, and to permit persons to whom the Softwar
e | 8 // and/or sell copies of the Software, and to permit persons to whom the Softwar
e |
9 // is furnished to do so, subject to the following conditions: | 9 // is furnished to do so, subject to the following conditions: |
10 // | 10 // |
(...skipping 16 matching lines...) Expand all Loading... |
27 #define FLOATSCALE (float)(PRECACHE_OUTPUT_SIZE) | 27 #define FLOATSCALE (float)(PRECACHE_OUTPUT_SIZE) |
28 #define CLAMPMAXVAL ( ((float) (PRECACHE_OUTPUT_SIZE - 1)) / PRECACHE_OUTPUT_SIZ
E ) | 28 #define CLAMPMAXVAL ( ((float) (PRECACHE_OUTPUT_SIZE - 1)) / PRECACHE_OUTPUT_SIZ
E ) |
29 static const ALIGN float floatScaleX4[4] = | 29 static const ALIGN float floatScaleX4[4] = |
30 { FLOATSCALE, FLOATSCALE, FLOATSCALE, FLOATSCALE}; | 30 { FLOATSCALE, FLOATSCALE, FLOATSCALE, FLOATSCALE}; |
31 static const ALIGN float clampMaxValueX4[4] = | 31 static const ALIGN float clampMaxValueX4[4] = |
32 { CLAMPMAXVAL, CLAMPMAXVAL, CLAMPMAXVAL, CLAMPMAXVAL}; | 32 { CLAMPMAXVAL, CLAMPMAXVAL, CLAMPMAXVAL, CLAMPMAXVAL}; |
33 | 33 |
34 void qcms_transform_data_rgb_out_lut_sse2(qcms_transform *transform, | 34 void qcms_transform_data_rgb_out_lut_sse2(qcms_transform *transform, |
35 unsigned char *src, | 35 unsigned char *src, |
36 unsigned char *dest, | 36 unsigned char *dest, |
37 size_t length) | 37 size_t length, |
| 38 qcms_format_type output_format) |
38 { | 39 { |
39 unsigned int i; | 40 unsigned int i; |
40 float (*mat)[4] = transform->matrix; | 41 float (*mat)[4] = transform->matrix; |
41 char input_back[32]; | 42 char input_back[32]; |
42 /* Ensure we have a buffer that's 16 byte aligned regardless of the original | 43 /* Ensure we have a buffer that's 16 byte aligned regardless of the original |
43 * stack alignment. We can't use __attribute__((aligned(16))) or __declspec(
align(32)) | 44 * stack alignment. We can't use __attribute__((aligned(16))) or __declspec(
align(32)) |
44 * because they don't work on stack variables. gcc 4.4 does do the right thi
ng | 45 * because they don't work on stack variables. gcc 4.4 does do the right thi
ng |
45 * on x86 but that's too new for us right now. For more info: gcc bug #16660
*/ | 46 * on x86 but that's too new for us right now. For more info: gcc bug #16660
*/ |
46 float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf); | 47 float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf); |
47 /* share input and output locations to save having to keep the | 48 /* share input and output locations to save having to keep the |
(...skipping 15 matching lines...) Expand all Loading... |
63 const __m128 mat1 = _mm_load_ps(mat[1]); | 64 const __m128 mat1 = _mm_load_ps(mat[1]); |
64 const __m128 mat2 = _mm_load_ps(mat[2]); | 65 const __m128 mat2 = _mm_load_ps(mat[2]); |
65 | 66 |
66 /* these values don't change, either */ | 67 /* these values don't change, either */ |
67 const __m128 max = _mm_load_ps(clampMaxValueX4); | 68 const __m128 max = _mm_load_ps(clampMaxValueX4); |
68 const __m128 min = _mm_setzero_ps(); | 69 const __m128 min = _mm_setzero_ps(); |
69 const __m128 scale = _mm_load_ps(floatScaleX4); | 70 const __m128 scale = _mm_load_ps(floatScaleX4); |
70 | 71 |
71 /* working variables */ | 72 /* working variables */ |
72 __m128 vec_r, vec_g, vec_b, result; | 73 __m128 vec_r, vec_g, vec_b, result; |
| 74 const int r_out = output_format.r; |
| 75 const int b_out = output_format.b; |
73 | 76 |
74 /* CYA */ | 77 /* CYA */ |
75 if (!length) | 78 if (!length) |
76 return; | 79 return; |
77 | 80 |
78 /* one pixel is handled outside of the loop */ | 81 /* one pixel is handled outside of the loop */ |
79 length--; | 82 length--; |
80 | 83 |
81 /* setup for transforming 1st pixel */ | 84 /* setup for transforming 1st pixel */ |
82 vec_r = _mm_load_ss(&igtbl_r[src[0]]); | 85 vec_r = _mm_load_ss(&igtbl_r[src[0]]); |
(...skipping 24 matching lines...) Expand all Loading... |
107 /* store calc'd output tables indices */ | 110 /* store calc'd output tables indices */ |
108 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result)); | 111 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result)); |
109 | 112 |
110 /* load for next loop while store completes */ | 113 /* load for next loop while store completes */ |
111 vec_r = _mm_load_ss(&igtbl_r[src[0]]); | 114 vec_r = _mm_load_ss(&igtbl_r[src[0]]); |
112 vec_g = _mm_load_ss(&igtbl_g[src[1]]); | 115 vec_g = _mm_load_ss(&igtbl_g[src[1]]); |
113 vec_b = _mm_load_ss(&igtbl_b[src[2]]); | 116 vec_b = _mm_load_ss(&igtbl_b[src[2]]); |
114 src += 3; | 117 src += 3; |
115 | 118 |
116 /* use calc'd indices to output RGB values */ | 119 /* use calc'd indices to output RGB values */ |
117 dest[0] = otdata_r[output[0]]; | 120 dest[r_out] = otdata_r[output[0]]; |
118 dest[1] = otdata_g[output[1]]; | 121 dest[1] = otdata_g[output[1]]; |
119 dest[2] = otdata_b[output[2]]; | 122 dest[b_out] = otdata_b[output[2]]; |
120 dest += 3; | 123 dest += 3; |
121 } | 124 } |
122 | 125 |
123 /* handle final (maybe only) pixel */ | 126 /* handle final (maybe only) pixel */ |
124 | 127 |
125 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0); | 128 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0); |
126 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0); | 129 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0); |
127 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0); | 130 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0); |
128 | 131 |
129 vec_r = _mm_mul_ps(vec_r, mat0); | 132 vec_r = _mm_mul_ps(vec_r, mat0); |
130 vec_g = _mm_mul_ps(vec_g, mat1); | 133 vec_g = _mm_mul_ps(vec_g, mat1); |
131 vec_b = _mm_mul_ps(vec_b, mat2); | 134 vec_b = _mm_mul_ps(vec_b, mat2); |
132 | 135 |
133 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b)); | 136 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b)); |
134 vec_r = _mm_max_ps(min, vec_r); | 137 vec_r = _mm_max_ps(min, vec_r); |
135 vec_r = _mm_min_ps(max, vec_r); | 138 vec_r = _mm_min_ps(max, vec_r); |
136 result = _mm_mul_ps(vec_r, scale); | 139 result = _mm_mul_ps(vec_r, scale); |
137 | 140 |
138 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result)); | 141 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result)); |
139 | 142 |
140 dest[0] = otdata_r[output[0]]; | 143 dest[r_out] = otdata_r[output[0]]; |
141 dest[1] = otdata_g[output[1]]; | 144 dest[1] = otdata_g[output[1]]; |
142 dest[2] = otdata_b[output[2]]; | 145 dest[b_out] = otdata_b[output[2]]; |
143 } | 146 } |
144 | 147 |
145 void qcms_transform_data_rgba_out_lut_sse2(qcms_transform *transform, | 148 void qcms_transform_data_rgba_out_lut_sse2(qcms_transform *transform, |
146 unsigned char *src, | 149 unsigned char *src, |
147 unsigned char *dest, | 150 unsigned char *dest, |
148 size_t length) | 151 size_t length, |
| 152 qcms_format_type output_format) |
149 { | 153 { |
150 unsigned int i; | 154 unsigned int i; |
151 float (*mat)[4] = transform->matrix; | 155 float (*mat)[4] = transform->matrix; |
152 char input_back[32]; | 156 char input_back[32]; |
153 /* Ensure we have a buffer that's 16 byte aligned regardless of the original | 157 /* Ensure we have a buffer that's 16 byte aligned regardless of the original |
154 * stack alignment. We can't use __attribute__((aligned(16))) or __declspec(
align(32)) | 158 * stack alignment. We can't use __attribute__((aligned(16))) or __declspec(
align(32)) |
155 * because they don't work on stack variables. gcc 4.4 does do the right thi
ng | 159 * because they don't work on stack variables. gcc 4.4 does do the right thi
ng |
156 * on x86 but that's too new for us right now. For more info: gcc bug #16660
*/ | 160 * on x86 but that's too new for us right now. For more info: gcc bug #16660
*/ |
157 float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf); | 161 float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf); |
158 /* share input and output locations to save having to keep the | 162 /* share input and output locations to save having to keep the |
(...skipping 15 matching lines...) Expand all Loading... |
174 const __m128 mat1 = _mm_load_ps(mat[1]); | 178 const __m128 mat1 = _mm_load_ps(mat[1]); |
175 const __m128 mat2 = _mm_load_ps(mat[2]); | 179 const __m128 mat2 = _mm_load_ps(mat[2]); |
176 | 180 |
177 /* these values don't change, either */ | 181 /* these values don't change, either */ |
178 const __m128 max = _mm_load_ps(clampMaxValueX4); | 182 const __m128 max = _mm_load_ps(clampMaxValueX4); |
179 const __m128 min = _mm_setzero_ps(); | 183 const __m128 min = _mm_setzero_ps(); |
180 const __m128 scale = _mm_load_ps(floatScaleX4); | 184 const __m128 scale = _mm_load_ps(floatScaleX4); |
181 | 185 |
182 /* working variables */ | 186 /* working variables */ |
183 __m128 vec_r, vec_g, vec_b, result; | 187 __m128 vec_r, vec_g, vec_b, result; |
| 188 const int r_out = output_format.r; |
| 189 const int b_out = output_format.b; |
184 unsigned char alpha; | 190 unsigned char alpha; |
185 | 191 |
186 /* CYA */ | 192 /* CYA */ |
187 if (!length) | 193 if (!length) |
188 return; | 194 return; |
189 | 195 |
190 /* one pixel is handled outside of the loop */ | 196 /* one pixel is handled outside of the loop */ |
191 length--; | 197 length--; |
192 | 198 |
193 /* setup for transforming 1st pixel */ | 199 /* setup for transforming 1st pixel */ |
(...skipping 30 matching lines...) Expand all Loading... |
224 /* store calc'd output tables indices */ | 230 /* store calc'd output tables indices */ |
225 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result)); | 231 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result)); |
226 | 232 |
227 /* load gamma values for next loop while store completes */ | 233 /* load gamma values for next loop while store completes */ |
228 vec_r = _mm_load_ss(&igtbl_r[src[0]]); | 234 vec_r = _mm_load_ss(&igtbl_r[src[0]]); |
229 vec_g = _mm_load_ss(&igtbl_g[src[1]]); | 235 vec_g = _mm_load_ss(&igtbl_g[src[1]]); |
230 vec_b = _mm_load_ss(&igtbl_b[src[2]]); | 236 vec_b = _mm_load_ss(&igtbl_b[src[2]]); |
231 src += 4; | 237 src += 4; |
232 | 238 |
233 /* use calc'd indices to output RGB values */ | 239 /* use calc'd indices to output RGB values */ |
234 dest[0] = otdata_r[output[0]]; | 240 dest[r_out] = otdata_r[output[0]]; |
235 dest[1] = otdata_g[output[1]]; | 241 dest[1] = otdata_g[output[1]]; |
236 dest[2] = otdata_b[output[2]]; | 242 dest[b_out] = otdata_b[output[2]]; |
237 dest += 4; | 243 dest += 4; |
238 } | 244 } |
239 | 245 |
240 /* handle final (maybe only) pixel */ | 246 /* handle final (maybe only) pixel */ |
241 | 247 |
242 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0); | 248 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0); |
243 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0); | 249 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0); |
244 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0); | 250 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0); |
245 | 251 |
246 vec_r = _mm_mul_ps(vec_r, mat0); | 252 vec_r = _mm_mul_ps(vec_r, mat0); |
247 vec_g = _mm_mul_ps(vec_g, mat1); | 253 vec_g = _mm_mul_ps(vec_g, mat1); |
248 vec_b = _mm_mul_ps(vec_b, mat2); | 254 vec_b = _mm_mul_ps(vec_b, mat2); |
249 | 255 |
250 dest[3] = alpha; | 256 dest[3] = alpha; |
251 | 257 |
252 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b)); | 258 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b)); |
253 vec_r = _mm_max_ps(min, vec_r); | 259 vec_r = _mm_max_ps(min, vec_r); |
254 vec_r = _mm_min_ps(max, vec_r); | 260 vec_r = _mm_min_ps(max, vec_r); |
255 result = _mm_mul_ps(vec_r, scale); | 261 result = _mm_mul_ps(vec_r, scale); |
256 | 262 |
257 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result)); | 263 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result)); |
258 | 264 |
259 dest[0] = otdata_r[output[0]]; | 265 dest[r_out] = otdata_r[output[0]]; |
260 dest[1] = otdata_g[output[1]]; | 266 dest[1] = otdata_g[output[1]]; |
261 dest[2] = otdata_b[output[2]]; | 267 dest[b_out] = otdata_b[output[2]]; |
262 } | 268 } |
OLD | NEW |