Exemple #1
0
// Should we add type to the parameter list?
// Copies a 1d block of pixels to the buffer pointed to by Data.
ILboolean ilCopyPixels1D(ILimage* image, ILuint XOff, ILuint Width, void *Data)
{
	ILuint	x, c, NewBps, NewOff, PixBpp;
	ILubyte	*Temp = (ILubyte*)Data, *TempData = image->Data;

	if (ilIsEnabled(IL_ORIGIN_SET)) {
		if ((ILenum)ilGetInteger(IL_ORIGIN_MODE) != image->Origin) {
			TempData = iGetFlipped(image);
			if (TempData == NULL)
				return IL_FALSE;
		}
	}

	PixBpp = image->Bpp * image->Bpc;

	if (image->Width < XOff + Width) {
		NewBps = (image->Width - XOff) * PixBpp;
	}
	else {
		NewBps = Width * PixBpp;
	}
	NewOff = XOff * PixBpp;

	for (x = 0; x < NewBps; x += PixBpp) {
		for (c = 0; c < PixBpp; c++) {
			Temp[x + c] = TempData[(x + NewOff) + c];
		}
	}

	if (TempData != image->Data)
		ifree(TempData);

	return IL_TRUE;
}
Exemple #2
0
ILboolean ilSetPixels2D(ILimage* image, ILint XOff, ILint YOff, ILuint Width, ILuint Height, void *Data)
{
	ILuint	c, SkipX = 0, SkipY = 0, NewBps, PixBpp;
	ILint	x, y, NewWidth, NewHeight;
	ILubyte	*Temp = (ILubyte*)Data, *TempData = image->Data;

	if (ilIsEnabled(IL_ORIGIN_SET)) {
		if ((ILenum)ilGetInteger(IL_ORIGIN_MODE) != image->Origin) {
			TempData = iGetFlipped(image);
			if (TempData == NULL)
				return IL_FALSE;
		}
	}

	PixBpp = image->Bpp * image->Bpc;

	if (XOff < 0) {
		SkipX = abs(XOff);
		XOff = 0;
	}
	if (YOff < 0) {
		SkipY = abs(YOff);
		YOff = 0;
	}

	if (image->Width < XOff + Width)
		NewWidth = image->Width - XOff;
	else
		NewWidth = Width;
	NewBps = Width * PixBpp;

	if (image->Height < YOff + Height)
		NewHeight = image->Height - YOff;
	else
		NewHeight = Height;

	NewWidth -= SkipX;
	NewHeight -= SkipY;

	for (y = 0; y < NewHeight; y++) {
		for (x = 0; x < NewWidth; x++) {
			for (c = 0; c < PixBpp; c++) {
				TempData[(y + YOff) * image->Bps + (x + XOff) * PixBpp + c] =
					Temp[(y + SkipY) * NewBps + (x + SkipX) * PixBpp + c];					
			}
		}
	}

	if (TempData != image->Data) {
		ifree(image->Data);
		image->Data = TempData;
	}

	return IL_TRUE;
}
Exemple #3
0
// Copies a 3d block of pixels to the buffer pointed to by Data.
ILboolean ilCopyPixels3D(ILimage* image, ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width, ILuint Height, ILuint Depth, void *Data)
{
	ILuint	x, y, z, c, NewBps, DataBps, NewSizePlane, NewH, NewD, NewXOff, PixBpp;
	ILubyte	*Temp = (ILubyte*)Data, *TempData = image->Data;

	if (ilIsEnabled(IL_ORIGIN_SET)) {
		if ((ILenum)ilGetInteger(IL_ORIGIN_MODE) != image->Origin) {
			TempData = iGetFlipped(image);
			if (TempData == NULL)
				return IL_FALSE;
		}
	}

	PixBpp = image->Bpp * image->Bpc;

	if (image->Width < XOff + Width)
		NewBps = (image->Width - XOff) * PixBpp;
	else
		NewBps = Width * PixBpp;

	if (image->Height < YOff + Height)
		NewH = image->Height - YOff;
	else
		NewH = Height;

	if (image->Depth < ZOff + Depth)
		NewD = image->Depth - ZOff;
	else
		NewD = Depth;

	DataBps = Width * PixBpp;
	NewSizePlane = NewBps * NewH;

	NewXOff = XOff * PixBpp;

	for (z = 0; z < NewD; z++) {
		for (y = 0; y < NewH; y++) {
			for (x = 0; x < NewBps; x += PixBpp) {
				for (c = 0; c < PixBpp; c++) {
					Temp[z * NewSizePlane + y * DataBps + x + c] = 
						TempData[(z + ZOff) * image->SizeOfPlane + (y + YOff) * image->Bps + x + NewXOff + c];
						//TempData[(z + ZOff) * image->SizeOfPlane + (y + YOff) * image->Bps + (x + XOff) * image->Bpp + c];
				}
			}
		}
	}

	if (TempData != image->Data)
		ifree(TempData);

	return IL_TRUE;
}
Exemple #4
0
// Internal function to load a raw image
ILboolean iLoadRawInternal()
{
	if (iCurImage == NULL) {
		ilSetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}


	iCurImage->Width = GetLittleUInt(&iCurImage->io);

	iCurImage->Height = GetLittleUInt(&iCurImage->io);

	iCurImage->Depth = GetLittleUInt(&iCurImage->io);

	iCurImage->Bpp = (ILubyte)iCurImage->io.getc(iCurImage->io.handle);

	if (iCurImage->io.read(iCurImage->io.handle, &iCurImage->Bpc, 1, 1) != 1)
		return IL_FALSE;

	if (!ilTexImage(iCurImage->Width, iCurImage->Height, iCurImage->Depth, iCurImage->Bpp, 0, ilGetTypeBpc(iCurImage->Bpc), NULL)) {
		return IL_FALSE;
	}
	iCurImage->Origin = IL_ORIGIN_LOWER_LEFT;

	// Tries to read the correct amount of data
	if (iCurImage->io.read(iCurImage->io.handle, iCurImage->Data, 1, iCurImage->SizeOfData) < iCurImage->SizeOfData)
		return IL_FALSE;

	if (ilIsEnabled(IL_ORIGIN_SET)) {
		iCurImage->Origin = ilGetInteger(IL_ORIGIN_MODE);
	}
	else {
		iCurImage->Origin = IL_ORIGIN_UPPER_LEFT;
	}

	if (iCurImage->Bpp == 1)
		iCurImage->Format = IL_LUMINANCE;
	else if (iCurImage->Bpp == 3)
		iCurImage->Format = IL_RGB;
	else  // 4
		iCurImage->Format = IL_RGBA;

	return ilFixImage();
}
Exemple #5
0
ILboolean ilSetPixels1D(ILimage* image, ILint XOff, ILuint Width, void *Data)
{
	ILuint	c, SkipX = 0, PixBpp;
	ILint	x, NewWidth;
	ILubyte	*Temp = (ILubyte*)Data, *TempData = image->Data;

	if (ilIsEnabled(IL_ORIGIN_SET)) {
		if ((ILenum)ilGetInteger(IL_ORIGIN_MODE) != image->Origin) {
			TempData = iGetFlipped(image);
			if (TempData == NULL)
				return IL_FALSE;
		}
	}

	PixBpp = image->Bpp * image->Bpc;

	if (XOff < 0) {
		SkipX = abs(XOff);
		XOff = 0;
	}

	if (image->Width < XOff + Width) {
		NewWidth = image->Width - XOff;
	}
	else {
		NewWidth = Width;
	}

	NewWidth -= SkipX;

	for (x = 0; x < NewWidth; x++) {
		for (c = 0; c < PixBpp; c++) {
			TempData[(x + XOff) * PixBpp + c] = Temp[(x + SkipX) * PixBpp + c];
		}
	}

	if (TempData != image->Data) {
		ifree(image->Data);
		image->Data = TempData;
	}

	return IL_TRUE;
}
Exemple #6
0
// Copies a 2d block of pixels to the buffer pointed to by Data.
ILboolean ilCopyPixels2D(ILimage* image, ILuint XOff, ILuint YOff, ILuint Width, ILuint Height, void *Data)
{
	ILuint	x, y, c, NewBps, DataBps, NewXOff, NewHeight, PixBpp;
	ILubyte	*Temp = (ILubyte*)Data, *TempData = image->Data;

	if (ilIsEnabled(IL_ORIGIN_SET)) {
		if ((ILenum)ilGetInteger(IL_ORIGIN_MODE) != image->Origin) {
			TempData = iGetFlipped(image);
			if (TempData == NULL)
				return IL_FALSE;
		}
	}

	PixBpp = image->Bpp * image->Bpc;

	if (image->Width < XOff + Width)
		NewBps = (image->Width - XOff) * PixBpp;
	else
		NewBps = Width * PixBpp;

	if (image->Height < YOff + Height)
		NewHeight = image->Height - YOff;
	else
		NewHeight = Height;

	DataBps = Width * PixBpp;
	NewXOff = XOff * PixBpp;

	for (y = 0; y < NewHeight; y++) {
		for (x = 0; x < NewBps; x += PixBpp) {
			for (c = 0; c < PixBpp; c++) {
				Temp[y * DataBps + x + c] = 
					TempData[(y + YOff) * image->Bps + x + NewXOff + c];
			}
		}
	}

	if (TempData != image->Data)
		ifree(TempData);

	return IL_TRUE;
}
Exemple #7
0
//! Checks whether the mode is disabled.
ILboolean ILAPIENTRY ilIsDisabled(ILenum Mode)
{
    return !ilIsEnabled(Mode);
}
ILboolean ilState::IsEnabled(ILenum Mode)
{
	return ilIsEnabled(Mode);
}
Exemple #9
0
ILboolean ilSetPixels3D(ILimage* image, ILint XOff, ILint YOff, ILint ZOff, ILuint Width, ILuint Height, ILuint Depth, void *Data)
{
	ILuint	SkipX = 0, SkipY = 0, SkipZ = 0, c, NewBps, NewSizePlane, PixBpp;
	ILint	x, y, z, NewW, NewH, NewD;
	ILubyte	*Temp = (ILubyte*)Data, *TempData = image->Data;

	if (ilIsEnabled(IL_ORIGIN_SET)) {
		if ((ILenum)ilGetInteger(IL_ORIGIN_MODE) != image->Origin) {
			TempData = iGetFlipped(image);
			if (TempData == NULL)
				return IL_FALSE;
		}
	}

	PixBpp = image->Bpp * image->Bpc;

	if (XOff < 0) {
		SkipX = abs(XOff);
		XOff = 0;
	}
	if (YOff < 0) {
		SkipY = abs(YOff);
		YOff = 0;
	}
	if (ZOff < 0) {
		SkipZ = abs(ZOff);
		ZOff = 0;
	}

	if (image->Width < XOff + Width)
		NewW = image->Width - XOff;
	else
		NewW = Width;
	NewBps = Width * PixBpp;

	if (image->Height < YOff + Height)
		NewH = image->Height - YOff;
	else
		NewH = Height;

	if (image->Depth < ZOff + Depth)
		NewD = image->Depth - ZOff;
	else
		NewD = Depth;
	NewSizePlane = NewBps * Height;

	NewW -= SkipX;
	NewH -= SkipY;
	NewD -= SkipZ;

	for (z = 0; z < NewD; z++) {
		for (y = 0; y < NewH; y++) {
			for (x = 0; x < NewW; x++) {
				for (c = 0; c < PixBpp; c++) {
					TempData[(z + ZOff) * image->SizeOfPlane + (y + YOff) * image->Bps + (x + XOff) * PixBpp + c] =
						Temp[(z + SkipZ) * NewSizePlane + (y + SkipY) * NewBps + (x + SkipX) * PixBpp + c];
				}
			}
		}
	}

	if (TempData != image->Data) {
		ifree(image->Data);
		image->Data = TempData;
	}

	return IL_TRUE;
}
Exemple #10
0
//@NEXT DestX,DestY,DestZ must be set to ILuint
ILboolean ILAPIENTRY ilBlit(ILuint Source, ILint DestX,  ILint DestY,   ILint DestZ, 
                                           ILuint SrcX,  ILuint SrcY,   ILuint SrcZ,
                                           ILuint Width, ILuint Height, ILuint Depth)
{
	ILuint 		x, y, z, ConvBps, ConvSizePlane;
	ILimage 	*Dest,*Src;
	ILubyte 	*Converted;
	ILuint		DestName = ilGetCurName();
	ILuint		c;
	ILuint		StartX, StartY, StartZ;
	ILboolean	DestFlipped = IL_FALSE;
	ILubyte 	*SrcTemp;
	ILfloat		Back;

	// Check if the desiination image really exists
	if( DestName == 0 || iCurImage == NULL ) {
		ilSetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}
	Dest = iCurImage;
	
	// set the destination image to upper left origin
	if( Dest->Origin == IL_ORIGIN_LOWER_LEFT ) {  // Dest
		DestFlipped = IL_TRUE;
		ilFlipImage();
	}
	//DestOrigin = Dest->Origin;
	ilBindImage(Source);
	
	// Check if the source image really exists
	if( iCurImage == NULL ) {
		ilSetError(IL_INVALID_PARAM);
		return IL_FALSE;
	}
	
	Src = iCurImage;
	
	//@TODO test if coordinates are inside the images (hard limit for source)
	
	// set the source image to upper left origin
	if (Src->Origin == IL_ORIGIN_LOWER_LEFT)
	{
		SrcTemp = iGetFlipped(iCurImage);
		if (SrcTemp == NULL)
		{
			ilBindImage(DestName);
			if (DestFlipped)
				ilFlipImage();
			return IL_FALSE;
		}
	}
	else
	{
		SrcTemp = iCurImage->Data;
	}
	
	// convert source image to match the destination image type and format
	Converted = (ILubyte*)ilConvertBuffer(Src->SizeOfData, Src->Format, Dest->Format, Src->Type, Dest->Type, SrcTemp);
	if (Converted == NULL)
		return IL_FALSE;
	
	ConvBps 	  = Dest->Bpp * Src->Width;
	ConvSizePlane = ConvBps   * Src->Height;
	
	//@NEXT in next version this would have to be removed since Dest* will be unsigned
	StartX = DestX >= 0 ? 0 : -DestX;
	StartY = DestY >= 0 ? 0 : -DestY;
	StartZ = DestZ >= 0 ? 0 : -DestZ;
	
	// Limit the copy of data inside of the destination image
	if (Width  + DestX > Dest->Width)  Width  = Dest->Width  - DestX;
	if (Height + DestY > Dest->Height) Height = Dest->Height - DestY;
	if (Depth  + DestZ > Dest->Depth)  Depth  = Dest->Depth  - DestZ;
	
	//@TODO: non funziona con rgba
	if (Src->Format == IL_RGBA || Src->Format == IL_BGRA || Src->Format == IL_LUMINANCE_ALPHA) {
		const ILuint bpp_without_alpha = Dest->Bpp - 1;
		for (z = 0; z < Depth; z++) {
			for (y = 0; y < Height; y++) {
				for (x = 0; x < Width; x++) {
					const ILuint  SrcIndex  = (z+SrcZ)*ConvSizePlane + (y+SrcY)*ConvBps + (x+SrcX)*Dest->Bpp;
					const ILuint  DestIndex = (z+DestZ)*Dest->SizeOfPlane + (y+DestY)*Dest->Bps + (x+DestX)*Dest->Bpp;
					const ILuint  AlphaIdx = SrcIndex + bpp_without_alpha;
					ILfloat Front = 0;
					
					switch (Dest->Type)
					{
						case IL_BYTE:
						case IL_UNSIGNED_BYTE:
							Front = Converted[AlphaIdx]/((float)IL_MAX_UNSIGNED_BYTE);
							break;
						case IL_SHORT:
						case IL_UNSIGNED_SHORT:
							Front = ((ILshort*)Converted)[AlphaIdx]/((float)IL_MAX_UNSIGNED_SHORT);
							break;
						case IL_INT:
						case IL_UNSIGNED_INT:
							Front = ((ILint*)Converted)[AlphaIdx]/((float)IL_MAX_UNSIGNED_INT);
							break;
						case IL_FLOAT:
							Front = ((ILfloat*)Converted)[AlphaIdx];
							break;
						case IL_DOUBLE:
							Front = (ILfloat)(((ILdouble*)Converted)[AlphaIdx]);
							break;
					}
					Back = 1.0f - Front;
					// In case of Alpha channel, the data is blended. Keeps the original alpha.
					if (ilIsEnabled(IL_BLIT_BLEND)) {
						for (c = 0; c < bpp_without_alpha; c++)
						{
							Dest->Data[DestIndex + c] = 
								(ILubyte)(Converted[SrcIndex + c] * Front
											+ Dest->Data[DestIndex + c] * Back);
						}
					}
					else {
						for (c = 0; c < Dest->Bpp; c++)
						{
							Dest->Data[DestIndex + c] = (ILubyte)(Converted[SrcIndex + c]);
						}
					}
				}
			}
		}
	} else {
		for( z = 0; z < Depth; z++ ) {
			for( y = 0; y < Height; y++ ) {
				for( x = 0; x < Width; x++ ) {
					for( c = 0; c < Dest->Bpp; c++ ) {
						Dest->Data[(z+DestZ)*Dest->SizeOfPlane + (y+DestY)*Dest->Bps + (x+DestX)*Dest->Bpp + c] =
						 Converted[(z+SrcZ)*ConvSizePlane + (y+SrcY)*ConvBps + (x+SrcX)*Dest->Bpp + c];
					}
				}
			}
		}
	}
	
	if (SrcTemp != iCurImage->Data)
		ifree(SrcTemp);
	
	ilBindImage(DestName);
	if (DestFlipped)
		ilFlipImage();
	
	ifree(Converted);
	
	return IL_TRUE;
}