Add NewRGB() with float gamma to SkColorSpace public API

Necessary because PNGs like to specify their gamma this way.

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3402

Change-Id: I399984d611db907b115b345df1afc88d39326fbb
Reviewed-on: https://skia-review.googlesource.com/3402
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>
This commit is contained in:
Matt Sarett 2016-10-13 18:24:20 -04:00 committed by Skia Commit-Bot
parent 285db44562
commit c434f5122a
6 changed files with 13 additions and 14 deletions

View File

@ -89,12 +89,14 @@ public:
/**
* Create an SkColorSpace from a transfer function and a color gamut.
*
* Transfer function can be specified as a render target or as the coefficients to an equation.
* Transfer function can be specified as a render target, as the coefficients to an equation,
* or as three exponents (R, G, B).
* Gamut is specified using the matrix transformation to XYZ D50.
*/
static sk_sp<SkColorSpace> NewRGB(RenderTargetGamma gamma, const SkMatrix44& toXYZD50);
static sk_sp<SkColorSpace> NewRGB(const SkColorSpaceTransferFn& coeffs,
const SkMatrix44& toXYZD50);
static sk_sp<SkColorSpace> NewRGB(const float exponents[3], const SkMatrix44& toXYZD50);
/**
* Create a common, named SkColorSpace.

View File

@ -8,7 +8,7 @@
#include "SkBitmap.h"
#include "SkCodecPriv.h"
#include "SkColorPriv.h"
#include "SkColorSpace_Base.h"
#include "SkColorSpace.h"
#include "SkColorTable.h"
#include "SkMath.h"
#include "SkOpts.h"
@ -387,7 +387,7 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) {
gammas[1] = value;
gammas[2] = value;
return SkColorSpace_Base::NewRGB(gammas, toXYZD50);
return SkColorSpace::NewRGB(gammas, toXYZD50);
}
// Default to sRGB gamma if the image has color space information,
@ -408,7 +408,7 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) {
SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor);
toXYZD50.set3x3RowMajorf(gSRGB_toXYZD50);
return SkColorSpace_Base::NewRGB(gammas, toXYZD50);
return SkColorSpace::NewRGB(gammas, toXYZD50);
}
#endif // LIBPNG >= 1.6

View File

@ -138,7 +138,7 @@ static bool xyz_almost_equal(const SkMatrix44& toXYZD50, const float* standard)
color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f);
}
sk_sp<SkColorSpace> SkColorSpace_Base::NewRGB(const float values[3], const SkMatrix44& toXYZD50) {
sk_sp<SkColorSpace> SkColorSpace::NewRGB(const float values[3], const SkMatrix44& toXYZD50) {
if (0.0f > values[0] || 0.0f > values[1] || 0.0f > values[2]) {
return nullptr;
}
@ -560,7 +560,7 @@ sk_sp<SkColorSpace> SkColorSpace::Deserialize(const void* data, size_t length) {
SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor);
toXYZ.set3x4RowMajorf((const float*) data);
return SkColorSpace_Base::NewRGB(gammas, toXYZ);
return SkColorSpace::NewRGB(gammas, toXYZ);
}
case ColorSpaceHeader::kTransferFn_Flag: {
if (length < 19 * sizeof(float)) {

View File

@ -169,9 +169,6 @@ struct SkColorLookUpTable : public SkRefCnt {
class SkColorSpace_Base : public SkColorSpace {
public:
static sk_sp<SkColorSpace> NewRGB(const float gammas[3], const SkMatrix44& toXYZD50);
SkGammaNamed gammaNamed() const { return fGammaNamed; }
const SkGammas* gammas() const { return fGammas.get(); }

View File

@ -228,7 +228,7 @@ DEF_TEST(ColorSpace_Serialize, r) {
const float gammas[] = { 1.1f, 1.2f, 1.7f, };
SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor);
test_serialize(r, SkColorSpace_Base::NewRGB(gammas, toXYZ).get(), false);
test_serialize(r, SkColorSpace::NewRGB(gammas, toXYZ).get(), false);
SkColorSpaceTransferFn fn;
fn.fA = 1.0f;
@ -256,9 +256,9 @@ DEF_TEST(ColorSpace_Equals, r) {
const float gammas1[] = { 1.1f, 1.2f, 1.3f, };
const float gammas2[] = { 1.1f, 1.2f, 1.7f, };
SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor);
sk_sp<SkColorSpace> rgb1 = SkColorSpace_Base::NewRGB(gammas1, toXYZ);
sk_sp<SkColorSpace> rgb2 = SkColorSpace_Base::NewRGB(gammas2, toXYZ);
sk_sp<SkColorSpace> rgb3 = SkColorSpace_Base::NewRGB(gammas1, toXYZ);
sk_sp<SkColorSpace> rgb1 = SkColorSpace::NewRGB(gammas1, toXYZ);
sk_sp<SkColorSpace> rgb2 = SkColorSpace::NewRGB(gammas2, toXYZ);
sk_sp<SkColorSpace> rgb3 = SkColorSpace::NewRGB(gammas1, toXYZ);
SkColorSpaceTransferFn fn;
fn.fA = 1.0f;

View File

@ -923,7 +923,7 @@ static void test_surface_creation_and_snapshot_with_color_space(
auto adobeColorSpace = SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named);
SkMatrix44 srgbMatrix = as_CSB(srgbColorSpace)->toXYZD50();
const float oddGamma[] = { 2.4f, 2.4f, 2.4f };
auto oddColorSpace = SkColorSpace_Base::NewRGB(oddGamma, srgbMatrix);
auto oddColorSpace = SkColorSpace::NewRGB(oddGamma, srgbMatrix);
auto linearColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGBLinear_Named);
const struct {