Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: src/core/SkImageInfo.cpp

Issue 514753002: add gamma/sRGB to SkImageInfo (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include/core/SkImageInfo.h ('K') | « include/core/SkImageInfo.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkImageInfo.cpp
diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp
index e61cd7d45f398c115f36d4332744f65d95e2fdad..d4f9a8aae25128062f0ca04634e57e617da73b42 100644
--- a/src/core/SkImageInfo.cpp
+++ b/src/core/SkImageInfo.cpp
@@ -17,6 +17,55 @@ static bool color_type_is_valid(SkColorType colorType) {
return (colorType >= 0) && (colorType <= kLastEnum_SkColorType);
}
+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 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 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);
+}
+
+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);
+}
+
+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::unflatten(SkReadBuffer& buffer) {
fWidth = buffer.read32();
fHeight = buffer.read32();
« include/core/SkImageInfo.h ('K') | « include/core/SkImageInfo.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698