Index: src/core/SkBitmap.cpp |
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp |
index 128726cb63d9198477afd698e377c6ee02cef6ed..4a7f6bf748e910e37232280589004d9e49366f55 100644 |
--- a/src/core/SkBitmap.cpp |
+++ b/src/core/SkBitmap.cpp |
@@ -266,33 +266,59 @@ void SkBitmap::getBounds(SkIRect* bounds) const { |
/////////////////////////////////////////////////////////////////////////////// |
-void SkBitmap::setConfig(Config c, int width, int height, size_t rowBytes) { |
- this->freePixels(); |
- |
+bool SkBitmap::setConfig(Config config, int width, int height, size_t rowBytes, |
+ SkAlphaType alphaType) { |
if ((width | height) < 0) { |
- goto err; |
+ goto ERROR; |
} |
- |
if (rowBytes == 0) { |
- rowBytes = SkBitmap::ComputeRowBytes(c, width); |
- if (0 == rowBytes && kNo_Config != c) { |
- goto err; |
+ rowBytes = SkBitmap::ComputeRowBytes(config, width); |
+ if (0 == rowBytes && kNo_Config != config) { |
+ goto ERROR; |
} |
} |
- fConfig = SkToU8(c); |
+ // check for legal/supported config+alphaType combinations |
+ // |
+ switch (config) { |
+ case kNo_Config: |
+ alphaType = kIgnore_SkAlphaType; // canonicalize |
+ break; |
+ case kA1_Config: |
+ case kA8_Config: |
+ if (kUnpremul_SkAlphaType == alphaType) { |
+ alphaType = kPremul_SkAlphaType; |
scroggo
2013/09/30 22:20:04
Why change it to Premul? For historical reasons/so
|
+ } |
+ // fall-through |
+ case kIndex8_Config: |
+ case kARGB_4444_Config: |
+ case kARGB_8888_Config: |
+ if (kIgnore_SkAlphaType == alphaType) { |
+ goto ERROR; // not supported yet |
+ } |
+ break; |
+ case kRGB_565_Config: |
+ alphaType = kOpaque_SkAlphaType; // canonicalize |
+ break; |
+ } |
+ |
+ this->freePixels(); |
+ |
+ fConfig = SkToU8(config); |
+ fAlphaType = SkToU8(alphaType); |
fWidth = width; |
fHeight = height; |
fRowBytes = SkToU32(rowBytes); |
- fBytesPerPixel = (uint8_t)ComputeBytesPerPixel(c); |
+ fBytesPerPixel = (uint8_t)ComputeBytesPerPixel(config); |
SkDEBUGCODE(this->validate();) |
- return; |
+ return true; |
// if we got here, we had an error, so we reset the bitmap to empty |
-err: |
+ERROR: |
this->reset(); |
+ return false; |
} |
void SkBitmap::updatePixelsFromRef() const { |