2016-08-16 01:52:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 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"
|
2019-01-08 20:04:23 +00:00
|
|
|
|
|
|
|
#include "Resources.h"
|
2016-08-16 01:52:17 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkData.h"
|
2019-01-08 20:04:23 +00:00
|
|
|
#include "SkFont.h"
|
2017-05-03 19:16:58 +00:00
|
|
|
#include "SkImage.h"
|
2016-08-16 01:52:17 +00:00
|
|
|
#include "SkImageEncoder.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class EncodeGM : public GM {
|
|
|
|
public:
|
|
|
|
EncodeGM() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("encode");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(1024, 600);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
SkBitmap orig;
|
2017-12-08 15:21:31 +00:00
|
|
|
GetResourceAsBitmap("images/mandrill_512_q075.jpg", &orig);
|
2018-09-24 19:24:31 +00:00
|
|
|
auto pngData = SkEncodeBitmap(orig, SkEncodedImageFormat::kPNG, 100);
|
|
|
|
auto jpgData = SkEncodeBitmap(orig, SkEncodedImageFormat::kJPEG, 100);
|
2016-08-16 01:52:17 +00:00
|
|
|
|
|
|
|
sk_sp<SkImage> pngImage = SkImage::MakeFromEncoded(pngData);
|
2018-09-24 19:24:31 +00:00
|
|
|
sk_sp<SkImage> jpgImage = SkImage::MakeFromEncoded(jpgData);
|
2016-08-16 01:52:17 +00:00
|
|
|
canvas->drawImage(pngImage.get(), 0.0f, 0.0f);
|
2018-09-24 19:24:31 +00:00
|
|
|
canvas->drawImage(jpgImage.get(), 512.0f, 0.0f);
|
2016-08-16 01:52:17 +00:00
|
|
|
|
2019-01-08 20:04:23 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setEdging(SkFont::Edging::kAlias);
|
|
|
|
canvas->drawString("Images should look identical.", 450.0f, 550.0f, font, SkPaint());
|
2016-08-16 01:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM( return new EncodeGM; )
|
|
|
|
}
|
2017-10-17 18:04:32 +00:00
|
|
|
|
|
|
|
///////////
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
DEF_SIMPLE_GM(jpeg_orientation, canvas, 1000, 1000) {
|
|
|
|
static sk_sp<SkImage> imgs[8];
|
|
|
|
if (!imgs[0]) {
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
SkString path;
|
|
|
|
path.printf("/skia/orientation/Landscape_%d.jpg", i + 1);
|
|
|
|
auto stream = SkStream::MakeFromFile(path.c_str());
|
|
|
|
auto data = SkData::MakeFromStream(stream.get(), stream->getLength());
|
|
|
|
imgs[i] = SkImage::MakeFromEncoded(data, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
canvas->scale(0.25, 0.25);
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
SkImage* img = imgs[i].get();
|
|
|
|
canvas->drawImage(img, 0, 0, nullptr);
|
|
|
|
canvas->translate(0, img->height());
|
|
|
|
if (i == 3) {
|
|
|
|
canvas->translate(img->width(), -4*img->height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|