2016-06-13 18:25:03 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2016-12-08 13:32:44 +00:00
|
|
|
#include "SkCodec.h"
|
2017-05-03 19:16:58 +00:00
|
|
|
#include "SkImage.h"
|
2016-06-13 18:25:03 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class BitmapImageGM : public GM {
|
|
|
|
public:
|
|
|
|
BitmapImageGM() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SkString onShortName() override {
|
2016-12-08 13:32:44 +00:00
|
|
|
return SkString("bitmap-image-srgb-legacy");
|
2016-06-13 18:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(2*kSize, 2*kSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
// Create image.
|
2017-12-08 15:21:31 +00:00
|
|
|
const char* path = "images/mandrill_512_q075.jpg";
|
2016-12-08 13:32:44 +00:00
|
|
|
sk_sp<SkImage> image = GetResourceAsImage(path);
|
2016-06-13 18:25:03 +00:00
|
|
|
if (!image) {
|
|
|
|
SkDebugf("Failure: Is the resource path set properly?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create matching bitmap.
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(GetResourceAsStream(path)));
|
2016-06-13 18:25:03 +00:00
|
|
|
SkBitmap bitmap;
|
2016-12-08 13:32:44 +00:00
|
|
|
bitmap.allocPixels(codec->getInfo());
|
|
|
|
codec->getPixels(codec->getInfo(), bitmap.getPixels(), bitmap.rowBytes());
|
2016-06-13 18:25:03 +00:00
|
|
|
|
|
|
|
// The GM will be displayed in a 2x2 grid.
|
2016-12-08 13:32:44 +00:00
|
|
|
// The top two squares show an sRGB image, then bitmap, drawn to a legacy canvas.
|
2016-06-13 18:25:03 +00:00
|
|
|
SkImageInfo linearInfo = SkImageInfo::MakeN32(2*kSize, kSize, kOpaque_SkAlphaType);
|
2016-12-08 13:32:44 +00:00
|
|
|
SkBitmap legacyBMCanvas;
|
|
|
|
legacyBMCanvas.allocPixels(linearInfo);
|
|
|
|
SkCanvas legacyCanvas(legacyBMCanvas);
|
|
|
|
legacyCanvas.drawImage(image, 0.0f, 0.0f, nullptr);
|
|
|
|
legacyCanvas.translate(SkScalar(kSize), 0.0f);
|
|
|
|
legacyCanvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr);
|
|
|
|
canvas->drawBitmap(legacyBMCanvas, 0.0f, 0.0f, nullptr);
|
2016-06-13 18:25:03 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
}
|