Flutter Engine
The Flutter Engine
Classes | Namespaces | Functions | Variables
SkPngEncoderImpl.cpp File Reference
#include "src/encode/SkPngEncoderImpl.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkData.h"
#include "include/core/SkDataTable.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/encode/SkEncoder.h"
#include "include/encode/SkPngEncoder.h"
#include "include/private/base/SkAssert.h"
#include "include/private/base/SkDebug.h"
#include "include/private/base/SkNoncopyable.h"
#include "include/private/base/SkTemplates.h"
#include "modules/skcms/skcms.h"
#include "src/base/SkMSAN.h"
#include "src/codec/SkPngPriv.h"
#include "src/encode/SkImageEncoderFns.h"
#include "src/encode/SkImageEncoderPriv.h"
#include "src/image/SkImage_Base.h"
#include <algorithm>
#include <csetjmp>
#include <cstdint>
#include <cstring>
#include <memory>
#include <utility>
#include <vector>
#include <png.h>
#include <pngconf.h>

Go to the source code of this file.

Classes

class  SkPngEncoderMgr
 

Namespaces

namespace  SkPngEncoder
 

Functions

static void sk_error_fn (png_structp png_ptr, png_const_charp msg)
 
static void sk_write_fn (png_structp png_ptr, png_bytep data, png_size_t len)
 
static transform_scanline_proc choose_proc (const SkImageInfo &info)
 
static void set_icc (png_structp png_ptr, png_infop info_ptr, const SkImageInfo &info, const skcms_ICCProfile *profile, const char *profile_description)
 
SK_API std::unique_ptr< SkEncoderSkPngEncoder::Make (SkWStream *dst, const SkPixmap &src, const Options &options)
 
SK_API bool SkPngEncoder::Encode (SkWStream *dst, const SkPixmap &src, const Options &options)
 
SK_API sk_sp< SkDataSkPngEncoder::Encode (GrDirectContext *ctx, const SkImage *img, const Options &options)
 

Variables

static constexpr bool kSuppressPngEncodeWarnings = true
 

Function Documentation

◆ choose_proc()

static transform_scanline_proc choose_proc ( const SkImageInfo info)
static

Definition at line 267 of file SkPngEncoderImpl.cpp.

267 {
268 switch (info.colorType()) {
270 break;
271
272 // TODO: I don't think this can just use kRGBA's procs.
273 // kPremul is especially tricky here, since it's presumably TF⁻¹(rgb * a),
274 // so to get at unpremul rgb we'd need to undo the transfer function first.
276 return nullptr;
277
279 switch (info.alphaType()) {
286 default:
287 SkDEBUGFAIL("unknown alpha type");
288 return nullptr;
289 }
291 switch (info.alphaType()) {
298 default:
299 SkDEBUGFAIL("unknown alpha type");
300 return nullptr;
301 }
307 switch (info.alphaType()) {
312 default:
313 SkDEBUGFAIL("unknown alpha type");
314 return nullptr;
315 }
318
321 switch (info.alphaType()) {
327 default:
328 SkDEBUGFAIL("unknown alpha type");
329 return nullptr;
330 }
332 switch (info.alphaType()) {
338 default:
339 SkDEBUGFAIL("unknown alpha type");
340 return nullptr;
341 }
343 switch (info.alphaType()) {
349 default:
350 SkDEBUGFAIL("unknown alpha type");
351 return nullptr;
352 }
354 switch (info.alphaType()) {
360 default:
361 SkDEBUGFAIL("unknown alpha type");
362 return nullptr;
363 }
369 switch (info.alphaType()) {
372 default:
373 SkDEBUGFAIL("unsupported color type");
374 return nullptr;
375 }
388 return nullptr;
389 }
390 SkDEBUGFAIL("unsupported color type");
391 return nullptr;
392}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
kUnpremul_SkAlphaType
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
@ kR16G16B16A16_unorm_SkColorType
pixel with a little endian uint16_t for red, green, blue
Definition: SkColorType.h:50
@ kRGBA_10x6_SkColorType
pixel with 10 used bits (most significant) followed by 6 unused
Definition: SkColorType.h:33
@ kR8_unorm_SkColorType
Definition: SkColorType.h:54
@ kBGR_101010x_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word
Definition: SkColorType.h:30
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
Definition: SkColorType.h:23
@ kR8G8_unorm_SkColorType
pixel with a uint8_t for red and green
Definition: SkColorType.h:43
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
@ kA16_unorm_SkColorType
pixel with a little endian uint16_t for alpha
Definition: SkColorType.h:48
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition: SkColorType.h:38
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition: SkColorType.h:21
@ kRGB_101010x_SkColorType
pixel with 10 bits each for red, green, blue; in 32-bit word
Definition: SkColorType.h:29
@ kSRGBA_8888_SkColorType
Definition: SkColorType.h:53
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition: SkColorType.h:35
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition: SkColorType.h:22
@ kBGRA_10101010_XR_SkColorType
pixel with 10 bits each for blue, green, red, alpha; in 64-bit word, extended range
Definition: SkColorType.h:32
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
Definition: SkColorType.h:25
@ kBGRA_1010102_SkColorType
10 bits for blue, green, red; 2 bits for alpha; in 32-bit word
Definition: SkColorType.h:28
@ kA16_float_SkColorType
pixel with a half float for alpha
Definition: SkColorType.h:45
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
Definition: SkColorType.h:40
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
Definition: SkColorType.h:27
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
Definition: SkColorType.h:31
@ kR16G16_unorm_SkColorType
pixel with a little endian uint16_t for red and green
Definition: SkColorType.h:49
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
Definition: SkColorType.h:36
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
@ kR16G16_float_SkColorType
pixel with a half float for red and green
Definition: SkColorType.h:46
static void transform_scanline_RGBX(char *dst, const char *src, int width, int)
static void transform_scanline_bgr_101010x(char *dst, const char *src, int width, int)
static void transform_scanline_F32(char *dst, const char *src, int width, int)
static void transform_scanline_F16_premul(char *dst, const char *src, int width, int)
static void transform_scanline_F16(char *dst, const char *src, int width, int)
static void transform_scanline_bgra_1010102_premul(char *dst, const char *src, int width, int)
static void transform_scanline_bgra_10101010_xr(char *dst, const char *src, int width, int)
static void transform_scanline_1010102(char *dst, const char *src, int width, int)
static void transform_scanline_BGRX(char *dst, const char *src, int width, int)
static void transform_scanline_bgra_1010102(char *dst, const char *src, int width, int)
static void transform_scanline_4444(char *dst, const char *src, int width, int)
static void transform_scanline_565(char *dst, const char *src, int width, int)
static void transform_scanline_memcpy(char *dst, const char *src, int width, int bpp)
static void transform_scanline_A8_to_GrayAlpha(char *dst, const char *src, int width, int)
static void transform_scanline_bgr_101010x_xr(char *dst, const char *src, int width, int)
static void transform_scanline_101010x(char *dst, const char *src, int width, int)
static void transform_scanline_444(char *dst, const char *src, int width, int)
static void transform_scanline_F32_premul(char *dst, const char *src, int width, int)
static void transform_scanline_1010102_premul(char *dst, const char *src, int width, int)
static void transform_scanline_rgbA(char *dst, const char *src, int width, int)
static void transform_scanline_BGRA(char *dst, const char *src, int width, int)
static void transform_scanline_bgrA(char *dst, const char *src, int width, int)

◆ set_icc()

static void set_icc ( png_structp  png_ptr,
png_infop  info_ptr,
const SkImageInfo info,
const skcms_ICCProfile profile,
const char *  profile_description 
)
static

Definition at line 394 of file SkPngEncoderImpl.cpp.

398 {
399 sk_sp<SkData> icc = icc_from_color_space(info, profile, profile_description);
400 if (!icc) {
401 return;
402 }
403
404#if PNG_LIBPNG_VER_MAJOR > 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 5)
405 const char* name = "Skia";
406 png_const_bytep iccPtr = icc->bytes();
407#else
408 SkString str("Skia");
409 char* name = str.data();
410 png_charp iccPtr = (png_charp)icc->writable_data();
411#endif
412 png_set_iCCP(png_ptr, info_ptr, name, 0, iccPtr, icc->size());
413}
static sk_sp< SkData > icc_from_color_space(const SkColorSpace *cs, const skcms_ICCProfile *profile, const char *profile_description)
const uint8_t * bytes() const
Definition: SkData.h:43
void * writable_data()
Definition: SkData.h:52
size_t size() const
Definition: SkData.h:30
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ sk_error_fn()

static void sk_error_fn ( png_structp  png_ptr,
png_const_charp  msg 
)
static

Definition at line 57 of file SkPngEncoderImpl.cpp.

57 {
59 SkDebugf("libpng encode error: %s\n", msg);
60 }
61
62 longjmp(png_jmpbuf(png_ptr), 1);
63}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static constexpr bool kSuppressPngEncodeWarnings

◆ sk_write_fn()

static void sk_write_fn ( png_structp  png_ptr,
png_bytep  data,
png_size_t  len 
)
static

Definition at line 65 of file SkPngEncoderImpl.cpp.

65 {
66 SkWStream* stream = (SkWStream*)png_get_io_ptr(png_ptr);
67 if (!stream->write(data, len)) {
68 png_error(png_ptr, "sk_write_fn cannot write to stream");
69 }
70}
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

Variable Documentation

◆ kSuppressPngEncodeWarnings

constexpr bool kSuppressPngEncodeWarnings = true
staticconstexpr

Definition at line 55 of file SkPngEncoderImpl.cpp.