From 29380bdd56526168d8f8e54d641a1f16b205da4d Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Mon, 9 Oct 2017 14:43:00 -0400 Subject: Remove carriage returns. Also add a presubmit so they don't get added to source code. Change-Id: I6a85c6a934b1068a63646a0dcc0d3a08baa96ced Reviewed-on: https://skia-review.googlesource.com/57110 Reviewed-by: Ravi Mistry Commit-Queue: Ben Wagner --- docs/SkBitmap_Reference.bmh | 1744 +++++++++++++++++++++---------------------- 1 file changed, 872 insertions(+), 872 deletions(-) (limited to 'docs/SkBitmap_Reference.bmh') diff --git a/docs/SkBitmap_Reference.bmh b/docs/SkBitmap_Reference.bmh index 03e8a103bb..35f4de6dcb 100644 --- a/docs/SkBitmap_Reference.bmh +++ b/docs/SkBitmap_Reference.bmh @@ -213,19 +213,19 @@ or setPixelRef was called. #Return true if pixels are allocated ## #Example - 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 -pixel address = (nil) -pixel address = 0x560ddd0ac670 -## + 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 +pixel address = (nil) +pixel address = 0x560ddd0ac670 +## ## #SeeAlso Allocator tryAllocPixels @@ -262,7 +262,7 @@ void draw(SkCanvas* canvas) { } } #StdOut -width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType +width: 0 height: 0 color: kUnknown_SkColorType alpha: kUnknown_SkAlphaType width: 25 height: 35 color: kRGBA_8888_SkColorType alpha: kOpaque_SkAlphaType ## ## @@ -283,17 +283,17 @@ allocated, so both bitmaps reference the same pixels. #Return copy of src ## #Example -void draw(SkCanvas* canvas) { - SkBitmap original; - original.tryAllocPixels(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); - SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false"); - SkBitmap copy(original); - SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false"); - SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); +void draw(SkCanvas* canvas) { + SkBitmap original; + original.tryAllocPixels(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); + SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false"); + SkBitmap copy(original); + SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false"); + SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); } #StdOut -original has pixels before copy: true -original has pixels after copy: true +original has pixels before copy: true +original has pixels after copy: true copy has pixels: true ## ## @@ -314,17 +314,17 @@ Bitmap. #Return copy of src ## #Example -void draw(SkCanvas* canvas) { - SkBitmap original; - original.tryAllocPixels(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); - SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false"); - SkBitmap copy(std::move(original)); - SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false"); - SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); -} +void draw(SkCanvas* canvas) { + SkBitmap original; + original.tryAllocPixels(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); + SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false"); + SkBitmap copy(std::move(original)); + SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false"); + SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); +} #StdOut -original has pixels before move: true -original has pixels after move: false +original has pixels before move: true +original has pixels after move: false copy has pixels: true ## ## @@ -358,17 +358,17 @@ allocated, so both bitmaps reference the same pixels. #Return copy of src ## #Example -void draw(SkCanvas* canvas) { - SkBitmap original; - original.tryAllocPixels(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); - SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false"); - SkBitmap copy = original; - SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false"); - SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); +void draw(SkCanvas* canvas) { + SkBitmap original; + original.tryAllocPixels(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); + SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false"); + SkBitmap copy = original; + SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false"); + SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); } #StdOut -original has pixels before copy: true -original has pixels after copy: true +original has pixels before copy: true +original has pixels after copy: true copy has pixels: true ## ## @@ -389,17 +389,17 @@ Bitmap. #Return copy of src ## #Example -void draw(SkCanvas* canvas) { - SkBitmap original; - original.tryAllocPixels(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); - SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false"); - SkBitmap copy = std::move(original); - SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false"); - SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); -} +void draw(SkCanvas* canvas) { + SkBitmap original; + original.tryAllocPixels(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); + SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false"); + SkBitmap copy = std::move(original); + SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false"); + SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); +} #StdOut -original has pixels before move: true -original has pixels after move: false +original has pixels before move: true +original has pixels after move: false copy has pixels: true ## ## @@ -417,27 +417,27 @@ Swaps the fields of the two bitmaps. #Param other Bitmap exchanged with original ## #Example -void draw(SkCanvas* canvas) { - auto debugster = [](const char* prefix, const SkBitmap& b) -> void { - const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; - const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444", "RGBA_8888", "BGRA_8888", - "Gray_8", "RGBA_F16"}; - 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; - one.tryAllocPixels(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); - two.tryAllocPixels(SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType)); - for (int index = 0; index < 2; ++index) { - debugster("one", one); - debugster("two", two); - one.swap(two); - } +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkBitmap& b) -> void { + const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; + const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444", "RGBA_8888", "BGRA_8888", + "Gray_8", "RGBA_F16"}; + 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; + one.tryAllocPixels(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); + two.tryAllocPixels(SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType)); + for (int index = 0; index < 2; ++index) { + debugster("one", one); + debugster("two", two); + one.swap(two); + } } #StdOut -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 +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 two width:1 height:1 colorType:kRGBA_8888_SkColorType alphaType:kOpaque_SkAlphaType ## ## @@ -456,17 +456,17 @@ Returns width, height, Alpha_Type, Color_Type, and Color_Space. #Example #Image 4 -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"}; - const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444", - "RGBA_8888", "BGRA_8888", "Gray_8", "RGBA_F16"}; - 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 -## +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"}; + const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444", + "RGBA_8888", "BGRA_8888", "Gray_8", "RGBA_F16"}; + 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 +## } ## @@ -539,11 +539,11 @@ kBGRA_8888_SkColorType, kGray_8_SkColorType, kRGBA_F16_SkColorType. #Return Color_Type in Image_Info ## #Example - const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444", - "RGBA_8888", "BGRA_8888", "Gray_8", "RGBA_F16"}; - SkBitmap bitmap; - bitmap.setInfo(SkImageInfo::MakeA8(16, 32)); - SkDebugf("color type: k" "%s" "_SkColorType\n", colors[bitmap.colorType()]); + const char* colors[] = {"Unknown", "Alpha", "RGB_565", "ARGB_4444", + "RGBA_8888", "BGRA_8888", "Gray_8", "RGBA_F16"}; + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::MakeA8(16, 32)); + SkDebugf("color type: k" "%s" "_SkColorType\n", colors[bitmap.colorType()]); #StdOut color type: kAlpha_SkColorType ## @@ -590,7 +590,7 @@ immutable. SkColorSpace::MakeSRGBLinear creates Color_Space with linear gamma and an sRGB gamut. This Color_Space gamma is not close to sRGB gamma. ## - SkBitmap bitmap; + SkBitmap bitmap; bitmap.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, SkColorSpace::MakeSRGBLinear())); SkColorSpace* colorSpace = bitmap.colorSpace(); @@ -620,7 +620,7 @@ The returned Color_Space is immutable. #Return Color_Space in Image_Info wrapped in a smart pointer ## #Example - SkBitmap bitmap1, bitmap2; + SkBitmap bitmap1, bitmap2; bitmap1.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, SkColorSpace::MakeSRGBLinear())); bitmap2.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, @@ -663,13 +663,13 @@ Returns zero if colorType( is kUnknown_SkColorType. bitmap.bytesPerPixel()); } #StdOut -color: kUnknown_SkColorType bytesPerPixel: 0 -color: kAlpha_SkColorType bytesPerPixel: 1 -color: kRGB_565_SkColorType bytesPerPixel: 2 -color: kARGB_4444_SkColorType bytesPerPixel: 2 -color: kRGBA_8888_SkColorType bytesPerPixel: 4 -color: kBGRA_8888_SkColorType bytesPerPixel: 4 -color: kGray_8_SkColorType bytesPerPixel: 1 +color: kUnknown_SkColorType bytesPerPixel: 0 +color: kAlpha_SkColorType bytesPerPixel: 1 +color: kRGB_565_SkColorType bytesPerPixel: 2 +color: kARGB_4444_SkColorType bytesPerPixel: 2 +color: kRGBA_8888_SkColorType bytesPerPixel: 4 +color: kBGRA_8888_SkColorType bytesPerPixel: 4 +color: kGray_8_SkColorType bytesPerPixel: 1 color: kRGBA_F16_SkColorType bytesPerPixel: 8 ## ## @@ -730,13 +730,13 @@ Returns zero for kUnknown_SkColorType. bitmap.shiftPerPixel()); } #StdOut -color: kUnknown_SkColorType shiftPerPixel: 0 -color: kAlpha_SkColorType shiftPerPixel: 0 -color: kRGB_565_SkColorType shiftPerPixel: 1 -color: kARGB_4444_SkColorType shiftPerPixel: 1 -color: kRGBA_8888_SkColorType shiftPerPixel: 2 -color: kBGRA_8888_SkColorType shiftPerPixel: 2 -color: kGray_8_SkColorType shiftPerPixel: 0 +color: kUnknown_SkColorType shiftPerPixel: 0 +color: kAlpha_SkColorType shiftPerPixel: 0 +color: kRGB_565_SkColorType shiftPerPixel: 1 +color: kARGB_4444_SkColorType shiftPerPixel: 1 +color: kRGBA_8888_SkColorType shiftPerPixel: 2 +color: kBGRA_8888_SkColorType shiftPerPixel: 2 +color: kGray_8_SkColorType shiftPerPixel: 0 color: kRGBA_F16_SkColorType shiftPerPixel: 3 ## ## @@ -789,15 +789,15 @@ width(), height(), and Pixel_Ref. #Return true if no Pixel_Ref is associated ## #Example - 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 " : ""); + 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 " : ""); #StdOut -empty bitmap does not have pixels -bitmap with dimensions does not have pixels +empty bitmap does not have pixels +bitmap with dimensions does not have pixels allocated bitmap does have pixels ## ## @@ -816,21 +816,21 @@ If true, Bitmap has no effect when drawn or drawn into. #Return true if drawing has no effect ## #Example - 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 -## + 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 +## ## #SeeAlso empty() isNull pixelRef @@ -854,15 +854,15 @@ setInfo is not large enough to hold a row of pixels. #Return byte length of pixel row ## #Example - 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 -## + 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 +## ## #SeeAlso info() setInfo SkImageInfo::minRowBytes @@ -903,29 +903,29 @@ are affected. #Return true if Alpha_Type is set ## #Example -void draw(SkCanvas* canvas) { - const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", - "RGBA_8888", "BGRA_8888", "Gray_8", "RGBA_F16"}; - const char* alphas[] = {"Unknown ", "Opaque ", "Premul ", "Unpremul"}; - - SkBitmap bitmap; - SkAlphaType alphaTypes[] = { kUnknown_SkAlphaType, kOpaque_SkAlphaType, - kPremul_SkAlphaType, kUnpremul_SkAlphaType }; - SkDebugf("%88s", "Canonical Unknown Opaque Premul Unpremul\n"); - for (SkColorType colorType : { kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, - kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, - kGray_8_SkColorType, kRGBA_F16_SkColorType } ) { - for (SkAlphaType canonicalAlphaType : alphaTypes) { - SkColorTypeValidateAlphaType(colorType, kUnknown_SkAlphaType, &canonicalAlphaType ); - SkDebugf("%10s %10s ", colors[(int) colorType], alphas[(int) canonicalAlphaType ]); - 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"); - } - } +void draw(SkCanvas* canvas) { + const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", + "RGBA_8888", "BGRA_8888", "Gray_8", "RGBA_F16"}; + const char* alphas[] = {"Unknown ", "Opaque ", "Premul ", "Unpremul"}; + + SkBitmap bitmap; + SkAlphaType alphaTypes[] = { kUnknown_SkAlphaType, kOpaque_SkAlphaType, + kPremul_SkAlphaType, kUnpremul_SkAlphaType }; + SkDebugf("%88s", "Canonical Unknown Opaque Premul Unpremul\n"); + for (SkColorType colorType : { kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, + kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, + kGray_8_SkColorType, kRGBA_F16_SkColorType } ) { + for (SkAlphaType canonicalAlphaType : alphaTypes) { + SkColorTypeValidateAlphaType(colorType, kUnknown_SkAlphaType, &canonicalAlphaType ); + SkDebugf("%10s %10s ", colors[(int) colorType], alphas[(int) canonicalAlphaType ]); + 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"); + } + } } ## @@ -942,18 +942,18 @@ Returns pixel address, the base address corresponding to the pixel origin. #Return pixel address ## #Example - 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 ? '=' : '!'); + 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 ? '=' : '!'); #StdOut -bitmap.getColor(0, 1) == 0x00000000 +bitmap.getColor(0, 1) == 0x00000000 bitmap.getColor(0, 0) == 0xFFFFFFFF ## ## @@ -975,7 +975,7 @@ Returns height() times rowBytes if colorType is kUnknown_SkColorType. #Return size in bytes of image buffer ## #Example - SkBitmap bitmap; + SkBitmap bitmap; for (int width : { 1, 1000, 1000000 } ) { for (int height: { 1, 1000, 1000000 } ) { SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType); @@ -985,14 +985,14 @@ Returns height() times rowBytes if colorType is kUnknown_SkColorType. } } #StdOut -width: 1 height: 1 computeByteSize: 4 -width: 1 height: 1000 computeByteSize: 4999 -width: 1 height: 1000000 computeByteSize: 4999999 -width: 1000 height: 1 computeByteSize: 4000 -width: 1000 height: 1000 computeByteSize: 4999000 -width: 1000 height: 1000000 computeByteSize: 4999999000 -width: 1000000 height: 1 computeByteSize: 4000000 -width: 1000000 height: 1000 computeByteSize: 4999000000 +width: 1 height: 1 computeByteSize: 4 +width: 1 height: 1000 computeByteSize: 4999 +width: 1 height: 1000000 computeByteSize: 4999999 +width: 1000 height: 1 computeByteSize: 4000 +width: 1000 height: 1000 computeByteSize: 4999000 +width: 1000 height: 1000000 computeByteSize: 4999999000 +width: 1000000 height: 1 computeByteSize: 4000000 +width: 1000000 height: 1000 computeByteSize: 4999000000 width: 1000000 height: 1000000 computeByteSize: 4999999000000 ## ## @@ -1017,25 +1017,25 @@ result may exceed 32 bits. #Description getSize results are not useful when width() and height() are large. ## -void draw(SkCanvas* canvas) { - SkBitmap bitmap; - 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 getSize: %9zu\n", width, height, bitmap.getSize()); - } - } +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + 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 getSize: %9zu\n", width, height, bitmap.getSize()); + } + } } #StdOut -width: 1 height: 1 getSize: 5 -width: 1 height: 1000 getSize: 5000 -width: 1 height: 1000000 getSize: 5000000 -width: 1000 height: 1 getSize: 5000 -width: 1000 height: 1000 getSize: 5000000 -width: 1000 height: 1000000 getSize: 705032704 -width: 1000000 height: 1 getSize: 5000000 -width: 1000000 height: 1000 getSize: 705032704 +width: 1 height: 1 getSize: 5 +width: 1 height: 1000 getSize: 5000 +width: 1 height: 1000000 getSize: 5000000 +width: 1000 height: 1 getSize: 5000 +width: 1000 height: 1000 getSize: 5000000 +width: 1000 height: 1000000 getSize: 705032704 +width: 1000000 height: 1 getSize: 5000000 +width: 1000000 height: 1000 getSize: 705032704 width: 1000000 height: 1000000 getSize: 658067456 ## ## @@ -1063,25 +1063,25 @@ beyond the result may generate an exception. #Description getSafeSize results are not useful when width() and height() are large. ## -void draw(SkCanvas* canvas) { - SkBitmap bitmap; - 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 getSafeSize: %9zu\n", width, height, bitmap.getSafeSize()); - } - } +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + 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 getSafeSize: %9zu\n", width, height, bitmap.getSafeSize()); + } + } } #StdOut -width: 1 height: 1 getSafeSize: 4 -width: 1 height: 1000 getSafeSize: 4999 -width: 1 height: 1000000 getSafeSize: 4999999 -width: 1000 height: 1 getSafeSize: 4000 -width: 1000 height: 1000 getSafeSize: 4999000 -width: 1000 height: 1000000 getSafeSize: 0 -width: 1000000 height: 1 getSafeSize: 4000000 -width: 1000000 height: 1000 getSafeSize: 0 +width: 1 height: 1 getSafeSize: 4 +width: 1 height: 1000 getSafeSize: 4999 +width: 1 height: 1000000 getSafeSize: 4999999 +width: 1000 height: 1 getSafeSize: 4000 +width: 1000 height: 1000 getSafeSize: 4999000 +width: 1000 height: 1000000 getSafeSize: 0 +width: 1000000 height: 1 getSafeSize: 4000000 +width: 1000000 height: 1000 getSafeSize: 0 width: 1000000 height: 1000000 getSafeSize: 0 ## ## @@ -1100,26 +1100,26 @@ Includes unused memory on last row when rowBytesAsPixels exceeds width(). #Return conservative pixel storage size ## #Example -void draw(SkCanvas* canvas) { - SkBitmap bitmap; - 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 computeSize64: %13lld\n", width, height, - bitmap.computeSize64()); - } - } +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + 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 computeSize64: %13lld\n", width, height, + bitmap.computeSize64()); + } + } } #StdOut -width: 1 height: 1 computeSize64: 5 -width: 1 height: 1000 computeSize64: 5000 -width: 1 height: 1000000 computeSize64: 5000000 -width: 1000 height: 1 computeSize64: 5000 -width: 1000 height: 1000 computeSize64: 5000000 -width: 1000 height: 1000000 computeSize64: 5000000000 -width: 1000000 height: 1 computeSize64: 5000000 -width: 1000000 height: 1000 computeSize64: 5000000000 +width: 1 height: 1 computeSize64: 5 +width: 1 height: 1000 computeSize64: 5000 +width: 1 height: 1000000 computeSize64: 5000000 +width: 1000 height: 1 computeSize64: 5000 +width: 1000 height: 1000 computeSize64: 5000000 +width: 1000 height: 1000000 computeSize64: 5000000000 +width: 1000000 height: 1 computeSize64: 5000000 +width: 1000000 height: 1000 computeSize64: 5000000000 width: 1000000 height: 1000000 computeSize64: 5000000000000 ## ## @@ -1138,26 +1138,26 @@ Does not include unused memory on last row when rowBytesAsPixels exceeds width() #Return exact pixel storage size ## #Example -void draw(SkCanvas* canvas) { - SkBitmap bitmap; - 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 computeSafeSize64: %13lld\n", width, height, - bitmap.computeSafeSize64()); - } - } +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + 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 computeSafeSize64: %13lld\n", width, height, + bitmap.computeSafeSize64()); + } + } } #StdOut -width: 1 height: 1 computeSafeSize64: 4 -width: 1 height: 1000 computeSafeSize64: 4999 -width: 1 height: 1000000 computeSafeSize64: 4999999 -width: 1000 height: 1 computeSafeSize64: 4000 -width: 1000 height: 1000 computeSafeSize64: 4999000 -width: 1000 height: 1000000 computeSafeSize64: 4999999000 -width: 1000000 height: 1 computeSafeSize64: 4000000 -width: 1000000 height: 1000 computeSafeSize64: 4999000000 +width: 1 height: 1 computeSafeSize64: 4 +width: 1 height: 1000 computeSafeSize64: 4999 +width: 1 height: 1000000 computeSafeSize64: 4999999 +width: 1000 height: 1 computeSafeSize64: 4000 +width: 1000 height: 1000 computeSafeSize64: 4999000 +width: 1000 height: 1000000 computeSafeSize64: 4999999000 +width: 1000000 height: 1 computeSafeSize64: 4000000 +width: 1000000 height: 1000 computeSafeSize64: 4999000000 width: 1000000 height: 1000000 computeSafeSize64: 4999999000000 ## ## @@ -1177,17 +1177,17 @@ Most immutable Bitmap checks trigger an assert only on debug builds. #Return true if pixels are immutable ## #Example - SkBitmap original; - SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); - if (original.tryAllocPixels(info)) { - original.setImmutable(); - SkBitmap copy; - original.extractSubset(©, {5, 10, 15, 20}); - SkDebugf("original is " "%s" "immutable\n", original.isImmutable() ? "" : "not "); - SkDebugf("copy is " "%s" "immutable\n", copy.isImmutable() ? "" : "not "); + SkBitmap original; + SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); + if (original.tryAllocPixels(info)) { + original.setImmutable(); + SkBitmap copy; + original.extractSubset(©, {5, 10, 15, 20}); + SkDebugf("original is " "%s" "immutable\n", original.isImmutable() ? "" : "not "); + SkDebugf("copy is " "%s" "immutable\n", copy.isImmutable() ? "" : "not "); } #StdOut -original is immutable +original is immutable copy is immutable ## ## @@ -1210,14 +1210,14 @@ Writing to immutable Bitmap pixels triggers an assert on debug builds. #Description Triggers assert if SK_DEBUG is true, runs fine otherwise. ## - 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"); + 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"); offscreen.clear(SK_ColorBLACK); ## @@ -1239,18 +1239,18 @@ transparency. #Description isOpaque ignores whether all pixels are opaque or not. ## - 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)); - } + 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)); + } #StdOut isOpaque: false isOpaque: false @@ -1275,17 +1275,17 @@ Volatile state is not shared by other bitmaps sharing the same Pixel_Ref. #Return true if marked volatile ## #Example - SkBitmap original; - SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); - if (original.tryAllocPixels(info)) { - original.setIsVolatile(true); - SkBitmap copy; - original.extractSubset(©, {5, 10, 15, 20}); - SkDebugf("original is " "%s" "volatile\n", original.isVolatile() ? "" : "not "); - SkDebugf("copy is " "%s" "volatile\n", copy.isImmutable() ? "" : "not "); - } + SkBitmap original; + SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); + if (original.tryAllocPixels(info)) { + original.setIsVolatile(true); + SkBitmap copy; + original.extractSubset(©, {5, 10, 15, 20}); + SkDebugf("original is " "%s" "volatile\n", original.isVolatile() ? "" : "not "); + SkDebugf("copy is " "%s" "volatile\n", copy.isImmutable() ? "" : "not "); + } #StdOut -original is volatile +original is volatile copy is not volatile ## ## @@ -1309,17 +1309,17 @@ consumption on Device. #Example #Height 20 - SkBitmap bitmap; - 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); + SkBitmap bitmap; + 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); ## #SeeAlso isVolatile @@ -1340,18 +1340,18 @@ If Pixel_Ref is allocated, its reference count is decreased by one, releasing its memory if Bitmap is the sole owner. #Example - SkBitmap bitmap; - 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 -## + SkBitmap bitmap; + 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 +## ## #SeeAlso SkBitmap() SkAlphaType SkColorType @@ -1381,15 +1381,15 @@ Returns false for kUnknown_SkColorType. #Return true if all pixels have opaque values or Color_Type is opaque ## #Example - 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)); + 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)); } #StdOut computeIsOpaque: false @@ -1414,14 +1414,14 @@ Returns Rect { 0, 0, width(), height() }. #Example #Height 160 #Image 3 - 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); + 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); ## #SeeAlso bounds() @@ -1438,13 +1438,13 @@ Returns IRect { 0, 0, width(), height() }. #Example #Image 3 - SkIRect bounds; - source.getBounds(&bounds); - bounds.inset(100, 100); - SkBitmap bitmap; - source.extractSubset(&bitmap, bounds); - canvas->scale(.5f, .5f); - canvas->drawBitmap(bitmap, 10, 10); + SkIRect bounds; + source.getBounds(&bounds); + bounds.inset(100, 100); + SkBitmap bitmap; + source.extractSubset(&bitmap, bounds); + canvas->scale(.5f, .5f); + canvas->drawBitmap(bitmap, 10, 10); ## #SeeAlso bounds() @@ -1461,12 +1461,12 @@ Returns IRect { 0, 0, width(), height() }. #Example #Image 4 - SkIRect bounds = source.bounds(); - for (int x : { 0, bounds.width() } ) { - for (int y : { 0, bounds.height() } ) { - canvas->drawBitmap(source, x, y); - } - } + SkIRect bounds = source.bounds(); + for (int x : { 0, bounds.width() } ) { + for (int y : { 0, bounds.height() } ) { + canvas->drawBitmap(source, x, y); + } + } ## #SeeAlso getBounds @@ -1482,13 +1482,13 @@ Returns ISize { width(), height() }. #Return integral size of width() and height() ## #Example - 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 ? '=' : '!'); + 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 ? '=' : '!'); ## #SeeAlso height() width() @@ -1505,19 +1505,19 @@ Returns the bounds of this bitmap, offset by its Pixel_Ref origin. #Example #Image 3 - 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 -## + 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 +## ## #SeeAlso extractSubset getBounds @@ -1563,16 +1563,16 @@ Calls reset() and returns false if: #Example #Height 96 ###^ -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); -^^^# +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); +^^^# ## #SeeAlso Alpha_Type Color_Type Color_Space height rowBytes width @@ -1634,18 +1634,18 @@ requires 40,000,000,000 bytes of storage. Allocator implemented internally by SkMallocPixelRef::MakeZeroed limits the maximum memory allowed; the allocation must fit in 31 bits. ## - SkBitmap bitmap; - int loop = 0; - while (++loop) { - SkDebugf("attempt %d\n", loop); - if (!bitmap.tryAllocPixelsFlags(SkImageInfo::MakeN32(100000, 100000, kOpaque_SkAlphaType), - SkBitmap::kZeroPixels_AllocFlag)) { - SkDebugf("failed!\n"); - break; - } + SkBitmap bitmap; + int loop = 0; + while (++loop) { + SkDebugf("attempt %d\n", loop); + if (!bitmap.tryAllocPixelsFlags(SkImageInfo::MakeN32(100000, 100000, kOpaque_SkAlphaType), + SkBitmap::kZeroPixels_AllocFlag)) { + SkDebugf("failed!\n"); + break; + } } #StdOut -attempt 1 +attempt 1 failed! ## ## @@ -1685,16 +1685,16 @@ Text is drawn on a transparent background; drawing the bitmap a second time lets the first draw show through. ## ###^ -SkBitmap bitmap; -bitmap.allocPixelsFlags(SkImageInfo::MakeN32(44, 16, kPremul_SkAlphaType), - 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); -^^^# +SkBitmap bitmap; +bitmap.allocPixelsFlags(SkImageInfo::MakeN32(44, 16, kPremul_SkAlphaType), + 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); +^^^# ## #SeeAlso tryAllocPixelsFlags allocPixels SkMallocPixelRef::MakeZeroed @@ -1732,15 +1732,15 @@ implementation of malloc(). #Example #Image 3 -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); - } +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); + } } ## @@ -1770,14 +1770,14 @@ implementation of malloc(). #Example #Image 3 -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); +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); } ## @@ -1806,14 +1806,14 @@ implementation of malloc(). #Example #Image 3 -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); - } +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); + } } ## @@ -1841,14 +1841,14 @@ implementation of malloc(). #Example #Image 4 -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); -} +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); +} ## #SeeAlso tryAllocPixels allocPixelsFlags SkMallocPixelRef::MakeAllocate @@ -1879,17 +1879,17 @@ to draw without converting its pixel format. #Example #Height 160 - 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); - } - } + 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); + } + } ## #SeeAlso tryAllocPixels allocN32Pixels SkMallocPixelRef::MakeAllocate @@ -1916,21 +1916,21 @@ to draw without converting its pixel format. #Param isOpaque true if pixels do not have transparency ## #Example - 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); - } - } + 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); + } + } ## #SeeAlso allocPixels tryAllocN32Pixels SkMallocPixelRef::MakeAllocate @@ -1970,24 +1970,24 @@ as parameters. releaseProc is called immediately because rowBytes is too small for Pixel_Ref. ## #Function -static void releaseProc(void* addr, void* ) { - SkDebugf("releaseProc called\n"); - delete[] (uint32_t*) addr; -} - -## - -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 "); +static void releaseProc(void* addr, void* ) { + SkDebugf("releaseProc called\n"); + delete[] (uint32_t*) addr; +} + +## + +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 "); } #StdOut -before installPixels -releaseProc called +before installPixels +releaseProc called install not successful ## ## @@ -2021,20 +2021,20 @@ Caller must ensure that pixels are valid for the lifetime of Bitmap and Pixel_Re #Bug 7079 ## GPU does not support kUnpremul_SkAlphaType, does not assert that it does not. ## -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); - } +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); + } } ## @@ -2107,22 +2107,22 @@ Caller must ensure that mask is valid for the lifetime of Bitmap and Pixel_Ref. 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 }}; - SkMask mask; - mask.fImage = storage[0]; - mask.fBounds = SkIRect::MakeWH(5, 5); - mask.fRowBytes = 5; - mask.fFormat = SkMask::kA8_Format; - SkBitmap bitmap; - bitmap.installMaskPixels(mask); - canvas->scale(10, 10); - canvas->drawBitmap(bitmap, 0, 0); - storage[2][2] = 0xFF; - bitmap.installMaskPixels(mask); + 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 }}; + SkMask mask; + mask.fImage = storage[0]; + mask.fBounds = SkIRect::MakeWH(5, 5); + mask.fRowBytes = 5; + mask.fFormat = SkMask::kA8_Format; + SkBitmap bitmap; + bitmap.installMaskPixels(mask); + canvas->scale(10, 10); + canvas->drawBitmap(bitmap, 0, 0); + storage[2][2] = 0xFF; + bitmap.installMaskPixels(mask); canvas->drawBitmap(bitmap, 10, 0); ## @@ -2147,14 +2147,14 @@ of Bitmap and Pixel_Ref. #Example #Height 50 - 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); + 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); ## #SeeAlso installPixels allocPixels @@ -2181,17 +2181,17 @@ 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 Pixel_Ref with set1. ## - 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); - } + 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); + } ## #SeeAlso allocPixels installPixels setPixels @@ -2216,16 +2216,16 @@ 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 Pixel_Ref with set2. ## - 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); + 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); canvas->drawBitmap(bitmap, 16, 0); ## @@ -2292,13 +2292,13 @@ public: void draw(SkCanvas* canvas) { LargeAllocator largeAllocator; SkBitmap bitmap; - 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); - } + 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); + } } ## @@ -2344,13 +2344,13 @@ public: void draw(SkCanvas* canvas) { TinyAllocator tinyAllocator; SkBitmap bitmap; - 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); - } + 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); + } } ## @@ -2371,11 +2371,11 @@ If Pixel_Ref has not been set, returns nullptr. #Example #Image 3 - 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) ? '=' : '!'); + 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) ? '=' : '!'); ## #SeeAlso getPixels getAddr @@ -2399,16 +2399,16 @@ Returns (0, 0) if Pixel_Ref is nullptr. #Example #Image 3 - 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 -## + 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 +## ## #ToDo incomplete ## @@ -2438,11 +2438,11 @@ Color_Type and Alpha_Type in Image_Info. #Description Treating 32 bit data as 8 bit data is unlikely to produce useful results. ## - SkBitmap bitmap; - bitmap.setInfo(SkImageInfo::Make(source.width() - 5, source.height() - 5, - kGray_8_SkColorType, kOpaque_SkAlphaType), source.rowBytes()); - bitmap.setPixelRef(sk_ref_sp(source.pixelRef()), 5, 5); - canvas->drawBitmap(bitmap, 10, 10); + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::Make(source.width() - 5, source.height() - 5, + kGray_8_SkColorType, kOpaque_SkAlphaType), source.rowBytes()); + bitmap.setPixelRef(sk_ref_sp(source.pixelRef()), 5, 5); + canvas->drawBitmap(bitmap, 10, 10); ## #SeeAlso setInfo @@ -2460,9 +2460,9 @@ Returns true if Bitmap is can be drawn. #Example #Image 5 #Height 160 - if (source.readyToDraw()) { - canvas->drawBitmap(source, 10, 10); - } + if (source.readyToDraw()) { + canvas->drawBitmap(source, 10, 10); + } ## #SeeAlso getPixels drawsNothing @@ -2482,16 +2482,16 @@ Determines if pixels have changed since last examined. #Return unique value for pixels in Pixel_Ref ## #Example - 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); + 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); SkDebugf("erase id %u\n", bitmap.getGenerationID()); #StdOut #Volatile -empty id 0 -alloc id 4 +empty id 0 +alloc id 4 erase id 6 ## ## @@ -2509,17 +2509,17 @@ getGenerationID() return a different value. #Example #Height 20 - SkBitmap bitmap; - 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); + SkBitmap bitmap; + 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); ## #SeeAlso getGenerationID isVolatile Pixel_Ref @@ -2539,11 +2539,11 @@ then Color_RGB is ignored. #Example #Height 20 - SkBitmap bitmap; - bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kOpaque_SkAlphaType)); - bitmap.eraseColor(SK_ColorRED); - canvas->scale(16, 16); - canvas->drawBitmap(bitmap, 0, 0); + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kOpaque_SkAlphaType)); + bitmap.eraseColor(SK_ColorRED); + canvas->scale(16, 16); + canvas->drawBitmap(bitmap, 0, 0); ## #SeeAlso eraseARGB eraseRGB erase @@ -2567,12 +2567,12 @@ then r, g, and b are ignored. #Example #Height 80 - SkBitmap bitmap; - 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); + SkBitmap bitmap; + 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); ## #SeeAlso eraseColor eraseRGB erase @@ -2593,12 +2593,12 @@ If colorType is kAlpha_8_SkColorType, all pixels are set to 255. #Example #Height 80 - SkBitmap bitmap; - bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType)); - bitmap.eraseRGB(0xff, 0x7f, 0x3f); - canvas->scale(50, 50); - canvas->drawBitmap(bitmap, 0, 0); - canvas->drawBitmap(bitmap, .5f, .5f); + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType)); + bitmap.eraseRGB(0xff, 0x7f, 0x3f); + canvas->scale(50, 50); + canvas->drawBitmap(bitmap, 0, 0); + canvas->drawBitmap(bitmap, .5f, .5f); ## #SeeAlso eraseColor eraseARGB erase @@ -2621,15 +2621,15 @@ then Color_RGB is ignored. #Example #Height 70 - SkBitmap bitmap; - 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); + SkBitmap bitmap; + 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); ## @@ -2733,12 +2733,12 @@ one of: getAddr8, getAddr16, or getAddr32. #Example #Image 3 - char* row0 = (char* ) source.getAddr(0, 0); - char* row1 = (char* ) source.getAddr(0, 1); - SkDebugf("addr interval %c= rowBytes\n", row1 - row0 == source.rowBytes() ? '=' : '!'); -#StdOut -addr interval == rowBytes -## + char* row0 = (char* ) source.getAddr(0, 0); + char* row1 = (char* ) source.getAddr(0, 1); + SkDebugf("addr interval %c= rowBytes\n", row1 - row0 == source.rowBytes() ? '=' : '!'); +#StdOut +addr interval == rowBytes +## ## #SeeAlso getAddr8 getAddr16 getAddr32 readPixels SkPixmap::addr @@ -2766,13 +2766,13 @@ Input is not validated. Triggers an assert() if built with SK_DEBUG defined and: #Example #Image 3 - 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 -## + 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 +## ## #SeeAlso getAddr8 getAddr16 getAddr readPixels SkPixmap::addr32 @@ -2800,19 +2800,19 @@ Input is not validated. Triggers an assert() if built with SK_DEBUG defined and: #Example #Image 3 - SkBitmap bitmap16; - SkImageInfo dstInfo = SkImageInfo::Make(source.width(), source.height(), kARGB_4444_SkColorType, - 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 -## + SkBitmap bitmap16; + SkImageInfo dstInfo = SkImageInfo::Make(source.width(), source.height(), kARGB_4444_SkColorType, + 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 +## ## #SeeAlso getAddr8 getAddr getAddr32 readPixels SkPixmap::addr16 @@ -2839,15 +2839,15 @@ Input is not validated. Triggers an assert() if built with SK_DEBUG defined and: #Return unsigned 8-bit pointer to pixel at (x, y) ## #Example - 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) ? '=' : '!'); - } + 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) ? '=' : '!'); + } #StdOut &pixels[4][2] == bitmap.getAddr8(2, 4) ## @@ -2886,36 +2886,36 @@ Return false if: #Example #Image 3 - 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) { - subset.getBounds(&s); - SkDebugf(" subset: %d, %d, %d, %d", s.fLeft, s.fTop, s.fRight, s.fBottom); - } - SkDebugf("\n"); - } - } + 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) { + subset.getBounds(&s); + SkDebugf(" subset: %d, %d, %d, %d", s.fLeft, s.fTop, s.fRight, s.fBottom); + } + SkDebugf("\n"); + } + } #StdOut -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 +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 subset: 1000, 100, 1000, 200 success; false ## ## @@ -2978,29 +2978,29 @@ pixels are treated as if they are linear, regardless of how they are encoded. #Example #Height 64 void draw(SkCanvas* canvas) { - const int width = 256; - const int height = 32; - std::vector dstPixels; - dstPixels.resize(height * width * 4); - SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); - SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 }; - SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } }; - SkPaint gradPaint; - gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, - SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); - for (auto behavior : { SkTransferFunctionBehavior::kRespect, - SkTransferFunctionBehavior::kIgnore} ) { - SkBitmap bitmap; - bitmap.allocPixels(info); - SkCanvas srcCanvas(bitmap); - srcCanvas.drawRect(SkRect::MakeWH(width, height), gradPaint); - if (bitmap.readPixels(info, &dstPixels.front(), width * 4, 0, 0, behavior)) { - SkPixmap dstPixmap(info, &dstPixels.front(), width * 4); - bitmap.installPixels(dstPixmap); - canvas->drawBitmap(bitmap, 0, 0); - } - canvas->translate(0, height); - } + const int width = 256; + const int height = 32; + std::vector dstPixels; + dstPixels.resize(height * width * 4); + SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); + SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 }; + SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } }; + SkPaint gradPaint; + gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, + SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); + for (auto behavior : { SkTransferFunctionBehavior::kRespect, + SkTransferFunctionBehavior::kIgnore} ) { + SkBitmap bitmap; + bitmap.allocPixels(info); + SkCanvas srcCanvas(bitmap); + srcCanvas.drawRect(SkRect::MakeWH(width, height), gradPaint); + if (bitmap.readPixels(info, &dstPixels.front(), width * 4, 0, 0, behavior)) { + SkPixmap dstPixmap(info, &dstPixels.front(), width * 4); + bitmap.installPixels(dstPixmap); + canvas->drawBitmap(bitmap, 0, 0); + } + canvas->translate(0, height); + } } ## @@ -3057,25 +3057,25 @@ abs(srcY) >= this->height() Transferring the gradient from 8 bits per component to 4 bits per component creates visible banding. ## - 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 dstPixels; - dstPixels.resize(height * width); - bitmap.readPixels(dstInfo, &dstPixels.front(), width * 2, 0, 0); - SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2); - bitmap.installPixels(dstPixmap); + 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 dstPixels; + dstPixels.resize(height * width); + bitmap.readPixels(dstInfo, &dstPixels.front(), width * 2, 0, 0); + SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2); + bitmap.installPixels(dstPixmap); canvas->drawBitmap(bitmap, 0, 64); ## @@ -3125,20 +3125,20 @@ abs(srcY) >= this->height() #Example #Image 3 - std::vector 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()); + std::vector 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()); canvas->drawBitmap(bitmap, 0, 0); ## @@ -3176,19 +3176,19 @@ false if pixel conversion is not possible. #Example #Height 128 #Image 3 - std::vector srcPixels; - srcPixels.resize(source.height() * source.width() * 8); - for (int i = 0; i < 2; ++i) { - SkPixmap pixmap(SkImageInfo::Make(source.width() * 2, source.height(), - 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); + std::vector srcPixels; + srcPixels.resize(source.height() * source.width() * 8); + for (int i = 0; i < 2; ++i) { + SkPixmap pixmap(SkImageInfo::Make(source.width() * 2, source.height(), + 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); ## #SeeAlso writePixels SkPixmap::readPixels SkCanvas::readPixels SkImage::readPixels SkSurface::readPixels @@ -3237,23 +3237,23 @@ abs(dstY) >= this->height() #Example #Image 3 - std::vector 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); - } + std::vector 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); + } } ## @@ -3290,14 +3290,14 @@ false if pixel conversion is not possible. #Example #Height 80 - 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); + 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); ## #SeeAlso readPixels @@ -3344,27 +3344,27 @@ pixels are treated as if they are linear, regardless of how they are encoded. #Example #Height 64 - const int width = 256; - const int height = 32; - std::vector dstPixels; - dstPixels.resize(height * width * 4); - SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); - SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 }; - SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } }; - SkPaint gradPaint; - gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, - SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); - for (auto behavior : { SkTransferFunctionBehavior::kRespect, - SkTransferFunctionBehavior::kIgnore} ) { - SkPixmap dstPixmap(info, &dstPixels.front(), width * 4); - SkBitmap bitmap; - bitmap.installPixels(dstPixmap); - SkCanvas srcCanvas(bitmap); - srcCanvas.drawRect(SkRect::MakeWH(width, height), gradPaint); - if (bitmap.writePixels(dstPixmap, 0, 0, behavior)) { - canvas->drawBitmap(bitmap, 0, 0); - } - canvas->translate(0, height); + const int width = 256; + const int height = 32; + std::vector dstPixels; + dstPixels.resize(height * width * 4); + SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); + SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 }; + SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } }; + SkPaint gradPaint; + gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, + SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); + for (auto behavior : { SkTransferFunctionBehavior::kRespect, + SkTransferFunctionBehavior::kIgnore} ) { + SkPixmap dstPixmap(info, &dstPixels.front(), width * 4); + SkBitmap bitmap; + bitmap.installPixels(dstPixmap); + SkCanvas srcCanvas(bitmap); + srcCanvas.drawRect(SkRect::MakeWH(width, height), gradPaint); + if (bitmap.writePixels(dstPixmap, 0, 0, behavior)) { + canvas->drawBitmap(bitmap, 0, 0); + } + canvas->translate(0, height); } ## @@ -3421,20 +3421,20 @@ Uses HeapAllocator to reserve memory for dst Pixel_Ref. #Example #Height 100 - 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); + 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); canvas->drawBitmap(alpha, 100, 0, &paint); ## @@ -3464,25 +3464,25 @@ Pixel_Ref. Sets offset to top-left position for dst for alignment with Bitmap; #Bug 7103 ## #Example #Height 160 - 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(); - const SkScalar kBlurSigma = SkBlurMaskFilter::ConvertRadiusToSigma(SkIntToScalar(25)); - paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, kBlurSigma, - SkBlurMaskFilter::kHighQuality_BlurFlag)); - 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); + 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(); + const SkScalar kBlurSigma = SkBlurMaskFilter::ConvertRadiusToSigma(SkIntToScalar(25)); + paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, kBlurSigma, + SkBlurMaskFilter::kHighQuality_BlurFlag)); + 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); ## #SeeAlso extractSubset @@ -3513,23 +3513,23 @@ mask. #Bug 7104 ## #Example #Height 128 - 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(); + 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(SkBlurMaskFilter::Make(kOuter_SkBlurStyle, 3)); - 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); + 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); ## #SeeAlso extractSubset @@ -3551,34 +3551,34 @@ is changed in any way, in which case the results are invalid. #Return true if Bitmap has direct access to pixels ## #Example - 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"); - } - } + 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"); + } + } #StdOut - ------ - --xxx- - -x--x- - ----x- - ---xx- - --xx-- - --x--- - ------ - --x--- - --x--- + ------ + --xxx- + -x--x- + ----x- + ---xx- + --xx-- + --x--- + ------ + --x--- + --x--- ------ #StdOut ## ## @@ -3604,18 +3604,18 @@ suppressed by defining SK_IGNORE_TO_STRING. #Param str storage for string representation ## #Example - SkBitmap bitmap; - int width = 6; - int height = 11; - bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height)); - SkString string; - bitmap.toString(&string); - SkString match; - match.printf("(%d, %d)", width, height); - int start = string.find(match.c_str()); - if (start >= 0) { - SkString whStr(&string.c_str()[start], match.size()); - SkDebugf("bitmap dimensions %s\n", whStr.c_str()); + SkBitmap bitmap; + int width = 6; + int height = 11; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height)); + SkString string; + bitmap.toString(&string); + SkString match; + match.printf("(%d, %d)", width, height); + int start = string.find(match.c_str()); + if (start >= 0) { + SkString whStr(&string.c_str()[start], match.size()); + SkDebugf("bitmap dimensions %s\n", whStr.c_str()); } #StdOut bitmap dimensions (6, 11) -- cgit v1.2.3