Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 258 of file SkPngEncoderImpl.cpp.

258 {
259 switch (info.colorType()) {
261 break;
262
263 // TODO: I don't think this can just use kRGBA's procs.
264 // kPremul is especially tricky here, since it's presumably TF⁻¹(rgb * a),
265 // so to get at unpremul rgb we'd need to undo the transfer function first.
267 return nullptr;
268
270 switch (info.alphaType()) {
277 default:
278 SkDEBUGFAIL("unknown alpha type");
279 return nullptr;
280 }
282 switch (info.alphaType()) {
289 default:
290 SkDEBUGFAIL("unknown alpha type");
291 return nullptr;
292 }
298 switch (info.alphaType()) {
303 default:
304 SkDEBUGFAIL("unknown alpha type");
305 return nullptr;
306 }
309
312 switch (info.alphaType()) {
318 default:
319 SkDEBUGFAIL("unknown alpha type");
320 return nullptr;
321 }
323 switch (info.alphaType()) {
329 default:
330 SkDEBUGFAIL("unknown alpha type");
331 return nullptr;
332 }
334 switch (info.alphaType()) {
340 default:
341 SkDEBUGFAIL("unknown alpha type");
342 return nullptr;
343 }
345 switch (info.alphaType()) {
351 default:
352 SkDEBUGFAIL("unknown alpha type");
353 return nullptr;
354 }
360 switch (info.alphaType()) {
363 default:
364 SkDEBUGFAIL("unsupported color type");
365 return nullptr;
366 }
378 return nullptr;
379 }
380 SkDEBUGFAIL("unsupported color type");
381 return nullptr;
382}
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_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 384 of file SkPngEncoderImpl.cpp.

388 {
389 sk_sp<SkData> icc = icc_from_color_space(info, profile, profile_description);
390 if (!icc) {
391 return;
392 }
393
394#if PNG_LIBPNG_VER_MAJOR > 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 5)
395 const char* name = "Skia";
396 png_const_bytep iccPtr = icc->bytes();
397#else
398 SkString str("Skia");
399 char* name = str.data();
400 png_charp iccPtr = (png_charp)icc->writable_data();
401#endif
402 png_set_iCCP(png_ptr, info_ptr, name, 0, iccPtr, icc->size());
403}
static sk_sp< SkData > icc_from_color_space(const SkColorSpace *cs, const skcms_ICCProfile *profile, const char *profile_description)
const char * name
Definition fuchsia.cc:50

◆ 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}

Variable Documentation

◆ kSuppressPngEncodeWarnings

constexpr bool kSuppressPngEncodeWarnings = true
staticconstexpr

Definition at line 55 of file SkPngEncoderImpl.cpp.