aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2014-08-29 07:50:28 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-29 07:50:28 -0700
commit64ba5fa1ff428858f803523257cd862f8b33423b (patch)
tree42a0045a3cfd126df51f0611cfadea76a1327be7 /src
parent32d0b3b5463c11032f12d03d993f11ea0af05959 (diff)
Revert of Add gamma/sRGB tags to SkImageInfo (patchset #1 of https://codereview.chromium.org/517123002/)
Reason for revert: Seems to be triggering assert in blink SSLUITest.TestRedirectHTTPToBadHTTPS (run #1): [ RUN ] SSLUITest.TestRedirectHTTPToBadHTTPS HTTP server started on http://127.0.0.1:58000... sending server_data: {"host": "127.0.0.1", "port": 58000} (36 bytes) HTTPS server started on https://127.0.0.1:58009... sending server_data: {"host": "127.0.0.1", "port": 58009} (36 bytes) ASSERTION FAILED: info.fAlphaType == m_imageInfo.fAlphaType ../../third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp(78) : virtual bool blink::DecodingImageGenerator::onGetPixels(const SkImageInfo &, void *, size_t, SkPMColor *, int *) 1 0x77eb0d3 blink::DecodingImageGenerator::onGetPixels(SkImageInfo const&, void*, unsigned long, unsigned int*, int*) 2 0x92edddc SkImageGenerator::getPixels(SkImageInfo const&, void*, unsigned long, unsigned int*, int*) 3 0x92adf78 SkDiscardablePixelRef::onNewLockPixels(SkPixelRef::LockRec*) 4 0x9369283 SkPixelRef::lockPixels(SkPixelRef::LockRec*) 5 0x9369433 SkPixelRef::lockPixels() 6 0x9213344 SkBitmap::lockPixels() const 7 0x921ca57 SkAutoLockPixels::SkAutoLockPixels(SkBitmap const&, bool) 8 0x921ad80 SkAutoLockPixels::SkAutoLockPixels(SkBitmap const&, bool) 9 0x92b7125 SkDraw::drawBitmap(SkBitmap const&, SkMatrix const&, SkPaint const&) const 10 0x921f4fb SkBitmapDevice::drawBitmap(SkDraw const&, SkBitmap const&, SkMatrix const&, SkPaint const&) 11 0x921f8c7 SkBitmapDevice::drawBitmapRect(SkDraw const&, SkBitmap const&, SkRect const*, SkRect const&, SkPaint const&, SkCanvas::DrawBitmapRectFlags) 12 0x9288e12 SkCanvas::internalDrawBitmapRect(SkBitmap const&, SkRect const*, SkRect const&, SkPaint const*, SkCanvas::DrawBitmapRectFlags) 13 0x9288ee9 SkCanvas::drawBitmapRectToRect(SkBitmap const&, SkRect const*, SkRect const&, SkPaint const*, SkCanvas::DrawBitmapRectFlags) Original issue's description: > Add gamma/sRGB tags to SkImageInfo > > requires this CL to land in chrome > https://codereview.chromium.org/517803002/ > > BUG=skia: > > Committed: https://skia.googlesource.com/skia/+/228b285ba14a6e9b6d1cc95ea1583caab30168a1 R=fmalita@google.com, fmalita@chromium.org, reed@chromium.org TBR=fmalita@chromium.org, fmalita@google.com, reed@chromium.org NOTREECHECKS=true NOTRY=true BUG=skia: Author: reed@google.com Review URL: https://codereview.chromium.org/519583004
Diffstat (limited to 'src')
-rw-r--r--src/core/SkImageInfo.cpp132
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);
-}