2015-05-22 15:06:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkPixmap_DEFINED
|
|
|
|
#define SkPixmap_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
2020-11-23 22:41:35 +00:00
|
|
|
#include "include/core/SkSamplingOptions.h"
|
|
|
|
|
2022-03-31 19:07:44 +00:00
|
|
|
class SkColorSpace;
|
2016-02-04 21:09:59 +00:00
|
|
|
class SkData;
|
2015-06-05 21:33:17 +00:00
|
|
|
struct SkMask;
|
2015-05-22 15:06:21 +00:00
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** \class SkPixmap
|
|
|
|
SkPixmap provides a utility to pair SkImageInfo with pixels and row bytes.
|
|
|
|
SkPixmap is a low level class which provides convenience functions to access
|
|
|
|
raster destinations. SkCanvas can not draw SkPixmap, nor does SkPixmap provide
|
|
|
|
a direct drawing destination.
|
|
|
|
|
|
|
|
Use SkBitmap to draw pixels referenced by SkPixmap; use SkSurface to draw into
|
|
|
|
pixels referenced by SkPixmap.
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
SkPixmap does not try to manage the lifetime of the pixel memory. Use SkPixelRef
|
|
|
|
to manage pixel memory; SkPixelRef is safe across threads.
|
2017-09-21 16:28:43 +00:00
|
|
|
*/
|
2015-07-27 17:27:28 +00:00
|
|
|
class SK_API SkPixmap {
|
2015-05-22 15:06:21 +00:00
|
|
|
public:
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** 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 empty SkPixmap
|
|
|
|
*/
|
2015-05-22 15:06:21 +00:00
|
|
|
SkPixmap()
|
2017-08-28 14:34:05 +00:00
|
|
|
: fPixels(nullptr), fRowBytes(0), fInfo(SkImageInfo::MakeUnknown(0, 0))
|
2015-05-22 15:06:21 +00:00
|
|
|
{}
|
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param info width, height, SkAlphaType, SkColorType of SkImageInfo
|
|
|
|
@param addr pointer to pixels allocated by caller; may be nullptr
|
|
|
|
@param rowBytes size of one row of addr; width times pixel size, or larger
|
|
|
|
@return initialized SkPixmap
|
|
|
|
*/
|
2017-07-18 14:53:11 +00:00
|
|
|
SkPixmap(const SkImageInfo& info, const void* addr, size_t rowBytes)
|
2017-07-17 21:33:53 +00:00
|
|
|
: fPixels(addr), fRowBytes(rowBytes), fInfo(info)
|
|
|
|
{}
|
2015-05-22 15:06:21 +00:00
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** 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.
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Pixmap_reset
|
2017-09-21 16:28:43 +00:00
|
|
|
*/
|
2015-05-26 18:31:54 +00:00
|
|
|
void reset();
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param info width, height, SkAlphaType, SkColorType of SkImageInfo
|
|
|
|
@param addr pointer to pixels allocated by caller; may be nullptr
|
|
|
|
@param rowBytes size of one row of addr; width times pixel size, or larger
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Pixmap_reset_2
|
2017-09-21 16:28:43 +00:00
|
|
|
*/
|
2017-07-18 14:53:11 +00:00
|
|
|
void reset(const SkImageInfo& info, const void* addr, size_t rowBytes);
|
2015-06-05 21:33:17 +00:00
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param colorSpace SkColorSpace moved to SkImageInfo
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Pixmap_setColorSpace
|
2017-09-21 16:28:43 +00:00
|
|
|
*/
|
2017-09-05 13:42:43 +00:00
|
|
|
void setColorSpace(sk_sp<SkColorSpace> colorSpace);
|
2016-06-09 18:03:45 +00:00
|
|
|
|
2018-11-15 13:25:12 +00:00
|
|
|
/** Deprecated.
|
2017-09-21 16:28:43 +00:00
|
|
|
*/
|
2017-09-05 13:42:43 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask);
|
2015-06-05 21:33:17 +00:00
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param subset storage for width, height, pixel address of intersection
|
|
|
|
@param area bounds to intersect with SkPixmap
|
|
|
|
@return true if intersection of SkPixmap and area is not empty
|
|
|
|
*/
|
2015-06-05 21:33:17 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT extractSubset(SkPixmap* subset, const SkIRect& area) const;
|
2015-05-26 18:31:54 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns width, height, SkAlphaType, SkColorType, and SkColorSpace.
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2018-10-31 14:54:50 +00:00
|
|
|
@return reference to SkImageInfo
|
2017-09-21 16:28:43 +00:00
|
|
|
*/
|
2015-05-22 15:06:21 +00:00
|
|
|
const SkImageInfo& info() const { return fInfo; }
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Returns row bytes, the interval from one pixel row to the next. Row bytes
|
2017-10-30 15:48:35 +00:00
|
|
|
is at least as large as: width() * info().bytesPerPixel().
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
Returns zero if colorType() is kUnknown_SkColorType.
|
|
|
|
It is up to the SkBitmap creator to ensure that row bytes is a useful value.
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
@return byte length of pixel row
|
|
|
|
*/
|
2015-05-22 15:06:21 +00:00
|
|
|
size_t rowBytes() const { return fRowBytes; }
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** 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 pixel address
|
|
|
|
*/
|
2015-05-22 15:06:21 +00:00
|
|
|
const void* addr() const { return fPixels; }
|
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** Returns pixel count in each pixel row. Should be equal or less than:
|
2017-10-30 15:48:35 +00:00
|
|
|
rowBytes() / info().bytesPerPixel().
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
@return pixel width in SkImageInfo
|
|
|
|
*/
|
2015-05-22 15:06:21 +00:00
|
|
|
int width() const { return fInfo.width(); }
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Returns pixel row count.
|
|
|
|
|
|
|
|
@return pixel height in SkImageInfo
|
|
|
|
*/
|
2015-05-22 15:06:21 +00:00
|
|
|
int height() const { return fInfo.height(); }
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2019-06-03 15:04:20 +00:00
|
|
|
/**
|
|
|
|
* Return the dimensions of the pixmap (from its ImageInfo)
|
|
|
|
*/
|
|
|
|
SkISize dimensions() const { return fInfo.dimensions(); }
|
|
|
|
|
2015-05-22 15:06:21 +00:00
|
|
|
SkColorType colorType() const { return fInfo.colorType(); }
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2015-05-22 15:06:21 +00:00
|
|
|
SkAlphaType alphaType() const { return fInfo.alphaType(); }
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
/** Returns SkColorSpace, the range of colors, associated with SkImageInfo. The
|
2017-10-30 15:48:35 +00:00
|
|
|
reference count of SkColorSpace is unchanged. The returned SkColorSpace is
|
|
|
|
immutable.
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
@return SkColorSpace in SkImageInfo, or nullptr
|
2017-09-21 16:28:43 +00:00
|
|
|
*/
|
2022-03-31 19:07:44 +00:00
|
|
|
SkColorSpace* colorSpace() const;
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2019-03-04 18:08:25 +00:00
|
|
|
/** Returns smart pointer to SkColorSpace, the range of colors, associated with
|
|
|
|
SkImageInfo. The smart pointer tracks the number of objects sharing this
|
|
|
|
SkColorSpace reference so the memory is released when the owners destruct.
|
|
|
|
|
|
|
|
The returned SkColorSpace is immutable.
|
|
|
|
|
|
|
|
@return SkColorSpace in SkImageInfo wrapped in a smart pointer
|
|
|
|
*/
|
2022-03-31 19:07:44 +00:00
|
|
|
sk_sp<SkColorSpace> refColorSpace() const;
|
2019-03-04 18:08:25 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns true if SkAlphaType is kOpaque_SkAlphaType.
|
|
|
|
Does not check if SkColorType allows alpha, or if any pixel value has
|
2017-10-30 15:48:35 +00:00
|
|
|
transparency.
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@return true if SkImageInfo has opaque SkAlphaType
|
2017-09-21 16:28:43 +00:00
|
|
|
*/
|
2015-05-22 15:06:21 +00:00
|
|
|
bool isOpaque() const { return fInfo.isOpaque(); }
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns SkIRect { 0, 0, width(), height() }.
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
@return integral rectangle from origin to width() and height()
|
|
|
|
*/
|
2015-06-04 21:12:25 +00:00
|
|
|
SkIRect bounds() const { return SkIRect::MakeWH(this->width(), this->height()); }
|
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** Returns number of pixels that fit on row. Should be greater than or equal to
|
|
|
|
width().
|
|
|
|
|
|
|
|
@return maximum pixels per row
|
|
|
|
*/
|
2016-03-24 18:21:25 +00:00
|
|
|
int rowBytesAsPixels() const { return int(fRowBytes >> this->shiftPerPixel()); }
|
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** Returns bit shift converting row bytes to row pixels.
|
|
|
|
Returns zero for kUnknown_SkColorType.
|
|
|
|
|
|
|
|
@return one of: 0, 1, 2, 3; left shift to convert pixels to bytes
|
|
|
|
*/
|
2016-04-15 13:59:38 +00:00
|
|
|
int shiftPerPixel() const { return fInfo.shiftPerPixel(); }
|
2016-03-24 18:21:25 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns minimum memory required for pixel storage.
|
|
|
|
Does not include unused memory on last row when rowBytesAsPixels() exceeds width().
|
2019-07-08 18:29:44 +00:00
|
|
|
Returns SIZE_MAX if result does not fit in size_t.
|
2017-10-30 15:48:35 +00:00
|
|
|
Returns zero if height() or width() is 0.
|
|
|
|
Returns height() times rowBytes() if colorType() is kUnknown_SkColorType.
|
|
|
|
|
|
|
|
@return size in bytes of image buffer
|
|
|
|
*/
|
2017-09-29 17:41:58 +00:00
|
|
|
size_t computeByteSize() const { return fInfo.computeByteSize(fRowBytes); }
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** 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
|
2017-09-21 16:28:43 +00:00
|
|
|
pixels have alpha values equivalent to 1.0 or greater.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
For SkColorType kRGB_565_SkColorType or kGray_8_SkColorType: always
|
|
|
|
returns true. For SkColorType kAlpha_8_SkColorType, kBGRA_8888_SkColorType,
|
2017-09-21 16:28:43 +00:00
|
|
|
kRGBA_8888_SkColorType: returns true if all pixel alpha values are 255.
|
2018-02-27 15:22:04 +00:00
|
|
|
For SkColorType kARGB_4444_SkColorType: returns true if all pixel alpha values are 15.
|
2017-09-21 16:28:43 +00:00
|
|
|
For kRGBA_F16_SkColorType: returns true if all pixel alpha values are 1.0 or
|
|
|
|
greater.
|
|
|
|
|
|
|
|
Returns false for kUnknown_SkColorType.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@return true if all pixels have opaque values or SkColorType is opaque
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Pixmap_computeIsOpaque
|
2017-09-21 16:28:43 +00:00
|
|
|
*/
|
2016-12-07 20:24:59 +00:00
|
|
|
bool computeIsOpaque() const;
|
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** Returns pixel at (x, y) as unpremultiplied color.
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns black with alpha if SkColorType is kAlpha_8_SkColorType.
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
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
|
2018-02-27 15:22:04 +00:00
|
|
|
SK_RELEASE is defined. Fails if SkColorType is kUnknown_SkColorType or
|
2017-09-21 16:28:43 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return pixel converted to unpremultiplied color
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Pixmap_getColor
|
2017-09-21 16:28:43 +00:00
|
|
|
*/
|
2016-10-31 13:38:12 +00:00
|
|
|
SkColor getColor(int x, int y) const;
|
|
|
|
|
2022-06-28 18:39:56 +00:00
|
|
|
/** Returns pixel at (x, y) as unpremultiplied color as an SkColor4f.
|
|
|
|
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, though this is less likely than for getColor(). Rounding errors may
|
|
|
|
occur if the underlying type has lower precision.
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return pixel converted to unpremultiplied float color
|
|
|
|
*/
|
|
|
|
SkColor4f getColor4f(int x, int y) const;
|
|
|
|
|
2018-09-20 19:00:56 +00:00
|
|
|
/** Look 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).
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return alpha converted to normalized float
|
|
|
|
*/
|
|
|
|
float getAlphaf(int x, int y) const;
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns readable pixel address at (x, y). Returns nullptr if SkPixelRef is nullptr.
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
Input is not validated: out of bounds values of x or y trigger an assert() if
|
2018-02-27 15:22:04 +00:00
|
|
|
built with SK_DEBUG defined. Returns nullptr if SkColorType is kUnknown_SkColorType.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
Performs a lookup of pixel size; for better performance, call
|
|
|
|
one of: addr8, addr16, addr32, addr64, or addrF16().
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return readable generic pointer to pixel
|
|
|
|
*/
|
2016-02-05 19:18:39 +00:00
|
|
|
const void* addr(int x, int y) const {
|
|
|
|
return (const char*)fPixels + fInfo.computeOffset(x, y, fRowBytes);
|
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Returns readable base pixel address. Result is addressable as unsigned 8-bit bytes.
|
2018-02-27 15:22:04 +00:00
|
|
|
Will trigger an assert() if SkColorType is not kAlpha_8_SkColorType or
|
2017-09-21 16:28:43 +00:00
|
|
|
kGray_8_SkColorType, and is built with SK_DEBUG defined.
|
|
|
|
|
|
|
|
One byte corresponds to one pixel.
|
|
|
|
|
|
|
|
@return readable unsigned 8-bit pointer to pixels
|
|
|
|
*/
|
2016-02-05 19:18:39 +00:00
|
|
|
const uint8_t* addr8() const {
|
2018-02-09 18:26:46 +00:00
|
|
|
SkASSERT(1 == fInfo.bytesPerPixel());
|
2016-02-05 19:18:39 +00:00
|
|
|
return reinterpret_cast<const uint8_t*>(fPixels);
|
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
|
2018-02-27 15:22:04 +00:00
|
|
|
Will trigger an assert() if SkColorType is not kRGB_565_SkColorType or
|
2017-09-21 16:28:43 +00:00
|
|
|
kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
|
|
|
|
|
|
|
|
One word corresponds to one pixel.
|
|
|
|
|
|
|
|
@return readable unsigned 16-bit pointer to pixels
|
|
|
|
*/
|
2016-02-05 19:18:39 +00:00
|
|
|
const uint16_t* addr16() const {
|
2018-02-09 18:26:46 +00:00
|
|
|
SkASSERT(2 == fInfo.bytesPerPixel());
|
2016-02-05 19:18:39 +00:00
|
|
|
return reinterpret_cast<const uint16_t*>(fPixels);
|
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Returns readable base pixel address. Result is addressable as unsigned 32-bit words.
|
2018-02-27 15:22:04 +00:00
|
|
|
Will trigger an assert() if SkColorType is not kRGBA_8888_SkColorType or
|
2017-09-21 16:28:43 +00:00
|
|
|
kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
|
|
|
|
|
|
|
|
One word corresponds to one pixel.
|
|
|
|
|
|
|
|
@return readable unsigned 32-bit pointer to pixels
|
|
|
|
*/
|
2015-05-22 15:06:21 +00:00
|
|
|
const uint32_t* addr32() const {
|
2018-02-09 18:26:46 +00:00
|
|
|
SkASSERT(4 == fInfo.bytesPerPixel());
|
2015-05-22 15:06:21 +00:00
|
|
|
return reinterpret_cast<const uint32_t*>(fPixels);
|
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Returns readable base pixel address. Result is addressable as unsigned 64-bit words.
|
2018-02-27 15:22:04 +00:00
|
|
|
Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built
|
2017-09-21 16:28:43 +00:00
|
|
|
with SK_DEBUG defined.
|
|
|
|
|
|
|
|
One word corresponds to one pixel.
|
|
|
|
|
|
|
|
@return readable unsigned 64-bit pointer to pixels
|
|
|
|
*/
|
2016-02-05 19:18:39 +00:00
|
|
|
const uint64_t* addr64() const {
|
2018-02-09 18:26:46 +00:00
|
|
|
SkASSERT(8 == fInfo.bytesPerPixel());
|
2016-02-05 19:18:39 +00:00
|
|
|
return reinterpret_cast<const uint64_t*>(fPixels);
|
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Returns readable base pixel address. Result is addressable as unsigned 16-bit words.
|
2018-02-27 15:22:04 +00:00
|
|
|
Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built
|
2017-09-21 16:28:43 +00:00
|
|
|
with SK_DEBUG defined.
|
|
|
|
|
|
|
|
Each word represents one color component encoded as a half float.
|
|
|
|
Four words correspond to one pixel.
|
|
|
|
|
|
|
|
@return readable unsigned 16-bit pointer to first component of pixels
|
|
|
|
*/
|
2016-02-05 19:18:39 +00:00
|
|
|
const uint16_t* addrF16() const {
|
2018-02-09 18:26:46 +00:00
|
|
|
SkASSERT(8 == fInfo.bytesPerPixel());
|
2019-03-07 19:03:58 +00:00
|
|
|
SkASSERT(kRGBA_F16_SkColorType == fInfo.colorType() ||
|
|
|
|
kRGBA_F16Norm_SkColorType == fInfo.colorType());
|
2015-05-22 15:06:21 +00:00
|
|
|
return reinterpret_cast<const uint16_t*>(fPixels);
|
|
|
|
}
|
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** Returns readable pixel address at (x, y).
|
2015-05-22 15:06:21 +00:00
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
Input is not validated: out of bounds values of x or y trigger an assert() if
|
|
|
|
built with SK_DEBUG defined.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Will trigger an assert() if SkColorType is not kAlpha_8_SkColorType or
|
2017-09-21 16:28:43 +00:00
|
|
|
kGray_8_SkColorType, and is built with SK_DEBUG defined.
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return readable unsigned 8-bit pointer to pixel at (x, y)
|
|
|
|
*/
|
2016-02-05 19:18:39 +00:00
|
|
|
const uint8_t* addr8(int x, int y) const {
|
2015-05-22 15:06:21 +00:00
|
|
|
SkASSERT((unsigned)x < (unsigned)fInfo.width());
|
|
|
|
SkASSERT((unsigned)y < (unsigned)fInfo.height());
|
2020-06-01 20:50:19 +00:00
|
|
|
return (const uint8_t*)((const char*)this->addr8() + (size_t)y * fRowBytes + (x << 0));
|
2015-05-22 15:06:21 +00:00
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Will trigger an assert() if SkColorType is not kRGB_565_SkColorType or
|
2017-09-21 16:28:43 +00:00
|
|
|
kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return readable unsigned 16-bit pointer to pixel at (x, y)
|
|
|
|
*/
|
2015-05-22 15:06:21 +00:00
|
|
|
const uint16_t* addr16(int x, int y) const {
|
|
|
|
SkASSERT((unsigned)x < (unsigned)fInfo.width());
|
|
|
|
SkASSERT((unsigned)y < (unsigned)fInfo.height());
|
2020-06-01 20:50:19 +00:00
|
|
|
return (const uint16_t*)((const char*)this->addr16() + (size_t)y * fRowBytes + (x << 1));
|
2015-05-22 15:06:21 +00:00
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Will trigger an assert() if SkColorType is not kRGBA_8888_SkColorType or
|
2017-09-21 16:28:43 +00:00
|
|
|
kBGRA_8888_SkColorType, and is built with SK_DEBUG defined.
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return readable unsigned 32-bit pointer to pixel at (x, y)
|
|
|
|
*/
|
2016-02-05 19:18:39 +00:00
|
|
|
const uint32_t* addr32(int x, int y) const {
|
2015-05-22 15:06:21 +00:00
|
|
|
SkASSERT((unsigned)x < (unsigned)fInfo.width());
|
|
|
|
SkASSERT((unsigned)y < (unsigned)fInfo.height());
|
2020-06-01 20:50:19 +00:00
|
|
|
return (const uint32_t*)((const char*)this->addr32() + (size_t)y * fRowBytes + (x << 2));
|
2015-05-22 15:06:21 +00:00
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built
|
2017-09-21 16:28:43 +00:00
|
|
|
with SK_DEBUG defined.
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return readable unsigned 64-bit pointer to pixel at (x, y)
|
|
|
|
*/
|
2016-02-05 19:18:39 +00:00
|
|
|
const uint64_t* addr64(int x, int y) const {
|
|
|
|
SkASSERT((unsigned)x < (unsigned)fInfo.width());
|
|
|
|
SkASSERT((unsigned)y < (unsigned)fInfo.height());
|
2020-06-01 20:50:19 +00:00
|
|
|
return (const uint64_t*)((const char*)this->addr64() + (size_t)y * fRowBytes + (x << 3));
|
2016-02-05 19:18:39 +00:00
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Will trigger an assert() if SkColorType is not kRGBA_F16_SkColorType and is built
|
2017-09-21 16:28:43 +00:00
|
|
|
with SK_DEBUG defined.
|
|
|
|
|
|
|
|
Each unsigned 16-bit word represents one color component encoded as a half float.
|
|
|
|
Four words correspond to one pixel.
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return readable unsigned 16-bit pointer to pixel component at (x, y)
|
|
|
|
*/
|
2016-02-05 19:18:39 +00:00
|
|
|
const uint16_t* addrF16(int x, int y) const {
|
2019-03-07 19:03:58 +00:00
|
|
|
SkASSERT(kRGBA_F16_SkColorType == fInfo.colorType() ||
|
|
|
|
kRGBA_F16Norm_SkColorType == fInfo.colorType());
|
2016-02-05 19:18:39 +00:00
|
|
|
return reinterpret_cast<const uint16_t*>(this->addr64(x, y));
|
2015-05-22 15:06:21 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** Returns writable base pixel address.
|
2015-05-22 15:06:21 +00:00
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
@return writable generic base pointer to pixels
|
|
|
|
*/
|
2015-05-22 15:06:21 +00:00
|
|
|
void* writable_addr() const { return const_cast<void*>(fPixels); }
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Returns writable pixel address at (x, y).
|
|
|
|
|
|
|
|
Input is not validated: out of bounds values of x or y trigger an assert() if
|
2018-02-27 15:22:04 +00:00
|
|
|
built with SK_DEBUG defined. Returns zero if SkColorType is kUnknown_SkColorType.
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return writable generic pointer to pixel
|
|
|
|
*/
|
2016-04-15 13:59:38 +00:00
|
|
|
void* writable_addr(int x, int y) const {
|
|
|
|
return const_cast<void*>(this->addr(x, y));
|
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Returns writable pixel address at (x, y). Result is addressable as unsigned
|
2018-02-27 15:22:04 +00:00
|
|
|
8-bit bytes. Will trigger an assert() if SkColorType is not kAlpha_8_SkColorType
|
2017-09-21 16:28:43 +00:00
|
|
|
or kGray_8_SkColorType, and is built with SK_DEBUG defined.
|
|
|
|
|
|
|
|
One byte corresponds to one pixel.
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return writable unsigned 8-bit pointer to pixels
|
|
|
|
*/
|
2016-02-05 19:18:39 +00:00
|
|
|
uint8_t* writable_addr8(int x, int y) const {
|
|
|
|
return const_cast<uint8_t*>(this->addr8(x, y));
|
2015-05-22 15:06:21 +00:00
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Returns writable_addr pixel address at (x, y). Result is addressable as unsigned
|
2018-02-27 15:22:04 +00:00
|
|
|
16-bit words. Will trigger an assert() if SkColorType is not kRGB_565_SkColorType
|
2017-09-21 16:28:43 +00:00
|
|
|
or kARGB_4444_SkColorType, and is built with SK_DEBUG defined.
|
|
|
|
|
|
|
|
One word corresponds to one pixel.
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return writable unsigned 16-bit pointer to pixel
|
|
|
|
*/
|
2015-05-22 15:06:21 +00:00
|
|
|
uint16_t* writable_addr16(int x, int y) const {
|
|
|
|
return const_cast<uint16_t*>(this->addr16(x, y));
|
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Returns writable pixel address at (x, y). Result is addressable as unsigned
|
2018-02-27 15:22:04 +00:00
|
|
|
32-bit words. Will trigger an assert() if SkColorType is not
|
2017-09-21 16:28:43 +00:00
|
|
|
kRGBA_8888_SkColorType or kBGRA_8888_SkColorType, and is built with SK_DEBUG
|
|
|
|
defined.
|
|
|
|
|
|
|
|
One word corresponds to one pixel.
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return writable unsigned 32-bit pointer to pixel
|
|
|
|
*/
|
2016-02-05 19:18:39 +00:00
|
|
|
uint32_t* writable_addr32(int x, int y) const {
|
|
|
|
return const_cast<uint32_t*>(this->addr32(x, y));
|
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Returns writable pixel address at (x, y). Result is addressable as unsigned
|
2018-02-27 15:22:04 +00:00
|
|
|
64-bit words. Will trigger an assert() if SkColorType is not
|
2017-09-21 16:28:43 +00:00
|
|
|
kRGBA_F16_SkColorType and is built with SK_DEBUG defined.
|
|
|
|
|
|
|
|
One word corresponds to one pixel.
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return writable unsigned 64-bit pointer to pixel
|
|
|
|
*/
|
2016-02-05 19:18:39 +00:00
|
|
|
uint64_t* writable_addr64(int x, int y) const {
|
|
|
|
return const_cast<uint64_t*>(this->addr64(x, y));
|
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Returns writable pixel address at (x, y). Result is addressable as unsigned
|
2018-02-27 15:22:04 +00:00
|
|
|
16-bit words. Will trigger an assert() if SkColorType is not
|
2017-09-21 16:28:43 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return writable unsigned 16-bit pointer to first component of pixel
|
|
|
|
*/
|
2016-02-05 19:18:39 +00:00
|
|
|
uint16_t* writable_addrF16(int x, int y) const {
|
|
|
|
return reinterpret_cast<uint16_t*>(writable_addr64(x, y));
|
2015-05-22 15:06:21 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** Copies a SkRect of pixels to dstPixels. Copy starts at (0, 0), and does not
|
2018-02-27 15:22:04 +00:00
|
|
|
exceed SkPixmap (width(), height()).
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
dstInfo specifies width, height, SkColorType, SkAlphaType, and
|
2017-09-21 16:28:43 +00:00
|
|
|
SkColorSpace of destination. dstRowBytes specifics the gap from one destination
|
|
|
|
row to the next. Returns true if pixels are copied. Returns false if
|
2018-10-31 14:54:50 +00:00
|
|
|
dstInfo address equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes().
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If SkPixmap colorType() is
|
2017-09-21 16:28:43 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match.
|
2018-02-27 15:22:04 +00:00
|
|
|
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
|
2017-09-21 16:28:43 +00:00
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns false if SkPixmap width() or height() is zero or negative.
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@param dstInfo destination width, height, SkColorType, SkAlphaType, SkColorSpace
|
2017-09-21 16:28:43 +00:00
|
|
|
@param dstPixels destination pixel storage
|
|
|
|
@param dstRowBytes destination row length
|
|
|
|
@return true if pixels are copied to dstPixels
|
|
|
|
*/
|
2015-05-23 20:21:06 +00:00
|
|
|
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes) const {
|
|
|
|
return this->readPixels(dstInfo, dstPixels, dstRowBytes, 0, 0);
|
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Copies a SkRect of pixels to dstPixels. Copy starts at (srcX, srcY), and does not
|
2018-02-27 15:22:04 +00:00
|
|
|
exceed SkPixmap (width(), height()).
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
dstInfo specifies width, height, SkColorType, SkAlphaType, and
|
2017-09-21 16:28:43 +00:00
|
|
|
SkColorSpace of destination. dstRowBytes specifics the gap from one destination
|
|
|
|
row to the next. Returns true if pixels are copied. Returns false if
|
2018-10-31 14:54:50 +00:00
|
|
|
dstInfo address equals nullptr, or dstRowBytes is less than dstInfo.minRowBytes().
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If SkPixmap colorType() is
|
2017-09-21 16:28:43 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match.
|
2018-02-27 15:22:04 +00:00
|
|
|
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
|
2017-09-21 16:28:43 +00:00
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
|
|
|
srcX and srcY may be negative to copy only top or left of source. Returns
|
2018-02-27 15:22:04 +00:00
|
|
|
false if SkPixmap width() or height() is zero or negative. Returns false if:
|
|
|
|
abs(srcX) >= Pixmap width(), or if abs(srcY) >= Pixmap height().
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@param dstInfo destination width, height, SkColorType, SkAlphaType, SkColorSpace
|
2017-09-21 16:28:43 +00:00
|
|
|
@param dstPixels destination pixel storage
|
|
|
|
@param dstRowBytes destination row length
|
|
|
|
@param srcX column index whose absolute value is less than width()
|
|
|
|
@param srcY row index whose absolute value is less than height()
|
|
|
|
@return true if pixels are copied to dstPixels
|
|
|
|
*/
|
2017-06-06 14:11:34 +00:00
|
|
|
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX,
|
2018-07-16 17:06:02 +00:00
|
|
|
int srcY) const;
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** Copies a SkRect of pixels to dst. Copy starts at (srcX, srcY), and does not
|
2018-02-27 15:22:04 +00:00
|
|
|
exceed SkPixmap (width(), height()). dst specifies width, height, SkColorType,
|
|
|
|
SkAlphaType, and SkColorSpace of destination. Returns true if pixels are copied.
|
2018-10-31 14:54:50 +00:00
|
|
|
Returns false if dst address equals nullptr, or dst.rowBytes() is less than
|
2017-09-21 16:28:43 +00:00
|
|
|
dst SkImageInfo::minRowBytes.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If SkPixmap colorType() is
|
2017-09-21 16:28:43 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; dst.info().colorType must match.
|
2018-02-27 15:22:04 +00:00
|
|
|
If SkPixmap colorType() is kGray_8_SkColorType, dst.info().colorSpace must match.
|
|
|
|
If SkPixmap alphaType() is kOpaque_SkAlphaType, dst.info().alphaType must
|
|
|
|
match. If SkPixmap colorSpace() is nullptr, dst.info().colorSpace must match. Returns
|
2017-09-21 16:28:43 +00:00
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
|
|
|
srcX and srcY may be negative to copy only top or left of source. Returns
|
2018-02-27 15:22:04 +00:00
|
|
|
false SkPixmap width() or height() is zero or negative. Returns false if:
|
|
|
|
abs(srcX) >= Pixmap width(), or if abs(srcY) >= Pixmap height().
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
@param dst SkImageInfo and pixel address to write to
|
|
|
|
@param srcX column index whose absolute value is less than width()
|
|
|
|
@param srcY row index whose absolute value is less than height()
|
|
|
|
@return true if pixels are copied to dst
|
|
|
|
*/
|
2015-05-23 20:21:06 +00:00
|
|
|
bool readPixels(const SkPixmap& dst, int srcX, int srcY) const {
|
|
|
|
return this->readPixels(dst.info(), dst.writable_addr(), dst.rowBytes(), srcX, srcY);
|
|
|
|
}
|
2017-09-21 16:28:43 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies pixels inside bounds() to dst. dst specifies width, height, SkColorType,
|
|
|
|
SkAlphaType, and SkColorSpace of destination. Returns true if pixels are copied.
|
2018-10-31 14:54:50 +00:00
|
|
|
Returns false if dst address equals nullptr, or dst.rowBytes() is less than
|
2017-09-21 16:28:43 +00:00
|
|
|
dst SkImageInfo::minRowBytes.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
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
|
2017-09-21 16:28:43 +00:00
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns false if SkPixmap width() or height() is zero or negative.
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
@param dst SkImageInfo and pixel address to write to
|
|
|
|
@return true if pixels are copied to dst
|
|
|
|
*/
|
2015-05-23 20:21:06 +00:00
|
|
|
bool readPixels(const SkPixmap& dst) const {
|
|
|
|
return this->readPixels(dst.info(), dst.writable_addr(), dst.rowBytes(), 0, 0);
|
|
|
|
}
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies SkBitmap to dst, scaling pixels to fit dst.width() and dst.height(), and
|
2017-09-21 16:28:43 +00:00
|
|
|
converting pixels to match dst.colorType() and dst.alphaType(). Returns true if
|
2018-10-31 14:54:50 +00:00
|
|
|
pixels are copied. Returns false if dst address is nullptr, or dst.rowBytes() is
|
2017-09-21 16:28:43 +00:00
|
|
|
less than dst SkImageInfo::minRowBytes.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
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
|
2017-09-21 16:28:43 +00:00
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns false if SkBitmap width() or height() is zero or negative.
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
@param dst SkImageInfo and pixel address to write to
|
2018-02-27 15:22:04 +00:00
|
|
|
@return true if pixels are scaled to fit dst
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Pixmap_scalePixels
|
2017-09-21 16:28:43 +00:00
|
|
|
*/
|
2020-11-23 22:41:35 +00:00
|
|
|
bool scalePixels(const SkPixmap& dst, const SkSamplingOptions&) const;
|
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** 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().
|
|
|
|
|
Reland "Make SkBitmap/SkPixmap::erase* do so in sRGB"
This reverts commit 832c931d5b660d7f0da10a01bd8950a8669de65b.
Reason for revert: To confirm whether it was blocking, and update
Chrome if necessary
Bug: skia:8663
Original change's description:
> Revert "Make SkBitmap/SkPixmap::erase* do so in sRGB"
>
> This reverts commit 6f44647e529924e414ee05462b1ef7b7d1cfb767.
>
> Reason for revert: checking to see if this is blocking the Chrome roll
>
> Original change's description:
> > Make SkBitmap/SkPixmap::erase* do so in sRGB
> >
> > We generally consider untagged colors to be sRGB, so this makes us more
> > consistent with other parts of the API.
> >
> > Add a test.
> >
> > Cq-Include-Trybots: luci.chromium.try:linux-blink-rel
> > Change-Id: I5468c86ad92164797a65ffd9fbe471e01a97a2ca
> > Reviewed-on: https://skia-review.googlesource.com/c/179245
> > Commit-Queue: Leon Scroggins <scroggo@google.com>
> > Reviewed-by: Mike Reed <reed@google.com>
> > Reviewed-by: Mike Klein <mtklein@google.com>
> > Reviewed-by: Brian Osman <brianosman@google.com>
>
> TBR=djsollen@google.com,mtklein@google.com,scroggo@google.com,brianosman@google.com,reed@google.com
>
> Change-Id: Ia592adf2c790d294da1e32c1e83f9f34e81d79cc
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Cq-Include-Trybots: luci.chromium.try:linux-blink-rel
> Reviewed-on: https://skia-review.googlesource.com/c/182083
> Reviewed-by: Robert Phillips <robertphillips@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>
TBR=djsollen@google.com,mtklein@google.com,robertphillips@google.com,scroggo@google.com,brianosman@google.com,reed@google.com
Cq-Include-Trybots: luci.chromium.try:linux-blink-rel;luci.chromium.try:android-kitkat-arm-rel;luci.chromium.try:android-marshmallow-arm64-rel;luci.chromium.try:linux-chromeos-rel;luci.chromium.try:linux_chromium_asan_rel_ng;luci.chromium.try:win7_chromium_rel_ng;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:mac_chromium_rel_ng;luci.chromium.try:linux_chromium_tsan_rel_ng;luci.chromium.try:linux_chromium_rel_ng;
Change-Id: I226fd5b6f298fad648b1d05c8a8e806eac874a46
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/182142
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
2019-01-08 14:06:17 +00:00
|
|
|
@param color sRGB unpremultiplied color to write
|
2017-09-21 16:28:43 +00:00
|
|
|
@param subset bounding integer SkRect of written pixels
|
|
|
|
@return true if pixels are changed
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Pixmap_erase
|
2017-09-21 16:28:43 +00:00
|
|
|
*/
|
2017-09-14 14:36:51 +00:00
|
|
|
bool erase(SkColor color, const SkIRect& subset) const;
|
2015-06-08 17:22:22 +00:00
|
|
|
|
2017-09-21 16:28:43 +00:00
|
|
|
/** Writes color to pixels inside bounds(); returns true on success.
|
|
|
|
Returns false if colorType() is kUnknown_SkColorType, or if bounds()
|
|
|
|
is empty.
|
|
|
|
|
Reland "Make SkBitmap/SkPixmap::erase* do so in sRGB"
This reverts commit 832c931d5b660d7f0da10a01bd8950a8669de65b.
Reason for revert: To confirm whether it was blocking, and update
Chrome if necessary
Bug: skia:8663
Original change's description:
> Revert "Make SkBitmap/SkPixmap::erase* do so in sRGB"
>
> This reverts commit 6f44647e529924e414ee05462b1ef7b7d1cfb767.
>
> Reason for revert: checking to see if this is blocking the Chrome roll
>
> Original change's description:
> > Make SkBitmap/SkPixmap::erase* do so in sRGB
> >
> > We generally consider untagged colors to be sRGB, so this makes us more
> > consistent with other parts of the API.
> >
> > Add a test.
> >
> > Cq-Include-Trybots: luci.chromium.try:linux-blink-rel
> > Change-Id: I5468c86ad92164797a65ffd9fbe471e01a97a2ca
> > Reviewed-on: https://skia-review.googlesource.com/c/179245
> > Commit-Queue: Leon Scroggins <scroggo@google.com>
> > Reviewed-by: Mike Reed <reed@google.com>
> > Reviewed-by: Mike Klein <mtklein@google.com>
> > Reviewed-by: Brian Osman <brianosman@google.com>
>
> TBR=djsollen@google.com,mtklein@google.com,scroggo@google.com,brianosman@google.com,reed@google.com
>
> Change-Id: Ia592adf2c790d294da1e32c1e83f9f34e81d79cc
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Cq-Include-Trybots: luci.chromium.try:linux-blink-rel
> Reviewed-on: https://skia-review.googlesource.com/c/182083
> Reviewed-by: Robert Phillips <robertphillips@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>
TBR=djsollen@google.com,mtklein@google.com,robertphillips@google.com,scroggo@google.com,brianosman@google.com,reed@google.com
Cq-Include-Trybots: luci.chromium.try:linux-blink-rel;luci.chromium.try:android-kitkat-arm-rel;luci.chromium.try:android-marshmallow-arm64-rel;luci.chromium.try:linux-chromeos-rel;luci.chromium.try:linux_chromium_asan_rel_ng;luci.chromium.try:win7_chromium_rel_ng;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:mac_chromium_rel_ng;luci.chromium.try:linux_chromium_tsan_rel_ng;luci.chromium.try:linux_chromium_rel_ng;
Change-Id: I226fd5b6f298fad648b1d05c8a8e806eac874a46
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/182142
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
2019-01-08 14:06:17 +00:00
|
|
|
@param color sRGB unpremultiplied color to write
|
2017-09-21 16:28:43 +00:00
|
|
|
@return true if pixels are changed
|
|
|
|
*/
|
2015-06-08 17:22:22 +00:00
|
|
|
bool erase(SkColor color) const { return this->erase(color, this->bounds()); }
|
2017-09-21 16:28:43 +00:00
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
Reland "Make SkBitmap/SkPixmap::erase* do so in sRGB"
This reverts commit 832c931d5b660d7f0da10a01bd8950a8669de65b.
Reason for revert: To confirm whether it was blocking, and update
Chrome if necessary
Bug: skia:8663
Original change's description:
> Revert "Make SkBitmap/SkPixmap::erase* do so in sRGB"
>
> This reverts commit 6f44647e529924e414ee05462b1ef7b7d1cfb767.
>
> Reason for revert: checking to see if this is blocking the Chrome roll
>
> Original change's description:
> > Make SkBitmap/SkPixmap::erase* do so in sRGB
> >
> > We generally consider untagged colors to be sRGB, so this makes us more
> > consistent with other parts of the API.
> >
> > Add a test.
> >
> > Cq-Include-Trybots: luci.chromium.try:linux-blink-rel
> > Change-Id: I5468c86ad92164797a65ffd9fbe471e01a97a2ca
> > Reviewed-on: https://skia-review.googlesource.com/c/179245
> > Commit-Queue: Leon Scroggins <scroggo@google.com>
> > Reviewed-by: Mike Reed <reed@google.com>
> > Reviewed-by: Mike Klein <mtklein@google.com>
> > Reviewed-by: Brian Osman <brianosman@google.com>
>
> TBR=djsollen@google.com,mtklein@google.com,scroggo@google.com,brianosman@google.com,reed@google.com
>
> Change-Id: Ia592adf2c790d294da1e32c1e83f9f34e81d79cc
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Cq-Include-Trybots: luci.chromium.try:linux-blink-rel
> Reviewed-on: https://skia-review.googlesource.com/c/182083
> Reviewed-by: Robert Phillips <robertphillips@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>
TBR=djsollen@google.com,mtklein@google.com,robertphillips@google.com,scroggo@google.com,brianosman@google.com,reed@google.com
Cq-Include-Trybots: luci.chromium.try:linux-blink-rel;luci.chromium.try:android-kitkat-arm-rel;luci.chromium.try:android-marshmallow-arm64-rel;luci.chromium.try:linux-chromeos-rel;luci.chromium.try:linux_chromium_asan_rel_ng;luci.chromium.try:win7_chromium_rel_ng;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:mac_chromium_rel_ng;luci.chromium.try:linux_chromium_tsan_rel_ng;luci.chromium.try:linux_chromium_rel_ng;
Change-Id: I226fd5b6f298fad648b1d05c8a8e806eac874a46
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/182142
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
2019-01-08 14:06:17 +00:00
|
|
|
@param color sRGB unpremultiplied color to write
|
2017-09-21 16:28:43 +00:00
|
|
|
@param subset bounding integer SkRect of pixels to write; may be nullptr
|
|
|
|
@return true if pixels are changed
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Pixmap_erase_3
|
2017-09-21 16:28:43 +00:00
|
|
|
*/
|
2020-04-24 12:44:50 +00:00
|
|
|
bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const {
|
|
|
|
return this->erase(color, nullptr, subset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@param color unpremultiplied color to write
|
|
|
|
@param cs SkColorSpace of color
|
|
|
|
@param subset bounding integer SkRect of pixels to write; may be nullptr
|
|
|
|
@return true if pixels are changed
|
|
|
|
*/
|
|
|
|
bool erase(const SkColor4f& color, SkColorSpace* cs, const SkIRect* subset = nullptr) const;
|
2015-06-08 17:22:22 +00:00
|
|
|
|
2015-05-22 15:06:21 +00:00
|
|
|
private:
|
|
|
|
const void* fPixels;
|
|
|
|
size_t fRowBytes;
|
|
|
|
SkImageInfo fInfo;
|
2017-12-15 02:13:47 +00:00
|
|
|
|
|
|
|
friend class SkPixmapPriv;
|
2015-05-22 15:06:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|