Remove unneeded SkColorSpace constructor
TBR=reed@google.com BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4140 Change-Id: Ib1c477b6b56a100ea449ffa20bdf18041c044a78 Reviewed-on: https://skia-review.googlesource.com/4140 Reviewed-by: Matt Sarett <msarett@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Matt Sarett <msarett@google.com>
This commit is contained in:
parent
8c05b450d2
commit
99e3f7d6fc
@ -175,10 +175,13 @@ void ColorCodecBench::onDelayedSetup() {
|
||||
}
|
||||
|
||||
if (FLAGS_nonstd) {
|
||||
float gammas[3] = { 1.8f, 2.0f, 2.5f, };
|
||||
SkColorSpaceTransferFn gamma;
|
||||
gamma.fA = 1.0f;
|
||||
gamma.fB = gamma.fC = gamma.fD = gamma.fE = gamma.fF = 0.0f;
|
||||
gamma.fG = 4.0f;
|
||||
SkMatrix44 matrix = SkMatrix44(SkMatrix44::kUninitialized_Constructor);
|
||||
matrix.set3x3(0.30f, 0.31f, 0.28f, 0.32f, 0.33f, 0.29f, 0.27f, 0.30f, 0.30f);
|
||||
fDstSpace = SkColorSpace::MakeRGB(gammas, matrix);
|
||||
fDstSpace = SkColorSpace::MakeRGB(gamma, matrix);
|
||||
}
|
||||
|
||||
fDstInfo = fDstInfo.makeColorSpace(fDstSpace);
|
||||
|
@ -96,7 +96,6 @@ public:
|
||||
static sk_sp<SkColorSpace> MakeRGB(RenderTargetGamma gamma, const SkMatrix44& toXYZD50);
|
||||
static sk_sp<SkColorSpace> MakeRGB(const SkColorSpaceTransferFn& coeffs,
|
||||
const SkMatrix44& toXYZD50);
|
||||
static sk_sp<SkColorSpace> MakeRGB(const float exponents[3], const SkMatrix44& toXYZD50);
|
||||
|
||||
/**
|
||||
* Create a common, named SkColorSpace.
|
||||
@ -116,9 +115,6 @@ public:
|
||||
const SkMatrix44& toXYZD50) {
|
||||
return MakeRGB(coeffs, toXYZD50);
|
||||
}
|
||||
static sk_sp<SkColorSpace> NewRGB(const float exponents[3], const SkMatrix44& toXYZD50) {
|
||||
return MakeRGB(exponents, toXYZD50);
|
||||
}
|
||||
static sk_sp<SkColorSpace> NewNamed(Named named) { return MakeNamed(named); }
|
||||
static sk_sp<SkColorSpace> NewICC(const void* input, size_t len) { return MakeICC(input, len); }
|
||||
#endif
|
||||
|
@ -361,7 +361,6 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) {
|
||||
// Next, check for chromaticities.
|
||||
png_fixed_point chrm[8];
|
||||
png_fixed_point gamma;
|
||||
float gammas[3];
|
||||
if (png_get_cHRM_fixed(png_ptr, info_ptr, &chrm[0], &chrm[1], &chrm[2], &chrm[3], &chrm[4],
|
||||
&chrm[5], &chrm[6], &chrm[7]))
|
||||
{
|
||||
@ -381,12 +380,12 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) {
|
||||
}
|
||||
|
||||
if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) {
|
||||
float value = png_inverted_fixed_point_to_float(gamma);
|
||||
gammas[0] = value;
|
||||
gammas[1] = value;
|
||||
gammas[2] = value;
|
||||
SkColorSpaceTransferFn fn;
|
||||
fn.fA = 1.0f;
|
||||
fn.fB = fn.fC = fn.fD = fn.fE = fn.fF = 0.0f;
|
||||
fn.fG = png_inverted_fixed_point_to_float(gamma);
|
||||
|
||||
return SkColorSpace::MakeRGB(gammas, toXYZD50);
|
||||
return SkColorSpace::MakeRGB(fn, toXYZD50);
|
||||
}
|
||||
|
||||
// Default to sRGB gamma if the image has color space information,
|
||||
@ -396,18 +395,16 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr) {
|
||||
|
||||
// Last, check for gamma.
|
||||
if (PNG_INFO_gAMA == png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) {
|
||||
|
||||
// Set the gammas.
|
||||
float value = png_inverted_fixed_point_to_float(gamma);
|
||||
gammas[0] = value;
|
||||
gammas[1] = value;
|
||||
gammas[2] = value;
|
||||
SkColorSpaceTransferFn fn;
|
||||
fn.fA = 1.0f;
|
||||
fn.fB = fn.fC = fn.fD = fn.fE = fn.fF = 0.0f;
|
||||
fn.fG = png_inverted_fixed_point_to_float(gamma);
|
||||
|
||||
// Since there is no cHRM, we will guess sRGB gamut.
|
||||
SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor);
|
||||
toXYZD50.set3x3RowMajorf(gSRGB_toXYZD50);
|
||||
|
||||
return SkColorSpace::MakeRGB(gammas, toXYZD50);
|
||||
return SkColorSpace::MakeRGB(fn, toXYZD50);
|
||||
}
|
||||
|
||||
#endif // LIBPNG >= 1.6
|
||||
|
@ -124,38 +124,8 @@ 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::MakeRGB(const float values[3], const SkMatrix44& toXYZD50) {
|
||||
if (0.0f > values[0] || 0.0f > values[1] || 0.0f > values[2]) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkGammaNamed gammaNamed = kNonStandard_SkGammaNamed;
|
||||
if (color_space_almost_equal(2.2f, values[0]) &&
|
||||
color_space_almost_equal(2.2f, values[1]) &&
|
||||
color_space_almost_equal(2.2f, values[2])) {
|
||||
gammaNamed = k2Dot2Curve_SkGammaNamed;
|
||||
} else if (color_space_almost_equal(1.0f, values[0]) &&
|
||||
color_space_almost_equal(1.0f, values[1]) &&
|
||||
color_space_almost_equal(1.0f, values[2])) {
|
||||
gammaNamed = kLinear_SkGammaNamed;
|
||||
}
|
||||
|
||||
if (kNonStandard_SkGammaNamed == gammaNamed) {
|
||||
sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new SkGammas());
|
||||
gammas->fRedType = SkGammas::Type::kValue_Type;
|
||||
gammas->fGreenType = SkGammas::Type::kValue_Type;
|
||||
gammas->fBlueType = SkGammas::Type::kValue_Type;
|
||||
gammas->fRedData.fValue = values[0];
|
||||
gammas->fGreenData.fValue = values[1];
|
||||
gammas->fBlueData.fValue = values[2];
|
||||
return sk_sp<SkColorSpace>(new SkColorSpace_XYZ(kNonStandard_SkGammaNamed,
|
||||
gammas, toXYZD50, nullptr));
|
||||
}
|
||||
|
||||
return SkColorSpace_Base::MakeRGB(gammaNamed, toXYZD50);
|
||||
}
|
||||
|
||||
sk_sp<SkColorSpace> SkColorSpace_Base::MakeRGB(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50) {
|
||||
sk_sp<SkColorSpace> SkColorSpace_Base::MakeRGB(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50)
|
||||
{
|
||||
switch (gammaNamed) {
|
||||
case kSRGB_SkGammaNamed:
|
||||
if (xyz_almost_equal(toXYZD50, gSRGB_toXYZD50)) {
|
||||
@ -307,13 +277,6 @@ struct ColorSpaceHeader {
|
||||
*/
|
||||
static constexpr uint8_t kICC_Flag = 1 << 1;
|
||||
|
||||
/**
|
||||
* If kFloatGamma_Flag is set, we will write 15 floats after the header.
|
||||
* The first three are the gamma values, and the next twelve are the
|
||||
* matrix.
|
||||
*/
|
||||
static constexpr uint8_t kFloatGamma_Flag = 1 << 2;
|
||||
|
||||
/**
|
||||
* If kTransferFn_Flag is set, we will write 19 floats after the header.
|
||||
* The first seven represent the transfer fn, and the next twelve are the
|
||||
@ -388,26 +351,9 @@ size_t SkColorSpace::writeToMemory(void* memory) const {
|
||||
}
|
||||
return sizeof(ColorSpaceHeader) + 12 * sizeof(float);
|
||||
}
|
||||
default:
|
||||
default: {
|
||||
const SkGammas* gammas = thisXYZ->gammas();
|
||||
SkASSERT(gammas);
|
||||
if (gammas->isValue(0) && gammas->isValue(1) && gammas->isValue(2)) {
|
||||
if (memory) {
|
||||
*((ColorSpaceHeader*) memory) =
|
||||
ColorSpaceHeader::Pack(k0_Version, 0, thisXYZ->fGammaNamed,
|
||||
ColorSpaceHeader::kFloatGamma_Flag);
|
||||
memory = SkTAddOffset<void>(memory, sizeof(ColorSpaceHeader));
|
||||
|
||||
*(((float*) memory) + 0) = gammas->fRedData.fValue;
|
||||
*(((float*) memory) + 1) = gammas->fGreenData.fValue;
|
||||
*(((float*) memory) + 2) = gammas->fBlueData.fValue;
|
||||
memory = SkTAddOffset<void>(memory, 3 * sizeof(float));
|
||||
|
||||
thisXYZ->fToXYZD50.as3x4RowMajorf((float*) memory);
|
||||
}
|
||||
|
||||
return sizeof(ColorSpaceHeader) + 15 * sizeof(float);
|
||||
} else {
|
||||
SkASSERT(gammas->isParametric(0));
|
||||
SkASSERT(gammas->isParametric(1));
|
||||
SkASSERT(gammas->isParametric(2));
|
||||
@ -512,21 +458,6 @@ sk_sp<SkColorSpace> SkColorSpace::Deserialize(const void* data, size_t length) {
|
||||
|
||||
return MakeICC(data, profileSize);
|
||||
}
|
||||
case ColorSpaceHeader::kFloatGamma_Flag: {
|
||||
if (length < 15 * sizeof(float)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
float gammas[3];
|
||||
gammas[0] = *(((const float*) data) + 0);
|
||||
gammas[1] = *(((const float*) data) + 1);
|
||||
gammas[2] = *(((const float*) data) + 2);
|
||||
data = SkTAddOffset<const void>(data, 3 * sizeof(float));
|
||||
|
||||
SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor);
|
||||
toXYZ.set3x4RowMajorf((const float*) data);
|
||||
return SkColorSpace::MakeRGB(gammas, toXYZ);
|
||||
}
|
||||
case ColorSpaceHeader::kTransferFn_Flag: {
|
||||
if (length < 19 * sizeof(float)) {
|
||||
return nullptr;
|
||||
|
@ -237,10 +237,6 @@ DEF_TEST(ColorSpace_Serialize, r) {
|
||||
monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc").c_str());
|
||||
test_serialize(r, SkColorSpace::MakeICC(monitorData->data(), monitorData->size()).get(), false);
|
||||
|
||||
const float gammas[] = { 1.1f, 1.2f, 1.7f, };
|
||||
SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor);
|
||||
test_serialize(r, SkColorSpace::MakeRGB(gammas, toXYZ).get(), false);
|
||||
|
||||
SkColorSpaceTransferFn fn;
|
||||
fn.fA = 1.0f;
|
||||
fn.fB = 0.0f;
|
||||
@ -249,6 +245,7 @@ DEF_TEST(ColorSpace_Serialize, r) {
|
||||
fn.fE = 1.0f;
|
||||
fn.fF = 0.0f;
|
||||
fn.fG = 1.0f;
|
||||
SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor);
|
||||
test_serialize(r, SkColorSpace::MakeRGB(fn, toXYZ).get(), false);
|
||||
}
|
||||
|
||||
@ -264,12 +261,6 @@ DEF_TEST(ColorSpace_Equals, r) {
|
||||
sk_sp<SkColorSpace> upperLeft = SkColorSpace::MakeICC(data->data(), data->size());
|
||||
data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc").c_str());
|
||||
sk_sp<SkColorSpace> upperRight = SkColorSpace::MakeICC(data->data(), data->size());
|
||||
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::MakeRGB(gammas1, toXYZ);
|
||||
sk_sp<SkColorSpace> rgb2 = SkColorSpace::MakeRGB(gammas2, toXYZ);
|
||||
sk_sp<SkColorSpace> rgb3 = SkColorSpace::MakeRGB(gammas1, toXYZ);
|
||||
|
||||
SkColorSpaceTransferFn fn;
|
||||
fn.fA = 1.0f;
|
||||
@ -279,6 +270,7 @@ DEF_TEST(ColorSpace_Equals, r) {
|
||||
fn.fE = 1.0f;
|
||||
fn.fF = 0.0f;
|
||||
fn.fG = 1.0f;
|
||||
SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor);
|
||||
sk_sp<SkColorSpace> rgb4 = SkColorSpace::MakeRGB(fn, toXYZ);
|
||||
|
||||
REPORTER_ASSERT(r, SkColorSpace::Equals(nullptr, nullptr));
|
||||
@ -288,8 +280,6 @@ DEF_TEST(ColorSpace_Equals, r) {
|
||||
REPORTER_ASSERT(r, SkColorSpace::Equals(z32.get(), z32.get()));
|
||||
REPORTER_ASSERT(r, SkColorSpace::Equals(upperLeft.get(), upperLeft.get()));
|
||||
REPORTER_ASSERT(r, SkColorSpace::Equals(upperRight.get(), upperRight.get()));
|
||||
REPORTER_ASSERT(r, SkColorSpace::Equals(rgb1.get(), rgb1.get()));
|
||||
REPORTER_ASSERT(r, SkColorSpace::Equals(rgb1.get(), rgb3.get()));
|
||||
REPORTER_ASSERT(r, SkColorSpace::Equals(rgb4.get(), rgb4.get()));
|
||||
|
||||
REPORTER_ASSERT(r, !SkColorSpace::Equals(nullptr, srgb.get()));
|
||||
@ -301,8 +291,8 @@ DEF_TEST(ColorSpace_Equals, r) {
|
||||
REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get()));
|
||||
REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get()));
|
||||
REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get()));
|
||||
REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb2.get()));
|
||||
REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb4.get()));
|
||||
REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), rgb4.get()));
|
||||
REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), rgb4.get()));
|
||||
}
|
||||
|
||||
static inline bool matrix_almost_equal(const SkMatrix44& a, const SkMatrix44& b) {
|
||||
|
@ -926,7 +926,10 @@ static void test_surface_creation_and_snapshot_with_color_space(
|
||||
auto adobeColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named);
|
||||
const SkMatrix44* srgbMatrix = as_CSB(srgbColorSpace)->toXYZD50();
|
||||
SkASSERT(srgbMatrix);
|
||||
const float oddGamma[] = { 2.4f, 2.4f, 2.4f };
|
||||
SkColorSpaceTransferFn oddGamma;
|
||||
oddGamma.fA = 1.0f;
|
||||
oddGamma.fB = oddGamma.fC = oddGamma.fD = oddGamma.fE = oddGamma.fF = 0.0f;
|
||||
oddGamma.fG = 4.0f;
|
||||
auto oddColorSpace = SkColorSpace::MakeRGB(oddGamma, *srgbMatrix);
|
||||
auto linearColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user