2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
15 class BitmapImageGM : public GM {
21 SkString onShortName() override {
22 return SkString("bitmap-image-srgb-legacy");
25 SkISize onISize() override {
26 return SkISize::Make(2*kSize, 2*kSize);
29 void onDraw(SkCanvas* canvas) override {
31 const char* path = "mandrill_512_q075.jpg";
32 sk_sp<SkImage> image = GetResourceAsImage(path);
34 SkDebugf("Failure: Is the resource path set properly?");
38 // Create matching bitmap.
39 std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(GetResourceAsStream(path)));
41 bitmap.allocPixels(codec->getInfo());
42 codec->getPixels(codec->getInfo(), bitmap.getPixels(), bitmap.rowBytes());
44 // The GM will be displayed in a 2x2 grid.
45 // The top two squares show an sRGB image, then bitmap, drawn to a legacy canvas.
46 SkImageInfo linearInfo = SkImageInfo::MakeN32(2*kSize, kSize, kOpaque_SkAlphaType);
47 SkBitmap legacyBMCanvas;
48 legacyBMCanvas.allocPixels(linearInfo);
49 SkCanvas legacyCanvas(legacyBMCanvas);
50 legacyCanvas.drawImage(image, 0.0f, 0.0f, nullptr);
51 legacyCanvas.translate(SkScalar(kSize), 0.0f);
52 legacyCanvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr);
53 canvas->drawBitmap(legacyBMCanvas, 0.0f, 0.0f, nullptr);
54 canvas->translate(0.0f, SkScalar(kSize));
56 // The bottom two squares show an sRGB image, then bitmap, drawn to a srgb canvas.
57 SkImageInfo srgbInfo = SkImageInfo::MakeS32(2*kSize, kSize, kOpaque_SkAlphaType);
58 SkBitmap srgbBMCanvas;
59 srgbBMCanvas.allocPixels(srgbInfo);
60 SkCanvas srgbCanvas(srgbBMCanvas);
61 srgbCanvas.drawImage(image, 0.0f, 0.0f, nullptr);
62 srgbCanvas.translate(SkScalar(kSize), 0.0f);
63 srgbCanvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr);
64 canvas->drawBitmap(srgbBMCanvas, 0.0f, 0.0f, nullptr);
68 static constexpr int kSize = 512;
73 //////////////////////////////////////////////////////////////////////////////
75 static GM* MyFactory(void*) { return new BitmapImageGM; }
76 static GMRegistry reg(MyFactory);