#include <SkBitmap.h>
Classes | |
class | HeapAllocator |
class | RLEPixels |
Public Types | |
enum | Config { kNo_Config, kA1_Config, kA8_Config, kIndex8_Config, kRGB_565_Config, kARGB_4444_Config, kARGB_8888_Config, kRLE_Index8_Config, kConfigCount } |
Public Member Functions | |
SkBitmap () | |
SkBitmap (const SkBitmap &src) | |
~SkBitmap () | |
SkBitmap & | operator= (const SkBitmap &src) |
void | swap (SkBitmap &other) |
bool | empty () const |
bool | isNull () const |
Config | config () const |
Config | getConfig () const |
int | width () const |
int | height () const |
int | rowBytes () const |
int | shiftPerPixel () const |
int | bytesPerPixel () const |
int | rowBytesAsPixels () const |
void * | getPixels () const |
size_t | getSize () const |
Sk64 | getSize64 () const |
bool | isOpaque () const |
void | setIsOpaque (bool) |
void | reset () |
void | setConfig (Config, int width, int height, int rowBytes=0) |
void | setPixels (void *p, SkColorTable *ctable=NULL) |
bool | allocPixels (SkColorTable *ctable=NULL) |
bool | allocPixels (Allocator *allocator, SkColorTable *ctable) |
SkPixelRef * | pixelRef () const |
size_t | pixelRefOffset () const |
SkPixelRef * | setPixelRef (SkPixelRef *pr, size_t offset=0) |
void | lockPixels () const |
void | unlockPixels () const |
bool | readyToDraw () const |
SkColorTable * | getColorTable () const |
uint32_t | getGenerationID () const |
void | notifyPixelsChanged () const |
void | eraseARGB (U8CPU a, U8CPU r, U8CPU g, U8CPU b) const |
void | eraseRGB (U8CPU r, U8CPU g, U8CPU b) const |
void | eraseColor (SkColor c) const |
bool | scrollRect (const SkIRect *subset, int dx, int dy, SkRegion *inval=NULL) const |
void * | getAddr (int x, int y) const |
uint32_t * | getAddr32 (int x, int y) const |
uint16_t * | getAddr16 (int x, int y) const |
uint8_t * | getAddr8 (int x, int y) const |
uint8_t * | getAddr1 (int x, int y) const |
SkPMColor | getIndex8Color (int x, int y) const |
bool | extractSubset (SkBitmap *dst, const SkIRect &subset) const |
bool | copyTo (SkBitmap *dst, Config c, Allocator *allocator=NULL) const |
bool | canCopyTo (Config newConfig) const |
bool | hasMipMap () const |
void | buildMipMap (bool forceRebuild=false) |
void | freeMipMap () |
int | extractMipLevel (SkBitmap *dst, SkFixed sx, SkFixed sy) |
void | extractAlpha (SkBitmap *dst) const |
void | extractAlpha (SkBitmap *dst, const SkPaint *paint, SkIPoint *offset) const |
void | flatten (SkFlattenableWriteBuffer &) const |
void | unflatten (SkFlattenableReadBuffer &) |
SkDEBUGCODE (void validate() const ;) class Allocator | |
Static Public Member Functions | |
static int | ComputeRowBytes (Config c, int width) |
static int | ComputeBytesPerPixel (Config c) |
static int | ComputeShiftPerPixel (Config c) |
static Sk64 | ComputeSize64 (Config, int width, int height) |
static size_t | ComputeSize (Config, int width, int height) |
The SkBitmap class specifies a raster bitmap. A bitmap has an integer width and height, and a format (config), and a pointer to the actual pixels. Bitmaps can be drawn into a SkCanvas, but they are also used to specify the target of a SkCanvas' drawing operations.
Definition at line 40 of file SkBitmap.h.
enum SkBitmap::Config |
kNo_Config |
bitmap has not been configured |
kA1_Config |
1-bit per pixel, (0 is transparent, 1 is opaque) |
kA8_Config |
8-bits per pixel, with only alpha specified (0 is transparent, 0xFF is opaque) |
kIndex8_Config |
8-bits per pixel, using SkColorTable to specify the colors |
kRGB_565_Config |
16-bits per pixel, (see SkColorPriv.h for packing) |
kARGB_4444_Config |
16-bits per pixel, (see SkColorPriv.h for packing) |
kARGB_8888_Config |
32-bits per pixel, (see SkColorPriv.h for packing) |
kRLE_Index8_Config | |
kConfigCount |
Definition at line 44 of file SkBitmap.h.
SkBitmap::SkBitmap | ( | ) |
Default construct creates a bitmap with zero width and height, and no pixels. Its config is set to kNo_Config.
SkBitmap::SkBitmap | ( | const SkBitmap & | src | ) |
Constructor initializes the new bitmap by copying the src bitmap. All fields are copied, but ownership of the pixels remains with the src bitmap.
SkBitmap::~SkBitmap | ( | ) |
Decrements our (shared) pixel ownership if needed.
bool SkBitmap::allocPixels | ( | Allocator * | allocator, | |
SkColorTable * | ctable | |||
) |
Use the specified Allocator to create the pixelref that manages the pixel memory. It will be sized based on the current width/height/config. If this is called multiple times, a new pixelref object will be created each time.
If the bitmap retains a reference to the colortable (assuming it is not null) it will take care of incrementing the reference count.
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. | |
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. |
bool SkBitmap::allocPixels | ( | SkColorTable * | ctable = NULL |
) | [inline] |
Use the standard HeapAllocator to create the pixelref that manages the pixel memory. It will be sized based on the current width/height/config. If this is called multiple times, a new pixelref object will be created each time.
If the bitmap retains a reference to the colortable (assuming it is not null) it will take care of incrementing the reference count.
ctable | ColorTable (or null) to use with the pixels that will be allocated. Only used if config == Index8_Config |
Definition at line 205 of file SkBitmap.h.
void SkBitmap::buildMipMap | ( | bool | forceRebuild = false |
) |
int SkBitmap::bytesPerPixel | ( | ) | const [inline] |
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.
Definition at line 113 of file SkBitmap.h.
bool SkBitmap::canCopyTo | ( | Config | newConfig | ) | const |
Returns true if this bitmap can be deep copied into the requested config by calling copyTo().
static int SkBitmap::ComputeBytesPerPixel | ( | Config | c | ) | [static] |
Return the bytes-per-pixel for the specified config. If the config is not at least 1-byte per pixel, return 0, including for kNo_Config.
static int SkBitmap::ComputeRowBytes | ( | Config | c, | |
int | width | |||
) | [static] |
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 int SkBitmap::ComputeShiftPerPixel | ( | Config | c | ) | [inline, static] |
Return the shift-per-pixel for the specified config. If the config is not at least 1-byte per pixel, return 0, including for kNo_Config.
Definition at line 168 of file SkBitmap.h.
static size_t SkBitmap::ComputeSize | ( | Config | , | |
int | width, | |||
int | height | |||
) | [static] |
Config SkBitmap::config | ( | ) | const [inline] |
Return the config for the bitmap.
Definition at line 89 of file SkBitmap.h.
Makes a deep copy of this bitmap, respecting the requested config. Returns false if either there is an error (i.e. the src does not have pixels) or the request cannot be satisfied (e.g. the src has per-pixel alpha, and the requested config does not support alpha).
dst | The bitmap to be sized and allocated | |
c | The desired config for dst | |
allocator | Allocator used to allocate the pixelref for the dst bitmap. If this is null, the standard HeapAllocator will be used. |
bool SkBitmap::empty | ( | ) | const [inline] |
Return true iff the bitmap has empty dimensions.
Definition at line 80 of file SkBitmap.h.
Initialize the bitmap's pixels with the specified color+alpha, automatically converting into the correct format for the bitmap's config. If the config is kRGB_565_Config, then the alpha value is ignored. If the config is kA8_Config, then the r,g,b parameters are ignored.
void SkBitmap::eraseColor | ( | SkColor | c | ) | const [inline] |
Initialize the bitmap's pixels with the specified color, automatically converting into the correct format for the bitmap's config. If the config is kRGB_565_Config, then the color's alpha value is presumed to be 0xFF. If the config is kA8_Config, then only the color's alpha value is used.
Definition at line 300 of file SkBitmap.h.
Initialize the bitmap's pixels with the specified color+alpha, automatically converting into the correct format for the bitmap's config. If the config is kRGB_565_Config, then the alpha value is presumed to be 0xFF. If the config is kA8_Config, then the r,g,b parameters are ignored and the pixels are all set to 0xFF.
Definition at line 293 of file SkBitmap.h.
void SkBitmap::extractAlpha | ( | SkBitmap * | dst | ) | const [inline] |
Definition at line 398 of file SkBitmap.h.
Given scale factors sx, sy, determine the miplevel available in the bitmap, and return it (this is the amount to shift matrix iterators by). If dst is not null, it is set to the correct level.
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 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.
dst | The bitmap that will be set to a subset of this bitmap | |
subset | The rectangle of pixels in this bitmap that dst will reference. |
void SkBitmap::flatten | ( | SkFlattenableWriteBuffer & | ) | const |
void SkBitmap::freeMipMap | ( | ) |
void* SkBitmap::getAddr | ( | int | x, | |
int | y | |||
) | const |
Returns the address of the specified pixel. This performs a runtime check to know the size of the pixels, and will return the same answer as the corresponding size-specific method (e.g. getAddr16). Since the check happens at runtime, it is much slower than using a size-specific version. Unlike the size-specific methods, this routine also checks if getPixels() returns null, and returns that. The size-specific routines perform a debugging assert that getPixels() is not null, but they do not do any runtime checks.
uint8_t * SkBitmap::getAddr1 | ( | int | x, | |
int | y | |||
) | const [inline] |
Returns the address of the byte containing the pixel specified by x,y for 1bit pixels.
Definition at line 670 of file SkBitmap.h.
uint16_t * SkBitmap::getAddr16 | ( | int | x, | |
int | y | |||
) | const [inline] |
Returns the address of the pixel specified by x,y for 16bit pixels.
Definition at line 647 of file SkBitmap.h.
uint32_t * SkBitmap::getAddr32 | ( | int | x, | |
int | y | |||
) | const [inline] |
Returns the address of the pixel specified by x,y for 32bit pixels.
Definition at line 640 of file SkBitmap.h.
uint8_t * SkBitmap::getAddr8 | ( | int | x, | |
int | y | |||
) | const [inline] |
Returns the address of the pixel specified by x,y for 8bit pixels.
Definition at line 654 of file SkBitmap.h.
SkColorTable* SkBitmap::getColorTable | ( | ) | const [inline] |
Return the bitmap's colortable (if any). Does not affect the colortable's reference count.
Definition at line 268 of file SkBitmap.h.
Config SkBitmap::getConfig | ( | ) | const [inline] |
DEPRECATED, use config()
Definition at line 92 of file SkBitmap.h.
uint32_t SkBitmap::getGenerationID | ( | ) | const |
Returns a non-zero, unique value corresponding to the pixels in our pixelref, or 0 if we do not have a pixelref. Each time the pixels are changed (and notifyPixelsChanged is called), a different generation ID will be returned.
SkPMColor SkBitmap::getIndex8Color | ( | int | x, | |
int | y | |||
) | const [inline] |
Returns the color corresponding to the pixel specified by x,y for colortable based bitmaps.
Definition at line 661 of file SkBitmap.h.
void* SkBitmap::getPixels | ( | ) | const [inline] |
Return the address of the pixels for this SkBitmap.
Definition at line 124 of file SkBitmap.h.
size_t SkBitmap::getSize | ( | ) | const [inline] |
Return the byte size of the pixels, based on the height and rowBytes. Note this truncates the result to 32bits. Call getSize64() to detect if the real size exceeds 32bits.
Definition at line 130 of file SkBitmap.h.
Sk64 SkBitmap::getSize64 | ( | ) | const [inline] |
Return the byte size of the pixels, based on the height and rowBytes. This routine is slightly slower than getSize(), but does not truncate the answer to 32bits.
Definition at line 136 of file SkBitmap.h.
bool SkBitmap::hasMipMap | ( | ) | const |
int SkBitmap::height | ( | ) | const [inline] |
Return the bitmap's height, in pixels.
Definition at line 98 of file SkBitmap.h.
bool SkBitmap::isNull | ( | ) | const [inline] |
Return true iff the bitmap has no pixels nor a pixelref. Note: this can return true even if the dimensions of the bitmap are > 0 (see empty()).
Definition at line 85 of file SkBitmap.h.
bool SkBitmap::isOpaque | ( | ) | const |
Returns true if the bitmap is opaque (has no translucent/transparent pixels).
void SkBitmap::lockPixels | ( | ) | const |
Call this to ensure that the bitmap points to the current pixel address in the pixelref. Balance it with a call to unlockPixels(). These calls are harmless if there is no pixelref.
void SkBitmap::notifyPixelsChanged | ( | ) | const |
Call this if you have changed the contents of the pixels. This will in- turn cause a different generation ID value to be returned from getGenerationID().
Copies the src bitmap into this bitmap. Ownership of the src bitmap's pixels remains with the src bitmap.
SkPixelRef* SkBitmap::pixelRef | ( | ) | const [inline] |
Return the current pixelref object, of any
Definition at line 232 of file SkBitmap.h.
size_t SkBitmap::pixelRefOffset | ( | ) | const [inline] |
Return the offset into the pixelref, if any. Will return 0 if there is no pixelref installed.
Definition at line 236 of file SkBitmap.h.
bool SkBitmap::readyToDraw | ( | ) | const [inline] |
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 non-null colortable. Returns true if all of the above are met.
Definition at line 259 of file SkBitmap.h.
void SkBitmap::reset | ( | ) |
Reset the bitmap to its initial state (see default constructor). If we are a (shared) owner of the pixels, that ownership is decremented.
int SkBitmap::rowBytes | ( | ) | const [inline] |
Return the number of bytes between subsequent rows of the bitmap.
Definition at line 101 of file SkBitmap.h.
int SkBitmap::rowBytesAsPixels | ( | ) | const [inline] |
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)
Definition at line 120 of file SkBitmap.h.
Scroll (a subset of) the contents of this bitmap by dx/dy. If there are no pixels allocated (i.e. getPixels() returns null) the method will still update the inval region (if present).
subset | The subset of the bitmap to scroll/move. To scroll the entire contents, specify [0, 0, width, height] or just pass null. | |
dx | The amount to scroll in X | |
dy | The amount to scroll in Y | |
inval | Optional (may be null). Returns the area of the bitmap that 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. |
void SkBitmap::setConfig | ( | Config | , | |
int | width, | |||
int | height, | |||
int | rowBytes = 0 | |||
) |
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 SkBitmap::setIsOpaque | ( | bool | ) |
Specify if this bitmap's pixels are all opaque or not. Is only meaningful for configs that support per-pixel alpha (RGB32, A1, A8).
SkPixelRef* SkBitmap::setPixelRef | ( | SkPixelRef * | pr, | |
size_t | offset = 0 | |||
) |
Assign a pixelref and optional offset. Pixelrefs are reference counted, so the existing one (if any) will be unref'd and the new one will be ref'd.
void SkBitmap::setPixels | ( | void * | p, | |
SkColorTable * | ctable = NULL | |||
) |
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.
If the bitmap retains a reference to the colortable (assuming it is not null) it will take care of incrementing the reference count.
pixels | Address for the pixels, managed by the caller. | |
ctable | ColorTable (or null) that matches the specified pixels |
int SkBitmap::shiftPerPixel | ( | ) | const [inline] |
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)
Definition at line 108 of file SkBitmap.h.
SkBitmap::SkDEBUGCODE | ( | void validate() const ; | ) | [inline] |
Allocate the pixel memory for the bitmap, given its dimensions and config. 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 installed via setColorTable. If false is returned, the bitmap and colortable should be left unchanged.
Definition at line 408 of file SkBitmap.h.
void SkBitmap::swap | ( | SkBitmap & | other | ) |
Swap the fields of the two bitmaps. This routine is guaranteed to never fail or throw.
void SkBitmap::unflatten | ( | SkFlattenableReadBuffer & | ) |
void SkBitmap::unlockPixels | ( | ) | const |
When you are finished access the pixel memory, call this to balance a previous call to lockPixels(). This allows pixelrefs that implement cached/deferred image decoding to know when there are active clients of a given image.
int SkBitmap::width | ( | ) | const [inline] |
Return the bitmap's width, in pixels.
Definition at line 95 of file SkBitmap.h.