예제 #1
0
파일: image.cpp 프로젝트: alilloyd/livecode
bool MCGImageHasPartialTransparency(MCGImageRef self)
{
	if (self == nil)
		return false;

	if (self->bitmap->isOpaque())
		return false;

	MCGRaster t_raster;
	/* UNCHECKED */ MCGImageGetRaster(self, t_raster);

	if (t_raster.format == kMCGRasterFormat_A)
		return true;

	uint8_t *t_row_ptr;
	t_row_ptr = (uint8_t*)t_raster.pixels;

	for (uint32_t y = 0; y < t_raster.height; y++)
	{
		uint32_t *t_pixel_ptr;
		t_pixel_ptr = (uint32_t*)t_row_ptr;
		for (uint32_t x = 0; x < t_raster.width; x++)
		{
			uint8_t t_alpha;
			t_alpha = MCGPixelGetNativeAlpha(*t_pixel_ptr++);
			if (t_alpha > 0 && t_alpha < 255)
				return true;
		}

		t_row_ptr += t_raster.stride;
	}

	return false;
}
예제 #2
0
bool MCGImageImageRep::EnsureBitmap()
{
	if (m_bitmap != nil)
		return true;
	
	bool t_success;
	t_success = true;
	
	MCGRaster t_raster;
	if (t_success)
		t_success = MCGImageGetRaster(m_frame.image, t_raster);
	
	MCImageBitmap *t_bitmap;
	t_bitmap = nil;
	
	if (t_success)
		t_success = MCImageBitmapCreateWithPixels(t_raster.pixels, t_raster.stride, t_raster.width, t_raster.height, t_bitmap);
	
	if (t_success)
	{
		t_bitmap->has_alpha = t_bitmap->has_transparency = t_raster.format == kMCGRasterFormat_ARGB;
		
		if (t_bitmap->has_transparency)
			MCImageBitmapUnpremultiply(t_bitmap);
	}
	
	if (t_success)
		m_bitmap = t_bitmap;
	
	return t_success;
}
예제 #3
0
bool MCGImageCreateCGDataProvider(MCGImageRef p_src, const MCGIntegerRectangle &p_src_rect, CGDataProviderRef &r_data_provider)
{
	MCAssert(p_src_rect.origin.x >= 0 && p_src_rect.origin.y >= 0);
	MCAssert(p_src_rect.origin.x + p_src_rect.size.width <= (uint32_t)MCGImageGetWidth(p_src));
	MCAssert(p_src_rect.origin.y + p_src_rect.size.height <= (uint32_t)MCGImageGetHeight(p_src));
	
	bool t_success = true;
	
	MCGRaster t_raster;
	if (t_success)
		t_success = MCGImageGetRaster(p_src, t_raster);
	
	CGDataProviderRef t_data_provider;
	t_data_provider = nil;
	
	if (t_success)
	{
		const void *t_src_ptr;
		t_src_ptr = MCGRasterGetPixelPtr(t_raster, p_src_rect.origin.x, p_src_rect.origin.y);
		
		t_data_provider = CGDataProviderCreateWithData(p_src, t_src_ptr, p_src_rect.size.height * t_raster.stride, MCGImageDataProviderReleaseDataCallback);
		t_success = t_data_provider != nil;
	}
	
	if (t_success)
	{
		MCGImageRetain(p_src);
		r_data_provider = t_data_provider;
	}
	
	return t_success;
}
예제 #4
0
bool MCGImageToCGImage(MCGImageRef p_src, MCGRectangle p_src_rect, CGColorSpaceRef p_colorspace, bool p_copy, bool p_invert, CGImageRef &r_image)
{
	MCGRaster t_raster;
	
	if (!MCGImageGetRaster(p_src, t_raster))
		return false;
	
	return MCGRasterToCGImage(t_raster, p_src_rect, p_colorspace, p_copy, p_invert, r_image);
}
예제 #5
0
파일: image.cpp 프로젝트: alilloyd/livecode
bool MCGImageGetPixel(MCGImageRef p_image, uint32_t x, uint32_t y, uint32_t &r_pixel)
{
	MCGRaster t_raster;
	if (!MCGImageGetRaster(p_image, t_raster) || x >= t_raster.width || y >= t_raster.height)
		return false;

	uint8_t* t_row_ptr;
	t_row_ptr = ((uint8_t*)t_raster.pixels) + y * t_raster.stride;

	if (t_raster.format == kMCGRasterFormat_A)
		r_pixel = t_row_ptr[x];
	else
		r_pixel = ((uint32_t*)t_row_ptr)[x];

	return true;
}
예제 #6
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;
}