diff options
author | msarett <msarett@google.com> | 2016-06-13 11:25:03 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-13 11:25:03 -0700 |
commit | be36d59e664513294c02ff9691a3c1817a712fee (patch) | |
tree | abd01814ad4b984cc72862726130b8ee51cc9bb6 /gm/bitmapimage.cpp | |
parent | b4da01d8f719f3c43d492e8f62a7e2c861e9ef27 (diff) |
Fix SkImage::asLegacyBitmap() to respect color space info
BUG=skia:5428
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2061783002
Review-Url: https://codereview.chromium.org/2061783002
Diffstat (limited to 'gm/bitmapimage.cpp')
-rw-r--r-- | gm/bitmapimage.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/gm/bitmapimage.cpp b/gm/bitmapimage.cpp new file mode 100644 index 0000000000..ad6a74dda8 --- /dev/null +++ b/gm/bitmapimage.cpp @@ -0,0 +1,73 @@ +/* + * Copyright 2016 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 "Resources.h" + +namespace skiagm { + +class BitmapImageGM : public GM { +public: + BitmapImageGM() {} + +protected: + + SkString onShortName() override { + return SkString("bitmap-image-srgb-linear"); + } + + SkISize onISize() override { + return SkISize::Make(2*kSize, 2*kSize); + } + + void onDraw(SkCanvas* canvas) override { + // Create image. + sk_sp<SkImage> image = GetResourceAsImage("mandrill_512_q075.jpg"); + if (!image) { + SkDebugf("Failure: Is the resource path set properly?"); + return; + } + + // Create matching bitmap. + SkBitmap bitmap; + SkAssertResult(image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode)); + + // The GM will be displayed in a 2x2 grid. + // The top two squares show an sRGB image, then bitmap, drawn to a linear canvas. + SkImageInfo linearInfo = SkImageInfo::MakeN32(2*kSize, kSize, kOpaque_SkAlphaType); + SkBitmap linearBMCanvas; + linearBMCanvas.allocPixels(linearInfo); + SkCanvas linearCanvas(linearBMCanvas); + linearCanvas.drawImage(image, 0.0f, 0.0f, nullptr); + linearCanvas.translate(SkScalar(kSize), 0.0f); + linearCanvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr); + canvas->drawBitmap(linearBMCanvas, 0.0f, 0.0f, nullptr); + canvas->translate(0.0f, SkScalar(kSize)); + + // The bottom two squares show an sRGB image, then bitmap, drawn to a srgb canvas. + SkImageInfo srgbInfo = SkImageInfo::MakeS32(2*kSize, kSize, kOpaque_SkAlphaType); + SkBitmap srgbBMCanvas; + srgbBMCanvas.allocPixels(srgbInfo); + SkCanvas srgbCanvas(srgbBMCanvas); + srgbCanvas.drawImage(image, 0.0f, 0.0f, nullptr); + srgbCanvas.translate(SkScalar(kSize), 0.0f); + srgbCanvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr); + canvas->drawBitmap(srgbBMCanvas, 0.0f, 0.0f, nullptr); + } + +private: + static constexpr int kSize = 512; + + typedef GM INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +static GM* MyFactory(void*) { return new BitmapImageGM; } +static GMRegistry reg(MyFactory); + +} |