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

Side by Side Diff: third_party/qcms/src/transform-sse1.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.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
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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 *((__m64 *)&output[0]) = _mm_cvtps_pi32(result); 265 *((__m64 *)&output[0]) = _mm_cvtps_pi32(result);
266 result = _mm_movehl_ps(result, result); 266 result = _mm_movehl_ps(result, result);
267 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result); 267 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result);
268 268
269 dest[0] = otdata_r[output[0]]; 269 dest[0] = otdata_r[output[0]];
270 dest[1] = otdata_g[output[1]]; 270 dest[1] = otdata_g[output[1]];
271 dest[2] = otdata_b[output[2]]; 271 dest[2] = otdata_b[output[2]];
272 272
273 _mm_empty(); 273 _mm_empty();
274 } 274 }
275
276 void qcms_transform_data_bgra_out_lut_sse1(qcms_transform *transform,
277 unsigned char *src,
278 unsigned char *dest,
279 size_t length)
280 {
281 unsigned int i;
282 float (*mat)[4] = transform->matrix;
283 char input_back[32];
284 /* Ensure we have a buffer that's 16 byte aligned regardless of the original
285 * stack alignment. We can't use __attribute__((aligned(16))) or __declspec( align(32))
286 * because they don't work on stack variables. gcc 4.4 does do the right thi ng
287 * on x86 but that's too new for us right now. For more info: gcc bug #16660 */
288 float const * input = (float*)(((uintptr_t)&input_back[16]) & ~0xf);
289 /* share input and output locations to save having to keep the
290 * locations in separate registers */
291 uint32_t const * output = (uint32_t*)input;
292
293 /* deref *transform now to avoid it in loop */
294 const float *igtbl_r = transform->input_gamma_table_r;
295 const float *igtbl_g = transform->input_gamma_table_g;
296 const float *igtbl_b = transform->input_gamma_table_b;
297
298 /* deref *transform now to avoid it in loop */
299 const uint8_t *otdata_r = &transform->output_table_r->data[0];
300 const uint8_t *otdata_g = &transform->output_table_g->data[0];
301 const uint8_t *otdata_b = &transform->output_table_b->data[0];
302
303 /* input matrix values never change */
304 const __m128 mat0 = _mm_load_ps(mat[0]);
305 const __m128 mat1 = _mm_load_ps(mat[1]);
306 const __m128 mat2 = _mm_load_ps(mat[2]);
307
308 /* these values don't change, either */
309 const __m128 max = _mm_load_ps(clampMaxValueX4);
310 const __m128 min = _mm_setzero_ps();
311 const __m128 scale = _mm_load_ps(floatScaleX4);
312
313 /* working variables */
314 __m128 vec_r, vec_g, vec_b, result;
315 unsigned char alpha;
316
317 /* CYA */
318 if (!length)
319 return;
320
321 /* one pixel is handled outside of the loop */
322 length--;
323
324 /* setup for transforming 1st pixel */
325 vec_b = _mm_load_ss(&igtbl_b[src[0]]);
326 vec_g = _mm_load_ss(&igtbl_g[src[1]]);
327 vec_r = _mm_load_ss(&igtbl_r[src[2]]);
328 alpha = src[3];
329 src += 4;
330
331 /* transform all but final pixel */
332
333 for (i=0; i<length; i++)
334 {
335 /* position values from gamma tables */
336 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0);
337 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0);
338 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0);
339
340 /* gamma * matrix */
341 vec_r = _mm_mul_ps(vec_r, mat0);
342 vec_g = _mm_mul_ps(vec_g, mat1);
343 vec_b = _mm_mul_ps(vec_b, mat2);
344
345 /* store alpha for this pixel; load alpha for next */
346 dest[3] = alpha;
347 alpha = src[3];
348
349 /* crunch, crunch, crunch */
350 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b));
351 vec_r = _mm_max_ps(min, vec_r);
352 vec_r = _mm_min_ps(max, vec_r);
353 result = _mm_mul_ps(vec_r, scale);
354
355 /* store calc'd output tables indices */
356 *((__m64 *)&output[0]) = _mm_cvtps_pi32(result);
357 result = _mm_movehl_ps(result, result);
358 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result);
359
360 /* load gamma values for next loop while store completes */
361 vec_b = _mm_load_ss(&igtbl_b[src[0]]);
362 vec_g = _mm_load_ss(&igtbl_g[src[1]]);
363 vec_r = _mm_load_ss(&igtbl_r[src[2]]);
364 src += 4;
365
366 /* use calc'd indices to output RGB values */
367 dest[0] = otdata_b[output[2]];
368 dest[1] = otdata_g[output[1]];
369 dest[2] = otdata_r[output[0]];
370 dest += 4;
371 }
372
373 /* handle final (maybe only) pixel */
374
375 vec_r = _mm_shuffle_ps(vec_r, vec_r, 0);
376 vec_g = _mm_shuffle_ps(vec_g, vec_g, 0);
377 vec_b = _mm_shuffle_ps(vec_b, vec_b, 0);
378
379 vec_r = _mm_mul_ps(vec_r, mat0);
380 vec_g = _mm_mul_ps(vec_g, mat1);
381 vec_b = _mm_mul_ps(vec_b, mat2);
382
383 dest[3] = alpha;
384
385 vec_r = _mm_add_ps(vec_r, _mm_add_ps(vec_g, vec_b));
386 vec_r = _mm_max_ps(min, vec_r);
387 vec_r = _mm_min_ps(max, vec_r);
388 result = _mm_mul_ps(vec_r, scale);
389
390 *((__m64 *)&output[0]) = _mm_cvtps_pi32(result);
391 result = _mm_movehl_ps(result, result);
392 *((__m64 *)&output[2]) = _mm_cvtps_pi32(result);
393
394 dest[0] = otdata_b[output[2]];
395 dest[1] = otdata_g[output[1]];
396 dest[2] = otdata_r[output[0]];
397
398 _mm_empty();
399 }
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