blob: 69a1ce173f7a2bf327a76d5e4994f4c4b0b689e8 [file] [log] [blame]
Matt Sarett3928ff82017-06-06 10:11:34 -04001/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkColorSpaceXformImageGenerator.h"
10
11class ColorXformImageGenGM : public skiagm::GM {
12public:
13 ColorXformImageGenGM() {}
14
15protected:
16
17 SkString onShortName() override {
18 return SkString("color_xform_image_gen");
19 }
20
21 SkISize onISize() override {
22 return SkISize::Make(100, 100);
23 }
24
25 void onDraw(SkCanvas* canvas) override {
26 SkBitmap bitmap;
27 SkImageInfo info =
28 SkImageInfo::MakeN32(100, 100, kOpaque_SkAlphaType, SkColorSpace::MakeSRGB());
29 bitmap.allocPixels(info);
30 bitmap.eraseColor(SK_ColorRED);
31 bitmap.eraseArea(SkIRect::MakeWH(25, 25), SK_ColorBLUE); // We should not see any blue.
32
33 std::unique_ptr<SkImageGenerator> gen = SkColorSpaceXformImageGenerator::Make(
34 bitmap,
35 SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
36 SkColorSpace::kRec2020_Gamut),
37 kNever_SkCopyPixelsMode);
38
39 SkIRect subset = SkIRect::MakeXYWH(25, 25, 50, 50);
40 sk_sp<SkImage> image = SkImage::MakeFromGenerator(std::move(gen), &subset);
41 canvas->drawImage(image, 25, 25);
42 }
43
44private:
45 typedef GM INHERITED;
46};
47
48DEF_GM( return new ColorXformImageGenGM(); )