• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
11 class ColorXformImageGenGM : public skiagm::GM {
12 public:
ColorXformImageGenGM()13     ColorXformImageGenGM() {}
14 
15 protected:
16 
onShortName()17     SkString onShortName() override {
18         return SkString("color_xform_image_gen");
19     }
20 
onISize()21     SkISize onISize() override {
22         return SkISize::Make(100, 100);
23     }
24 
onDraw(SkCanvas * canvas)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 
44 private:
45     typedef GM INHERITED;
46 };
47 
48 DEF_GM( return new ColorXformImageGenGM(); )
49