blob: f6b408ffdd2abc0fe0ebe3ba14e0c26d96ceffdf [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// 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.
Mike Kleinc0bd9f92019-04-23 12:05:21 -05003#include "tools/fiddle/examples.h"
Hal Canary87515122019-03-15 14:22:51 -04004// HASH=e72db006f1bea26feceaef8727ff9818
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(ImageInfo_makeAlphaType, 256, 256, false, 3) {
Hal Canary87515122019-03-15 14:22:51 -04006void 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 unpremulInfo = info.makeAlphaType(kUnpremul_SkAlphaType);
26 bitmap.installPixels(unpremulInfo, (void*) pixels, sizeof(SkColor) * width);
27 canvas->drawBitmap(bitmap, 0, 128);
28}
29} // END FIDDLE