| Index: include/core/SkBitmap.h
|
| diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
|
| index 42ef8778bfcf05c66221a2bcff2ded6dec875c30..b8027f6fae6c202501392a47fcc293e6ddd968f0 100644
|
| --- a/include/core/SkBitmap.h
|
| +++ b/include/core/SkBitmap.h
|
| @@ -14,6 +14,9 @@
|
| #include "SkPoint.h"
|
| #include "SkRefCnt.h"
|
|
|
| +#define SK_SUPPORT_LEGACY_BITMAPCONFIG
|
| +//#define SK_SUPPORT_LEGACY_BITMAP_COMPUTESIZE
|
| +
|
| struct SkIRect;
|
| struct SkRect;
|
| class SkPaint;
|
| @@ -88,24 +91,22 @@ public:
|
| SkColorType colorType() const { return fInfo.fColorType; }
|
| SkAlphaType alphaType() const { return fInfo.fAlphaType; }
|
|
|
| - /** Return the number of bytes per pixel based on the config. If the config
|
| - does not have at least 1 byte per (e.g. kA1_Config) then 0 is returned.
|
| + /**
|
| + * Return the number of bytes per pixel based on the colorType.
|
| */
|
| int bytesPerPixel() const { return fInfo.bytesPerPixel(); }
|
|
|
| - /** Return the rowbytes expressed as a number of pixels (like width and
|
| - height). Note, for 1-byte per pixel configs like kA8_Config, this will
|
| - return the same as rowBytes(). Is undefined for configs that are less
|
| - than 1-byte per pixel (e.g. kA1_Config)
|
| + /**
|
| + * Return the rowbytes expressed as a number of pixels (like width and
|
| + * height).
|
| */
|
| int rowBytesAsPixels() const {
|
| return fRowBytes >> this->shiftPerPixel();
|
| }
|
|
|
| - /** Return the shift amount per pixel (i.e. 0 for 1-byte per pixel, 1 for
|
| - 2-bytes per pixel configs, 2 for 4-bytes per pixel configs). Return 0
|
| - for configs that are not at least 1-byte per pixel (e.g. kA1_Config
|
| - or kNo_Config)
|
| + /**
|
| + * Return the shift amount per pixel (i.e. 0 for 1-byte per pixel, 1 for
|
| + * 2-bytes per pixel configs, 2 for 4-bytes per pixel configs).
|
| */
|
| int shiftPerPixel() const { return this->bytesPerPixel() >> 1; }
|
|
|
| @@ -126,11 +127,13 @@ public:
|
| */
|
| bool drawsNothing() const { return this->empty() || this->isNull(); }
|
|
|
| - /** Return the config for the bitmap. */
|
| +//#ifdef SK_SUPPORT_LEGACY_BITMAPCONFIG
|
| + SK_ATTR_DEPRECATED("use colorType()")
|
| Config config() const;
|
|
|
| - SK_ATTR_DEPRECATED("use config()")
|
| + SK_ATTR_DEPRECATED("use colorType()")
|
| Config getConfig() const { return this->config(); }
|
| +//#endif
|
|
|
| /** Return the number of bytes between subsequent rows of the bitmap. */
|
| size_t rowBytes() const { return fRowBytes; }
|
| @@ -138,7 +141,7 @@ public:
|
| /**
|
| * Set the bitmap's alphaType, returning true on success. If false is
|
| * returned, then the specified new alphaType is incompatible with the
|
| - * Config, and the current alphaType is unchanged.
|
| + * ColorType, and the current alphaType is unchanged.
|
| *
|
| * Note: this changes the alphatype for the underlying pixels, which means
|
| * that all bitmaps that might be sharing (subsets of) the pixels will
|
| @@ -215,9 +218,11 @@ public:
|
| */
|
| void reset();
|
|
|
| - /** Given a config and a width, this computes the optimal rowBytes value. This is called automatically
|
| - if you pass 0 for rowBytes to setConfig().
|
| - */
|
| +#ifdef SK_SUPPORT_LEGACY_BITMAP_COMPUTESIZE
|
| + /**
|
| + * Given a config and a width, this computes the optimal rowBytes value.
|
| + * This is called automatically if you pass 0 for rowBytes to setConfig().
|
| + */
|
| static size_t ComputeRowBytes(Config c, int width);
|
|
|
| /** Return the bytes-per-pixel for the specified config. If the config is
|
| @@ -234,6 +239,7 @@ public:
|
|
|
| static int64_t ComputeSize64(Config, int width, int height);
|
| static size_t ComputeSize(Config, int width, int height);
|
| +#endif
|
|
|
| /**
|
| * This will brute-force return true if all of the pixels in the bitmap
|
| @@ -252,6 +258,7 @@ public:
|
| void getBounds(SkRect* bounds) const;
|
| void getBounds(SkIRect* bounds) const;
|
|
|
| +#ifdef SK_SUPPORT_LEGACY_BITMAPCONFIG
|
| /** 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().
|
| @@ -262,6 +269,7 @@ public:
|
| return this->setConfig(config, width, height, rowBytes,
|
| kPremul_SkAlphaType);
|
| }
|
| +#endif
|
|
|
| bool setConfig(const SkImageInfo& info, size_t rowBytes = 0);
|
|
|
| @@ -283,11 +291,13 @@ public:
|
| return this->allocPixels(info, NULL, NULL);
|
| }
|
|
|
| +#ifdef SK_SUPPORT_LEGACY_BITMAPCONFIG
|
| /**
|
| * Legacy helper function, which creates an SkImageInfo from the specified
|
| * config and then calls allocPixels(info).
|
| */
|
| bool allocConfigPixels(Config, int width, int height, bool isOpaque = false);
|
| +#endif
|
|
|
| bool allocN32Pixels(int width, int height, bool isOpaque = false) {
|
| SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
|
| @@ -356,7 +366,7 @@ public:
|
| bool preserveDstPad = false) const;
|
|
|
| /** Use the standard HeapAllocator to create the pixelref that manages the
|
| - pixel memory. It will be sized based on the current width/height/config.
|
| + pixel memory. It will be sized based on the current ImageInfo.
|
| If this is called multiple times, a new pixelref object will be created
|
| each time.
|
|
|
| @@ -364,7 +374,7 @@ public:
|
| not null) it will take care of incrementing the reference count.
|
|
|
| @param ctable ColorTable (or null) to use with the pixels that will
|
| - be allocated. Only used if config == Index8_Config
|
| + be allocated. Only used if ColorType == Index_8
|
| @return true if the allocation succeeds. If not the pixelref field of
|
| the bitmap will be unchanged.
|
| */
|
| @@ -373,7 +383,7 @@ public:
|
| }
|
|
|
| /** Use the specified Allocator to create the pixelref that manages the
|
| - pixel memory. It will be sized based on the current width/height/config.
|
| + pixel memory. It will be sized based on the current ImageInfo.
|
| If this is called multiple times, a new pixelref object will be created
|
| each time.
|
|
|
| @@ -381,13 +391,13 @@ public:
|
| not null) it will take care of incrementing the reference count.
|
|
|
| @param allocator The Allocator to use to create a pixelref that can
|
| - manage the pixel memory for the current
|
| - width/height/config. If allocator is NULL, the standard
|
| - HeapAllocator will be used.
|
| + manage the pixel memory for the current ImageInfo.
|
| + If allocator is NULL, the standard HeapAllocator will
|
| + be used.
|
| @param ctable ColorTable (or null) to use with the pixels that will
|
| - be allocated. Only used if config == Index8_Config.
|
| - If it is non-null and the config is not Index8, it will
|
| - be ignored.
|
| + be allocated. Only used if ColorType == Index_8.
|
| + If it is non-null and the colorType is not Index_8, it
|
| + will be ignored.
|
| @return true if the allocation succeeds. If not the pixelref field of
|
| the bitmap will be unchanged.
|
| */
|
| @@ -450,12 +460,13 @@ public:
|
| bool lockPixelsAreWritable() const;
|
|
|
| /** Call this to be sure that the bitmap is valid enough to be drawn (i.e.
|
| - it has non-null pixels, and if required by its config, it has a
|
| + it has non-null pixels, and if required by its colorType, it has a
|
| non-null colortable. Returns true if all of the above are met.
|
| */
|
| bool readyToDraw() const {
|
| - return this->getPixels() != NULL &&
|
| - (this->config() != kIndex8_Config || NULL != fColorTable);
|
| + return NULL != this->getPixels() &&
|
| + (this->colorType() != kIndex_8_SkColorType ||
|
| + NULL != fColorTable);
|
| }
|
|
|
| /** Returns the pixelRef's texture, or NULL
|
| @@ -484,9 +495,9 @@ public:
|
|
|
| /**
|
| * Fill the entire bitmap with the specified color.
|
| - * If the bitmap's config does not support alpha (e.g. 565) then the alpha
|
| + * If the ColorType does not support alpha (e.g. 565) then the alpha
|
| * of the color is ignored (treated as opaque). If the config only supports
|
| - * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored.
|
| + * alpha (e.g. Alpha_8) then the color's r,g,b components are ignored.
|
| */
|
| void eraseColor(SkColor c) const {
|
| this->eraseARGB(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c),
|
| @@ -495,9 +506,9 @@ public:
|
|
|
| /**
|
| * Fill the entire bitmap with the specified color.
|
| - * If the bitmap's config does not support alpha (e.g. 565) then the alpha
|
| - * of the color is ignored (treated as opaque). If the config only supports
|
| - * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored.
|
| + * If the ColorType does not support alpha (e.g. 565) then the alpha
|
| + * of the color is ignored (treated as opaque). If the ColorType only
|
| + * supports alpha (e.g. Alpha_8) then the r,g,b components are ignored.
|
| */
|
| void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const;
|
|
|
| @@ -508,9 +519,9 @@ public:
|
|
|
| /**
|
| * Fill the specified area of this bitmap with the specified color.
|
| - * If the bitmap's config does not support alpha (e.g. 565) then the alpha
|
| - * of the color is ignored (treated as opaque). If the config only supports
|
| - * alpha (e.g. A1 or A8) then the color's r,g,b components are ignored.
|
| + * If the ColorType does not support alpha (e.g. 565) then the alpha
|
| + * of the color is ignored (treated as opaque). If the ColorType only
|
| + * supports alpha (e.g. Alpha_8) then the r,g,b components are ignored.
|
| */
|
| void eraseArea(const SkIRect& area, SkColor c) const;
|
|
|
| @@ -528,9 +539,7 @@ public:
|
| was scrolled away. E.g. if dx = dy = 0, then inval would
|
| be set to empty. If dx >= width or dy >= height, then
|
| inval would be set to the entire bounds of the bitmap.
|
| - @return true if the scroll was doable. Will return false if the bitmap
|
| - uses an unsupported config for scrolling (only kA8,
|
| - kIndex8, kRGB_565, kARGB_4444, kARGB_8888 are supported).
|
| + @return true if the scroll was doable. Will return false on failure.
|
| If no pixels are present (i.e. getPixels() returns false)
|
| inval will still be updated, and true will be returned.
|
| */
|
| @@ -539,9 +548,9 @@ public:
|
|
|
| /**
|
| * Return the SkColor of the specified pixel. In most cases this will
|
| - * require un-premultiplying the color. Alpha only configs (A1 and A8)
|
| + * require un-premultiplying the color. Alpha only ColorType (Alpha_8)
|
| * return black with the appropriate alpha set. The value is undefined
|
| - * for kNone_Config or if x or y are out of bounds, or if the bitmap
|
| + * for kUnknown_ColorType or if x or y are out of bounds, or if the bitmap
|
| * does not have any pixels (or has not be locked with lockPixels()).
|
| */
|
| SkColor getColor(int x, int y) const;
|
| @@ -559,39 +568,39 @@ public:
|
|
|
| /** Returns the address of the pixel specified by x,y for 32bit pixels.
|
| * In debug build, this asserts that the pixels are allocated and locked,
|
| - * and that the config is 32-bit, however none of these checks are performed
|
| - * in the release build.
|
| + * and that the ColorType is 32-bit, however none of these checks are
|
| + * performed in the release build.
|
| */
|
| inline uint32_t* getAddr32(int x, int y) const;
|
|
|
| /** Returns the address of the pixel specified by x,y for 16bit pixels.
|
| * In debug build, this asserts that the pixels are allocated and locked,
|
| - * and that the config is 16-bit, however none of these checks are performed
|
| - * in the release build.
|
| + * and that the ColorType is 16-bit, however none of these checks are
|
| + * performed in the release build.
|
| */
|
| inline uint16_t* getAddr16(int x, int y) const;
|
|
|
| /** Returns the address of the pixel specified by x,y for 8bit pixels.
|
| * In debug build, this asserts that the pixels are allocated and locked,
|
| - * and that the config is 8-bit, however none of these checks are performed
|
| - * in the release build.
|
| + * and that the ColorType is 8-bit, however none of these checks are
|
| + * performed in the release build.
|
| */
|
| inline uint8_t* getAddr8(int x, int y) const;
|
|
|
| /** Returns the color corresponding to the pixel specified by x,y for
|
| * colortable based bitmaps.
|
| * In debug build, this asserts that the pixels are allocated and locked,
|
| - * that the config is kIndex8, and that the colortable is allocated,
|
| + * that the ColorType is Index_8, and that the colortable is allocated,
|
| * however none of these checks are performed in the release build.
|
| */
|
| inline SkPMColor getIndex8Color(int x, int y) const;
|
|
|
| /** Set dst to be a setset of this bitmap. If possible, it will share the
|
| - pixel memory, and just point into a subset of it. However, if the config
|
| - does not support this, a local copy will be made and associated with
|
| + pixel memory, and just point into a subset of it. If this is not
|
| + supported, a local copy will be made and associated with
|
| the dst bitmap. If the subset rectangle, intersected with the bitmap's
|
| - dimensions is empty, or if there is an unsupported config, false will be
|
| - returned and dst will be untouched.
|
| + dimensions is empty, or if there is an unsupported colorType, false will
|
| + be returned and dst will be untouched.
|
| @param dst The bitmap that will be set to a subset of this bitmap
|
| @param subset The rectangle of pixels in this bitmap that dst will
|
| reference.
|
| @@ -599,6 +608,7 @@ public:
|
| */
|
| bool extractSubset(SkBitmap* dst, const SkIRect& subset) const;
|
|
|
| +#ifdef SK_SUPPORT_LEGACY_BITMAPCONFIG
|
| /** Makes a deep copy of this bitmap, respecting the requested config,
|
| * and allocating the dst pixels on the cpu.
|
| * Returns false if either there is an error (i.e. the src does not have
|
| @@ -625,7 +635,13 @@ public:
|
| /** Returns true if this bitmap can be deep copied into the requested config
|
| by calling copyTo().
|
| */
|
| - bool canCopyTo(Config newConfig) const;
|
| + bool canCopyTo(Config config) const;
|
| +#endif
|
| + /**
|
| + * Returns true if this bitmap can be deep copied into the requested
|
| + * colorType by calling copyTo().
|
| + */
|
| + bool canCopyTo(SkColorType) const;
|
|
|
| SK_ATTR_DEPRECATED("use setFilterLevel on SkPaint")
|
| void buildMipMap(bool forceRebuild = false);
|
| @@ -685,10 +701,10 @@ public:
|
| public:
|
| SK_DECLARE_INST_COUNT(Allocator)
|
|
|
| - /** Allocate the pixel memory for the bitmap, given its dimensions and
|
| - config. Return true on success, where success means either setPixels
|
| + /** Allocate the pixel memory for the bitmap, given its ImageInfo.
|
| + Return true on success, where success means either setPixels
|
| or setPixelRef was called. The pixels need not be locked when this
|
| - returns. If the config requires a colortable, it also must be
|
| + returns. If the ColorType requires a colortable, it also must be
|
| installed via setColorTable. If false is returned, the bitmap and
|
| colortable should be left unchanged.
|
| */
|
| @@ -762,6 +778,7 @@ private:
|
|
|
| void internalErase(const SkIRect&, U8CPU a, U8CPU r, U8CPU g, U8CPU b)const;
|
|
|
| +#ifdef SK_SUPPORT_LEGACY_BITMAP_COMPUTESIZE
|
| /* Internal computations for safe size.
|
| */
|
| static int64_t ComputeSafeSize64(Config config,
|
| @@ -772,6 +789,7 @@ private:
|
| uint32_t width,
|
| uint32_t height,
|
| size_t rowBytes);
|
| +#endif
|
|
|
| /* Unreference any pixelrefs or colortables
|
| */
|
| @@ -870,31 +888,36 @@ private:
|
|
|
| inline uint32_t* SkBitmap::getAddr32(int x, int y) const {
|
| SkASSERT(fPixels);
|
| - SkASSERT(this->config() == kARGB_8888_Config);
|
| + SkASSERT(4 == this->bytesPerPixel());
|
| SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height());
|
| return (uint32_t*)((char*)fPixels + y * fRowBytes + (x << 2));
|
| }
|
|
|
| inline uint16_t* SkBitmap::getAddr16(int x, int y) const {
|
| SkASSERT(fPixels);
|
| - SkASSERT(this->config() == kRGB_565_Config || this->config() == kARGB_4444_Config);
|
| + SkASSERT(2 == this->bytesPerPixel());
|
| SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height());
|
| return (uint16_t*)((char*)fPixels + y * fRowBytes + (x << 1));
|
| }
|
|
|
| inline uint8_t* SkBitmap::getAddr8(int x, int y) const {
|
| SkASSERT(fPixels);
|
| - SkASSERT(this->config() == kA8_Config || this->config() == kIndex8_Config);
|
| + SkASSERT(1 == this->bytesPerPixel());
|
| SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height());
|
| return (uint8_t*)fPixels + y * fRowBytes + x;
|
| }
|
|
|
| inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const {
|
| SkASSERT(fPixels);
|
| - SkASSERT(this->config() == kIndex8_Config);
|
| + SkASSERT(kIndex_8_SkColorType == this->colorType());
|
| SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)this->height());
|
| SkASSERT(fColorTable);
|
| return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)];
|
| }
|
|
|
| +///////////////////////////////////////////////////////////////////////////////
|
| +
|
| +extern SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType);
|
| +extern SkColorType SkBitmapConfigToColorType(SkBitmap::Config);
|
| +
|
| #endif
|
|
|