diff options
author | reed <reed@google.com> | 2014-08-28 14:46:19 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-28 14:46:19 -0700 |
commit | 088f4b8eb31b2af26e66dcbaae062f40b3955059 (patch) | |
tree | a3b56ed04ca92b60a689a7acc08d2263f3de325d /src/core | |
parent | 0b4abb904eca43447114951266c6c849d5e8fd32 (diff) |
Revert of Revert of Revert of add gamma/sRGB to SkImageInfo (patchset #1 of https://codereview.chromium.org/511363002/)
Reason for revert:
android builder in chrome reveals the caller using { } initialization for SkImageInfo, which this CL now makes illegal. Will have to fix the call site before I can re-land this
Original issue's description:
> Revert of Revert of add gamma/sRGB to SkImageInfo (patchset #1 of https://codereview.chromium.org/512243002/)
>
> Reason for revert:
> this revert was premature -- the chrome canary I looked at is old, and newer ones were green. So trying again...
>
> Original issue's description:
> > Revert of add gamma/sRGB to SkImageInfo (patchset #4 of https://codereview.chromium.org/514753002/)
> >
> > Reason for revert:
> > breaks linker on chrome -- may need SK_API, but not sure.
> >
> > Original issue's description:
> > > add gamma/sRGB to SkImageInfo
> > >
> > > BUG=skia:
> > >
> > > Committed: https://skia.googlesource.com/skia/+/615c369777258231054840a88cdb74c68c382485
> >
> > TBR=bungeman@google.com,bsalomon@google.com
> > NOTREECHECKS=true
> > NOTRY=true
> > BUG=skia:
> >
> > Committed: https://skia.googlesource.com/skia/+/dc53701216c0e9f98eacf6c0cda769ebbd200b59
>
> TBR=bungeman@google.com,bsalomon@google.com
> NOTREECHECKS=true
> NOTRY=true
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/e759a2662273fdf52ebbb3822229945eda317e46
R=bungeman@google.com, bsalomon@google.com
TBR=bsalomon@google.com, bungeman@google.com
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Author: reed@google.com
Review URL: https://codereview.chromium.org/517113002
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkImageInfo.cpp | 132 |
1 files changed, 21 insertions, 111 deletions
diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp index 44fd808dc8..e61cd7d45f 100644 --- a/src/core/SkImageInfo.cpp +++ b/src/core/SkImageInfo.cpp @@ -9,53 +9,34 @@ #include "SkReadBuffer.h" #include "SkWriteBuffer.h" -static bool color_type_supports_sRGB(SkColorType colorType) { - switch (colorType) { - case kRGBA_8888_SkColorType: - case kBGRA_8888_SkColorType: - return true; - default: - return false; - } +static bool alpha_type_is_valid(SkAlphaType alphaType) { + return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType); } -static bool color_type_supports_gamma(SkColorType colorType) { - switch (colorType) { - case kRGBA_8888_SkColorType: - case kBGRA_8888_SkColorType: - // case kLuminance ... - return true; - default: - return false; - } +static bool color_type_is_valid(SkColorType colorType) { + return (colorType >= 0) && (colorType <= kLastEnum_SkColorType); } -static float pin_gamma_to_legal(float gamma) { - if (!SkScalarIsFinite(gamma)) { - return 1; - } - // these limits are just made up -- feel free to change them within reason - const float min_gamma = 0.01f; - const float max_gamma = 4.0; - return SkScalarPin(gamma, min_gamma, max_gamma); -} +void SkImageInfo::unflatten(SkReadBuffer& buffer) { + fWidth = buffer.read32(); + fHeight = buffer.read32(); -SkImageInfo SkImageInfo::MakeSRGB(int width, int height, SkColorType ct, SkAlphaType at) { - Profile p = color_type_supports_sRGB(ct) ? kSRGB_Profile : kUnknown_Profile; - return SkImageInfo(width, height, ct, at, p, 0); + uint32_t packed = buffer.read32(); + SkASSERT(0 == (packed >> 16)); + fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF); + fColorType = (SkColorType)((packed >> 0) & 0xFF); + buffer.validate(alpha_type_is_valid(fAlphaType) && + color_type_is_valid(fColorType)); } -SkImageInfo SkImageInfo::MakeWithGamma(int width, int height, SkColorType ct, SkAlphaType at, - float gamma) { - Profile p; - if (color_type_supports_gamma(ct)) { - gamma = pin_gamma_to_legal(gamma); - p = kExponential_Profile; - } else { - p = kUnknown_Profile; - gamma = 0; - } - return SkImageInfo(width, height, ct, at, p, gamma); +void SkImageInfo::flatten(SkWriteBuffer& buffer) const { + buffer.write32(fWidth); + buffer.write32(fHeight); + + SkASSERT(0 == (fAlphaType & ~0xFF)); + SkASSERT(0 == (fColorType & ~0xFF)); + uint32_t packed = (fAlphaType << 8) | fColorType; + buffer.write32(packed); } bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, @@ -88,74 +69,3 @@ bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, } return true; } - -void SkImageInfo::unflatten(SkReadBuffer& buffer) { - *this = Unflatten(buffer); -} - -//////////////////////////////////////////////////////////////////////////////////////////// - -static bool alpha_type_is_valid(SkAlphaType alphaType) { - return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType); -} - -static bool color_type_is_valid(SkColorType colorType) { - return (colorType >= 0) && (colorType <= kLastEnum_SkColorType); -} - -static float igamma_to_gamma(int gamma3dot9) { - return gamma3dot9 / 512.0f; -} - -static unsigned gamma_to_igamma(float gamma) { - SkASSERT(gamma >= 0 && gamma < 8); - int igamma = SkScalarRoundToInt(gamma * 512); - SkASSERT(igamma >= 0 && igamma <= 0xFFF); - return igamma; -} - -SkImageInfo SkImageInfo::Unflatten(SkReadBuffer& buffer) { - int width = buffer.read32(); - int height = buffer.read32(); - uint32_t packed = buffer.read32(); - - SkColorType ct = (SkColorType)((packed >> 0) & 0xFF); // 8 bits for colortype - SkAlphaType at = (SkAlphaType)((packed >> 8) & 0xFF); // 8 bits for alphatype - if (!alpha_type_is_valid(at) || !color_type_is_valid(ct)) { - return MakeUnknown(); - } - - // Earlier formats always stored 0 in the upper 16 bits. That corresponds to - // days before we had gamma/profile. That happens to correspond to kUnknown_Profile, - // which means we can just ignore the gamma value anyways. - // - int iprofile = ((packed >> 16) & 0xF); // 4 bits for profile - - switch (iprofile) { - case kUnknown_Profile: - return Make(width, height, ct, at); - case kSRGB_Profile: - return MakeSRGB(width, height, ct, at); - case kExponential_Profile: { - int igamma = packed >> 20; // 12 bits for gamma 3.9 - float gamma = igamma_to_gamma(igamma); - return MakeWithGamma(width, height, ct, at, gamma); - } - default: - (void)buffer.validate(false); - return MakeUnknown(); - } -} - -void SkImageInfo::flatten(SkWriteBuffer& buffer) const { - buffer.write32(fWidth); - buffer.write32(fHeight); - - SkASSERT(0 == (fColorType & ~0xFF)); // 8 bits for colortype - SkASSERT(0 == (fAlphaType & ~0xFF)); // 8 bits for alphatype - SkASSERT(0 == (fProfile & ~0xF)); // 4 bits for profile - int igamma = gamma_to_igamma(fGamma); // 12 bits for gamma (if needed) - - uint32_t packed = (igamma << 20) | (fProfile << 16) | (fAlphaType << 8) | fColorType; - buffer.write32(packed); -} |