Reland "Split building encoding from decoding"

This reverts commit 9d4b788807.
Copyright issue has been fixed in
https://skia-review.googlesource.com/c/skia/+/275998.

Original description:
Bug: skia:9756

In CanvasKit, a large part of the binary is for encoding. Clients
would be happier with a smaller binary and no webp/jpeg encoding. Make
this an option by splitting up the GN arguments.

Split SK_HAS_WEBP_LIBRARY into SK_CODEC_DECODES_WEBP (to match the
existing SK_CODEC_DECODES_RAW) and SK_ENCODE_WEBP. Same for JPEG and
PNG.

Update CanvasKit compile script to disable webp and jpeg encoding.
Update debugger compile script to disable all encoding.

Change IsPng signature to match other SkCodecs.

TBR=djsollen@google.com

Change-Id: Ic847bae0154e0a2922100b3f2ee14a077ee5635a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/276007
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
This commit is contained in:
Leon Scroggins III 2020-03-09 14:23:30 -04:00 committed by Skia Commit-Bot
parent 85da3368c5
commit a77f30c7db
21 changed files with 155 additions and 80 deletions

View File

@ -661,9 +661,23 @@ optional("heif") {
]
}
optional("jpeg") {
enabled = skia_use_libjpeg_turbo
public_defines = [ "SK_HAS_JPEG_LIBRARY" ]
optional("jpeg_decode") {
enabled = skia_use_libjpeg_turbo_decode
public_defines = [ "SK_CODEC_DECODES_JPEG" ]
deps = [
"//third_party/libjpeg-turbo:libjpeg",
]
sources = [
"src/codec/SkJpegCodec.cpp",
"src/codec/SkJpegDecoderMgr.cpp",
"src/codec/SkJpegUtility.cpp",
]
}
optional("jpeg_encode") {
enabled = skia_use_libjpeg_turbo_encode
public_defines = [ "SK_ENCODE_JPEG" ]
deps = [
"//third_party/libjpeg-turbo:libjpeg",
@ -672,9 +686,6 @@ optional("jpeg") {
"include/encode/SkJpegEncoder.h",
]
sources = [
"src/codec/SkJpegCodec.cpp",
"src/codec/SkJpegDecoderMgr.cpp",
"src/codec/SkJpegUtility.cpp",
"src/images/SkJPEGWriteUtility.cpp",
"src/images/SkJpegEncoder.cpp",
]
@ -687,8 +698,11 @@ optional("pdf") {
deps = [
"//third_party/zlib",
]
if (skia_use_libjpeg_turbo) {
deps += [ ":jpeg" ]
if (skia_use_libjpeg_turbo_decode) {
deps += [ ":jpeg_decode" ]
}
if (skia_use_libjpeg_turbo_encode) {
deps += [ ":jpeg_encode" ]
}
sources = skia_pdf_sources
sources_when_disabled = [ "src/pdf/SkDocument_PDF_None.cpp" ]
@ -701,9 +715,9 @@ optional("pdf") {
}
}
optional("png") {
enabled = skia_use_libpng
public_defines = [ "SK_HAS_PNG_LIBRARY" ]
optional("png_decode") {
enabled = skia_use_libpng_decode
public_defines = [ "SK_CODEC_DECODES_PNG" ]
deps = [
"//third_party/libpng",
@ -711,12 +725,23 @@ optional("png") {
sources = [
"src/codec/SkIcoCodec.cpp",
"src/codec/SkPngCodec.cpp",
]
}
optional("png_encode") {
enabled = skia_use_libpng_encode
public_defines = [ "SK_ENCODE_PNG" ]
deps = [
"//third_party/libpng",
]
sources = [
"src/images/SkPngEncoder.cpp",
]
}
optional("raw") {
enabled = skia_use_dng_sdk && skia_use_libjpeg_turbo && skia_use_piex
enabled = skia_use_dng_sdk && skia_use_libjpeg_turbo_decode && skia_use_piex
public_defines = [ "SK_CODEC_DECODES_RAW" ]
deps = [
@ -763,15 +788,26 @@ optional("typeface_freetype") {
]
}
optional("webp") {
enabled = skia_use_libwebp
public_defines = [ "SK_HAS_WEBP_LIBRARY" ]
optional("webp_decode") {
enabled = skia_use_libwebp_decode
public_defines = [ "SK_CODEC_DECODES_WEBP" ]
deps = [
"//third_party/libwebp",
]
sources = [
"src/codec/SkWebpCodec.cpp",
]
}
optional("webp_encode") {
enabled = skia_use_libwebp_encode
public_defines = [ "SK_ENCODE_WEBP" ]
deps = [
"//third_party/libwebp",
]
sources = [
"src/images/SkWebpEncoder.cpp",
]
}
@ -868,9 +904,11 @@ component("skia") {
":gif",
":heif",
":hsw",
":jpeg",
":jpeg_decode",
":jpeg_encode",
":none",
":png",
":png_decode",
":png_encode",
":raw",
":sksl_interpreter",
":skvm_jit",
@ -878,7 +916,8 @@ component("skia") {
":sse41",
":sse42",
":ssse3",
":webp",
":webp_decode",
":webp_encode",
":wuffs",
":xml",
]

View File

@ -7,6 +7,9 @@ This file includes a list of high level updates for each milestone release.
Milestone 82
<Insert new notes here- top is most recent.>
* Make it possible to selectively turn on/off individual encoders/decoders,
using skia_use_(libpng/libjpeg_turbo/libwebp)(decode/encode).
* Removed GrGpuResource, GrSurface, and GrTexture from public api. These were not
meant to be public, and we now can move them into src. Also removed getTexture
function from SkImage.h

View File

@ -86,9 +86,12 @@ echo "Compiling bitcode"
skia_use_fontconfig=false \
skia_use_freetype=true \
skia_use_libheif=false \
skia_use_libjpeg_turbo=true \
skia_use_libpng=true \
skia_use_libwebp=true \
skia_use_libjpeg_turbo_decode=true \
skia_use_libjpeg_turbo_encode=false \
skia_use_libpng_decode=true \
skia_use_libpng_encode=false \
skia_use_libwebp_decode=true \
skia_use_libwebp_encode=false \
skia_use_wuffs=true \
skia_use_lua=false \
skia_use_piex=false \

View File

@ -51,9 +51,12 @@ declare_args() {
skia_use_gl = !is_fuchsia
skia_use_icu = !is_fuchsia
skia_use_libheif = is_skia_dev_build
skia_use_libjpeg_turbo = true
skia_use_libpng = true
skia_use_libwebp = true
skia_use_libjpeg_turbo_decode = true
skia_use_libjpeg_turbo_encode = true
skia_use_libpng_decode = true
skia_use_libpng_encode = true
skia_use_libwebp_decode = true
skia_use_libwebp_encode = true
skia_use_lua = is_skia_dev_build && !is_ios
skia_use_metal = false
skia_use_opencl = false
@ -93,7 +96,8 @@ declare_args() {
skia_enable_fontmgr_custom_empty = is_fuchsia && skia_use_freetype
skia_enable_nvpr = !skia_enable_flutter_defines
skia_enable_spirv_validation = is_skia_dev_build && is_debug && !skia_use_dawn
skia_use_dng_sdk = !is_fuchsia && skia_use_libjpeg_turbo && skia_use_zlib
skia_use_dng_sdk =
!is_fuchsia && skia_use_libjpeg_turbo_decode && skia_use_zlib
skia_use_libgifcodec = !skia_use_wuffs
skia_use_sfntly = skia_use_icu
skia_enable_vulkan_debug_layers = skia_enable_gpu_debug_layers

View File

@ -974,7 +974,7 @@ public:
Returns nullptr if encoding fails, or if encodedImageFormat is not supported.
SkImage encoding in a format requires both building with one or more of:
SK_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY; and platform support
SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP; and platform support
for the encoded format.
If SK_BUILD_FOR_MAC or SK_BUILD_FOR_IOS is defined, encodedImageFormat can
@ -996,7 +996,7 @@ public:
/** Encodes SkImage pixels, returning result as SkData. Returns existing encoded data
if present; otherwise, SkImage is encoded with SkEncodedImageFormat::kPNG. Skia
must be built with SK_HAS_PNG_LIBRARY to encode SkImage.
must be built with SK_ENCODE_PNG to encode SkImage.
Returns nullptr if existing encoded data is missing or invalid, and
encoding fails.
@ -1009,7 +1009,7 @@ public:
/** Returns encoded SkImage pixels as SkData, if SkImage was created from supported
encoded stream format. Platform support for formats vary and may require building
with one or more of: SK_HAS_JPEG_LIBRARY, SK_HAS_PNG_LIBRARY, SK_HAS_WEBP_LIBRARY.
with one or more of: SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP.
Returns nullptr if SkImage contents are not encoded.

View File

@ -248,19 +248,22 @@ def compile_fn(api, checkout_root, out_dir):
args['skia_enable_spirv_validation'] = 'false'
if 'NoDEPS' in extra_tokens:
args.update({
'is_official_build': 'true',
'skia_enable_fontmgr_empty': 'true',
'skia_enable_gpu': 'true',
'is_official_build': 'true',
'skia_enable_fontmgr_empty': 'true',
'skia_enable_gpu': 'true',
'skia_enable_pdf': 'false',
'skia_use_expat': 'false',
'skia_use_freetype': 'false',
'skia_use_harfbuzz': 'false',
'skia_use_libjpeg_turbo': 'false',
'skia_use_libpng': 'false',
'skia_use_libwebp': 'false',
'skia_use_vulkan': 'false',
'skia_use_zlib': 'false',
'skia_enable_pdf': 'false',
'skia_use_expat': 'false',
'skia_use_freetype': 'false',
'skia_use_harfbuzz': 'false',
'skia_use_libjpeg_turbo_decode': 'false',
'skia_use_libjpeg_turbo_encode': 'false',
'skia_use_libpng_decode': 'false',
'skia_use_libpng_encode': 'false',
'skia_use_libwebp_decode': 'false',
'skia_use_libwebp_encode': 'false',
'skia_use_vulkan': 'false',
'skia_use_zlib': 'false',
})
if 'Shared' in extra_tokens:
args['is_component_build'] = 'true'

View File

@ -52,7 +52,7 @@
"[START_DIR]/cache/work/skia/bin/gn",
"gen",
"[START_DIR]/cache/work/skia/out/Build-Debian9-Clang-x86_64-Release-NoDEPS/Release",
"--args=cc=\"[START_DIR]/clang_linux/bin/clang\" cc_wrapper=\"[START_DIR]/ccache_linux/bin/ccache\" cxx=\"[START_DIR]/clang_linux/bin/clang++\" extra_cflags=[\"-B[START_DIR]/clang_linux/bin\", \"-DDUMMY_clang_linux_version=42\"] extra_ldflags=[\"-B[START_DIR]/clang_linux/bin\", \"-fuse-ld=lld\", \"-L[START_DIR]/clang_linux/lib\"] is_debug=false is_official_build=true skia_enable_fontmgr_empty=true skia_enable_gpu=true skia_enable_pdf=false skia_use_expat=false skia_use_freetype=false skia_use_harfbuzz=false skia_use_libjpeg_turbo=false skia_use_libpng=false skia_use_libwebp=false skia_use_vulkan=false skia_use_zlib=false target_cpu=\"x86_64\" werror=true"
"--args=cc=\"[START_DIR]/clang_linux/bin/clang\" cc_wrapper=\"[START_DIR]/ccache_linux/bin/ccache\" cxx=\"[START_DIR]/clang_linux/bin/clang++\" extra_cflags=[\"-B[START_DIR]/clang_linux/bin\", \"-DDUMMY_clang_linux_version=42\"] extra_ldflags=[\"-B[START_DIR]/clang_linux/bin\", \"-fuse-ld=lld\", \"-L[START_DIR]/clang_linux/lib\"] is_debug=false is_official_build=true skia_enable_fontmgr_empty=true skia_enable_gpu=true skia_enable_pdf=false skia_use_expat=false skia_use_freetype=false skia_use_harfbuzz=false skia_use_libjpeg_turbo_decode=false skia_use_libjpeg_turbo_encode=false skia_use_libpng_decode=false skia_use_libpng_encode=false skia_use_libwebp_decode=false skia_use_libwebp_encode=false skia_use_vulkan=false skia_use_zlib=false target_cpu=\"x86_64\" werror=true"
],
"cwd": "[START_DIR]/cache/work/skia",
"env": {

View File

@ -139,7 +139,7 @@
"[START_DIR]\\skia\\bin\\gn",
"gen",
"[START_DIR]\\skia\\out\\Build-Win10-Clang-x86_64-Release-NoDEPS\\Release_x64",
"--args=cc=\"clang\" clang_win=\"[START_DIR]\\clang_win\" cxx=\"clang++\" extra_cflags=[\"-DDUMMY_clang_win_version=42\"] is_debug=false is_official_build=true skia_enable_fontmgr_empty=true skia_enable_gpu=true skia_enable_pdf=false skia_use_expat=false skia_use_freetype=false skia_use_harfbuzz=false skia_use_libjpeg_turbo=false skia_use_libpng=false skia_use_libwebp=false skia_use_vulkan=false skia_use_zlib=false target_cpu=\"x86_64\" werror=true win_sdk=\"[START_DIR]\\win_toolchain/win_sdk\" win_vc=\"[START_DIR]\\win_toolchain/VC\""
"--args=cc=\"clang\" clang_win=\"[START_DIR]\\clang_win\" cxx=\"clang++\" extra_cflags=[\"-DDUMMY_clang_win_version=42\"] is_debug=false is_official_build=true skia_enable_fontmgr_empty=true skia_enable_gpu=true skia_enable_pdf=false skia_use_expat=false skia_use_freetype=false skia_use_harfbuzz=false skia_use_libjpeg_turbo_decode=false skia_use_libjpeg_turbo_encode=false skia_use_libpng_decode=false skia_use_libpng_encode=false skia_use_libwebp_decode=false skia_use_libwebp_encode=false skia_use_vulkan=false skia_use_zlib=false target_cpu=\"x86_64\" werror=true win_sdk=\"[START_DIR]\\win_toolchain/win_sdk\" win_vc=\"[START_DIR]\\win_toolchain/VC\""
],
"cwd": "[START_DIR]\\skia",
"env": {

View File

@ -20,6 +20,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Shadows are properly draw on fillRect and strokeRect in the canvas2d emulation layer.
- Shadow offsets properly ignore the CTM in the canvas2d emulation layer.
### Changed
- Stop compiling jpeg and webp encoders, for a smaller binary.
## [0.13.0] - 2020-02-28
### Deprecated
@ -46,7 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- SkMatrix.invert now returns null when the matrix is not invertible. Previously it would return an
identity matrix. Callers must determine what behavior would be appropriate in this situation.
- In Canvas2D compatibility layer, the underlying SkFont will have setSubpixel(true).
- Bones are removed from Vertices builder
- Bones are removed from Vertices builder
### Fixed
- Support for .otf fonts (.woff and .woff2 still not supported).

View File

@ -233,9 +233,12 @@ echo "Compiling bitcode"
skia_use_fontconfig=false \
skia_use_freetype=true \
skia_use_libheif=false \
skia_use_libjpeg_turbo=true \
skia_use_libpng=true \
skia_use_libwebp=true \
skia_use_libjpeg_turbo_decode=true \
skia_use_libjpeg_turbo_encode=false \
skia_use_libpng_decode=true \
skia_use_libpng_encode=true \
skia_use_libwebp_decode=true \
skia_use_libwebp_encode=false \
skia_use_lua=false \
skia_use_piex=false \
skia_use_system_freetype2=false \

View File

@ -673,7 +673,8 @@ def base_defines(os_conditions):
# Experiment to diagnose image diffs in Google3
"SK_DISABLE_LOWP_RASTER_PIPELINE",
# JPEG is in codec_limited
"SK_HAS_JPEG_LIBRARY",
"SK_CODEC_DECODES_JPEG",
"SK_ENCODE_JPEG",
# Needed for some tests in dm
"SK_ENABLE_SKSL_INTERPRETER",
] + skia_select(
@ -683,15 +684,19 @@ def base_defines(os_conditions):
[
"PNG_SKIP_SETJMP_CHECK",
"SK_BUILD_FOR_UNIX",
"SK_CODEC_DECODES_PNG",
"SK_CODEC_DECODES_WEBP",
"SK_ENCODE_PNG",
"SK_ENCODE_WEBP",
"SK_R32_SHIFT=16",
"SK_HAS_PNG_LIBRARY",
"SK_HAS_WEBP_LIBRARY",
],
# ANDROID
[
"SK_BUILD_FOR_ANDROID",
"SK_HAS_PNG_LIBRARY",
"SK_HAS_WEBP_LIBRARY",
"SK_CODEC_DECODES_PNG",
"SK_CODEC_DECODES_WEBP",
"SK_ENCODE_PNG",
"SK_ENCODE_WEBP",
],
# IOS
[

View File

@ -100,13 +100,13 @@ std::unique_ptr<SkAndroidCodec> SkAndroidCodec::MakeFromCodec(std::unique_ptr<Sk
#ifdef SK_HAS_WUFFS_LIBRARY
case SkEncodedImageFormat::kGIF:
#endif
#ifdef SK_HAS_WEBP_LIBRARY
#ifdef SK_CODEC_DECODES_WEBP
case SkEncodedImageFormat::kWEBP:
#endif
#ifdef SK_CODEC_DECODES_RAW
case SkEncodedImageFormat::kDNG:
#endif
#if defined(SK_HAS_WEBP_LIBRARY) || defined(SK_CODEC_DECODES_RAW) || defined(SK_HAS_WUFFS_LIBRARY)
#if defined(SK_CODEC_DECODES_WEBP) || defined(SK_CODEC_DECODES_RAW) || defined(SK_HAS_WUFFS_LIBRARY)
return std::make_unique<SkAndroidCodecAdapter>(codec.release(), orientationBehavior);
#endif

View File

@ -17,7 +17,7 @@
#endif
#include "src/codec/SkIcoCodec.h"
#include "src/codec/SkJpegCodec.h"
#ifdef SK_HAS_PNG_LIBRARY
#ifdef SK_CODEC_DECODES_PNG
#include "src/codec/SkPngCodec.h"
#endif
#include "include/core/SkStream.h"
@ -37,10 +37,10 @@ struct DecoderProc {
static std::vector<DecoderProc>* decoders() {
static auto* decoders = new std::vector<DecoderProc> {
#ifdef SK_HAS_JPEG_LIBRARY
#ifdef SK_CODEC_DECODES_JPEG
{ SkJpegCodec::IsJpeg, SkJpegCodec::MakeFromStream },
#endif
#ifdef SK_HAS_WEBP_LIBRARY
#ifdef SK_CODEC_DECODES_WEBP
{ SkWebpCodec::IsWebp, SkWebpCodec::MakeFromStream },
#endif
#ifdef SK_HAS_WUFFS_LIBRARY
@ -48,7 +48,7 @@ static std::vector<DecoderProc>* decoders() {
#elif defined(SK_USE_LIBGIFCODEC)
{ SkGifCodec::IsGif, SkGifCodec::MakeFromStream },
#endif
#ifdef SK_HAS_PNG_LIBRARY
#ifdef SK_CODEC_DECODES_PNG
{ SkIcoCodec::IsIco, SkIcoCodec::MakeFromStream },
#endif
{ SkBmpCodec::IsBmp, SkBmpCodec::MakeFromStream },
@ -112,7 +112,7 @@ std::unique_ptr<SkCodec> SkCodec::MakeFromStream(
// PNG is special, since we want to be able to supply an SkPngChunkReader.
// But this code follows the same pattern as the loop.
#ifdef SK_HAS_PNG_LIBRARY
#ifdef SK_CODEC_DECODES_PNG
if (SkPngCodec::IsPng(buffer, bytesRead)) {
return SkPngCodec::MakeFromStream(std::move(stream), outResult, chunkReader);
} else

View File

@ -325,7 +325,7 @@ bool SkPngCodec::createColorTable(const SkImageInfo& dstInfo) {
// Creation
///////////////////////////////////////////////////////////////////////////////
bool SkPngCodec::IsPng(const char* buf, size_t bytesRead) {
bool SkPngCodec::IsPng(const void* buf, size_t bytesRead) {
return !png_sig_cmp((png_bytep) buf, (png_size_t)0, bytesRead);
}

View File

@ -19,7 +19,7 @@ class SkStream;
class SkPngCodec : public SkCodec {
public:
static bool IsPng(const char*, size_t);
static bool IsPng(const void*, size_t);
// Assume IsPng was called and returned true.
static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*,

View File

@ -10,21 +10,21 @@
#include "include/encode/SkWebpEncoder.h"
#include "src/images/SkImageEncoderPriv.h"
#ifndef SK_HAS_JPEG_LIBRARY
#ifndef SK_ENCODE_JPEG
bool SkJpegEncoder::Encode(SkWStream*, const SkPixmap&, const Options&) { return false; }
std::unique_ptr<SkEncoder> SkJpegEncoder::Make(SkWStream*, const SkPixmap&, const Options&) {
return nullptr;
}
#endif
#ifndef SK_HAS_PNG_LIBRARY
#ifndef SK_ENCODE_PNG
bool SkPngEncoder::Encode(SkWStream*, const SkPixmap&, const Options&) { return false; }
std::unique_ptr<SkEncoder> SkPngEncoder::Make(SkWStream*, const SkPixmap&, const Options&) {
return nullptr;
}
#endif
#ifndef SK_HAS_WEBP_LIBRARY
#ifndef SK_ENCODE_WEBP
bool SkWebpEncoder::Encode(SkWStream*, const SkPixmap&, const Options&) { return false; }
#endif

View File

@ -7,7 +7,7 @@
#include "src/images/SkImageEncoderPriv.h"
#ifdef SK_HAS_JPEG_LIBRARY
#ifdef SK_ENCODE_JPEG
#include "include/core/SkStream.h"
#include "include/encode/SkJpegEncoder.h"

View File

@ -7,7 +7,7 @@
#include "src/images/SkImageEncoderPriv.h"
#ifdef SK_HAS_PNG_LIBRARY
#ifdef SK_ENCODE_PNG
#include "include/core/SkStream.h"
#include "include/core/SkString.h"

View File

@ -7,7 +7,7 @@
#include "src/images/SkImageEncoderPriv.h"
#ifdef SK_HAS_WEBP_LIBRARY
#ifdef SK_ENCODE_WEBP
#include "include/core/SkBitmap.h"
#include "include/core/SkStream.h"

View File

@ -9,7 +9,7 @@
#include "include/private/SkTo.h"
#ifndef SK_HAS_JPEG_LIBRARY
#ifndef SK_CODEC_DECODES_JPEG
namespace {
class JpegSegment {
@ -125,4 +125,4 @@ bool SkGetJpegInfo(const void* data, size_t len,
}
return true;
}
#endif // SK_HAS_JPEG_LIBRARY
#endif // SK_CODEC_DECODES_JPEG

View File

@ -24,7 +24,6 @@
#include "include/utils/SkBase64.h"
#include "include/utils/SkParsePath.h"
#include "src/codec/SkJpegCodec.h"
#include "src/codec/SkPngCodec.h"
#include "src/core/SkAnnotationKeys.h"
#include "src/core/SkClipOpPriv.h"
#include "src/core/SkClipStack.h"
@ -452,6 +451,13 @@ void SkSVGDevice::AutoElement::addColorFilterResources(const SkColorFilter& cf,
resources->fColorFilter.printf("url(#%s)", colorfilterID.c_str());
}
namespace {
bool is_png(const void* bytes, size_t length) {
constexpr uint8_t kPngSig[] = { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
return length >= sizeof(kPngSig) && !memcmp(bytes, kPngSig, sizeof(kPngSig));
}
}
// Returns data uri from bytes.
// it will use any cached data if available, otherwise will
// encode as png.
@ -461,22 +467,28 @@ sk_sp<SkData> AsDataUri(SkImage* image) {
return nullptr;
}
const char* src = (char*)imageData->data();
const char* selectedPrefix = nullptr;
size_t selectedPrefixLength = 0;
const static char pngDataPrefix[] = "data:image/png;base64,";
const static char jpgDataPrefix[] = "data:image/jpeg;base64,";
if (SkJpegCodec::IsJpeg(src, imageData->size())) {
#ifdef SK_CODEC_DECODES_JPEG
if (SkJpegCodec::IsJpeg(imageData->data(), imageData->size())) {
const static char jpgDataPrefix[] = "data:image/jpeg;base64,";
selectedPrefix = jpgDataPrefix;
selectedPrefixLength = sizeof(jpgDataPrefix);
} else {
if (!SkPngCodec::IsPng(src, imageData->size())) {
imageData = image->encodeToData(SkEncodedImageFormat::kPNG, 100);
}
selectedPrefix = pngDataPrefix;
selectedPrefixLength = sizeof(pngDataPrefix);
}
else
#endif
{
if (!is_png(imageData->data(), imageData->size())) {
#ifdef SK_ENCODE_PNG
imageData = image->encodeToData(SkEncodedImageFormat::kPNG, 100);
#else
return nullptr;
#endif
}
const static char pngDataPrefix[] = "data:image/png;base64,";
selectedPrefix = pngDataPrefix;
selectedPrefixLength = sizeof(pngDataPrefix);
}
size_t b64Size = SkBase64::Encode(imageData->data(), imageData->size(), nullptr);