2017-05-04 12:53:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 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"
|
|
|
|
#include "SkImagePriv.h"
|
|
|
|
|
2018-07-12 18:44:27 +00:00
|
|
|
sk_sp<SkImage> make_raster_image(const char* path) {
|
2017-12-09 01:27:41 +00:00
|
|
|
sk_sp<SkData> resourceData = GetResourceAsData(path);
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(resourceData);
|
2017-05-04 12:53:32 +00:00
|
|
|
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(codec->getInfo());
|
|
|
|
|
2018-07-12 18:44:27 +00:00
|
|
|
codec->getPixels(codec->getInfo(), bitmap.getPixels(), bitmap.rowBytes());
|
2017-05-04 12:53:32 +00:00
|
|
|
return SkImage::MakeFromBitmap(bitmap);
|
|
|
|
}
|
|
|
|
|
2018-07-12 18:44:27 +00:00
|
|
|
sk_sp<SkImage> make_color_space(sk_sp<SkImage> orig, sk_sp<SkColorSpace> colorSpace) {
|
|
|
|
sk_sp<SkImage> xform = orig->makeColorSpace(colorSpace);
|
2017-05-04 12:53:32 +00:00
|
|
|
|
|
|
|
// Assign an sRGB color space on the xformed image, so we can see the effects of the xform
|
|
|
|
// when we draw.
|
|
|
|
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
|
|
|
|
if (colorSpace->gammaIsLinear()) {
|
|
|
|
srgb = SkColorSpace::MakeSRGBLinear();
|
|
|
|
}
|
|
|
|
return SkImageMakeRasterCopyAndAssignColorSpace(xform.get(), srgb.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
class MakeCSGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
MakeCSGM() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("makecolorspace");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(128*3, 128*4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2019-01-04 22:03:00 +00:00
|
|
|
sk_sp<SkColorSpace> wideGamut = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
|
|
|
|
SkNamedGamut::kAdobeRGB);
|
2017-12-12 19:09:31 +00:00
|
|
|
sk_sp<SkColorSpace> wideGamutLinear = wideGamut->makeLinearGamma();
|
2017-05-04 12:53:32 +00:00
|
|
|
|
|
|
|
// Lazy images
|
2017-12-08 15:21:31 +00:00
|
|
|
sk_sp<SkImage> opaqueImage = GetResourceAsImage("images/mandrill_128.png");
|
|
|
|
sk_sp<SkImage> premulImage = GetResourceAsImage("images/color_wheel.png");
|
2018-11-26 20:34:12 +00:00
|
|
|
if (!opaqueImage || !premulImage) {
|
|
|
|
return;
|
|
|
|
}
|
2017-05-04 12:53:32 +00:00
|
|
|
canvas->drawImage(opaqueImage, 0.0f, 0.0f);
|
2018-07-12 18:44:27 +00:00
|
|
|
canvas->drawImage(make_color_space(opaqueImage, wideGamut), 128.0f, 0.0f);
|
|
|
|
canvas->drawImage(make_color_space(opaqueImage, wideGamutLinear), 256.0f, 0.0f);
|
2017-05-04 12:53:32 +00:00
|
|
|
canvas->drawImage(premulImage, 0.0f, 128.0f);
|
2018-07-12 18:44:27 +00:00
|
|
|
canvas->drawImage(make_color_space(premulImage, wideGamut), 128.0f, 128.0f);
|
|
|
|
canvas->drawImage(make_color_space(premulImage, wideGamutLinear), 256.0f, 128.0f);
|
2017-05-04 12:53:32 +00:00
|
|
|
canvas->translate(0.0f, 256.0f);
|
|
|
|
|
|
|
|
// Raster images
|
2018-07-12 18:44:27 +00:00
|
|
|
opaqueImage = make_raster_image("images/mandrill_128.png");
|
|
|
|
premulImage = make_raster_image("images/color_wheel.png");
|
2017-05-04 12:53:32 +00:00
|
|
|
canvas->drawImage(opaqueImage, 0.0f, 0.0f);
|
2018-07-12 18:44:27 +00:00
|
|
|
canvas->drawImage(make_color_space(opaqueImage, wideGamut), 128.0f, 0.0f);
|
|
|
|
canvas->drawImage(make_color_space(opaqueImage, wideGamutLinear), 256.0f, 0.0f);
|
2017-05-04 12:53:32 +00:00
|
|
|
canvas->drawImage(premulImage, 0.0f, 128.0f);
|
2018-07-12 18:44:27 +00:00
|
|
|
canvas->drawImage(make_color_space(premulImage, wideGamut), 128.0f, 128.0f);
|
|
|
|
canvas->drawImage(make_color_space(premulImage, wideGamutLinear), 256.0f, 128.0f);
|
2017-05-04 12:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM(return new MakeCSGM;)
|