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

Side by Side Diff: include/codec/SkEncodedInfo.h

Issue 1820073002: Add SkEncodedInfo to report properties of encoded image data (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkEncodedInfo_DEFINED
9 #define SkEncodedInfo_DEFINED
10
11 #include "SkImageInfo.h"
12
13 struct SkEncodedInfo {
14 public:
15
16 enum Alpha {
scroggo 2016/03/23 14:48:50 Are these "Alpha" and "Color" (instead of "AlphaTy
msarett 2016/03/24 16:20:43 I agree that Type makes sense. The reason I left
17 kOpaque_Alpha,
18 kUnpremul_Alpha,
19
20 // Each pixel is either fully opaque or fully transparent.
21 // There is no difference between requesting kPremul or kUnpremul.
22 kBinary_Alpha,
23 };
24
25 /*
26 * We strive to make the number of components per pixel obvious through
27 * our naming conventions.
28 * Ex: kRGB has 3 components. kRGBA has 4 components.
29 *
30 * This sometimes results in redundant Alpha and Color information.
31 * Ex: kRGB images must also be kOpaque.
32 */
33 enum Color {
34 // PNG, WBMP
scroggo 2016/03/23 14:48:50 Isn't WBMP only Gray?
msarett 2016/03/24 16:20:43 Yes. Making this more clear.
35 kGray_Color,
36 kGrayAlpha_Color,
37
38 // PNG, GIF, BMP
39 kPalette_Color,
40
41 // PNG, RAW
42 kRGB_Color,
43 kRGBA_Color,
44
45 // BMP
46 kBGR_Color,
47 kBGRX_Color,
scroggo 2016/03/23 14:48:49 X means we ignore the alpha value, right?
msarett 2016/03/24 16:20:43 Yes. Alpha is ignored, image is always opaque.
48 kBGRA_Color,
49
50 // JPEG, WEBP
51 kYUV_Color,
52
53 // WEBP
54 kYUVA_Color,
55
56 // JPEG
57 kInvertedCMYK_Color,
scroggo 2016/03/23 14:48:50 Maybe a note here about how the spec disagrees wit
msarett 2016/03/24 16:20:43 sgtm Adding a comment.
58 kYCCK_Color,
59 };
60
61 static SkEncodedInfo Make(int width, int height, Color color, Alpha alpha,
62 int bitsPerComponent) {
63 SkASSERT(width > 0 && height > 0);
64
65 SkASSERT(1 == bitsPerComponent ||
66 2 == bitsPerComponent ||
67 4 == bitsPerComponent ||
68 8 == bitsPerComponent ||
69 16 == bitsPerComponent);
70
71 return SkEncodedInfo(width, height, color, alpha, bitsPerComponent);
72 }
73
74 /*
75 * Returns an SkImageInfo with Skia color and alpha types that are the
76 * closest possible match to the encoded info.
77 */
78 SkImageInfo makeImageInfo() const {
reed1 2016/03/22 19:12:44 why do we have this?
scroggo 2016/03/23 14:48:49 To implement SkCodec::getInfo(). Maybe we only nee
79 switch (fColor) {
80 case kGray_Color:
81 SkASSERT(kOpaque_Alpha == fAlpha);
scroggo 2016/03/23 14:48:50 Would it make sense to put all these asserts into
msarett 2016/03/24 16:20:43 Yes I think so. Let's not depend on this being ca
82 return SkImageInfo::Make(fWidth, fHeight, kGray_8_SkColorType, k Opaque_SkAlphaType);
83 case kGrayAlpha_Color:
84 SkASSERT(kOpaque_Alpha != fAlpha);
85 return SkImageInfo::Make(fWidth, fHeight, kGray_8_SkColorType,
86 kUnpremul_SkAlphaType);
87 case kPalette_Color: {
88 SkAlphaType alphaType = (kOpaque_Alpha == fAlpha) ? kOpaque_SkAl phaType :
89 kUnpremul_SkAlphaType;
90 return SkImageInfo::Make(fWidth, fHeight, kIndex_8_SkColorType, alphaType);
91 }
92 case kRGB_Color:
scroggo 2016/03/23 14:48:49 For RGB(A), should we instead return kRGBA_8888_Sk
msarett 2016/03/24 16:20:43 I think we should, but maybe not yet. I think thi
93 case kBGR_Color:
94 case kBGRX_Color:
95 case kYUV_Color:
96 case kInvertedCMYK_Color:
97 case kYCCK_Color:
98 SkASSERT(kOpaque_Alpha == fAlpha);
99 return SkImageInfo::Make(fWidth, fHeight, kN32_SkColorType, kOpa que_SkAlphaType);
100 case kRGBA_Color:
101 case kBGRA_Color:
102 case kYUVA_Color:
103 SkASSERT(kOpaque_Alpha != fAlpha);
104 return SkImageInfo::Make(fWidth, fHeight, kN32_SkColorType, kUnp remul_SkAlphaType);
105 default:
106 SkASSERT(false);
107 return SkImageInfo::MakeUnknown();
108 }
109 }
110
111 int width() const { return fWidth; }
112 int height() const { return fHeight; }
113
114 SkEncodedInfo()
115 : fWidth(0)
116 , fHeight(0)
117 , fColor(kRGBA_Color)
scroggo 2016/03/23 14:48:50 The default constructor for SkImageInfo creates so
msarett 2016/03/24 16:20:43 Yeah I think so. Adding kUnknown_Color and kUnkno
118 , fAlpha(kUnpremul_Alpha)
119 , fBitsPerComponent(0)
120 {}
121
122 private:
123
124 SkEncodedInfo(int width, int height, Color color, Alpha alpha, uint8_t bitsP erComponent)
125 : fWidth(width)
126 , fHeight(height)
127 , fColor(color)
128 , fAlpha(alpha)
129 , fBitsPerComponent(bitsPerComponent)
130 {}
131
132 int fWidth;
133 int fHeight;
134 Color fColor;
135 Alpha fAlpha;
136 uint8_t fBitsPerComponent;
137 };
138
139 #endif
OLDNEW
« no previous file with comments | « include/codec/SkCodec.h ('k') | src/codec/SkBmpCodec.h » ('j') | src/codec/SkBmpCodec.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698