Flutter Engine
The Flutter Engine
third_party
skia
docs
examples
SkImage_to_PPM_binary.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.
3
#include "
tools/fiddle/examples.h
"
4
REG_FIDDLE
(SkImage_to_PPM_binary, 256, 256,
true
, 4) {
5
void
print_data(
const
SkData
*
data
,
const
char
*
name
) {
6
if
(
data
) {
7
SkDebugf
(
"\nxxd -r -p > %s << EOF"
,
name
);
8
size_t
s
=
data
->size();
9
const
uint8_t*
d
=
data
->bytes();
10
for
(
size_t
i
= 0;
i
<
s
; ++
i
) {
11
if
(
i
% 40 == 0) {
12
SkDebugf
(
"\n"
);
13
}
14
SkDebugf
(
"%02x"
,
d
[
i
]);
15
}
16
SkDebugf
(
"\nEOF\n\n"
);
17
}
18
}
19
20
sk_sp<SkData>
Encode_PPM_B(
const
SkPixmap
&
src
) {
21
if
(
src
.width() <= 0 ||
src
.height() <= 0 || !
src
.addr() ||
22
src
.colorType() ==
kUnknown_SkColorType
) {
23
return
nullptr
;
24
}
25
SkString
s
=
SkStringPrintf
(
"P6\n%d %d\n255\n"
,
src
.width(),
src
.height());
26
auto
result
=
SkData::MakeUninitialized
(
s
.size() + 3 *
src
.width() *
src
.height());
27
uint8_t* ptr =
static_cast<
uint8_t*
>
(
result
->writable_data());
28
memcpy(ptr,
s
.c_str(),
s
.size());
29
ptr +=
s
.size();
30
for
(
int
y
= 0;
y
<
src
.height(); ++
y
) {
31
for
(
int
x
= 0;
x
<
src
.height(); ++
x
) {
32
SkColor
c =
src
.getColor(
x
,
y
);
33
*ptr++ =
SkColorGetR
(c);
34
*ptr++ =
SkColorGetG
(c);
35
*ptr++ =
SkColorGetB
(c);
36
}
37
}
38
return
result
;
39
}
40
41
SkBitmap
ToBitmap
(
SkImage
* img) {
42
SkBitmap
bitmap
;
43
(void)img->
asLegacyBitmap
(&
bitmap
,
SkImage::kRO_LegacyBitmapMode
);
44
return
bitmap
;
45
}
46
47
void
draw
(
SkCanvas
*) {
48
SkBitmap
bitmap
=
ToBitmap
(
image
.
get
());
49
sk_sp<SkData>
data
= Encode_PPM_B(
bitmap
.pixmap());
50
print_data(
data
.get(),
"foo.ppm"
);
51
}
52
}
// END FIDDLE
kUnknown_SkColorType
@ kUnknown_SkColorType
uninitialized
Definition:
SkColorType.h:20
SkColorGetR
#define SkColorGetR(color)
Definition:
SkColor.h:65
SkColorGetG
#define SkColorGetG(color)
Definition:
SkColor.h:69
SkColor
uint32_t SkColor
Definition:
SkColor.h:37
SkColorGetB
#define SkColorGetB(color)
Definition:
SkColor.h:73
SkDebugf
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
REG_FIDDLE
REG_FIDDLE(SkImage_to_PPM_binary, 256, 256, true, 4)
Definition:
SkImage_to_PPM_binary.cpp:4
SkStringPrintf
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
draw
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition:
aaclip.cpp:27
SkBitmap
Definition:
SkBitmap.h:59
SkCanvas
Definition:
SkCanvas.h:106
SkData
Definition:
SkData.h:25
SkData::MakeUninitialized
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition:
SkData.cpp:116
SkImage
Definition:
SkImage.h:272
SkImage::asLegacyBitmap
bool asLegacyBitmap(SkBitmap *bitmap, LegacyBitmapMode legacyBitmapMode=kRO_LegacyBitmapMode) const
Definition:
SkImage.cpp:233
SkImage::kRO_LegacyBitmapMode
@ kRO_LegacyBitmapMode
returned bitmap is read-only and immutable
Definition:
SkImage.h:826
SkPixmap
Definition:
SkPixmap.h:40
SkString
Definition:
SkString.h:118
sk_sp< SkData >
sk_sp::get
T * get() const
Definition:
SkRefCnt.h:303
d
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition:
main.cc:19
examples.h
s
struct MyStruct s
i
int i
Definition:
fl_socket_accessible.cc:18
result
GAsyncResult * result
Definition:
fl_text_input_plugin.cc:106
y
double y
Definition:
mouse-input-test.cc:83
x
double x
Definition:
mouse-input-test.cc:82
SkPDFUtils::ToBitmap
bool ToBitmap(const SkImage *img, SkBitmap *dst)
Definition:
SkPDFUtils.cpp:348
SkRecords::image
sk_sp< const SkImage > image
Definition:
SkRecords.h:269
bitmap
Definition:
bitmap.py:1
flutter::name
DEF_SWITCHES_START aot vmservice shared library name
Definition:
switches.h:32
mskp_parser.src
src
Definition:
mskp_parser.py:22
data
std::shared_ptr< const fml::Mapping > data
Definition:
texture_gles.cc:63
Generated on Sun Jun 23 2024 21:55:56 for Flutter Engine by
1.9.4