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=de418ccb42471d1589508ef3955f8c53
5 REG_FIDDLE(ImageInfo_MakeS32, 256, 128, false, 0) {
draw(SkCanvas * canvas)6 void draw(SkCanvas* canvas) {
7 const int width = 256;
8 const int height = 32;
9 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
10 SkColor gradColors[] = { 0xFFAA0055, 0xFF11CC88 };
11 SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } };
12 SkPaint gradPaint;
13 gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
14 SK_ARRAY_COUNT(gradColors), SkTileMode::kClamp));
15 SkBitmap bitmap;
16 bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
17 SkCanvas offScreen(bitmap);
18 offScreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
19 canvas->drawImage(bitmap.asImage(), 0, 0);
20 bitmap.allocPixels(SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType));
21 SkCanvas sRGBOffscreen(bitmap);
22 sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
23 canvas->drawImage(bitmap.asImage(), 0, 48);
24 SkBitmap noColorSpaceBitmap;
25 noColorSpaceBitmap.setInfo(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
26 noColorSpaceBitmap.setPixels(bitmap.getAddr(0, 0));
27 canvas->drawImage(noColorSpaceBitmap.asImage(), 0, 96);
28 }
29 } // END FIDDLE
30