From 6f67fc29eddfb6f415f7e6a86197db5d8c8539ed Mon Sep 17 00:00:00 2001 From: Matt Sarett Date: Thu, 26 Jan 2017 13:10:49 -0500 Subject: Add SkICC::rawTransferFnData() BUG=skia: Change-Id: I912b044a0091a4d396c954d1ad1d84f5f8d50f56 Reviewed-on: https://skia-review.googlesource.com/7366 Reviewed-by: Mike Reed Commit-Queue: Matt Sarett --- include/core/SkICC.h | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/core/SkICC.h b/include/core/SkICC.h index 3780498df9..04fa1dafab 100644 --- a/include/core/SkICC.h +++ b/include/core/SkICC.h @@ -8,6 +8,7 @@ #ifndef SkICC_DEFINED #define SkICC_DEFINED +#include "SkData.h" #include "SkRefCnt.h" struct SkColorSpaceTransferFn; @@ -48,16 +49,48 @@ public: bool isNumericalTransferFn(SkColorSpaceTransferFn* fn) const; /** - * If the transfer function can be approximated as coefficients to the standard - * equation, returns true and sets |fn| to the proper values. + * Please do not call this unless isNumericalTransferFn() has been called and it + * fails. SkColorSpaceTransferFn is the preferred representation. * - * If not, returns false. This indicates one of the following: - * (1) The R, G, and B transfer functions are not the same. - * (2) The transfer function is represented as a table that is not increasing with - * end points at zero and one. - * (3) The ICC data is too complex to isolate a single transfer function. + * If it is not possible to represent the R, G, and B transfer functions numerically + * and it is still necessary to get the transfer function, this will return the + * transfer functions as three tables (R, G, and B). + * + * If possible, this will return tables of the same length as they were specified in + * the ICC profile. This means that the lengths of the three tables are not + * guaranteed to be the same. If the ICC representation was not a table, the length + * will be chosen arbitrarily. + * + * Entries in the tables are guaranteed to be in [0, 1]. + * + * This API may be deleted in favor of a numerical approximation of the raw data. + * + * This function may fail, indicating that the ICC profile does not have transfer + * functions. */ - bool approximateNumericalTransferFn(SkColorSpaceTransferFn* fn) const; + struct Channel { + // Byte offset of the start of the table in |fStorage| + size_t fOffset; + int fCount; + }; + struct Tables { + Channel fRed; + Channel fGreen; + Channel fBlue; + + const float* red() { + return (const float*) (fStorage->bytes() + fRed.fOffset); + } + const float* green() { + return (const float*) (fStorage->bytes() + fGreen.fOffset); + } + const float* blue() { + return (const float*) (fStorage->bytes() + fBlue.fOffset); + } + + sk_sp fStorage; + }; + bool rawTransferFnData(Tables* tables) const; /** * Write an ICC profile with transfer function |fn| and gamut |toXYZD50|. @@ -68,6 +101,8 @@ private: SkICC(sk_sp colorSpace); sk_sp fColorSpace; + + friend class ICCTest; }; #endif -- cgit v1.2.3