示例#1
0
bool MCGImageToCGImage(MCGImageRef p_src, const MCGIntegerRectangle &p_src_rect, CGColorSpaceRef p_colorspace, bool p_invert, CGImageRef &r_image)
{
	MCGRaster t_raster;
	if (!MCGImageGetRaster(p_src, t_raster))
		return false;
	
	if (p_invert)
	{
		return MCGRasterToCGImage(t_raster, p_src_rect, p_colorspace, true, true, r_image);
	}
	
	// If we don't need to modify the data then create image with data provider that references the MCGImageRef
	bool t_success = true;
	
	CGImageRef t_image = nil;
	CGDataProviderRef t_data_provider = nil;
	
	if (t_success)
		t_success = MCGImageCreateCGDataProvider(p_src, p_src_rect, t_data_provider);
	
	bool t_alpha;
	t_alpha = !MCGImageIsOpaque(p_src);
	
	CGBitmapInfo t_bm_info;
	t_bm_info = MCGPixelFormatToCGBitmapInfo(kMCGPixelFormatNative, t_alpha);
	
	if (t_success)
	{
		t_image = CGImageCreate(p_src_rect.size.width, p_src_rect.size.height, 8, 32, t_raster.stride, p_colorspace, t_bm_info, t_data_provider, nil, true, kCGRenderingIntentDefault);
		t_success = t_image != nil;
	}
	
	CGDataProviderRelease(t_data_provider);
	
	if (t_success)
		r_image = t_image;
	
	return t_success;
}
示例#2
0
bool MCPatternIsOpaque(MCPatternRef p_pattern)
{
	return p_pattern != nil && MCGImageIsOpaque(p_pattern->image);
}