Commit 86316166 authored by noel's avatar noel Committed by Commit bot

Add bgra (z,y,x) sampled transform lookup table api

Add an API to extract a color transform lookup table in BGRA format, with
(z,y,x) sampling order (B changes the slowest, R the fastest).

See r314425 for speed results, noting that qcms_chain_transform takes 8ms
for a 32-cube since floating-point is used to compute the color transform
to maintain transform precision.

The float data produced by qcms_chain_transform() is stored in the output
in BGRA order (color components are rounded to the nearest 8-bit integer)
with time cost 0.000031 secs. Note that if the data needed re-indexing to
(x,y,z) sampled, RGBA order on writing to the output, the time cost would
be 0.00056 secs (18 times slower) [1].

[1] See r314425 review comments about sampling and pixel order.

BUG=443863

Review URL: https://codereview.chromium.org/892413005

Cr-Commit-Position: refs/heads/master@{#315188}
parent 6377eb4a
......@@ -53,5 +53,7 @@ google.patch contains the following modifications. Apply with
- https://code.google.com/p/chromium/issues/detail?id=401971
- Avoid divisions creating sample points in the float cube LUT builder
- https://code.google.com/p/chromium/issues/detail?id=443863
- Add bgra (z,y,x) sampled transform lookup table api
- https://code.google.com/p/chromium/issues/detail?id=443863
To regenerate google.patch:
git diff b8456f38 src > google.patch
......@@ -158,11 +158,15 @@ qcms_transform* qcms_transform_create(
qcms_profile* out, qcms_data_type out_type,
qcms_intent intent);
void qcms_transform_release(qcms_transform *);
qcms_bool qcms_transform_create_LUT_zyx_bgra(
qcms_profile *in, qcms_profile* out, qcms_intent intent,
int samples, unsigned char* lut);
void qcms_transform_data(qcms_transform *transform, void *src, void *dest, size_t length);
void qcms_transform_data_type(qcms_transform *transform, void *src, void *dest, size_t length, qcms_output_type type);
void qcms_transform_release(qcms_transform *);
void qcms_enable_iccv4();
#ifdef __cplusplus
......
......@@ -1167,6 +1167,71 @@ qcms_transform* qcms_transform_precacheLUT_float(qcms_transform *transform, qcms
return transform;
}
/* Create a transform LUT using the given number of sample points. The transform LUT data is stored
in the output (cube) in bgra format in zyx sample order. */
qcms_bool qcms_transform_create_LUT_zyx_bgra(qcms_profile *in, qcms_profile *out, qcms_intent intent,
int samples, unsigned char* cube)
{
uint16_t z,y,x;
uint32_t l,index;
uint32_t lutSize = 3 * samples * samples * samples;
float* src = NULL;
float* dest = NULL;
float* lut = NULL;
float inverse;
src = malloc(lutSize*sizeof(float));
dest = malloc(lutSize*sizeof(float));
if (src && dest) {
/* Prepare a list of points we want to sample: z, y, x order */
l = 0;
inverse = 1 / (float)(samples-1);
for (z = 0; z < samples; z++) {
for (y = 0; y < samples; y++) {
for (x = 0; x < samples; x++) {
src[l++] = x * inverse; // r
src[l++] = y * inverse; // g
src[l++] = z * inverse; // b
}
}
}
lut = qcms_chain_transform(in, out, src, dest, lutSize);
if (lut) {
index = l = 0;
for (z = 0; z < samples; z++) {
for (y = 0; y < samples; y++) {
for (x = 0; x < samples; x++) {
cube[index++] = (int)floorf(lut[l + 2] * 255.0f + 0.5f); // b
cube[index++] = (int)floorf(lut[l + 1] * 255.0f + 0.5f); // g
cube[index++] = (int)floorf(lut[l + 0] * 255.0f + 0.5f); // r
cube[index++] = 255; // a
l += 3;
}
}
}
}
}
// XXX: qcms_modular_transform_data may return the lut data in either the src or
// dest buffer so free src, dest, and lut with care.
if (src && lut != src)
free(src);
if (dest && lut != dest)
free(dest);
if (lut) {
free(lut);
return true;
}
return false;
}
#define NO_MEM_TRANSFORM NULL
qcms_transform* qcms_transform_create(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment