Flutter Engine
The Flutter Engine
SkImage_to_PPM_ascii.cpp
Go to the documentation of this file.
1// Copyright 2020 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4REG_FIDDLE(SkImage_to_PPM_ascii, 256, 256, true, 4) {
5void dump_txt(const SkData* data, const char* name) {
6 if (data) {
7 SkDebugf("\ncat > %s << EOF\n", name);
8 size_t s = data->size();
9 const char* d = (const char*)data->bytes();
10 while (s > 0) {
11 int l = (int)std::min(s, (size_t)1024);
12 SkDebugf("%.*s", l, d);
13 s -= l;
14 d += l;
15 }
16 SkDebugf("\nEOF\n\n");
17 }
18}
19
20sk_sp<SkData> Encode_PPM_A(const SkPixmap& src) {
21 if (src.width() <= 0 || src.height() <= 0 || !src.addr() ||
22 src.colorType() == kUnknown_SkColorType) {
23 return nullptr;
24 }
26 SkString s = SkStringPrintf("P3\n%d %d\n255\n", src.width(), src.height());
27 buf.write(s.c_str(), s.size());
28 for (int y = 0; y < src.height(); ++y) {
29 for (int x = 0; x < src.height(); ++x) {
30 char buffer[13];
31 SkColor c = src.getColor(x, y);
32 int n = snprintf(buffer, sizeof(buffer), "%u %u %u\n", SkColorGetR(c),
34 if (n < 6 || n + 1 > (int)sizeof(buffer)) {
35 return nullptr;
36 }
37 buf.write(buffer, n);
38 }
39 }
40 return buf.detachAsData();
41}
42
46 return bitmap;
47}
48
49void draw(SkCanvas*) {
51 sk_sp<SkData> data = Encode_PPM_A(bitmap.pixmap());
52 dump_txt(data.get(), "fooa.ppm");
53}
54} // END FIDDLE
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
uint32_t SkColor
Definition: SkColor.h:37
#define SkColorGetB(color)
Definition: SkColor.h:73
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
REG_FIDDLE(SkImage_to_PPM_ascii, 256, 256, true, 4)
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
Definition: SkData.h:25
bool write(const void *buffer, size_t size) override
Definition: SkStream.cpp:535
sk_sp< SkData > detachAsData()
Definition: SkStream.cpp:707
bool asLegacyBitmap(SkBitmap *bitmap, LegacyBitmapMode legacyBitmapMode=kRO_LegacyBitmapMode) const
Definition: SkImage.cpp:233
@ kRO_LegacyBitmapMode
returned bitmap is read-only and immutable
Definition: SkImage.h:826
T * get() const
Definition: SkRefCnt.h:303
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
struct MyStruct s
static float min(float r, float g, float b)
Definition: hsl.cpp:48
double y
double x
bool ToBitmap(const SkImage *img, SkBitmap *dst)
Definition: SkPDFUtils.cpp:348
sk_sp< const SkImage > image
Definition: SkRecords.h:269
Definition: bitmap.py:1
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
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 to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63