2017-10-04 18:31:33 +00:00
|
|
|
#Topic Bitmap
|
2018-05-30 13:21:49 +00:00
|
|
|
#Alias Bitmaps ##
|
|
|
|
#Alias Bitmap_Reference ##
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Class SkBitmap
|
2018-10-08 18:57:48 +00:00
|
|
|
#Line # two-dimensional raster pixel array ##
|
|
|
|
|
|
|
|
#Code
|
|
|
|
#Populate
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
Bitmap describes a two-dimensional raster pixel array. Bitmap is built on
|
|
|
|
Image_Info, containing integer width and height, Color_Type and Alpha_Type
|
|
|
|
describing the pixel format, and Color_Space describing the range of colors.
|
|
|
|
Bitmap points to Pixel_Ref, which describes the physical array of pixels.
|
|
|
|
Image_Info bounds may be located anywhere fully inside Pixel_Ref bounds.
|
|
|
|
|
|
|
|
Bitmap can be drawn using Canvas. Bitmap can be a drawing destination for Canvas
|
2018-05-30 13:21:49 +00:00
|
|
|
draw member functions. Bitmap flexibility as a pixel container limits some
|
2018-05-16 11:07:07 +00:00
|
|
|
optimizations available to the target platform.
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
If pixel array is primarily read-only, use Image for better performance.
|
|
|
|
If pixel array is primarily written to, use Surface for better performance.
|
|
|
|
|
|
|
|
Declaring SkBitmap const prevents altering Image_Info: the Bitmap height, width,
|
|
|
|
and so on cannot change. It does not affect Pixel_Ref: a caller may write its
|
|
|
|
pixels. Declaring SkBitmap const affects Bitmap configuration, not its contents.
|
|
|
|
|
2017-10-31 19:44:45 +00:00
|
|
|
Bitmap is not thread safe. Each thread must have its own copy of Bitmap fields,
|
2017-10-04 18:31:33 +00:00
|
|
|
although threads may share the underlying pixel array.
|
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
#Subtopic Row_Bytes
|
|
|
|
#Line # interval from one row to the next ##
|
2017-10-04 18:31:33 +00:00
|
|
|
Bitmap pixels may be contiguous, or may have a gap at the end of each row.
|
|
|
|
Row_Bytes is the interval from one row to the next. Row_Bytes may be specified;
|
|
|
|
sometimes passing zero will compute the Row_Bytes from the row width and the
|
|
|
|
number of bytes in a pixel. Row_Bytes may be larger than the row requires. This
|
|
|
|
is useful to position one or more Bitmaps within a shared pixel array.
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Class Allocator
|
2018-02-01 14:37:32 +00:00
|
|
|
#Line # abstract subclass of HeapAllocator ##
|
2017-10-04 18:31:33 +00:00
|
|
|
#Code
|
2018-10-16 14:30:28 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
Abstract subclass of HeapAllocator.
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method virtual bool allocPixelRef(SkBitmap* bitmap) = 0
|
2018-08-10 17:09:13 +00:00
|
|
|
#Line # allocates pixel memory ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#NoExample
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso HeapAllocator
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Class Allocator ##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Class HeapAllocator
|
2018-02-01 14:37:32 +00:00
|
|
|
#Line # allocates pixel memory from heap ##
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Code
|
2018-10-16 14:30:28 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
2018-02-09 21:49:09 +00:00
|
|
|
Subclass of SkBitmap::Allocator that returns a Pixel_Ref that allocates its pixel
|
|
|
|
memory from the heap. This is the default SkBitmap::Allocator invoked by
|
2017-10-04 18:31:33 +00:00
|
|
|
allocPixels.
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool allocPixelRef(SkBitmap* bitmap) override
|
2018-05-16 11:07:07 +00:00
|
|
|
#Line # allocates pixel memory ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.setInfo(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType));
|
|
|
|
SkDebugf("pixel address = %p\n", bitmap.getPixels());
|
|
|
|
SkBitmap::HeapAllocator stdalloc;
|
|
|
|
if (!stdalloc.allocPixelRef(&bitmap)) {
|
|
|
|
SkDebugf("pixel allocation failed\n");
|
|
|
|
} else {
|
|
|
|
SkDebugf("pixel address = %p\n", bitmap.getPixels());
|
|
|
|
}
|
|
|
|
#StdOut
|
2017-10-11 14:37:52 +00:00
|
|
|
#Volatile
|
2017-10-09 18:43:00 +00:00
|
|
|
pixel address = (nil)
|
|
|
|
pixel address = 0x560ddd0ac670
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
2018-02-09 21:49:09 +00:00
|
|
|
#SeeAlso SkBitmap::Allocator tryAllocPixels
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
#Class HeapAllocator ##
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkBitmap()
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # constructs with default values ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
|
2018-01-30 15:08:57 +00:00
|
|
|
const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
|
|
|
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
|
2017-10-04 18:31:33 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
SkDebugf("width: %2d height: %2d", bitmap.width(), bitmap.height());
|
|
|
|
SkDebugf(" color: k%s_SkColorType", colors[bitmap.colorType()]);
|
|
|
|
SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[bitmap.alphaType()]);
|
|
|
|
bitmap.setInfo(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType),
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#StdOut
|
2017-10-09 18:43:00 +00:00
|
|
|
width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType
|
2017-10-04 18:31:33 +00:00
|
|
|
width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso setInfo
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkBitmap(const SkBitmap& src)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # shares ownership of pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkBitmap original;
|
2018-03-16 15:34:15 +00:00
|
|
|
if (original.tryAllocPixels(
|
|
|
|
SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
|
|
|
|
SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false");
|
2018-05-16 11:07:07 +00:00
|
|
|
SkBitmap copy(original);
|
2018-03-16 15:34:15 +00:00
|
|
|
SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false");
|
|
|
|
SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
#StdOut
|
2017-10-09 18:43:00 +00:00
|
|
|
original has pixels before copy: true
|
|
|
|
original has pixels after copy: true
|
2017-10-04 18:31:33 +00:00
|
|
|
copy has pixels: true
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso setInfo setPixelRef setPixels swap
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkBitmap(SkBitmap&& src)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # takes ownership of pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkBitmap original;
|
2018-03-16 15:34:15 +00:00
|
|
|
if (original.tryAllocPixels(
|
|
|
|
SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
|
|
|
|
SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false");
|
2018-05-16 11:07:07 +00:00
|
|
|
SkBitmap copy(std::move(original));
|
2018-03-16 15:34:15 +00:00
|
|
|
SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false");
|
|
|
|
SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
|
|
|
|
}
|
2017-10-09 18:43:00 +00:00
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
#StdOut
|
2017-10-09 18:43:00 +00:00
|
|
|
original has pixels before move: true
|
|
|
|
original has pixels after move: false
|
2017-10-04 18:31:33 +00:00
|
|
|
copy has pixels: true
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso setInfo setPixelRef setPixels swap
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method ~SkBitmap()
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # releases ownership of pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#NoExample
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso Pixel_Ref
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkBitmap& operator=(const SkBitmap& src)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # shares ownership of pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkBitmap original;
|
2018-03-16 15:34:15 +00:00
|
|
|
if (original.tryAllocPixels(
|
|
|
|
SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
|
|
|
|
SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false");
|
2018-05-16 11:07:07 +00:00
|
|
|
SkBitmap copy = original;
|
2018-03-16 15:34:15 +00:00
|
|
|
SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false");
|
|
|
|
SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
#StdOut
|
2017-10-09 18:43:00 +00:00
|
|
|
original has pixels before copy: true
|
|
|
|
original has pixels after copy: true
|
2017-10-04 18:31:33 +00:00
|
|
|
copy has pixels: true
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso setInfo setPixelRef setPixels swap
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkBitmap& operator=(SkBitmap&& src)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # takes ownership of pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkBitmap original;
|
2018-03-16 15:34:15 +00:00
|
|
|
if (original.tryAllocPixels(
|
|
|
|
SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
|
|
|
|
SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false");
|
2018-05-16 11:07:07 +00:00
|
|
|
SkBitmap copy = std::move(original);
|
2018-03-16 15:34:15 +00:00
|
|
|
SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false");
|
|
|
|
SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
|
|
|
|
}
|
2017-10-09 18:43:00 +00:00
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
#StdOut
|
2017-10-09 18:43:00 +00:00
|
|
|
original has pixels before move: true
|
|
|
|
original has pixels after move: false
|
2017-10-04 18:31:33 +00:00
|
|
|
copy has pixels: true
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso setInfo setPixelRef setPixels swap
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void swap(SkBitmap& other)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Utility
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # exchanges Bitmap pair ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
auto debugster = [](const char* prefix, const SkBitmap& b) -> void {
|
|
|
|
const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
|
2018-01-30 15:08:57 +00:00
|
|
|
const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
|
|
|
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
|
2017-10-09 18:43:00 +00:00
|
|
|
SkDebugf("%s width:%d height:%d colorType:k%s_SkColorType alphaType:k%s_SkAlphaType\n",
|
|
|
|
prefix, b.width(), b.height(), colors[b.colorType()], alphas[b.alphaType()]);
|
|
|
|
};
|
|
|
|
SkBitmap one, two;
|
2018-03-16 15:34:15 +00:00
|
|
|
if (!one.tryAllocPixels(
|
|
|
|
SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!two.tryAllocPixels(
|
|
|
|
SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType))) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-09 18:43:00 +00:00
|
|
|
for (int index = 0; index < 2; ++index) {
|
|
|
|
debugster("one", one);
|
|
|
|
debugster("two", two);
|
|
|
|
one.swap(two);
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
#StdOut
|
2017-10-09 18:43:00 +00:00
|
|
|
one width:1 height:1 colorType:kRGBA_8888_SkColorType alphaType:kOpaque_SkAlphaType
|
|
|
|
two width:2 height:2 colorType:kBGRA_8888_SkColorType alphaType:kPremul_SkAlphaType
|
|
|
|
one width:2 height:2 colorType:kBGRA_8888_SkColorType alphaType:kPremul_SkAlphaType
|
2017-10-04 18:31:33 +00:00
|
|
|
two width:1 height:1 colorType:kRGBA_8888_SkColorType alphaType:kOpaque_SkAlphaType
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso SkBitmap(SkBitmap&& src) operator=(SkBitmap&& src)
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-07 12:27:09 +00:00
|
|
|
#Subtopic Property
|
|
|
|
#Line # metrics and attributes ##
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
|
2017-12-15 02:13:47 +00:00
|
|
|
#Method const SkPixmap& pixmap() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns Pixmap ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-12-15 16:21:51 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(10, 11));
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
offscreen.clear(SK_ColorWHITE);
|
|
|
|
SkPaint paint;
|
|
|
|
offscreen.drawString("&", 0, 10, paint);
|
2017-12-15 02:13:47 +00:00
|
|
|
const SkPixmap& pixmap = bitmap.pixmap();
|
2017-12-15 16:21:51 +00:00
|
|
|
if (pixmap.addr()) {
|
2017-12-15 02:13:47 +00:00
|
|
|
SkPMColor pmWhite = *pixmap.addr32(0, 0);
|
|
|
|
for (int y = 0; y < pixmap.height(); ++y) {
|
|
|
|
for (int x = 0; x < pixmap.width(); ++x) {
|
|
|
|
SkDebugf("%c", *pixmap.addr32(x, y) == pmWhite ? '-' : 'x');
|
2017-12-15 16:21:51 +00:00
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
----------
|
|
|
|
---xx-----
|
|
|
|
--x--x----
|
|
|
|
--x-------
|
|
|
|
--xx------
|
|
|
|
--x-x---x-
|
|
|
|
-x---x--x-
|
|
|
|
-x----xx--
|
|
|
|
-xx---x---
|
|
|
|
--xxxx-xx-
|
|
|
|
----------
|
|
|
|
#StdOut ##
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso peekPixels installPixels readPixels writePixels
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
#Method const SkImageInfo& info() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns Image_Info ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 4
|
2017-10-09 18:43:00 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
// SkBitmap source; // pre-populated with soccer ball by fiddle.skia.org
|
|
|
|
const SkImageInfo& info = source.info();
|
|
|
|
const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
|
2018-01-30 15:08:57 +00:00
|
|
|
const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
|
|
|
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
|
2017-10-09 18:43:00 +00:00
|
|
|
SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(),
|
|
|
|
colors[info.colorType()], alphas[info.alphaType()]);
|
|
|
|
#StdOut
|
|
|
|
width: 56 height: 56 color: BGRA_8888 alpha: Opaque
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso Image_Info
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method int width() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns pixel column count ##
|
Condense embedded formulas.
Bookmaker delimits formulas and equations to allow
representing variables and symbols without tripping
up reference lookup, spell checking, and comment
generation.
Before, formulas were represented with:
some text
#Formula
(x + y, 0)
##
, and more text
This made it difficult to know when spacing should
be preserved before and after the formula. Now,
formulas are represented with:
some text #Formula # (x + y, 0) ##, and more text
The presence or absence of a space between ## and ,
is now significant (before it was not).
Also, formulas are bracketed by <code> in markdown
generation, so that variables stand out better.
See:
https://skia.org/user/api/SkBlendMode_Reference?cl=152781#Dst_Out
for an example.
Also fixed 100 column offenders and added a code
check to identify them. For the moment, 100 column
offenders are outed with SkDebugf but their presence
does not cause bookmaker to fail.
TBR=caryclark@google.com
Docs-Preview: https://skia.org/?cl=152781
Bug: skia:6898
Change-Id: If92a65a234f5d616bf4485984a8d219a6f04821a
Reviewed-on: https://skia-review.googlesource.com/152781
Commit-Queue: Cary Clark <caryclark@skia.org>
Auto-Submit: Cary Clark <caryclark@skia.org>
Reviewed-by: Cary Clark <caryclark@skia.org>
2018-09-13 16:04:30 +00:00
|
|
|
Returns pixel count in each row. Should be equal or less than
|
|
|
|
#Formula # rowBytes() / info().bytesPerPixel() ##.
|
2017-10-04 18:31:33 +00:00
|
|
|
|
2018-07-11 20:18:41 +00:00
|
|
|
May be less than pixelRef().width(). Will not exceed pixelRef().width() less
|
2017-10-04 18:31:33 +00:00
|
|
|
pixelRefOrigin().fX.
|
|
|
|
|
|
|
|
#Return pixel width in Image_Info ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
SkImageInfo info = SkImageInfo::MakeA8(16, 32);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.setInfo(info);
|
|
|
|
SkDebugf("bitmap width: %d info width: %d\n", bitmap.width(), info.width());
|
|
|
|
#StdOut
|
|
|
|
bitmap width: 16 info width: 16
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso height() SkPixelRef::width() SkImageInfo::width()
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method int height() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns pixel row count ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
SkImageInfo info = SkImageInfo::MakeA8(16, 32);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.setInfo(info);
|
|
|
|
SkDebugf("bitmap height: %d info height: %d\n", bitmap.height(), info.height());
|
|
|
|
#StdOut
|
|
|
|
bitmap height: 32 info height: 32
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso width() SkPixelRef::height() SkImageInfo::height()
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkColorType colorType() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns Image_Info Color_Type ##
|
2018-03-05 18:26:16 +00:00
|
|
|
Returns Color_Type, one of: #list_of_color_types#.
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Return Color_Type in Image_Info ##
|
|
|
|
|
|
|
|
#Example
|
2018-01-30 15:08:57 +00:00
|
|
|
const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
|
|
|
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.setInfo(SkImageInfo::MakeA8(16, 32));
|
|
|
|
SkDebugf("color type: k" "%s" "_SkColorType\n", colors[bitmap.colorType()]);
|
2017-10-04 18:31:33 +00:00
|
|
|
#StdOut
|
2018-01-30 15:08:57 +00:00
|
|
|
color type: kAlpha_8_SkColorType
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso alphaType() SkImageInfo::colorType
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkAlphaType alphaType() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns Image_Info Alpha_Type ##
|
2018-03-16 15:34:15 +00:00
|
|
|
Returns Alpha_Type, one of: #list_of_alpha_types#.
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Return Alpha_Type in Image_Info ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
|
|
|
|
SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64);
|
|
|
|
SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]);
|
|
|
|
#StdOut
|
|
|
|
alpha type: kPremul_SkAlphaType
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso colorType() SkImageInfo::alphaType
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkColorSpace* colorSpace() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns Image_Info Color_Space ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma
|
|
|
|
and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma.
|
|
|
|
##
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
2018-05-16 11:07:07 +00:00
|
|
|
bitmap.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
|
2017-10-04 18:31:33 +00:00
|
|
|
SkColorSpace::MakeSRGBLinear()));
|
|
|
|
SkColorSpace* colorSpace = bitmap.colorSpace();
|
|
|
|
SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
|
|
|
|
colorSpace->gammaCloseToSRGB() ? "true" : "false",
|
|
|
|
colorSpace->gammaIsLinear() ? "true" : "false",
|
|
|
|
colorSpace->isSRGB() ? "true" : "false");
|
|
|
|
#StdOut
|
|
|
|
gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso Color_Space SkImageInfo::colorSpace
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method sk_sp<SkColorSpace> refColorSpace() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns Image_Info Color_Space ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap1, bitmap2;
|
2018-05-16 11:07:07 +00:00
|
|
|
bitmap1.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
|
2017-10-04 18:31:33 +00:00
|
|
|
SkColorSpace::MakeSRGBLinear()));
|
|
|
|
bitmap2.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
|
|
|
|
bitmap1.refColorSpace()));
|
|
|
|
SkColorSpace* colorSpace = bitmap2.colorSpace();
|
|
|
|
SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n",
|
|
|
|
colorSpace->gammaCloseToSRGB() ? "true" : "false",
|
|
|
|
colorSpace->gammaIsLinear() ? "true" : "false",
|
|
|
|
colorSpace->isSRGB() ? "true" : "false");
|
|
|
|
#StdOut
|
|
|
|
gammaCloseToSRGB: false gammaIsLinear: true isSRGB: false
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso Color_Space SkImageInfo::colorSpace
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method int bytesPerPixel() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns number of bytes in pixel based on Color_Type ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2018-01-30 15:08:57 +00:00
|
|
|
const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
|
|
|
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
|
2017-10-04 18:31:33 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeA8(1, 1);
|
|
|
|
SkBitmap bitmap;
|
2018-03-05 18:26:16 +00:00
|
|
|
for (SkColorType colorType : { #list_of_color_types#
|
|
|
|
} ) {
|
2017-10-04 18:31:33 +00:00
|
|
|
bitmap.setInfo(info.makeColorType(colorType));
|
|
|
|
SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n",
|
2018-01-30 15:08:57 +00:00
|
|
|
colors[colorType], 13 - strlen(colors[colorType]), " ",
|
2017-10-04 18:31:33 +00:00
|
|
|
bitmap.bytesPerPixel());
|
|
|
|
}
|
|
|
|
#StdOut
|
2018-03-13 13:02:35 +00:00
|
|
|
color: kUnknown_SkColorType bytesPerPixel: 0
|
|
|
|
color: kAlpha_8_SkColorType bytesPerPixel: 1
|
|
|
|
color: kRGB_565_SkColorType bytesPerPixel: 2
|
|
|
|
color: kARGB_4444_SkColorType bytesPerPixel: 2
|
|
|
|
color: kRGBA_8888_SkColorType bytesPerPixel: 4
|
|
|
|
color: kRGB_888x_SkColorType bytesPerPixel: 4
|
|
|
|
color: kBGRA_8888_SkColorType bytesPerPixel: 4
|
|
|
|
color: kRGBA_1010102_SkColorType bytesPerPixel: 4
|
|
|
|
color: kRGB_101010x_SkColorType bytesPerPixel: 4
|
|
|
|
color: kGray_8_SkColorType bytesPerPixel: 1
|
2018-01-30 15:08:57 +00:00
|
|
|
color: kRGBA_F16_SkColorType bytesPerPixel: 8
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2018-03-16 15:34:15 +00:00
|
|
|
#SeeAlso rowBytes rowBytesAsPixels width shiftPerPixel SkImageInfo::bytesPerPixel
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method int rowBytesAsPixels() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns interval between rows in pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
SkBitmap bitmap;
|
|
|
|
for (int rowBytes : { 4, 5, 6, 7, 8} ) {
|
|
|
|
bitmap.setInfo(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), rowBytes);
|
|
|
|
SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, bitmap.rowBytesAsPixels());
|
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
rowBytes: 4 rowBytesAsPixels: 1
|
|
|
|
rowBytes: 5 rowBytesAsPixels: 1
|
|
|
|
rowBytes: 6 rowBytesAsPixels: 1
|
|
|
|
rowBytes: 7 rowBytesAsPixels: 1
|
|
|
|
rowBytes: 8 rowBytesAsPixels: 2
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso rowBytes shiftPerPixel width bytesPerPixel
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method int shiftPerPixel() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns bit shift from pixels to bytes ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2018-01-30 15:08:57 +00:00
|
|
|
const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
|
|
|
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16"};
|
2017-10-04 18:31:33 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeA8(1, 1);
|
|
|
|
SkBitmap bitmap;
|
2018-03-05 18:26:16 +00:00
|
|
|
for (SkColorType colorType : { #list_of_color_types#
|
|
|
|
} ) {
|
2017-10-04 18:31:33 +00:00
|
|
|
bitmap.setInfo(info.makeColorType(colorType));
|
|
|
|
SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n",
|
2018-03-05 18:26:16 +00:00
|
|
|
colors[colorType], 14 - strlen(colors[colorType]), " ",
|
2017-10-04 18:31:33 +00:00
|
|
|
bitmap.shiftPerPixel());
|
|
|
|
}
|
|
|
|
#StdOut
|
2018-03-13 13:02:35 +00:00
|
|
|
color: kUnknown_SkColorType shiftPerPixel: 0
|
|
|
|
color: kAlpha_8_SkColorType shiftPerPixel: 0
|
|
|
|
color: kRGB_565_SkColorType shiftPerPixel: 1
|
|
|
|
color: kARGB_4444_SkColorType shiftPerPixel: 1
|
|
|
|
color: kRGBA_8888_SkColorType shiftPerPixel: 2
|
|
|
|
color: kRGB_888x_SkColorType shiftPerPixel: 2
|
|
|
|
color: kBGRA_8888_SkColorType shiftPerPixel: 2
|
|
|
|
color: kRGBA_1010102_SkColorType shiftPerPixel: 2
|
|
|
|
color: kRGB_101010x_SkColorType shiftPerPixel: 2
|
|
|
|
color: kGray_8_SkColorType shiftPerPixel: 0
|
2018-03-05 18:26:16 +00:00
|
|
|
color: kRGBA_F16_SkColorType shiftPerPixel: 3
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso rowBytes rowBytesAsPixels width bytesPerPixel
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool empty() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns true if Image_Info has zero width() or height() ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
SkBitmap bitmap;
|
|
|
|
for (int width : { 0, 2 } ) {
|
|
|
|
for (int height : { 0, 2 } ) {
|
|
|
|
bitmap.setInfo(SkImageInfo::MakeA8(width, height));
|
|
|
|
SkDebugf("width: %d height: %d empty: %s\n", width, height,
|
|
|
|
bitmap.empty() ? "true" : "false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
width: 0 height: 0 empty: true
|
|
|
|
width: 0 height: 2 empty: true
|
|
|
|
width: 2 height: 0 empty: true
|
|
|
|
width: 2 height: 2 empty: false
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#SeeAlso height() width() drawsNothing
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool isNull() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns true if Pixel_Ref is nullptr ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
SkDebugf("empty bitmap does %shave pixels\n", bitmap.isNull() ? "not " : "");
|
|
|
|
bitmap.setInfo(SkImageInfo::MakeA8(8, 8));
|
|
|
|
SkDebugf("bitmap with dimensions does %shave pixels\n", bitmap.isNull() ? "not " : "");
|
|
|
|
bitmap.allocPixels();
|
|
|
|
SkDebugf("allocated bitmap does %shave pixels\n", bitmap.isNull() ? "not " : "");
|
2017-10-04 18:31:33 +00:00
|
|
|
#StdOut
|
2017-10-09 18:43:00 +00:00
|
|
|
empty bitmap does not have pixels
|
|
|
|
bitmap with dimensions does not have pixels
|
2017-10-04 18:31:33 +00:00
|
|
|
allocated bitmap does have pixels
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso empty() drawsNothing pixelRef
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool drawsNothing() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns true if no width(), no height(), or no Pixel_Ref ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
for (int w : { 0, 8 } ) {
|
|
|
|
for (bool allocate : { false, true} ) {
|
|
|
|
bitmap.setInfo(SkImageInfo::MakeA8(w, 8));
|
|
|
|
allocate ? bitmap.allocPixels() : (void) 0 ;
|
|
|
|
SkDebugf("empty:%s isNull:%s drawsNothing:%s\n", bitmap.empty() ? "true " : "false",
|
|
|
|
bitmap.isNull() ? "true " : "false", bitmap.drawsNothing() ? "true" : "false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
empty:true isNull:true drawsNothing:true
|
|
|
|
empty:true isNull:false drawsNothing:true
|
|
|
|
empty:false isNull:true drawsNothing:true
|
|
|
|
empty:false isNull:false drawsNothing:false
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso empty() isNull pixelRef
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method size_t rowBytes() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns interval between rows in bytes ##
|
2017-10-04 18:31:33 +00:00
|
|
|
Returns row bytes, the interval from one pixel row to the next. Row bytes
|
Condense embedded formulas.
Bookmaker delimits formulas and equations to allow
representing variables and symbols without tripping
up reference lookup, spell checking, and comment
generation.
Before, formulas were represented with:
some text
#Formula
(x + y, 0)
##
, and more text
This made it difficult to know when spacing should
be preserved before and after the formula. Now,
formulas are represented with:
some text #Formula # (x + y, 0) ##, and more text
The presence or absence of a space between ## and ,
is now significant (before it was not).
Also, formulas are bracketed by <code> in markdown
generation, so that variables stand out better.
See:
https://skia.org/user/api/SkBlendMode_Reference?cl=152781#Dst_Out
for an example.
Also fixed 100 column offenders and added a code
check to identify them. For the moment, 100 column
offenders are outed with SkDebugf but their presence
does not cause bookmaker to fail.
TBR=caryclark@google.com
Docs-Preview: https://skia.org/?cl=152781
Bug: skia:6898
Change-Id: If92a65a234f5d616bf4485984a8d219a6f04821a
Reviewed-on: https://skia-review.googlesource.com/152781
Commit-Queue: Cary Clark <caryclark@skia.org>
Auto-Submit: Cary Clark <caryclark@skia.org>
Reviewed-by: Cary Clark <caryclark@skia.org>
2018-09-13 16:04:30 +00:00
|
|
|
is at least as large as: #Formula # width() * info().bytesPerPixel() ##.
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
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 ##
|
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
for (int rowBytes : { 2, 8 } ) {
|
|
|
|
bool result = bitmap.setInfo(SkImageInfo::MakeA8(4, 4), rowBytes);
|
|
|
|
SkDebugf("setInfo returned:%s rowBytes:%d\n", result ? "true " : "false", bitmap.rowBytes());
|
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
setInfo returned:false rowBytes:0
|
|
|
|
setInfo returned:true rowBytes:8
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso info() setInfo SkImageInfo::minRowBytes
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool setAlphaType(SkAlphaType alphaType)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Set
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # sets Alpha_Type of shared pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
2018-01-30 15:08:57 +00:00
|
|
|
const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
|
|
|
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
|
2018-05-16 11:07:07 +00:00
|
|
|
const char* alphas[] = {"Unknown ", "Opaque ", "Premul ", "Unpremul"};
|
2018-01-30 15:08:57 +00:00
|
|
|
SkBitmap bitmap;
|
2018-03-16 15:34:15 +00:00
|
|
|
SkAlphaType alphaTypes[] = { #list_of_alpha_types#
|
|
|
|
};
|
2018-10-16 14:30:28 +00:00
|
|
|
SkDebugf("%18s%15s%17s%18s%19s\n", "Canonical", "Unknown", "Opaque", "Premul", "Unpremul");
|
2018-03-05 18:26:16 +00:00
|
|
|
for (SkColorType colorType : { #list_of_color_types#
|
|
|
|
} ) {
|
2017-10-09 18:43:00 +00:00
|
|
|
for (SkAlphaType canonicalAlphaType : alphaTypes) {
|
|
|
|
SkColorTypeValidateAlphaType(colorType, kUnknown_SkAlphaType, &canonicalAlphaType );
|
2018-10-16 14:30:28 +00:00
|
|
|
SkDebugf("%12s %9s ", colors[(int) colorType], alphas[(int) canonicalAlphaType ]);
|
2017-10-09 18:43:00 +00:00
|
|
|
for (SkAlphaType alphaType : alphaTypes) {
|
|
|
|
bitmap.setInfo(SkImageInfo::Make(4, 4, colorType, canonicalAlphaType));
|
|
|
|
bool result = bitmap.setAlphaType(alphaType);
|
|
|
|
SkDebugf("%s %s ", result ? "true " : "false", alphas[(int) bitmap.alphaType()]);
|
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
|
|
|
}
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso Alpha_Type Color_Type Image_Info setInfo
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void* getPixels() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns address of pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.setInfo(SkImageInfo::MakeN32(4, 4, kPremul_SkAlphaType));
|
|
|
|
bitmap.allocPixels();
|
|
|
|
bitmap.eraseColor(0x00000000);
|
|
|
|
void* baseAddr = bitmap.getPixels();
|
|
|
|
*(SkPMColor*)baseAddr = 0xFFFFFFFF;
|
|
|
|
SkDebugf("bitmap.getColor(0, 1) %c= 0x00000000\n",
|
|
|
|
bitmap.getColor(0, 1) == 0x00000000 ? '=' : '!');
|
|
|
|
SkDebugf("bitmap.getColor(0, 0) %c= 0xFFFFFFFF\n",
|
|
|
|
bitmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!');
|
2017-10-04 18:31:33 +00:00
|
|
|
#StdOut
|
2017-10-09 18:43:00 +00:00
|
|
|
bitmap.getColor(0, 1) == 0x00000000
|
2017-10-04 18:31:33 +00:00
|
|
|
bitmap.getColor(0, 0) == 0xFFFFFFFF
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso isNull drawsNothing
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method size_t computeByteSize() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Utility
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns size required for pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
2017-10-04 18:31:33 +00:00
|
|
|
for (int width : { 1, 1000, 1000000 } ) {
|
|
|
|
for (int height: { 1, 1000, 1000000 } ) {
|
|
|
|
SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
|
|
|
|
bitmap.setInfo(imageInfo, width * 5);
|
|
|
|
SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height,
|
|
|
|
bitmap.computeByteSize());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#StdOut
|
2017-10-09 18:43:00 +00:00
|
|
|
width: 1 height: 1 computeByteSize: 4
|
|
|
|
width: 1 height: 1000 computeByteSize: 4999
|
|
|
|
width: 1 height: 1000000 computeByteSize: 4999999
|
|
|
|
width: 1000 height: 1 computeByteSize: 4000
|
|
|
|
width: 1000 height: 1000 computeByteSize: 4999000
|
|
|
|
width: 1000 height: 1000000 computeByteSize: 4999999000
|
|
|
|
width: 1000000 height: 1 computeByteSize: 4000000
|
|
|
|
width: 1000000 height: 1000 computeByteSize: 4999000000
|
2017-10-04 18:31:33 +00:00
|
|
|
width: 1000000 height: 1000000 computeByteSize: 4999999000000
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso SkImageInfo::computeByteSize
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool isImmutable() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns true if pixels will not change ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2018-05-16 11:07:07 +00:00
|
|
|
SkBitmap original;
|
2017-10-09 18:43:00 +00:00
|
|
|
SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
|
|
|
|
if (original.tryAllocPixels(info)) {
|
|
|
|
original.setImmutable();
|
|
|
|
SkBitmap copy;
|
2018-05-16 11:07:07 +00:00
|
|
|
original.extractSubset(©, {5, 10, 15, 20});
|
2017-10-09 18:43:00 +00:00
|
|
|
SkDebugf("original is " "%s" "immutable\n", original.isImmutable() ? "" : "not ");
|
|
|
|
SkDebugf("copy is " "%s" "immutable\n", copy.isImmutable() ? "" : "not ");
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
#StdOut
|
2017-10-09 18:43:00 +00:00
|
|
|
original is immutable
|
2017-10-04 18:31:33 +00:00
|
|
|
copy is immutable
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso setImmutable SkPixelRef::isImmutable SkImage
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void setImmutable()
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Set
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # marks that pixels will not change ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2018-05-16 11:07:07 +00:00
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
Triggers assert if SK_DEBUG is true, runs fine otherwise.
|
|
|
|
##
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.setInfo(SkImageInfo::MakeN32(4, 4, kPremul_SkAlphaType));
|
|
|
|
bitmap.allocPixels();
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
SkDebugf("draw white\n");
|
|
|
|
offscreen.clear(SK_ColorWHITE);
|
|
|
|
bitmap.setImmutable();
|
|
|
|
SkDebugf("draw black\n");
|
2017-10-04 18:31:33 +00:00
|
|
|
offscreen.clear(SK_ColorBLACK);
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso isImmutable SkPixelRef::setImmutable SkImage
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool isOpaque() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns true if Image_Info describes opaque pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
isOpaque ignores whether all pixels are opaque or not.
|
|
|
|
##
|
2017-10-09 18:43:00 +00:00
|
|
|
const int height = 2;
|
|
|
|
const int width = 2;
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.setInfo(SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType));
|
|
|
|
for (int index = 0; index < 2; ++index) {
|
|
|
|
bitmap.allocPixels();
|
|
|
|
bitmap.eraseColor(0x00000000);
|
|
|
|
SkDebugf("isOpaque: %s\n", bitmap.isOpaque() ? "true" : "false");
|
|
|
|
bitmap.eraseColor(0xFFFFFFFF);
|
|
|
|
SkDebugf("isOpaque: %s\n", bitmap.isOpaque() ? "true" : "false");
|
|
|
|
bitmap.setInfo(bitmap.info().makeAlphaType(kOpaque_SkAlphaType));
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
#StdOut
|
|
|
|
isOpaque: false
|
|
|
|
isOpaque: false
|
|
|
|
isOpaque: true
|
|
|
|
isOpaque: true
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso ComputeIsOpaque SkImageInfo::isOpaque
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool isVolatile() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns true if pixels should not be cached ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2018-05-16 11:07:07 +00:00
|
|
|
SkBitmap original;
|
2017-10-09 18:43:00 +00:00
|
|
|
SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
|
|
|
|
if (original.tryAllocPixels(info)) {
|
|
|
|
original.setIsVolatile(true);
|
|
|
|
SkBitmap copy;
|
2018-05-16 11:07:07 +00:00
|
|
|
original.extractSubset(©, {5, 10, 15, 20});
|
2017-10-09 18:43:00 +00:00
|
|
|
SkDebugf("original is " "%s" "volatile\n", original.isVolatile() ? "" : "not ");
|
|
|
|
SkDebugf("copy is " "%s" "volatile\n", copy.isImmutable() ? "" : "not ");
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
#StdOut
|
2017-10-09 18:43:00 +00:00
|
|
|
original is volatile
|
2017-10-04 18:31:33 +00:00
|
|
|
copy is not volatile
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso setIsVolatile
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void setIsVolatile(bool isVolatile)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Set
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # marks if pixels should not be cached ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 20
|
2018-05-16 11:07:07 +00:00
|
|
|
SkBitmap bitmap;
|
2017-10-09 18:43:00 +00:00
|
|
|
bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType));
|
|
|
|
bitmap.allocPixels();
|
|
|
|
bitmap.eraseColor(SK_ColorRED);
|
|
|
|
canvas->scale(16, 16);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
*(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorBLUE);
|
|
|
|
canvas->drawBitmap(bitmap, 2, 0);
|
|
|
|
bitmap.setIsVolatile(true);
|
|
|
|
*(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorGREEN);
|
|
|
|
canvas->drawBitmap(bitmap, 4, 0);
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso isVolatile
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void reset()
|
2018-10-08 18:57:48 +00:00
|
|
|
#In Constructors
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # sets to default values, releases pixel ownership ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2018-05-16 11:07:07 +00:00
|
|
|
SkBitmap bitmap;
|
2017-10-09 18:43:00 +00:00
|
|
|
bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType));
|
|
|
|
bitmap.allocPixels();
|
|
|
|
SkDebugf("width:%d height:%d isNull:%s\n", bitmap.width(), bitmap.height(),
|
|
|
|
bitmap.isNull() ? "true" : "false");
|
|
|
|
bitmap.reset();
|
|
|
|
SkDebugf("width:%d height:%d isNull:%s\n", bitmap.width(), bitmap.height(),
|
|
|
|
bitmap.isNull() ? "true" : "false");
|
|
|
|
#StdOut
|
|
|
|
width:1 height:1 isNull:false
|
|
|
|
width:0 height:0 isNull:true
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso SkBitmap() SkAlphaType SkColorType
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method static bool ComputeIsOpaque(const SkBitmap& bm)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Utility
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns true if all pixels are opaque ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.setInfo(SkImageInfo::Make(2, 2, kN32_SkColorType, kPremul_SkAlphaType));
|
|
|
|
for (int index = 0; index < 2; ++index) {
|
|
|
|
bitmap.allocPixels();
|
|
|
|
bitmap.eraseColor(0x00000000);
|
|
|
|
SkDebugf("computeIsOpaque: %s\n", SkBitmap::ComputeIsOpaque(bitmap) ? "true" : "false");
|
|
|
|
bitmap.eraseColor(0xFFFFFFFF);
|
|
|
|
SkDebugf("computeIsOpaque: %s\n", SkBitmap::ComputeIsOpaque(bitmap) ? "true" : "false");
|
|
|
|
bitmap.setInfo(bitmap.info().makeAlphaType(kOpaque_SkAlphaType));
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
computeIsOpaque: false
|
|
|
|
computeIsOpaque: true
|
|
|
|
computeIsOpaque: false
|
|
|
|
computeIsOpaque: true
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso isOpaque Color_Type Alpha
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void getBounds(SkRect* bounds) const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns width() and height() as Rectangle ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 160
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
SkRect bounds;
|
|
|
|
source.getBounds(&bounds);
|
|
|
|
bounds.offset(100, 100);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorGRAY);
|
|
|
|
canvas->scale(.25f, .25f);
|
|
|
|
canvas->drawRect(bounds, paint);
|
|
|
|
canvas->drawBitmap(source, 40, 40);
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#SeeAlso bounds()
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void getBounds(SkIRect* bounds) const
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
SkIRect bounds;
|
|
|
|
source.getBounds(&bounds);
|
|
|
|
bounds.inset(100, 100);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
source.extractSubset(&bitmap, bounds);
|
|
|
|
canvas->scale(.5f, .5f);
|
|
|
|
canvas->drawBitmap(bitmap, 10, 10);
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#SeeAlso bounds()
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkIRect bounds() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns width() and height() as Rectangle ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2018-03-16 15:34:15 +00:00
|
|
|
#Height 64
|
2017-10-04 18:31:33 +00:00
|
|
|
#Image 4
|
2018-01-02 16:34:14 +00:00
|
|
|
canvas->scale(.5f, .5f);
|
2017-10-09 18:43:00 +00:00
|
|
|
SkIRect bounds = source.bounds();
|
|
|
|
for (int x : { 0, bounds.width() } ) {
|
|
|
|
for (int y : { 0, bounds.height() } ) {
|
|
|
|
canvas->drawBitmap(source, x, y);
|
|
|
|
}
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#SeeAlso getBounds
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkISize dimensions() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns width() and height() ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.setInfo(SkImageInfo::MakeN32(33, 55, kOpaque_SkAlphaType));
|
|
|
|
SkISize dimensions = bitmap.dimensions();
|
|
|
|
SkRect bounds;
|
|
|
|
bitmap.getBounds(&bounds);
|
|
|
|
SkRect dimensionsAsBounds = SkRect::Make(dimensions);
|
|
|
|
SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!');
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
2018-10-16 14:30:28 +00:00
|
|
|
#SeeAlso height width
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkIRect getSubset() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns bounds offset by origin ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
SkIRect bounds;
|
|
|
|
source.getBounds(&bounds);
|
|
|
|
bounds.inset(100, 100);
|
|
|
|
SkBitmap subset;
|
|
|
|
source.extractSubset(&subset, bounds);
|
|
|
|
SkIRect r = source.getSubset();
|
|
|
|
SkDebugf("source: %d, %d, %d, %d\n", r.fLeft, r.fTop, r.fRight, r.fBottom);
|
|
|
|
r = subset.getSubset();
|
|
|
|
SkDebugf("subset: %d, %d, %d, %d\n", r.fLeft, r.fTop, r.fRight, r.fBottom);
|
|
|
|
#StdOut
|
|
|
|
source: 0, 0, 512, 512
|
|
|
|
subset: 100, 100, 412, 412
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso extractSubset getBounds
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool setInfo(const SkImageInfo& imageInfo, size_t rowBytes = 0)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Set
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # sets height, width, Color_Type, and so on, releasing pixels ##
|
2017-10-04 18:31:33 +00:00
|
|
|
Sets width, height, Alpha_Type, Color_Type, Color_Space, and optional
|
|
|
|
rowBytes. Frees pixels, and returns true if successful.
|
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
imageInfo.alphaType() may be altered to a value permitted by imageInfo.colorSpace().
|
|
|
|
If imageInfo.colorType() is kUnknown_SkColorType, imageInfo.alphaType() is
|
2017-10-04 18:31:33 +00:00
|
|
|
set to kUnknown_SkAlphaType.
|
2018-11-07 19:59:03 +00:00
|
|
|
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
|
2017-10-04 18:31:33 +00:00
|
|
|
unchanged.
|
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
rowBytes must equal or exceed imageInfo.minRowBytes(). If imageInfo.colorSpace() is
|
2017-10-04 18:31:33 +00:00
|
|
|
kUnknown_SkColorType, rowBytes is ignored and treated as zero; for all other
|
2018-11-07 19:59:03 +00:00
|
|
|
Color_Space values, rowBytes of zero is treated as imageInfo.minRowBytes().
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
Calls reset() and returns false if:
|
|
|
|
#List
|
|
|
|
# rowBytes exceeds 31 bits ##
|
|
|
|
# imageInfo.width() is negative ##
|
|
|
|
# imageInfo.height() is negative ##
|
2018-11-07 19:59:03 +00:00
|
|
|
# rowBytes is positive and less than imageInfo.width() times imageInfo.bytesPerPixel() ##
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Param imageInfo contains width, height, Alpha_Type, Color_Type, Color_Space ##
|
2018-11-07 19:59:03 +00:00
|
|
|
#Param rowBytes imageInfo.minRowBytes() or larger; or zero ##
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Return true if Image_Info set successfully ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 96
|
|
|
|
###^
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.setInfo(SkImageInfo::MakeN32(44, 16, kOpaque_SkAlphaType));
|
|
|
|
bitmap.allocPixels();
|
|
|
|
bitmap.eraseColor(SK_ColorGREEN);
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
SkPaint paint;
|
|
|
|
offscreen.drawString("!@#$%", 0, 12, paint);
|
|
|
|
canvas->scale(6, 6);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
^^^#
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso Alpha_Type Color_Type Color_Space height rowBytes width
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Enum AllocFlags
|
2018-02-06 14:41:53 +00:00
|
|
|
#Line # zero pixel memory ##
|
2017-10-04 18:31:33 +00:00
|
|
|
#Code
|
2018-10-16 14:30:28 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
AllocFlags provides the option to zero pixel memory when allocated.
|
|
|
|
|
|
|
|
#Const kZeroPixels_AllocFlag 1
|
2018-05-16 11:07:07 +00:00
|
|
|
#Line # zero pixel memory ##
|
|
|
|
Instructs tryAllocPixelsFlags and allocPixelsFlags to zero pixel memory.
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#NoExample
|
|
|
|
##
|
|
|
|
|
2018-10-16 14:30:28 +00:00
|
|
|
#SeeAlso tryAllocPixelsFlags allocPixelsFlags erase eraseColor
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-07 12:27:09 +00:00
|
|
|
#Subtopic Allocate
|
|
|
|
#Line # allocates storage for pixels ##
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
|
2018-10-08 18:57:48 +00:00
|
|
|
#Method bool tryAllocPixelsFlags(const SkImageInfo& info, uint32_t flags)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Allocate
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # allocates pixels from Image_Info with options if possible ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
2018-05-16 11:07:07 +00:00
|
|
|
if (!bitmap.tryAllocPixelsFlags(SkImageInfo::MakeN32(10000, 10000, kOpaque_SkAlphaType),
|
2017-11-27 15:44:06 +00:00
|
|
|
SkBitmap::kZeroPixels_AllocFlag)) {
|
|
|
|
SkDebugf("bitmap allocation failed!\n");
|
|
|
|
} else {
|
|
|
|
SkDebugf("bitmap allocation succeeded!\n");
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
#StdOut
|
2017-11-27 15:44:06 +00:00
|
|
|
bitmap allocation succeeded!
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso allocPixelsFlags tryAllocPixels SkMallocPixelRef::MakeZeroed
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void allocPixelsFlags(const SkImageInfo& info, uint32_t flags)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Allocate
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # allocates pixels from Image_Info with options, or aborts ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
|
|
|
#Description
|
|
|
|
Text is drawn on a transparent background; drawing the bitmap a second time
|
|
|
|
lets the first draw show through.
|
|
|
|
##
|
|
|
|
###^
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
2018-05-16 11:07:07 +00:00
|
|
|
bitmap.allocPixelsFlags(SkImageInfo::MakeN32(44, 16, kPremul_SkAlphaType),
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap::kZeroPixels_AllocFlag);
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
SkPaint paint;
|
|
|
|
offscreen.drawString("!@#$%", 0, 12, paint);
|
|
|
|
canvas->scale(6, 6);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
canvas->drawBitmap(bitmap, 8, 8);
|
|
|
|
^^^#
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeZeroed
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-10-08 18:57:48 +00:00
|
|
|
#Method bool tryAllocPixels(const SkImageInfo& info, size_t rowBytes)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Allocate
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # allocates pixels from Image_Info if possible ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
SkImageInfo info = SkImageInfo::Make(64, 256, kGray_8_SkColorType, kOpaque_SkAlphaType);
|
|
|
|
if (bitmap.tryAllocPixels(info, 0)) {
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
offscreen.scale(.5f, .5f);
|
|
|
|
for (int x : { 0, 64, 128, 192 } ) {
|
|
|
|
offscreen.drawBitmap(source, -x, 0);
|
|
|
|
canvas->drawBitmap(bitmap, x, 0);
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeAllocate
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void allocPixels(const SkImageInfo& info, size_t rowBytes)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Allocate
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # allocates pixels from Image_Info, or aborts ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
SkImageInfo info = SkImageInfo::Make(256, 64, kGray_8_SkColorType, kOpaque_SkAlphaType);
|
|
|
|
bitmap.allocPixels(info, info.width() * info.bytesPerPixel() + 64);
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
offscreen.scale(.5f, .5f);
|
|
|
|
for (int y : { 0, 64, 128, 192 } ) {
|
|
|
|
offscreen.drawBitmap(source, 0, -y);
|
|
|
|
canvas->drawBitmap(bitmap, 0, y);
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso tryAllocPixels allocPixelsFlags SkMallocPixelRef::MakeAllocate
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-10-08 18:57:48 +00:00
|
|
|
#Method bool tryAllocPixels(const SkImageInfo& info)
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
if (bitmap.tryAllocPixels(SkImageInfo::Make(64, 64, kGray_8_SkColorType, kOpaque_SkAlphaType))) {
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
offscreen.scale(.25f, .5f);
|
|
|
|
for (int y : { 0, 64, 128, 192 } ) {
|
|
|
|
offscreen.drawBitmap(source, -y, -y);
|
|
|
|
canvas->drawBitmap(bitmap, y, y);
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeAllocate
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void allocPixels(const SkImageInfo& info)
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 4
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::Make(64, 64, kGray_8_SkColorType, kOpaque_SkAlphaType));
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
offscreen.scale(.5f, .5f);
|
|
|
|
for (int y : { 0, 64, 128, 192 } ) {
|
|
|
|
offscreen.drawBitmap(source, -y, -y);
|
|
|
|
canvas->drawBitmap(bitmap, y, y);
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso tryAllocPixels allocPixelsFlags SkMallocPixelRef::MakeAllocate
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-10-08 18:57:48 +00:00
|
|
|
#Method bool tryAllocN32Pixels(int width, int height, bool isOpaque = false)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Allocate
|
2018-05-17 16:17:28 +00:00
|
|
|
#Line # allocates compatible ARGB pixels if possible ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 160
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
if (bitmap.tryAllocN32Pixels(80, 80)) {
|
|
|
|
bitmap.eraseColor(SK_ColorTRANSPARENT);
|
|
|
|
bitmap.erase(0x7f3f7fff, SkIRect::MakeWH(50, 30));
|
|
|
|
bitmap.erase(0x3f7fff3f, SkIRect::MakeXYWH(20, 10, 50, 30));
|
|
|
|
bitmap.erase(0x5fff3f7f, SkIRect::MakeXYWH(40, 20, 50, 30));
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
for (int x : { 0, 30, 60, 90 } ) {
|
|
|
|
canvas->drawBitmap(bitmap, x, 70);
|
|
|
|
}
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso tryAllocPixels allocN32Pixels SkMallocPixelRef::MakeAllocate
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void allocN32Pixels(int width, int height, bool isOpaque = false)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Allocate
|
2018-05-17 16:17:28 +00:00
|
|
|
#Line # allocates compatible ARGB pixels, or aborts ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkRandom random;
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocN32Pixels(64, 64);
|
|
|
|
bitmap.eraseColor(SK_ColorTRANSPARENT);
|
|
|
|
for (int y = 0; y < 256; y += 64) {
|
|
|
|
for (int x = 0; x < 256; x += 64) {
|
|
|
|
SkColor color = random.nextU();
|
|
|
|
uint32_t w = random.nextRangeU(4, 32);
|
|
|
|
uint32_t cx = random.nextRangeU(0, 64 - w);
|
|
|
|
uint32_t h = random.nextRangeU(4, 32);
|
|
|
|
uint32_t cy = random.nextRangeU(0, 64 - h);
|
|
|
|
bitmap.erase(color, SkIRect::MakeXYWH(cx, cy, w, h));
|
|
|
|
canvas->drawBitmap(bitmap, x, y);
|
|
|
|
}
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso allocPixels tryAllocN32Pixels SkMallocPixelRef::MakeAllocate
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
|
|
|
void (*releaseProc)(void* addr, void* context), void* context)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Allocate
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # creates Pixel_Ref, with optional release function ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
releaseProc is called immediately because rowBytes is too small for Pixel_Ref.
|
|
|
|
##
|
|
|
|
#Function
|
2017-10-09 18:43:00 +00:00
|
|
|
static void releaseProc(void* addr, void* ) {
|
|
|
|
SkDebugf("releaseProc called\n");
|
2018-05-16 11:07:07 +00:00
|
|
|
delete[] (uint32_t*) addr;
|
2017-10-09 18:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
void* pixels = new uint32_t[8 * 8];
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32(8, 8, kOpaque_SkAlphaType);
|
|
|
|
SkDebugf("before installPixels\n");
|
|
|
|
bool installed = bitmap.installPixels(info, pixels, 16, releaseProc, nullptr);
|
|
|
|
SkDebugf("install " "%s" "successful\n", installed ? "" : "not ");
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
#StdOut
|
2017-10-09 18:43:00 +00:00
|
|
|
before installPixels
|
|
|
|
releaseProc called
|
2017-10-04 18:31:33 +00:00
|
|
|
install not successful
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso allocPixels
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes)
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2018-02-06 14:41:53 +00:00
|
|
|
#Bug 7079
|
2017-10-04 18:31:33 +00:00
|
|
|
#Description
|
|
|
|
GPU does not support kUnpremul_SkAlphaType, does not assert that it does not.
|
|
|
|
##
|
2017-10-09 18:43:00 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkRandom random;
|
|
|
|
SkBitmap bitmap;
|
|
|
|
const int width = 8;
|
|
|
|
const int height = 8;
|
|
|
|
uint32_t pixels[width * height];
|
|
|
|
for (unsigned x = 0; x < width * height; ++x) {
|
|
|
|
pixels[x] = random.nextU();
|
|
|
|
}
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32(width, height, kUnpremul_SkAlphaType);
|
|
|
|
if (bitmap.installPixels(info, pixels, info.minRowBytes())) {
|
|
|
|
canvas->scale(32, 32);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso allocPixels
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool installPixels(const SkPixmap& pixmap)
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
Draw a five by five bitmap, and draw it again with a center white pixel.
|
|
|
|
##
|
|
|
|
#Height 64
|
|
|
|
uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
|
|
|
|
{ 0xAC, 0xA8, 0x89, 0x47, 0x87 },
|
|
|
|
{ 0x4B, 0x25, 0x25, 0x25, 0x46 },
|
|
|
|
{ 0x90, 0x81, 0x25, 0x41, 0x33 },
|
|
|
|
{ 0x75, 0x55, 0x44, 0x20, 0x00 }};
|
|
|
|
SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType);
|
|
|
|
SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(pixmap);
|
|
|
|
canvas->scale(10, 10);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
*pixmap.writable_addr8(2, 2) = 0xFF;
|
|
|
|
bitmap.installPixels(pixmap);
|
|
|
|
canvas->drawBitmap(bitmap, 10, 0);
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso allocPixels
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-07 12:27:09 +00:00
|
|
|
#Subtopic Pixels
|
|
|
|
#Line # read and write pixel values ##
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Method void setPixels(void* pixels)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Pixels
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # sets Pixel_Ref without an offset ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 50
|
2017-10-09 18:43:00 +00:00
|
|
|
uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 };
|
|
|
|
uint8_t set2[5] = { 0xAC, 0xA8, 0x89, 0x47, 0x87 };
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5);
|
|
|
|
canvas->scale(10, 50);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
bitmap.setPixels(set2);
|
|
|
|
canvas->drawBitmap(bitmap, 10, 0);
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso installPixels allocPixels
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-10-08 18:57:48 +00:00
|
|
|
#Method bool tryAllocPixels()
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Allocate
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 50
|
2018-05-16 11:07:07 +00:00
|
|
|
#Description
|
2017-10-04 18:31:33 +00:00
|
|
|
Bitmap hosts and draws gray values in set1. tryAllocPixels replaces Pixel_Ref
|
|
|
|
and erases it to black, but does not alter set1. setPixels replaces black
|
2018-05-16 11:07:07 +00:00
|
|
|
Pixel_Ref with set1.
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
2017-10-09 18:43:00 +00:00
|
|
|
uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 };
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5);
|
|
|
|
canvas->scale(10, 50);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
if (bitmap.tryAllocPixels()) {
|
|
|
|
bitmap.eraseColor(SK_ColorBLACK);
|
|
|
|
canvas->drawBitmap(bitmap, 8, 0);
|
|
|
|
bitmap.setPixels(set1);
|
|
|
|
canvas->drawBitmap(bitmap, 16, 0);
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso allocPixels installPixels setPixels
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void allocPixels()
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Allocate
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 50
|
2018-05-16 11:07:07 +00:00
|
|
|
#Description
|
2017-10-04 18:31:33 +00:00
|
|
|
Bitmap hosts and draws gray values in set1. allocPixels replaces Pixel_Ref
|
|
|
|
and erases it to black, but does not alter set1. setPixels replaces black
|
2018-05-16 11:07:07 +00:00
|
|
|
Pixel_Ref with set2.
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
2017-10-09 18:43:00 +00:00
|
|
|
uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 };
|
|
|
|
uint8_t set2[5] = { 0xAC, 0xA8, 0x89, 0x47, 0x87 };
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5);
|
|
|
|
canvas->scale(10, 50);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
bitmap.allocPixels();
|
|
|
|
bitmap.eraseColor(SK_ColorBLACK);
|
|
|
|
canvas->drawBitmap(bitmap, 8, 0);
|
|
|
|
bitmap.setPixels(set2);
|
2017-10-04 18:31:33 +00:00
|
|
|
canvas->drawBitmap(bitmap, 16, 0);
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso tryAllocPixels installPixels setPixels
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-10-08 18:57:48 +00:00
|
|
|
#Method bool tryAllocPixels(Allocator* allocator)
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 100
|
|
|
|
#Description
|
|
|
|
HeapAllocator limits the maximum size of Bitmap to two gigabytes. Using
|
|
|
|
a custom allocator, this limitation may be relaxed. This example can be
|
2018-05-16 11:07:07 +00:00
|
|
|
modified to allocate an eight gigabyte Bitmap on a 64-bit platform with
|
2017-10-04 18:31:33 +00:00
|
|
|
sufficient memory.
|
|
|
|
##
|
|
|
|
#Function
|
|
|
|
class LargePixelRef : public SkPixelRef {
|
|
|
|
public:
|
|
|
|
LargePixelRef(const SkImageInfo& info, char* storage, size_t rowBytes)
|
|
|
|
: SkPixelRef(info.width(), info.height(), storage, rowBytes) {
|
|
|
|
}
|
|
|
|
|
|
|
|
~LargePixelRef() override {
|
|
|
|
delete[] (char* ) this->pixels();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class LargeAllocator : public SkBitmap::Allocator {
|
|
|
|
public:
|
|
|
|
bool allocPixelRef(SkBitmap* bitmap) override {
|
|
|
|
const SkImageInfo& info = bitmap->info();
|
|
|
|
uint64_t rowBytes = info.minRowBytes64();
|
|
|
|
uint64_t size = info.height() * rowBytes;
|
|
|
|
char* addr = new char[size];
|
|
|
|
if (nullptr == addr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sk_sp<SkPixelRef> pr = sk_sp<SkPixelRef>(new LargePixelRef(info, addr, rowBytes));
|
|
|
|
if (!pr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bitmap->setPixelRef(std::move(pr), 0, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
LargeAllocator largeAllocator;
|
|
|
|
SkBitmap bitmap;
|
2017-10-09 18:43:00 +00:00
|
|
|
int width = 100; // make this 20000
|
|
|
|
int height = 100; // and this 100000 to allocate 8 gigs on a 64-bit platform
|
|
|
|
bitmap.setInfo(SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType));
|
|
|
|
if (bitmap.tryAllocPixels(&largeAllocator)) {
|
|
|
|
bitmap.eraseColor(0xff55aa33);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso allocPixels Allocator Pixel_Ref
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void allocPixels(Allocator* allocator)
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 32
|
|
|
|
#Function
|
|
|
|
class TinyAllocator : public SkBitmap::Allocator {
|
|
|
|
public:
|
|
|
|
bool allocPixelRef(SkBitmap* bitmap) override {
|
|
|
|
const SkImageInfo& info = bitmap->info();
|
|
|
|
if (info.height() * info.minRowBytes() > sizeof(storage)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sk_sp<SkPixelRef> pr = sk_sp<SkPixelRef>(
|
|
|
|
new SkPixelRef(info.width(), info.height(), storage, info.minRowBytes()));
|
|
|
|
bitmap->setPixelRef(std::move(pr), 0, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
char storage[16];
|
|
|
|
};
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
TinyAllocator tinyAllocator;
|
|
|
|
SkBitmap bitmap;
|
2017-10-09 18:43:00 +00:00
|
|
|
bitmap.setInfo(SkImageInfo::MakeN32(2, 2, kOpaque_SkAlphaType));
|
|
|
|
if (bitmap.tryAllocPixels(&tinyAllocator)) {
|
|
|
|
bitmap.eraseColor(0xff55aa33);
|
|
|
|
bitmap.erase(0xffaa3355, SkIRect::MakeXYWH(1, 1, 1, 1));
|
|
|
|
canvas->scale(16, 16);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso allocPixels Allocator Pixel_Ref
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkPixelRef* pixelRef() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns Pixel_Ref, or nullptr ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap subset;
|
|
|
|
source.extractSubset(&subset, SkIRect::MakeXYWH(32, 64, 128, 256));
|
|
|
|
SkDebugf("src ref %c= sub ref\n", source.pixelRef() == subset.pixelRef() ? '=' : '!');
|
|
|
|
SkDebugf("src pixels %c= sub pixels\n", source.getPixels() == subset.getPixels() ? '=' : '!');
|
|
|
|
SkDebugf("src addr %c= sub addr\n", source.getAddr(32, 64) == subset.getAddr(0, 0) ? '=' : '!');
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso getPixels getAddr
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkIPoint pixelRefOrigin() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns offset within Pixel_Ref ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap subset;
|
|
|
|
source.extractSubset(&subset, SkIRect::MakeXYWH(32, 64, 128, 256));
|
|
|
|
SkIPoint sourceOrigin = source.pixelRefOrigin();
|
|
|
|
SkIPoint subsetOrigin = subset.pixelRefOrigin();
|
|
|
|
SkDebugf("source origin: %d, %d\n", sourceOrigin.fX, sourceOrigin.fY);
|
|
|
|
SkDebugf("subset origin: %d, %d\n", subsetOrigin.fX, subsetOrigin.fY);
|
|
|
|
#StdOut
|
|
|
|
source origin: 0, 0
|
|
|
|
subset origin: 32, 64
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SkPixelRef getSubset setPixelRef
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-07 12:27:09 +00:00
|
|
|
#Subtopic Set
|
|
|
|
#Line # updates values and attributes ##
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Method void setPixelRef(sk_sp<SkPixelRef> pixelRef, int dx, int dy)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Set
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # sets Pixel_Ref and offset ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 140
|
|
|
|
#Image 5
|
|
|
|
#Description
|
2018-05-16 11:07:07 +00:00
|
|
|
Treating 32-bit data as 8-bit data is unlikely to produce useful results.
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
2018-05-16 11:07:07 +00:00
|
|
|
bitmap.setInfo(SkImageInfo::Make(source.width() - 5, source.height() - 5,
|
2017-10-09 18:43:00 +00:00
|
|
|
kGray_8_SkColorType, kOpaque_SkAlphaType), source.rowBytes());
|
|
|
|
bitmap.setPixelRef(sk_ref_sp(source.pixelRef()), 5, 5);
|
|
|
|
canvas->drawBitmap(bitmap, 10, 10);
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso setInfo
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool readyToDraw() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Utility
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns true if address of pixels is not nullptr ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 5
|
|
|
|
#Height 160
|
2017-10-09 18:43:00 +00:00
|
|
|
if (source.readyToDraw()) {
|
|
|
|
canvas->drawBitmap(source, 10, 10);
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso getPixels drawsNothing
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method uint32_t getGenerationID() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Utility
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns unique ID ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
SkDebugf("empty id %u\n", bitmap.getGenerationID());
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType));
|
|
|
|
SkDebugf("alloc id %u\n", bitmap.getGenerationID());
|
|
|
|
bitmap.eraseColor(SK_ColorRED);
|
2017-10-04 18:31:33 +00:00
|
|
|
SkDebugf("erase id %u\n", bitmap.getGenerationID());
|
|
|
|
#StdOut
|
|
|
|
#Volatile
|
2017-10-09 18:43:00 +00:00
|
|
|
empty id 0
|
|
|
|
alloc id 4
|
2017-10-04 18:31:33 +00:00
|
|
|
erase id 6
|
2018-05-16 11:07:07 +00:00
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso notifyPixelsChanged Pixel_Ref
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void notifyPixelsChanged() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Pixels
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # marks pixels as changed, altering the unique ID ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 20
|
2018-05-16 11:07:07 +00:00
|
|
|
SkBitmap bitmap;
|
2017-10-09 18:43:00 +00:00
|
|
|
bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType));
|
|
|
|
bitmap.allocPixels();
|
|
|
|
bitmap.eraseColor(SK_ColorRED);
|
|
|
|
canvas->scale(16, 16);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
*(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorBLUE);
|
|
|
|
canvas->drawBitmap(bitmap, 2, 0);
|
|
|
|
bitmap.notifyPixelsChanged();
|
|
|
|
*(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorGREEN);
|
|
|
|
canvas->drawBitmap(bitmap, 4, 0);
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso getGenerationID isVolatile Pixel_Ref
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-07 12:27:09 +00:00
|
|
|
#Subtopic Draw
|
2018-05-16 11:07:07 +00:00
|
|
|
#Line # sets pixels to Color ##
|
2018-02-07 12:27:09 +00:00
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Method void eraseColor(SkColor c) const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # writes Color to pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 20
|
2018-05-16 11:07:07 +00:00
|
|
|
SkBitmap bitmap;
|
2017-10-09 18:43:00 +00:00
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kOpaque_SkAlphaType));
|
|
|
|
bitmap.eraseColor(SK_ColorRED);
|
|
|
|
canvas->scale(16, 16);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
2017-10-26 11:58:48 +00:00
|
|
|
#SeeAlso eraseARGB erase
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # writes Color to pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 80
|
2018-05-16 11:07:07 +00:00
|
|
|
SkBitmap bitmap;
|
2017-10-09 18:43:00 +00:00
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType));
|
|
|
|
bitmap.eraseARGB(0x7f, 0xff, 0x7f, 0x3f);
|
|
|
|
canvas->scale(50, 50);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
canvas->drawBitmap(bitmap, .5f, .5f);
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
2017-10-26 11:58:48 +00:00
|
|
|
#SeeAlso eraseColor erase
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void erase(SkColor c, const SkIRect& area) const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # writes Color to rectangle of pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 70
|
2018-05-16 11:07:07 +00:00
|
|
|
SkBitmap bitmap;
|
2017-10-09 18:43:00 +00:00
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32(2, 2, kPremul_SkAlphaType));
|
|
|
|
bitmap.erase(0x7fff7f3f, SkIRect::MakeWH(1, 1));
|
|
|
|
bitmap.erase(0x7f7f3fff, SkIRect::MakeXYWH(0, 1, 1, 1));
|
|
|
|
bitmap.erase(0x7f3fff7f, SkIRect::MakeXYWH(1, 0, 1, 1));
|
|
|
|
bitmap.erase(0x7f1fbf5f, SkIRect::MakeXYWH(1, 1, 1, 1));
|
|
|
|
canvas->scale(25, 25);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
canvas->drawBitmap(bitmap, .5f, .5f);
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-10-04 14:18:13 +00:00
|
|
|
#SeeAlso eraseColor eraseARGB SkCanvas::drawRect
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkColor getColor(int x, int y) const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
|
|
|
#In Pixels
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns one pixel as Unpremultiplied Color ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
const int w = 4;
|
|
|
|
const int h = 4;
|
|
|
|
SkColor colors[][w] = {
|
2018-06-20 16:45:16 +00:00
|
|
|
{ 0x00000000, 0x2a0e002a, 0x55380055, 0x7f7f007f },
|
|
|
|
{ 0x2a000e2a, 0x551c1c55, 0x7f542a7f, 0xaaaa38aa },
|
|
|
|
{ 0x55003855, 0x7f2a547f, 0xaa7171aa, 0xd4d48dd4 },
|
|
|
|
{ 0x7f007f7f, 0xaa38aaaa, 0xd48dd4d4, 0xffffffff }
|
2017-10-04 18:31:33 +00:00
|
|
|
};
|
|
|
|
SkDebugf("Premultiplied:\n");
|
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
SkDebugf("(0, %d) ", y);
|
|
|
|
for (int x = 0; x < w; ++x) {
|
|
|
|
SkDebugf("0x%08x%c", colors[y][x], x == w - 1 ? '\n' : ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), colors, w * 4);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(pixmap);
|
|
|
|
SkDebugf("Unpremultiplied:\n");
|
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
SkDebugf("(0, %d) ", y);
|
|
|
|
for (int x = 0; x < w; ++x) {
|
|
|
|
SkDebugf("0x%08x%c", bitmap.getColor(x, y), x == w - 1 ? '\n' : ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
Premultiplied:
|
2018-05-16 11:07:07 +00:00
|
|
|
(0, 0) 0x00000000 0x2a0e002a 0x55380055 0x7f7f007f
|
|
|
|
(0, 1) 0x2a000e2a 0x551c1c55 0x7f542a7f 0xaaaa38aa
|
|
|
|
(0, 2) 0x55003855 0x7f2a547f 0xaa7171aa 0xd4d48dd4
|
|
|
|
(0, 3) 0x7f007f7f 0xaa38aaaa 0xd48dd4d4 0xffffffff
|
2017-10-04 18:31:33 +00:00
|
|
|
Unpremultiplied:
|
2018-05-16 11:07:07 +00:00
|
|
|
(0, 0) 0x00000000 0x2a5500ff 0x55a800ff 0x7fff00ff
|
|
|
|
(0, 1) 0x2a0055ff 0x555454ff 0x7fa954ff 0xaaff54ff
|
|
|
|
(0, 2) 0x5500a8ff 0x7f54a9ff 0xaaaaaaff 0xd4ffaaff
|
|
|
|
(0, 3) 0x7f00ffff 0xaa54ffff 0xd4aaffff 0xffffffff
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2018-09-20 21:31:43 +00:00
|
|
|
#SeeAlso getAlphaf getAddr readPixels
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-09-20 21:31:43 +00:00
|
|
|
#Method float getAlphaf(int x, int y) const
|
|
|
|
#In Property
|
|
|
|
#Line # returns Alpha normalized from zero to one ##
|
|
|
|
|
|
|
|
Looks up the pixel at (x,y) and return its alpha component, normalized to [0..1].
|
2018-11-07 19:59:03 +00:00
|
|
|
This is roughly equivalent to #Formula # SkGetColorA(getColor()) ##, but can be more efficient
|
2018-09-20 21:31:43 +00:00
|
|
|
(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 ##
|
|
|
|
|
|
|
|
#NoExample
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso getColor
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void* getAddr(int x, int y) const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns readable pixel address as void pointer ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
char* row0 = (char* ) source.getAddr(0, 0);
|
|
|
|
char* row1 = (char* ) source.getAddr(0, 1);
|
2018-03-16 15:34:15 +00:00
|
|
|
SkDebugf("addr interval %c= rowBytes\n",
|
|
|
|
(size_t) (row1 - row0) == source.rowBytes() ? '=' : '!');
|
2017-10-09 18:43:00 +00:00
|
|
|
#StdOut
|
|
|
|
addr interval == rowBytes
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso getAddr8 getAddr16 getAddr32 readPixels SkPixmap::addr
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-10-08 18:57:48 +00:00
|
|
|
#Method uint32_t* getAddr32(int x, int y) const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns readable pixel address as 32-bit pointer ##
|
2018-05-16 11:07:07 +00:00
|
|
|
Returns address at (x, y).
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
|
|
|
|
#List
|
|
|
|
# Pixel_Ref 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) ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
uint32_t* row0 = source.getAddr32(0, 0);
|
|
|
|
uint32_t* row1 = source.getAddr32(0, 1);
|
|
|
|
size_t interval = (row1 - row0) * source.bytesPerPixel();
|
|
|
|
SkDebugf("addr interval %c= rowBytes\n", interval == source.rowBytes() ? '=' : '!');
|
|
|
|
#StdOut
|
|
|
|
addr interval == rowBytes
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso getAddr8 getAddr16 getAddr readPixels SkPixmap::addr32
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-10-08 18:57:48 +00:00
|
|
|
#Method uint16_t* getAddr16(int x, int y) const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns readable pixel address as 16-bit pointer ##
|
2018-05-16 11:07:07 +00:00
|
|
|
Returns address at (x, y).
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
|
|
|
|
#List
|
|
|
|
# Pixel_Ref 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)##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap16;
|
2018-05-16 11:07:07 +00:00
|
|
|
SkImageInfo dstInfo = SkImageInfo::Make(source.width(), source.height(), kARGB_4444_SkColorType,
|
2017-10-09 18:43:00 +00:00
|
|
|
kPremul_SkAlphaType);
|
|
|
|
bitmap16.allocPixels(dstInfo);
|
|
|
|
if (source.readPixels(dstInfo, bitmap16.getPixels(), bitmap16.rowBytes(), 0, 0)) {
|
|
|
|
uint16_t* row0 = bitmap16.getAddr16(0, 0);
|
|
|
|
uint16_t* row1 = bitmap16.getAddr16(0, 1);
|
|
|
|
size_t interval = (row1 - row0) * bitmap16.bytesPerPixel();
|
|
|
|
SkDebugf("addr interval %c= rowBytes\n", interval == bitmap16.rowBytes() ? '=' : '!');
|
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
addr interval == rowBytes
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso getAddr8 getAddr getAddr32 readPixels SkPixmap::addr16
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-10-08 18:57:48 +00:00
|
|
|
#Method uint8_t* getAddr8(int x, int y) const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns readable pixel address as 8-bit pointer ##
|
2018-05-16 11:07:07 +00:00
|
|
|
Returns address at (x, y).
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
Input is not validated. Triggers an assert() if built with SK_DEBUG defined and:
|
|
|
|
#List
|
|
|
|
# Pixel_Ref 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) ##
|
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
const int width = 8;
|
|
|
|
const int height = 8;
|
|
|
|
uint8_t pixels[height][width];
|
|
|
|
SkImageInfo info = SkImageInfo::Make(width, height, kGray_8_SkColorType, kOpaque_SkAlphaType);
|
|
|
|
if (bitmap.installPixels(info, pixels, info.minRowBytes())) {
|
|
|
|
SkDebugf("&pixels[4][2] %c= bitmap.getAddr8(2, 4)\n",
|
|
|
|
&pixels[4][2] == bitmap.getAddr8(2, 4) ? '=' : '!');
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
#StdOut
|
|
|
|
&pixels[4][2] == bitmap.getAddr8(2, 4)
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso getAddr getAddr16 getAddr32 readPixels SkPixmap::addr8
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool extractSubset(SkBitmap* dst, const SkIRect& subset) const
|
2018-10-08 18:57:48 +00:00
|
|
|
#In Constructors
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # creates Bitmap, sharing pixels if possible ##
|
2017-10-04 18:31:33 +00:00
|
|
|
Shares Pixel_Ref with dst. Pixels are not copied; Bitmap 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:
|
|
|
|
#List
|
|
|
|
# dst is nullptr ##
|
|
|
|
# Pixel_Ref is nullptr ##
|
|
|
|
# subset does not intersect bounds() ##
|
2018-05-16 11:07:07 +00:00
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Param dst Bitmap set to subset ##
|
|
|
|
#Param subset rectangle of pixels to reference ##
|
|
|
|
|
|
|
|
#Return true if dst is replaced by subset
|
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
SkIRect bounds, s;
|
|
|
|
source.getBounds(&bounds);
|
|
|
|
SkDebugf("bounds: %d, %d, %d, %d\n", bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
|
|
|
|
SkBitmap subset;
|
|
|
|
for (int left: { -100, 0, 100, 1000 } ) {
|
|
|
|
for (int right: { 0, 100, 1000 } ) {
|
|
|
|
SkIRect b = SkIRect::MakeLTRB(left, 100, right, 200);
|
|
|
|
bool success = source.extractSubset(&subset, b);
|
|
|
|
SkDebugf("subset: %4d, %4d, %4d, %4d ", b.fLeft, b.fTop, b.fRight, b.fBottom);
|
|
|
|
SkDebugf("success; %s", success ? "true" : "false");
|
|
|
|
if (success) {
|
2018-05-16 11:07:07 +00:00
|
|
|
subset.getBounds(&s);
|
2017-10-09 18:43:00 +00:00
|
|
|
SkDebugf(" subset: %d, %d, %d, %d", s.fLeft, s.fTop, s.fRight, s.fBottom);
|
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
2018-05-16 11:07:07 +00:00
|
|
|
}
|
2017-10-09 18:43:00 +00:00
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
#StdOut
|
2017-10-09 18:43:00 +00:00
|
|
|
bounds: 0, 0, 512, 512
|
|
|
|
subset: -100, 100, 0, 200 success; false
|
|
|
|
subset: -100, 100, 100, 200 success; true subset: 0, 0, 100, 100
|
|
|
|
subset: -100, 100, 1000, 200 success; true subset: 0, 0, 512, 100
|
|
|
|
subset: 0, 100, 0, 200 success; false
|
|
|
|
subset: 0, 100, 100, 200 success; true subset: 0, 0, 100, 100
|
|
|
|
subset: 0, 100, 1000, 200 success; true subset: 0, 0, 512, 100
|
|
|
|
subset: 100, 100, 0, 200 success; false
|
|
|
|
subset: 100, 100, 100, 200 success; false
|
|
|
|
subset: 100, 100, 1000, 200 success; true subset: 0, 0, 412, 100
|
|
|
|
subset: 1000, 100, 0, 200 success; false
|
|
|
|
subset: 1000, 100, 100, 200 success; false
|
2017-10-04 18:31:33 +00:00
|
|
|
subset: 1000, 100, 1000, 200 success; false
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso readPixels writePixels SkCanvas::drawBitmap
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
|
|
|
|
int srcX, int srcY) const
|
2018-07-17 17:19:56 +00:00
|
|
|
#In Pixels
|
2018-10-31 16:14:03 +00:00
|
|
|
#Line # copies and converts pixels ##
|
2017-10-04 18:31:33 +00:00
|
|
|
|
2018-01-11 15:35:44 +00:00
|
|
|
Copies a Rect of pixels from Bitmap to dstPixels. Copy starts at (srcX, srcY),
|
2018-05-16 11:07:07 +00:00
|
|
|
and does not exceed Bitmap (width(), height()).
|
2017-10-04 18:31:33 +00:00
|
|
|
|
2018-01-11 15:35:44 +00:00
|
|
|
dstInfo specifies width, height, Color_Type, Alpha_Type, and Color_Space of
|
|
|
|
destination. dstRowBytes specifics the gap from one destination row to the next.
|
|
|
|
Returns true if pixels are copied. Returns false if:
|
2017-10-04 18:31:33 +00:00
|
|
|
#List
|
2018-10-31 16:14:03 +00:00
|
|
|
# dstInfo has no address ##
|
2018-11-07 19:59:03 +00:00
|
|
|
# dstRowBytes is less than dstInfo.minRowBytes() ##
|
2017-10-04 18:31:33 +00:00
|
|
|
# Pixel_Ref is nullptr ##
|
|
|
|
##
|
|
|
|
|
2018-01-11 15:35:44 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
|
2018-11-07 19:59:03 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; dstInfo.colorType() must match.
|
|
|
|
If Bitmap colorType is kGray_8_SkColorType, dstInfo.colorSpace() must match.
|
|
|
|
If Bitmap alphaType is kOpaque_SkAlphaType, dstInfo.alphaType() must
|
|
|
|
match. If Bitmap colorSpace is nullptr, dstInfo.colorSpace() must match. Returns
|
2017-10-04 18:31:33 +00:00
|
|
|
false if pixel conversion is not possible.
|
2018-05-16 11:07:07 +00:00
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
srcX and srcY may be negative to copy only top or left of source. Returns
|
2017-10-26 11:58:48 +00:00
|
|
|
false if width() or height() is zero or negative.
|
Condense embedded formulas.
Bookmaker delimits formulas and equations to allow
representing variables and symbols without tripping
up reference lookup, spell checking, and comment
generation.
Before, formulas were represented with:
some text
#Formula
(x + y, 0)
##
, and more text
This made it difficult to know when spacing should
be preserved before and after the formula. Now,
formulas are represented with:
some text #Formula # (x + y, 0) ##, and more text
The presence or absence of a space between ## and ,
is now significant (before it was not).
Also, formulas are bracketed by <code> in markdown
generation, so that variables stand out better.
See:
https://skia.org/user/api/SkBlendMode_Reference?cl=152781#Dst_Out
for an example.
Also fixed 100 column offenders and added a code
check to identify them. For the moment, 100 column
offenders are outed with SkDebugf but their presence
does not cause bookmaker to fail.
TBR=caryclark@google.com
Docs-Preview: https://skia.org/?cl=152781
Bug: skia:6898
Change-Id: If92a65a234f5d616bf4485984a8d219a6f04821a
Reviewed-on: https://skia-review.googlesource.com/152781
Commit-Queue: Cary Clark <caryclark@skia.org>
Auto-Submit: Cary Clark <caryclark@skia.org>
Reviewed-by: Cary Clark <caryclark@skia.org>
2018-09-13 16:04:30 +00:00
|
|
|
Returns false if #Formula # abs(srcX) >= Bitmap width() ##, or if #Formula # abs(srcY) >= Bitmap height() ##.
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Param dstInfo destination width, height, Color_Type, Alpha_Type, Color_Space ##
|
|
|
|
#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 ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
|
|
|
#Description
|
|
|
|
Transferring the gradient from 8 bits per component to 4 bits per component
|
|
|
|
creates visible banding.
|
|
|
|
##
|
2017-10-09 18:43:00 +00:00
|
|
|
const int width = 256;
|
|
|
|
const int height = 64;
|
|
|
|
SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height);
|
|
|
|
SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 };
|
|
|
|
SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } };
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
|
|
|
|
SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode));
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(srcInfo);
|
|
|
|
SkCanvas srcCanvas(bitmap);
|
|
|
|
srcCanvas.drawRect(SkRect::MakeWH(width, height), paint);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType);
|
|
|
|
std::vector<int16_t> dstPixels;
|
|
|
|
dstPixels.resize(height * width);
|
|
|
|
bitmap.readPixels(dstInfo, &dstPixels.front(), width * 2, 0, 0);
|
|
|
|
SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2);
|
|
|
|
bitmap.installPixels(dstPixmap);
|
2017-10-04 18:31:33 +00:00
|
|
|
canvas->drawBitmap(bitmap, 0, 64);
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool readPixels(const SkPixmap& dst, int srcX, int srcY) const
|
|
|
|
|
2018-01-11 15:35:44 +00:00
|
|
|
Copies a Rect of pixels from Bitmap to dst. Copy starts at (srcX, srcY), and
|
2018-05-16 11:07:07 +00:00
|
|
|
does not exceed Bitmap (width(), height()).
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
|
2018-11-07 19:59:03 +00:00
|
|
|
and row bytes of destination. dst.rowBytes() specifics the gap from one destination
|
2017-10-04 18:31:33 +00:00
|
|
|
row to the next. Returns true if pixels are copied. Returns false if:
|
|
|
|
#List
|
|
|
|
# dst pixel storage equals nullptr ##
|
2018-11-07 19:59:03 +00:00
|
|
|
# dst.rowBytes() is less than SkImageInfo::minRowBytes() ##
|
2017-10-04 18:31:33 +00:00
|
|
|
# Pixel_Ref is nullptr ##
|
|
|
|
##
|
|
|
|
|
2018-01-11 15:35:44 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
|
2017-10-04 18:31:33 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
|
2018-01-11 15:35:44 +00:00
|
|
|
If Bitmap colorType is kGray_8_SkColorType, dst Color_Space must match.
|
|
|
|
If Bitmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
|
|
|
|
match. If Bitmap colorSpace is nullptr, dst Color_Space must match. Returns
|
2017-10-04 18:31:33 +00:00
|
|
|
false if pixel conversion is not possible.
|
2018-05-16 11:07:07 +00:00
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
srcX and srcY may be negative to copy only top or left of source. Returns
|
2018-05-16 11:07:07 +00:00
|
|
|
false if width() or height() is zero or negative.
|
Condense embedded formulas.
Bookmaker delimits formulas and equations to allow
representing variables and symbols without tripping
up reference lookup, spell checking, and comment
generation.
Before, formulas were represented with:
some text
#Formula
(x + y, 0)
##
, and more text
This made it difficult to know when spacing should
be preserved before and after the formula. Now,
formulas are represented with:
some text #Formula # (x + y, 0) ##, and more text
The presence or absence of a space between ## and ,
is now significant (before it was not).
Also, formulas are bracketed by <code> in markdown
generation, so that variables stand out better.
See:
https://skia.org/user/api/SkBlendMode_Reference?cl=152781#Dst_Out
for an example.
Also fixed 100 column offenders and added a code
check to identify them. For the moment, 100 column
offenders are outed with SkDebugf but their presence
does not cause bookmaker to fail.
TBR=caryclark@google.com
Docs-Preview: https://skia.org/?cl=152781
Bug: skia:6898
Change-Id: If92a65a234f5d616bf4485984a8d219a6f04821a
Reviewed-on: https://skia-review.googlesource.com/152781
Commit-Queue: Cary Clark <caryclark@skia.org>
Auto-Submit: Cary Clark <caryclark@skia.org>
Reviewed-by: Cary Clark <caryclark@skia.org>
2018-09-13 16:04:30 +00:00
|
|
|
Returns false if #Formula # abs(srcX) >= Bitmap width() ##, or if #Formula # abs(srcY) >= Bitmap height() ##.
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Param dst destination Pixmap: Image_Info, 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 ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
std::vector<int32_t> srcPixels;
|
|
|
|
srcPixels.resize(source.height() * source.rowBytes());
|
|
|
|
for (int y = 0; y < 4; ++y) {
|
|
|
|
for (int x = 0; x < 4; ++x) {
|
|
|
|
SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width() / 4, source.height() / 4),
|
|
|
|
&srcPixels.front() + x * source.height() * source.width() / 4 +
|
|
|
|
y * source.width() / 4, source.rowBytes());
|
|
|
|
source.readPixels(pixmap, x * source.width() / 4, y * source.height() / 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
canvas->scale(.5f, .5f);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(SkImageInfo::MakeN32Premul(source.width(), source.height()),
|
|
|
|
&srcPixels.front(), source.rowBytes());
|
2017-10-04 18:31:33 +00:00
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool readPixels(const SkPixmap& dst) const
|
|
|
|
|
2018-01-11 15:35:44 +00:00
|
|
|
Copies a Rect of pixels from Bitmap to dst. Copy starts at (0, 0), and
|
2018-05-16 11:07:07 +00:00
|
|
|
does not exceed Bitmap (width(), height()).
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
dst specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
|
2018-11-07 19:59:03 +00:00
|
|
|
and row bytes of destination. dst.rowBytes() specifics the gap from one destination
|
2017-10-04 18:31:33 +00:00
|
|
|
row to the next. Returns true if pixels are copied. Returns false if:
|
|
|
|
#List
|
|
|
|
# dst pixel storage equals nullptr ##
|
2018-11-07 19:59:03 +00:00
|
|
|
# dst.rowBytes() is less than SkImageInfo::minRowBytes() ##
|
2017-10-04 18:31:33 +00:00
|
|
|
# Pixel_Ref is nullptr ##
|
|
|
|
##
|
|
|
|
|
2018-01-11 15:35:44 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
|
2017-10-04 18:31:33 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; dst Color_Type must match.
|
2018-01-11 15:35:44 +00:00
|
|
|
If Bitmap colorType is kGray_8_SkColorType, dst Color_Space must match.
|
|
|
|
If Bitmap alphaType is kOpaque_SkAlphaType, dst Alpha_Type must
|
|
|
|
match. If Bitmap colorSpace is nullptr, dst Color_Space must match. Returns
|
2017-10-04 18:31:33 +00:00
|
|
|
false if pixel conversion is not possible.
|
2018-05-16 11:07:07 +00:00
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
#Param dst destination Pixmap: Image_Info, pixels, row bytes ##
|
|
|
|
|
|
|
|
#Return true if pixels are copied to dst ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
std::vector<int32_t> srcPixels;
|
|
|
|
srcPixels.resize(source.height() * source.width() * 8);
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
2018-05-16 11:07:07 +00:00
|
|
|
SkPixmap pixmap(SkImageInfo::Make(source.width() * 2, source.height(),
|
2017-10-09 18:43:00 +00:00
|
|
|
i ? kRGBA_8888_SkColorType : kBGRA_8888_SkColorType, kPremul_SkAlphaType),
|
|
|
|
&srcPixels.front() + i * source.width(), source.rowBytes() * 2);
|
|
|
|
source.readPixels(pixmap);
|
|
|
|
}
|
|
|
|
canvas->scale(.25f, .25f);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.installPixels(SkImageInfo::MakeN32Premul(source.width() * 2, source.height()),
|
|
|
|
&srcPixels.front(), source.rowBytes() * 2);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool writePixels(const SkPixmap& src, int dstX, int dstY)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Pixels
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # copies and converts pixels ##
|
2017-10-04 18:31:33 +00:00
|
|
|
Copies a Rect of pixels from src. Copy starts at (dstX, dstY), and does not exceed
|
2018-05-16 11:07:07 +00:00
|
|
|
(src.width(), src.height()).
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
src specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
|
2018-11-07 19:59:03 +00:00
|
|
|
and row bytes of source. src.rowBytes() specifics the gap from one source
|
2017-10-04 18:31:33 +00:00
|
|
|
row to the next. Returns true if pixels are copied. Returns false if:
|
|
|
|
#List
|
|
|
|
# src pixel storage equals nullptr ##
|
2018-11-07 19:59:03 +00:00
|
|
|
# src.rowBytes() is less than SkImageInfo::minRowBytes() ##
|
2017-10-04 18:31:33 +00:00
|
|
|
# Pixel_Ref is nullptr ##
|
|
|
|
##
|
|
|
|
|
2018-01-11 15:35:44 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
|
2017-10-04 18:31:33 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color_Type must match.
|
2018-01-11 15:35:44 +00:00
|
|
|
If Bitmap colorType is kGray_8_SkColorType, src Color_Space must match.
|
|
|
|
If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha_Type must
|
|
|
|
match. If Bitmap colorSpace is nullptr, src Color_Space must match. Returns
|
2017-10-04 18:31:33 +00:00
|
|
|
false if pixel conversion is not possible.
|
2018-05-16 11:07:07 +00:00
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
dstX and dstY may be negative to copy only top or left of source. Returns
|
2017-10-26 11:58:48 +00:00
|
|
|
false if width() or height() is zero or negative.
|
Condense embedded formulas.
Bookmaker delimits formulas and equations to allow
representing variables and symbols without tripping
up reference lookup, spell checking, and comment
generation.
Before, formulas were represented with:
some text
#Formula
(x + y, 0)
##
, and more text
This made it difficult to know when spacing should
be preserved before and after the formula. Now,
formulas are represented with:
some text #Formula # (x + y, 0) ##, and more text
The presence or absence of a space between ## and ,
is now significant (before it was not).
Also, formulas are bracketed by <code> in markdown
generation, so that variables stand out better.
See:
https://skia.org/user/api/SkBlendMode_Reference?cl=152781#Dst_Out
for an example.
Also fixed 100 column offenders and added a code
check to identify them. For the moment, 100 column
offenders are outed with SkDebugf but their presence
does not cause bookmaker to fail.
TBR=caryclark@google.com
Docs-Preview: https://skia.org/?cl=152781
Bug: skia:6898
Change-Id: If92a65a234f5d616bf4485984a8d219a6f04821a
Reviewed-on: https://skia-review.googlesource.com/152781
Commit-Queue: Cary Clark <caryclark@skia.org>
Auto-Submit: Cary Clark <caryclark@skia.org>
Reviewed-by: Cary Clark <caryclark@skia.org>
2018-09-13 16:04:30 +00:00
|
|
|
Returns false if #Formula # abs(dstX) >= Bitmap width() ##, or if #Formula # abs(dstY) >= Bitmap height() ##.
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Param src source Pixmap: Image_Info, 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 Bitmap ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-10-09 18:43:00 +00:00
|
|
|
std::vector<int32_t> srcPixels;
|
|
|
|
int width = image->width();
|
|
|
|
int height = image->height();
|
|
|
|
srcPixels.resize(height * width * 4);
|
|
|
|
SkPixmap pixmap(SkImageInfo::MakeN32Premul(width, height), (const void*) &srcPixels.front(),
|
|
|
|
width * 4);
|
|
|
|
image->readPixels(pixmap, 0, 0);
|
|
|
|
canvas->scale(.5f, .5f);
|
|
|
|
width /= 4;
|
|
|
|
height /= 4;
|
|
|
|
for (int y = 0; y < 4; ++y) {
|
|
|
|
for (int x = 0; x < 4; ++x) {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height));
|
|
|
|
bitmap.writePixels(pixmap, -y * width, -x * height);
|
|
|
|
canvas->drawBitmap(bitmap, x * width, y * height);
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2018-05-16 11:07:07 +00:00
|
|
|
#SeeAlso readPixels
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool writePixels(const SkPixmap& src)
|
|
|
|
|
|
|
|
Copies a Rect of pixels from src. Copy starts at (0, 0), and does not exceed
|
2018-05-16 11:07:07 +00:00
|
|
|
(src.width(), src.height()).
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
src specifies width, height, Color_Type, Alpha_Type, Color_Space, pixel storage,
|
2018-11-07 19:59:03 +00:00
|
|
|
and row bytes of source. src.rowBytes() specifics the gap from one source
|
2017-10-04 18:31:33 +00:00
|
|
|
row to the next. Returns true if pixels are copied. Returns false if:
|
|
|
|
#List
|
|
|
|
# src pixel storage equals nullptr ##
|
2018-11-07 19:59:03 +00:00
|
|
|
# src.rowBytes() is less than SkImageInfo::minRowBytes() ##
|
2017-10-04 18:31:33 +00:00
|
|
|
# Pixel_Ref is nullptr ##
|
|
|
|
##
|
|
|
|
|
2018-01-11 15:35:44 +00:00
|
|
|
Pixels are copied only if pixel conversion is possible. If Bitmap colorType is
|
2017-10-04 18:31:33 +00:00
|
|
|
kGray_8_SkColorType, or kAlpha_8_SkColorType; src Color_Type must match.
|
2018-01-11 15:35:44 +00:00
|
|
|
If Bitmap colorType is kGray_8_SkColorType, src Color_Space must match.
|
|
|
|
If Bitmap alphaType is kOpaque_SkAlphaType, src Alpha_Type must
|
|
|
|
match. If Bitmap colorSpace is nullptr, src Color_Space must match. Returns
|
2017-10-04 18:31:33 +00:00
|
|
|
false if pixel conversion is not possible.
|
|
|
|
|
|
|
|
#Param src source Pixmap: Image_Info, pixels, row bytes ##
|
|
|
|
|
|
|
|
#Return true if src pixels are copied to Bitmap ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 80
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2));
|
|
|
|
bitmap.eraseColor(SK_ColorGREEN);
|
|
|
|
SkPMColor color = 0xFF5599BB;
|
|
|
|
SkPixmap src(SkImageInfo::MakeN32Premul(1, 1), &color, 4);
|
|
|
|
bitmap.writePixels(src);
|
|
|
|
canvas->scale(40, 40);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso readPixels
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool extractAlpha(SkBitmap* dst) const
|
2018-10-08 18:57:48 +00:00
|
|
|
#In Constructors
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # creates Bitmap containing Alpha of pixels ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 100
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap alpha, bitmap;
|
|
|
|
bitmap.allocN32Pixels(100, 100);
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
offscreen.clear(0);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(20);
|
|
|
|
offscreen.drawCircle(50, 50, 39, paint);
|
|
|
|
offscreen.flush();
|
|
|
|
bitmap.extractAlpha(&alpha);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0, &paint);
|
2017-10-04 18:31:33 +00:00
|
|
|
canvas->drawBitmap(alpha, 100, 0, &paint);
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso extractSubset
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool extractAlpha(SkBitmap* dst, const SkPaint* paint,
|
|
|
|
SkIPoint* offset) const
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 160
|
2018-03-16 15:34:15 +00:00
|
|
|
auto radiusToSigma = [](SkScalar radius) -> SkScalar {
|
|
|
|
static const SkScalar kBLUR_SIGMA_SCALE = 0.57735f;
|
|
|
|
return radius > 0 ? kBLUR_SIGMA_SCALE * radius + 0.5f : 0.0f;
|
|
|
|
};
|
|
|
|
SkBitmap alpha, bitmap;
|
|
|
|
bitmap.allocN32Pixels(100, 100);
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
offscreen.clear(0);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(20);
|
|
|
|
offscreen.drawCircle(50, 50, 39, paint);
|
|
|
|
offscreen.flush();
|
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, radiusToSigma(25)));
|
|
|
|
SkIPoint offset;
|
|
|
|
bitmap.extractAlpha(&alpha, &paint, &offset);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawBitmap(bitmap, 0, -offset.fY, &paint);
|
|
|
|
canvas->drawBitmap(alpha, 100 + offset.fX, 0, &paint);
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso extractSubset
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator* allocator,
|
|
|
|
SkIPoint* offset) const
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap alpha, bitmap;
|
|
|
|
bitmap.allocN32Pixels(100, 100);
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
offscreen.clear(0);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(20);
|
|
|
|
offscreen.drawCircle(50, 50, 39, paint);
|
|
|
|
offscreen.flush();
|
2018-03-16 15:34:15 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kOuter_SkBlurStyle, 3));
|
2017-10-09 18:43:00 +00:00
|
|
|
SkIPoint offset;
|
|
|
|
bitmap.extractAlpha(&alpha, &paint, nullptr, &offset);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawBitmap(bitmap, 0, -offset.fY, &paint);
|
|
|
|
canvas->drawBitmap(alpha, 100 + offset.fX, 0, &paint);
|
2017-10-04 18:31:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso extractSubset
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool peekPixels(SkPixmap* pixmap) const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Pixels
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns Pixmap if possible ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
#Example
|
2017-10-09 18:43:00 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(6, 11));
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
offscreen.clear(SK_ColorWHITE);
|
|
|
|
SkPaint paint;
|
|
|
|
offscreen.drawString("?", 0, 10, paint);
|
|
|
|
SkPixmap pixmap;
|
|
|
|
if (bitmap.peekPixels(&pixmap)) {
|
|
|
|
const SkPMColor* pixels = pixmap.addr32();
|
|
|
|
SkPMColor pmWhite = pixels[0];
|
|
|
|
for (int y = 0; y < bitmap.height(); ++y) {
|
|
|
|
for (int x = 0; x < bitmap.width(); ++x) {
|
|
|
|
SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
|
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
|
|
|
}
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
#StdOut
|
2017-12-11 21:03:17 +00:00
|
|
|
------
|
|
|
|
-xxx--
|
|
|
|
x---x-
|
|
|
|
----x-
|
|
|
|
---x--
|
|
|
|
--x---
|
|
|
|
--x---
|
|
|
|
------
|
|
|
|
--x---
|
|
|
|
--x---
|
2017-11-27 15:44:06 +00:00
|
|
|
------
|
2017-10-04 18:31:33 +00:00
|
|
|
#StdOut ##
|
|
|
|
##
|
|
|
|
|
2018-10-16 14:30:28 +00:00
|
|
|
#SeeAlso pixmap installPixels readPixels writePixels
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
##
|
2017-10-26 11:58:48 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-07 12:27:09 +00:00
|
|
|
#Subtopic Utility
|
|
|
|
#Line # rarely called management functions ##
|
|
|
|
##
|
2017-10-26 11:58:48 +00:00
|
|
|
|
|
|
|
#Method void validate() const;
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Utility
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # asserts if Bitmap is invalid (debug only) ##
|
2018-10-31 16:14:03 +00:00
|
|
|
#Populate
|
2017-10-26 11:58:48 +00:00
|
|
|
|
|
|
|
#NoExample
|
|
|
|
##
|
|
|
|
|
2018-03-20 19:53:27 +00:00
|
|
|
#SeeAlso SkImageInfo::validate
|
2017-10-26 11:58:48 +00:00
|
|
|
|
|
|
|
##
|
2017-10-04 18:31:33 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Class SkBitmap ##
|
|
|
|
|
|
|
|
#Topic Bitmap ##
|