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.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkBitmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkData.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkEncodedImageFormat.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkImageEncoder.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/Resources.h"
|
2016-08-16 01:52:17 +00:00
|
|
|
|
|
|
|
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; )
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|
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
|