Skia
2DGraphicsLibrary
|
The SkBitmap class specifies a raster bitmap. More...
#include <SkBitmap.h>
Classes | |
class | Allocator |
class | HeapAllocator |
Subclass of Allocator that returns a pixelref that allocates its pixel memory from the heap. More... | |
class | RLEPixels |
Public Member Functions | |
SkBitmap () | |
Default construct creates a bitmap with zero width and height, and no pixels. More... | |
SkBitmap (const SkBitmap &src) | |
Copy the settings from the src into this bitmap. More... | |
SkBitmap (SkBitmap &&src) | |
Copy the settings from the src into this bitmap. More... | |
SkBitmap & | operator= (const SkBitmap &src) |
Copies the src bitmap into this bitmap. More... | |
SkBitmap & | operator= (SkBitmap &&src) |
Copies the src bitmap into this bitmap. More... | |
void | swap (SkBitmap &other) |
Swap the fields of the two bitmaps. More... | |
const SkImageInfo & | info () const |
int | width () const |
int | height () const |
SkColorType | colorType () const |
SkAlphaType | alphaType () const |
SkColorSpace * | colorSpace () const |
int | bytesPerPixel () const |
Return the number of bytes per pixel based on the colortype. More... | |
int | rowBytesAsPixels () const |
Return the rowbytes expressed as a number of pixels (like width and height). More... | |
int | shiftPerPixel () const |
Return the shift amount per pixel (i.e. More... | |
bool | empty () const |
Return true iff the bitmap has empty dimensions. More... | |
bool | isNull () const |
Return true iff the bitmap has no pixelref. More... | |
bool | drawsNothing () const |
Return true iff drawing this bitmap has no effect. | |
size_t | rowBytes () const |
Return the number of bytes between subsequent rows of the bitmap. More... | |
bool | setAlphaType (SkAlphaType) |
Set the bitmap's alphaType, returning true on success. More... | |
void * | getPixels () const |
Return the address of the pixels for this SkBitmap. | |
size_t | getSize () const |
Return the byte size of the pixels, based on the height and rowBytes. More... | |
size_t | getSafeSize () const |
Return the number of bytes from the pointer returned by getPixels() to the end of the allocated space in the buffer. More... | |
int64_t | computeSize64 () const |
Return the full size of the bitmap, in bytes. | |
int64_t | computeSafeSize64 () const |
Return the number of bytes from the pointer returned by getPixels() to the end of the allocated space in the buffer. More... | |
bool | isImmutable () const |
Returns true if this bitmap is marked as immutable, meaning that the contents of its pixels will not change for the lifetime of the bitmap. | |
void | setImmutable () |
Marks this bitmap as immutable, meaning that the contents of its pixels will not change for the lifetime of the bitmap and of the underlying pixelref. More... | |
bool | isOpaque () const |
Returns true if the bitmap is opaque (has no translucent/transparent pixels). | |
bool | isVolatile () const |
Returns true if the bitmap is volatile (i.e. More... | |
void | setIsVolatile (bool) |
Specify whether this bitmap is volatile. More... | |
void | reset () |
Reset the bitmap to its initial state (see default constructor). More... | |
void | getBounds (SkRect *bounds) const |
Return the bitmap's bounds [0, 0, width, height] as an SkRect. | |
void | getBounds (SkIRect *bounds) const |
SkIRect | bounds () const |
SkISize | dimensions () const |
SkIRect | getSubset () const |
bool | setInfo (const SkImageInfo &, size_t rowBytes=0) |
bool SK_WARN_UNUSED_RESULT | tryAllocPixels (const SkImageInfo &, SkPixelRefFactory *, SkColorTable *) |
Allocate the bitmap's pixels to match the requested image info. More... | |
void | allocPixels (const SkImageInfo &info, SkPixelRefFactory *factory, SkColorTable *ctable) |
bool SK_WARN_UNUSED_RESULT | tryAllocPixels (const SkImageInfo &info, size_t rowBytes) |
Allocate the bitmap's pixels to match the requested image info and rowBytes. More... | |
void | allocPixels (const SkImageInfo &info, size_t rowBytes) |
bool SK_WARN_UNUSED_RESULT | tryAllocPixels (const SkImageInfo &info) |
void | allocPixels (const SkImageInfo &info) |
bool SK_WARN_UNUSED_RESULT | tryAllocN32Pixels (int width, int height, bool isOpaque=false) |
void | allocN32Pixels (int width, int height, bool isOpaque=false) |
bool | installPixels (const SkImageInfo &, void *pixels, size_t rowBytes, SkColorTable *, void(*releaseProc)(void *addr, void *context), void *context) |
Install a pixelref that wraps the specified pixels and rowBytes, and optional ReleaseProc and context. More... | |
bool | installPixels (const SkImageInfo &info, void *pixels, size_t rowBytes) |
Call installPixels with no ReleaseProc specified. More... | |
bool | installPixels (const SkPixmap &) |
Call installPixels with no ReleaseProc specified. More... | |
bool | installMaskPixels (const SkMask &) |
Calls installPixels() with the value in the SkMask. More... | |
void | setPixels (void *p, SkColorTable *ctable=NULL) |
Use this to assign a new pixel address for an existing bitmap. More... | |
bool | copyPixelsTo (void *const dst, size_t dstSize, size_t dstRowBytes=0, bool preserveDstPad=false) const |
Copies the bitmap's pixels to the location pointed at by dst and returns true if possible, returns false otherwise. More... | |
bool SK_WARN_UNUSED_RESULT | tryAllocPixels (SkColorTable *ctable=NULL) |
Use the standard HeapAllocator to create the pixelref that manages the pixel memory. More... | |
void | allocPixels (SkColorTable *ctable=NULL) |
bool SK_WARN_UNUSED_RESULT | tryAllocPixels (Allocator *allocator, SkColorTable *ctable) |
Use the specified Allocator to create the pixelref that manages the pixel memory. More... | |
void | allocPixels (Allocator *allocator, SkColorTable *ctable) |
SkPixelRef * | pixelRef () const |
Return the current pixelref object or NULL if there is none. More... | |
SkIPoint | pixelRefOrigin () const |
A bitmap can reference a subset of a pixelref's pixels. More... | |
SkPixelRef * | setPixelRef (SkPixelRef *pr, int dx, int dy) |
Assign a pixelref and origin to the bitmap. More... | |
SkPixelRef * | setPixelRef (SkPixelRef *pr, const SkIPoint &origin) |
SkPixelRef * | setPixelRef (SkPixelRef *pr) |
void | lockPixels () const |
Call this to ensure that the bitmap points to the current pixel address in the pixelref. More... | |
void | unlockPixels () const |
When you are finished access the pixel memory, call this to balance a previous call to lockPixels(). More... | |
bool | lockPixelsAreWritable () const |
Some bitmaps can return a copy of their pixels for lockPixels(), but that copy, if modified, will not be pushed back. More... | |
bool | requestLock (SkAutoPixmapUnlock *result) const |
bool | readyToDraw () const |
Call this to be sure that the bitmap is valid enough to be drawn (i.e. More... | |
SkColorTable * | getColorTable () const |
Return the bitmap's colortable, if it uses one (i.e. More... | |
uint32_t | getGenerationID () const |
Returns a non-zero, unique value corresponding to the pixels in our pixelref. More... | |
void | notifyPixelsChanged () const |
Call this if you have changed the contents of the pixels. More... | |
void | eraseColor (SkColor c) const |
Fill the entire bitmap with the specified color. More... | |
void | eraseARGB (U8CPU a, U8CPU r, U8CPU g, U8CPU b) const |
Fill the entire bitmap with the specified color. More... | |
void | eraseRGB (U8CPU r, U8CPU g, U8CPU b) const |
void | erase (SkColor c, const SkIRect &area) const |
Fill the specified area of this bitmap with the specified color. More... | |
void | eraseArea (const SkIRect &area, SkColor c) const |
SkColor | getColor (int x, int y) const |
Return the SkColor of the specified pixel. More... | |
void * | getAddr (int x, int y) const |
Returns the address of the specified pixel. More... | |
uint32_t * | getAddr32 (int x, int y) const |
Returns the address of the pixel specified by x,y for 32bit pixels. More... | |
uint16_t * | getAddr16 (int x, int y) const |
Returns the address of the pixel specified by x,y for 16bit pixels. More... | |
uint8_t * | getAddr8 (int x, int y) const |
Returns the address of the pixel specified by x,y for 8bit pixels. More... | |
SkPMColor | getIndex8Color (int x, int y) const |
Returns the color corresponding to the pixel specified by x,y for colortable based bitmaps. More... | |
bool | extractSubset (SkBitmap *dst, const SkIRect &subset) const |
Set dst to be a setset of this bitmap. More... | |
bool | copyTo (SkBitmap *dst, SkColorType ct, Allocator *=NULL) const |
Makes a deep copy of this bitmap, respecting the requested colorType, and allocating the dst pixels on the cpu. More... | |
bool | copyTo (SkBitmap *dst, Allocator *allocator=NULL) const |
bool | readPixels (const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const |
Copy the bitmap's pixels into the specified buffer (pixels + rowBytes), converting them into the requested format (SkImageInfo). More... | |
bool | canCopyTo (SkColorType colorType) const |
Returns true if this bitmap's pixels can be converted into the requested colorType, such that copyTo() could succeed. | |
bool | deepCopyTo (SkBitmap *dst) const |
Makes a deep copy of this bitmap, keeping the copied pixels in the same domain as the source: If the src pixels are allocated for the cpu, then so will the dst. More... | |
bool | extractAlpha (SkBitmap *dst) const |
bool | extractAlpha (SkBitmap *dst, const SkPaint *paint, SkIPoint *offset) const |
bool | extractAlpha (SkBitmap *dst, const SkPaint *paint, Allocator *allocator, SkIPoint *offset) const |
Set dst to contain alpha layer of this bitmap. More... | |
bool | peekPixels (SkPixmap *) const |
If the pixels are available from this bitmap (w/o locking) return true, and fill out the specified pixmap (if not null). More... | |
void | validate () const |
Static Public Member Functions | |
static bool | ComputeIsOpaque (const SkBitmap &) |
This will brute-force return true if all of the pixels in the bitmap are opaque. More... | |
Public Attributes | |
class SK_API | Allocator |
Private Types | |
enum | Flags { kImageIsVolatile_Flag = 0x02 } |
Private Member Functions | |
void | freePixels () |
void | updatePixelsFromRef () const |
Static Private Member Functions | |
static void | WriteRawPixels (SkWriteBuffer *, const SkBitmap &) |
static bool | ReadRawPixels (SkReadBuffer *, SkBitmap *) |
Private Attributes | |
SkPixelRef * | fPixelRef |
int | fPixelLockCount |
void * | fPixels |
SkColorTable * | fColorTable |
SkIPoint | fPixelRefOrigin |
SkImageInfo | fInfo |
uint32_t | fRowBytes |
uint8_t | fFlags |
Friends | |
class | SkReadBuffer |
class | SkBinaryWriteBuffer |
struct | SkBitmapProcState |
The SkBitmap class specifies a raster bitmap.
A bitmap has an integer width and height, and a format (colortype), 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. A const SkBitmap exposes getAddr(), which lets a caller write its pixels; the constness is considered to apply to the bitmap's configuration, not its contents.
SkBitmap::SkBitmap | ( | ) |
Default construct creates a bitmap with zero width and height, and no pixels.
Its colortype is set to kUnknown_SkColorType.
SkBitmap::SkBitmap | ( | const SkBitmap & | src | ) |
Copy the settings from the src into this bitmap.
If the src has pixels allocated, they will be shared, not copied, so that the two bitmaps will reference the same memory for the pixels. If a deep copy is needed, where the new bitmap has its own separate copy of the pixels, use deepCopyTo().
SkBitmap::SkBitmap | ( | SkBitmap && | src | ) |
Copy the settings from the src into this bitmap.
If the src has pixels allocated, ownership of the pixels will be taken.
|
inline |
Return the number of bytes per pixel based on the colortype.
If the colortype is kUnknown_SkColorType, then 0 is returned.
|
static |
This will brute-force return true if all of the pixels in the bitmap are opaque.
If it fails to read the pixels, or encounters an error, it will return false.
Since this can be an expensive operation, the bitmap stores a flag for this (isOpaque). Only call this if you need to compute this value from "unknown" pixels.
|
inline |
Return the number of bytes from the pointer returned by getPixels() to the end of the allocated space in the buffer.
This may be smaller than computeSize64() if there is any rowbytes padding beyond the width.
bool SkBitmap::copyPixelsTo | ( | void *const | dst, |
size_t | dstSize, | ||
size_t | dstRowBytes = 0 , |
||
bool | preserveDstPad = false |
||
) | const |
Copies the bitmap's pixels to the location pointed at by dst and returns true if possible, returns false otherwise.
In the case when the dstRowBytes matches the bitmap's rowBytes, the copy may be made faster by copying over the dst's per-row padding (for all rows but the last). By setting preserveDstPad to true the caller can disable this optimization and ensure that pixels in the padding are not overwritten.
Always returns false for RLE formats.
dst | Location of destination buffer. |
dstSize | Size of destination buffer. Must be large enough to hold pixels using indicated stride. |
dstRowBytes | Width of each line in the buffer. If 0, uses bitmap's internal stride. |
preserveDstPad | Must we preserve padding in the dst |
Makes a deep copy of this bitmap, respecting the requested colorType, and allocating the dst pixels on the cpu.
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 colortype does not support alpha).
dst | The bitmap to be sized and allocated |
ct | The desired colorType 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::deepCopyTo | ( | SkBitmap * | dst | ) | const |
Makes a deep copy of this bitmap, keeping the copied pixels in the same domain as the source: If the src pixels are allocated for the cpu, then so will the dst.
If the src pixels are allocated on the gpu (typically as a texture), the it will do the same for the dst. If the request cannot be fulfilled, returns false and dst is unmodified.
|
inline |
Return true iff the bitmap has empty dimensions.
Hey! Before you use this, see if you really want to know drawsNothing() instead.
Fill the specified area of this bitmap with the specified color.
If the bitmap's 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. A1 or A8) then the color's r,g,b components are ignored.
Fill the entire bitmap with the specified color.
If the bitmap's 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. A1 or A8) then the color's r,g,b components are ignored.
void SkBitmap::eraseColor | ( | SkColor | c | ) | const |
Fill the entire bitmap with the specified color.
If the bitmap's 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. A1 or A8) then the color's r,g,b components are ignored.
bool SkBitmap::extractAlpha | ( | SkBitmap * | dst, |
const SkPaint * | paint, | ||
Allocator * | allocator, | ||
SkIPoint * | offset | ||
) | const |
Set dst to contain alpha layer of this bitmap.
If destination bitmap fails to be initialized, e.g. because allocator can't allocate pixels for it, dst will not be modified and false will be returned.
dst | The bitmap to be filled with alpha layer |
paint | The paint to draw with |
allocator | Allocator used to allocate the pixelref for the dst bitmap. If this is null, the standard HeapAllocator will be used. |
offset | If not null, it is set to top-left coordinate to position the returned bitmap so that it visually lines up with the original |
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 colortype 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 colortype, 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::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.
|
inline |
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 colortype is 16-bit, however none of these checks are performed in the release build.
|
inline |
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 colortype is 32-bit, however none of these checks are performed in the release build.
|
inline |
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 colortype is 8-bit, however none of these checks are performed in the release build.
SkColor SkBitmap::getColor | ( | int | x, |
int | y | ||
) | const |
Return the SkColor of the specified pixel.
In most cases this will require un-premultiplying the color. Alpha only colortypes (e.g. kAlpha_8_SkColorType) return black with the appropriate alpha set. The value is undefined for kUnknown_SkColorType 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()).
|
inline |
Return the bitmap's colortable, if it uses one (i.e.
colorType is Index_8) and the pixels are locked. Otherwise returns NULL. Does not affect the colortable's reference count.
uint32_t SkBitmap::getGenerationID | ( | ) | const |
Returns a non-zero, unique value corresponding to the pixels in our pixelref.
Each time the pixels are changed (and notifyPixelsChanged is called), a different generation ID will be returned. Finally, if there is no pixelRef then zero is returned.
|
inline |
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 colortype is indexed, and that the colortable is allocated, however none of these checks are performed in the release build.
|
inline |
Return the number of bytes from the pointer returned by getPixels() to the end of the allocated space in the buffer.
Required in cases where extractSubset has been called.
|
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.
bool SkBitmap::installMaskPixels | ( | const SkMask & | ) |
Calls installPixels() with the value in the SkMask.
The caller must ensure that the specified mask pixels are valid for the lifetime of the created bitmap (and its pixelRef).
bool SkBitmap::installPixels | ( | const SkImageInfo & | , |
void * | pixels, | ||
size_t | rowBytes, | ||
SkColorTable * | , | ||
void(*)(void *addr, void *context) | releaseProc, | ||
void * | context | ||
) |
Install a pixelref that wraps the specified pixels and rowBytes, and optional ReleaseProc and context.
When the pixels are no longer referenced, if releaseProc is not null, it will be called with the pixels and context as parameters. On failure, the bitmap will be set to empty and return false.
If specified, the releaseProc will always be called, even on failure. It is also possible for success but the releaseProc is immediately called (e.g. valid Info but NULL pixels).
|
inline |
Call installPixels with no ReleaseProc specified.
This means that the caller must ensure that the specified pixels are valid for the lifetime of the created bitmap (and its pixelRef).
bool SkBitmap::installPixels | ( | const SkPixmap & | ) |
Call installPixels with no ReleaseProc specified.
This means that the caller must ensure that the specified pixels and colortable are valid for the lifetime of the created bitmap (and its pixelRef).
|
inline |
Return true iff the bitmap has no pixelref.
Note: this can return true even if the dimensions of the bitmap are > 0 (see empty()). Hey! Before you use this, see if you really want to know drawsNothing() instead.
bool SkBitmap::isVolatile | ( | ) | const |
Returns true if the bitmap is volatile (i.e.
should not be cached by devices.)
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.
bool SkBitmap::lockPixelsAreWritable | ( | ) | const |
Some bitmaps can return a copy of their pixels for lockPixels(), but that copy, if modified, will not be pushed back.
These bitmaps should not be used as targets for a raster device/canvas (since all pixels modifications will be lost when unlockPixels() is called.)
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 is shared with the src bitmap.
Copies the src bitmap into this bitmap.
Takes ownership of the src bitmap's pixels.
bool SkBitmap::peekPixels | ( | SkPixmap * | ) | const |
If the pixels are available from this bitmap (w/o locking) return true, and fill out the specified pixmap (if not null).
If the pixels are not available (either because there are none, or becuase accessing them would require locking or other machinary) return false and ignore the pixmap parameter.
Note: if this returns true, the results (in the pixmap) are only valid until the bitmap is changed in anyway, in which case the results are invalid.
|
inline |
Return the current pixelref object or NULL if there is none.
This does not affect the refcount of the pixelref.
|
inline |
A bitmap can reference a subset of a pixelref's pixels.
That means the bitmap's width/height can be <= the dimensions of the pixelref. The pixelref origin is the x,y location within the pixelref's pixels for the bitmap's top/left corner. To be valid the following must be true:
origin_x + bitmap_width <= pixelref_width origin_y + bitmap_height <= pixelref_height
pixelRefOrigin() returns this origin, or (0,0) if there is no pixelRef.
bool SkBitmap::readPixels | ( | const SkImageInfo & | dstInfo, |
void * | dstPixels, | ||
size_t | dstRowBytes, | ||
int | srcX, | ||
int | srcY | ||
) | const |
Copy the bitmap's pixels into the specified buffer (pixels + rowBytes), converting them into the requested format (SkImageInfo).
The src pixels are read starting at the specified (srcX,srcY) offset, relative to the top-left corner.
The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle
srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
srcR is intersected with the bounds of the bitmap. If this intersection is not empty, then we have two sets of pixels (of equal size). Replace the dst pixels with the corresponding src pixels, performing any colortype/alphatype transformations needed (in the case where the src and dst have different colortypes or alphatypes).
This call can fail, returning false, for several reasons:
|
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 colortype, it has a non-null colortable. Returns true if all of the above are met.
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.
|
inline |
Return the number of bytes between subsequent rows of the bitmap.
|
inline |
Return the rowbytes expressed as a number of pixels (like width and height).
If the colortype is kUnknown_SkColorType, then 0 is returned.
bool SkBitmap::setAlphaType | ( | SkAlphaType | ) |
Set the bitmap's alphaType, returning true on success.
If false is returned, then the specified new alphaType is incompatible with the 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 be affected.
void SkBitmap::setImmutable | ( | ) |
Marks this bitmap as immutable, meaning that the contents of its pixels will not change for the lifetime of the bitmap and of the underlying pixelref.
This state can be set, but it cannot be cleared once it is set. This state propagates to all other bitmaps that share the same pixelref.
void SkBitmap::setIsVolatile | ( | bool | ) |
Specify whether this bitmap is volatile.
Bitmaps are not volatile by default. Temporary bitmaps that are discarded after use should be marked as volatile. This provides a hint to the device that the bitmap should not be cached. Providing this hint when appropriate can improve performance by avoiding unnecessary overhead and resource consumption on the device.
SkPixelRef* SkBitmap::setPixelRef | ( | SkPixelRef * | pr, |
int | dx, | ||
int | dy | ||
) |
Assign a pixelref and origin to the bitmap.
Pixelrefs are reference, so the existing one (if any) will be unref'd and the new one will be ref'd. (x,y) specify the offset within the pixelref's pixels for the top/left corner of the bitmap. For a bitmap that encompases the entire pixels of the pixelref, these will be (0,0).
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 |
|
inline |
Return the shift amount per pixel (i.e.
0 for 1-byte per pixel, 1 for 2-bytes per pixel colortypes, 2 for 4-bytes per pixel colortypes). Return 0 for kUnknown_SkColorType.
void SkBitmap::swap | ( | SkBitmap & | other | ) |
Swap the fields of the two bitmaps.
This routine is guaranteed to never fail or throw.
bool SK_WARN_UNUSED_RESULT SkBitmap::tryAllocPixels | ( | const SkImageInfo & | , |
SkPixelRefFactory * | , | ||
SkColorTable * | |||
) |
Allocate the bitmap's pixels to match the requested image info.
If the Factory is non-null, call it to allcoate the pixelref. If the ImageInfo requires a colortable, then ColorTable must be non-null, and will be ref'd. On failure, the bitmap will be set to empty and return false.
bool SK_WARN_UNUSED_RESULT SkBitmap::tryAllocPixels | ( | const SkImageInfo & | info, |
size_t | rowBytes | ||
) |
Allocate the bitmap's pixels to match the requested image info and rowBytes.
If the request cannot be met (e.g. the info is invalid or the requested rowBytes are not compatible with the info (e.g. rowBytes < info.minRowBytes() or rowBytes is not aligned with the pixel size specified by info.colorType()) then false is returned and the bitmap is set to empty.
|
inline |
Use the standard HeapAllocator to create the pixelref that manages the 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.
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 colortype == kIndex_8_SkColorType |
bool SK_WARN_UNUSED_RESULT SkBitmap::tryAllocPixels | ( | 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 ImageInfo. 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 ImageInfo. 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 colortype == kIndex_8_SkColorType. If it is non-null and the colortype is not indexed, it will be ignored. |
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.