SkPixmap Reference
===
# Pixmap
# Class SkPixmap
Pixmap provides a utility to pair SkImageInfo with pixels and row bytes.
Pixmap is a low level class which provides convenience functions to access
raster destinations. Canvas can not draw Pixmap, nor does Pixmap provide
a direct drawing destination.
Use Bitmap to draw pixels referenced by Pixmap; use Surface to draw into
pixels referenced by Pixmap.
Pixmap does not try to manage the lifetime of the pixel memory. Use Pixel Ref
to manage pixel memory; Pixel Ref is safe across threads.
# Overview
## Subtopics
| topics | description |
| --- | --- |
| Image Info Access | Returns all or part of Image Info. |
| Initialization | Sets fields for use. |
| Reader | Examine pixel value. |
| Writer | Copy to pixel values. |
| Readable Address | Returns read only pixels. |
| Writable Address | Returns writable pixels. |
## Constructors
| | description |
| --- | --- |
| SkPixmap() | Constructs with default values. |
| SkPixmap(const SkImageInfo& info, const void* addr, size t rowBytes) | Constructs from Image Info, pixels. |
## Member Functions
| function | description |
| --- | --- |
| addr | Returns readable pixel address as void pointer. |
| addr16 | Returns readable pixel address as 16-bit pointer. |
| addr32 | Returns readable pixel address as 32-bit pointer. |
| addr64 | Returns readable pixel address as 64-bit pointer. |
| addr8 | Returns readable pixel address as 8-bit pointer. |
| addrF16 | Returns readable pixel component address as 16-bit pointer. |
| alphaType | Returns Image Info Alpha Type. |
| bounds | Returns width and height as Rectangle. |
| colorSpace | Returns Image Info Color Space. |
| colorType | Returns Image Info Color Type. |
| computeByteSize | Returns size required for pixels. |
| computeIsOpaque | Returns true if all pixels are opaque. |
| erase | Writes Color to pixels. |
| extractSubset | Sets pointer to portion of original. |
| getColor | Returns one pixel as Unpremultiplied Color. |
| height | Returns pixel row count. |
| info | Returns Image Info. |
| isOpaque | Returns true if Image Info describes opaque pixels. |
| readPixels | Copies and converts pixels. |
| reset | Reuses existing Pixmap with replacement values. |
| rowBytes | Returns interval between rows in bytes. |
| rowBytesAsPixels | Returns interval between rows in pixels. |
| scalePixels | Scales and converts pixels. |
| setColorSpace | Sets Image Info Color Space. |
| shiftPerPixel | Returns bit shift from pixels to bytes. |
| width | Returns pixel column count. |
| writable addr | Returns writable pixel address as void pointer. |
| writable addr16 | Returns writable pixel address as 16-bit pointer. |
| writable addr32 | Returns writable pixel address as 32-bit pointer. |
| writable addr64 | Returns writable pixel address as 64-bit pointer. |
| writable addr8 | Returns writable pixel address as 8-bit pointer. |
| writable addrF16 | Returns writable pixel component address as 16-bit pointer. |
## Initialization
## SkPixmap
SkPixmap()
Creates an empty Pixmap without pixels, with kUnknown SkColorType, with
kUnknown SkAlphaType, and with a width and height of zero. Use
reset to associate pixels, SkColorType, SkAlphaType, width, and height
after Pixmap has been created.
### Return Value
empty Pixmap
### Example
#### Example Output
~~~~
width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
~~~~
### See Also
SkPixmap(const SkImageInfo& info, const void* addr, size t rowBytes) reset SkAlphaType SkColorType
---
## SkPixmap
SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes)
Creates Pixmap from info width, height, SkAlphaType, and SkColorType.
addr points to pixels, or nullptr. rowBytes should be info.width times
info.bytesPerPixel(), or larger.
No parameter checking is performed; it is up to the caller to ensure that
addr and rowBytes agree with info.
The memory lifetime of pixels is managed by the caller. When Pixmap goes
out of scope, addr is unaffected.
Pixmap may be later modified by reset to change its size, pixel type, or
storage.
### Parameters
### Return Value
initialized Pixmap
### Example
#### Example Output
~~~~
image alpha only = false
copy alpha only = true
~~~~
### See Also
SkPixmap() reset SkAlphaType SkColorType
---
## reset
void reset()
Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to
kUnknown SkColorType; and SkAlphaType to kUnknown SkAlphaType.
The prior pixels are unaffected; it is up to the caller to release pixels
memory if desired.
### Example
#### Example Output
~~~~
width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
~~~~
### See Also
SkPixmap() SkAlphaType SkColorType
---
void reset(const SkImageInfo& info, const void* addr, size_t rowBytes)
Sets width, height, SkAlphaType, and SkColorType from info.
Sets pixel address from addr, which may be nullptr.
Sets row bytes from rowBytes, which should be info.width times
info.bytesPerPixel(), or larger.
Does not check addr. Asserts if built with SK DEBUG defined and if rowBytes is
too small to hold one row of pixels.
The memory lifetime pixels are managed by the caller. When Pixmap goes
out of scope, addr is unaffected.
### Parameters
### Example
### See Also
SkPixmap(const SkImageInfo& info, const void* addr, size t rowBytes) reset SkAlphaType SkColorType
---
## setColorSpace
void setColorSpace(sk_sp<SkColorSpace> colorSpace)
Changes Color Space in Image Info; preserves width, height, SkAlphaType, and
SkColorType in Image, and leaves pixel address and row bytes unchanged.
Color Space reference count is incremented.
### Parameters
### Example
#### Example Output
~~~~
is unique
is not unique
~~~~
### See Also
Color Space SkImageInfo::makeColorSpace
---
bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask)
Sets width, height, pixel address, and row bytes to Mask properties, if Mask
format is SkMask::kA8 Format; and returns true. Otherwise sets width, height,
row bytes to zero; pixel address to nullptr; SkColorType to kUnknown SkColorType;
and SkAlphaType to kUnknown SkAlphaType; and returns false.
Failing to read the return value generates a compile time warning.
### Parameters
mask |
Mask containing pixels and dimensions |
### Return Value
true if set to Mask properties
### Example
#### Example Output
~~~~
success: true width: 2 height: 2
success: false width: 0 height: 0
~~~~
### See Also
Mask reset
---
## extractSubset
bool SK_WARN_UNUSED_RESULT extractSubset(SkPixmap* subset, const SkIRect& area) const
Sets subset width, height, pixel address to intersection of Pixmap with area,
if intersection is not empty; and return true. Otherwise, leave subset unchanged
and return false.
Failing to read the return value generates a compile time warning.
### Parameters
### Return Value
true if intersection of Pixmap and area is not empty
### Example
### See Also
reset SkIRect::intersect
---
## Image Info Access
## info
const SkImageInfo& info() const
Returns width, height, Alpha Type, Color Type, and Color Space.
### Return Value
reference to ImageInfo
### Example
#### Example Output
~~~~
width: 384 height: 384 color: BGRA_8888 alpha: Opaque
~~~~
### See Also
Image Info
---
## rowBytes
size_t rowBytes() const
Returns row bytes, the interval from one pixel row to the next. Row bytes
is at least as large as:
width * info.bytesPerPixel().
Returns zero if colorType is kUnknown SkColorType.
It is up to the Bitmap creator to ensure that row bytes is a useful value.
### Return Value
byte length of pixel row
### Example
#### Example Output
~~~~
rowBytes: 2 minRowBytes: 4
rowBytes: 8 minRowBytes: 4
~~~~
### See Also
addr info SkImageInfo::minRowBytes
---
## addr
const void* addr() const
Returns pixel address, the base address corresponding to the pixel origin.
It is up to the Pixmap creator to ensure that pixel address is a useful value.
### Return Value
pixel address
### Example
#### Example Output
~~~~
#Volatile
pixels address: 0x7f2a440bb010
inset address: 0x7f2a440fb210
~~~~
### See Also
addr(int x, int y) addr8 addr16 addr32 addr64 info rowBytes
---
## width
int width() const
Returns pixel count in each pixel row. Should be equal or less than:
rowBytes / info.bytesPerPixel().
### Return Value
pixel width in Image Info
### Example
#### Example Output
~~~~
pixmap width: 16 info width: 16
~~~~
### See Also
height SkImageInfo::width()
---
## height
int height() const
Returns pixel row count.
### Return Value
pixel height in Image Info
### Example
#### Example Output
~~~~
pixmap height: 32 info height: 32
~~~~
### See Also
width ImageInfo::height()
---
## colorType
SkColorType colorType() const
Returns Color Type, one of: kUnknown SkColorType, kAlpha 8 SkColorType,
kRGB 565 SkColorType, kARGB 4444 SkColorType, kRGBA 8888 SkColorType,
kBGRA 8888 SkColorType, kGray 8 SkColorType, kRGBA F16 SkColorType.
### Return Value
Color Type in Image Info
### Example
#### Example Output
~~~~
color type: kAlpha_SkColorType
~~~~
### See Also
alphaType SkImageInfo::colorType
---
## alphaType
SkAlphaType alphaType() const
Returns Alpha Type, one of: kUnknown SkAlphaType, kOpaque SkAlphaType,
kPremul SkAlphaType, kUnpremul SkAlphaType.
### Return Value
Alpha Type in Image Info
### Example
#### Example Output
~~~~
alpha type: kPremul_SkAlphaType
~~~~
### See Also
colorType SkImageInfo::alphaType
---
## colorSpace
SkColorSpace* colorSpace() const
Returns Color Space associated with Image Info. The
reference count of Color Space is unchanged. The returned Color Space is
immutable.
### Return Value
Color Space, the range of colors, in Image Info
### Example
#### Example Output
~~~~
gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
~~~~
### See Also
Color Space SkImageInfo::colorSpace
---
## isOpaque
bool isOpaque() const
Returns true if Alpha Type is kOpaque SkAlphaType.
Does not check if Color Type allows Alpha, or if any pixel value has
transparency.
### Return Value
true if Image Info has opaque Alpha Type
### Example
isOpaque ignores whether all pixels are opaque or not.
#### Example Output
~~~~
isOpaque: false
isOpaque: false
isOpaque: true
isOpaque: true
~~~~
### See Also
computeIsOpaque SkImageInfo::isOpaque
---
## bounds
SkIRect bounds() const
Returns IRect { 0, 0, width, height }.
### Return Value
integral rectangle from origin to width and height
### Example
#### Example Output
~~~~
width: 0 height: 0 empty: true
width: 0 height: 2 empty: true
width: 2 height: 0 empty: true
width: 2 height: 2 empty: false
~~~~
### See Also
height width IRect
---
## rowBytesAsPixels
int rowBytesAsPixels() const
Returns number of pixels that fit on row. Should be greater than or equal to
width.
### Return Value
maximum pixels per row
### Example
#### Example Output
~~~~
rowBytes: 4 rowBytesAsPixels: 1
rowBytes: 5 rowBytesAsPixels: 1
rowBytes: 6 rowBytesAsPixels: 1
rowBytes: 7 rowBytesAsPixels: 1
rowBytes: 8 rowBytesAsPixels: 2
~~~~
### See Also
rowBytes shiftPerPixel width SkImageInfo::bytesPerPixel
---
## shiftPerPixel
int shiftPerPixel() const
Returns bit shift converting row bytes to row pixels.
Returns zero for kUnknown SkColorType.
### Return Value
one of: 0, 1, 2, 3; left shift to convert pixels to bytes
### Example
#### Example Output
~~~~
color: kUnknown_SkColorType bytesPerPixel: 0 shiftPerPixel: 0
color: kAlpha_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
color: kRGB_565_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
color: kARGB_4444_SkColorType bytesPerPixel: 2 shiftPerPixel: 1
color: kRGBA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
color: kBGRA_8888_SkColorType bytesPerPixel: 4 shiftPerPixel: 2
color: kGray_8_SkColorType bytesPerPixel: 1 shiftPerPixel: 0
color: kRGBA_F16_SkColorType bytesPerPixel: 8 shiftPerPixel: 3
~~~~
### See Also
rowBytes rowBytesAsPixels width SkImageInfo::bytesPerPixel
---
## computeByteSize
size_t computeByteSize() const
Returns minimum memory required for pixel storage.
Does not include unused memory on last row when rowBytesAsPixels exceeds width.
Returns zero if result does not fit in size_t.
Returns zero if height or width is 0.
Returns height times rowBytes if colorType is kUnknown SkColorType.
### Return Value
size in bytes of image buffer
### Example
#### Example Output
~~~~
width: 1 height: 1 computeByteSize: 4
width: 1 height: 1000 computeByteSize: 4999
width: 1 height: 1000000 computeByteSize: 4999999
width: 1000 height: 1 computeByteSize: 4000
width: 1000 height: 1000 computeByteSize: 4999000
width: 1000 height: 1000000 computeByteSize: 4999999000
width: 1000000 height: 1 computeByteSize: 4000000
width: 1000000 height: 1000 computeByteSize: 4999000000
width: 1000000 height: 1000000 computeByteSize: 4999999000000
~~~~
### See Also
SkImageInfo::computeByteSize
---
## Reader
## computeIsOpaque
bool computeIsOpaque() const
Returns true if all pixels are opaque. Color Type determines how pixels
are encoded, and whether pixel describes Alpha. Returns true for Color Types
without alpha in each pixel; for other Color Types, returns true if all
pixels have alpha values equivalent to 1.0 or greater.
For Color Types kRGB 565 SkColorType or kGray 8 SkColorType: always
returns true. For Color Types kAlpha 8 SkColorType, kBGRA 8888 SkColorType,
kRGBA 8888 SkColorType: returns true if all pixel Alpha values are 255.
For Color Type kARGB 4444 SkColorType: returns true if all pixel Alpha values are 15.
For kRGBA F16 SkColorType: returns true if all pixel Alpha values are 1.0 or
greater.
Returns false for kUnknown SkColorType.
### Return Value
true if all pixels have opaque values or Color Type is opaque
### Example
#### Example Output
~~~~
computeIsOpaque: false
computeIsOpaque: true
computeIsOpaque: false
computeIsOpaque: true
~~~~
### See Also
isOpaque Color Type Alpha
---
## getColor
SkColor getColor(int x, int y) const
Returns pixel at (x, y) as Unpremultiplied Color.
Returns black with Alpha if Color Type is kAlpha 8 SkColorType.
Input is not validated: out of bounds values of x or y trigger an assert() if
built with SK DEBUG defined; and returns undefined values or may crash if
SK RELEASE is defined. Fails if Color Type is kUnknown SkColorType or
pixel address is nullptr.
Color Space in Image Info is ignored. Some Color precision may be lost in the
conversion to Unpremultiplied Color; original pixel data may have additional
precision.
### Parameters
x |
column index, zero or greater, and less than width |
y |
row index, zero or greater, and less than height |
### Return Value
pixel converted to Unpremultiplied Color
### Example
#### Example Output
~~~~
Premultiplied:
(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
Unpremultiplied:
(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
~~~~
### See Also
addr readPixels
---
## Readable Address
const void* addr(int x, int y) const
Returns readable pixel address at (x, y). Returns nullptr if Pixel Ref is nullptr.
Input is not validated: out of bounds values of x or y trigger an assert() if
built with SK DEBUG defined. Returns nullptr if Color Type is kUnknown SkColorType.
Performs a lookup of pixel size; for better performance, call
one of: addr8, addr16, addr32, addr64, or addrF16.
### Parameters
x |
column index, zero or greater, and less than width |
y |
row index, zero or greater, and less than height |
### Return Value
readable generic pointer to pixel
### Example
#### Example Output
~~~~
pixmap.addr(1, 2) == &storage[1 + 2 * w]
~~~~
### See Also
addr8 addr16 addr32 addr64 addrF16 getColor writable addr SkBitmap::getAddr
---
## addr8
const uint8_t* addr8() const
Returns readable base pixel address. Result is addressable as unsigned 8-bit bytes.
Will trigger an assert() if Color Type is not kAlpha 8 SkColorType or
kGray 8 SkColorType, and is built with SK DEBUG defined.
One byte corresponds to one pixel.
### Return Value
readable unsigned 8-bit pointer to pixels
### Example
#### Example Output
~~~~
pixmap.addr8() == storage
~~~~
### See Also
addr addr16 addr32 addr64 addrF16 getColor writable addr writable addr8
---
## addr16
const uint16_t* addr16() const
Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
Will trigger an assert() if Color Type is not kRGB 565 SkColorType or
kARGB 4444 SkColorType, and is built with SK DEBUG defined.
One word corresponds to one pixel.
### Return Value
readable unsigned 16-bit pointer to pixels
### Example
#### Example Output
~~~~
pixmap.addr16() == storage
~~~~
### See Also
addr addr8 addr32 addr64 addrF16 getColor writable addr writable addr16
---
## addr32
const uint32_t* addr32() const
Returns readable base pixel address. Result is addressable as unsigned 32-bit words.
Will trigger an assert() if Color Type is not kRGBA 8888 SkColorType or
kBGRA 8888 SkColorType, and is built with SK DEBUG defined.
One word corresponds to one pixel.
### Return Value
readable unsigned 32-bit pointer to pixels
### Example
#### Example Output
~~~~
pixmap.addr32() == storage
~~~~
### See Also
addr addr8 addr16 addr64 addrF16 getColor writable addr writable addr32
---
## addr64
const uint64_t* addr64() const
Returns readable base pixel address. Result is addressable as unsigned 64-bit words.
Will trigger an assert() if Color Type is not kRGBA F16 SkColorType and is built
with SK DEBUG defined.
One word corresponds to one pixel.
### Return Value
readable unsigned 64-bit pointer to pixels
### Example
#### Example Output
~~~~
pixmap.addr64() == storage
~~~~
### See Also
addr addr8 addr16 addr32 addrF16 getColor writable addr writable addr64
---
## addrF16
const uint16_t* addrF16() const
Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
Will trigger an assert() if Color Type is not kRGBA F16 SkColorType and is built
with SK DEBUG defined.
Each word represents one color component encoded as a half float.
Four words correspond to one pixel.
### Return Value
readable unsigned 16-bit pointer to first component of pixels
### Example
#### Example Output
~~~~
pixmap.addrF16() == storage
~~~~
### See Also
addr addr8 addr16 addr32 addr64 getColor writable addr writable addrF16
---
const uint8_t* addr8(int x, int y) const
Returns readable pixel address at (x, y).
Input is not validated: out of bounds values of x or y trigger an assert() if
built with SK DEBUG defined.
Will trigger an assert() if Color Type is not kAlpha 8 SkColorType or
kGray 8 SkColorType, and is built with SK DEBUG defined.
### Parameters
x |
column index, zero or greater, and less than width |
y |
row index, zero or greater, and less than height |
### Return Value
readable unsigned 8-bit pointer to pixel at (x, y)
### Example
#### Example Output
~~~~
pixmap.addr8(1, 2) == &storage[1 + 2 * w]
~~~~
### See Also
addr addr16 addr32 addr64 addrF16 getColor writable addr writable addr8
---
const uint16_t* addr16(int x, int y) const
Returns readable pixel address at (x, y).
Input is not validated: out of bounds values of x or y trigger an assert() if
built with SK DEBUG defined.
Will trigger an assert() if Color Type is not kRGB 565 SkColorType or
kARGB 4444 SkColorType, and is built with SK DEBUG defined.
### Parameters
x |
column index, zero or greater, and less than width |
y |
row index, zero or greater, and less than height |
### Return Value
readable unsigned 16-bit pointer to pixel at (x, y)
### Example
#### Example Output
~~~~
pixmap.addr16(1, 2) == &storage[1 + 2 * w]
~~~~
### See Also
addr addr8 addr32 addr64 addrF16 getColor writable addr writable addr16
---
const uint32_t* addr32(int x, int y) const
Returns readable pixel address at (x, y).
Input is not validated: out of bounds values of x or y trigger an assert() if
built with SK DEBUG defined.
Will trigger an assert() if Color Type is not kRGBA 8888 SkColorType or
kBGRA 8888 SkColorType, and is built with SK DEBUG defined.
### Parameters
x |
column index, zero or greater, and less than width |
y |
row index, zero or greater, and less than height |
### Return Value
readable unsigned 32-bit pointer to pixel at (x, y)
### Example
#### Example Output
~~~~
pixmap.addr32(1, 2) == &storage[1 + 2 * w]
~~~~
### See Also
addr addr8 addr16 addr64 addrF16 getColor writable addr writable addr64
---
const uint64_t* addr64(int x, int y) const
Returns readable pixel address at (x, y).
Input is not validated: out of bounds values of x or y trigger an assert() if
built with SK DEBUG defined.
Will trigger an assert() if Color Type is not kRGBA F16 SkColorType and is built
with SK DEBUG defined.
### Parameters
x |
column index, zero or greater, and less than width |
y |
row index, zero or greater, and less than height |
### Return Value
readable unsigned 64-bit pointer to pixel at (x, y)
### Example
#### Example Output
~~~~
pixmap.addr64(1, 2) == &storage[1 + 2 * w]
~~~~
### See Also
addr addr8 addr16 addr32 addrF16 getColor writable addr writable addr64
---
const uint16_t* addrF16(int x, int y) const
Returns readable pixel address at (x, y).
Input is not validated: out of bounds values of x or y trigger an assert() if
built with SK DEBUG defined.
Will trigger an assert() if Color Type is not kRGBA F16 SkColorType and is built
with SK DEBUG defined.
Each unsigned 16-bit word represents one color component encoded as a half float.
Four words correspond to one pixel.
### Parameters
x |
column index, zero or greater, and less than width |
y |
row index, zero or greater, and less than height |
### Return Value
readable unsigned 16-bit pointer to pixel component at (x, y)
### Example
#### Example Output
~~~~
pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords]
~~~~
### See Also
addr addr8 addr16 addr32 addr64 getColor writable addr writable addrF16
---
## Writable Address
## writable_addr
void* writable_addr() const
Returns writable base pixel address.
### Return Value
writable generic base pointer to pixels
### Example
#### Example Output
~~~~
pixmap.writable_addr() == (void *)storage
pixmap.getColor(0, 1) == 0x00000000
pixmap.getColor(0, 0) == 0xFFFFFFFF
~~~~
### See Also
writable addr8 writable addr16 writable addr32 writable addr64 writable addrF16 addr
---
void* writable_addr(int x, int y) const
Returns writable pixel address at (x, y).
Input is not validated: out of bounds values of x or y trigger an assert() if
built with SK DEBUG defined. Returns zero if Color Type is kUnknown SkColorType.
### Parameters
x |
column index, zero or greater, and less than width |
y |
row index, zero or greater, and less than height |
### Return Value
writable generic pointer to pixel
### Example
#### Example Output
~~~~
pixmap.writable_addr() == (void *)storage
pixmap.getColor(0, 0) == 0x00000000
pixmap.getColor(1, 2) == 0xFFFFFFFF
~~~~
### See Also
writable addr8 writable addr16 writable addr32 writable addr64 writable addrF16 addr
---
## writable_addr8
uint8_t* writable_addr8(int x, int y) const
Returns writable pixel address at (x, y). Result is addressable as unsigned
8-bit bytes. Will trigger an assert() if Color Type is not kAlpha 8 SkColorType
or kGray 8 SkColorType, and is built with SK DEBUG defined.
One byte corresponds to one pixel.
### Parameters
x |
column index, zero or greater, and less than width |
y |
row index, zero or greater, and less than height |
### Return Value
writable unsigned 8-bit pointer to pixels
### Example
Altering pixels after drawing
Bitmap is not guaranteed to affect subsequent
drawing on all platforms. Adding a second
SkBitmap::installPixels after editing
pixel memory is safer.
### See Also
writable addr writable addr16 writable addr32 writable addr64 writable addrF16 addr addr8
---
## writable_addr16
uint16_t* writable_addr16(int x, int y) const
Returns writable addr pixel address at (x, y). Result is addressable as unsigned
16-bit words. Will trigger an assert() if Color Type is not kRGB 565 SkColorType
or kARGB 4444 SkColorType, and is built with SK DEBUG defined.
One word corresponds to one pixel.
### Parameters
x |
column index, zero or greater, and less than width |
y |
row index, zero or greater, and less than height |
### Return Value
writable unsigned 16-bit pointer to pixel
### Example
Draw a five by five bitmap, and draw it again with a center black pixel.
The low nibble of the 16-bit word is
Alpha.
### See Also
writable addr writable addr8 writable addr32 writable addr64 writable addrF16 addr addr16
---
## writable_addr32
uint32_t* writable_addr32(int x, int y) const
Returns writable pixel address at (x, y). Result is addressable as unsigned
32-bit words. Will trigger an assert() if Color Type is not
kRGBA 8888 SkColorType or kBGRA 8888 SkColorType, and is built with SK DEBUG
defined.
One word corresponds to one pixel.
### Parameters
x |
column index, zero or greater, and less than width |
y |
row index, zero or greater, and less than height |
### Return Value
writable unsigned 32-bit pointer to pixel
### Example
### See Also
writable addr writable addr8 writable addr16 writable addr64 writable addrF16 addr addr32
---
## writable_addr64
uint64_t* writable_addr64(int x, int y) const
Returns writable pixel address at (x, y). Result is addressable as unsigned
64-bit words. Will trigger an assert() if Color Type is not
kRGBA F16 SkColorType and is built with SK DEBUG defined.
One word corresponds to one pixel.
### Parameters
x |
column index, zero or greater, and less than width |
y |
row index, zero or greater, and less than height |
### Return Value
writable unsigned 64-bit pointer to pixel
### Example
### See Also
writable addr writable addr8 writable addr16 writable addr32 writable addrF16 addr addr64
---
## writable_addrF16
uint16_t* writable_addrF16(int x, int y) const
Returns writable pixel address at (x, y). Result is addressable as unsigned
16-bit words. Will trigger an assert() if Color Type is not
kRGBA F16 SkColorType and is built with SK DEBUG defined.
Each word represents one color component encoded as a half float.
Four words correspond to one pixel.
### Parameters
x |
column index, zero or greater, and less than width |
y |
row index, zero or greater, and less than height |
### Return Value
writable unsigned 16-bit pointer to first component of pixel
### Example
Left bitmap is drawn with two pixels defined in half float format. Right bitmap
is drawn after overwriting bottom half float color with top half float color.
### See Also
writable addr writable addr8 writable addr16 writable addr32 writable addr64 addr addrF16
---
## Writer
## readPixels
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
int srcX, int srcY, SkTransferFunctionBehavior behavior) const
Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
exceed (this->width, this->height).
dstInfo specifies width, height, Color Type, Alpha Type, and
Color Space of destination. dstRowBytes specifics the gap from one destination
row to the next. Returns true if pixels are copied. Returns false if
dstInfo.addr equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
Pixels are copied only if pixel conversion is possible. If this->colorType is
kGray 8 SkColorType, or kAlpha 8 SkColorType; dstInfo.colorType must match.
If this->colorType is kGray 8 SkColorType, dstInfo.colorSpace must match.
If this->alphaType is kOpaque SkAlphaType, dstInfo.alphaType must
match. If this->colorSpace is nullptr, dstInfo.colorSpace must match. Returns
false if pixel conversion is not possible.
srcX and srcY may be negative to copy only top or left of source. Returns
false if width or height is zero or negative. Returns false if:
abs(srcX) >= this->width,
or ifabs(srcY) >= this->height.
If behavior is SkTransferFunctionBehavior::kRespect: converts source
pixels to a linear space before converting to dstInfo.
If behavior is SkTransferFunctionBehavior::kIgnore: source
pixels are treated as if they are linear, regardless of how they are encoded.
### Parameters
### Return Value
true if pixels are copied to dstPixels
### Example
### See Also
erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
---
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const
Copies a Rect of pixels to dstPixels. Copy starts at (0, 0), and does not
exceed (this->width, this->height).
dstInfo specifies width, height, Color Type, Alpha Type, and
Color Space of destination. dstRowBytes specifics the gap from one destination
row to the next. Returns true if pixels are copied. Returns false if
dstInfo.addr equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
Pixels are copied only if pixel conversion is possible. If this->colorType is
kGray 8 SkColorType, or kAlpha 8 SkColorType; dstInfo.colorType must match.
If this->colorType is kGray 8 SkColorType, dstInfo.colorSpace must match.
If this->alphaType is kOpaque SkAlphaType, dstInfo.alphaType must
match. If this->colorSpace is nullptr, dstInfo.colorSpace must match. Returns
false if pixel conversion is not possible.
Returns false if this->width or this->height is zero or negative.
### Parameters
### Return Value
true if pixels are copied to dstPixels
### Example
Transferring the gradient from 8 bits per component to 4 bits per component
creates visible banding.
### See Also
erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
---
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
int srcX, int srcY) const
Copies a Rect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
exceed (this->width, this->height).
dstInfo specifies width, height, Color Type, Alpha Type, and
Color Space of destination. dstRowBytes specifics the gap from one destination
row to the next. Returns true if pixels are copied. Returns false if
dstInfo.addr equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes.
Pixels are copied only if pixel conversion is possible. If this->colorType is
kGray 8 SkColorType, or kAlpha 8 SkColorType; dstInfo.colorType must match.
If this->colorType is kGray 8 SkColorType, dstInfo.colorSpace must match.
If this->alphaType is kOpaque SkAlphaType, dstInfo.alphaType must
match. If this->colorSpace is nullptr, dstInfo.colorSpace must match. Returns
false if pixel conversion is not possible.
srcX and srcY may be negative to copy only top or left of source. Returns
false if this->width or this->height is zero or negative. Returns false if:
abs(srcX) >= this->width,
or ifabs(srcY) >= this->height.
### Parameters
### Return Value
true if pixels are copied to dstPixels
### Example
### See Also
erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
---
bool readPixels(const SkPixmap& dst, int srcX, int srcY) const
Copies a Rect of pixels to dst. Copy starts at (srcX, srcY), and does not
exceed (this->width, this->height). dst specifies width, height, Color Type,
Alpha Type, and Color Space of destination. Returns true if pixels are copied.
Returns false if dst.addr equals nullptr, or dst.rowBytes is less than
dst SkImageInfo::minRowBytes.
Pixels are copied only if pixel conversion is possible. If this->colorType is
kGray 8 SkColorType, or kAlpha 8 SkColorType; dst.info.colorType must match.
If this->colorType is kGray 8 SkColorType, dst.info.colorSpace must match.
If this->alphaType is kOpaque SkAlphaType, dst.info.alphaType must
match. If this->colorSpace is nullptr, dst.info.colorSpace must match. Returns
false if pixel conversion is not possible.
srcX and srcY may be negative to copy only top or left of source. Returns
false this->width or this->height is zero or negative. Returns false if:
abs(srcX) >= this->width,
or ifabs(srcY) >= this->height.
### Parameters
### Return Value
true if pixels are copied to dst
### Example
### See Also
erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
---
bool readPixels(const SkPixmap& dst) const
Copies pixels inside bounds to dst. dst specifies width, height, Color Type,
Alpha Type, and Color Space of destination. Returns true if pixels are copied.
Returns false if dst.addr equals nullptr, or dst.rowBytes is less than
dst SkImageInfo::minRowBytes.
Pixels are copied only if pixel conversion is possible. If this->colorType is
kGray 8 SkColorType, or kAlpha 8 SkColorType; dst Color Type must match.
If this->colorType is kGray 8 SkColorType, dst Color Space must match.
If this->alphaType is kOpaque SkAlphaType, dst Alpha Type must
match. If this->colorSpace is nullptr, dst Color Space must match. Returns
false if pixel conversion is not possible.
Returns false if this->width or this->height is zero or negative.
### Parameters
### Return Value
true if pixels are copied to dst
### Example
### See Also
erase SkBitmap::readPixels SkCanvas::drawBitmap SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
---
## scalePixels
bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const
Copies this to dst, scaling pixels to fit dst.width and dst.height, and
converting pixels to match dst.colorType and dst.alphaType. Returns true if
pixels are copied. Returns false if dst.addr is nullptr, or dst.rowBytes is
less than dst SkImageInfo::minRowBytes.
Pixels are copied only if pixel conversion is possible. If this->colorType is
kGray 8 SkColorType, or kAlpha 8 SkColorType; dst Color Type must match.
If this->colorType is kGray 8 SkColorType, dst Color Space must match.
If this->alphaType is kOpaque SkAlphaType, dst Alpha Type must
match. If this->colorSpace is nullptr, dst Color Space must match. Returns
false if pixel conversion is not possible.
Returns false if this->width or this->height is zero or negative.
Scales the image, with filterQuality, to match dst.width and dst.height.
filterQuality kNone SkFilterQuality is fastest, typically implemented with
Filter Quality Nearest Neighbor. kLow SkFilterQuality is typically implemented with
Filter Quality Bilerp. kMedium SkFilterQuality is typically implemented with
Filter Quality Bilerp, and Filter Quality MipMap when size is reduced.
kHigh SkFilterQuality is slowest, typically implemented with Filter Quality BiCubic.
### Parameters
### Return Value
true if pixels are copied to dst
### Example
### See Also
SkCanvas::drawBitmap SkImage::scalePixels
---
## erase
bool erase(SkColor color, const SkIRect& subset) const
Writes color to pixels bounded by subset; returns true on success.
Returns false if colorType is kUnknown SkColorType, or if subset does
not intersect bounds.
### Parameters
### Return Value
true if pixels are changed
### Example
### See Also
SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
---
bool erase(SkColor color) const
Writes color to pixels inside bounds; returns true on success.
Returns false if colorType is kUnknown SkColorType, or if bounds
is empty.
### Parameters
### Return Value
true if pixels are changed
### Example
### See Also
SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
---
bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const
Writes color to pixels bounded by subset; returns true on success.
if subset is nullptr, writes colors pixels inside bounds. Returns false if
colorType is kUnknown SkColorType, if subset is not nullptr and does
not intersect bounds, or if subset is nullptr and bounds is empty.
### Parameters
### Return Value
true if pixels are changed
### Example
### See Also
SkBitmap::erase SkCanvas::clear SkCanvas::drawColor
---