skia2/gm/encode.cpp
Mike Reed 4379869461 Revert[4] "apply codec origin in generator"
This reverts commit dd340146f1.

Reason for revert: ios gn file fixed

Original change's description:
> Revert "Revert "Revert "apply codec origin in generator"""
> 
> This reverts commit 82269abfec.
> 
> Reason for revert: ios build needs include path for SkCodec.h
> 
> Original change's description:
> > Revert "Revert "apply codec origin in generator""
> > 
> > This reverts commit 363dd988a5.
> > 
> > Reason for revert: pdfium fix landed
> > 
> > Original change's description:
> > > Revert "apply codec origin in generator"
> > > 
> > > This reverts commit fa15877f48.
> > > 
> > > Reason for revert: Appears to break PDFium.
> > > 
> > > Original change's description:
> > > > apply codec origin in generator
> > > > 
> > > > Bug: skia:
> > > > Change-Id: I383dacb49b1e3c88467ccdbf3288764bb1bbf01a
> > > > Reviewed-on: https://skia-review.googlesource.com/58600
> > > > Reviewed-by: Leon Scroggins <scroggo@google.com>
> > > > Commit-Queue: Mike Reed <reed@google.com>
> > > 
> > > TBR=scroggo@google.com,reed@google.com
> > > 
> > > Change-Id: Id97137d6ec39ca638c941928bae6510814b1c499
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Bug: skia:
> > > Reviewed-on: https://skia-review.googlesource.com/60041
> > > Reviewed-by: Ben Wagner <benjaminwagner@google.com>
> > > Commit-Queue: Ben Wagner <benjaminwagner@google.com>
> > 
> > TBR=benjaminwagner@google.com,scroggo@google.com,reed@google.com
> > 
> > Change-Id: I1b54a6e6e6cbda07f346ffbbc4977f9db705abcd
> > No-Presubmit: true
> > No-Tree-Checks: true
> > No-Try: true
> > Bug: skia:
> > Reviewed-on: https://skia-review.googlesource.com/60320
> > Reviewed-by: Mike Reed <reed@google.com>
> > Commit-Queue: Mike Reed <reed@google.com>
> 
> TBR=benjaminwagner@google.com,scroggo@google.com,reed@google.com
> 
> Change-Id: I4c2d310521d1a678b407d30b9fe3c261c49d67bc
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/60560
> Reviewed-by: Mike Reed <reed@google.com>
> Commit-Queue: Mike Reed <reed@google.com>

TBR=benjaminwagner@google.com,scroggo@google.com,reed@google.com

Change-Id: I5c1e53aff3ad174b0d4a806c35b7cdcd194479d7
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/60563
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2017-10-17 18:04:43 +00:00

77 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 "sk_tool_utils.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkImage.h"
#include "SkImageEncoder.h"
#include "Resources.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("mandrill_512_q075.jpg", &orig);
sk_sp<SkData> pngData(sk_tool_utils::EncodeImageToData(orig, SkEncodedImageFormat::kPNG, 100));
sk_sp<SkData> jpegData(sk_tool_utils::EncodeImageToData(orig, SkEncodedImageFormat::kJPEG, 100));
sk_sp<SkImage> pngImage = SkImage::MakeFromEncoded(pngData);
sk_sp<SkImage> jpegImage = SkImage::MakeFromEncoded(jpegData);
canvas->drawImage(pngImage.get(), 0.0f, 0.0f);
canvas->drawImage(jpegImage.get(), 512.0f, 0.0f);
const char text[] = "Images should look identical.";
canvas->drawText(text, sizeof(text) - 1, 450.0f, 550.0f, 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