Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=de418ccb42471d1589508ef3955f8c53 |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(ImageInfo_MakeS32, 256, 128, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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, |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 14 | SK_ARRAY_COUNT(gradColors), SkTileMode::kClamp)); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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->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 |