9#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
24static CGBitmapInfo compute_cgalpha_info_rgba(
SkAlphaType at) {
25 CGBitmapInfo
info = kCGBitmapByteOrder32Big;
35static CGBitmapInfo compute_cgalpha_info_bgra(
SkAlphaType at) {
36 CGBitmapInfo
info = kCGBitmapByteOrder32Little;
45static CGBitmapInfo compute_cgalpha_info_4444(
SkAlphaType at) {
46 CGBitmapInfo
info = kCGBitmapByteOrder16Little;
49 default:
info |= kCGImageAlphaPremultipliedLast;
break;
56 size_t* bitsPerComponent,
62 switch (skColorType) {
68 *bitsPerComponent = 8;
72 *bitsPerComponent = 8;
73 *
info = compute_cgalpha_info_rgba(skAlphaType);
76 *bitsPerComponent = 8;
77 *
info = compute_cgalpha_info_bgra(skAlphaType);
80 *bitsPerComponent = 4;
81 *
info = compute_cgalpha_info_4444(skAlphaType);
89static std::unique_ptr<SkBitmap> prepare_for_image_ref(
const SkBitmap& bm,
90 size_t* bitsPerComponent,
104 return std::make_unique<SkBitmap>(bm);
107CGImageRef SkCreateCGImageRefWithColorspace(
const SkBitmap& bm,
108 CGColorSpaceRef colorSpace) {
109 return SkCreateCGImageRef(bm);
112CGImageRef SkCreateCGImageRef(
const SkBitmap& bm) {
119 std::unique_ptr<SkBitmap>
bitmap = prepare_for_image_ref(bm, &bitsPerComponent, &
info);
125 const size_t s =
bitmap->computeByteSize();
126 void* pixels =
bitmap->getPixels();
129 SkUniqueCFRef<CGDataProviderRef> dataRef(CGDataProviderCreateWithData(
131 [](
void*
p,
const void*,
size_t) { delete reinterpret_cast<SkBitmap*>(p); }));
133 SkUniqueCFRef<CGColorSpaceRef> colorSpace(SkCreateCGColorSpace(bm.
colorSpace()));
134 return CGImageCreate(pm.
width(),
144 kCGRenderingIntentDefault);
147void SkCGDrawBitmap(CGContextRef cg,
const SkBitmap& bm,
float x,
float y) {
148 SkUniqueCFRef<CGImageRef> img(SkCreateCGImageRef(bm));
151 CGRect r = CGRectMake(0, 0, bm.
width(), bm.
height());
153 CGContextSaveGState(cg);
154 CGContextTranslateCTM(cg,
x, r.size.height +
y);
155 CGContextScaleCTM(cg, 1, -1);
157 CGContextDrawImage(cg, r, img.get());
159 CGContextRestoreGState(cg);
165CGContextRef SkCreateCGContext(
const SkPixmap& pmap) {
166 CGBitmapInfo cg_bitmap_info = 0;
167 size_t bitsPerComponent = 0;
170 bitsPerComponent = 8;
171 cg_bitmap_info = compute_cgalpha_info_rgba(pmap.
alphaType());
174 bitsPerComponent = 8;
175 cg_bitmap_info = compute_cgalpha_info_bgra(pmap.
alphaType());
182 SkUniqueCFRef<CGColorSpaceRef> cs(SkCreateCGColorSpace(pmap.
colorSpace()));
184 bitsPerComponent, rb, cs.get(), cg_bitmap_info);
188bool SkCopyPixelsFromCGImage(
const SkImageInfo&
info,
size_t rowBytes,
void* pixels,
190 CGBitmapInfo cg_bitmap_info = 0;
191 size_t bitsPerComponent = 0;
192 switch (
info.colorType()) {
194 bitsPerComponent = 8;
195 cg_bitmap_info = compute_cgalpha_info_rgba(
info.alphaType());
198 bitsPerComponent = 8;
199 cg_bitmap_info = compute_cgalpha_info_bgra(
info.alphaType());
205 SkUniqueCFRef<CGColorSpaceRef> cs(SkCreateCGColorSpace(
info.colorSpace()));
206 SkUniqueCFRef<CGContextRef> cg(CGBitmapContextCreate(
207 pixels,
info.width(),
info.height(), bitsPerComponent,
208 rowBytes, cs.get(), cg_bitmap_info));
215 CGContextSetBlendMode(cg.get(), kCGBlendModeCopy);
217 CGContextDrawImage(cg.get(), CGRectMake(0, 0,
info.width(),
info.height()),
image);
236 CGImageAlphaInfo cgInfo = CGImageGetAlphaInfo(
image);
238 case kCGImageAlphaNone:
239 case kCGImageAlphaNoneSkipLast:
240 case kCGImageAlphaNoneSkipFirst:
257 if (!SkCreateBitmapFromCGImage(&bm,
src)) {
270 CGDataProviderRef
result = CGDataProviderCreateWithData(
271 data.get(),
data->data(),
data->size(), [](
void*
info,
const void*,
size_t) {
272 reinterpret_cast<SkData*>(info)->unref();
289 SkUniqueCFRef<CFStringRef>
name(CGColorSpaceCopyName(cgColorSpace));
290 if (
name && CFStringCompare(
name.get(), kCGColorSpaceSRGB, 0) == kCFCompareEqualTo) {
295 SkUniqueCFRef<CFDataRef> iccData(CGColorSpaceCopyICCData(cgColorSpace));
301 CFDataGetBytePtr(iccData.get()), CFDataGetLength(iccData.get()), &iccProfile)) {
307CGColorSpaceRef SkCreateCGColorSpace(
const SkColorSpace* space) {
309 CGColorSpaceRef cgSRGB = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
312 if (!space || space->
isSRGB()) {
327 const size_t kNumComponents = 3;
328 const CGFloat kComponentRanges[6] = {0, 1, 0, 1, 0, 1};
329 SkUniqueCFRef<CGDataProviderRef> iccDataProvider(SkCreateCGDataProvider(iccData));
330 CGColorSpaceRef
result = CGColorSpaceCreateICCBased(
331 kNumComponents, kComponentRanges, iccDataProvider.get(), cgSRGB);
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
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
SK_API sk_sp< SkData > SkWriteICCProfile(const skcms_TransferFunction &, const skcms_Matrix3x3 &toXYZD50)
#define SK_INIT_TO_AVOID_WARNING
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
constexpr int SkToInt(S x)
SkColorSpace * colorSpace() const
sk_sp< SkImage > asImage() const
SkAlphaType alphaType() const
SkColorType colorType() const
bool drawsNothing() const
const SkImageInfo & info() const
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const
static bool ComputeIsOpaque(const SkBitmap &bm)
bool setAlphaType(SkAlphaType alphaType)
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
bool toXYZD50(skcms_Matrix3x3 *toXYZD50) const
static sk_sp< SkColorSpace > MakeSRGB()
void transferFn(float gabcdef[7]) const
static sk_sp< SkColorSpace > Make(const skcms_ICCProfile &)
SkColorType colorType() const
SkColorSpace * colorSpace() const
const SkImageInfo & info() const
void * writable_addr() const
const void * addr() const
SkAlphaType alphaType() const
sk_sp< const SkImage > image
DEF_SWITCHES_START aot vmservice shared library name
static bool skcms_Parse(const void *buf, size_t len, skcms_ICCProfile *profile)
static SkImageInfo MakeN32Premul(int width, int height)
int bytesPerPixel() const
SkImageInfo makeColorType(SkColorType newColorType) const
std::shared_ptr< const fml::Mapping > data