Compile all fiddle examples locally
Motivation: it would be a good idea if the API documentation examples were checked into the skia repository, so we could make sure they compile as part of the commit queue. Fiddle would make/update a named fiddle each time it gets a new commit of Skia, extracted from the code in the examples/ directory. The docs would point at those named fiddles. Named fiddles have urls in the form: https://fiddle.skia.org/c/@Bitmap_000 Then we would stick a link to the example into the header documentation like this: /** Allocates the pixel memory for the bitmap, given its dimensions and SkColorType. Returns true on success, where success means either setPixels() or setPixelRef() was called. @param bitmap SkBitmap containing SkImageInfo as input, and SkPixelRef as output @return true if SkPixelRef was allocated @example https://fiddle.skia.org/c/@Bitmap_000 */ bool allocPixelRef(SkBitmap* bitmap) override; There are still around 200 disabled examples that need to be fixed (these result from API changes since the author left). Change-Id: I14a31348a9ccaaa31f65424b91e3a3533d2583a7 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/198824 Commit-Queue: Hal Canary <halcanary@google.com> Reviewed-by: Leon Scroggins <scroggo@google.com> Reviewed-by: Joe Gregorio <jcgregorio@google.com>
This commit is contained in:
parent
5ced0bfd00
commit
83c2f70b51
16
BUILD.gn
16
BUILD.gn
@ -2245,6 +2245,22 @@ if (skia_enable_tools) {
|
||||
}
|
||||
}
|
||||
|
||||
import("gn/examples.gni")
|
||||
if (!skia_use_vulkan && (is_mac || is_linux || is_win)) {
|
||||
test_app("fiddle_examples") {
|
||||
sources = [
|
||||
"tools/fiddle/examples.cpp",
|
||||
"tools/fiddle/examples.h"
|
||||
]
|
||||
sources += examples_sources
|
||||
include_dirs = [ "tools" ]
|
||||
deps = [
|
||||
":skia",
|
||||
":skia.h",
|
||||
"modules/skottie",
|
||||
]
|
||||
}
|
||||
}
|
||||
test_app("viewer") {
|
||||
is_shared_library = is_android
|
||||
if (is_ios) {
|
||||
|
19
docs/examples/AutoCanvasRestore_000.cpp
Normal file
19
docs/examples/AutoCanvasRestore_000.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=466ef576b88e29d7252422db7adeed1c
|
||||
REG_FIDDLE(AutoCanvasRestore_000, 256, 128, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
SkFont font(nullptr, 64);
|
||||
for (SkScalar sx : { -1, 1 } ) {
|
||||
for (SkScalar sy : { -1, 1 } ) {
|
||||
SkAutoCanvasRestore autoRestore(canvas, true);
|
||||
SkMatrix m = SkMatrix::MakeAll(sx, 1, 96, 0, sy, 64, 0, 0, 1);
|
||||
canvas->concat(m);
|
||||
canvas->drawString("R", 0, 0, font, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
22
docs/examples/AutoCanvasRestore_001.cpp
Normal file
22
docs/examples/AutoCanvasRestore_001.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=9f459b218ec079c1ada23f4412968f9a
|
||||
REG_FIDDLE(AutoCanvasRestore_001, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
for (bool callRestore : { false, true } ) {
|
||||
for (bool saveCanvas : {false, true} ) {
|
||||
SkAutoCanvasRestore autoRestore(canvas, saveCanvas);
|
||||
if (!saveCanvas) {
|
||||
canvas->save();
|
||||
}
|
||||
SkDebugf("saveCanvas: %s before restore: %d\n",
|
||||
saveCanvas ? "true" : "false", canvas->getSaveCount());
|
||||
if (callRestore) autoRestore.restore();
|
||||
SkDebugf("saveCanvas: %s after restore: %d\n",
|
||||
saveCanvas ? "true" : "false", canvas->getSaveCount());
|
||||
}
|
||||
}
|
||||
SkDebugf("final count: %d\n", canvas->getSaveCount());
|
||||
}
|
||||
} // END FIDDLE
|
17
docs/examples/Bitmap_000.cpp
Normal file
17
docs/examples/Bitmap_000.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=fe79a9c1ec350264eb9c7b2509dd3638
|
||||
REG_FIDDLE(Bitmap_000, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
20
docs/examples/Bitmap_001.cpp
Normal file
20
docs/examples/Bitmap_001.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=6739d14ec0d6a373f2fcadc6b3077fd4
|
||||
REG_FIDDLE(Bitmap_001, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"};
|
||||
const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
||||
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm",
|
||||
"RGBA_F16"};
|
||||
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);
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
16
docs/examples/Bitmap_002.cpp
Normal file
16
docs/examples/Bitmap_002.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=bbbae7a181bfd128a4484e8e9f454db1
|
||||
REG_FIDDLE(Bitmap_002, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkBitmap original;
|
||||
if (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");
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
17
docs/examples/Bitmap_003.cpp
Normal file
17
docs/examples/Bitmap_003.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=40afd4f1fa69e02d69d92b38252088ef
|
||||
REG_FIDDLE(Bitmap_003, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkBitmap original;
|
||||
if (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));
|
||||
// NOLINTNEXTLINE(bugprone-use-after-move)
|
||||
SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false");
|
||||
SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
16
docs/examples/Bitmap_004.cpp
Normal file
16
docs/examples/Bitmap_004.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=45279c519ae808f78bd30e9d84bdfdde
|
||||
REG_FIDDLE(Bitmap_004, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkBitmap original;
|
||||
if (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");
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
17
docs/examples/Bitmap_005.cpp
Normal file
17
docs/examples/Bitmap_005.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=35ea3fed27d8db22dc00f48670de64de
|
||||
REG_FIDDLE(Bitmap_005, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkBitmap original;
|
||||
if (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);
|
||||
// NOLINTNEXTLINE(bugprone-use-after-move)
|
||||
SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false");
|
||||
SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false");
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
30
docs/examples/Bitmap_006.cpp
Normal file
30
docs/examples/Bitmap_006.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=de9be45255e48fae445c916a41063abc
|
||||
REG_FIDDLE(Bitmap_006, 256, 256, true, 0) {
|
||||
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_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
||||
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm",
|
||||
"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;
|
||||
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;
|
||||
}
|
||||
for (int index = 0; index < 2; ++index) {
|
||||
debugster("one", one);
|
||||
debugster("two", two);
|
||||
one.swap(two);
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
26
docs/examples/Bitmap_007.cpp
Normal file
26
docs/examples/Bitmap_007.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=7f972d742dd78d2500034d8867e9ef2f
|
||||
REG_FIDDLE(Bitmap_007, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkBitmap bitmap;
|
||||
bitmap.allocPixels(SkImageInfo::MakeN32Premul(10, 11));
|
||||
SkCanvas offscreen(bitmap);
|
||||
offscreen.clear(SK_ColorWHITE);
|
||||
SkPaint paint;
|
||||
SkFont font;
|
||||
font.setEdging(SkFont::Edging::kAlias);
|
||||
offscreen.drawString("&", 0, 10, font, paint);
|
||||
const SkPixmap& pixmap = bitmap.pixmap();
|
||||
if (pixmap.addr()) {
|
||||
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');
|
||||
}
|
||||
SkDebugf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
16
docs/examples/Bitmap_008.cpp
Normal file
16
docs/examples/Bitmap_008.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=ec47c4dc23e2925ad565eaba55a91553
|
||||
REG_FIDDLE(Bitmap_008, 256, 256, true, 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_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
||||
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm",
|
||||
"RGBA_F16"};
|
||||
SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(),
|
||||
colors[info.colorType()], alphas[info.alphaType()]);
|
||||
}
|
||||
} // END FIDDLE
|
12
docs/examples/Bitmap_009.cpp
Normal file
12
docs/examples/Bitmap_009.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=d06880c42f8bb3b4c3b67bd988046049
|
||||
REG_FIDDLE(Bitmap_009, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkImageInfo info = SkImageInfo::MakeA8(16, 32);
|
||||
SkBitmap bitmap;
|
||||
bitmap.setInfo(info);
|
||||
SkDebugf("bitmap width: %d info width: %d\n", bitmap.width(), info.width());
|
||||
}
|
||||
} // END FIDDLE
|
12
docs/examples/Bitmap_010.cpp
Normal file
12
docs/examples/Bitmap_010.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=c79a196278c58b34cd5f551b0124ecc9
|
||||
REG_FIDDLE(Bitmap_010, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkImageInfo info = SkImageInfo::MakeA8(16, 32);
|
||||
SkBitmap bitmap;
|
||||
bitmap.setInfo(info);
|
||||
SkDebugf("bitmap height: %d info height: %d\n", bitmap.height(), info.height());
|
||||
}
|
||||
} // END FIDDLE
|
14
docs/examples/Bitmap_011.cpp
Normal file
14
docs/examples/Bitmap_011.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=ceb77fab7326b57822a147b04aa0960e
|
||||
REG_FIDDLE(Bitmap_011, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
||||
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm",
|
||||
"RGBA_F16"};
|
||||
SkBitmap bitmap;
|
||||
bitmap.setInfo(SkImageInfo::MakeA8(16, 32));
|
||||
SkDebugf("color type: k" "%s" "_SkColorType\n", colors[bitmap.colorType()]);
|
||||
}
|
||||
} // END FIDDLE
|
11
docs/examples/Bitmap_012.cpp
Normal file
11
docs/examples/Bitmap_012.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=070b1a60232be499eb10c6ea62371804
|
||||
REG_FIDDLE(Bitmap_012, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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()]);
|
||||
}
|
||||
} // END FIDDLE
|
16
docs/examples/Bitmap_013.cpp
Normal file
16
docs/examples/Bitmap_013.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=817f95879fadba44baf87ea60e9b595a
|
||||
REG_FIDDLE(Bitmap_013, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkBitmap bitmap;
|
||||
bitmap.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
|
||||
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");
|
||||
}
|
||||
} // END FIDDLE
|
18
docs/examples/Bitmap_014.cpp
Normal file
18
docs/examples/Bitmap_014.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=cb028b7931da85b949ad0953b9711f9f
|
||||
REG_FIDDLE(Bitmap_014, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkBitmap bitmap1, bitmap2;
|
||||
bitmap1.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType,
|
||||
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");
|
||||
}
|
||||
} // END FIDDLE
|
24
docs/examples/Bitmap_015.cpp
Normal file
24
docs/examples/Bitmap_015.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=2a688e6f0a516c0d44a826381e9d637f
|
||||
REG_FIDDLE(Bitmap_015, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
||||
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm",
|
||||
"RGBA_F16"};
|
||||
SkImageInfo info = SkImageInfo::MakeA8(1, 1);
|
||||
SkBitmap bitmap;
|
||||
for (SkColorType colorType : {
|
||||
kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
|
||||
kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
|
||||
kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
|
||||
kGray_8_SkColorType, kRGBA_F16_SkColorType
|
||||
} ) {
|
||||
bitmap.setInfo(info.makeColorType(colorType));
|
||||
SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n",
|
||||
colors[colorType], 13 - strlen(colors[colorType]), " ",
|
||||
bitmap.bytesPerPixel());
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
13
docs/examples/Bitmap_016.cpp
Normal file
13
docs/examples/Bitmap_016.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=03a9e08082a23a98de17c3e24871d61a
|
||||
REG_FIDDLE(Bitmap_016, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
24
docs/examples/Bitmap_017.cpp
Normal file
24
docs/examples/Bitmap_017.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=56ede4b7d45c15d5936f81ac3d74f070
|
||||
REG_FIDDLE(Bitmap_017, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
||||
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm",
|
||||
"RGBA_F16"};
|
||||
SkImageInfo info = SkImageInfo::MakeA8(1, 1);
|
||||
SkBitmap bitmap;
|
||||
for (SkColorType colorType : {
|
||||
kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
|
||||
kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
|
||||
kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
|
||||
kGray_8_SkColorType, kRGBA_F16_SkColorType
|
||||
} ) {
|
||||
bitmap.setInfo(info.makeColorType(colorType));
|
||||
SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n",
|
||||
colors[colorType], 14 - strlen(colors[colorType]), " ",
|
||||
bitmap.shiftPerPixel());
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
16
docs/examples/Bitmap_018.cpp
Normal file
16
docs/examples/Bitmap_018.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=a3762c2722b56ba55e42689c527f146c
|
||||
REG_FIDDLE(Bitmap_018, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
14
docs/examples/Bitmap_019.cpp
Normal file
14
docs/examples/Bitmap_019.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=211ec89418011aa6e54aa2cc9567e003
|
||||
REG_FIDDLE(Bitmap_019, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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 " : "");
|
||||
}
|
||||
} // END FIDDLE
|
17
docs/examples/Bitmap_020.cpp
Normal file
17
docs/examples/Bitmap_020.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=daacf43394ce4045a362a48b5774deed
|
||||
REG_FIDDLE(Bitmap_020, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
13
docs/examples/Bitmap_021.cpp
Normal file
13
docs/examples/Bitmap_021.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=a654fd0b73f424859ae6c95e03f55099
|
||||
REG_FIDDLE(Bitmap_021, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
34
docs/examples/Bitmap_022.cpp
Normal file
34
docs/examples/Bitmap_022.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=af3adcbea7b58bf90298ca5e0ea93030
|
||||
REG_FIDDLE(Bitmap_022, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
||||
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm",
|
||||
"RGBA_F16"};
|
||||
const char* alphas[] = {"Unknown ", "Opaque ", "Premul ", "Unpremul"};
|
||||
SkBitmap bitmap;
|
||||
SkAlphaType alphaTypes[] = { kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
||||
kUnpremul_SkAlphaType
|
||||
};
|
||||
SkDebugf("%18s%15s%17s%18s%19s\n", "Canonical", "Unknown", "Opaque", "Premul", "Unpremul");
|
||||
for (SkColorType colorType : {
|
||||
kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
|
||||
kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
|
||||
kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
|
||||
kGray_8_SkColorType, kRGBA_F16_SkColorType
|
||||
} ) {
|
||||
for (SkAlphaType canonicalAlphaType : alphaTypes) {
|
||||
SkColorTypeValidateAlphaType(colorType, kUnknown_SkAlphaType, &canonicalAlphaType );
|
||||
SkDebugf("%12s %9s ", 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
18
docs/examples/Bitmap_023.cpp
Normal file
18
docs/examples/Bitmap_023.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=e006bb05cf74ec8d2b3d6adeb5dba11b
|
||||
REG_FIDDLE(Bitmap_023, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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 ? '=' : '!');
|
||||
}
|
||||
} // END FIDDLE
|
17
docs/examples/Bitmap_024.cpp
Normal file
17
docs/examples/Bitmap_024.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=165c8f208829fc0908e8a50da60c0076
|
||||
REG_FIDDLE(Bitmap_024, 256, 256, true, 0) {
|
||||
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 computeByteSize: %13lld\n", width, height,
|
||||
bitmap.computeByteSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
17
docs/examples/Bitmap_025.cpp
Normal file
17
docs/examples/Bitmap_025.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=db61fdcd382342ee88ea1b4f27c27b95
|
||||
REG_FIDDLE(Bitmap_025, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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 ");
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
18
docs/examples/Bitmap_026.cpp
Normal file
18
docs/examples/Bitmap_026.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=9210060d1f4ca46e1375496237902ef3
|
||||
REG_FIDDLE(Bitmap_026, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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");
|
||||
// Triggers assert if SK_DEBUG is true, runs fine otherwise.
|
||||
// offscreen.clear(SK_ColorBLACK);
|
||||
}
|
||||
} // END FIDDLE
|
20
docs/examples/Bitmap_027.cpp
Normal file
20
docs/examples/Bitmap_027.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=5e76b68bb46d54315eb0c12d83bd6949
|
||||
REG_FIDDLE(Bitmap_027, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
17
docs/examples/Bitmap_028.cpp
Normal file
17
docs/examples/Bitmap_028.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=23c4543ac6cdd0e8fe762816a0dc2e03
|
||||
REG_FIDDLE(Bitmap_028, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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 ");
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
19
docs/examples/Bitmap_029.cpp
Normal file
19
docs/examples/Bitmap_029.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=e8627a4df659b896402f89a91326618f
|
||||
REG_FIDDLE(Bitmap_029, 256, 20, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
16
docs/examples/Bitmap_030.cpp
Normal file
16
docs/examples/Bitmap_030.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=52ccaeda67924373c5b55a2b89fe314d
|
||||
REG_FIDDLE(Bitmap_030, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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");
|
||||
}
|
||||
} // END FIDDLE
|
18
docs/examples/Bitmap_031.cpp
Normal file
18
docs/examples/Bitmap_031.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=9df1baa17658fbd0c419780f26fd854f
|
||||
REG_FIDDLE(Bitmap_031, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
16
docs/examples/Bitmap_032.cpp
Normal file
16
docs/examples/Bitmap_032.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=2431ebc7e7d1e91e6d9daafd0f7a478f
|
||||
REG_FIDDLE(Bitmap_032, 256, 160, false, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
15
docs/examples/Bitmap_033.cpp
Normal file
15
docs/examples/Bitmap_033.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=0c45da35172bc0a529b2faecddae62a2
|
||||
REG_FIDDLE(Bitmap_033, 256, 256, false, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkIRect bounds;
|
||||
source.getBounds(&bounds);
|
||||
bounds.inset(100, 100);
|
||||
SkBitmap bitmap;
|
||||
source.extractSubset(&bitmap, bounds);
|
||||
canvas->scale(.5f, .5f);
|
||||
canvas->drawBitmap(bitmap, 10, 10);
|
||||
}
|
||||
} // END FIDDLE
|
15
docs/examples/Bitmap_034.cpp
Normal file
15
docs/examples/Bitmap_034.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=3e9126152ff1cc592aef6facbcb5fc96
|
||||
REG_FIDDLE(Bitmap_034, 256, 64, false, 4) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
canvas->scale(.5f, .5f);
|
||||
SkIRect bounds = source.bounds();
|
||||
for (int x : { 0, bounds.width() } ) {
|
||||
for (int y : { 0, bounds.height() } ) {
|
||||
canvas->drawBitmap(source, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
15
docs/examples/Bitmap_035.cpp
Normal file
15
docs/examples/Bitmap_035.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=647056bcc12c27fb4413f212f33a2898
|
||||
REG_FIDDLE(Bitmap_035, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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 ? '=' : '!');
|
||||
}
|
||||
} // END FIDDLE
|
17
docs/examples/Bitmap_036.cpp
Normal file
17
docs/examples/Bitmap_036.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=d6dd0b425aa550f21b938a18c2e1a981
|
||||
REG_FIDDLE(Bitmap_036, 256, 256, true, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
18
docs/examples/Bitmap_037.cpp
Normal file
18
docs/examples/Bitmap_037.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=599ab64d0aea005498176249bbfb64eb
|
||||
REG_FIDDLE(Bitmap_037, 256, 96, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkBitmap bitmap;
|
||||
bitmap.setInfo(SkImageInfo::MakeN32(44, 16, kOpaque_SkAlphaType));
|
||||
bitmap.allocPixels();
|
||||
bitmap.eraseColor(SK_ColorGREEN);
|
||||
SkCanvas offscreen(bitmap);
|
||||
SkPaint paint;
|
||||
SkFont font;
|
||||
offscreen.drawString("!@#$%", 0, 12, font, paint);
|
||||
canvas->scale(6, 6);
|
||||
canvas->drawBitmap(bitmap, 0, 0);
|
||||
}
|
||||
} // END FIDDLE
|
15
docs/examples/Bitmap_038.cpp
Normal file
15
docs/examples/Bitmap_038.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=f1d1880d38e0aea4cefd3e11745e8a09
|
||||
REG_FIDDLE(Bitmap_038, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkBitmap bitmap;
|
||||
if (!bitmap.tryAllocPixelsFlags(SkImageInfo::MakeN32(10000, 10000, kOpaque_SkAlphaType),
|
||||
SkBitmap::kZeroPixels_AllocFlag)) {
|
||||
SkDebugf("bitmap allocation failed!\n");
|
||||
} else {
|
||||
SkDebugf("bitmap allocation succeeded!\n");
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
18
docs/examples/Bitmap_039.cpp
Normal file
18
docs/examples/Bitmap_039.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=737e721c7d9e0f367d25521a1b823b9d
|
||||
REG_FIDDLE(Bitmap_039, 256, 128, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkBitmap bitmap;
|
||||
bitmap.allocPixelsFlags(SkImageInfo::MakeN32(44, 16, kPremul_SkAlphaType),
|
||||
SkBitmap::kZeroPixels_AllocFlag);
|
||||
SkCanvas offscreen(bitmap);
|
||||
SkPaint paint;
|
||||
SkFont font;
|
||||
offscreen.drawString("!@#$%", 0, 12, font, paint);
|
||||
canvas->scale(6, 6);
|
||||
canvas->drawBitmap(bitmap, 0, 0);
|
||||
canvas->drawBitmap(bitmap, 8, 8);
|
||||
}
|
||||
} // END FIDDLE
|
18
docs/examples/Bitmap_040.cpp
Normal file
18
docs/examples/Bitmap_040.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=34479d5aa23ce9f5e334b0786c9edb22
|
||||
REG_FIDDLE(Bitmap_040, 256, 256, false, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
17
docs/examples/Bitmap_041.cpp
Normal file
17
docs/examples/Bitmap_041.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=555c0f62f96602a9dcd459badcd005e0
|
||||
REG_FIDDLE(Bitmap_041, 256, 256, false, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
17
docs/examples/Bitmap_042.cpp
Normal file
17
docs/examples/Bitmap_042.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=7ef3d043c4c5885649e591dd7dca92ff
|
||||
REG_FIDDLE(Bitmap_042, 256, 256, false, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
16
docs/examples/Bitmap_043.cpp
Normal file
16
docs/examples/Bitmap_043.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=91f474a11a2112cd5c88c40a9015048d
|
||||
REG_FIDDLE(Bitmap_043, 256, 256, false, 4) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
19
docs/examples/Bitmap_044.cpp
Normal file
19
docs/examples/Bitmap_044.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=a2b1e0910f37066f15ae56368775a6d8
|
||||
REG_FIDDLE(Bitmap_044, 256, 160, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
23
docs/examples/Bitmap_045.cpp
Normal file
23
docs/examples/Bitmap_045.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=c717491f9251604724c9cbde7088ec20
|
||||
REG_FIDDLE(Bitmap_045, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
19
docs/examples/Bitmap_046.cpp
Normal file
19
docs/examples/Bitmap_046.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=8c4f7bf73fffa1a812ee8e88e44e639c
|
||||
REG_FIDDLE(Bitmap_046, 256, 256, true, 0) {
|
||||
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 ");
|
||||
}
|
||||
} // END FIDDLE
|
21
docs/examples/Bitmap_047.cpp
Normal file
21
docs/examples/Bitmap_047.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=a7e04447b2081010c50d7920e80a6bb2
|
||||
REG_FIDDLE(Bitmap_047, 256, 256, false, 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);
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
22
docs/examples/Bitmap_048.cpp
Normal file
22
docs/examples/Bitmap_048.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=6e2a8c9358b34aebd2ec586815fe9d3a
|
||||
REG_FIDDLE(Bitmap_048, 256, 64, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
16
docs/examples/Bitmap_049.cpp
Normal file
16
docs/examples/Bitmap_049.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=f0db16e06c9a1436917c8179f8c1718f
|
||||
REG_FIDDLE(Bitmap_049, 256, 50, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
19
docs/examples/Bitmap_050.cpp
Normal file
19
docs/examples/Bitmap_050.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=720e4c053fae9e929ab6518b47e49370
|
||||
REG_FIDDLE(Bitmap_050, 256, 50, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
19
docs/examples/Bitmap_051.cpp
Normal file
19
docs/examples/Bitmap_051.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=1219b38c788bf270fb20f8cd2d78cff8
|
||||
REG_FIDDLE(Bitmap_051, 256, 50, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
45
docs/examples/Bitmap_052.cpp
Normal file
45
docs/examples/Bitmap_052.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=eb6f861ca1839146d26e40d56c2a001c
|
||||
REG_FIDDLE(Bitmap_052, 256, 100, false, 0) {
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
32
docs/examples/Bitmap_053.cpp
Normal file
32
docs/examples/Bitmap_053.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=1b2800d23c9ea249b45c2c21a34b6d14
|
||||
REG_FIDDLE(Bitmap_053, 256, 32, false, 0) {
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
13
docs/examples/Bitmap_054.cpp
Normal file
13
docs/examples/Bitmap_054.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=5db2d30870a7cc45f28e22578d1880c3
|
||||
REG_FIDDLE(Bitmap_054, 256, 256, true, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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) ? '=' : '!');
|
||||
}
|
||||
} // END FIDDLE
|
14
docs/examples/Bitmap_055.cpp
Normal file
14
docs/examples/Bitmap_055.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=6d31686c6c0829c70f284ae716526d6a
|
||||
REG_FIDDLE(Bitmap_055, 256, 256, true, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
13
docs/examples/Bitmap_056.cpp
Normal file
13
docs/examples/Bitmap_056.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=f98cc0451c6e77a8833d261c9a484c5f
|
||||
REG_FIDDLE(Bitmap_056, 256, 140, false, 5) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
11
docs/examples/Bitmap_057.cpp
Normal file
11
docs/examples/Bitmap_057.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=e89c78ca992e2e789ed50944fe68f920
|
||||
REG_FIDDLE(Bitmap_057, 256, 160, false, 5) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
if (source.readyToDraw()) {
|
||||
canvas->drawBitmap(source, 10, 10);
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
14
docs/examples/Bitmap_058.cpp
Normal file
14
docs/examples/Bitmap_058.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=db9dd91e0207c3941c09538555817b4b
|
||||
REG_FIDDLE(Bitmap_058, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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());
|
||||
}
|
||||
} // END FIDDLE
|
19
docs/examples/Bitmap_059.cpp
Normal file
19
docs/examples/Bitmap_059.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=8f463ed17b0ed4fb9c503a0ec71706f9
|
||||
REG_FIDDLE(Bitmap_059, 256, 20, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
13
docs/examples/Bitmap_060.cpp
Normal file
13
docs/examples/Bitmap_060.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=418928dbfffa9eb00c8225530f44baf5
|
||||
REG_FIDDLE(Bitmap_060, 256, 20, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkBitmap bitmap;
|
||||
bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kOpaque_SkAlphaType));
|
||||
bitmap.eraseColor(SK_ColorRED);
|
||||
canvas->scale(16, 16);
|
||||
canvas->drawBitmap(bitmap, 0, 0);
|
||||
}
|
||||
} // END FIDDLE
|
14
docs/examples/Bitmap_061.cpp
Normal file
14
docs/examples/Bitmap_061.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=67277b0a1003f340473a35982533561c
|
||||
REG_FIDDLE(Bitmap_061, 256, 80, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
17
docs/examples/Bitmap_062.cpp
Normal file
17
docs/examples/Bitmap_062.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=2c5c4230ccd2861a5d15b7cd2764ab6e
|
||||
REG_FIDDLE(Bitmap_062, 256, 70, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
33
docs/examples/Bitmap_063.cpp
Normal file
33
docs/examples/Bitmap_063.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=193d1f6d8a43b7a8e9f27ba21de38617
|
||||
REG_FIDDLE(Bitmap_063, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
const int w = 4;
|
||||
const int h = 4;
|
||||
SkColor colors[][w] = {
|
||||
{ 0x00000000, 0x2a0e002a, 0x55380055, 0x7f7f007f },
|
||||
{ 0x2a000e2a, 0x551c1c55, 0x7f542a7f, 0xaaaa38aa },
|
||||
{ 0x55003855, 0x7f2a547f, 0xaa7171aa, 0xd4d48dd4 },
|
||||
{ 0x7f007f7f, 0xaa38aaaa, 0xd48dd4d4, 0xffffffff }
|
||||
};
|
||||
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' : ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
12
docs/examples/Bitmap_064.cpp
Normal file
12
docs/examples/Bitmap_064.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=ffcefb2344cd38c3b99f69cfe6d64a17
|
||||
REG_FIDDLE(Bitmap_064, 256, 256, true, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
char* row0 = (char* ) source.getAddr(0, 0);
|
||||
char* row1 = (char* ) source.getAddr(0, 1);
|
||||
SkDebugf("addr interval %c= rowBytes\n",
|
||||
(size_t) (row1 - row0) == source.rowBytes() ? '=' : '!');
|
||||
}
|
||||
} // END FIDDLE
|
12
docs/examples/Bitmap_065.cpp
Normal file
12
docs/examples/Bitmap_065.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=837a2bcc9fb9ce617a3420956cefc64a
|
||||
REG_FIDDLE(Bitmap_065, 256, 256, true, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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() ? '=' : '!');
|
||||
}
|
||||
} // END FIDDLE
|
18
docs/examples/Bitmap_066.cpp
Normal file
18
docs/examples/Bitmap_066.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=53e00899ef2e00e2096daf7a07d9b059
|
||||
REG_FIDDLE(Bitmap_066, 256, 256, true, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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() ? '=' : '!');
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
17
docs/examples/Bitmap_067.cpp
Normal file
17
docs/examples/Bitmap_067.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=cb9a08e8ff779b6a1cf8bb54f3883aaf
|
||||
REG_FIDDLE(Bitmap_067, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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) ? '=' : '!');
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
25
docs/examples/Bitmap_068.cpp
Normal file
25
docs/examples/Bitmap_068.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=304148c50c91490bfd58e9222342419c
|
||||
REG_FIDDLE(Bitmap_068, 256, 256, true, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
28
docs/examples/Bitmap_069.cpp
Normal file
28
docs/examples/Bitmap_069.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=b2cbbbbcffb618865d8aae3bc04b2a62
|
||||
REG_FIDDLE(Bitmap_069, 256, 128, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
canvas->drawBitmap(bitmap, 0, 64);
|
||||
}
|
||||
} // END FIDDLE
|
23
docs/examples/Bitmap_070.cpp
Normal file
23
docs/examples/Bitmap_070.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=e9f70cbc9827097449a386ec7a8a8188
|
||||
REG_FIDDLE(Bitmap_070, 256, 256, false, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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());
|
||||
canvas->drawBitmap(bitmap, 0, 0);
|
||||
}
|
||||
} // END FIDDLE
|
21
docs/examples/Bitmap_071.cpp
Normal file
21
docs/examples/Bitmap_071.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=4590fbf052659d6e629fbfd827081ae5
|
||||
REG_FIDDLE(Bitmap_071, 256, 128, false, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
std::vector<int32_t> 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);
|
||||
}
|
||||
} // END FIDDLE
|
26
docs/examples/Bitmap_072.cpp
Normal file
26
docs/examples/Bitmap_072.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=9b3133a6673d2514d166398adbe1f9f4
|
||||
REG_FIDDLE(Bitmap_072, 256, 256, false, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
16
docs/examples/Bitmap_073.cpp
Normal file
16
docs/examples/Bitmap_073.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=faa5dfa466f6e16c07c124d971f32679
|
||||
REG_FIDDLE(Bitmap_073, 256, 80, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
23
docs/examples/Bitmap_074.cpp
Normal file
23
docs/examples/Bitmap_074.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=ab6577df079e6c70511cf2bfc6447b44
|
||||
REG_FIDDLE(Bitmap_074, 256, 100, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
29
docs/examples/Bitmap_075.cpp
Normal file
29
docs/examples/Bitmap_075.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=092739b4cd5d732a27c07ced8ef45f01
|
||||
REG_FIDDLE(Bitmap_075, 256, 160, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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);
|
||||
}
|
||||
} // END FIDDLE
|
25
docs/examples/Bitmap_076.cpp
Normal file
25
docs/examples/Bitmap_076.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=cd7543fa8c9f3cede46dc2d72eb8c4bd
|
||||
REG_FIDDLE(Bitmap_076, 256, 128, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
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(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);
|
||||
}
|
||||
} // END FIDDLE
|
26
docs/examples/Bitmap_077.cpp
Normal file
26
docs/examples/Bitmap_077.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=0cc2c6a0dffa61a88711534bd3d43b40
|
||||
REG_FIDDLE(Bitmap_077, 256, 256, true, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkBitmap bitmap;
|
||||
bitmap.allocPixels(SkImageInfo::MakeN32Premul(6, 11));
|
||||
SkCanvas offscreen(bitmap);
|
||||
offscreen.clear(SK_ColorWHITE);
|
||||
SkPaint paint;
|
||||
SkFont font;
|
||||
offscreen.drawString("?", 0, 10, font, 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
19
docs/examples/BlendMode_000.cpp
Normal file
19
docs/examples/BlendMode_000.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=a9b56a26ca469bab9ab10e16f62fb2e2
|
||||
REG_FIDDLE(BlendMode_000, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
canvas->saveLayer(nullptr, nullptr);
|
||||
canvas->drawColor(SK_ColorYELLOW, SkBlendMode::kClear);
|
||||
SkPaint paint;
|
||||
for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) {
|
||||
SkColor colors[] = { color, SkColorSetA(color, 0) };
|
||||
paint.setShader(SkGradientShader::MakeRadial({ 64, 64}, 100,
|
||||
colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
|
||||
canvas->drawCircle(64, 64, 100, paint);
|
||||
canvas->translate(64, 64);
|
||||
}
|
||||
canvas->restore();
|
||||
}
|
||||
} // END FIDDLE
|
18
docs/examples/BlendMode_001.cpp
Normal file
18
docs/examples/BlendMode_001.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=0fc85dd916cc1a5896d36c80b9847391
|
||||
REG_FIDDLE(BlendMode_001, 256, 256, false, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
canvas->drawImage(image, 0, 0);
|
||||
canvas->clipRect({50, 50, 200, 200});
|
||||
SkPaint srcBlend;
|
||||
srcBlend.setBlendMode(SkBlendMode::kSrc);
|
||||
canvas->saveLayer(nullptr, &srcBlend);
|
||||
canvas->drawColor(0);
|
||||
SkPaint transRed;
|
||||
transRed.setColor(SkColorSetA(SK_ColorRED, 127));
|
||||
canvas->drawCircle(125, 125, 75, transRed);
|
||||
canvas->restore();
|
||||
}
|
||||
} // END FIDDLE
|
14
docs/examples/BlendMode_002.cpp
Normal file
14
docs/examples/BlendMode_002.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=35915a2273be1076f00f2e47998ce808
|
||||
REG_FIDDLE(BlendMode_002, 256, 256, false, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 125, 128 } };
|
||||
SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } };
|
||||
SkColor colors[] = { 0x7f55aa00, 0x7f3333bf };
|
||||
canvas->drawAtlas(image.get(), xforms, tex, colors, 2, SkBlendMode::kSrc, nullptr, nullptr);
|
||||
canvas->translate(128, 0);
|
||||
canvas->drawAtlas(image.get(), xforms, tex, colors, 2, SkBlendMode::kDst, nullptr, nullptr);
|
||||
}
|
||||
} // END FIDDLE
|
22
docs/examples/BlendMode_003.cpp
Normal file
22
docs/examples/BlendMode_003.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=2ea9c149964a06cdb4929158cb4f15f8
|
||||
REG_FIDDLE(BlendMode_003, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
|
||||
SkPoint horz[] = { { 0, 0 }, { 256, 0 } };
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
paint.setBlendMode(SkBlendMode::kDstIn);
|
||||
SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT };
|
||||
SkPoint vert[] = { { 0, 0 }, { 0, 256 } };
|
||||
paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
canvas->clipRect( { 30, 30, 226, 226 } );
|
||||
canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kSrcOver);
|
||||
}
|
||||
} // END FIDDLE
|
22
docs/examples/BlendMode_004.cpp
Normal file
22
docs/examples/BlendMode_004.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=10dbb4d97902956ef5f5f8562f65119e
|
||||
REG_FIDDLE(BlendMode_004, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
|
||||
SkPoint horz[] = { { 0, 0 }, { 256, 0 } };
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
paint.setBlendMode(SkBlendMode::kDstIn);
|
||||
SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT };
|
||||
SkPoint vert[] = { { 0, 0 }, { 0, 256 } };
|
||||
paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
canvas->clipRect( { 30, 30, 226, 226 } );
|
||||
canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kDstOver);
|
||||
}
|
||||
} // END FIDDLE
|
22
docs/examples/BlendMode_005.cpp
Normal file
22
docs/examples/BlendMode_005.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=b0833c18fe8b0eeaab9bd6d2160d272f
|
||||
REG_FIDDLE(BlendMode_005, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
|
||||
SkPoint horz[] = { { 0, 0 }, { 256, 0 } };
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
paint.setBlendMode(SkBlendMode::kDstIn);
|
||||
SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT };
|
||||
SkPoint vert[] = { { 0, 0 }, { 0, 256 } };
|
||||
paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
canvas->clipRect( { 30, 30, 226, 226 } );
|
||||
canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kSrcIn);
|
||||
}
|
||||
} // END FIDDLE
|
22
docs/examples/BlendMode_006.cpp
Normal file
22
docs/examples/BlendMode_006.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=a5eeba05ccf6097a5d110a9d64f97c25
|
||||
REG_FIDDLE(BlendMode_006, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
|
||||
SkPoint horz[] = { { 0, 0 }, { 256, 0 } };
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
paint.setBlendMode(SkBlendMode::kDstIn);
|
||||
SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT };
|
||||
SkPoint vert[] = { { 0, 0 }, { 0, 256 } };
|
||||
paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
canvas->clipRect( { 30, 30, 226, 226 } );
|
||||
canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kDstIn);
|
||||
}
|
||||
} // END FIDDLE
|
22
docs/examples/BlendMode_007.cpp
Normal file
22
docs/examples/BlendMode_007.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=ccc1e74226e0c9eacbc21f1eed017b84
|
||||
REG_FIDDLE(BlendMode_007, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
|
||||
SkPoint horz[] = { { 0, 0 }, { 256, 0 } };
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
paint.setBlendMode(SkBlendMode::kDstIn);
|
||||
SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT };
|
||||
SkPoint vert[] = { { 0, 0 }, { 0, 256 } };
|
||||
paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
canvas->clipRect( { 30, 30, 226, 226 } );
|
||||
canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kSrcOut);
|
||||
}
|
||||
} // END FIDDLE
|
22
docs/examples/BlendMode_008.cpp
Normal file
22
docs/examples/BlendMode_008.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=b9a894c9accfc5d94081bbd77d5d790a
|
||||
REG_FIDDLE(BlendMode_008, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
|
||||
SkPoint horz[] = { { 0, 0 }, { 256, 0 } };
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
paint.setBlendMode(SkBlendMode::kDstIn);
|
||||
SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT };
|
||||
SkPoint vert[] = { { 0, 0 }, { 0, 256 } };
|
||||
paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
canvas->clipRect( { 30, 30, 226, 226 } );
|
||||
canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kDstOut);
|
||||
}
|
||||
} // END FIDDLE
|
22
docs/examples/BlendMode_009.cpp
Normal file
22
docs/examples/BlendMode_009.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=a13148977bfc985934a92752c83a2041
|
||||
REG_FIDDLE(BlendMode_009, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
|
||||
SkPoint horz[] = { { 0, 0 }, { 256, 0 } };
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
paint.setBlendMode(SkBlendMode::kDstIn);
|
||||
SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT };
|
||||
SkPoint vert[] = { { 0, 0 }, { 0, 256 } };
|
||||
paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
canvas->clipRect( { 30, 30, 226, 226 } );
|
||||
canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kSrcATop);
|
||||
}
|
||||
} // END FIDDLE
|
22
docs/examples/BlendMode_010.cpp
Normal file
22
docs/examples/BlendMode_010.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=1955856d45773a4fd914fcc1f813222f
|
||||
REG_FIDDLE(BlendMode_010, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
|
||||
SkPoint horz[] = { { 0, 0 }, { 256, 0 } };
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
paint.setBlendMode(SkBlendMode::kDstATop);
|
||||
SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT };
|
||||
SkPoint vert[] = { { 0, 0 }, { 0, 256 } };
|
||||
paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
canvas->clipRect( { 30, 30, 226, 226 } );
|
||||
canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kSrcATop);
|
||||
}
|
||||
} // END FIDDLE
|
18
docs/examples/BlendMode_011.cpp
Normal file
18
docs/examples/BlendMode_011.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=29db2c7493d9098b8a086ddbe30dd6d6
|
||||
REG_FIDDLE(BlendMode_011, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setBlendMode(SkBlendMode::kXor);
|
||||
for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) {
|
||||
SkColor colors[] = { color, SkColorSetA(color, 192), SkColorSetA(color, 128),
|
||||
SkColorSetA(color, 0) };
|
||||
paint.setShader(SkGradientShader::MakeRadial({ 64, 64}, 100,
|
||||
colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
|
||||
canvas->drawCircle(64, 64, 100, paint);
|
||||
canvas->translate(64, 64);
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
19
docs/examples/BlendMode_012.cpp
Normal file
19
docs/examples/BlendMode_012.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=05383441e510d54008402e128fc8ad2b
|
||||
REG_FIDDLE(BlendMode_012, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
canvas->drawColor(SK_ColorBLACK);
|
||||
SkPaint paint;
|
||||
paint.setBlendMode(SkBlendMode::kPlus);
|
||||
for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) {
|
||||
SkColor colors[] = { color, SkColorSetA(color, 192), SkColorSetA(color, 128),
|
||||
SkColorSetA(color, 0) };
|
||||
paint.setShader(SkGradientShader::MakeRadial({ 64, 64}, 100,
|
||||
colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
|
||||
canvas->drawCircle(64, 64, 100, paint);
|
||||
canvas->translate(64, 64);
|
||||
}
|
||||
}
|
||||
} // END FIDDLE
|
29
docs/examples/BlendMode_013.cpp
Normal file
29
docs/examples/BlendMode_013.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=3fdac2b2f48bd227d2e74234c260bc8e
|
||||
REG_FIDDLE(BlendMode_013, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
auto drawSquare = [=](int dx, int dy, SkBlendMode mode, const char* label) -> void {
|
||||
const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
|
||||
const SkPoint horz[] = { { 0, 0 }, { 128, 0 } };
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode));
|
||||
paint.setBlendMode(mode);
|
||||
canvas->translate(dx, dy);
|
||||
canvas->drawRect({0, 0, 128, 128}, paint);
|
||||
paint.setBlendMode(SkBlendMode::kXor);
|
||||
SkFont font;
|
||||
canvas->drawString(label, 40, 100, font, paint);
|
||||
};
|
||||
drawSquare(0, 0, SkBlendMode::kSrc, "destination");
|
||||
drawSquare(128, 0, SkBlendMode::kSrc, "");
|
||||
drawSquare(0, 128, SkBlendMode::kSrc, "");
|
||||
canvas->translate(-128, -128);
|
||||
canvas->rotate(90, 0, 128);
|
||||
drawSquare(0, 0, SkBlendMode::kSrc, "source");
|
||||
drawSquare(0, -128, SkBlendMode::kModulate, "modulate");
|
||||
drawSquare(-128, 0, SkBlendMode::kMultiply, "multiply");
|
||||
}
|
||||
} // END FIDDLE
|
22
docs/examples/BlendMode_014.cpp
Normal file
22
docs/examples/BlendMode_014.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=b7b42965927788d853f449f08ddf46de
|
||||
REG_FIDDLE(BlendMode_014, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
|
||||
SkPoint horz[] = { { 0, 0 }, { 256, 0 } };
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
paint.setBlendMode(SkBlendMode::kDstATop);
|
||||
SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT };
|
||||
SkPoint vert[] = { { 0, 0 }, { 0, 256 } };
|
||||
paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
canvas->clipRect( { 30, 30, 226, 226 } );
|
||||
canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kScreen);
|
||||
}
|
||||
} // END FIDDLE
|
22
docs/examples/BlendMode_015.cpp
Normal file
22
docs/examples/BlendMode_015.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=03bf042201de02d6d131938ccd3172eb
|
||||
REG_FIDDLE(BlendMode_015, 256, 256, false, 0) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
|
||||
SkPoint horz[] = { { 0, 0 }, { 256, 0 } };
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
paint.setBlendMode(SkBlendMode::kDstATop);
|
||||
SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT };
|
||||
SkPoint vert[] = { { 0, 0 }, { 0, 256 } };
|
||||
paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas),
|
||||
SkShader::kClamp_TileMode));
|
||||
canvas->drawPaint(paint);
|
||||
canvas->clipRect( { 30, 30, 226, 226 } );
|
||||
canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kOverlay);
|
||||
}
|
||||
} // END FIDDLE
|
16
docs/examples/BlendMode_016.cpp
Normal file
16
docs/examples/BlendMode_016.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=23c974d2759f523ca2f4a78ae86855c3
|
||||
REG_FIDDLE(BlendMode_016, 256, 256, false, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
canvas->drawImage(image, 0, 0);
|
||||
SkColor colors[] = { SK_ColorWHITE, SK_ColorBLACK };
|
||||
SkPoint horz[] = { { 0, 0 }, { 256, 0 } };
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode));
|
||||
paint.setBlendMode(SkBlendMode::kDarken);
|
||||
canvas->drawPaint(paint);
|
||||
}
|
||||
} // END FIDDLE
|
16
docs/examples/BlendMode_017.cpp
Normal file
16
docs/examples/BlendMode_017.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=95cb08b8c8db3af3b2c9ad56ae7d6bc1
|
||||
REG_FIDDLE(BlendMode_017, 256, 256, false, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
canvas->drawImage(image, 0, 0);
|
||||
SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
|
||||
SkPoint horz[] = { { 0, 0 }, { 256, 0 } };
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkShader::kClamp_TileMode));
|
||||
paint.setBlendMode(SkBlendMode::kLighten);
|
||||
canvas->drawPaint(paint);
|
||||
}
|
||||
} // END FIDDLE
|
11
docs/examples/BlendMode_018.cpp
Normal file
11
docs/examples/BlendMode_018.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
#include "fiddle/examples.h"
|
||||
// HASH=280ad6267a7d2d77b6d2c4531c6fc0bf
|
||||
REG_FIDDLE(BlendMode_018, 256, 256, false, 3) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
canvas->drawImage(image, 0, 0);
|
||||
canvas->clipRect({128, 0, 256, 256});
|
||||
canvas->drawColor(SkColorSetARGB(0x80, 0x90, 0x90, 0x90), SkBlendMode::kColorDodge);
|
||||
}
|
||||
} // END FIDDLE
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user