42#include "webp/encode.h"
44#include "webp/mux_types.h"
55 WebPConfig* webp_config,
68 if (
nullptr == pixmap.
addr()) {
72 pic->width = pixmap.
width();
73 pic->height = pixmap.
height();
80 webp_config->lossless = 0;
81#ifndef SK_WEBP_ENCODER_USE_DEFAULT_METHOD
82 webp_config->method = 3;
86 webp_config->lossless = 1;
87 webp_config->method = 0;
99 importProc = WebPPictureImportRGBX;
101 importProc = WebPPictureImportRGBA;
103#ifdef WebPPictureImportBGRA
105 importProc = WebPPictureImportBGRA;
109 importProc = WebPPictureImportRGBA;
120 if (!importProc(pic,
reinterpret_cast<const uint8_t*
>(
src->addr()),
src->rowBytes())) {
135 WebPConfig webp_config;
136 if (!WebPConfigPreset(&webp_config, WEBP_PRESET_DEFAULT, opts.fQuality)) {
141 if (!WebPPictureInit(&pic)) {
156 pic.custom_ptr = icc ? (
void*)&tmp : (
void*)
stream;
159 if (!WebPEncode(&webp_config, &pic)) {
165 WebPData encoded = {encodedData->
bytes(), encodedData->
size()};
166 WebPData iccChunk = {icc->
bytes(), icc->
size()};
169 if (WEBP_MUX_OK != WebPMuxSetImage(mux, &encoded, 0)) {
173 if (WEBP_MUX_OK != WebPMuxSetChunk(mux,
"ICCP", &iccChunk, 0)) {
179 if (WEBP_MUX_OK != WebPMuxAssemble(mux, &assembled)) {
183 if (!
stream->write(assembled.bytes, assembled.size)) {
196 const int canvasWidth = frames.
front().pixmap.width();
197 const int canvasHeight = frames.
front().pixmap.height();
200 std::unique_ptr<WebPAnimEncoder, void (*)(WebPAnimEncoder*)> enc(
201 WebPAnimEncoderNew(canvasWidth, canvasHeight,
nullptr), WebPAnimEncoderDelete);
206 for (
const auto&
frame : frames) {
207 const auto& pixmap =
frame.pixmap;
209 if (pixmap.
width() != canvasWidth || pixmap.
height() != canvasHeight) {
213 WebPConfig webp_config;
214 if (!WebPConfigPreset(&webp_config, WEBP_PRESET_DEFAULT, opts.
fQuality)) {
219 if (!WebPPictureInit(&pic)) {
228 if (!WebPEncode(&webp_config, &pic)) {
232 if (!WebPAnimEncoderAdd(enc.get(), &pic, timestamp, &webp_config)) {
236 timestamp +=
frame.duration;
240 if (!WebPAnimEncoderAdd(enc.get(),
nullptr, timestamp,
nullptr)) {
246 if (!WebPAnimEncoderAssemble(enc.get(), &assembled)) {
252 return stream->write(assembled.bytes, assembled.size);
260 if (!
as_IB(img)->getROPixels(ctx, &bm)) {
265 return stream.detachAsData();
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ 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
static sk_sp< SkData > icc_from_color_space(const SkColorSpace *cs, const skcms_ICCProfile *profile, const char *profile_description)
static bool SkPixmapIsValid(const SkPixmap &src)
static bool SkColorTypeIsAlphaOnly(SkColorType ct)
static SkImage_Base * as_IB(SkImage *image)
static int stream_writer(const uint8_t *data, size_t data_size, const WebPPicture *const picture)
static bool preprocess_webp_picture(WebPPicture *pic, WebPConfig *webp_config, const SkPixmap &pixmap, const SkWebpEncoder::Options &opts)
int(*)(WebPPicture *picture, const uint8_t *pixels, int stride) WebPPictureImportProc
static uint32_t premul(uint32_t color)
const SkPixmap & pixmap() const
const SkImageInfo & info() const
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
const uint8_t * bytes() const
sk_sp< SkData > detachAsData()
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes) const
SkColorType colorType() const
const SkImageInfo & info() const
const void * addr() const
SkAlphaType alphaType() const
constexpr T & front() const
constexpr bool empty() const
sk_sp< const SkPicture > picture
SK_API bool EncodeAnimated(SkWStream *dst, SkSpan< const SkEncoder::Frame > src, const Options &options)
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
SkImageInfo makeColorType(SkColorType newColorType) const
std::shared_ptr< const fml::Mapping > data