skia2/gm/encode.cpp
Hal Canary a70ae1a70f drawText Cleanup, part 5
Change-Id: I2e6cb63839ec9c6f9d5b829505472f97b076a82c
Reviewed-on: https://skia-review.googlesource.com/c/182260
Auto-Submit: Hal Canary <halcanary@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Reed <reed@google.com>
2019-01-09 16:10:30 +00:00

79 lines
2.1 KiB
C++

/*
* 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"
#include "Resources.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkFont.h"
#include "SkImage.h"
#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;
GetResourceAsBitmap("images/mandrill_512_q075.jpg", &orig);
auto pngData = SkEncodeBitmap(orig, SkEncodedImageFormat::kPNG, 100);
auto jpgData = SkEncodeBitmap(orig, SkEncodedImageFormat::kJPEG, 100);
sk_sp<SkImage> pngImage = SkImage::MakeFromEncoded(pngData);
sk_sp<SkImage> jpgImage = SkImage::MakeFromEncoded(jpgData);
canvas->drawImage(pngImage.get(), 0.0f, 0.0f);
canvas->drawImage(jpgImage.get(), 512.0f, 0.0f);
SkFont font;
font.setEdging(SkFont::Edging::kAlias);
canvas->drawString("Images should look identical.", 450.0f, 550.0f, font, SkPaint());
}
private:
typedef GM INHERITED;
};
DEF_GM( return new EncodeGM; )
}
///////////
#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