Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: third_party/qcms/src/transform-sse1.c

Issue 9969111: Adds qcms to third_party for use in handling ICC color profiles. (Closed) Base URL: http://git.chromium.org/chromium/src.git@bug143
Patch Set: Moved downloaded src to third_party/qcms/src Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/qcms/src/transform.c ('k') | third_party/qcms/src/transform-sse2.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // qcms
2 // Copyright (C) 2009 Mozilla Foundation
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
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
9 // is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
16 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 #include <xmmintrin.h>
23
24 #include "qcmsint.h"
25
26 /* pre-shuffled: just load these into XMM reg instead of load-scalar/shufps sequ ence */
27 #define FLOATSCALE (float)(PRECACHE_OUTPUT_SIZE)
28 #define CLAMPMAXVAL ( ((float) (PRECACHE_OUTPUT_SIZE - 1)) / PRECACHE_OUTPUT_SIZ E )
29 static const ALIGN float floatScaleX4[4] =
30 { FLOATSCALE, FLOATSCALE, FLOATSCALE, FLOATSCALE};
31 static const ALIGN float clampMaxValueX4[4] =
32 { CLAMPMAXVAL, CLAMPMAXVAL, CLAMPMAXVAL, CLAMPMAXVAL};
33
34 void qcms_transform_data_rgb_out_lut_sse1(qcms_transform *transform,
35 unsigned char *src,
36 unsigned char *dest,
37 size_t length)
38 {
39 unsigned int i;
40 float (*mat)[4] = transform->matrix;
41 char input_back[32];
42 /* 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 * 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 float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf);
47 /* share input and output locations to save having to keep the
48 * locations in separate registers */
49 uint32_t const * output = (uint32_t*)input;
50
51 /* deref *transform now to avoid it in loop */
52 const float *igtbl_r = transform->input_gamma_table_r;
53 const float *igtbl_g = transform->input_gamma_table_g;
54 const float *igtbl_b = transform->input_gamma_table_b;
55
56 /* deref *transform now to avoid it in loop */
57 const uint8_t *otdata_r = &transform->output_table_r->data[0];
58 const uint8_t *otdata_g = &transform->output_table_g->data[0];
59 const uint8_t *otdata_b = &transform->output_table_b->data[0];
60
61 /* input matrix values never change */
62 const __m128 mat0 = _mm_load_ps(mat[0]);
63 const __m128 mat1 = _mm_load_ps(mat[1]);
64 const __m128 mat2 = _mm_load_ps(mat[2]);
65
66 /* these values don't change, either */
67 const __m128 max = _mm_load_ps(clampMaxValueX4);
68 const __m128 min = _mm_setzero_ps();
69 const __m128 scale = _mm_load_ps(floatScaleX4);
70
71 /* working variables */
72 __m128 vec_r, vec_g, vec_b, result;
73
74 /* CYA */
75 if (!length)
76 return;
77
78 /* one pixel is handled outside of the loop */
79 length--;
80
81 /* setup for transforming 1st pixel */
82 vec_r = _mm_load_ss(&igtbl_r[src[0]]);
83 vec_g = _mm_load_ss(&igtbl_g[src[1]]);
84 vec_b = _mm_load_ss(&igtbl_b[src[2]]);
85 src += 3;
86
87 /* transform all but final pixel */
88
89 for (i=0; i<length; i++)
90 {
91 /* position values from gamma tables */
92 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0);
93 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0);
94 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0);
95
96 /* gamma * matrix */
97 vec_r = _mm_mul_ps(vec_r, mat0);
98 vec_g = _mm_mul_ps(vec_g, mat1);
99 vec_b = _mm_mul_ps(vec_b, mat2);
100
101 /* crunch, crunch, crunch */
102 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b));
103 vec_r = _mm_max_ps(min, vec_r);
104 vec_r = _mm_min_ps(max, vec_r);
105 result = _mm_mul_ps(vec_r, scale);
106
107 /* store calc'd output tables indices */
108 *((__m64 *)&output[0]) = _mm_cvtps_pi32(result);
109 result = _mm_movehl_ps(result, result);
110 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result) ;
111
112 /* load for next loop while store completes */
113 vec_r = _mm_load_ss(&igtbl_r[src[0]]);
114 vec_g = _mm_load_ss(&igtbl_g[src[1]]);
115 vec_b = _mm_load_ss(&igtbl_b[src[2]]);
116 src += 3;
117
118 /* use calc'd indices to output RGB values */
119 dest[0] = otdata_r[output[0]];
120 dest[1] = otdata_g[output[1]];
121 dest[2] = otdata_b[output[2]];
122 dest += 3;
123 }
124
125 /* handle final (maybe only) pixel */
126
127 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0);
128 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0);
129 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0);
130
131 vec_r = _mm_mul_ps(vec_r, mat0);
132 vec_g = _mm_mul_ps(vec_g, mat1);
133 vec_b = _mm_mul_ps(vec_b, mat2);
134
135 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b));
136 vec_r = _mm_max_ps(min, vec_r);
137 vec_r = _mm_min_ps(max, vec_r);
138 result = _mm_mul_ps(vec_r, scale);
139
140 *((__m64 *)&output[0]) = _mm_cvtps_pi32(result);
141 result = _mm_movehl_ps(result, result);
142 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result);
143
144 dest[0] = otdata_r[output[0]];
145 dest[1] = otdata_g[output[1]];
146 dest[2] = otdata_b[output[2]];
147
148 _mm_empty();
149 }
150
151 void qcms_transform_data_rgba_out_lut_sse1(qcms_transform *transform,
152 unsigned char *src,
153 unsigned char *dest,
154 size_t length)
155 {
156 unsigned int i;
157 float (*mat)[4] = transform->matrix;
158 char input_back[32];
159 /* Ensure we have a buffer that's 16 byte aligned regardless of the original
160 * stack alignment. We can't use __attribute__((aligned(16))) or __declspec( align(32))
161 * because they don't work on stack variables. gcc 4.4 does do the right thi ng
162 * on x86 but that's too new for us right now. For more info: gcc bug #16660 */
163 float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf);
164 /* share input and output locations to save having to keep the
165 * locations in separate registers */
166 uint32_t const * output = (uint32_t*)input;
167
168 /* deref *transform now to avoid it in loop */
169 const float *igtbl_r = transform->input_gamma_table_r;
170 const float *igtbl_g = transform->input_gamma_table_g;
171 const float *igtbl_b = transform->input_gamma_table_b;
172
173 /* deref *transform now to avoid it in loop */
174 const uint8_t *otdata_r = &transform->output_table_r->data[0];
175 const uint8_t *otdata_g = &transform->output_table_g->data[0];
176 const uint8_t *otdata_b = &transform->output_table_b->data[0];
177
178 /* input matrix values never change */
179 const __m128 mat0 = _mm_load_ps(mat[0]);
180 const __m128 mat1 = _mm_load_ps(mat[1]);
181 const __m128 mat2 = _mm_load_ps(mat[2]);
182
183 /* these values don't change, either */
184 const __m128 max = _mm_load_ps(clampMaxValueX4);
185 const __m128 min = _mm_setzero_ps();
186 const __m128 scale = _mm_load_ps(floatScaleX4);
187
188 /* working variables */
189 __m128 vec_r, vec_g, vec_b, result;
190 unsigned char alpha;
191
192 /* CYA */
193 if (!length)
194 return;
195
196 /* one pixel is handled outside of the loop */
197 length--;
198
199 /* setup for transforming 1st pixel */
200 vec_r = _mm_load_ss(&igtbl_r[src[0]]);
201 vec_g = _mm_load_ss(&igtbl_g[src[1]]);
202 vec_b = _mm_load_ss(&igtbl_b[src[2]]);
203 alpha = src[3];
204 src += 4;
205
206 /* transform all but final pixel */
207
208 for (i=0; i<length; i++)
209 {
210 /* position values from gamma tables */
211 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0);
212 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0);
213 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0);
214
215 /* gamma * matrix */
216 vec_r = _mm_mul_ps(vec_r, mat0);
217 vec_g = _mm_mul_ps(vec_g, mat1);
218 vec_b = _mm_mul_ps(vec_b, mat2);
219
220 /* store alpha for this pixel; load alpha for next */
221 dest[3] = alpha;
222 alpha = src[3];
223
224 /* crunch, crunch, crunch */
225 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b));
226 vec_r = _mm_max_ps(min, vec_r);
227 vec_r = _mm_min_ps(max, vec_r);
228 result = _mm_mul_ps(vec_r, scale);
229
230 /* store calc'd output tables indices */
231 *((__m64 *)&output[0]) = _mm_cvtps_pi32(result);
232 result = _mm_movehl_ps(result, result);
233 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result);
234
235 /* load gamma values for next loop while store completes */
236 vec_r = _mm_load_ss(&igtbl_r[src[0]]);
237 vec_g = _mm_load_ss(&igtbl_g[src[1]]);
238 vec_b = _mm_load_ss(&igtbl_b[src[2]]);
239 src += 4;
240
241 /* use calc'd indices to output RGB values */
242 dest[0] = otdata_r[output[0]];
243 dest[1] = otdata_g[output[1]];
244 dest[2] = otdata_b[output[2]];
245 dest += 4;
246 }
247
248 /* handle final (maybe only) pixel */
249
250 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0);
251 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0);
252 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0);
253
254 vec_r = _mm_mul_ps(vec_r, mat0);
255 vec_g = _mm_mul_ps(vec_g, mat1);
256 vec_b = _mm_mul_ps(vec_b, mat2);
257
258 dest[3] = alpha;
259
260 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b));
261 vec_r = _mm_max_ps(min, vec_r);
262 vec_r = _mm_min_ps(max, vec_r);
263 result = _mm_mul_ps(vec_r, scale);
264
265 *((__m64 *)&output[0]) = _mm_cvtps_pi32(result);
266 result = _mm_movehl_ps(result, result);
267 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result);
268
269 dest[0] = otdata_r[output[0]];
270 dest[1] = otdata_g[output[1]];
271 dest[2] = otdata_b[output[2]];
272
273 _mm_empty();
274 }
OLDNEW
« no previous file with comments | « third_party/qcms/src/transform.c ('k') | third_party/qcms/src/transform-sse2.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698