From 7b67b4af1fcfa76a0551f9055d2b6336c1a66b75 Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Thu, 12 Apr 2018 09:21:02 -0400 Subject: skcms→1654786 concat gamut transform matrices together MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No-Tree-Checks: true Change-Id: Ibfbbfe35caf9e2ed8a80aa9add2c4cae50585120 Reviewed-on: https://skia-review.googlesource.com/120997 Reviewed-by: Mike Klein Commit-Queue: Mike Klein --- third_party/skcms/src/Transform.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/third_party/skcms/src/Transform.c b/third_party/skcms/src/Transform.c index 1f46e35f75..7428ea6be4 100644 --- a/third_party/skcms/src/Transform.c +++ b/third_party/skcms/src/Transform.c @@ -301,6 +301,17 @@ static size_t bytes_per_pixel(skcms_PixelFormat fmt) { return 0; } +static skcms_Matrix3x3 concat_3x3(const skcms_Matrix3x3* A, const skcms_Matrix3x3* B) { + skcms_Matrix3x3 m = {{ {0,0,0}, {0,0,0}, {0,0,0} }}; + for (int r = 0; r < 3; r++) + for (int c = 0; c < 3; c++) { + m.vals[r][c] = A->vals[r][0] * B->vals[0][c] + + A->vals[r][1] * B->vals[1][c] + + A->vals[r][2] * B->vals[2][c]; + } + return m; +} + bool skcms_Transform(const void* src, skcms_PixelFormat srcFmt, skcms_AlphaFormat srcAlpha, @@ -467,9 +478,11 @@ bool skcms_Transform(const void* src, if (!skcms_Matrix3x3_invert(&dstProfile->toXYZD50, &from_xyz)) { return false; } - // TODO: concat these here and only append one matrix_3x3 op. - *ops++ = Op_matrix_3x3; *args++ = to_xyz; - *ops++ = Op_matrix_3x3; *args++ = &from_xyz; + // Concat the entire gamut transform into from_xyz, + // now slightly misnamed but it's a handy spot to stash the result. + from_xyz = concat_3x3(&from_xyz, to_xyz); + *ops++ = Op_matrix_3x3; + *args++ = &from_xyz; } // Encode back to dst RGB using its parametric transfer functions. -- cgit v1.2.3