58 for (
size_t i = 0;
i < n /
sizeof(
buffer); ++
i) {
73SkColor get_neighbor_avg_color(
const SkPixmap& bm,
int xOrig,
int yOrig) {
75 unsigned r = 0, g = 0,
b = 0, n = 0;
81 for (
int y = ymin;
y <= ymax; ++
y) {
83 for (
int x = xmin;
x <= xmax; ++
x) {
97enum class SkPDFStreamFormat { DCT, Flate, Uncompressed };
107 SkPDFStreamFormat
format) {
109 pdfDict.insertName(
"Subtype",
"Image");
110 pdfDict.insertInt(
"Width",
size.width());
111 pdfDict.insertInt(
"Height",
size.height());
112 pdfDict.insertUnion(
"ColorSpace", std::move(colorSpace));
114 pdfDict.insertRef(
"SMask", sMask);
116 pdfDict.insertInt(
"BitsPerComponent", 8);
117 #ifdef SK_PDF_BASE85_BINARY
119 filters->appendName(
"ASCII85Decode");
121 case SkPDFStreamFormat::DCT: filters->appendName(
"DCTDecode");
break;
122 case SkPDFStreamFormat::Flate: filters->appendName(
"FlateDecode");
break;
123 case SkPDFStreamFormat::Uncompressed:
break;
125 pdfDict.insertObject(
"Filter", std::move(filters));
128 case SkPDFStreamFormat::DCT: pdfDict.insertName(
"Filter",
"DCTDecode");
break;
129 case SkPDFStreamFormat::Flate: pdfDict.insertName(
"Filter",
"FlateDecode");
break;
130 case SkPDFStreamFormat::Uncompressed:
break;
133 if (
format == SkPDFStreamFormat::DCT) {
134 pdfDict.insertInt(
"ColorTransform", 0);
136 pdfDict.insertInt(
"Length",
length);
137 doc->
emitStream(pdfDict, std::move(writeStream), ref);
143 ? SkPDFStreamFormat::Uncompressed
144 : SkPDFStreamFormat::Flate;
147 std::optional<SkDeflateWStream> deflateWStream;
148 if (
format == SkPDFStreamFormat::Flate) {
150 stream = &*deflateWStream;
159 const uint32_t* ptr = pm.
addr32();
160 const uint32_t* stop = ptr + pm.
height() * pm.
width();
162 uint8_t byteBuffer[4092];
163 uint8_t* bufferStop = byteBuffer +
std::size(byteBuffer);
164 uint8_t*
dst = byteBuffer;
165 while (ptr != stop) {
167 if (
dst == bufferStop) {
168 stream->write(byteBuffer,
sizeof(byteBuffer));
172 stream->write(byteBuffer,
dst - byteBuffer);
174 if (deflateWStream) {
175 deflateWStream->finalize();
178 #ifdef SK_PDF_BASE85_BINARY
179 SkPDFUtils::Base85Encode(
buffer.detachAsStream(), &
buffer);
190 static SkMutex iccProfileMapMutex;
198 iccStreamDict->insertInt(
"N", channels);
205 iccPDF->appendName(
"ICCBased");
206 iccPDF->appendRef(iccStreamRef);
210void do_deflated_image(
const SkPixmap& pm,
220 ? SkPDFStreamFormat::Uncompressed
221 : SkPDFStreamFormat::Flate;
224 std::optional<SkDeflateWStream> deflateWStream;
225 if (
format == SkPDFStreamFormat::Flate) {
227 stream = &*deflateWStream;
248 uint8_t byteBuffer[3072];
249 static_assert(
std::size(byteBuffer) % 3 == 0,
"");
250 uint8_t* bufferStop = byteBuffer +
std::size(byteBuffer);
251 uint8_t*
dst = byteBuffer;
254 for (
int x = 0;
x < pm.
width(); ++
x) {
257 color = get_neighbor_avg_color(pm,
x,
y);
262 if (
dst == bufferStop) {
263 stream->write(byteBuffer,
sizeof(byteBuffer));
268 stream->write(byteBuffer,
dst - byteBuffer);
270 if (deflateWStream) {
271 deflateWStream->finalize();
278 colorSpace = write_icc_profile(doc, std::move(iccData), channels);
281 #ifdef SK_PDF_BASE85_BINARY
282 SkPDFUtils::Base85Encode(
buffer.detachAsStream(), &
buffer);
288 do_deflated_alpha(pm, doc, sMask);
302 SkISize jpegSize = codec->dimensions();
314 #ifdef SK_PDF_BASE85_BINARY
320 int channels = yuv ? 3 : 1;
323 colorSpace = write_icc_profile(doc, std::move(encodedIccProfileData), channels);
324 }
else if (
const skcms_ICCProfile* codecIccProfile = codec->getICCProfile()) {
326 colorSpace = write_icc_profile(doc, std::move(codecIccData), channels);
327 }
else if (imageColorSpace && channels != 1) {
329 imageColorSpace->
toProfile(&imageIccProfile);
331 colorSpace = write_icc_profile(doc, std::move(imageIccData), channels);
334 emit_image_stream(doc, ref,
336 jpegSize, std::move(colorSpace),
376 if (do_jpeg(std::move(
data), img->
colorSpace(), doc, dimensions, ref)) {
383 if (encodingQuality <= 100 && isOpaque) {
388 if (do_jpeg(
stream.detachAsData(), pm.
colorSpace(), doc, dimensions, ref)) {
393 do_deflated_image(pm, doc, isOpaque, ref);
400 int encodingQuality) {
407 executor->add([img, encodingQuality, doc, ref]() {
@ kOpaque_SkAlphaType
pixel is opaque
#define SK_BGRA_A32_SHIFT
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
#define SkColorGetR(color)
#define SkColorGetG(color)
#define SkColorSetRGB(r, g, b)
constexpr SkColor SK_ColorTRANSPARENT
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
#define SkColorGetA(color)
#define SkColorGetB(color)
constexpr SkAlpha SK_AlphaTRANSPARENT
@ kTopLeft_SkEncodedOrigin
SK_API sk_sp< SkData > SkWriteICCProfile(const skcms_TransferFunction &, const skcms_Matrix3x3 &toXYZD50)
SkPDFIndirectReference SkPDFSerializeImage(const SkImage *img, SkPDFDocument *doc, int encodingQuality)
SkPDFIndirectReference SkPDFStreamOut(std::unique_ptr< SkPDFDict > dict, std::unique_ptr< SkStreamAsset > content, SkPDFDocument *doc, SkPDFSteamCompressionEnabled compress)
static std::unique_ptr< SkPDFDict > SkPDFMakeDict(const char *type=nullptr)
static std::unique_ptr< SkPDFArray > SkPDFMakeArray(Args... args)
static void SkSafeUnref(T *obj)
constexpr int SkToInt(S x)
constexpr uint8_t SkToU8(S x)
static sk_sp< SkData > serialize_image(const SkImage *image, SkSerialProcs procs)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
const SkPixmap & pixmap() const
void eraseColor(SkColor4f) const
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
const SkEncodedInfo & getEncodedInfo() const
void toProfile(skcms_ICCProfile *) const
SkColorSpace * colorSpace() const
SkISize dimensions() const
bool readPixels(GrDirectContext *context, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
SkColorType colorType() const
sk_sp< SkData > refEncodedData() const
sk_sp< SkColorSpace > refColorSpace() const
static std::unique_ptr< SkMemoryStream > Make(sk_sp< SkData > data)
static std::unique_ptr< SkMemoryStream > MakeDirect(const void *data, size_t length)
static const SkEncodedInfo & GetEncodedInfo(SkCodec &)
SkExecutor * executor() const
const SkPDF::Metadata & metadata() const
skia_private::THashMap< SkPDFIccProfileKey, SkPDFIndirectReference, SkPDFIccProfileKey::Hash > fICCProfileMap
void emitStream(const SkPDFDict &dict, T writeStream, SkPDFIndirectReference ref)
SkPDFIndirectReference reserveRef()
static SkPDFUnion Object(std::unique_ptr< SkPDFObject >)
static SkPDFUnion Name(const char *)
const uint8_t * addr8() const
bool computeIsOpaque() const
const uint32_t * addr32() const
SkColorType colorType() const
SkColorSpace * colorSpace() const
const SkImageInfo & info() const
SkAlphaType alphaType() const
V * find(const K &key) const
uint32_t uint32_t * format
static float max(float r, float g, float b)
static float min(float r, float g, float b)
constexpr SkCodecs::Decoder Decoder()
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
sk_sp< const SkImage > image
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
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
sk_sp< SkData > profileData() const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static SkImageInfo MakeA8(int width, int height)
std::shared_ptr< const fml::Mapping > data