Chromium Code Reviews| Index: include/core/SkBitmap.h |
| diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h |
| index ad185479801c8b71d66c7e7381412a3be5ab13e8..9b5897d5eb60ba03e52646cea1388a3ba062c2dc 100644 |
| --- a/include/core/SkBitmap.h |
| +++ b/include/core/SkBitmap.h |
| @@ -104,6 +104,12 @@ public: |
| /** DEPRECATED, use config() |
| */ |
| Config getConfig() const { return this->config(); } |
| + |
| + /** Whether the colors are stored premultiplied. If the bitmap is opaque, |
| + the return value is undefined. |
| + */ |
| + bool premultiplied() const { return 0 == (fFlags & kColorsAreNotPremultiplied_Flag); } |
|
reed1
2013/06/12 20:20:00
isPremultiplied() ?
isUnpremultiplied() ?
|
| + |
| /** Return the bitmap's width, in pixels. |
| */ |
| int width() const { return fWidth; } |
| @@ -250,8 +256,14 @@ public: |
| /** Set the bitmap's config and dimensions. If rowBytes is 0, then |
| ComputeRowBytes() is called to compute the optimal value. This resets |
| any pixel/colortable ownership, just like reset(). |
| - */ |
| - void setConfig(Config, int width, int height, size_t rowBytes = 0); |
| + @param premul Whether the color values are premultiplied. A value of |
| + false will only be respected if Config supports unpremultiplied |
| + colors, which is currently only true for kARGB_8888. |
| + A bitmap with unpremultiplied pixels cannot be drawn to or from |
| + by Skia, but may be used by other libraries. |
| + */ |
| + void setConfig(Config, int width, int height, size_t rowBytes = 0, |
| + bool premul = true); |
|
djsollen
2013/06/12 17:59:21
why not just add a new config for unpremultiplied
scroggo
2013/06/12 18:24:42
That was my first approach, but it was brought up
|
| /** Use this to assign a new pixel address for an existing bitmap. This |
| will automatically release any pixelref previously installed. Only call |
| this if you are handling ownership/lifetime of the pixel memory. |
| @@ -364,7 +376,7 @@ public: |
| return this->getPixels() != NULL && |
| ((this->config() != kIndex8_Config && |
| this->config() != kRLE_Index8_Config) || |
| - fColorTable != NULL); |
| + fColorTable != NULL) && this->premultiplied(); |
| } |
| /** Returns the pixelRef's texture, or NULL |
| @@ -656,16 +668,17 @@ private: |
| mutable SkColorTable* fColorTable; // only meaningful for kIndex8 |
| enum Flags { |
| - kImageIsOpaque_Flag = 0x01, |
| - kImageIsVolatile_Flag = 0x02, |
| - kImageIsImmutable_Flag = 0x04, |
| + kImageIsOpaque_Flag = 0x01, |
| + kImageIsVolatile_Flag = 0x02, |
| + kImageIsImmutable_Flag = 0x04, |
| #ifdef SK_BUILD_FOR_ANDROID |
| /* A hint for the renderer responsible for drawing this bitmap |
| * indicating that it should attempt to use mipmaps when this bitmap |
| * is drawn scaled down. |
| */ |
| - kHasHardwareMipMap_Flag = 0x08, |
| + kHasHardwareMipMap_Flag = 0x08, |
| #endif |
| + kColorsAreNotPremultiplied_Flag = 0x10, |
| }; |
| uint32_t fRowBytes; |