20 switch (
bitmap.alphaType()) {
29 switch (
bitmap.colorType()) {
66 if (
auto cs =
bitmap.colorSpace()) {
67 cs->toProfile(&srcProfile);
88 fPixels.reset(
new uint64_t[
N]);
90 const void* src =
bitmap.getPixels();
91 void* dst = fPixels.get();
93 int todo = std::min(
N, 1<<27);
95 dst, dstFmt, dstAlpha, &dstProfile, todo)) {
97 fPixels.reset(
nullptr);
101 dst = (
char*)dst + todo*
sizeof(uint64_t);
107 st->
write(&fSize,
sizeof(fSize));
108 if (
const uint64_t* px = fPixels.get()) {
115 st->
write(&salt,
sizeof(salt));
130 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
nullptr,
nullptr,
nullptr);
135 png_infop
info = png_create_info_struct(png);
137 png_destroy_write_struct(&png, &
info);
140 auto write_to_stream = +[](png_structp png, png_bytep ptr, png_size_t len) {
141 auto st = (
SkWStream*)png_get_io_ptr(png);
142 if (!st->
write(ptr, len)) {
143 png_error(png,
"HashAndEncode::encodePNG() failed writing stream");
146 png_set_write_fn(png, st, write_to_stream,
nullptr);
149 description.
append(
"Key: ");
150 for (
int i = 0; i <
key.size(); i++) {
153 description.
append(
"Properties: ");
154 for (
int i = 0; i < properties.
size(); i++) {
155 description.
appendf(
"%s ", properties[i]);
160 text[0].key =
const_cast<png_charp
>(
"Author");
161 text[0].text =
const_cast<png_charp
>(
"DM unified Rec.2020");
162 text[0].compression = PNG_TEXT_COMPRESSION_NONE;
163 text[1].key =
const_cast<png_charp
>(
"Description");
164 text[1].text =
const_cast<png_charp
>(description.
c_str());
165 text[1].compression = PNG_TEXT_COMPRESSION_NONE;
168 png_set_IHDR(png,
info, (png_uint_32)fSize.
width()
169 , (png_uint_32)fSize.
height()
171 , PNG_COLOR_TYPE_RGB_ALPHA
173 , PNG_COMPRESSION_TYPE_DEFAULT
174 , PNG_FILTER_TYPE_DEFAULT);
177 png_set_filter(png, PNG_FILTER_TYPE_BASE, PNG_FILTER_NONE);
178 png_set_compression_level(png, 1);
182 png_set_iCCP(png,
info,
185 (png_const_bytep)profile->data(),
186 (png_uint_32) profile->size());
188 png_write_info(png,
info);
189 for (
int y = 0;
y < fSize.
height();
y++) {
190 png_write_row(png, (png_bytep)(fPixels.get() +
y*fSize.
width()));
192 png_write_end(png,
info);
194 png_destroy_write_struct(&png, &
info);
static SkMD5::Digest md5(const SkBitmap &bm)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static sk_sp< SkColorSpace > rec2020()
@ kUnknown_SkAlphaType
uninitialized
@ kOpaque_SkAlphaType
pixel is opaque
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kR16G16B16A16_unorm_SkColorType
pixel with a little endian uint16_t for red, green, blue
@ kRGBA_10x6_SkColorType
pixel with 10 used bits (most significant) followed by 6 unused
@ kBGR_101010x_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
@ kR8G8_unorm_SkColorType
pixel with a uint8_t for red and green
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kA16_unorm_SkColorType
pixel with a little endian uint16_t for alpha
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
@ kRGB_101010x_SkColorType
pixel with 10 bits each for red, green, blue; in 32-bit word
@ kSRGBA_8888_SkColorType
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
@ kBGRA_10101010_XR_SkColorType
pixel with 10 bits each for blue, green, red, alpha; in 64-bit word, extended range
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
@ kBGRA_1010102_SkColorType
10 bits for blue, green, red; 2 bits for alpha; in 32-bit word
@ kA16_float_SkColorType
pixel with a half float for alpha
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
@ kR16G16_unorm_SkColorType
pixel with a little endian uint16_t for red and green
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
@ kUnknown_SkColorType
uninitialized
@ kR16G16_float_SkColorType
pixel with a half float for red and green
SK_API sk_sp< SkData > SkWriteICCProfile(const skcms_TransferFunction &, const skcms_Matrix3x3 &toXYZD50)
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
bool encodePNG(SkWStream *, const char *md5, CommandLineFlags::StringArray key, CommandLineFlags::StringArray properties) const
HashAndEncode(const SkBitmap &)
void feedHash(SkWStream *) const
void toProfile(skcms_ICCProfile *) const
static sk_sp< SkColorSpace > MakeRGB(const skcms_TransferFunction &transferFn, const skcms_Matrix3x3 &toXYZ)
void append(const char text[])
const char * c_str() const
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
virtual bool write(const void *buffer, size_t size)=0
static constexpr skcms_Matrix3x3 kRec2020
static constexpr skcms_TransferFunction kRec2020
bool skcms_Transform(const void *src, skcms_PixelFormat srcFmt, skcms_AlphaFormat srcAlpha, const skcms_ICCProfile *srcProfile, void *dst, skcms_PixelFormat dstFmt, skcms_AlphaFormat dstAlpha, const skcms_ICCProfile *dstProfile, size_t nz)
const skcms_ICCProfile * skcms_sRGB_profile()
@ skcms_PixelFormat_RGBA_8888_sRGB
@ skcms_PixelFormat_RGBA_16161616BE
@ skcms_PixelFormat_BGR_101010x_XR
@ skcms_PixelFormat_RGBA_ffff
@ skcms_PixelFormat_RGBA_1010102
@ skcms_PixelFormat_BGRA_8888
@ skcms_PixelFormat_RGBA_hhhh
@ skcms_PixelFormat_RGBA_8888
@ skcms_PixelFormat_BGR_565
@ skcms_PixelFormat_ABGR_4444
@ skcms_PixelFormat_BGRA_1010102
@ skcms_PixelFormat_RGBA_16161616LE
@ skcms_AlphaFormat_Unpremul
@ skcms_AlphaFormat_PremulAsEncoded
@ skcms_AlphaFormat_Opaque
constexpr int32_t width() const
constexpr int32_t height() const