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

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: remove colorprofiletype from imageinfo 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 #ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE
14 SkColorProfileType SkImageInfo::profileType() const {
15 return fColorSpace && fColorSpace->gammaCloseToSRGB()
16 ? kSRGB_SkColorProfileType : kLinear_SkColorProfileType;
17 }
18 #endif
19
13 // Indicate how images and gradients should interpret colors by default. 20 // Indicate how images and gradients should interpret colors by default.
14 bool gDefaultProfileIsSRGB; 21 bool gDefaultProfileIsSRGB;
15 22
16 SkColorProfileType SkDefaultColorProfile() { 23 SkColorProfileType SkDefaultColorProfile() {
17 return gDefaultProfileIsSRGB ? kSRGB_SkColorProfileType 24 return gDefaultProfileIsSRGB ? kSRGB_SkColorProfileType
18 : kLinear_SkColorProfileType; 25 : kLinear_SkColorProfileType;
19 } 26 }
20 27
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) { 28 static bool alpha_type_is_valid(SkAlphaType alphaType) {
26 return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType); 29 return (alphaType >= 0) && (alphaType <= kLastEnum_SkAlphaType);
27 } 30 }
28 31
29 static bool color_type_is_valid(SkColorType colorType) { 32 static bool color_type_is_valid(SkColorType colorType) {
30 return (colorType >= 0) && (colorType <= kLastEnum_SkColorType); 33 return (colorType >= 0) && (colorType <= kLastEnum_SkColorType);
31 } 34 }
32 35
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) { 36 SkImageInfo SkImageInfo::MakeS32(int width, int height, SkAlphaType at) {
45 return SkImageInfo(width, height, kN32_SkColorType, at, kSRGB_SkColorProfile Type, 37 return SkImageInfo(width, height, kN32_SkColorType, at,
46 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)); 38 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named));
47 } 39 }
48 40
49 void SkImageInfo::unflatten(SkReadBuffer& buffer) { 41 void SkImageInfo::unflatten(SkReadBuffer& buffer) {
50 fWidth = buffer.read32(); 42 fWidth = buffer.read32();
51 fHeight = buffer.read32(); 43 fHeight = buffer.read32();
52 44
53 uint32_t packed = buffer.read32(); 45 uint32_t packed = buffer.read32();
54 SkASSERT(0 == (packed >> 24)); 46 SkASSERT(0 == (packed >> 24));
55 fProfileType = (SkColorProfileType)((packed >> 16) & 0xFF); 47 // fProfileType = (SkColorProfileType)((packed >> 16) & 0xFF);
msarett 2016/06/17 12:44:19 I'll need to fix these to flatten/unflatten SkColo
reed1 2016/06/17 13:11:48 Ooo right. I need to ponder that.
56 fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF); 48 fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF);
57 fColorType = (SkColorType)((packed >> 0) & 0xFF); 49 fColorType = (SkColorType)((packed >> 0) & 0xFF);
58 buffer.validate(profile_type_is_valid(fProfileType) && 50 buffer.validate(alpha_type_is_valid(fAlphaType) && color_type_is_valid(fColo rType));
59 alpha_type_is_valid(fAlphaType) &&
60 color_type_is_valid(fColorType));
61 } 51 }
62 52
63 void SkImageInfo::flatten(SkWriteBuffer& buffer) const { 53 void SkImageInfo::flatten(SkWriteBuffer& buffer) const {
64 buffer.write32(fWidth); 54 buffer.write32(fWidth);
65 buffer.write32(fHeight); 55 buffer.write32(fHeight);
66 56
67 SkASSERT(0 == (fProfileType & ~0xFF));
68 SkASSERT(0 == (fAlphaType & ~0xFF)); 57 SkASSERT(0 == (fAlphaType & ~0xFF));
69 SkASSERT(0 == (fColorType & ~0xFF)); 58 SkASSERT(0 == (fColorType & ~0xFF));
70 uint32_t packed = (fProfileType << 16) | (fAlphaType << 8) | fColorType; 59 uint32_t packed = /*(fProfileType << 16) |*/ (fAlphaType << 8) | fColorType;
71 buffer.write32(packed); 60 buffer.write32(packed);
72 } 61 }
73 62
74 bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, 63 bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
75 SkAlphaType* canonical) { 64 SkAlphaType* canonical) {
76 switch (colorType) { 65 switch (colorType) {
77 case kUnknown_SkColorType: 66 case kUnknown_SkColorType:
78 alphaType = kUnknown_SkAlphaType; 67 alphaType = kUnknown_SkAlphaType;
79 break; 68 break;
80 case kAlpha_8_SkColorType: 69 case kAlpha_8_SkColorType:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 128 }
140 // here x,y are either 0 or negative 129 // here x,y are either 0 or negative
141 fPixels = ((char*)fPixels - y * fRowBytes - x * fInfo.bytesPerPixel()); 130 fPixels = ((char*)fPixels - y * fRowBytes - x * fInfo.bytesPerPixel());
142 // the intersect may have shrunk info's logical size 131 // the intersect may have shrunk info's logical size
143 fInfo = fInfo.makeWH(srcR.width(), srcR.height()); 132 fInfo = fInfo.makeWH(srcR.width(), srcR.height());
144 fX = srcR.x(); 133 fX = srcR.x();
145 fY = srcR.y(); 134 fY = srcR.y();
146 135
147 return true; 136 return true;
148 } 137 }
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