michael@0: /* vim: set ts=8 sw=8 noexpandtab: */ michael@0: // qcms michael@0: // Copyright (C) 2009 Mozilla Corporation michael@0: // Copyright (C) 1998-2007 Marti Maria michael@0: // michael@0: // Permission is hereby granted, free of charge, to any person obtaining michael@0: // a copy of this software and associated documentation files (the "Software"), michael@0: // to deal in the Software without restriction, including without limitation michael@0: // the rights to use, copy, modify, merge, publish, distribute, sublicense, michael@0: // and/or sell copies of the Software, and to permit persons to whom the Software michael@0: // is furnished to do so, subject to the following conditions: michael@0: // michael@0: // The above copyright notice and this permission notice shall be included in michael@0: // all copies or substantial portions of the Software. michael@0: // michael@0: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, michael@0: // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO michael@0: // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND michael@0: // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE michael@0: // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION michael@0: // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION michael@0: // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. michael@0: michael@0: #include michael@0: michael@0: #include "qcmsint.h" michael@0: michael@0: #define FLOATSCALE (float)(PRECACHE_OUTPUT_SIZE) michael@0: #define CLAMPMAXVAL (((float) (PRECACHE_OUTPUT_SIZE - 1)) / PRECACHE_OUTPUT_SIZE) michael@0: static const ALIGN float floatScaleX4 = FLOATSCALE; michael@0: static const ALIGN float clampMaxValueX4 = CLAMPMAXVAL; michael@0: michael@0: inline vector float load_aligned_float(float *dataPtr) michael@0: { michael@0: vector float data = vec_lde(0, dataPtr); michael@0: vector unsigned char moveToStart = vec_lvsl(0, dataPtr); michael@0: return vec_perm(data, data, moveToStart); michael@0: } michael@0: michael@0: void qcms_transform_data_rgb_out_lut_altivec(qcms_transform *transform, michael@0: unsigned char *src, michael@0: unsigned char *dest, michael@0: size_t length) michael@0: { michael@0: unsigned int i; michael@0: float (*mat)[4] = transform->matrix; michael@0: char input_back[32]; michael@0: /* Ensure we have a buffer that's 16 byte aligned regardless of the original michael@0: * stack alignment. We can't use __attribute__((aligned(16))) or __declspec(align(32)) michael@0: * because they don't work on stack variables. gcc 4.4 does do the right thing michael@0: * on x86 but that's too new for us right now. For more info: gcc bug #16660 */ michael@0: float const *input = (float*)(((uintptr_t)&input_back[16]) & ~0xf); michael@0: /* share input and output locations to save having to keep the michael@0: * locations in separate registers */ michael@0: uint32_t const *output = (uint32_t*)input; michael@0: michael@0: /* deref *transform now to avoid it in loop */ michael@0: const float *igtbl_r = transform->input_gamma_table_r; michael@0: const float *igtbl_g = transform->input_gamma_table_g; michael@0: const float *igtbl_b = transform->input_gamma_table_b; michael@0: michael@0: /* deref *transform now to avoid it in loop */ michael@0: const uint8_t *otdata_r = &transform->output_table_r->data[0]; michael@0: const uint8_t *otdata_g = &transform->output_table_g->data[0]; michael@0: const uint8_t *otdata_b = &transform->output_table_b->data[0]; michael@0: michael@0: /* input matrix values never change */ michael@0: const vector float mat0 = vec_ldl(0, (vector float*)mat[0]); michael@0: const vector float mat1 = vec_ldl(0, (vector float*)mat[1]); michael@0: const vector float mat2 = vec_ldl(0, (vector float*)mat[2]); michael@0: michael@0: /* these values don't change, either */ michael@0: const vector float max = vec_splat(vec_lde(0, (float*)&clampMaxValueX4), 0); michael@0: const vector float min = (vector float)vec_splat_u32(0); michael@0: const vector float scale = vec_splat(vec_lde(0, (float*)&floatScaleX4), 0); michael@0: michael@0: /* working variables */ michael@0: vector float vec_r, vec_g, vec_b, result; michael@0: michael@0: /* CYA */ michael@0: if (!length) michael@0: return; michael@0: michael@0: /* one pixel is handled outside of the loop */ michael@0: length--; michael@0: michael@0: /* setup for transforming 1st pixel */ michael@0: vec_r = load_aligned_float((float*)&igtbl_r[src[0]]); michael@0: vec_g = load_aligned_float((float*)&igtbl_r[src[1]]); michael@0: vec_b = load_aligned_float((float*)&igtbl_r[src[2]]); michael@0: src += 3; michael@0: michael@0: /* transform all but final pixel */ michael@0: michael@0: for (i=0; imatrix; michael@0: char input_back[32]; michael@0: /* Ensure we have a buffer that's 16 byte aligned regardless of the original michael@0: * stack alignment. We can't use __attribute__((aligned(16))) or __declspec(align(32)) michael@0: * because they don't work on stack variables. gcc 4.4 does do the right thing michael@0: * on x86 but that's too new for us right now. For more info: gcc bug #16660 */ michael@0: float const *input = (float*)(((uintptr_t)&input_back[16]) & ~0xf); michael@0: /* share input and output locations to save having to keep the michael@0: * locations in separate registers */ michael@0: uint32_t const *output = (uint32_t*)input; michael@0: michael@0: /* deref *transform now to avoid it in loop */ michael@0: const float *igtbl_r = transform->input_gamma_table_r; michael@0: const float *igtbl_g = transform->input_gamma_table_g; michael@0: const float *igtbl_b = transform->input_gamma_table_b; michael@0: michael@0: /* deref *transform now to avoid it in loop */ michael@0: const uint8_t *otdata_r = &transform->output_table_r->data[0]; michael@0: const uint8_t *otdata_g = &transform->output_table_g->data[0]; michael@0: const uint8_t *otdata_b = &transform->output_table_b->data[0]; michael@0: michael@0: /* input matrix values never change */ michael@0: const vector float mat0 = vec_ldl(0, (vector float*)mat[0]); michael@0: const vector float mat1 = vec_ldl(0, (vector float*)mat[1]); michael@0: const vector float mat2 = vec_ldl(0, (vector float*)mat[2]); michael@0: michael@0: /* these values don't change, either */ michael@0: const vector float max = vec_splat(vec_lde(0, (float*)&clampMaxValueX4), 0); michael@0: const vector float min = (vector float)vec_splat_u32(0); michael@0: const vector float scale = vec_splat(vec_lde(0, (float*)&floatScaleX4), 0); michael@0: michael@0: /* working variables */ michael@0: vector float vec_r, vec_g, vec_b, result; michael@0: unsigned char alpha; michael@0: michael@0: /* CYA */ michael@0: if (!length) michael@0: return; michael@0: michael@0: /* one pixel is handled outside of the loop */ michael@0: length--; michael@0: michael@0: /* setup for transforming 1st pixel */ michael@0: vec_r = load_aligned_float((float*)&igtbl_r[src[0]]); michael@0: vec_g = load_aligned_float((float*)&igtbl_r[src[1]]); michael@0: vec_b = load_aligned_float((float*)&igtbl_r[src[2]]); michael@0: alpha = src[3]; michael@0: src += 4; michael@0: michael@0: /* transform all but final pixel */ michael@0: michael@0: for (i=0; i