8 #ifndef SkPixmap_DEFINED
9 #define SkPixmap_DEFINED
18 #include "include/private/base/SkAPI.h"
19 #include "include/private/base/SkAssert.h"
51 : fPixels(nullptr), fRowBytes(0), fInfo(
SkImageInfo::MakeUnknown(0, 0))
73 : fPixels(addr), fRowBytes(rowBytes), fInfo(info)
117 [[nodiscard]]
bool reset(
const SkMask& mask);
153 const void*
addr()
const {
return fPixels; }
160 int width()
const {
return fInfo.width(); }
166 int height()
const {
return fInfo.height(); }
314 const void*
addr(
int x,
int y)
const {
315 return (
const char*)fPixels + fInfo.computeOffset(x, y, fRowBytes);
327 SkASSERT(1 == fInfo.bytesPerPixel());
328 return reinterpret_cast<const uint8_t*
>(fPixels);
340 SkASSERT(2 == fInfo.bytesPerPixel());
341 return reinterpret_cast<const uint16_t*
>(fPixels);
353 SkASSERT(4 == fInfo.bytesPerPixel());
354 return reinterpret_cast<const uint32_t*
>(fPixels);
366 SkASSERT(8 == fInfo.bytesPerPixel());
367 return reinterpret_cast<const uint64_t*
>(fPixels);
380 SkASSERT(8 == fInfo.bytesPerPixel());
383 return reinterpret_cast<const uint16_t*
>(fPixels);
398 const uint8_t*
addr8(
int x,
int y)
const {
399 SkASSERT((
unsigned)x < (
unsigned)fInfo.width());
400 SkASSERT((
unsigned)y < (
unsigned)fInfo.height());
401 return (
const uint8_t*)((
const char*)this->addr8() + (size_t)y * fRowBytes + (x << 0));
416 const uint16_t*
addr16(
int x,
int y)
const {
417 SkASSERT((
unsigned)x < (
unsigned)fInfo.width());
418 SkASSERT((
unsigned)y < (
unsigned)fInfo.height());
419 return (
const uint16_t*)((
const char*)this->addr16() + (size_t)y * fRowBytes + (x << 1));
434 const uint32_t*
addr32(
int x,
int y)
const {
435 SkASSERT((
unsigned)x < (
unsigned)fInfo.width());
436 SkASSERT((
unsigned)y < (
unsigned)fInfo.height());
437 return (
const uint32_t*)((
const char*)this->addr32() + (size_t)y * fRowBytes + (x << 2));
452 const uint64_t*
addr64(
int x,
int y)
const {
453 SkASSERT((
unsigned)x < (
unsigned)fInfo.width());
454 SkASSERT((
unsigned)y < (
unsigned)fInfo.height());
455 return (
const uint64_t*)((
const char*)this->addr64() + (size_t)y * fRowBytes + (x << 3));
476 return reinterpret_cast<const uint16_t*
>(this->addr64(x, y));
495 return const_cast<void*
>(this->addr(x, y));
509 return const_cast<uint8_t*
>(this->addr8(x, y));
523 return const_cast<uint16_t*
>(this->addr16(x, y));
538 return const_cast<uint32_t*
>(this->addr32(x, y));
552 return const_cast<uint64_t*
>(this->addr64(x, y));
567 return reinterpret_cast<uint16_t*
>(writable_addr64(x, y));
593 return this->readPixels(dstInfo, dstPixels, dstRowBytes, 0, 0);
SkAlphaType
Describes how to interpret the alpha component of a pixel.
Definition: SkAlphaType.h:26
SkColorType
Describes how pixel bits encode color.
Definition: SkColorType.h:19
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition: SkColorType.h:37
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
Definition: SkColorType.h:35
Types, consts, functions, and macros for colors.
uint32_t SkColor
32-bit ARGB color value, unpremultiplied.
Definition: SkColor.h:37
Definition: SkColorSpace.h:107
SkPixmap provides a utility to pair SkImageInfo with pixels and row bytes.
Definition: SkPixmap.h:40
uint32_t * writable_addr32(int x, int y) const
Returns writable pixel address at (x, y).
Definition: SkPixmap.h:537
const uint16_t * addr16(int x, int y) const
Returns readable pixel address at (x, y).
Definition: SkPixmap.h:416
bool scalePixels(const SkPixmap &dst, const SkSamplingOptions &) const
Copies SkBitmap to dst, scaling pixels to fit dst.width() and dst.height(), and converting pixels to ...
void reset(const SkImageInfo &info, const void *addr, size_t rowBytes)
Sets width, height, SkAlphaType, and SkColorType from info.
SkColor getColor(int x, int y) const
Returns pixel at (x, y) as unpremultiplied color.
const uint16_t * addrF16(int x, int y) const
Returns readable pixel address at (x, y).
Definition: SkPixmap.h:473
uint8_t * writable_addr8(int x, int y) const
Returns writable pixel address at (x, y).
Definition: SkPixmap.h:508
const uint8_t * addr8(int x, int y) const
Returns readable pixel address at (x, y).
Definition: SkPixmap.h:398
bool computeIsOpaque() const
Returns true if all pixels are opaque.
uint64_t * writable_addr64(int x, int y) const
Returns writable pixel address at (x, y).
Definition: SkPixmap.h:551
SkColorSpace * colorSpace() const
Returns SkColorSpace, the range of colors, associated with SkImageInfo.
SkIRect bounds() const
Returns SkIRect { 0, 0, width(), height() }.
Definition: SkPixmap.h:207
const uint64_t * addr64(int x, int y) const
Returns readable pixel address at (x, y).
Definition: SkPixmap.h:452
bool erase(SkColor color, const SkIRect &subset) const
Writes color to pixels bounded by subset; returns true on success.
uint16_t * writable_addrF16(int x, int y) const
Returns writable pixel address at (x, y).
Definition: SkPixmap.h:566
uint16_t * writable_addr16(int x, int y) const
Returns writable_addr pixel address at (x, y).
Definition: SkPixmap.h:522
size_t rowBytes() const
Returns row bytes, the interval from one pixel row to the next.
Definition: SkPixmap.h:145
int width() const
Returns pixel count in each pixel row.
Definition: SkPixmap.h:160
void * writable_addr(int x, int y) const
Returns writable pixel address at (x, y).
Definition: SkPixmap.h:494
const uint8_t * addr8() const
Returns readable base pixel address.
Definition: SkPixmap.h:326
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes) const
Copies a SkRect of pixels to dstPixels.
Definition: SkPixmap.h:592
const void * addr() const
Returns pixel address, the base address corresponding to the pixel origin.
Definition: SkPixmap.h:153
SkColorType colorType() const
Definition: SkPixmap.h:173
SkPixmap()
Creates an empty SkPixmap without pixels, with kUnknown_SkColorType, with kUnknown_SkAlphaType,...
Definition: SkPixmap.h:50
sk_sp< SkColorSpace > refColorSpace() const
Returns smart pointer to SkColorSpace, the range of colors, associated with SkImageInfo.
const uint32_t * addr32() const
Returns readable base pixel address.
Definition: SkPixmap.h:352
bool isOpaque() const
Returns true if SkAlphaType is kOpaque_SkAlphaType.
Definition: SkPixmap.h:201
const uint16_t * addr16() const
Returns readable base pixel address.
Definition: SkPixmap.h:339
const uint32_t * addr32(int x, int y) const
Returns readable pixel address at (x, y).
Definition: SkPixmap.h:434
bool reset(const SkMask &mask)
Deprecated.
void setColorSpace(sk_sp< SkColorSpace > colorSpace)
Changes SkColorSpace in SkImageInfo; preserves width, height, SkAlphaType, and SkColorType in SkImage...
const void * addr(int x, int y) const
Returns readable pixel address at (x, y).
Definition: SkPixmap.h:314
const uint16_t * addrF16() const
Returns readable base pixel address.
Definition: SkPixmap.h:379
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const
Copies a SkRect of pixels to dstPixels.
SkColor4f getColor4f(int x, int y) const
Returns pixel at (x, y) as unpremultiplied color as an SkColor4f.
bool erase(const SkColor4f &color, const SkIRect *subset=nullptr) const
Writes color to pixels bounded by subset; returns true on success.
bool readPixels(const SkPixmap &dst, int srcX, int srcY) const
Copies a SkRect of pixels to dst.
Definition: SkPixmap.h:647
int rowBytesAsPixels() const
Returns number of pixels that fit on row.
Definition: SkPixmap.h:214
size_t computeByteSize() const
Returns minimum memory required for pixel storage.
Definition: SkPixmap.h:231
float getAlphaf(int x, int y) const
Look up the pixel at (x,y) and return its alpha component, normalized to [0..1].
int shiftPerPixel() const
Returns bit shift converting row bytes to row pixels.
Definition: SkPixmap.h:221
const uint64_t * addr64() const
Returns readable base pixel address.
Definition: SkPixmap.h:365
int height() const
Returns pixel row count.
Definition: SkPixmap.h:166
SkAlphaType alphaType() const
Definition: SkPixmap.h:175
SkISize dimensions() const
Return the dimensions of the pixmap (from its ImageInfo)
Definition: SkPixmap.h:171
void * writable_addr() const
Returns writable base pixel address.
Definition: SkPixmap.h:483
bool erase(SkColor color) const
Writes color to pixels inside bounds(); returns true on success.
Definition: SkPixmap.h:712
bool readPixels(const SkPixmap &dst) const
Copies pixels inside bounds() to dst.
Definition: SkPixmap.h:668
const SkImageInfo & info() const
Returns width, height, SkAlphaType, SkColorType, and SkColorSpace.
Definition: SkPixmap.h:135
void reset()
Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to kUnknown_SkColorType;...
bool extractSubset(SkPixmap *subset, const SkIRect &area) const
Sets subset width, height, pixel address to intersection of SkPixmap with area, if intersection is no...
SkPixmap(const SkImageInfo &info, const void *addr, size_t rowBytes)
Creates SkPixmap from info width, height, SkAlphaType, and SkColorType.
Definition: SkPixmap.h:72
RGBA color value, holding four floating point components.
SkIRect holds four 32-bit integer coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:32
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Returns constructed SkIRect set to (0, 0, w, h).
Definition: SkRect.h:56
Describes pixel dimensions and encoding.
Definition: SkImageInfo.h:194
Definition: SkSamplingOptions.h:58