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

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

Issue 10384114: Added BGRA support to qcms. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 7 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-sse1.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 vec_r = _mm_min_ps(max, vec_r); 135 vec_r = _mm_min_ps(max, vec_r);
136 result = _mm_mul_ps(vec_r, scale); 136 result = _mm_mul_ps(vec_r, scale);
137 137
138 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result)); 138 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result));
139 139
140 dest[0] = otdata_r[output[0]]; 140 dest[0] = otdata_r[output[0]];
141 dest[1] = otdata_g[output[1]]; 141 dest[1] = otdata_g[output[1]];
142 dest[2] = otdata_b[output[2]]; 142 dest[2] = otdata_b[output[2]];
143 } 143 }
144 144
145 void qcms_transform_data_bgra_out_lut_sse2(qcms_transform *transform,
146 unsigned char *src,
147 unsigned char *dest,
148 size_t length)
149 {
150 unsigned int i;
151 float (*mat)[4] = transform->matrix;
152 char input_back[32];
153 /* 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))
155 * 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 */
157 float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf);
158 /* share input and output locations to save having to keep the
159 * locations in separate registers */
160 uint32_t const * output = (uint32_t*)input;
161
162 /* deref *transform now to avoid it in loop */
163 const float *igtbl_r = transform->input_gamma_table_r;
164 const float *igtbl_g = transform->input_gamma_table_g;
165 const float *igtbl_b = transform->input_gamma_table_b;
166
167 /* deref *transform now to avoid it in loop */
168 const uint8_t *otdata_r = &transform->output_table_r->data[0];
169 const uint8_t *otdata_g = &transform->output_table_g->data[0];
170 const uint8_t *otdata_b = &transform->output_table_b->data[0];
171
172 /* input matrix values never change */
173 const __m128 mat0 = _mm_load_ps(mat[0]);
174 const __m128 mat1 = _mm_load_ps(mat[1]);
175 const __m128 mat2 = _mm_load_ps(mat[2]);
176
177 /* these values don't change, either */
178 const __m128 max = _mm_load_ps(clampMaxValueX4);
179 const __m128 min = _mm_setzero_ps();
180 const __m128 scale = _mm_load_ps(floatScaleX4);
181
182 /* working variables */
183 __m128 vec_r, vec_g, vec_b, result;
184 unsigned char alpha;
185
186 /* CYA */
187 if (!length)
188 return;
189
190 /* one pixel is handled outside of the loop */
191 length--;
192
193 /* setup for transforming 1st pixel */
194 vec_b = _mm_load_ss(&igtbl_b[src[0]]);
195 vec_g = _mm_load_ss(&igtbl_g[src[1]]);
196 vec_r = _mm_load_ss(&igtbl_r[src[2]]);
197 alpha = src[3];
198 src += 4;
199
200 /* transform all but final pixel */
201
202 for (i=0; i<length; i++)
203 {
204 /* position values from gamma tables */
205 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0);
206 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0);
207 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0);
208
209 /* gamma * matrix */
210 vec_r = _mm_mul_ps(vec_r, mat0);
211 vec_g = _mm_mul_ps(vec_g, mat1);
212 vec_b = _mm_mul_ps(vec_b, mat2);
213
214 /* store alpha for this pixel; load alpha for next */
215 dest[3] = alpha;
216 alpha = src[3];
217
218 /* crunch, crunch, crunch */
219 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b));
220 vec_r = _mm_max_ps(min, vec_r);
221 vec_r = _mm_min_ps(max, vec_r);
222 result = _mm_mul_ps(vec_r, scale);
223
224 /* store calc'd output tables indices */
225 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result));
226
227 /* load gamma values for next loop while store completes */
228 vec_b = _mm_load_ss(&igtbl_b[src[0]]);
229 vec_g = _mm_load_ss(&igtbl_g[src[1]]);
230 vec_r = _mm_load_ss(&igtbl_r[src[2]]);
231 src += 4;
232
233 /* use calc'd indices to output RGB values */
234 dest[0] = otdata_b[output[2]];
235 dest[1] = otdata_g[output[1]];
236 dest[2] = otdata_r[output[0]];
237 dest += 4;
238 }
239
240 /* handle final (maybe only) pixel */
241
242 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0);
243 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0);
244 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0);
245
246 vec_r = _mm_mul_ps(vec_r, mat0);
247 vec_g = _mm_mul_ps(vec_g, mat1);
248 vec_b = _mm_mul_ps(vec_b, mat2);
249
250 dest[3] = alpha;
251
252 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b));
253 vec_r = _mm_max_ps(min, vec_r);
254 vec_r = _mm_min_ps(max, vec_r);
255 result = _mm_mul_ps(vec_r, scale);
256
257 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result));
258
259 dest[0] = otdata_b[output[2]];
260 dest[1] = otdata_g[output[1]];
261 dest[2] = otdata_r[output[0]];
262 }
145 void qcms_transform_data_rgba_out_lut_sse2(qcms_transform *transform, 263 void qcms_transform_data_rgba_out_lut_sse2(qcms_transform *transform,
146 unsigned char *src, 264 unsigned char *src,
147 unsigned char *dest, 265 unsigned char *dest,
148 size_t length) 266 size_t length)
149 { 267 {
150 unsigned int i; 268 unsigned int i;
151 float (*mat)[4] = transform->matrix; 269 float (*mat)[4] = transform->matrix;
152 char input_back[32]; 270 char input_back[32];
153 /* Ensure we have a buffer that's 16 byte aligned regardless of the original 271 /* 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)) 272 * stack alignment. We can't use __attribute__((aligned(16))) or __declspec( align(32))
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 vec_r = _mm_max_ps(min, vec_r); 371 vec_r = _mm_max_ps(min, vec_r);
254 vec_r = _mm_min_ps(max, vec_r); 372 vec_r = _mm_min_ps(max, vec_r);
255 result = _mm_mul_ps(vec_r, scale); 373 result = _mm_mul_ps(vec_r, scale);
256 374
257 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result)); 375 _mm_store_si128((__m128i*)output, _mm_cvtps_epi32(result));
258 376
259 dest[0] = otdata_r[output[0]]; 377 dest[0] = otdata_r[output[0]];
260 dest[1] = otdata_g[output[1]]; 378 dest[1] = otdata_g[output[1]];
261 dest[2] = otdata_b[output[2]]; 379 dest[2] = otdata_b[output[2]];
262 } 380 }
OLDNEW
« no previous file with comments | « third_party/qcms/src/transform-sse1.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698