
extern "C" 
{

//------------------------------------------------------------------------------------
// irr::video::IImage wrappers
//
// you cannot create IImages directly.  you must use IVideoDriver::createImage 
// methods.  when you are done with the image, the drop function must be called.
//------------------------------------------------------------------------------------


	void IrrVideo_IImage_del(IImage* img)
	{
		if (img)
			img->drop();
	}
	
	void* IrrVideo_IImage_lock(IImage* img)
	{
		if (img)
			return img->lock();
		else return 0;
	}
	
	void IrrVideo_IImage_unlock(IImage* img)
	{
		if (img)
			img->unlock();
	}
	
	dimension2d<s32>* IrrVideo_IImage_getDimension(IImage* img)
	{
		if (img)
			return new dimension2d<s32>(img->getDimension());
		else
			return 0;
	}
	
	s32 IrrVideo_IImage_getBitsPerPixel(IImage* img)
	{
		if (img)
			return img->getBitsPerPixel();
		else
			return -1;
	}
	
	s32 IrrVideo_IImage_getBytesPerPixel(IImage* img)
	{
		if (img)
			return img->getBytesPerPixel();
		else
			return -1;
	}
	
	s32 IrrVideo_IImage_getImageDataSizeInBytes(IImage* img)
	{
		if (img)
			return img->getImageDataSizeInBytes();
		else
			return -1;
	}
	
	s32 IrrVideo_IImage_getImageDataSizeInPixels(IImage* img)
	{
		if (img)
			return img->getImageDataSizeInPixels();
		else
			return -1;
	}
	
	SColor* IrrVideo_IImage_getPixel(IImage* img,u32 x,u32 y)
	{
		if (img)
			return new SColor(img->getPixel(x,y));
		else
			return 0;
	}
	
	
	s32 IrrVideo_IImage_getColorFormat(IImage* img)
	{
		if (img)
			return img->getColorFormat();
		else
			return -1;
	}
	
	u32 IrrVideo_IImage_getRedMask(IImage* img)
	{
		if (img)
			return img->getRedMask();
		else return 0;
	}
	
	u32 IrrVideo_IImage_getGreenMask(IImage* img)
	{
		if (img)
			return img->getGreenMask();
		else return 0;
	}
	
	u32 IrrVideo_IImage_getBlueMask(IImage* img)
	{
		if (img)
			return img->getBlueMask();
		else return 0;
	}
	
	u32 IrrVideo_IImage_getAlphaMask(IImage* img)
	{
		if (img)
			return img->getAlphaMask();
		else return 0;
	}
	
	u32 IrrVideo_IImage_getPitch(IImage* img)
	{
		if (img)
			return img->getPitch();
		else return 0;
	}

	bool IrrVideo_IImage_drop(IImage* unk)
	{
		if (unk)
			return unk->drop();
		else return 0;
	}
	
	const c8* IrrVideo_IImage_getDebugName(IImage* unk)
	{
		if (unk)
			return unk->getDebugName();
		else return "";
	}
	
	void IrrVideo_IImage_grab(IImage* unk)
	{
		if (unk)
			unk->grab();
	}

	void IrrVideo_IImage_setPixel(IImage* img,u32 x, u32 y, SColor* color, bool blend = false)
	{
		if (img)
			img->setPixel(x, y, *color, blend);
	}
	
	void IrrVideo_IImage_copyToScaling(IImage* img,void* target, u32 width, u32 height, ECOLOR_FORMAT format=ECF_A8R8G8B8, u32 pitch=0)
	{
		if (img)
			img->copyToScaling(target,width,height,format,pitch);
	}
	
	void IrrVideo_IImage_copyToScalingToImage(IImage* img,IImage* target)
	{
		if (img)
			img->copyToScaling(target);
	}

	//! copies this surface into another
	void IrrVideo_IImage_copyToImage(IImage* img, IImage* target, core::position2d<s32>* pos = 0)
	{
		if (img) {
		
			if (!pos) {
				core::position2d<s32> def_pos = core::position2d<s32>(0,0);
				pos = &def_pos;
			}
			
			img->copyTo(target, *pos);
		}
	}

	void IrrVideo_IImage_copyToImageFromPart(IImage* img, IImage* target, core::position2d<s32>* pos, core::rect<s32>* sourceRect, core::rect<s32>* clipRect = 0)
	{
		if (img) {
			img->copyTo(target, *pos, *sourceRect, clipRect);
		}
	}

	void IrrVideo_IImage_copyToWithAlpha(IImage* img, IImage* target, core::position2d<s32>* pos, core::rect<s32>* sourceRect, SColor* color, core::rect<s32>* clipRect = 0)
	{
		if (img)
			img->copyToWithAlpha(target, *pos, *sourceRect, *color, clipRect);
	}

	void IrrVideo_IImage_fill(IImage* img, SColor* color)
	{
		if (img)
			img->fill(*color);
	}
	
	void IrrVideo_IImage_copyToScalingBoxFilter(IImage* img, IImage* target, s32 bias = 0, bool blend = false) 
	{
		if (img)
			img->copyToScalingBoxFilter(target, bias, blend);
	}

	u32 IrrVideo_IImage_getBitsPerPixelFromFormat(IImage* img, const ECOLOR_FORMAT format) 
	{
		if (img)
			return img->getBitsPerPixelFromFormat(format);
		else return 0;
	}
	
	bool IrrVideo_IImage_isRenderTargetOnlyFormat(IImage* img, const ECOLOR_FORMAT format)
	{
		if (img)
			return img->isRenderTargetOnlyFormat(format);
		else return false;
	}
}
