CGImageRef ImageSource::createFrameAtIndex(size_t index, SubsamplingLevel subsamplingLevel) { if (!initialized()) return 0; RetainPtr<CGImageRef> image = adoptCF(CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions(SkipMetadata, subsamplingLevel))); #if PLATFORM(IOS) // <rdar://problem/7371198> - CoreGraphics changed the default caching behaviour in iOS 4.0 to kCGImageCachingTransient // which caused a performance regression for us since the images had to be resampled/recreated every time we called // CGContextDrawImage. We now tell CG to cache the drawn images. See also <rdar://problem/14366755> - // CoreGraphics needs to un-deprecate kCGImageCachingTemporary since it's still not the default. #if COMPILER(CLANG) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif CGImageSetCachingFlags(image.get(), kCGImageCachingTemporary); #if COMPILER(CLANG) #pragma clang diagnostic pop #endif #endif // !PLATFORM(IOS) CFStringRef imageUTI = CGImageSourceGetType(m_decoder); static const CFStringRef xbmUTI = CFSTR("public.xbitmap-image"); if (!imageUTI || !CFEqual(imageUTI, xbmUTI)) return image.leakRef(); // If it is an xbm image, mask out all the white areas to render them transparent. const CGFloat maskingColors[6] = {255, 255, 255, 255, 255, 255}; RetainPtr<CGImageRef> maskedImage = adoptCF(CGImageCreateWithMaskingColors(image.get(), maskingColors)); if (!maskedImage) return image.leakRef(); return maskedImage.leakRef(); }
CGImageRef ImageSource::createFrameAtIndex(size_t index, float* scale) { UNUSED_PARAM(scale); if (!initialized()) return 0; #if !PLATFORM(IOS) UNUSED_PARAM(scale); RetainPtr<CGImageRef> image = adoptCF(CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions(SkipMetadata))); #else // Subsampling can be 1, 2 or 3, which means quarter-, sixteenth- and sixty-fourth-size, respectively. // A zero or negative value means no subsampling. int subsampling = scale ? static_cast<int>(log2f(1.0f / std::max(0.1f, std::min(1.0f, *scale)))) : -1; RetainPtr<CGImageRef> image = adoptCF(CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions(SkipMetadata, subsampling))); // <rdar://problem/7371198> - CoreGraphics changed the default caching behaviour in iOS 4.0 to kCGImageCachingTransient // which caused a performance regression for us since the images had to be resampled/recreated every time we called // CGContextDrawImage. We now tell CG to cache the drawn images. See also <rdar://problem/14366755> - // CoreGraphics needs to un-deprecate kCGImageCachingTemporary since it's still not the default. #if COMPILER(CLANG) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif CGImageSetCachingFlags(image.get(), kCGImageCachingTemporary); #if COMPILER(CLANG) #pragma clang diagnostic pop #endif if (scale) { if (subsampling > 0) *scale = static_cast<float>(CGImageGetWidth(image.get())) / size(DoNotRespectImageOrientation).width(); else { ASSERT(static_cast<int>(CGImageGetWidth(image.get())) == size(DoNotRespectImageOrientation).width()); *scale = 1; } } #endif // !PLATFORM(IOS) CFStringRef imageUTI = CGImageSourceGetType(m_decoder); static const CFStringRef xbmUTI = CFSTR("public.xbitmap-image"); if (!imageUTI || !CFEqual(imageUTI, xbmUTI)) return image.leakRef(); // If it is an xbm image, mask out all the white areas to render them transparent. const CGFloat maskingColors[6] = {255, 255, 255, 255, 255, 255}; RetainPtr<CGImageRef> maskedImage = adoptCF(CGImageCreateWithMaskingColors(image.get(), maskingColors)); if (!maskedImage) return image.leakRef(); return maskedImage.leakRef(); }
CGImageRef ImageSource::createFrameAtIndex(size_t index) { if (!initialized()) return 0; RetainPtr<CGImageRef> image(AdoptCF, CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions())); CFStringRef imageUTI = CGImageSourceGetType(m_decoder); static const CFStringRef xbmUTI = CFSTR("public.xbitmap-image"); if (!imageUTI || !CFEqual(imageUTI, xbmUTI)) return image.releaseRef(); // If it is an xbm image, mask out all the white areas to render them transparent. const CGFloat maskingColors[6] = {255, 255, 255, 255, 255, 255}; RetainPtr<CGImageRef> maskedImage(AdoptCF, CGImageCreateWithMaskingColors(image.get(), maskingColors)); if (!maskedImage) return image.releaseRef(); return maskedImage.releaseRef(); }
NativeImagePtr ImageDecoder::createFrameImageAtIndex(size_t index, SubsamplingLevel subsamplingLevel, DecodingMode decodingMode) const { LOG(Images, "ImageDecoder %p createFrameImageAtIndex %lu", this, index); RetainPtr<CFDictionaryRef> options = imageSourceOptions(subsamplingLevel, decodingMode); RetainPtr<CGImageRef> image; if (decodingMode == DecodingMode::OnDemand) image = adoptCF(CGImageSourceCreateImageAtIndex(m_nativeDecoder.get(), index, options.get())); else image = adoptCF(CGImageSourceCreateThumbnailAtIndex(m_nativeDecoder.get(), index, options.get())); #if PLATFORM(IOS) // <rdar://problem/7371198> - CoreGraphics changed the default caching behaviour in iOS 4.0 to kCGImageCachingTransient // which caused a performance regression for us since the images had to be resampled/recreated every time we called // CGContextDrawImage. We now tell CG to cache the drawn images. See also <rdar://problem/14366755> - // CoreGraphics needs to un-deprecate kCGImageCachingTemporary since it's still not the default. #if COMPILER(CLANG) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif CGImageSetCachingFlags(image.get(), kCGImageCachingTemporary); #if COMPILER(CLANG) #pragma clang diagnostic pop #endif #endif // PLATFORM(IOS) CFStringRef imageUTI = CGImageSourceGetType(m_nativeDecoder.get()); static const CFStringRef xbmUTI = CFSTR("public.xbitmap-image"); if (!imageUTI) return image; if (!CFEqual(imageUTI, xbmUTI)) return image; // If it is an xbm image, mask out all the white areas to render them transparent. const CGFloat maskingColors[6] = {255, 255, 255, 255, 255, 255}; RetainPtr<CGImageRef> maskedImage = adoptCF(CGImageCreateWithMaskingColors(image.get(), maskingColors)); return maskedImage ? maskedImage : image; }
void VPictureData_MacPicture::_CreateTransparent(VPictureDrawSettings* inSet)const { CGImageRef result = 0; if (fTrans) return; VPictureDrawSettings set(inSet); if (GetWidth() && GetHeight()) { if (fMetaFile) { CGContextRef context = NULL; CGColorSpaceRef colorSpace; void * bitmapData; int bitmapByteCount; int bitmapBytesPerRow; sLONG width, height; CGRect cgr = QDPictGetBounds(fMetaFile); width = cgr.size.width; height = cgr.size.height; bitmapBytesPerRow = (4 * width + 15) & ~15; bitmapByteCount = (bitmapBytesPerRow * height); bitmapData = malloc(bitmapByteCount); if (bitmapData) { colorSpace = CGColorSpaceCreateDeviceRGB();//CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); memset(bitmapData, 0, bitmapByteCount); context = CGBitmapContextCreate(bitmapData, width, height, 8, // bits per component bitmapBytesPerRow, colorSpace, kCGImageAlphaNoneSkipLast); if (context) { CGRect vr; vr.origin.x = 0; vr.origin.y = 0; vr.size.width = width; vr.size.height = height; VRect pictrect(0, 0, width, height); set.SetScaleMode(PM_SCALE_TO_FIT); set.SetYAxisSwap(height, true); set.SetPictureMatrix(VAffineTransform()); CGContextSaveGState(context); CGContextSetRGBFillColor(context, 1, 1, 1, 1); CGContextFillRect(context, vr); xDraw(fMetaFile, context, pictrect, &set); CGContextRestoreGState(context); CGDataProviderRef dataprov = xV4DPicture_MemoryDataProvider::CGDataProviderCreate((char*) bitmapData, bitmapByteCount, true); result = CGImageCreate(width, height, 8, 32, bitmapBytesPerRow, colorSpace, kCGImageAlphaNoneSkipLast, dataprov, 0, 0, kCGRenderingIntentDefault); CGContextRelease(context); CGDataProviderRelease(dataprov); if (set.GetDrawingMode() == 1) { const VColor& col = set.GetTransparentColor(); CGFloat MaskingColors[6]; MaskingColors[0] = col.GetRed(); MaskingColors[1] = col.GetGreen(); MaskingColors[2] = col.GetBlue(); MaskingColors[3] = col.GetRed(); MaskingColors[4] = col.GetGreen(); MaskingColors[5] = col.GetBlue(); CGImageRef trans = CGImageCreateWithMaskingColors(result, MaskingColors); if (trans) { CFRelease(result); fTrans = trans; } } } CGColorSpaceRelease(colorSpace); } free(bitmapData); } } }
CGImageRef CGImageCreateWithMaskingColors_wrap(CGImageRef im, float min1, float max1, float min2, float max2, float min3, float max3, float min4, float max4) { float comps[8] = {min1, max2, min2, max2, min3, max3, min4, max4}; return CGImageCreateWithMaskingColors(im, comps); }