diff options
author | 2016-06-17 09:26:41 -0700 | |
---|---|---|
committer | 2016-06-17 09:26:41 -0700 | |
commit | 960b2d69bbae19dc814f06d841b94ef71e291b48 (patch) | |
tree | ed69d0f4d45e4e7e223a1fc9d8d631addce15e43 /src | |
parent | 7d2f607ac16788eac985d4738b8cb901971f33c3 (diff) |
remove colorprofiletype from imageinfo
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2075853002
Review-Url: https://codereview.chromium.org/2075853002
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkBitmapScaler.cpp | 4 | ||||
-rw-r--r-- | src/core/SkBlitter.cpp | 4 | ||||
-rw-r--r-- | src/core/SkImageInfo.cpp | 102 |
3 files changed, 83 insertions, 27 deletions
diff --git a/src/core/SkBitmapScaler.cpp b/src/core/SkBitmapScaler.cpp index fb72875443..5edb1b23e1 100644 --- a/src/core/SkBitmapScaler.cpp +++ b/src/core/SkBitmapScaler.cpp @@ -252,8 +252,8 @@ bool SkBitmapScaler::Resize(SkBitmap* resultPtr, const SkPixmap& source, ResizeM SkBitmap result; // Note: pass along the profile information even thought this is no the right answer because // this could be scaling in sRGB. - result.setInfo(SkImageInfo::MakeN32(destWidth, destHeight, - source.alphaType(), source.info().profileType())); + result.setInfo(SkImageInfo::MakeN32(destWidth, destHeight, source.alphaType(), + sk_ref_sp(source.info().colorSpace()))); result.allocPixels(allocator, nullptr); SkPixmap resultPM; diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp index daced55ef2..43471946c1 100644 --- a/src/core/SkBlitter.cpp +++ b/src/core/SkBlitter.cpp @@ -788,7 +788,7 @@ SkShader::ContextRec::DstType SkBlitter::PreferredShaderDest(const SkImageInfo& #ifdef SK_FORCE_PM4f_FOR_L32_BLITS return SkShader::ContextRec::kPM4f_DstType; #else - return (dstInfo.isSRGB() || dstInfo.colorType() == kRGBA_F16_SkColorType) + return (dstInfo.gammaCloseToSRGB() || dstInfo.colorType() == kRGBA_F16_SkColorType) ? SkShader::ContextRec::kPM4f_DstType : SkShader::ContextRec::kPMColor_DstType; #endif @@ -922,7 +922,7 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device, #ifdef SK_FORCE_PM4f_FOR_L32_BLITS if (true) #else - if (device.info().isSRGB()) + if (device.info().gammaCloseToSRGB()) #endif { blitter = SkBlitter_ARGB32_Create(device, *paint, shaderContext, allocator); diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp index 88f1ed65c6..9485754823 100644 --- a/src/core/SkImageInfo.cpp +++ b/src/core/SkImageInfo.cpp @@ -10,6 +10,57 @@ #include "SkReadBuffer.h" #include "SkWriteBuffer.h" +/* + * We store this as a byte in the ImageInfo flatten buffer. + */ +enum class SkFlattenColorSpaceEnum { + kUnspecified, + kSRGB, + kAdobe1998, + // ... add more here + kLastEnum = kAdobe1998, + // final value means the actual profile data follows the info + kICCProfile = 0xFF, +}; + +static sk_sp<SkColorSpace> make_from_enum(SkFlattenColorSpaceEnum value) { + switch (value) { + case SkFlattenColorSpaceEnum::kSRGB: + return SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); + case SkFlattenColorSpaceEnum::kAdobe1998: + return SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named); + default: + return nullptr; + } +} + +SkColorSpace::Named sk_deduce_named_from_colorspace(SkColorSpace* cs) { + return cs->fNamed; +} + +static SkFlattenColorSpaceEnum deduce_from_colorspace(SkColorSpace* cs) { + if (!cs) { + return SkFlattenColorSpaceEnum::kUnspecified; + } + switch (sk_deduce_named_from_colorspace(cs)) { + case SkColorSpace::kSRGB_Named: + return SkFlattenColorSpaceEnum::kSRGB; + case SkColorSpace::kAdobeRGB_Named: + return SkFlattenColorSpaceEnum::kAdobe1998; + default: + return SkFlattenColorSpaceEnum::kICCProfile; + } +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE +SkColorProfileType SkImageInfo::profileType() const { + return fColorSpace && fColorSpace->gammaCloseToSRGB() + ? kSRGB_SkColorProfileType : kLinear_SkColorProfileType; +} +#endif + // Indicate how images and gradients should interpret colors by default. bool gDefaultProfileIsSRGB; @@ -18,10 +69,6 @@ SkColorProfileType SkDefaultColorProfile() { : kLinear_SkColorProfileType; } -static bool profile_type_is_valid(SkColorProfileType profileType) { - return (profileType >= 0) && (profileType <= kLastEnum_SkColorProfileType); -} - static bool alpha_type_is_valid(SkAlphaType alphaType) { return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType); } @@ -30,19 +77,8 @@ static bool color_type_is_valid(SkColorType colorType) { return (colorType >= 0) && (colorType <= kLastEnum_SkColorType); } -SkImageInfo SkImageInfo::Make(int width, int height, SkColorType ct, SkAlphaType at, - sk_sp<SkColorSpace> cs) { - SkColorProfileType pt = SkDefaultColorProfile(); - // try to keep the enum and the colorspace in sync. - // TODO: eliminate the enum entirely, now that we have colorspace objects - if (cs && (SkColorSpace::kLinear_GammaNamed != cs->gammaNamed())) { - pt = kSRGB_SkColorProfileType; - } - return SkImageInfo(width, height, ct, at, pt, std::move(cs)); -} - SkImageInfo SkImageInfo::MakeS32(int width, int height, SkAlphaType at) { - return SkImageInfo(width, height, kN32_SkColorType, at, kSRGB_SkColorProfileType, + return SkImageInfo(width, height, kN32_SkColorType, at, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)); } @@ -52,23 +88,43 @@ void SkImageInfo::unflatten(SkReadBuffer& buffer) { uint32_t packed = buffer.read32(); SkASSERT(0 == (packed >> 24)); - fProfileType = (SkColorProfileType)((packed >> 16) & 0xFF); - fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF); fColorType = (SkColorType)((packed >> 0) & 0xFF); - buffer.validate(profile_type_is_valid(fProfileType) && - alpha_type_is_valid(fAlphaType) && - color_type_is_valid(fColorType)); + fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF); + SkFlattenColorSpaceEnum csenum = (SkFlattenColorSpaceEnum)((packed >> 16) & 0xFF); + buffer.validate(alpha_type_is_valid(fAlphaType) && color_type_is_valid(fColorType)); + + if (SkFlattenColorSpaceEnum::kICCProfile == csenum) { + SkASSERT(false); // we shouldn't hit this yet, as we don't write these yet + fColorSpace.reset(); + } else { + if (csenum > SkFlattenColorSpaceEnum::kLastEnum) { + csenum = SkFlattenColorSpaceEnum::kUnspecified; + } + fColorSpace = make_from_enum(csenum); + } } void SkImageInfo::flatten(SkWriteBuffer& buffer) const { buffer.write32(fWidth); buffer.write32(fHeight); - SkASSERT(0 == (fProfileType & ~0xFF)); + SkFlattenColorSpaceEnum csenum = deduce_from_colorspace(fColorSpace.get()); + + // TODO: when we actually support flattening the colorspace to a profile blob, remove this + // hack (and write the blob after we write packed. + if (SkFlattenColorSpaceEnum::kICCProfile == csenum) { + csenum = SkFlattenColorSpaceEnum::kUnspecified; + } + + SkASSERT(0 == ((int)csenum & ~0xFF)); SkASSERT(0 == (fAlphaType & ~0xFF)); SkASSERT(0 == (fColorType & ~0xFF)); - uint32_t packed = (fProfileType << 16) | (fAlphaType << 8) | fColorType; + uint32_t packed = ((int)csenum << 16) | (fAlphaType << 8) | fColorType; buffer.write32(packed); + + if (SkFlattenColorSpaceEnum::kICCProfile == csenum) { + // TODO: write the ICCProfile blob + } } bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, |