OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #ifndef SkImageInfo_DEFINED | 8 #ifndef SkImageInfo_DEFINED |
9 #define SkImageInfo_DEFINED | 9 #define SkImageInfo_DEFINED |
10 | 10 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 102 |
103 /** | 103 /** |
104 * Describe an image's dimensions and pixel type. | 104 * Describe an image's dimensions and pixel type. |
105 */ | 105 */ |
106 struct SkImageInfo { | 106 struct SkImageInfo { |
107 int fWidth; | 107 int fWidth; |
108 int fHeight; | 108 int fHeight; |
109 SkColorType fColorType; | 109 SkColorType fColorType; |
110 SkAlphaType fAlphaType; | 110 SkAlphaType fAlphaType; |
111 | 111 |
112 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t) { | |
113 SkASSERT(width >= 0); | |
114 SkASSERT(height >= 0); | |
115 SkImageInfo info = { | |
116 width, height, ct, at | |
117 }; | |
118 return info; | |
119 } | |
120 | |
121 /** | |
122 * Sets colortype to the native ARGB32 type. | |
123 */ | |
124 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { | |
125 SkASSERT(width >= 0); | |
126 SkASSERT(height >= 0); | |
127 SkImageInfo info = { | |
128 width, height, kPMColor_SkColorType, at | |
129 }; | |
130 return info; | |
131 } | |
132 | |
133 /** | |
134 * Sets colortype to the native ARGB32 type, and the alphatype to premul. | |
135 */ | |
136 static SkImageInfo MakeN32Premul(int width, int height) { | |
137 SkASSERT(width >= 0); | |
138 SkASSERT(height >= 0); | |
139 SkImageInfo info = { | |
140 width, height, kPMColor_SkColorType, kPremul_SkAlphaType | |
141 }; | |
142 return info; | |
143 } | |
144 | |
145 /** | |
146 * Sets colortype to the native ARGB32 type, and the alphatype to opaque. | |
147 */ | |
148 static SkImageInfo MakeN32Opaque(int width, int height) { | |
149 SkASSERT(width >= 0); | |
150 SkASSERT(height >= 0); | |
151 SkImageInfo info = { | |
152 width, height, kPMColor_SkColorType, kOpaque_SkAlphaType | |
153 }; | |
154 return info; | |
155 } | |
156 | |
157 static SkImageInfo MakeA8(int width, int height) { | |
158 SkASSERT(width >= 0); | |
159 SkASSERT(height >= 0); | |
160 SkImageInfo info = { | |
161 width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType | |
162 }; | |
163 return info; | |
164 } | |
165 | |
166 bool isOpaque() const { | 112 bool isOpaque() const { |
167 return SkAlphaTypeIsOpaque(fAlphaType); | 113 return SkAlphaTypeIsOpaque(fAlphaType); |
168 } | 114 } |
169 | 115 |
170 int bytesPerPixel() const { | 116 int bytesPerPixel() const { |
171 return SkColorTypeBytesPerPixel(fColorType); | 117 return SkColorTypeBytesPerPixel(fColorType); |
172 } | 118 } |
173 | 119 |
174 size_t minRowBytes() const { | 120 size_t minRowBytes() const { |
175 return fWidth * this->bytesPerPixel(); | 121 return fWidth * this->bytesPerPixel(); |
(...skipping 11 matching lines...) Expand all Loading... |
187 | 133 |
188 size_t getSafeSize(size_t rowBytes) const { | 134 size_t getSafeSize(size_t rowBytes) const { |
189 if (0 == fHeight) { | 135 if (0 == fHeight) { |
190 return 0; | 136 return 0; |
191 } | 137 } |
192 return (fHeight - 1) * rowBytes + fWidth * this->bytesPerPixel(); | 138 return (fHeight - 1) * rowBytes + fWidth * this->bytesPerPixel(); |
193 } | 139 } |
194 }; | 140 }; |
195 | 141 |
196 #endif | 142 #endif |
OLD | NEW |