Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkImageInfo.h" | 8 #include "SkImageInfo.h" |
| 9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
| 10 #include "SkWriteBuffer.h" | 10 #include "SkWriteBuffer.h" |
| 11 | 11 |
| 12 static bool alpha_type_is_valid(SkAlphaType alphaType) { | 12 static bool alpha_type_is_valid(SkAlphaType alphaType) { |
| 13 return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType); | 13 return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType); |
| 14 } | 14 } |
| 15 | 15 |
| 16 static bool color_type_is_valid(SkColorType colorType) { | 16 static bool color_type_is_valid(SkColorType colorType) { |
| 17 return (colorType >= 0) && (colorType <= kLastEnum_SkColorType); | 17 return (colorType >= 0) && (colorType <= kLastEnum_SkColorType); |
| 18 } | 18 } |
| 19 | 19 |
| 20 static bool color_type_supports_sRGB(SkColorType colorType) { | |
| 21 switch (colorType) { | |
| 22 case kRGBA_8888_SkColorType: | |
| 23 case kBGRA_8888_SkColorType: | |
| 24 return true; | |
|
bsalomon
2014/08/27 17:11:30
// case kLuminance:
reed1
2014/08/27 18:52:49
Done.
| |
| 25 default: | |
| 26 return false; | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 static bool color_type_supports_gamma(SkColorType colorType) { | |
| 31 switch (colorType) { | |
| 32 case kRGBA_8888_SkColorType: | |
| 33 case kBGRA_8888_SkColorType: | |
| 34 // case kLuminance ... | |
| 35 return true; | |
| 36 default: | |
| 37 return false; | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 static bool gamma_in_range(float gamma, float* pinnedGamma) { | |
| 42 if (!SkScalarIsFinite(gamma)) { | |
| 43 return false; | |
| 44 } | |
| 45 const float min_gamma = 0.01f; | |
| 46 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.
| |
| 47 *pinnedGamma = SkScalarPin(gamma, min_gamma, max_gamma); | |
| 48 return true; | |
| 49 } | |
| 50 | |
| 51 SkImageInfo SkImageInfo::MakeSRGB(int width, int height, SkColorType ct, SkAlpha Type at) { | |
| 52 SkImageInfo info = Make(width, height, ct, at); | |
| 53 if (color_type_supports_sRGB(info.colorType())) { | |
| 54 fProfile = kSRGB_Profile; | |
| 55 fGamma = 0; | |
| 56 } | |
| 57 return info; | |
| 58 } | |
| 59 | |
| 60 SkImageInfo SkImageInfo::MakeWithGamma(int width, int height, SkColorType ct, Sk AlphaType at, | |
| 61 float gamma) { | |
| 62 SkImageInfo info = Make(width, height, ct, at); | |
| 63 if (color_type_supports_gamma(info.colorType()) && gamma_in_range(gamma, &fG amma)) { | |
| 64 fProfile = kExponential_Profile; | |
| 65 } | |
| 66 return info; | |
| 67 } | |
| 68 | |
| 20 void SkImageInfo::unflatten(SkReadBuffer& buffer) { | 69 void SkImageInfo::unflatten(SkReadBuffer& buffer) { |
| 21 fWidth = buffer.read32(); | 70 fWidth = buffer.read32(); |
| 22 fHeight = buffer.read32(); | 71 fHeight = buffer.read32(); |
| 23 | 72 |
| 24 uint32_t packed = buffer.read32(); | 73 uint32_t packed = buffer.read32(); |
| 25 SkASSERT(0 == (packed >> 16)); | 74 SkASSERT(0 == (packed >> 16)); |
| 26 fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF); | 75 fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF); |
| 27 fColorType = (SkColorType)((packed >> 0) & 0xFF); | 76 fColorType = (SkColorType)((packed >> 0) & 0xFF); |
| 28 buffer.validate(alpha_type_is_valid(fAlphaType) && | 77 buffer.validate(alpha_type_is_valid(fAlphaType) && |
| 29 color_type_is_valid(fColorType)); | 78 color_type_is_valid(fColorType)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 alphaType = kOpaque_SkAlphaType; | 111 alphaType = kOpaque_SkAlphaType; |
| 63 break; | 112 break; |
| 64 default: | 113 default: |
| 65 return false; | 114 return false; |
| 66 } | 115 } |
| 67 if (canonical) { | 116 if (canonical) { |
| 68 *canonical = alphaType; | 117 *canonical = alphaType; |
| 69 } | 118 } |
| 70 return true; | 119 return true; |
| 71 } | 120 } |
| OLD | NEW |