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(); |