OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 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 "Resources.h" |
| 10 |
| 11 namespace skiagm { |
| 12 |
| 13 class BitmapImageGM : public GM { |
| 14 public: |
| 15 BitmapImageGM() {} |
| 16 |
| 17 protected: |
| 18 |
| 19 SkString onShortName() override { |
| 20 return SkString("bitmap-image-srgb-linear"); |
| 21 } |
| 22 |
| 23 SkISize onISize() override { |
| 24 return SkISize::Make(2*kSize, 2*kSize); |
| 25 } |
| 26 |
| 27 void onDraw(SkCanvas* canvas) override { |
| 28 // Create image. |
| 29 sk_sp<SkImage> image = GetResourceAsImage("mandrill_512_q075.jpg"); |
| 30 if (!image) { |
| 31 SkDebugf("Failure: Is the resource path set properly?"); |
| 32 return; |
| 33 } |
| 34 |
| 35 // Create matching bitmap. |
| 36 SkBitmap bitmap; |
| 37 SkAssertResult(image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapM
ode)); |
| 38 |
| 39 // The GM will be displayed in a 2x2 grid. |
| 40 // The top two squares show an sRGB image, then bitmap, drawn to a linea
r canvas. |
| 41 SkImageInfo linearInfo = SkImageInfo::MakeN32(2*kSize, kSize, kOpaque_Sk
AlphaType); |
| 42 SkBitmap linearBMCanvas; |
| 43 linearBMCanvas.allocPixels(linearInfo); |
| 44 SkCanvas linearCanvas(linearBMCanvas); |
| 45 linearCanvas.drawImage(image, 0.0f, 0.0f, nullptr); |
| 46 linearCanvas.translate(SkScalar(kSize), 0.0f); |
| 47 linearCanvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr); |
| 48 canvas->drawBitmap(linearBMCanvas, 0.0f, 0.0f, nullptr); |
| 49 canvas->translate(0.0f, SkScalar(kSize)); |
| 50 |
| 51 // The bottom two squares show an sRGB image, then bitmap, drawn to a sr
gb canvas. |
| 52 SkImageInfo srgbInfo = SkImageInfo::MakeS32(2*kSize, kSize, kOpaque_SkAl
phaType); |
| 53 SkBitmap srgbBMCanvas; |
| 54 srgbBMCanvas.allocPixels(srgbInfo); |
| 55 SkCanvas srgbCanvas(srgbBMCanvas); |
| 56 srgbCanvas.drawImage(image, 0.0f, 0.0f, nullptr); |
| 57 srgbCanvas.translate(SkScalar(kSize), 0.0f); |
| 58 srgbCanvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr); |
| 59 canvas->drawBitmap(srgbBMCanvas, 0.0f, 0.0f, nullptr); |
| 60 } |
| 61 |
| 62 private: |
| 63 static constexpr int kSize = 512; |
| 64 |
| 65 typedef GM INHERITED; |
| 66 }; |
| 67 |
| 68 ////////////////////////////////////////////////////////////////////////////// |
| 69 |
| 70 static GM* MyFactory(void*) { return new BitmapImageGM; } |
| 71 static GMRegistry reg(MyFactory); |
| 72 |
| 73 } |
OLD | NEW |