15#ifdef SK_BUILD_FOR_MAC
16#include <ApplicationServices/ApplicationServices.h>
19#ifdef SK_BUILD_FOR_IOS
20#include <CoreGraphics/CoreGraphics.h>
21#include <ImageIO/ImageIO.h>
22#include <MobileCoreServices/MobileCoreServices.h>
28 ImageGeneratorCG(
const SkImageInfo&, SkUniqueCFRef<CGImageSourceRef> imageSrc,
37 const SkUniqueCFRef<CGImageSourceRef> fImageSrc;
44static SkUniqueCFRef<CGImageSourceRef> data_to_CGImageSrc(
SkData*
data) {
45 SkUniqueCFRef<CGDataProviderRef> cgData(
46 CGDataProviderCreateWithData(
data,
data->data(),
data->size(),
nullptr));
50 return SkUniqueCFRef<CGImageSourceRef>(
51 CGImageSourceCreateWithDataProvider(cgData.get(),
nullptr));
56std::unique_ptr<SkImageGenerator> SkImageGeneratorCG::MakeFromEncodedCG(
sk_sp<SkData> data) {
57 SkUniqueCFRef<CGImageSourceRef> imageSrc = data_to_CGImageSrc(
data.get());
62 SkUniqueCFRef<CFDictionaryRef> properties(
63 CGImageSourceCopyPropertiesAtIndex(imageSrc.get(), 0,
nullptr));
68 CFNumberRef widthRef =
static_cast<CFNumberRef
>(
69 CFDictionaryGetValue(properties.get(), kCGImagePropertyPixelWidth));
70 CFNumberRef heightRef =
static_cast<CFNumberRef
>(
71 CFDictionaryGetValue(properties.get(), kCGImagePropertyPixelHeight));
72 if (
nullptr == widthRef ||
nullptr == heightRef) {
77 if (!CFNumberGetValue(widthRef , kCFNumberIntType, &
width ) ||
78 !CFNumberGetValue(heightRef, kCFNumberIntType, &
height))
83 bool hasAlpha = bool(CFDictionaryGetValue(properties.get(), kCGImagePropertyHasAlpha));
88 CFNumberRef orientationRef =
static_cast<CFNumberRef
>(
89 CFDictionaryGetValue(properties.get(), kCGImagePropertyOrientation));
91 if (orientationRef && CFNumberGetValue(orientationRef, kCFNumberIntType, &originInt)) {
103 return std::unique_ptr<SkImageGenerator>(
new ImageGeneratorCG(
info, std::move(imageSrc),
104 std::move(
data), origin));
107ImageGeneratorCG::ImageGeneratorCG(
const SkImageInfo&
info, SkUniqueCFRef<CGImageSourceRef>
src,
110 , fImageSrc(
std::move(
src))
119bool ImageGeneratorCG::onGetPixels(
const SkImageInfo&
info,
void* pixels,
size_t rowBytes,
122 if (kN32_SkColorType !=
info.colorType()) {
127 switch (
info.alphaType()) {
139 SkUniqueCFRef<CGImageRef>
image(CGImageSourceCreateImageAtIndex(fImageSrc.get(), 0,
nullptr));
154 return SkCopyPixelsFromCGImage(pm,
image.
get());
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kOpaque_SkAlphaType
pixel is opaque
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kDefault_SkEncodedOrigin
static bool SkEncodedOriginSwapsWidthHeight(SkEncodedOrigin origin)
#define INHERITED(method,...)
SkImageGenerator(const SkImageInfo &info, uint32_t uniqueId=kNeedNewImageUniqueID)
virtual sk_sp< SkData > onRefEncodedData()
virtual bool onGetPixels(const SkImageInfo &, void *, size_t, const Options &)
SK_API bool Orient(const SkPixmap &dst, const SkPixmap &src, SkEncodedOrigin origin)
SK_API SkImageInfo SwapWidthHeight(const SkImageInfo &info)
sk_sp< const SkImage > image
static DecodeResult decode(std::string path)
static SkImageInfo MakeS32(int width, int height, SkAlphaType at)
std::shared_ptr< const fml::Mapping > data