skia2/gm/bitmapimage.cpp
Florin Malita ab244f045a Revert "Revert "Reland: Remove SkLights include from SkCanvas.h""
This reverts commit 9d5f66d9c2.

Reason for revert: Leon landed Android fixes.

Original change's description:
> Revert "Reland: Remove SkLights include from SkCanvas.h"
> 
> This reverts commit fed00319c9.
> 
> Reason for revert: breaking the Android roll.
> 
> Original change's description:
> > Reland: Remove SkLights include from SkCanvas.h
> > 
> > SkLights.h pulls in a bunch of other headers and is not needed (fwdecl
> > works fine).
> > 
> > Change-Id: I3ed97cd7861e51dcb7cfa7950a97b420dbc6fbfb
> > TBR=reed@google.com
> > Reviewed-on: https://skia-review.googlesource.com/15143
> > Commit-Queue: Florin Malita <fmalita@chromium.org>
> > Reviewed-by: Florin Malita <fmalita@chromium.org>
> > 
> 
> TBR=fmalita@chromium.org,reed@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> 
> Change-Id: I3b0e69f1d04d160f16a5567b09982d35cc9ca84e
> Reviewed-on: https://skia-review.googlesource.com/15195
> Reviewed-by: Florin Malita <fmalita@chromium.org>
> Commit-Queue: Florin Malita <fmalita@chromium.org>
> 

TBR=msarett@google.com,reviews@skia.org,fmalita@chromium.org,reed@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Change-Id: I0a1c2f9df61f16987ab72dfb4f3a205fbcc37667
Reviewed-on: https://skia-review.googlesource.com/15229
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
2017-05-03 19:17:11 +00:00

79 lines
2.5 KiB
C++

/*
* 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"
#include "SkCodec.h"
#include "SkImage.h"
namespace skiagm {
class BitmapImageGM : public GM {
public:
BitmapImageGM() {}
protected:
SkString onShortName() override {
return SkString("bitmap-image-srgb-legacy");
}
SkISize onISize() override {
return SkISize::Make(2*kSize, 2*kSize);
}
void onDraw(SkCanvas* canvas) override {
// Create image.
const char* path = "mandrill_512_q075.jpg";
sk_sp<SkImage> image = GetResourceAsImage(path);
if (!image) {
SkDebugf("Failure: Is the resource path set properly?");
return;
}
// Create matching bitmap.
std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(GetResourceAsStream(path)));
SkBitmap bitmap;
bitmap.allocPixels(codec->getInfo());
codec->getPixels(codec->getInfo(), bitmap.getPixels(), bitmap.rowBytes());
// The GM will be displayed in a 2x2 grid.
// The top two squares show an sRGB image, then bitmap, drawn to a legacy canvas.
SkImageInfo linearInfo = SkImageInfo::MakeN32(2*kSize, kSize, kOpaque_SkAlphaType);
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);
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);
}