1*c8dee2aaSAndroid Build Coastguard Worker // Copyright 2019 Google LLC.
2*c8dee2aaSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3*c8dee2aaSAndroid Build Coastguard Worker #include "tools/fiddle/examples.h"
4*c8dee2aaSAndroid Build Coastguard Worker REG_FIDDLE(Pixmap_writable_addr32, 256, 72, false, 4) {
draw(SkCanvas * canvas)5*c8dee2aaSAndroid Build Coastguard Worker void draw(SkCanvas* canvas) {
6*c8dee2aaSAndroid Build Coastguard Worker std::vector<int32_t> pixels;
7*c8dee2aaSAndroid Build Coastguard Worker pixels.resize(image->height() * image->width() * 4);
8*c8dee2aaSAndroid Build Coastguard Worker SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType,
9*c8dee2aaSAndroid Build Coastguard Worker image->alphaType()), (const void*) &pixels.front(), image->width() * 4);
10*c8dee2aaSAndroid Build Coastguard Worker image->readPixels(nullptr, pixmap, 0, 0);
11*c8dee2aaSAndroid Build Coastguard Worker for (int y = 0; y < pixmap.height() / 2; ++y) {
12*c8dee2aaSAndroid Build Coastguard Worker for (int x = 0; x < pixmap.width(); ++x) {
13*c8dee2aaSAndroid Build Coastguard Worker if ((x & 4) == (y & 4)) {
14*c8dee2aaSAndroid Build Coastguard Worker *pixmap.writable_addr32(x, y) =
15*c8dee2aaSAndroid Build Coastguard Worker *pixmap.writable_addr32(pixmap.width() - x - 1, pixmap.height() - y - 1);
16*c8dee2aaSAndroid Build Coastguard Worker }
17*c8dee2aaSAndroid Build Coastguard Worker }
18*c8dee2aaSAndroid Build Coastguard Worker }
19*c8dee2aaSAndroid Build Coastguard Worker SkBitmap bitmap;
20*c8dee2aaSAndroid Build Coastguard Worker bitmap.installPixels(pixmap);
21*c8dee2aaSAndroid Build Coastguard Worker canvas->drawImage(bitmap.asImage(), 0, 0);
22*c8dee2aaSAndroid Build Coastguard Worker }
23*c8dee2aaSAndroid Build Coastguard Worker } // END FIDDLE
24