diff options
author | Matt Sarett <msarett@google.com> | 2017-06-06 10:11:34 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-06-06 14:34:03 +0000 |
commit | 3928ff8e0b617c3a00eee1963bc31ce5470fba6d (patch) | |
tree | 98bbe9e51b3316c175a8b1ffe1063877ca84eb55 /gm | |
parent | 1608a1dd17187aeeada376e710ecfafb1e229af2 (diff) |
Create an SkColorSpaceXform image generator
This should be immediately useful in the Skia-Android
rendering pipeline.
Possible future uses include creating a "renderable"
SkImage from a bitmap with a funny color space.
Inspired by:
https://skia-review.googlesource.com/c/13981/
Bug: b/62347704
Change-Id: I388c7af1fc43834b8ad22022d0caf3ac90b734c8
Reviewed-on: https://skia-review.googlesource.com/18598
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>
Diffstat (limited to 'gm')
-rw-r--r-- | gm/xform_image_gen.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/gm/xform_image_gen.cpp b/gm/xform_image_gen.cpp new file mode 100644 index 0000000000..69a1ce173f --- /dev/null +++ b/gm/xform_image_gen.cpp @@ -0,0 +1,48 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gm.h" +#include "SkColorSpaceXformImageGenerator.h" + +class ColorXformImageGenGM : public skiagm::GM { +public: + ColorXformImageGenGM() {} + +protected: + + SkString onShortName() override { + return SkString("color_xform_image_gen"); + } + + SkISize onISize() override { + return SkISize::Make(100, 100); + } + + void onDraw(SkCanvas* canvas) override { + SkBitmap bitmap; + SkImageInfo info = + SkImageInfo::MakeN32(100, 100, kOpaque_SkAlphaType, SkColorSpace::MakeSRGB()); + bitmap.allocPixels(info); + bitmap.eraseColor(SK_ColorRED); + bitmap.eraseArea(SkIRect::MakeWH(25, 25), SK_ColorBLUE); // We should not see any blue. + + std::unique_ptr<SkImageGenerator> gen = SkColorSpaceXformImageGenerator::Make( + bitmap, + SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, + SkColorSpace::kRec2020_Gamut), + kNever_SkCopyPixelsMode); + + SkIRect subset = SkIRect::MakeXYWH(25, 25, 50, 50); + sk_sp<SkImage> image = SkImage::MakeFromGenerator(std::move(gen), &subset); + canvas->drawImage(image, 25, 25); + } + +private: + typedef GM INHERITED; +}; + +DEF_GM( return new ColorXformImageGenGM(); ) |