13#include <android/bitmap.h>
14#include <android/data_space.h>
15#include <android/imagedecoder.h>
21 ~ImageGeneratorNDK()
override;
27 const Options& opts)
override;
31 AImageDecoder* fDecoder;
37 bool fPreviouslySetADataSpace;
45 return result == ANDROID_IMAGE_DECODER_SUCCESS;
50 return ok(AImageDecoder_setAndroidBitmapFormat(decoder,
format));
59 auto format =
static_cast<AndroidBitmapFormat
>(
60 AImageDecoderHeaderInfo_getAndroidBitmapFormat(headerInfo));
65 auto dataSpace =
static_cast<ADataSpace
>(AImageDecoderHeaderInfo_getDataSpace(headerInfo));
73std::unique_ptr<SkImageGenerator> SkImageGeneratorNDK::MakeFromEncodedNDK(
sk_sp<SkData> data) {
74 if (!
data)
return nullptr;
76 AImageDecoder* rawDecoder;
77 if (!
ok(AImageDecoder_createFromBuffer(
data->data(),
data->size(), &rawDecoder))) {
81 const AImageDecoderHeaderInfo* headerInfo = AImageDecoder_getHeaderInfo(rawDecoder);
82 int32_t
width = AImageDecoderHeaderInfo_getWidth(headerInfo);
83 int32_t
height = AImageDecoderHeaderInfo_getHeight(headerInfo);
88 SkAlphaType at = AImageDecoderHeaderInfo_getAlphaFlags(headerInfo)
91 return std::unique_ptr<SkImageGenerator>(
92 new ImageGeneratorNDK(imageInfo, std::move(
data), rawDecoder));
96 AImageDecoder* decoder)
100 , fPreviouslySetADataSpace(
false)
105ImageGeneratorNDK::~ImageGeneratorNDK() {
106 AImageDecoder_delete(fDecoder);
110 if (
size != targetSize) {
113 const AImageDecoderHeaderInfo* headerInfo = AImageDecoder_getHeaderInfo(decoder);
114 const char* mimeType = AImageDecoderHeaderInfo_getMimeType(headerInfo);
115 if (0 == strcmp(mimeType,
"image/jpeg")) {
116 bool supported =
false;
117 for (
int sampleSize : { 2, 4, 8 }) {
120 if (
ok(AImageDecoder_computeSampledSize(decoder, sampleSize, &
width, &
height))
126 if (!supported)
return false;
127 }
else if (0 == strcmp(mimeType,
"image/webp")) {
136 return ok(AImageDecoder_setTargetSize(decoder, targetSize.
width(), targetSize.
height()));
139bool ImageGeneratorNDK::onGetPixels(
const SkImageInfo&
info,
void* pixels,
size_t rowBytes,
140 const Options& opts) {
141 if (
auto* cs =
info.colorSpace()) {
145 fPreviouslySetADataSpace =
true;
152 if (fPreviouslySetADataSpace) {
156 const AImageDecoderHeaderInfo* headerInfo = AImageDecoder_getHeaderInfo(fDecoder);
157 const auto defaultDataSpace = AImageDecoderHeaderInfo_getDataSpace(headerInfo);
158 if (defaultDataSpace == ADATASPACE_UNKNOWN) {
161 AImageDecoder* decoder;
162 if (!
ok(AImageDecoder_createFromBuffer(fData->data(), fData->size(), &decoder))) {
165 AImageDecoder_delete(fDecoder);
168 if (!
ok(AImageDecoder_setDataSpace(fDecoder, defaultDataSpace))) {
176 fPreviouslySetADataSpace =
false;
184 switch (
info.alphaType()) {
193 if (!
ok(AImageDecoder_setUnpremultipliedRequired(fDecoder,
true))) {
205 auto byteSize =
info.computeByteSize(rowBytes);
206 switch (AImageDecoder_decodeImage(fDecoder, pixels, rowBytes, byteSize)) {
207 case ANDROID_IMAGE_DECODER_INCOMPLETE:
210 case ANDROID_IMAGE_DECODER_ERROR:
213 case ANDROID_IMAGE_DECODER_SUCCESS:
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kUnknown_SkAlphaType
uninitialized
@ kOpaque_SkAlphaType
pixel is opaque
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
static bool set_android_bitmap_format(AImageDecoder *decoder, SkColorType colorType)
static sk_sp< SkColorSpace > get_default_colorSpace(const AImageDecoderHeaderInfo *headerInfo)
static bool set_target_size(AImageDecoder *decoder, const SkISize &size, const SkISize targetSize)
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static bool ok(int result)
#define INHERITED(method,...)
static sk_sp< SkColorSpace > MakeSRGB()
SkImageGenerator(const SkImageInfo &info, uint32_t uniqueId=kNeedNewImageUniqueID)
virtual sk_sp< SkData > onRefEncodedData()
virtual bool onGetPixels(const SkImageInfo &, void *, size_t, const Options &)
uint32_t uint32_t * format
AndroidBitmapFormat toAndroidBitmapFormat(SkColorType colorType)
ADataSpace toDataSpace(SkColorSpace *cs)
SkColorType toColorType(AndroidBitmapFormat format)
sk_sp< SkColorSpace > toColorSpace(ADataSpace dataSpace)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
static constexpr SkISize Make(int32_t w, int32_t h)
constexpr int32_t width() const
constexpr int32_t height() const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
std::shared_ptr< const fml::Mapping > data