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

Side by Side Diff: src/core/SkImageInfo.cpp

Issue 2075853002: remove colorprofiletype from imageinfo (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: continue writing an enum, with forward-mode for flattening the actual profile Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « src/core/SkBlitter.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkImageInfoPriv.h" 9 #include "SkImageInfoPriv.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
11 #include "SkWriteBuffer.h" 11 #include "SkWriteBuffer.h"
12 12
13 /*
14 * We store this as a byte in the ImageInfo flatten buffer.
15 */
16 enum class SkFlattenColorSpaceEnum {
17 kUnspecified,
18 kSRGB,
19 kAdobe1998,
20 // ... add more here
21 kLastEnum = kAdobe1998,
22 // final value means the actual profile data follows the info
23 kICCProfile = 0xFF,
24 };
25
26 static sk_sp<SkColorSpace> make_from_enum(SkFlattenColorSpaceEnum value) {
27 switch (value) {
28 case SkFlattenColorSpaceEnum::kSRGB:
29 return SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
30 case SkFlattenColorSpaceEnum::kAdobe1998:
31 return SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named);
32 default:
33 return nullptr;
34 }
35 }
36
37 SkColorSpace::Named sk_deduce_named_from_colorspace(SkColorSpace* cs) {
38 return cs->fNamed;
39 }
40
41 static SkFlattenColorSpaceEnum deduce_from_colorspace(SkColorSpace* cs) {
42 if (!cs) {
43 return SkFlattenColorSpaceEnum::kUnspecified;
44 }
45 switch (sk_deduce_named_from_colorspace(cs)) {
46 case SkColorSpace::kSRGB_Named:
47 return SkFlattenColorSpaceEnum::kSRGB;
48 case SkColorSpace::kAdobeRGB_Named:
49 return SkFlattenColorSpaceEnum::kAdobe1998;
50 default:
51 return SkFlattenColorSpaceEnum::kICCProfile;
52 }
53 }
54
55 //////////////////////////////////////////////////////////////////////////////// ///////////////////
56
57 #ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE
58 SkColorProfileType SkImageInfo::profileType() const {
59 return fColorSpace && fColorSpace->gammaCloseToSRGB()
60 ? kSRGB_SkColorProfileType : kLinear_SkColorProfileType;
61 }
62 #endif
63
13 // Indicate how images and gradients should interpret colors by default. 64 // Indicate how images and gradients should interpret colors by default.
14 bool gDefaultProfileIsSRGB; 65 bool gDefaultProfileIsSRGB;
15 66
16 SkColorProfileType SkDefaultColorProfile() { 67 SkColorProfileType SkDefaultColorProfile() {
17 return gDefaultProfileIsSRGB ? kSRGB_SkColorProfileType 68 return gDefaultProfileIsSRGB ? kSRGB_SkColorProfileType
18 : kLinear_SkColorProfileType; 69 : kLinear_SkColorProfileType;
19 } 70 }
20 71
21 static bool profile_type_is_valid(SkColorProfileType profileType) {
22 return (profileType >= 0) && (profileType <= kLastEnum_SkColorProfileType);
23 }
24
25 static bool alpha_type_is_valid(SkAlphaType alphaType) { 72 static bool alpha_type_is_valid(SkAlphaType alphaType) {
26 return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType); 73 return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType);
27 } 74 }
28 75
29 static bool color_type_is_valid(SkColorType colorType) { 76 static bool color_type_is_valid(SkColorType colorType) {
30 return (colorType >= 0) && (colorType <= kLastEnum_SkColorType); 77 return (colorType >= 0) && (colorType <= kLastEnum_SkColorType);
31 } 78 }
32 79
33 SkImageInfo SkImageInfo::Make(int width, int height, SkColorType ct, SkAlphaType at,
34 sk_sp<SkColorSpace> cs) {
35 SkColorProfileType pt = SkDefaultColorProfile();
36 // try to keep the enum and the colorspace in sync.
37 // TODO: eliminate the enum entirely, now that we have colorspace objects
38 if (cs && (SkColorSpace::kLinear_GammaNamed != cs->gammaNamed())) {
39 pt = kSRGB_SkColorProfileType;
40 }
41 return SkImageInfo(width, height, ct, at, pt, std::move(cs));
42 }
43
44 SkImageInfo SkImageInfo::MakeS32(int width, int height, SkAlphaType at) { 80 SkImageInfo SkImageInfo::MakeS32(int width, int height, SkAlphaType at) {
45 return SkImageInfo(width, height, kN32_SkColorType, at, kSRGB_SkColorProfile Type, 81 return SkImageInfo(width, height, kN32_SkColorType, at,
46 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)); 82 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named));
47 } 83 }
48 84
49 void SkImageInfo::unflatten(SkReadBuffer& buffer) { 85 void SkImageInfo::unflatten(SkReadBuffer& buffer) {
50 fWidth = buffer.read32(); 86 fWidth = buffer.read32();
51 fHeight = buffer.read32(); 87 fHeight = buffer.read32();
52 88
53 uint32_t packed = buffer.read32(); 89 uint32_t packed = buffer.read32();
54 SkASSERT(0 == (packed >> 24)); 90 SkASSERT(0 == (packed >> 24));
55 fProfileType = (SkColorProfileType)((packed >> 16) & 0xFF); 91 fColorType = (SkColorType)((packed >> 0) & 0xFF);
56 fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF); 92 fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF);
57 fColorType = (SkColorType)((packed >> 0) & 0xFF); 93 SkFlattenColorSpaceEnum csenum = (SkFlattenColorSpaceEnum)((packed >> 16) & 0xFF);
58 buffer.validate(profile_type_is_valid(fProfileType) && 94 buffer.validate(alpha_type_is_valid(fAlphaType) && color_type_is_valid(fColo rType));
59 alpha_type_is_valid(fAlphaType) && 95
60 color_type_is_valid(fColorType)); 96 if (SkFlattenColorSpaceEnum::kICCProfile == csenum) {
97 SkASSERT(false); // we shouldn't hit this yet, as we don't write thes e yet
98 fColorSpace.reset();
99 } else {
100 if (csenum > SkFlattenColorSpaceEnum::kLastEnum) {
101 csenum = SkFlattenColorSpaceEnum::kUnspecified;
102 }
103 fColorSpace = make_from_enum(csenum);
104 }
61 } 105 }
62 106
63 void SkImageInfo::flatten(SkWriteBuffer& buffer) const { 107 void SkImageInfo::flatten(SkWriteBuffer& buffer) const {
64 buffer.write32(fWidth); 108 buffer.write32(fWidth);
65 buffer.write32(fHeight); 109 buffer.write32(fHeight);
66 110
67 SkASSERT(0 == (fProfileType & ~0xFF)); 111 SkFlattenColorSpaceEnum csenum = deduce_from_colorspace(fColorSpace.get());
112
113 // TODO: when we actually support flattening the colorspace to a profile blo b, remove this
114 // hack (and write the blob after we write packed.
115 if (SkFlattenColorSpaceEnum::kICCProfile == csenum) {
116 csenum = SkFlattenColorSpaceEnum::kUnspecified;
117 }
118
119 SkASSERT(0 == ((int)csenum & ~0xFF));
68 SkASSERT(0 == (fAlphaType & ~0xFF)); 120 SkASSERT(0 == (fAlphaType & ~0xFF));
69 SkASSERT(0 == (fColorType & ~0xFF)); 121 SkASSERT(0 == (fColorType & ~0xFF));
70 uint32_t packed = (fProfileType << 16) | (fAlphaType << 8) | fColorType; 122 uint32_t packed = ((int)csenum << 16) | (fAlphaType << 8) | fColorType;
71 buffer.write32(packed); 123 buffer.write32(packed);
124
125 if (SkFlattenColorSpaceEnum::kICCProfile == csenum) {
126 // TODO: write the ICCProfile blob
127 }
72 } 128 }
73 129
74 bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, 130 bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
75 SkAlphaType* canonical) { 131 SkAlphaType* canonical) {
76 switch (colorType) { 132 switch (colorType) {
77 case kUnknown_SkColorType: 133 case kUnknown_SkColorType:
78 alphaType = kUnknown_SkAlphaType; 134 alphaType = kUnknown_SkAlphaType;
79 break; 135 break;
80 case kAlpha_8_SkColorType: 136 case kAlpha_8_SkColorType:
81 if (kUnpremul_SkAlphaType == alphaType) { 137 if (kUnpremul_SkAlphaType == alphaType) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 195 }
140 // here x,y are either 0 or negative 196 // here x,y are either 0 or negative
141 fPixels = ((char*)fPixels - y * fRowBytes - x * fInfo.bytesPerPixel()); 197 fPixels = ((char*)fPixels - y * fRowBytes - x * fInfo.bytesPerPixel());
142 // the intersect may have shrunk info's logical size 198 // the intersect may have shrunk info's logical size
143 fInfo = fInfo.makeWH(srcR.width(), srcR.height()); 199 fInfo = fInfo.makeWH(srcR.width(), srcR.height());
144 fX = srcR.x(); 200 fX = srcR.x();
145 fY = srcR.y(); 201 fY = srcR.y();
146 202
147 return true; 203 return true;
148 } 204 }
OLDNEW
« no previous file with comments | « src/core/SkBlitter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698