blob: 391450c2cdbfde96bcee55c37a351c953ebbf938 [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=de418ccb42471d1589508ef3955f8c53
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(ImageInfo_MakeS32, 256, 128, false, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006void 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,
Mike Reedfae8fce2019-04-03 10:27:45 -040014 SK_ARRAY_COUNT(gradColors), SkTileMode::kClamp));
Hal Canary87515122019-03-15 14:22:51 -040015 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->drawBitmap(bitmap, 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->drawBitmap(bitmap, 0, 48);
24 SkBitmap noColorSpaceBitmap;
25 noColorSpaceBitmap.setInfo(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
26 noColorSpaceBitmap.setPixels(bitmap.getAddr(0, 0));
27 canvas->drawBitmap(noColorSpaceBitmap, 0, 96);
28}
29} // END FIDDLE