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 // HASH=3ac267b08b12dc83c95f91d8dd5d70ee
5 REG_FIDDLE(ImageInfo_makeColorType, 256, 256, false, 0) {
draw(SkCanvas * canvas)6 void draw(SkCanvas* canvas) {
7 const int width = 256;
8 const int height = 128;
9 SkColor pixels[height][width];
10 for (int y = 0; y < height; ++y) {
11 for (int x = 0; x < width; ++x) {
12 int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f)));
13 int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f)));
14 int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f)));
15 int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f)));
16 pixels[y][x] =
17 SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255);
18 }
19 }
20 SkBitmap bitmap;
21 SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
22 bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width);
23 canvas->drawBitmap(source, 0, 0);
24 canvas->drawBitmap(bitmap, 0, 0);
25 SkImageInfo rgbaInfo = info.makeColorType(kRGBA_8888_SkColorType);
26 bitmap.installPixels(rgbaInfo, (void*) pixels, sizeof(SkColor) * width);
27 canvas->drawBitmap(bitmap, 0, 128);
28 }
29 } // END FIDDLE
30