2019-03-15 18:22:51 +00:00
|
|
|
// Copyright 2019 Google LLC.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/fiddle/examples.h"
|
2019-03-15 18:22:51 +00:00
|
|
|
// HASH=de418ccb42471d1589508ef3955f8c53
|
2019-03-18 20:06:34 +00:00
|
|
|
REG_FIDDLE(ImageInfo_MakeS32, 256, 128, false, 0) {
|
2019-03-15 18:22:51 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
const int width = 256;
|
|
|
|
const int height = 32;
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
|
|
|
|
SkColor gradColors[] = { 0xFFAA0055, 0xFF11CC88 };
|
|
|
|
SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } };
|
|
|
|
SkPaint gradPaint;
|
|
|
|
gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr,
|
2019-04-03 14:27:45 +00:00
|
|
|
SK_ARRAY_COUNT(gradColors), SkTileMode::kClamp));
|
2019-03-15 18:22:51 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
|
|
|
|
SkCanvas offScreen(bitmap);
|
|
|
|
offScreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
|
2021-01-27 22:09:40 +00:00
|
|
|
canvas->drawImage(bitmap.asImage(), 0, 0);
|
2019-03-15 18:22:51 +00:00
|
|
|
bitmap.allocPixels(SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType));
|
|
|
|
SkCanvas sRGBOffscreen(bitmap);
|
|
|
|
sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint);
|
2021-01-27 22:09:40 +00:00
|
|
|
canvas->drawImage(bitmap.asImage(), 0, 48);
|
2019-03-15 18:22:51 +00:00
|
|
|
SkBitmap noColorSpaceBitmap;
|
|
|
|
noColorSpaceBitmap.setInfo(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
|
|
|
|
noColorSpaceBitmap.setPixels(bitmap.getAddr(0, 0));
|
2021-01-27 22:09:40 +00:00
|
|
|
canvas->drawImage(noColorSpaceBitmap.asImage(), 0, 96);
|
2019-03-15 18:22:51 +00:00
|
|
|
}
|
|
|
|
} // END FIDDLE
|