diff options
author | msarett <msarett@google.com> | 2016-08-15 18:52:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-15 18:52:17 -0700 |
commit | 36c38cbb29744e0b5390a38367e47c0c74287c2d (patch) | |
tree | 4a29a1b61e8ebbdd8e7bfb999636e6e4497a7bd5 /gm | |
parent | 4ed2f01cf6f3a63d5185ea5b442549d20ce2ec16 (diff) |
Fix WIC encoder to support kJPEG_Type
(1) Add support for kJPEG to WIC
(2) Add encoding test.
(3) Turn on WIC jpeg encoder on Windows and CG jpeg
encoder on Mac.
A follow-up may make Skia's encoders the default on all
platforms. But, in order to do that, I think we need
to write better encoding unit tests for CG and WIC.
BUG=skia:3969
BUG=skia:5632
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2245453002
Committed: https://skia.googlesource.com/skia/+/b3a7ef1fc0adc24859d2498aee54d3ec2cbcac3a
Review-Url: https://codereview.chromium.org/2245453002
Diffstat (limited to 'gm')
-rw-r--r-- | gm/encode.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/gm/encode.cpp b/gm/encode.cpp new file mode 100644 index 0000000000..0cd562a358 --- /dev/null +++ b/gm/encode.cpp @@ -0,0 +1,48 @@ +/* + * 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 "SkCanvas.h" +#include "SkData.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(SkImageEncoder::EncodeData(orig, SkImageEncoder::kPNG_Type, 100)); + sk_sp<SkData> jpegData(SkImageEncoder::EncodeData(orig, SkImageEncoder::kJPEG_Type, 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; ) +} |