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

Unified Diff: src/core/SkBitmap.cpp

Issue 25275004: store SkAlphaType inside SkBitmap, on road to support unpremul (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« include/core/SkBitmap.h ('K') | « include/core/SkBitmap.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
« include/core/SkBitmap.h ('K') | « include/core/SkBitmap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698