| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 */ | 129 */ |
| 130 bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, | 130 bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, |
| 131 SkAlphaType* canonical = NULL); | 131 SkAlphaType* canonical = NULL); |
| 132 | 132 |
| 133 /////////////////////////////////////////////////////////////////////////////// | 133 /////////////////////////////////////////////////////////////////////////////// |
| 134 | 134 |
| 135 /** | 135 /** |
| 136 * Describe an image's dimensions and pixel type. | 136 * Describe an image's dimensions and pixel type. |
| 137 */ | 137 */ |
| 138 struct SkImageInfo { | 138 struct SkImageInfo { |
| 139 int fWidth; | 139 public: |
| 140 int fHeight; | 140 SkImageInfo() |
| 141 SkColorType fColorType; | 141 : fWidth(0) |
| 142 SkAlphaType fAlphaType; | 142 , fHeight(0) |
| 143 , fColorType(kUnknown_SkColorType) |
| 144 , fAlphaType(kIgnore_SkAlphaType) |
| 145 {} |
| 143 | 146 |
| 144 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t) { | 147 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a
t) { |
| 145 SkImageInfo info = { | 148 return SkImageInfo(width, height, ct, at); |
| 146 width, height, ct, at | |
| 147 }; | |
| 148 return info; | |
| 149 } | 149 } |
| 150 | 150 |
| 151 /** | 151 /** |
| 152 * Sets colortype to the native ARGB32 type. | 152 * Sets colortype to the native ARGB32 type. |
| 153 */ | 153 */ |
| 154 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { | 154 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { |
| 155 SkImageInfo info = { | 155 return SkImageInfo(width, height, kN32_SkColorType, at); |
| 156 width, height, kN32_SkColorType, at | |
| 157 }; | |
| 158 return info; | |
| 159 } | 156 } |
| 160 | 157 |
| 161 /** | 158 /** |
| 162 * Sets colortype to the native ARGB32 type, and the alphatype to premul. | 159 * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
| 163 */ | 160 */ |
| 164 static SkImageInfo MakeN32Premul(int width, int height) { | 161 static SkImageInfo MakeN32Premul(int width, int height) { |
| 165 SkImageInfo info = { | 162 return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType)
; |
| 166 width, height, kN32_SkColorType, kPremul_SkAlphaType | |
| 167 }; | |
| 168 return info; | |
| 169 } | 163 } |
| 170 | 164 |
| 171 /** | 165 /** |
| 172 * Sets colortype to the native ARGB32 type, and the alphatype to premul. | 166 * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
| 173 */ | 167 */ |
| 174 static SkImageInfo MakeN32Premul(const SkISize& size) { | 168 static SkImageInfo MakeN32Premul(const SkISize& size) { |
| 175 return MakeN32Premul(size.width(), size.height()); | 169 return MakeN32Premul(size.width(), size.height()); |
| 176 } | 170 } |
| 177 | 171 |
| 178 static SkImageInfo MakeA8(int width, int height) { | 172 static SkImageInfo MakeA8(int width, int height) { |
| 179 SkImageInfo info = { | 173 return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaT
ype); |
| 180 width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType | |
| 181 }; | |
| 182 return info; | |
| 183 } | 174 } |
| 184 | 175 |
| 185 static SkImageInfo MakeUnknown(int width, int height) { | 176 static SkImageInfo MakeUnknown(int width, int height) { |
| 186 SkImageInfo info = { | 177 return SkImageInfo(width, height, kUnknown_SkColorType, kIgnore_SkAlphaT
ype); |
| 187 width, height, kUnknown_SkColorType, kIgnore_SkAlphaType | |
| 188 }; | |
| 189 return info; | |
| 190 } | 178 } |
| 191 | 179 |
| 192 static SkImageInfo MakeUnknown() { | 180 static SkImageInfo MakeUnknown() { |
| 193 SkImageInfo info = { | 181 return SkImageInfo(); |
| 194 0, 0, kUnknown_SkColorType, kIgnore_SkAlphaType | |
| 195 }; | |
| 196 return info; | |
| 197 } | 182 } |
| 198 | 183 |
| 199 int width() const { return fWidth; } | 184 int width() const { return fWidth; } |
| 200 int height() const { return fHeight; } | 185 int height() const { return fHeight; } |
| 201 SkColorType colorType() const { return fColorType; } | 186 SkColorType colorType() const { return fColorType; } |
| 202 SkAlphaType alphaType() const { return fAlphaType; } | 187 SkAlphaType alphaType() const { return fAlphaType; } |
| 203 | 188 |
| 204 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } | 189 bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } |
| 205 | 190 |
| 206 bool isOpaque() const { | 191 bool isOpaque() const { |
| 207 return SkAlphaTypeIsOpaque(fAlphaType); | 192 return SkAlphaTypeIsOpaque(fAlphaType); |
| 208 } | 193 } |
| 209 | 194 |
| 210 SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); } | 195 SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); } |
| 211 | 196 |
| 212 /** | 197 /** |
| 213 * Return a new ImageInfo with the same colortype and alphatype as this inf
o, | 198 * Return a new ImageInfo with the same colortype and alphatype as this inf
o, |
| 214 * but with the specified width and height. | 199 * but with the specified width and height. |
| 215 */ | 200 */ |
| 216 SkImageInfo makeWH(int newWidth, int newHeight) const { | 201 SkImageInfo makeWH(int newWidth, int newHeight) const { |
| 217 return SkImageInfo::Make(newWidth, newHeight, fColorType, fAlphaType); | 202 return SkImageInfo::Make(newWidth, newHeight, fColorType, fAlphaType); |
| 218 } | 203 } |
| 219 | 204 |
| 205 SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const { |
| 206 return SkImageInfo::Make(fWidth, fHeight, fColorType, newAlphaType); |
| 207 } |
| 208 |
| 209 SkImageInfo makeColorType(SkColorType newColorType) const { |
| 210 return SkImageInfo::Make(fWidth, fHeight, newColorType, fAlphaType); |
| 211 } |
| 212 |
| 220 int bytesPerPixel() const { | 213 int bytesPerPixel() const { |
| 221 return SkColorTypeBytesPerPixel(fColorType); | 214 return SkColorTypeBytesPerPixel(fColorType); |
| 222 } | 215 } |
| 223 | 216 |
| 224 uint64_t minRowBytes64() const { | 217 uint64_t minRowBytes64() const { |
| 225 return sk_64_mul(fWidth, this->bytesPerPixel()); | 218 return sk_64_mul(fWidth, this->bytesPerPixel()); |
| 226 } | 219 } |
| 227 | 220 |
| 228 size_t minRowBytes() const { | 221 size_t minRowBytes() const { |
| 229 return (size_t)this->minRowBytes64(); | 222 return (size_t)this->minRowBytes64(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 249 size_t getSafeSize(size_t rowBytes) const { | 242 size_t getSafeSize(size_t rowBytes) const { |
| 250 return (size_t)this->getSafeSize64(rowBytes); | 243 return (size_t)this->getSafeSize64(rowBytes); |
| 251 } | 244 } |
| 252 | 245 |
| 253 bool validRowBytes(size_t rowBytes) const { | 246 bool validRowBytes(size_t rowBytes) const { |
| 254 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); | 247 uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); |
| 255 return rowBytes >= rb; | 248 return rowBytes >= rb; |
| 256 } | 249 } |
| 257 | 250 |
| 258 SkDEBUGCODE(void validate() const;) | 251 SkDEBUGCODE(void validate() const;) |
| 252 |
| 253 #ifdef SK_SUPPORT_LEGACY_PUBLIC_IMAGEINFO_FIELDS |
| 254 public: |
| 255 #else |
| 256 private: |
| 257 #endif |
| 258 int fWidth; |
| 259 int fHeight; |
| 260 SkColorType fColorType; |
| 261 SkAlphaType fAlphaType; |
| 262 |
| 263 private: |
| 264 SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at) |
| 265 : fWidth(width) |
| 266 , fHeight(height) |
| 267 , fColorType(ct) |
| 268 , fAlphaType(at) |
| 269 {} |
| 259 }; | 270 }; |
| 260 | 271 |
| 261 #endif | 272 #endif |
| OLD | NEW |