diff options
author | noel <noel@chromium.org> | 2015-02-06 22:16:50 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-07 06:17:36 +0000 |
commit | 86316166abe8d0bc597f4482109d7afcac1f0fe2 (patch) | |
tree | e37dac711f1b5cd0e7f9f33e8db5d8da05aefc4f | |
parent | 6377eb4a7055d3135e286e71b563ccd100ed4669 (diff) | |
download | chromium_src-86316166abe8d0bc597f4482109d7afcac1f0fe2.zip chromium_src-86316166abe8d0bc597f4482109d7afcac1f0fe2.tar.gz chromium_src-86316166abe8d0bc597f4482109d7afcac1f0fe2.tar.bz2 |
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}
-rw-r--r-- | third_party/qcms/README.chromium | 2 | ||||
-rw-r--r-- | third_party/qcms/src/qcms.h | 6 | ||||
-rw-r--r-- | third_party/qcms/src/transform.c | 65 |
3 files changed, 72 insertions, 1 deletions
diff --git a/third_party/qcms/README.chromium b/third_party/qcms/README.chromium index 8fb3768..368d604 100644 --- a/third_party/qcms/README.chromium +++ b/third_party/qcms/README.chromium @@ -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 diff --git a/third_party/qcms/src/qcms.h b/third_party/qcms/src/qcms.h index c69a772..e9c0b09 100644 --- a/third_party/qcms/src/qcms.h +++ b/third_party/qcms/src/qcms.h @@ -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 diff --git a/third_party/qcms/src/transform.c b/third_party/qcms/src/transform.c index 9fd8238..f669a6b 100644 --- a/third_party/qcms/src/transform.c +++ b/third_party/qcms/src/transform.c @@ -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( |