2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
2018-06-08 15:49:19 +00:00
|
|
|
/* Generated by tools/bookmaker from include/core/SkBitmap.h and docs/SkBitmap_Reference.bmh
|
|
|
|
on 2018-06-08 11:48:28. Additional documentation and examples can be found at:
|
|
|
|
https://skia.org/user/api/SkBitmap_Reference
|
|
|
|
|
|
|
|
You may edit either file directly. Structural changes to public interfaces require
|
|
|
|
editing both files. After editing docs/SkBitmap_Reference.bmh, run:
|
|
|
|
bookmaker -b docs -i include/core/SkBitmap.h -p
|
|
|
|
to create an updated version of this file.
|
|
|
|
*/
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkBitmap_DEFINED
|
|
|
|
#define SkBitmap_DEFINED
|
|
|
|
|
|
|
|
#include "SkColor.h"
|
2013-11-13 19:09:13 +00:00
|
|
|
#include "SkImageInfo.h"
|
2015-05-22 15:06:21 +00:00
|
|
|
#include "SkPixmap.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkPoint.h"
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
|
2014-02-17 21:21:46 +00:00
|
|
|
struct SkMask;
|
2008-12-17 15:59:43 +00:00
|
|
|
struct SkIRect;
|
2012-03-15 21:18:11 +00:00
|
|
|
struct SkRect;
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkPaint;
|
|
|
|
class SkPixelRef;
|
2013-01-15 20:17:47 +00:00
|
|
|
class SkString;
|
2016-07-25 15:29:10 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** \class SkBitmap
|
2017-10-30 15:48:35 +00:00
|
|
|
SkBitmap describes a two-dimensional raster pixel array. SkBitmap is built on
|
|
|
|
SkImageInfo, containing integer width and height, SkColorType and SkAlphaType
|
|
|
|
describing the pixel format, and SkColorSpace describing the range of colors.
|
|
|
|
SkBitmap points to SkPixelRef, which describes the physical array of pixels.
|
|
|
|
SkImageInfo bounds may be located anywhere fully inside SkPixelRef bounds.
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
SkBitmap can be drawn using SkCanvas. SkBitmap can be a drawing destination for SkCanvas
|
2018-05-30 13:20:29 +00:00
|
|
|
draw member functions. SkBitmap flexibility as a pixel container limits some
|
|
|
|
optimizations available to the target platform.
|
2017-03-01 16:16:17 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
If pixel array is primarily read-only, use SkImage for better performance.
|
|
|
|
If pixel array is primarily written to, use SkSurface for better performance.
|
|
|
|
|
|
|
|
Declaring SkBitmap const prevents altering SkImageInfo: the SkBitmap height, width,
|
|
|
|
and so on cannot change. It does not affect SkPixelRef: a caller may write its
|
|
|
|
pixels. Declaring SkBitmap const affects SkBitmap configuration, not its contents.
|
|
|
|
|
|
|
|
SkBitmap is not thread safe. Each thread must have its own copy of SkBitmap fields,
|
|
|
|
although threads may share the underlying pixel array.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2011-03-15 21:27:08 +00:00
|
|
|
class SK_API SkBitmap {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2013-11-25 15:44:37 +00:00
|
|
|
class SK_API Allocator;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Creates an empty SkBitmap without pixels, with kUnknown_SkColorType,
|
|
|
|
kUnknown_SkAlphaType, and with a width and height of zero. SkPixelRef origin is
|
|
|
|
set to (0, 0). SkBitmap is not volatile.
|
|
|
|
|
|
|
|
Use setInfo() to associate SkColorType, SkAlphaType, width, and height
|
|
|
|
after SkBitmap has been created.
|
|
|
|
|
|
|
|
@return empty SkBitmap
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
SkBitmap();
|
2012-05-16 13:04:22 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Copies settings from src to returned SkBitmap. Shares pixels if src has pixels
|
|
|
|
allocated, so both bitmaps reference the same pixels.
|
|
|
|
|
|
|
|
@param src SkBitmap to copy SkImageInfo, and share SkPixelRef
|
|
|
|
@return copy of src
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
SkBitmap(const SkBitmap& src);
|
2012-05-16 13:04:22 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Copies settings from src to returned SkBitmap. Moves ownership of src pixels to
|
|
|
|
SkBitmap.
|
|
|
|
|
|
|
|
@param src SkBitmap to copy SkImageInfo, and reassign SkPixelRef
|
|
|
|
@return copy of src
|
|
|
|
*/
|
2015-12-14 18:19:17 +00:00
|
|
|
SkBitmap(SkBitmap&& src);
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Decrements SkPixelRef reference count, if SkPixelRef is not nullptr.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
~SkBitmap();
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Copies settings from src to returned SkBitmap. Shares pixels if src has pixels
|
|
|
|
allocated, so both bitmaps reference the same pixels.
|
|
|
|
|
|
|
|
@param src SkBitmap to copy SkImageInfo, and share SkPixelRef
|
|
|
|
@return copy of src
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
SkBitmap& operator=(const SkBitmap& src);
|
2015-12-14 18:19:17 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Copies settings from src to returned SkBitmap. Moves ownership of src pixels to
|
|
|
|
SkBitmap.
|
|
|
|
|
|
|
|
@param src SkBitmap to copy SkImageInfo, and reassign SkPixelRef
|
|
|
|
@return copy of src
|
2015-12-14 18:19:17 +00:00
|
|
|
*/
|
|
|
|
SkBitmap& operator=(SkBitmap&& src);
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Swaps the fields of the two bitmaps.
|
|
|
|
|
|
|
|
@param other SkBitmap exchanged with original
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
void swap(SkBitmap& other);
|
2009-05-03 18:23:30 +00:00
|
|
|
|
2017-12-15 02:13:47 +00:00
|
|
|
/** Returns a constant reference to the SkPixmap holding the SkBitmap pixel
|
|
|
|
address, row bytes, and SkImageInfo.
|
2017-12-14 20:33:23 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@return reference to SkPixmap describing this SkBitmap
|
2017-12-14 20:33:23 +00:00
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
const SkPixmap& pixmap() const { return fPixmap; }
|
2017-12-14 20:33:23 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns width, height, SkAlphaType, SkColorType, and SkColorSpace.
|
2014-02-11 18:21:45 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
@return reference to SkImageInfo
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
const SkImageInfo& info() const { return fPixmap.info(); }
|
2014-02-11 18:21:45 +00:00
|
|
|
|
2018-01-03 15:00:34 +00:00
|
|
|
/** Returns pixel count in each row. Should be equal or less than:
|
2017-10-30 15:48:35 +00:00
|
|
|
rowBytes() / info().bytesPerPixel().
|
|
|
|
|
|
|
|
Maybe be less than pixelRef().width(). Will not exceed pixelRef().width() less
|
|
|
|
pixelRefOrigin().fX.
|
|
|
|
|
|
|
|
@return pixel width in SkImageInfo
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
int width() const { return fPixmap.width(); }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns pixel row count.
|
|
|
|
|
|
|
|
Maybe be less than pixelRef().height(). Will not exceed pixelRef().height() less
|
|
|
|
pixelRefOrigin().fY.
|
|
|
|
|
|
|
|
@return pixel height in SkImageInfo
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
int height() const { return fPixmap.height(); }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
/** Returns SkColorType, 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.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@return SkColorType in SkImageInfo
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
SkColorType colorType() const { return fPixmap.colorType(); }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
/** Returns SkAlphaType, one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_SkAlphaType.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@return SkAlphaType in SkImageInfo
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
SkAlphaType alphaType() const { return fPixmap.alphaType(); }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns SkColorSpace, the range of colors, associated with SkImageInfo. The
|
|
|
|
reference count of SkColorSpace is unchanged. The returned SkColorSpace is
|
|
|
|
immutable.
|
|
|
|
|
2018-01-03 15:00:34 +00:00
|
|
|
@return SkColorSpace in SkImageInfo, or nullptr
|
2017-10-30 15:48:35 +00:00
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
SkColorSpace* colorSpace() const { return fPixmap.colorSpace(); }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
/** Returns smart pointer to SkColorSpace, the range of colors, associated with
|
2017-10-30 15:48:35 +00:00
|
|
|
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
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
sk_sp<SkColorSpace> refColorSpace() const { return fPixmap.info().refColorSpace(); }
|
2014-02-11 18:21:45 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns number of bytes per pixel required by SkColorType.
|
|
|
|
Returns zero if colorType( is kUnknown_SkColorType.
|
|
|
|
|
|
|
|
@return bytes in pixel
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
int bytesPerPixel() const { return fPixmap.info().bytesPerPixel(); }
|
2014-02-11 18:21:45 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns number of pixels that fit on row. Should be greater than or equal to
|
|
|
|
width().
|
|
|
|
|
|
|
|
@return maximum pixels per row
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
int rowBytesAsPixels() const { return fPixmap.rowBytesAsPixels(); }
|
2014-02-11 18:21:45 +00:00
|
|
|
|
2017-10-30 15:48:35 +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
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
int shiftPerPixel() const { return fPixmap.shiftPerPixel(); }
|
2014-02-11 18:21:45 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if either width() or height() are zero.
|
|
|
|
|
|
|
|
Does not check if SkPixelRef is nullptr; call drawsNothing() to check width(),
|
|
|
|
height(), and SkPixelRef.
|
2014-02-11 18:21:45 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
@return true if dimensions do not enclose area
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
bool empty() const { return fPixmap.info().isEmpty(); }
|
2009-05-03 18:23:30 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Return true if SkPixelRef is nullptr.
|
|
|
|
|
|
|
|
Does not check if width() or height() are zero; call drawsNothing() to check
|
|
|
|
width(), height(), and SkPixelRef.
|
|
|
|
|
|
|
|
@return true if no SkPixelRef is associated
|
|
|
|
*/
|
2016-12-12 18:48:12 +00:00
|
|
|
bool isNull() const { return nullptr == fPixelRef; }
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Return true if width() or height() are zero, or if SkPixelRef is nullptr.
|
|
|
|
If true, SkBitmap has no effect when drawn or drawn into.
|
|
|
|
|
|
|
|
@return true if drawing has no effect
|
|
|
|
*/
|
2017-07-02 19:46:49 +00:00
|
|
|
bool drawsNothing() const {
|
2017-07-13 02:10:29 +00:00
|
|
|
return this->empty() || this->isNull();
|
2017-07-02 19:46:49 +00:00
|
|
|
}
|
2014-02-10 18:29:10 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** 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, or if row bytes supplied to
|
|
|
|
setInfo() is not large enough to hold a row of pixels.
|
|
|
|
|
|
|
|
@return byte length of pixel row
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
size_t rowBytes() const { return fPixmap.rowBytes(); }
|
2009-05-03 18:23:30 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkAlphaType, if alphaType is compatible with SkColorType.
|
|
|
|
Returns true unless alphaType is kUnknown_SkAlphaType and current SkAlphaType
|
|
|
|
is not kUnknown_SkAlphaType.
|
|
|
|
|
|
|
|
Returns true if SkColorType is kUnknown_SkColorType. alphaType is ignored, and
|
|
|
|
SkAlphaType remains kUnknown_SkAlphaType.
|
|
|
|
|
|
|
|
Returns true if SkColorType is kRGB_565_SkColorType or kGray_8_SkColorType.
|
|
|
|
alphaType is ignored, and SkAlphaType remains kOpaque_SkAlphaType.
|
|
|
|
|
|
|
|
If SkColorType is kARGB_4444_SkColorType, kRGBA_8888_SkColorType,
|
|
|
|
kBGRA_8888_SkColorType, or kRGBA_F16_SkColorType: returns true unless
|
|
|
|
alphaType is kUnknown_SkAlphaType and SkAlphaType is not kUnknown_SkAlphaType.
|
|
|
|
If SkAlphaType is kUnknown_SkAlphaType, alphaType is ignored.
|
|
|
|
|
|
|
|
If SkColorType is kAlpha_8_SkColorType, returns true unless
|
|
|
|
alphaType is kUnknown_SkAlphaType and SkAlphaType is not kUnknown_SkAlphaType.
|
|
|
|
If SkAlphaType is kUnknown_SkAlphaType, alphaType is ignored. If alphaType is
|
|
|
|
kUnpremul_SkAlphaType, it is treated as kPremul_SkAlphaType.
|
|
|
|
|
|
|
|
This changes SkAlphaType in SkPixelRef; all bitmaps sharing SkPixelRef
|
|
|
|
are affected.
|
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
@param alphaType one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_SkAlphaType
|
2017-10-30 15:48:35 +00:00
|
|
|
@return true if SkAlphaType is set
|
|
|
|
*/
|
2017-10-04 14:56:37 +00:00
|
|
|
bool setAlphaType(SkAlphaType alphaType);
|
2013-10-21 14:00:07 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns pixel address, the base address corresponding to the pixel origin.
|
|
|
|
|
|
|
|
@return pixel address
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
void* getPixels() const { return fPixmap.writable_addr(); }
|
2008-12-17 15:59:43 +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().
|
|
|
|
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 size in bytes of image buffer
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
size_t computeByteSize() const { return fPixmap.computeByteSize(); }
|
2017-09-29 17:41:58 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if pixels can not change.
|
|
|
|
|
|
|
|
Most immutable SkBitmap checks trigger an assert only on debug builds.
|
|
|
|
|
|
|
|
@return true if pixels are immutable
|
2011-12-15 20:14:06 +00:00
|
|
|
*/
|
|
|
|
bool isImmutable() const;
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets internal flag to mark SkBitmap as immutable. Once set, pixels can not change.
|
|
|
|
Any other bitmap sharing the same SkPixelRef are also marked as immutable.
|
|
|
|
Once SkPixelRef is marked immutable, the setting cannot be cleared.
|
|
|
|
|
|
|
|
Writing to immutable SkBitmap pixels triggers an assert on debug builds.
|
2011-12-15 20:14:06 +00:00
|
|
|
*/
|
|
|
|
void setImmutable();
|
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
/** Returns true if SkAlphaType is set to hint that all pixels are opaque; their
|
2018-05-30 13:20:29 +00:00
|
|
|
alpha value is implicitly or explicitly 1.0. If true, and all pixels are
|
2018-04-03 15:49:10 +00:00
|
|
|
not opaque, Skia may draw incorrectly.
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
Does not check if SkColorType allows alpha, or if any pixel value has
|
|
|
|
transparency.
|
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
@return true if SkImageInfo SkAlphaType is kOpaque_SkAlphaType
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2013-10-21 14:00:07 +00:00
|
|
|
bool isOpaque() const {
|
|
|
|
return SkAlphaTypeIsOpaque(this->alphaType());
|
|
|
|
}
|
2011-06-30 17:30:49 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** If true, provides a hint to caller that pixels should not
|
|
|
|
be cached. Only true if setIsVolatile() has been called to mark as volatile.
|
|
|
|
|
|
|
|
Volatile state is not shared by other bitmaps sharing the same SkPixelRef.
|
|
|
|
|
|
|
|
@return true if marked volatile
|
2011-06-30 17:30:49 +00:00
|
|
|
*/
|
|
|
|
bool isVolatile() const;
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets if pixels should be read from SkPixelRef on every access. SkBitmap are not
|
|
|
|
volatile by default; a GPU back end may upload pixel values expecting them to be
|
|
|
|
accessed repeatedly. Marking temporary SkBitmap as volatile provides a hint to
|
|
|
|
SkBaseDevice that the SkBitmap pixels should not be cached. This can
|
|
|
|
improve performance by avoiding overhead and reducing resource
|
|
|
|
consumption on SkBaseDevice.
|
|
|
|
|
|
|
|
@param isVolatile true if backing pixels are temporary
|
2011-06-30 17:30:49 +00:00
|
|
|
*/
|
2017-10-04 14:56:37 +00:00
|
|
|
void setIsVolatile(bool isVolatile);
|
2011-06-30 17:30:49 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Resets to its initial state; all fields are set to zero, as if SkBitmap had
|
|
|
|
been initialized by SkBitmap().
|
|
|
|
|
|
|
|
Sets width, height, row bytes to zero; pixel address to nullptr; SkColorType to
|
|
|
|
kUnknown_SkColorType; and SkAlphaType to kUnknown_SkAlphaType.
|
|
|
|
|
|
|
|
If SkPixelRef is allocated, its reference count is decreased by one, releasing
|
|
|
|
its memory if SkBitmap is the sole owner.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
void reset();
|
|
|
|
|
2017-10-30 15:48:35 +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
|
|
|
|
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.
|
|
|
|
|
|
|
|
@param bm SkBitmap to check
|
|
|
|
@return true if all pixels have opaque values or SkColorType is opaque
|
|
|
|
*/
|
2016-12-07 20:24:59 +00:00
|
|
|
static bool ComputeIsOpaque(const SkBitmap& bm) {
|
2017-12-14 20:33:23 +00:00
|
|
|
return bm.pixmap().computeIsOpaque();
|
2016-12-07 20:24:59 +00:00
|
|
|
}
|
2012-11-07 18:30:18 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns SkRect { 0, 0, width(), height() }.
|
|
|
|
|
|
|
|
@param bounds container for floating point rectangle
|
|
|
|
*/
|
2012-03-15 21:17:03 +00:00
|
|
|
void getBounds(SkRect* bounds) const;
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns SkIRect { 0, 0, width(), height() }.
|
|
|
|
|
|
|
|
@param bounds container for integral rectangle
|
|
|
|
*/
|
2012-03-16 14:58:07 +00:00
|
|
|
void getBounds(SkIRect* bounds) const;
|
2012-03-15 21:17:03 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns SkIRect { 0, 0, width(), height() }.
|
|
|
|
|
|
|
|
@return integral rectangle from origin to width() and height()
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
SkIRect bounds() const { return fPixmap.info().bounds(); }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns SkISize { width(), height() }.
|
|
|
|
|
|
|
|
@return integral size of width() and height()
|
|
|
|
*/
|
2017-12-15 02:13:47 +00:00
|
|
|
SkISize dimensions() const { return fPixmap.info().dimensions(); }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns the bounds of this bitmap, offset by its SkPixelRef origin.
|
|
|
|
|
|
|
|
@return bounds within SkPixelRef bounds
|
|
|
|
*/
|
2015-09-10 21:33:38 +00:00
|
|
|
SkIRect getSubset() const {
|
2018-01-05 04:04:23 +00:00
|
|
|
SkIPoint origin = this->pixelRefOrigin();
|
|
|
|
return SkIRect::MakeXYWH(origin.x(), origin.y(), this->width(), this->height());
|
2015-09-10 21:33:38 +00:00
|
|
|
}
|
2014-10-24 19:54:53 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets width, height, SkAlphaType, SkColorType, SkColorSpace, and optional
|
|
|
|
rowBytes. Frees pixels, and returns true if successful.
|
|
|
|
|
|
|
|
imageInfo.alphaType() may be altered to a value permitted by imageInfo.colorSpace().
|
|
|
|
If imageInfo.colorType() is kUnknown_SkColorType, imageInfo.alphaType() is
|
|
|
|
set to kUnknown_SkAlphaType.
|
|
|
|
If imageInfo.colorType() is kAlpha_8_SkColorType and imageInfo.alphaType() is
|
|
|
|
kUnpremul_SkAlphaType, imageInfo.alphaType() is replaced by kPremul_SkAlphaType.
|
|
|
|
If imageInfo.colorType() is kRGB_565_SkColorType or kGray_8_SkColorType,
|
|
|
|
imageInfo.alphaType() is set to kOpaque_SkAlphaType.
|
|
|
|
If imageInfo.colorType() is kARGB_4444_SkColorType, kRGBA_8888_SkColorType,
|
|
|
|
kBGRA_8888_SkColorType, or kRGBA_F16_SkColorType: imageInfo.alphaType() remains
|
|
|
|
unchanged.
|
|
|
|
|
|
|
|
rowBytes must equal or exceed imageInfo.minRowBytes(). If imageInfo.colorSpace() is
|
|
|
|
kUnknown_SkColorType, rowBytes is ignored and treated as zero; for all other
|
|
|
|
SkColorSpace values, rowBytes of zero is treated as imageInfo.minRowBytes().
|
|
|
|
|
|
|
|
Calls reset() and returns false if:
|
|
|
|
- rowBytes exceeds 31 bits
|
|
|
|
- imageInfo.width() is negative
|
|
|
|
- imageInfo.height() is negative
|
|
|
|
- rowBytes is positive and less than imageInfo.width() times imageInfo.bytesPerPixel()
|
|
|
|
|
|
|
|
@param imageInfo contains width, height, SkAlphaType, SkColorType, SkColorSpace
|
|
|
|
@param rowBytes imageInfo.minRowBytes or larger; or zero
|
|
|
|
@return true if SkImageInfo set successfully
|
|
|
|
*/
|
2017-09-21 16:36:48 +00:00
|
|
|
bool setInfo(const SkImageInfo& imageInfo, size_t rowBytes = 0);
|
2014-05-30 13:26:10 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** \enum SkBitmap::AllocFlags
|
|
|
|
AllocFlags provides the option to zero pixel memory when allocated.
|
|
|
|
*/
|
2017-04-03 18:41:44 +00:00
|
|
|
enum AllocFlags {
|
2018-05-30 13:20:29 +00:00
|
|
|
kZeroPixels_AllocFlag = 1 << 0, //!< zero pixel memory
|
2017-04-03 18:41:44 +00:00
|
|
|
};
|
2017-07-18 14:53:11 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkImageInfo to info following the rules in setInfo() and allocates pixel
|
|
|
|
memory. If flags is kZeroPixels_AllocFlag, memory is zeroed.
|
|
|
|
|
|
|
|
Returns false and calls reset() if SkImageInfo could not be set, or memory could
|
2018-01-03 15:00:34 +00:00
|
|
|
not be allocated, or memory could not optionally be zeroed.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
On most platforms, allocating pixel memory may succeed even though there is
|
|
|
|
not sufficient memory to hold pixels; allocation does not take place
|
|
|
|
until the pixels are written to. The actual behavior depends on the platform
|
|
|
|
implementation of malloc(), if flags is zero, and calloc(), if flags is
|
|
|
|
kZeroPixels_AllocFlag.
|
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
flags set to kZeroPixels_AllocFlag offers equal or better performance than
|
|
|
|
subsequently calling eraseColor() with SK_ColorTRANSPARENT.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@param info contains width, height, SkAlphaType, SkColorType, SkColorSpace
|
|
|
|
@param flags kZeroPixels_AllocFlag, or zero
|
|
|
|
@return true if pixels allocation is successful
|
|
|
|
*/
|
2017-07-18 14:53:11 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT tryAllocPixelsFlags(const SkImageInfo& info, uint32_t flags);
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Sets SkImageInfo to info following the rules in setInfo() and allocates pixel
|
|
|
|
memory. If flags is kZeroPixels_AllocFlag, memory is zeroed.
|
|
|
|
|
|
|
|
Aborts execution if SkImageInfo could not be set, or memory could
|
2018-01-03 15:00:34 +00:00
|
|
|
not be allocated, or memory could not optionally
|
2017-10-30 15:48:35 +00:00
|
|
|
be zeroed. Abort steps may be provided by the user at compile time by defining
|
|
|
|
SK_ABORT.
|
|
|
|
|
|
|
|
On most platforms, allocating pixel memory may succeed even though there is
|
|
|
|
not sufficient memory to hold pixels; allocation does not take place
|
|
|
|
until the pixels are written to. The actual behavior depends on the platform
|
|
|
|
implementation of malloc(), if flags is zero, and calloc(), if flags is
|
|
|
|
kZeroPixels_AllocFlag.
|
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
flags set to kZeroPixels_AllocFlag offers equal or better performance than
|
|
|
|
subsequently calling eraseColor() with SK_ColorTRANSPARENT.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@param info contains width, height, SkAlphaType, SkColorType, SkColorSpace
|
|
|
|
@param flags kZeroPixels_AllocFlag, or zero
|
|
|
|
*/
|
2017-07-18 14:53:11 +00:00
|
|
|
void allocPixelsFlags(const SkImageInfo& info, uint32_t flags) {
|
2017-08-17 18:05:04 +00:00
|
|
|
SkASSERT_RELEASE(this->tryAllocPixelsFlags(info, flags));
|
2014-09-02 19:50:45 +00:00
|
|
|
}
|
2014-01-25 07:01:49 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkImageInfo to info following the rules in setInfo() and allocates pixel
|
|
|
|
memory. rowBytes must equal or exceed info.width() times info.bytesPerPixel(),
|
|
|
|
or equal zero. Pass in zero for rowBytes to compute the minimum valid value.
|
|
|
|
|
|
|
|
Returns false and calls reset() if SkImageInfo could not be set, or memory could
|
|
|
|
not be allocated.
|
|
|
|
|
|
|
|
On most platforms, allocating pixel memory may succeed even though there is
|
|
|
|
not sufficient memory to hold pixels; allocation does not take place
|
|
|
|
until the pixels are written to. The actual behavior depends on the platform
|
|
|
|
implementation of malloc().
|
|
|
|
|
|
|
|
@param info contains width, height, SkAlphaType, SkColorType, SkColorSpace
|
|
|
|
@param rowBytes size of pixel row or larger; may be zero
|
|
|
|
@return true if pixel storage is allocated
|
|
|
|
*/
|
2014-09-02 19:50:45 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info, size_t rowBytes);
|
2014-06-28 21:26:35 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkImageInfo to info following the rules in setInfo() and allocates pixel
|
|
|
|
memory. rowBytes must equal or exceed info.width() times info.bytesPerPixel(),
|
|
|
|
or equal zero. Pass in zero for rowBytes to compute the minimum valid value.
|
|
|
|
|
|
|
|
Aborts execution if SkImageInfo could not be set, or memory could
|
2018-01-03 15:00:34 +00:00
|
|
|
not be allocated. Abort steps may be provided by
|
2017-10-30 15:48:35 +00:00
|
|
|
the user at compile time by defining SK_ABORT.
|
|
|
|
|
|
|
|
On most platforms, allocating pixel memory may succeed even though there is
|
|
|
|
not sufficient memory to hold pixels; allocation does not take place
|
|
|
|
until the pixels are written to. The actual behavior depends on the platform
|
|
|
|
implementation of malloc().
|
|
|
|
|
|
|
|
@param info contains width, height, SkAlphaType, SkColorType, SkColorSpace
|
|
|
|
@param rowBytes size of pixel row or larger; may be zero
|
|
|
|
*/
|
2014-12-18 20:48:16 +00:00
|
|
|
void allocPixels(const SkImageInfo& info, size_t rowBytes) {
|
2017-08-17 18:05:04 +00:00
|
|
|
SkASSERT_RELEASE(this->tryAllocPixels(info, rowBytes));
|
2014-09-02 19:50:45 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkImageInfo to info following the rules in setInfo() and allocates pixel
|
|
|
|
memory.
|
|
|
|
|
|
|
|
Returns false and calls reset() if SkImageInfo could not be set, or memory could
|
|
|
|
not be allocated.
|
|
|
|
|
|
|
|
On most platforms, allocating pixel memory may succeed even though there is
|
|
|
|
not sufficient memory to hold pixels; allocation does not take place
|
|
|
|
until the pixels are written to. The actual behavior depends on the platform
|
|
|
|
implementation of malloc().
|
|
|
|
|
|
|
|
@param info contains width, height, SkAlphaType, SkColorType, SkColorSpace
|
|
|
|
@return true if pixel storage is allocated
|
|
|
|
*/
|
2014-09-02 19:50:45 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info) {
|
|
|
|
return this->tryAllocPixels(info, info.minRowBytes());
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkImageInfo to info following the rules in setInfo() and allocates pixel
|
|
|
|
memory.
|
|
|
|
|
|
|
|
Aborts execution if SkImageInfo could not be set, or memory could
|
2018-01-03 15:00:34 +00:00
|
|
|
not be allocated. Abort steps may be provided by
|
2017-10-30 15:48:35 +00:00
|
|
|
the user at compile time by defining SK_ABORT.
|
|
|
|
|
|
|
|
On most platforms, allocating pixel memory may succeed even though there is
|
|
|
|
not sufficient memory to hold pixels; allocation does not take place
|
|
|
|
until the pixels are written to. The actual behavior depends on the platform
|
|
|
|
implementation of malloc().
|
|
|
|
|
|
|
|
@param info contains width, height, SkAlphaType, SkColorType, SkColorSpace
|
|
|
|
*/
|
2014-12-18 20:48:16 +00:00
|
|
|
void allocPixels(const SkImageInfo& info) {
|
|
|
|
this->allocPixels(info, info.minRowBytes());
|
2014-01-24 18:53:42 +00:00
|
|
|
}
|
2014-01-25 07:01:49 +00:00
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
/** Sets SkImageInfo to width, height, and native color type; and allocates
|
2017-10-30 15:48:35 +00:00
|
|
|
pixel memory. If isOpaque is true, sets SkImageInfo to kOpaque_SkAlphaType;
|
|
|
|
otherwise, sets to kPremul_SkAlphaType.
|
|
|
|
|
|
|
|
Calls reset() and returns false if width exceeds 29 bits or is negative,
|
|
|
|
or height is negative.
|
|
|
|
|
|
|
|
Returns false if allocation fails.
|
|
|
|
|
2018-01-03 15:00:34 +00:00
|
|
|
Use to create SkBitmap that matches SkPMColor, the native pixel arrangement on
|
|
|
|
the platform. SkBitmap drawn to output device skips converting its pixel format.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@param width pixel column count; must be zero or greater
|
|
|
|
@param height pixel row count; must be zero or greater
|
|
|
|
@param isOpaque true if pixels do not have transparency
|
|
|
|
@return true if pixel storage is allocated
|
|
|
|
*/
|
2014-09-02 19:50:45 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isOpaque = false) {
|
2014-09-03 18:54:58 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32(width, height,
|
|
|
|
isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
|
2014-09-02 19:50:45 +00:00
|
|
|
return this->tryAllocPixels(info);
|
|
|
|
}
|
2014-12-02 17:11:25 +00:00
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
/** Sets SkImageInfo to width, height, and the native color type; and allocates
|
2017-10-30 15:48:35 +00:00
|
|
|
pixel memory. If isOpaque is true, sets SkImageInfo to kPremul_SkAlphaType;
|
|
|
|
otherwise, sets to kOpaque_SkAlphaType.
|
|
|
|
|
|
|
|
Aborts if width exceeds 29 bits or is negative, or height is negative, or
|
|
|
|
allocation fails. Abort steps may be provided by the user at compile time by
|
|
|
|
defining SK_ABORT.
|
|
|
|
|
2018-01-03 15:00:34 +00:00
|
|
|
Use to create SkBitmap that matches SkPMColor, the native pixel arrangement on
|
|
|
|
the platform. SkBitmap drawn to output device skips converting its pixel format.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@param width pixel column count; must be zero or greater
|
|
|
|
@param height pixel row count; must be zero or greater
|
|
|
|
@param isOpaque true if pixels do not have transparency
|
|
|
|
*/
|
2014-12-18 20:48:16 +00:00
|
|
|
void allocN32Pixels(int width, int height, bool isOpaque = false) {
|
2014-09-03 18:54:58 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32(width, height,
|
|
|
|
isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
|
2014-12-18 20:48:16 +00:00
|
|
|
this->allocPixels(info);
|
2014-01-25 16:46:20 +00:00
|
|
|
}
|
2014-12-02 17:11:25 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkImageInfo to info following the rules in setInfo(), and creates SkPixelRef
|
|
|
|
containing pixels and rowBytes. releaseProc, if not nullptr, is called
|
|
|
|
immediately on failure or when pixels are no longer referenced. context may be
|
|
|
|
nullptr.
|
|
|
|
|
|
|
|
If SkImageInfo could not be set, or rowBytes is less than info.minRowBytes():
|
|
|
|
calls releaseProc if present, calls reset(), and returns false.
|
|
|
|
|
|
|
|
Otherwise, if pixels equals nullptr: sets SkImageInfo, calls releaseProc if
|
|
|
|
present, returns true.
|
|
|
|
|
|
|
|
If SkImageInfo is set, pixels is not nullptr, and releaseProc is not nullptr:
|
|
|
|
when pixels are no longer referenced, calls releaseProc with pixels and context
|
|
|
|
as parameters.
|
|
|
|
|
|
|
|
@param info contains width, height, SkAlphaType, SkColorType, SkColorSpace
|
|
|
|
@param pixels address or pixel storage; may be nullptr
|
|
|
|
@param rowBytes size of pixel row or larger
|
|
|
|
@param releaseProc function called when pixels can be deleted; may be nullptr
|
|
|
|
@param context caller state passed to releaseProc; may be nullptr
|
|
|
|
@return true if SkImageInfo is set to info
|
|
|
|
*/
|
2017-09-21 16:36:48 +00:00
|
|
|
bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
2014-05-29 15:57:20 +00:00
|
|
|
void (*releaseProc)(void* addr, void* context), void* context);
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkImageInfo to info following the rules in setInfo(), and creates SkPixelRef
|
|
|
|
containing pixels and rowBytes.
|
|
|
|
|
|
|
|
If SkImageInfo could not be set, or rowBytes is less than info.minRowBytes():
|
|
|
|
calls reset(), and returns false.
|
|
|
|
|
|
|
|
Otherwise, if pixels equals nullptr: sets SkImageInfo, returns true.
|
|
|
|
|
|
|
|
Caller must ensure that pixels are valid for the lifetime of SkBitmap and SkPixelRef.
|
|
|
|
|
|
|
|
@param info contains width, height, SkAlphaType, SkColorType, SkColorSpace
|
|
|
|
@param pixels address or pixel storage; may be nullptr
|
|
|
|
@param rowBytes size of pixel row or larger
|
|
|
|
@return true if SkImageInfo is set to info
|
|
|
|
*/
|
2014-02-17 21:21:46 +00:00
|
|
|
bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) {
|
2017-07-18 14:53:11 +00:00
|
|
|
return this->installPixels(info, pixels, rowBytes, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkImageInfo to pixmap.info() following the rules in setInfo(), and creates
|
|
|
|
SkPixelRef containing pixmap.addr() and pixmap.rowBytes().
|
|
|
|
|
|
|
|
If SkImageInfo could not be set, or pixmap.rowBytes() is less than
|
|
|
|
SkImageInfo::minRowBytes: calls reset(), and returns false.
|
|
|
|
|
|
|
|
Otherwise, if pixmap.addr() equals nullptr: sets SkImageInfo, returns true.
|
|
|
|
|
|
|
|
Caller must ensure that pixmap is valid for the lifetime of SkBitmap and SkPixelRef.
|
|
|
|
|
|
|
|
@param pixmap SkImageInfo, pixel address, and rowBytes()
|
|
|
|
@return true if SkImageInfo was set to pixmap.info()
|
|
|
|
*/
|
2017-09-21 16:36:48 +00:00
|
|
|
bool installPixels(const SkPixmap& pixmap);
|
2015-12-09 19:36:59 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** To be deprecated soon.
|
2017-10-30 15:48:35 +00:00
|
|
|
*/
|
2017-09-21 16:36:48 +00:00
|
|
|
bool installMaskPixels(const SkMask& mask);
|
2014-01-25 07:01:49 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Replaces SkPixelRef with pixels, preserving SkImageInfo and rowBytes().
|
|
|
|
Sets SkPixelRef origin to (0, 0).
|
|
|
|
|
|
|
|
If pixels is nullptr, or if info().colorType equals kUnknown_SkColorType;
|
|
|
|
release reference to SkPixelRef, and set SkPixelRef to nullptr.
|
2009-05-03 18:23:30 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
Caller is responsible for handling ownership pixel memory for the lifetime
|
|
|
|
of SkBitmap and SkPixelRef.
|
|
|
|
|
|
|
|
@param pixels address of pixel storage, managed by caller
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2017-09-21 16:36:48 +00:00
|
|
|
void setPixels(void* pixels);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Allocates pixel memory with HeapAllocator, and replaces existing SkPixelRef.
|
|
|
|
The allocation size is determined by SkImageInfo width, height, and SkColorType.
|
|
|
|
|
2018-01-03 15:00:34 +00:00
|
|
|
Returns false if info().colorType is kUnknown_SkColorType, or allocation fails.
|
2009-05-03 18:23:30 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
@return true if the allocation succeeds
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2017-07-18 14:53:11 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT tryAllocPixels() {
|
|
|
|
return this->tryAllocPixels((Allocator*)nullptr);
|
2014-09-02 19:50:45 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Allocates pixel memory with HeapAllocator, and replaces existing SkPixelRef.
|
|
|
|
The allocation size is determined by SkImageInfo width, height, and SkColorType.
|
|
|
|
|
2018-01-03 15:00:34 +00:00
|
|
|
Aborts if info().colorType is kUnknown_SkColorType, or allocation fails.
|
|
|
|
Abort steps may be provided by the user at compile
|
2017-10-30 15:48:35 +00:00
|
|
|
time by defining SK_ABORT.
|
|
|
|
*/
|
2017-07-18 14:53:11 +00:00
|
|
|
void allocPixels() {
|
|
|
|
this->allocPixels((Allocator*)nullptr);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2009-05-03 18:23:30 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Allocates pixel memory with allocator, and replaces existing SkPixelRef.
|
|
|
|
The allocation size is determined by SkImageInfo width, height, and SkColorType.
|
|
|
|
If allocator is nullptr, use HeapAllocator instead.
|
2009-05-03 18:23:30 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns false if Allocator::allocPixelRef return false.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@param allocator instance of SkBitmap::Allocator instantiation
|
|
|
|
@return true if custom allocator reports success
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2017-07-18 14:53:11 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT tryAllocPixels(Allocator* allocator);
|
2014-09-02 19:50:45 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Allocates pixel memory with allocator, and replaces existing SkPixelRef.
|
|
|
|
The allocation size is determined by SkImageInfo width, height, and SkColorType.
|
|
|
|
If allocator is nullptr, use HeapAllocator instead.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Aborts if Allocator::allocPixelRef return false. Abort steps may be provided by
|
2017-10-30 15:48:35 +00:00
|
|
|
the user at compile time by defining SK_ABORT.
|
|
|
|
|
|
|
|
@param allocator instance of SkBitmap::Allocator instantiation
|
|
|
|
*/
|
2017-07-18 14:53:11 +00:00
|
|
|
void allocPixels(Allocator* allocator) {
|
2017-08-17 18:05:04 +00:00
|
|
|
SkASSERT_RELEASE(this->tryAllocPixels(allocator));
|
2014-09-02 19:50:45 +00:00
|
|
|
}
|
2009-05-03 18:23:30 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns SkPixelRef, which contains: pixel base address; its dimensions; and
|
|
|
|
rowBytes(), the interval from one row to the next. Does not change SkPixelRef
|
|
|
|
reference count. SkPixelRef may be shared by multiple bitmaps.
|
|
|
|
If SkPixelRef has not been set, returns nullptr.
|
|
|
|
|
|
|
|
@return SkPixelRef, or nullptr
|
|
|
|
*/
|
2016-12-12 18:48:12 +00:00
|
|
|
SkPixelRef* pixelRef() const { return fPixelRef.get(); }
|
2014-01-08 15:42:01 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns origin of pixels within SkPixelRef. SkBitmap bounds is always contained
|
|
|
|
by SkPixelRef bounds, which may be the same size or larger. Multiple SkBitmap
|
|
|
|
can share the same SkPixelRef, where each SkBitmap has different bounds.
|
|
|
|
|
|
|
|
The returned origin added to SkBitmap dimensions equals or is smaller than the
|
|
|
|
SkPixelRef dimensions.
|
|
|
|
|
|
|
|
Returns (0, 0) if SkPixelRef is nullptr.
|
|
|
|
|
|
|
|
@return pixel origin within SkPixelRef
|
|
|
|
*/
|
2018-01-05 04:04:23 +00:00
|
|
|
SkIPoint pixelRefOrigin() const;
|
2014-01-08 15:42:01 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Replaces pixelRef and origin in SkBitmap. dx and dy specify the offset
|
|
|
|
within the SkPixelRef pixels for the top-left corner of the bitmap.
|
|
|
|
|
|
|
|
Asserts in debug builds if dx or dy are out of range. Pins dx and dy
|
|
|
|
to legal range in release builds.
|
|
|
|
|
|
|
|
The caller is responsible for ensuring that the pixels match the
|
|
|
|
SkColorType and SkAlphaType in SkImageInfo.
|
|
|
|
|
|
|
|
@param pixelRef SkPixelRef describing pixel address and rowBytes()
|
|
|
|
@param dx column offset in SkPixelRef for bitmap origin
|
|
|
|
@param dy row offset in SkPixelRef for bitmap origin
|
|
|
|
*/
|
2017-09-21 16:36:48 +00:00
|
|
|
void setPixelRef(sk_sp<SkPixelRef> pixelRef, int dx, int dy);
|
2016-12-12 18:48:12 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if SkBitmap is can be drawn.
|
|
|
|
|
|
|
|
@return true if getPixels() is not nullptr
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
bool readyToDraw() const {
|
2017-08-28 14:34:05 +00:00
|
|
|
return this->getPixels() != nullptr;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns a unique value corresponding to the pixels in SkPixelRef.
|
|
|
|
Returns a different value after notifyPixelsChanged() has been called.
|
|
|
|
Returns zero if SkPixelRef is nullptr.
|
|
|
|
|
|
|
|
Determines if pixels have changed since last examined.
|
|
|
|
|
|
|
|
@return unique value for pixels in SkPixelRef
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
uint32_t getGenerationID() const;
|
2009-05-03 18:23:30 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Marks that pixels in SkPixelRef have changed. Subsequent calls to
|
|
|
|
getGenerationID() return a different value.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
void notifyPixelsChanged() const;
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Replaces pixel values with c. All pixels contained by bounds() are affected.
|
2018-05-30 13:20:29 +00:00
|
|
|
If the colorType() is kGray_8_SkColorType or k565_SkColorType, then alpha
|
2017-10-30 15:48:35 +00:00
|
|
|
is ignored; RGB is treated as opaque. If colorType() is kAlpha_8_SkColorType,
|
|
|
|
then RGB is ignored.
|
|
|
|
|
|
|
|
@param c unpremultiplied color
|
|
|
|
*/
|
2015-06-08 17:22:22 +00:00
|
|
|
void eraseColor(SkColor c) const;
|
2009-05-03 18:23:30 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Replaces pixel values with unpremultiplied color built from a, r, g, and b.
|
|
|
|
All pixels contained by bounds() are affected.
|
|
|
|
If the colorType() is kGray_8_SkColorType or k565_SkColorType, then a
|
|
|
|
is ignored; r, g, and b are treated as opaque. If colorType() is kAlpha_8_SkColorType,
|
|
|
|
then r, g, and b are ignored.
|
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
@param a amount of alpha, from fully transparent (0) to fully opaque (255)
|
|
|
|
@param r amount of red, from no red (0) to full red (255)
|
|
|
|
@param g amount of green, from no green (0) to full green (255)
|
|
|
|
@param b amount of blue, from no blue (0) to full blue (255)
|
2017-10-30 15:48:35 +00:00
|
|
|
*/
|
2015-06-08 17:22:22 +00:00
|
|
|
void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const {
|
|
|
|
this->eraseColor(SkColorSetARGB(a, r, g, b));
|
|
|
|
}
|
2013-06-28 19:40:50 +00:00
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
/** Deprecated.
|
2017-10-30 15:48:35 +00:00
|
|
|
*/
|
2013-10-31 17:28:30 +00:00
|
|
|
SK_ATTR_DEPRECATED("use eraseARGB or eraseColor")
|
2013-06-28 19:40:50 +00:00
|
|
|
void eraseRGB(U8CPU r, U8CPU g, U8CPU b) const {
|
|
|
|
this->eraseARGB(0xFF, r, g, b);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Replaces pixel values inside area with c. If area does not intersect bounds(),
|
|
|
|
call has no effect.
|
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
If the colorType() is kGray_8_SkColorType or k565_SkColorType, then alpha
|
2017-10-30 15:48:35 +00:00
|
|
|
is ignored; RGB is treated as opaque. If colorType() is kAlpha_8_SkColorType,
|
|
|
|
then RGB is ignored.
|
|
|
|
|
|
|
|
@param c unpremultiplied color
|
|
|
|
@param area rectangle to fill
|
|
|
|
*/
|
2015-06-08 17:22:22 +00:00
|
|
|
void erase(SkColor c, const SkIRect& area) const;
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Deprecated.
|
2017-10-30 15:48:35 +00:00
|
|
|
*/
|
2015-06-08 17:22:22 +00:00
|
|
|
void eraseArea(const SkIRect& area, SkColor c) const {
|
|
|
|
this->erase(c, area);
|
|
|
|
}
|
2013-06-28 19:40:50 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@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
|
|
|
|
*/
|
2016-10-31 13:38:12 +00:00
|
|
|
SkColor getColor(int x, int y) const {
|
2017-12-14 20:33:23 +00:00
|
|
|
return this->pixmap().getColor(x, y);
|
2016-10-31 13:38:12 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns pixel address at (x, y).
|
|
|
|
|
|
|
|
Input is not validated: out of bounds values of x or y, or kUnknown_SkColorType,
|
|
|
|
trigger an assert() if built with SK_DEBUG defined. Returns nullptr if
|
|
|
|
SkColorType is kUnknown_SkColorType, or SkPixelRef is nullptr.
|
|
|
|
|
|
|
|
Performs a lookup of pixel size; for better performance, call
|
|
|
|
one of: getAddr8(), getAddr16(), or getAddr32().
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return generic pointer to pixel
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
void* getAddr(int x, int y) const;
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns address at (x, y).
|
|
|
|
|
|
|
|
Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
|
|
|
|
- SkPixelRef is nullptr
|
|
|
|
- bytesPerPixel() is not four
|
|
|
|
- x is negative, or not less than width()
|
|
|
|
- y is negative, or not less than height()
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return unsigned 32-bit pointer to pixel at (x, y)
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
inline uint32_t* getAddr32(int x, int y) const;
|
2011-04-29 11:53:41 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns address at (x, y).
|
|
|
|
|
|
|
|
Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
|
|
|
|
- SkPixelRef is nullptr
|
|
|
|
- bytesPerPixel() is not two
|
|
|
|
- x is negative, or not less than width()
|
|
|
|
- y is negative, or not less than height()
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return unsigned 16-bit pointer to pixel at (x, y)
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
inline uint16_t* getAddr16(int x, int y) const;
|
2011-04-29 11:53:41 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns address at (x, y).
|
|
|
|
|
|
|
|
Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
|
|
|
|
- SkPixelRef is nullptr
|
|
|
|
- bytesPerPixel() is not one
|
|
|
|
- x is negative, or not less than width()
|
|
|
|
- y is negative, or not less than height()
|
|
|
|
|
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@return unsigned 8-bit pointer to pixel at (x, y)
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
inline uint8_t* getAddr8(int x, int y) const;
|
2011-04-29 11:53:41 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Shares SkPixelRef with dst. Pixels are not copied; SkBitmap and dst point
|
|
|
|
to the same pixels; dst bounds() are set to the intersection of subset
|
|
|
|
and the original bounds().
|
|
|
|
|
|
|
|
subset may be larger than bounds(). Any area outside of bounds() is ignored.
|
|
|
|
|
|
|
|
Any contents of dst are discarded. isVolatile() setting is copied to dst.
|
|
|
|
dst is set to colorType(), alphaType(), and colorSpace().
|
|
|
|
|
|
|
|
Return false if:
|
|
|
|
- dst is nullptr
|
|
|
|
- SkPixelRef is nullptr
|
|
|
|
- subset does not intersect bounds()
|
|
|
|
|
|
|
|
@param dst SkBitmap set to subset
|
|
|
|
@param subset rectangle of pixels to reference
|
|
|
|
@return true if dst is replaced by subset
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
bool extractSubset(SkBitmap* dst, const SkIRect& subset) const;
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies SkRect of pixels from SkBitmap pixels to dstPixels. Copy starts at (srcX, srcY),
|
|
|
|
and does not exceed SkBitmap (width(), height()).
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
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.addr() equals nullptr
|
|
|
|
- dstRowBytes is less than dstInfo.minRowBytes()
|
|
|
|
- SkPixelRef is nullptr
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If SkBitmap colorType() is
|
2017-10-30 15:48:35 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match.
|
2018-02-27 15:22:04 +00:00
|
|
|
If SkBitmap colorType() is kGray_8_SkColorType, dstInfo.colorSpace() must match.
|
|
|
|
If SkBitmap alphaType() is kOpaque_SkAlphaType, dstInfo.alphaType() must
|
|
|
|
match. If SkBitmap colorSpace() is nullptr, dstInfo.colorSpace() must match. Returns
|
2017-10-30 15:48:35 +00:00
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
|
|
|
srcX and srcY may be negative to copy only top or left of source. Returns
|
|
|
|
false if width() or height() is zero or negative.
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns false if abs(srcX) >= Bitmap width(), or if abs(srcY) >= Bitmap height().
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
If behavior is SkTransferFunctionBehavior::kRespect: converts source
|
|
|
|
pixels to a linear space before converting to dstInfo.
|
|
|
|
If behavior is SkTransferFunctionBehavior::kIgnore: source
|
|
|
|
pixels are treated as if they are linear, regardless of how they are encoded.
|
|
|
|
|
|
|
|
@param dstInfo destination width, height, SkColorType, SkAlphaType, SkColorSpace
|
|
|
|
@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()
|
|
|
|
@param behavior one of: SkTransferFunctionBehavior::kRespect,
|
|
|
|
SkTransferFunctionBehavior::kIgnore
|
|
|
|
@return true if pixels are copied to dstPixels
|
|
|
|
*/
|
2014-07-13 11:32:32 +00:00
|
|
|
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
|
2017-06-06 14:11:34 +00:00
|
|
|
int srcX, int srcY, SkTransferFunctionBehavior behavior) const;
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies a SkRect of pixels from SkBitmap to dstPixels. Copy starts at (srcX, srcY),
|
|
|
|
and does not exceed SkBitmap (width(), height()).
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
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:
|
2017-10-30 15:48:35 +00:00
|
|
|
- dstInfo.addr() equals nullptr
|
|
|
|
- dstRowBytes is less than dstInfo.minRowBytes()
|
|
|
|
- SkPixelRef is nullptr
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If SkBitmap colorType() is
|
2017-10-30 15:48:35 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match.
|
2018-02-27 15:22:04 +00:00
|
|
|
If SkBitmap colorType() is kGray_8_SkColorType, dstInfo.colorSpace() must match.
|
|
|
|
If SkBitmap alphaType() is kOpaque_SkAlphaType, dstInfo.alphaType() must
|
|
|
|
match. If SkBitmap colorSpace() is nullptr, dstInfo.colorSpace() must match. Returns
|
2017-10-30 15:48:35 +00:00
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
|
|
|
srcX and srcY may be negative to copy only top or left of source. Returns
|
|
|
|
false if width() or height() is zero or negative.
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns false if abs(srcX) >= Bitmap width(), or if abs(srcY) >= Bitmap height().
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@param dstInfo destination width, height, SkColorType, SkAlphaType, SkColorSpace
|
|
|
|
@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, int srcY) const {
|
|
|
|
return this->readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY,
|
|
|
|
SkTransferFunctionBehavior::kRespect);
|
|
|
|
}
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies a SkRect of pixels from SkBitmap to dst. Copy starts at (srcX, srcY), and
|
|
|
|
does not exceed SkBitmap (width(), height()).
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
dst specifies width, height, SkColorType, SkAlphaType, SkColorSpace, pixel storage,
|
|
|
|
and row bytes of destination. dst.rowBytes() specifics the gap from one destination
|
|
|
|
row to the next. Returns true if pixels are copied. Returns false if:
|
|
|
|
- dst pixel storage equals nullptr
|
|
|
|
- dst.rowBytes is less than SkImageInfo::minRowBytes
|
|
|
|
- SkPixelRef is nullptr
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If SkBitmap colorType() is
|
2017-10-30 15:48:35 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; dst SkColorType must match.
|
2018-02-27 15:22:04 +00:00
|
|
|
If SkBitmap colorType() is kGray_8_SkColorType, dst SkColorSpace must match.
|
|
|
|
If SkBitmap alphaType() is kOpaque_SkAlphaType, dst SkAlphaType must
|
|
|
|
match. If SkBitmap colorSpace() is nullptr, dst SkColorSpace must match. Returns
|
2017-10-30 15:48:35 +00:00
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
|
|
|
srcX and srcY may be negative to copy only top or left of source. Returns
|
|
|
|
false if width() or height() is zero or negative.
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns false if abs(srcX) >= Bitmap width(), or if abs(srcY) >= Bitmap height().
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@param dst destination SkPixmap: SkImageInfo, pixels, row bytes
|
|
|
|
@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
|
|
|
|
*/
|
2017-01-04 21:34:31 +00:00
|
|
|
bool readPixels(const SkPixmap& dst, int srcX, int srcY) const;
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Copies a SkRect of pixels from SkBitmap to dst. Copy starts at (0, 0), and
|
|
|
|
does not exceed SkBitmap (width(), height()).
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
dst specifies width, height, SkColorType, SkAlphaType, SkColorSpace, pixel storage,
|
|
|
|
and row bytes of destination. dst.rowBytes() specifics the gap from one destination
|
|
|
|
row to the next. Returns true if pixels are copied. Returns false if:
|
|
|
|
- dst pixel storage equals nullptr
|
|
|
|
- dst.rowBytes is less than SkImageInfo::minRowBytes
|
|
|
|
- SkPixelRef is nullptr
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If SkBitmap colorType() is
|
2017-10-30 15:48:35 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; dst SkColorType must match.
|
2018-02-27 15:22:04 +00:00
|
|
|
If SkBitmap colorType() is kGray_8_SkColorType, dst SkColorSpace must match.
|
|
|
|
If SkBitmap alphaType() is kOpaque_SkAlphaType, dst SkAlphaType must
|
|
|
|
match. If SkBitmap colorSpace() is nullptr, dst SkColorSpace must match. Returns
|
2017-10-30 15:48:35 +00:00
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
|
|
|
@param dst destination SkPixmap: SkImageInfo, pixels, row bytes
|
|
|
|
@return true if pixels are copied to dst
|
|
|
|
*/
|
2017-01-04 21:34:31 +00:00
|
|
|
bool readPixels(const SkPixmap& dst) const {
|
|
|
|
return this->readPixels(dst, 0, 0);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Copies a SkRect of pixels from src. Copy starts at (dstX, dstY), and does not exceed
|
|
|
|
(src.width(), src.height()).
|
|
|
|
|
|
|
|
src specifies width, height, SkColorType, SkAlphaType, SkColorSpace, pixel storage,
|
|
|
|
and row bytes of source. src.rowBytes() specifics the gap from one source
|
|
|
|
row to the next. Returns true if pixels are copied. Returns false if:
|
|
|
|
- src pixel storage equals nullptr
|
|
|
|
- src.rowBytes is less than SkImageInfo::minRowBytes
|
|
|
|
- SkPixelRef is nullptr
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If SkBitmap colorType() is
|
2017-10-30 15:48:35 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; src SkColorType must match.
|
2018-02-27 15:22:04 +00:00
|
|
|
If SkBitmap colorType() is kGray_8_SkColorType, src SkColorSpace must match.
|
|
|
|
If SkBitmap alphaType() is kOpaque_SkAlphaType, src SkAlphaType must
|
|
|
|
match. If SkBitmap colorSpace() is nullptr, src SkColorSpace must match. Returns
|
2017-10-30 15:48:35 +00:00
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
|
|
|
dstX and dstY may be negative to copy only top or left of source. Returns
|
|
|
|
false if width() or height() is zero or negative.
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns false if abs(dstX) >= Bitmap width(), or if abs(dstY) >= Bitmap height().
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@param src source SkPixmap: SkImageInfo, pixels, row bytes
|
|
|
|
@param dstX column index whose absolute value is less than width()
|
|
|
|
@param dstY row index whose absolute value is less than height()
|
|
|
|
@return true if src pixels are copied to SkBitmap
|
|
|
|
*/
|
2017-03-27 19:07:35 +00:00
|
|
|
bool writePixels(const SkPixmap& src, int dstX, int dstY) {
|
|
|
|
return this->writePixels(src, dstX, dstY, SkTransferFunctionBehavior::kRespect);
|
|
|
|
}
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Copies a SkRect of pixels from src. Copy starts at (0, 0), and does not exceed
|
|
|
|
(src.width(), src.height()).
|
|
|
|
|
|
|
|
src specifies width, height, SkColorType, SkAlphaType, SkColorSpace, pixel storage,
|
|
|
|
and row bytes of source. src.rowBytes() specifics the gap from one source
|
|
|
|
row to the next. Returns true if pixels are copied. Returns false if:
|
|
|
|
- src pixel storage equals nullptr
|
|
|
|
- src.rowBytes is less than SkImageInfo::minRowBytes
|
|
|
|
- SkPixelRef is nullptr
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If SkBitmap colorType() is
|
2017-10-30 15:48:35 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; src SkColorType must match.
|
2018-02-27 15:22:04 +00:00
|
|
|
If SkBitmap colorType() is kGray_8_SkColorType, src SkColorSpace must match.
|
|
|
|
If SkBitmap alphaType() is kOpaque_SkAlphaType, src SkAlphaType must
|
|
|
|
match. If SkBitmap colorSpace() is nullptr, src SkColorSpace must match. Returns
|
2017-10-30 15:48:35 +00:00
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
|
|
|
@param src source SkPixmap: SkImageInfo, pixels, row bytes
|
|
|
|
@return true if src pixels are copied to SkBitmap
|
|
|
|
*/
|
2017-01-04 21:34:31 +00:00
|
|
|
bool writePixels(const SkPixmap& src) {
|
|
|
|
return this->writePixels(src, 0, 0);
|
|
|
|
}
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Copies a SkRect of pixels from src. Copy starts at (0, 0), and does not exceed
|
|
|
|
(src.width(), src.height()).
|
|
|
|
|
|
|
|
src specifies width, height, SkColorType, SkAlphaType, SkColorSpace, pixel storage,
|
|
|
|
and row bytes of source. src.rowBytes() specifics the gap from one source
|
|
|
|
row to the next. Returns true if pixels are copied. Returns false if:
|
|
|
|
- src pixel storage equals nullptr
|
|
|
|
- src.rowBytes is less than SkImageInfo::minRowBytes
|
|
|
|
- SkPixelRef is nullptr
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If SkBitmap colorType() is
|
2017-10-30 15:48:35 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; src SkColorType must match.
|
2018-02-27 15:22:04 +00:00
|
|
|
If SkBitmap colorType() is kGray_8_SkColorType, src SkColorSpace must match.
|
|
|
|
If SkBitmap alphaType() is kOpaque_SkAlphaType, src SkAlphaType must
|
|
|
|
match. If SkBitmap colorSpace() is nullptr, src SkColorSpace must match. Returns
|
2017-10-30 15:48:35 +00:00
|
|
|
false if pixel conversion is not possible. Returns false if width() or height()
|
|
|
|
is zero or negative.
|
|
|
|
|
|
|
|
If behavior is SkTransferFunctionBehavior::kRespect: converts src
|
|
|
|
pixels to a linear space before converting to SkImageInfo.
|
|
|
|
If behavior is SkTransferFunctionBehavior::kIgnore: src
|
|
|
|
pixels are treated as if they are linear, regardless of how they are encoded.
|
|
|
|
|
|
|
|
@param src source SkPixmap: SkImageInfo, pixels, row bytes
|
|
|
|
@param x column index whose absolute value is less than width()
|
|
|
|
@param y row index whose absolute value is less than height()
|
|
|
|
@param behavior one of: SkTransferFunctionBehavior::kRespect,
|
|
|
|
SkTransferFunctionBehavior::kIgnore
|
|
|
|
@return true if src pixels are copied to SkBitmap
|
|
|
|
*/
|
2017-06-06 14:11:34 +00:00
|
|
|
bool writePixels(const SkPixmap& src, int x, int y, SkTransferFunctionBehavior behavior);
|
2014-07-13 11:32:32 +00:00
|
|
|
|
2017-10-04 14:56:37 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Android framework only.
|
|
|
|
|
|
|
|
@return true if setHasHardwareMipMap() has been called with true
|
|
|
|
*/
|
2013-03-08 18:35:13 +00:00
|
|
|
bool hasHardwareMipMap() const {
|
|
|
|
return (fFlags & kHasHardwareMipMap_Flag) != 0;
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Android framework only.
|
|
|
|
|
|
|
|
@param hasHardwareMipMap sets state
|
|
|
|
*/
|
2013-03-08 18:35:13 +00:00
|
|
|
void setHasHardwareMipMap(bool hasHardwareMipMap) {
|
|
|
|
if (hasHardwareMipMap) {
|
|
|
|
fFlags |= kHasHardwareMipMap_Flag;
|
|
|
|
} else {
|
|
|
|
fFlags &= ~kHasHardwareMipMap_Flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets dst to alpha described by pixels. Returns false if dst cannot be written to
|
|
|
|
or dst pixels cannot be allocated.
|
|
|
|
|
|
|
|
Uses HeapAllocator to reserve memory for dst SkPixelRef.
|
|
|
|
|
|
|
|
@param dst holds SkPixelRef to fill with alpha layer
|
|
|
|
@return true if alpha layer was constructed in dst SkPixelRef
|
|
|
|
*/
|
2011-03-14 20:30:14 +00:00
|
|
|
bool extractAlpha(SkBitmap* dst) const {
|
2017-08-28 14:34:05 +00:00
|
|
|
return this->extractAlpha(dst, nullptr, nullptr, nullptr);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets dst to alpha described by pixels. Returns false if dst cannot be written to
|
|
|
|
or dst pixels cannot be allocated.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
If paint is not nullptr and contains SkMaskFilter, SkMaskFilter
|
2017-10-30 15:48:35 +00:00
|
|
|
generates mask alpha from SkBitmap. Uses HeapAllocator to reserve memory for dst
|
|
|
|
SkPixelRef. Sets offset to top-left position for dst for alignment with SkBitmap;
|
|
|
|
(0, 0) unless SkMaskFilter generates mask.
|
|
|
|
|
|
|
|
@param dst holds SkPixelRef to fill with alpha layer
|
|
|
|
@param paint holds optional SkMaskFilter; may be nullptr
|
|
|
|
@param offset top-left position for dst; may be nullptr
|
|
|
|
@return true if alpha layer was constructed in dst SkPixelRef
|
|
|
|
*/
|
2011-03-14 20:30:14 +00:00
|
|
|
bool extractAlpha(SkBitmap* dst, const SkPaint* paint,
|
2011-02-23 20:46:31 +00:00
|
|
|
SkIPoint* offset) const {
|
2017-08-28 14:34:05 +00:00
|
|
|
return this->extractAlpha(dst, paint, nullptr, offset);
|
2011-02-23 20:46:31 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets dst to alpha described by pixels. Returns false if dst cannot be written to
|
|
|
|
or dst pixels cannot be allocated.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
If paint is not nullptr and contains SkMaskFilter, SkMaskFilter
|
2017-10-30 15:48:35 +00:00
|
|
|
generates mask alpha from SkBitmap. allocator may reference a custom allocation
|
|
|
|
class or be set to nullptr to use HeapAllocator. Sets offset to top-left
|
|
|
|
position for dst for alignment with SkBitmap; (0, 0) unless SkMaskFilter generates
|
|
|
|
mask.
|
2011-03-14 20:30:14 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
@param dst holds SkPixelRef to fill with alpha layer
|
|
|
|
@param paint holds optional SkMaskFilter; may be nullptr
|
2018-05-30 13:20:29 +00:00
|
|
|
@param allocator function to reserve memory for SkPixelRef; may be nullptr
|
2017-10-30 15:48:35 +00:00
|
|
|
@param offset top-left position for dst; may be nullptr
|
|
|
|
@return true if alpha layer was constructed in dst SkPixelRef
|
2011-03-14 20:30:14 +00:00
|
|
|
*/
|
|
|
|
bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator,
|
2008-12-17 15:59:43 +00:00
|
|
|
SkIPoint* offset) const;
|
2009-05-03 18:23:30 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Copies SkBitmap pixel address, row bytes, and SkImageInfo to pixmap, if address
|
|
|
|
is available, and returns true. If pixel address is not available, return
|
|
|
|
false and leave pixmap unchanged.
|
|
|
|
|
|
|
|
pixmap contents become invalid on any future change to SkBitmap.
|
|
|
|
|
|
|
|
@param pixmap storage for pixel state if pixels are readable; otherwise, ignored
|
|
|
|
@return true if SkBitmap has direct access to pixels
|
|
|
|
*/
|
2017-09-21 16:36:48 +00:00
|
|
|
bool peekPixels(SkPixmap* pixmap) const;
|
2015-06-05 13:58:22 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Asserts if internal values are illegal or inconsistent. Only available if
|
|
|
|
SK_DEBUG is defined at compile time.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
SkDEBUGCODE(void validate() const;)
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** \class SkBitmap::Allocator
|
|
|
|
Abstract subclass of HeapAllocator.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
class Allocator : public SkRefCnt {
|
|
|
|
public:
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Allocates the pixel memory for the bitmap, given its dimensions and
|
2018-02-27 15:22:04 +00:00
|
|
|
SkColorType. Returns true on success, where success means either setPixels()
|
2017-10-30 15:48:35 +00:00
|
|
|
or setPixelRef() was called.
|
|
|
|
|
|
|
|
@param bitmap SkBitmap containing SkImageInfo as input, and SkPixelRef as output
|
|
|
|
@return true if SkPixelRef was allocated
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2017-09-21 16:36:48 +00:00
|
|
|
virtual bool allocPixelRef(SkBitmap* bitmap) = 0;
|
2012-06-21 20:25:03 +00:00
|
|
|
private:
|
|
|
|
typedef SkRefCnt INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** \class SkBitmap::HeapAllocator
|
2018-02-27 15:22:04 +00:00
|
|
|
Subclass of SkBitmap::Allocator that returns a SkPixelRef that allocates its pixel
|
|
|
|
memory from the heap. This is the default SkBitmap::Allocator invoked by
|
2008-12-17 15:59:43 +00:00
|
|
|
allocPixels().
|
|
|
|
*/
|
|
|
|
class HeapAllocator : public Allocator {
|
|
|
|
public:
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Allocates the pixel memory for the bitmap, given its dimensions and
|
2018-02-27 15:22:04 +00:00
|
|
|
SkColorType. Returns true on success, where success means either setPixels()
|
2017-10-30 15:48:35 +00:00
|
|
|
or setPixelRef() was called.
|
|
|
|
|
|
|
|
@param bitmap SkBitmap containing SkImageInfo as input, and SkPixelRef as output
|
|
|
|
@return true if pixels are allocated
|
|
|
|
*/
|
2017-09-21 16:36:48 +00:00
|
|
|
bool allocPixelRef(SkBitmap* bitmap) override;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum Flags {
|
2011-12-15 20:14:06 +00:00
|
|
|
kImageIsVolatile_Flag = 0x02,
|
2013-03-08 18:35:13 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID
|
|
|
|
/* A hint for the renderer responsible for drawing this bitmap
|
|
|
|
* indicating that it should attempt to use mipmaps when this bitmap
|
|
|
|
* is drawn scaled down.
|
|
|
|
*/
|
|
|
|
kHasHardwareMipMap_Flag = 0x08,
|
|
|
|
#endif
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
2017-04-14 21:16:36 +00:00
|
|
|
sk_sp<SkPixelRef> fPixelRef;
|
2017-12-15 02:13:47 +00:00
|
|
|
SkPixmap fPixmap;
|
2017-04-14 21:16:36 +00:00
|
|
|
uint8_t fFlags;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-11-30 21:14:34 +00:00
|
|
|
friend class SkReadBuffer; // unflatten
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
inline uint32_t* SkBitmap::getAddr32(int x, int y) const {
|
2017-12-15 02:13:47 +00:00
|
|
|
SkASSERT(fPixmap.addr());
|
|
|
|
return fPixmap.writable_addr32(x, y);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline uint16_t* SkBitmap::getAddr16(int x, int y) const {
|
2017-12-15 02:13:47 +00:00
|
|
|
SkASSERT(fPixmap.addr());
|
|
|
|
return fPixmap.writable_addr16(x, y);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline uint8_t* SkBitmap::getAddr8(int x, int y) const {
|
2017-12-15 02:13:47 +00:00
|
|
|
SkASSERT(fPixmap.addr());
|
|
|
|
return fPixmap.writable_addr8(x, y);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|