xref: /aosp_15_r20/external/skia/docs/examples/Canvas_writePixels_2.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 // Copyright 2019 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(Canvas_writePixels_2, 256, 256, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(2, 2);
7     SkBitmap bitmap;
8     bitmap.setInfo(imageInfo);
9     uint32_t pixels[4];
10     bitmap.setPixels(pixels);
11     for (int y = 0; y < 256; y += 2) {
12         for (int x = 0; x < 256;  x += 2) {
13             pixels[0] = SkColorSetRGB(x, y, x | y);
14             pixels[1] = SkColorSetRGB(x ^ y, y, x);
15             pixels[2] = SkColorSetRGB(x, x & y, y);
16             pixels[3] = SkColorSetRGB((~x) & 0xFF, (~y) & 0xFF, x);
17             canvas->writePixels(bitmap, x, y);
18         }
19     }
20 }
21 }  // END FIDDLE
22