Flutter Engine
The Flutter Engine
encode.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
9
12#include "include/core/SkData.h"
13#include "include/core/SkFont.h"
17#include "include/core/SkSize.h"
22#include "tools/DecodeUtils.h"
23#include "tools/Resources.h"
25
26namespace skiagm {
27
28class EncodeGM : public GM {
29public:
31
32protected:
33 SkString getName() const override { return SkString("encode"); }
34
35 SkISize getISize() override { return SkISize::Make(1024, 600); }
36
37 void onDraw(SkCanvas* canvas) override {
38 SkBitmap orig;
39 ToolUtils::GetResourceAsBitmap("images/mandrill_512_q075.jpg", &orig);
42 sk_sp<SkData> pngData = stream.detachAsData();
43 stream.reset();
44
46 sk_sp<SkData> jpgData = stream.detachAsData();
47
50 canvas->drawImage(pngImage.get(), 0.0f, 0.0f);
51 canvas->drawImage(jpgImage.get(), 512.0f, 0.0f);
52
55 canvas->drawString("Images should look identical.", 450.0f, 550.0f, font, SkPaint());
56 }
57
58private:
59 using INHERITED = GM;
60};
61
62DEF_GM( return new EncodeGM; )
63} // namespace skiagm
64
65///////////
66
67#if 0
68DEF_SIMPLE_GM(jpeg_orientation, canvas, 1000, 1000) {
69 static sk_sp<SkImage> imgs[8];
70 if (!imgs[0]) {
71 for (int i = 0; i < 8; ++i) {
73 path.printf("/skia/orientation/Landscape_%d.jpg", i + 1);
74 auto stream = SkStream::MakeFromFile(path.c_str());
75 auto data = SkData::MakeFromStream(stream.get(), stream->getLength());
77 }
78 }
79 canvas->scale(0.25, 0.25);
80 for (int i = 0; i < 8; ++i) {
81 SkImage* img = imgs[i].get();
82 canvas->drawImage(img, 0, 0, nullptr);
83 canvas->translate(0, img->height());
84 if (i == 3) {
85 canvas->translate(img->width(), -4*img->height());
86 }
87 }
88}
89#endif
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
const SkPixmap & pixmap() const
Definition: SkBitmap.h:133
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static sk_sp< SkData > MakeFromStream(SkStream *, size_t size)
Definition: SkData.cpp:208
Definition: SkFont.h:35
@ kAlias
no transparent pixels on glyph edges
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
static std::unique_ptr< SkStreamAsset > MakeFromFile(const char path[])
Definition: SkStream.cpp:922
T * get() const
Definition: SkRefCnt.h:303
SkString getName() const override
Definition: encode.cpp:33
SkISize getISize() override
Definition: encode.cpp:35
void onDraw(SkCanvas *canvas) override
Definition: encode.cpp:37
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition: gm.h:50
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
SkFont DefaultPortableFont()
bool GetResourceAsBitmap(const char *resource, SkBitmap *dst)
Definition: DecodeUtils.h:21
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
font
Font Metadata and Metrics.
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63