skia2/site/user/api/SkPixmap_Reference.md
Cary Clark 09d80c0337 docs with more pop
Replace a hunk of documentation in docs/*.bmh
with #Populate, which instructs bookmaker to
retrieve the documentation from include/core.

Check spelling for all documentation retrieved
from include/core against Skia declarations
and a list of words in spelling.txt.

TBR=caryclark@google.com
Docs-Preview: https://skia.org/?cl=163491
Bug: skia:
Change-Id: If057c3a1336e312ad59c084a3a130f0276802496
Reviewed-on: https://skia-review.googlesource.com/c/163491
Commit-Queue: Cary Clark <caryclark@skia.org>
Reviewed-by: Cary Clark <caryclark@skia.org>
Auto-Submit: Cary Clark <caryclark@skia.org>
2018-10-31 16:45:32 +00:00

100 KiB

SkPixmap Reference


class SkPixmap {
public:
    SkPixmap();
    SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes);
    void reset();
    void reset(const SkImageInfo& info, const void* addr, size_t rowBytes);
    void setColorSpace(sk_sp<SkColorSpace> colorSpace);
    bool reset(const SkMask& mask);
    bool extractSubset(SkPixmap* subset, const SkIRect& area) const;
    const SkImageInfo& info() const;
    size_t rowBytes() const;
    const void* addr() const;
    int width() const;
    int height() const;
    SkColorType colorType() const;
    SkAlphaType alphaType() const;
    SkColorSpace* colorSpace() const;
    bool isOpaque() const;
    SkIRect bounds() const;
    int rowBytesAsPixels() const;
    int shiftPerPixel() const;
    size_t computeByteSize() const;
    bool computeIsOpaque() const;
    SkColor getColor(int x, int y) const;
    float getAlphaf(int x, int y) const;
    const void* addr(int x, int y) const;
    const uint8_t* addr8() const;
    const uint16_t* addr16() const;
    const uint32_t* addr32() const;
    const uint64_t* addr64() const;
    const uint16_t* addrF16() const;
    const uint8_t* addr8(int x, int y) const;
    const uint16_t* addr16(int x, int y) const;
    const uint32_t* addr32(int x, int y) const;
    const uint64_t* addr64(int x, int y) const;
    const uint16_t* addrF16(int x, int y) const;
    void* writable_addr() const;
    void* writable_addr(int x, int y) const;
    uint8_t* writable_addr8(int x, int y) const;
    uint16_t* writable_addr16(int x, int y) const;
    uint32_t* writable_addr32(int x, int y) const;
    uint64_t* writable_addr64(int x, int y) const;
    uint16_t* writable_addrF16(int x, int y) const;
    bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const;
    bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX,
                    int srcY) const;
    bool readPixels(const SkPixmap& dst, int srcX, int srcY) const;
    bool readPixels(const SkPixmap& dst) const;
    bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const;
    bool erase(SkColor color, const SkIRect& subset) const;
    bool erase(SkColor color) const;
    bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const;
};

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.


SkPixmap()

Creates an empty SkPixmap 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 SkPixmap has been created.

Return Value

empty SkPixmap

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[2][3]() SkAlphaType SkColorType


SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes)

Creates SkPixmap 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 SkPixmap goes out of scope, addr is unaffected.

SkPixmap may be later modified by reset() to change its size, pixel type, or storage.

Parameters

info width, height, SkAlphaType, SkColorType of SkImageInfo
addr pointer to pixels allocated by caller; may be nullptr
rowBytes size of one row of addr; width times pixel size, or larger

Return Value

initialized SkPixmap

Example

SkImage::MakeRasterCopy takes const SkPixmap& as an argument. The example constructs a SkPixmap from the brace-delimited parameters.

Example Output

image alpha only = false
copy alpha only = true

See Also

SkPixmap() reset[2][3]() SkAlphaType SkColorType


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 SkPixmap goes out of scope, addr is unaffected.

Parameters

info width, height, SkAlphaType, SkColorType of SkImageInfo
addr pointer to pixels allocated by caller; may be nullptr
rowBytes size of one row of addr; width times pixel size, or larger

Example

See Also

SkPixmap(const SkImageInfo& info, const void* addr, size t rowBytes) reset[2][3]() SkAlphaType SkColorType


void setColorSpace(sk sp<SkColorSpace> colorSpace)

Changes SkColorSpace in SkImageInfo; preserves width, height, SkAlphaType, and SkColorType in SkImage, and leaves pixel address and row bytes unchanged. SkColorSpace reference count is incremented.

Parameters

colorSpace SkColorSpace moved to SkImageInfo

Example

Example Output

is unique
is not unique

See Also

Color Space SkImageInfo::makeColorSpace


bool reset(const SkMask& mask)

To be deprecated soon.


bool extractSubset(SkPixmap* subset, const SkIRect& area) const

Sets subset width, height, pixel address to intersection of SkPixmap 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

subset storage for width, height, pixel address of intersection
area bounds to intersect with SkPixmap

Return Value

true if intersection of SkPixmap and area is not empty

Example

See Also

reset[2][3]() SkIRect::intersect[2][3]


const SkImageInfo& info() const

Returns width, height, SkAlphaType, SkColorType, and SkColorSpace.

Return Value

reference to SkImageInfo

Example

Example Output

width: 384 height: 384 color: BGRA_8888 alpha: Opaque

See Also

Image Info


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[2]() info() SkImageInfo::minRowBytes


const void* addr() const

Returns pixel address, the base address corresponding to the pixel origin.

It is up to the SkPixmap 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[2] addr16[2] addr32[2] addr64[2] info() rowBytes()


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()


int height() const

Returns pixel row count.

Return Value

pixel height in SkImageInfo

Example

Example Output

pixmap height: 32  info height: 32

See Also

width() ImageInfo::height()


SkColorType colorType() const

Returns Color Type, one of: kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType.

Return Value

Color Type in Image Info

Example

Example Output

color type: kAlpha_8_SkColorType

See Also

alphaType() SkImageInfo::colorType


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


SkColorSpace* colorSpace() const

Returns SkColorSpace, the range of colors, associated with SkImageInfo. The reference count of SkColorSpace is unchanged. The returned SkColorSpace is immutable.

Return Value

SkColorSpace in SkImageInfo, or nullptr

Example

SkColorSpace::MakeSRGBLinear creates Color Space with linear gamma and an sRGB gamut. This Color Space gamma is not close to sRGB gamma.

Example Output

gammaCloseToSRGB: false  gammaIsLinear: true  isSRGB: false

See Also

Color Space SkImageInfo::colorSpace


bool isOpaque() const

Returns true if SkAlphaType is kOpaque_SkAlphaType. Does not check if SkColorType allows alpha, or if any pixel value has transparency.

Return Value

true if SkImageInfo has opaque SkAlphaType

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


SkIRect bounds() const

Returns SkIRect { 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


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


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_8_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


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


bool computeIsOpaque() const

Returns true if all pixels are opaque. SkColorType determines how pixels are encoded, and whether pixel describes alpha. Returns true for SkColorType without alpha in each pixel; for other SkColorType, returns true if all pixels have alpha values equivalent to 1.0 or greater.

For SkColorType kRGB_565_SkColorType or kGray_8_SkColorType: always returns true. For SkColorType kAlpha_8_SkColorType, kBGRA_8888_SkColorType, kRGBA_8888_SkColorType: returns true if all pixel alpha values are 255. For SkColorType 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 SkColorType is opaque

Example

Example Output

computeIsOpaque: false
computeIsOpaque: true
computeIsOpaque: false
computeIsOpaque: true

See Also

isOpaque Color Type Alpha


SkColor getColor(int x, int y) const

Returns pixel at (x, y) as unpremultiplied color. Returns black with alpha if SkColorType 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 SkColorType is kUnknown_SkColorType or pixel address is nullptr.

SkColorSpace in SkImageInfo 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

getAlphaf addr[2]() readPixels[2][3][4]


float getAlphaf(int x, int y) const

Looks up the pixel at (x,y) and return its alpha component, normalized to [0..1]. This is roughly equivalent to SkGetColorA(getColor()), but can be more efficent (and more precise if the pixels store more than 8 bits per component).

Parameters

x column index, zero or greater, and less than width()
y row index, zero or greater, and less than height()

Return Value

alpha converted to normalized float

See Also

getColor


const void* addr(int x, int y) const

Returns readable pixel address at (x, y). Returns nullptr if SkPixelRef 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 SkColorType 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[2] addr16[2] addr32[2] addr64[2] addrF16[2] getColor writable addr[2] SkBitmap::getAddr


const uint8_t* addr8() const

Returns readable base pixel address. Result is addressable as unsigned 8-bit bytes. Will trigger an assert() if SkColorType 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[2]() addr16[2] addr32[2] addr64[2] addrF16[2] getColor writable addr[2] writable addr8


const uint16_t* addr16() const

Returns readable base pixel address. Result is addressable as unsigned 16-bit words. Will trigger an assert() if SkColorType 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[2]() addr8[2] addr32[2] addr64[2] addrF16[2] getColor writable addr[2] writable addr16


const uint32_t* addr32() const

Returns readable base pixel address. Result is addressable as unsigned 32-bit words. Will trigger an assert() if SkColorType 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[2]() addr8[2] addr16[2] addr64[2] addrF16[2] getColor writable addr[2] writable addr32


const uint64_t* addr64() const

Returns readable base pixel address. Result is addressable as unsigned 64-bit words. Will trigger an assert() if SkColorType 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[2]() addr8[2] addr16[2] addr32[2] addrF16[2] getColor writable addr[2] writable addr64


const uint16_t* addrF16() const

Returns readable base pixel address. Result is addressable as unsigned 16-bit words. Will trigger an assert() if SkColorType 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[2]() addr8[2] addr16[2] addr32[2] addr64[2] getColor writable addr[2] 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 SkColorType 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[2]() addr16[2] addr32[2] addr64[2] addrF16[2] getColor writable addr[2] 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 SkColorType 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[2]() addr8[2] addr32[2] addr64[2] addrF16[2] getColor writable addr[2] 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 SkColorType 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[2]() addr8[2] addr16[2] addr64[2] addrF16[2] getColor writable addr[2] 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 SkColorType 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[2]() addr8[2] addr16[2] addr32[2] addrF16[2] getColor writable addr[2] 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 SkColorType 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[2]() addr8[2] addr16[2] addr32[2] addr64[2] getColor writable addr[2] writable addrF16


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[2]()


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 SkColorType 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[2]()


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 SkColorType 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[2] writable addr16 writable addr32 writable addr64 writable addrF16 addr[2]() addr8[2]


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 SkColorType 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[2] writable addr8 writable addr32 writable addr64 writable addrF16 addr[2]() addr16[2]


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 SkColorType 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[2] writable addr8 writable addr16 writable addr64 writable addrF16 addr[2]() addr32[2]


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 SkColorType 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[2] writable addr8 writable addr16 writable addr32 writable addrF16 addr[2]() addr64[2]


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 SkColorType 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[2] writable addr8 writable addr16 writable addr32 writable addr64 addr[2]() addrF16[2]


bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const

Copies a SkRect of pixels to dstPixels. Copy starts at (0, 0), and does not exceed SkPixmap (width(), height()).

dstInfo specifies width, height, SkColorType, SkAlphaType, and SkColorSpace of destination. dstRowBytes specifics the gap from one destination row to the next. Returns true if pixels are copied. Returns false if dstInfo address equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes().

Pixels are copied only if pixel conversion is possible. If SkPixmap colorType() is kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match. If SkPixmap colorType() is kGray_8_SkColorType, dstInfo.colorSpace() must match. If SkPixmap alphaType() is kOpaque_SkAlphaType, dstInfo.alphaType() must match. If SkPixmap colorSpace() is nullptr, dstInfo.colorSpace() must match. Returns false if pixel conversion is not possible.

Returns false if SkPixmap width() or height() is zero or negative.

Parameters

dstInfo destination width, height, SkColorType, SkAlphaType, SkColorSpace
dstPixels destination pixel storage
dstRowBytes destination row length

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[2][3] SkBitmap::readPixels[2][3] SkCanvas::drawBitmap SkCanvas::readPixels[2][3] SkImage::readPixels[2] SkSurface::readPixels[2][3]


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 Pixmap (width(), 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 Pixmap colorType is kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType must match. If Pixmap colorType is kGray_8_SkColorType, dstInfo.colorSpace must match. If Pixmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType must match. If Pixmap 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 Pixmap width() or height() is zero or negative. Returns false if:

abs(srcX) >= Pixmap width(), or if abs(srcY) >= Pixmap height().

Parameters

dstInfo destination width, height, Color Type, Alpha Type, Color Space
dstPixels destination pixel storage
dstRowBytes destination row length
srcX column index whose absolute value is less than width()
srcY row index whose absolute value is less than height()

Return Value

true if pixels are copied to dstPixels

Example

See Also

erase[2][3] SkBitmap::readPixels[2][3] SkCanvas::drawBitmap SkCanvas::readPixels[2][3] SkImage::readPixels[2] SkSurface::readPixels[2][3]


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 Pixmap (width(), 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 Pixmap colorType is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType must match. If Pixmap colorType is kGray_8_SkColorType, dst.info().colorSpace must match. If Pixmap alphaType is kOpaque_SkAlphaType, dst.info().alphaType must match. If Pixmap 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 Pixmap width() or height() is zero or negative. Returns false if:

abs(srcX) >= Pixmap width(), or if abs(srcY) >= Pixmap height().

Parameters

dst Image Info and pixel address to write to
srcX column index whose absolute value is less than width()
srcY row index whose absolute value is less than height()

Return Value

true if pixels are copied to dst

Example

See Also

erase[2][3] SkBitmap::readPixels[2][3] SkCanvas::drawBitmap SkCanvas::readPixels[2][3] SkImage::readPixels[2] SkSurface::readPixels[2][3]


bool readPixels(const SkPixmap& dst) const

Copies pixels inside bounds() to dst. dst specifies width, height, SkColorType, SkAlphaType, and SkColorSpace of destination. Returns true if pixels are copied. Returns false if dst address equals nullptr, or dst.rowBytes() is less than dst SkImageInfo::minRowBytes.

Pixels are copied only if pixel conversion is possible. If SkPixmap colorType() is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst SkColorType must match. If SkPixmap colorType() is kGray_8_SkColorType, dst SkColorSpace must match. If SkPixmap alphaType() is kOpaque_SkAlphaType, dst SkAlphaType must match. If SkPixmap colorSpace() is nullptr, dst SkColorSpace must match. Returns false if pixel conversion is not possible.

Returns false if SkPixmap width() or height() is zero or negative.

Parameters

dst SkImageInfo and pixel address to write to

Return Value

true if pixels are copied to dst

Example

See Also

erase[2][3] SkBitmap::readPixels[2][3] SkCanvas::drawBitmap SkCanvas::readPixels[2][3] SkImage::readPixels[2] SkSurface::readPixels[2][3]


bool scalePixels(const SkPixmap& dst, SkFilterQuality filterQuality) const

Copies SkBitmap 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 address is nullptr, or dst.rowBytes() is less than dst SkImageInfo::minRowBytes.

Pixels are copied only if pixel conversion is possible. If SkPixmap colorType() is kGray_8_SkColorType, or kAlpha_8_SkColorType; dst SkColorType must match. If SkPixmap colorType() is kGray_8_SkColorType, dst SkColorSpace must match. If SkPixmap alphaType() is kOpaque_SkAlphaType, dst SkAlphaType must match. If SkPixmap colorSpace() is nullptr, dst SkColorSpace must match. Returns false if pixel conversion is not possible.

Returns false if SkBitmap width() or 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 nearest neighbor filter. kLow_SkFilterQuality is typically implemented with bilerp filter. kMedium_SkFilterQuality is typically implemented with bilerp filter, and mip-map filter when size is reduced. kHigh_SkFilterQuality is slowest, typically implemented with bicubic filter.

Parameters

dst SkImageInfo and pixel address to write to
filterQuality one of: kNone_SkFilterQuality, kLow_SkFilterQuality,

kMedium_SkFilterQuality, kHigh_SkFilterQuality

Return Value

true if pixels are scaled to fit dst

Example

See Also

SkCanvas::drawBitmap SkImage::scalePixels


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

color unpremultiplied color to write
subset bounding integer SkRect of written pixels

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

color unpremultiplied color to write

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

color unpremultiplied color to write
subset bounding integer SkRect of pixels to write; may be nullptr

Return Value

true if pixels are changed

Example

See Also

SkBitmap::erase SkCanvas::clear SkCanvas::drawColor