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