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

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..27bcdb8129d1feed5ca35732f9592fdf615b1b90 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;
bsalomon 2014/08/27 17:11:30 // case kLuminance:
reed1 2014/08/27 18:52:49 Done.
+ 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 gamma_in_range(float gamma, float* pinnedGamma) {
+ if (!SkScalarIsFinite(gamma)) {
+ return false;
+ }
+ const float min_gamma = 0.01f;
+ const float max_gamma = 100.0f;
bungeman-skia 2014/08/27 18:08:52 I actually currently have a max of 4.0 - epsilon o
reed1 2014/08/27 18:52:49 Done.
+ *pinnedGamma = SkScalarPin(gamma, min_gamma, max_gamma);
+ return true;
+}
+
+SkImageInfo SkImageInfo::MakeSRGB(int width, int height, SkColorType ct, SkAlphaType at) {
+ SkImageInfo info = Make(width, height, ct, at);
+ if (color_type_supports_sRGB(info.colorType())) {
+ fProfile = kSRGB_Profile;
+ fGamma = 0;
+ }
+ return info;
+}
+
+SkImageInfo SkImageInfo::MakeWithGamma(int width, int height, SkColorType ct, SkAlphaType at,
+ float gamma) {
+ SkImageInfo info = Make(width, height, ct, at);
+ if (color_type_supports_gamma(info.colorType()) && gamma_in_range(gamma, &fGamma)) {
+ fProfile = kExponential_Profile;
+ }
+ return info;
+}
+
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