Example #1
0
ILboolean iCopySubImage(ILimage *Dest, ILimage *Src)
{
    ILimage *DestTemp, *SrcTemp;
    
    DestTemp = Dest;
    SrcTemp = Src;
    
    do {
        ilCopyImageAttr(DestTemp, SrcTemp);
        DestTemp->Data = (ILubyte*)ialloc(SrcTemp->SizeOfData);
        if (DestTemp->Data == NULL) {
            return IL_FALSE;
        }
        memcpy(DestTemp->Data, SrcTemp->Data, SrcTemp->SizeOfData);
        
        if (SrcTemp->Next) {
            DestTemp->Next = (ILimage*)icalloc(1, sizeof(ILimage));
            if (!DestTemp->Next) {
                return IL_FALSE;
            }
        }
        else {
            DestTemp->Next = NULL;
        }
        
        DestTemp = DestTemp->Next;
		SrcTemp = SrcTemp->Next;
    } while (SrcTemp);
    
    return IL_TRUE;
}
Example #2
0
// Sharpens when Factor is in the range [1.0, 2.5].
// Blurs when Factor is in the range [0.0, 1.0].
ILboolean ILAPIENTRY iluSharpen(ILfloat Factor, ILuint Iter)
{
	ILimage	*Blur, *CurImage;  // iluBlur() changes iluCurImage
	ILuint	i;
	
	CurImage = ilGetCurImage();
	if (CurImage == NULL) {
		ilSetError(ILU_ILLEGAL_OPERATION);
		return IL_FALSE;
	}

	Blur = ilNewImage(CurImage->Width, CurImage->Height, CurImage->Depth, CurImage->Bpp, CurImage->Bpc);
	if (Blur == NULL) {
		return IL_FALSE;
	}
	ilCopyImageAttr(Blur, CurImage);

	ilCopyPixels(0, 0, 0, CurImage->Width, CurImage->Height, 1, CurImage->Format, CurImage->Type, Blur->Data);
	ilSetCurImage(Blur);
	iluBlurGaussian(1);

	for (i = 0; i < Iter; i++) {
		iIntExtImg(Blur, CurImage, Factor);
	}

	ilCloseImage(Blur);
	ilSetCurImage(CurImage);

	return IL_TRUE;
}
Example #3
0
// Does not account for converting luminance...
BITMAP* ILAPIENTRY ilutConvertToAlleg(PALETTE Pal)
{
	BITMAP *Bitmap;
	ILimage *TempImage;
	ILuint i = 0, j = 0;

	ilutCurImage = ilGetCurImage();

	if (ilutCurImage == NULL) {
		ilSetError(ILUT_ILLEGAL_OPERATION);
		return NULL;
	}

	// Should be IL_BGR(A), but Djgpp screws up somewhere along the line.
	if (ilutCurImage->Format == IL_RGB || ilutCurImage->Format == IL_RGBA) {
		iluSwapColours();
	}

	if (ilutCurImage->Origin == IL_ORIGIN_LOWER_LEFT)
		iluFlipImage();
	if (ilutCurImage->Type > IL_UNSIGNED_BYTE) {}  // Can't do anything about this right now...
	if (ilutCurImage->Type == IL_BYTE) {}  // Can't do anything about this right now...

	Bitmap = create_bitmap_ex(ilutCurImage->Bpp * 8, ilutCurImage->Width, ilutCurImage->Height);
	if (Bitmap == NULL) {
		return IL_FALSE;
	}
	memcpy(Bitmap->dat, ilutCurImage->Data, ilutCurImage->SizeOfData);

	// Should we make this toggleable?
	if (ilutCurImage->Bpp == 8 && ilutCurImage->Pal.PalType != IL_PAL_NONE) {
		// Use the image's palette if there is one

		// ilConvertPal is destructive to the original image
		// @TODO:  Use new ilCopyPal!!!
		TempImage = ilNewImage(ilutCurImage->Width, ilutCurImage->Height, ilutCurImage->Depth, ilutCurImage->Bpp, 1);
		ilCopyImageAttr(TempImage, ilutCurImage);
		ilSetCurImage(TempImage);

		if (!ilConvertPal(IL_PAL_RGB24)) {
			destroy_bitmap(Bitmap);
			ilSetError(ILUT_ILLEGAL_OPERATION);
			return NULL;
		}

		for (; i < ilutCurImage->Pal.PalSize && i < 768; i += 3, j++) {
			Pal[j].r = TempImage->Pal.Palette[i+0];
			Pal[j].g = TempImage->Pal.Palette[i+1];
			Pal[j].b = TempImage->Pal.Palette[i+2];
			Pal[j].filler = 255;
		}

		ilCloseImage(TempImage);
		ilSetCurImage(ilutCurImage);
	}

	return Bitmap;
}
Example #4
0
ILAPI ILimage* ILAPIENTRY iluScale_(ILimage *Image, ILuint Width, ILuint Height, ILuint Depth)
{
	ILimage	*Scaled, *CurImage, *ToScale;
	ILenum	Format, PalType;

	CurImage = ilGetCurImage();
	Format = Image->Format;
	if (Format == IL_COLOUR_INDEX) {
		ilSetCurImage(Image);
		PalType = Image->Pal.PalType;
		ToScale = iConvertImage(iluCurImage, ilGetPalBaseType(Image->Pal.PalType), iluCurImage->Type);
	}
	else {
		ToScale = Image;
	}

	// So we don't replicate this 3 times (one in each iluScalexD_() function.
	Scaled = (ILimage*)icalloc(1, sizeof(ILimage));
	if (ilCopyImageAttr(Scaled, ToScale) == IL_FALSE) {
		ilCloseImage(Scaled);
		if (ToScale != Image)
			ilCloseImage(ToScale);
		ilSetCurImage(CurImage);
		return NULL;
	}
	if (ilResizeImage(Scaled, Width, Height, Depth, ToScale->Bpp, ToScale->Bpc) == IL_FALSE) {
		ilCloseImage(Scaled);
		if (ToScale != Image)
			ilCloseImage(ToScale);
		ilSetCurImage(CurImage);
		return NULL;
	}
	
	if (Height <= 1 && Image->Height <= 1) {
		iluScale1D_(ToScale, Scaled, Width);
	}
	if (Depth <= 1 && Image->Depth <= 1) {
		iluScale2D_(ToScale, Scaled, Width, Height);
	}
	else {
		iluScale3D_(ToScale, Scaled, Width, Height, Depth);
	}

	if (Format == IL_COLOUR_INDEX) {
		//ilSetCurImage(Scaled);
		//ilConvertImage(IL_COLOUR_INDEX);
		ilSetCurImage(CurImage);
		ilCloseImage(ToScale);
	}

	return Scaled;
}
Example #5
0
//! Copies everything from Src to the current bound image.
ILboolean ILAPIENTRY ilCopyImage(ILuint Src)
{
    ILuint DestName = ilGetCurName();
    ILimage *DestImage = iCurImage, *SrcImage;
    
    if (iCurImage == NULL || DestName == 0) {
        ilSetError(IL_ILLEGAL_OPERATION);
        return IL_FALSE;
    }
    
    ilBindImage(Src);
    SrcImage = iCurImage;
    ilBindImage(DestName);
    ilTexImage(SrcImage->Width, SrcImage->Height, SrcImage->Depth, SrcImage->Bpp, SrcImage->Format, SrcImage->Type, SrcImage->Data);
    ilCopyImageAttr(DestImage, SrcImage);
    
    return IL_TRUE;
}
Example #6
0
// Creates a copy of Src and returns it.
ILAPI ILimage* ILAPIENTRY ilCopyImage_(ILimage *Src)
{
    ILimage *Dest;
    
    if (Src == NULL) {
        ilSetError(IL_INVALID_PARAM);
        return NULL;
    }
    
    Dest = ilNewImage(Src->Width, Src->Height, Src->Depth, Src->Bpp, Src->Bpc);
    if (Dest == NULL) {
        return NULL;
    }
    
    if (ilCopyImageAttr(Dest, Src) == IL_FALSE)
        return NULL;
    
    memcpy(Dest->Data, Src->Data, Src->SizeOfData);
    
    return Dest;
}
Example #7
0
ILuint ILAPIENTRY ilCloneCurImage()
{
    ILuint Id;
    ILimage *CurImage;
    
    if (iCurImage == NULL) {
        ilSetError(IL_ILLEGAL_OPERATION);
        return 0;
    }
    
    ilGenImages(1, &Id);
    if (Id == 0)
        return 0;
    
    CurImage = iCurImage;
    
    ilBindImage(Id);
    ilTexImage(CurImage->Width, CurImage->Height, CurImage->Depth, CurImage->Bpp, CurImage->Format, CurImage->Type, CurImage->Data);
    ilCopyImageAttr(iCurImage, CurImage);
    
    iCurImage = CurImage;
    
    return Id;
}
Example #8
0
ILAPI ILimage* ILAPIENTRY iluRotate_(ILimage *Image, ILfloat Angle)
{
	ILimage		*Rotated = NULL;
	ILuint		x, y, c;
	ILfloat		x0, y0, x1, y1;
	ILfloat		HalfRotW, HalfRotH, HalfImgW, HalfImgH, Cos, Sin;
	ILuint		RotOffset, ImgOffset;
	ILint		XCorner[4], YCorner[4], MaxX, MaxY;
	ILushort	*ShortPtr;
	ILuint		*IntPtr;

	Rotated = (ILimage*)icalloc(1, sizeof(ILimage));
	if (Rotated == NULL)
		return NULL;
	if (ilCopyImageAttr(Rotated, Image) == IL_FALSE) {
		ilCloseImage(Rotated);
		return NULL;
	}
	// Precalculate shit
	HalfImgW = Image->Width / 2.0f;
	HalfImgH = Image->Height / 2.0f;
	Cos = ilCos(Angle);
	Sin = ilSin(Angle);

	// Find where edges are in new image (origin in center).
	XCorner[0] = ilRound(-HalfImgW * Cos - -HalfImgH * Sin);
	YCorner[0] = ilRound(-HalfImgW * Sin + -HalfImgH * Cos);
	XCorner[1] = ilRound(HalfImgW * Cos - -HalfImgH * Sin);
	YCorner[1] = ilRound(HalfImgW * Sin + -HalfImgH * Cos);
	XCorner[2] = ilRound(HalfImgW * Cos - HalfImgH * Sin);
	YCorner[2] = ilRound(HalfImgW * Sin + HalfImgH * Cos);
	XCorner[3] = ilRound(-HalfImgW * Cos - HalfImgH * Sin);
	YCorner[3] = ilRound(-HalfImgW * Sin + HalfImgH * Cos);

	MaxX = 0;  MaxY = 0;
	for (x = 0; x < 4; x++) {
		if (XCorner[x] > MaxX)
			MaxX = XCorner[x];
		if (YCorner[x] > MaxY)
			MaxY = YCorner[x];
	}

	if (ilResizeImage(Rotated, MaxX * 2, MaxY * 2, 1, Image->Bpp, Image->Bpc) == IL_FALSE) {
		ilCloseImage(Rotated);
		return IL_FALSE;
	}

	HalfRotW = Rotated->Width / 2.0f;
	HalfRotH = Rotated->Height / 2.0f;

	ilClearImage_(Rotated);

	ShortPtr = (ILushort*)iluCurImage->Data;
	IntPtr = (ILuint*)iluCurImage->Data;

	//if (iluFilter == ILU_NEAREST) {
	switch (iluCurImage->Bpc)
	{
		case 1:
			for (y = 0; y < Rotated->Height; y++) {
				y0 = y - HalfRotH;
				for (x = 0; x < Rotated->Width; x++) {
					x0 = x - HalfRotW;
					x1 = x0 * Cos - y0 * Sin;
					y1 = x0 * Sin + y0 * Cos;
					x1 += HalfImgW;
					y1 += HalfImgH;

					if (x1 < Image->Width && x1 >= 0 && y1 < Image->Height && y1 >= 0) {
						RotOffset = y * Rotated->Bps + x * Rotated->Bpp;
						ImgOffset = (ILuint)y1 * Image->Bps + (ILuint)x1 * Image->Bpp;
						for (c = 0; c < Image->Bpp; c++) {
							Rotated->Data[RotOffset + c] = Image->Data[ImgOffset + c];
						}
					}
				}
			}
			break;
		case 2:
			Image->Bps /= 2;
			Rotated->Bps /= 2;
			for (y = 0; y < Rotated->Height; y++) {
				y0 = y - HalfRotH;
				for (x = 0; x < Rotated->Width; x++) {
					x0 = x - HalfRotW;
					x1 = x0 * Cos - y0 * Sin;
					y1 = x0 * Sin + y0 * Cos;
					x1 += HalfImgW;
					y1 += HalfImgH;

					if (x1 < Image->Width && x1 >= 0 && y1 < Image->Height && y1 >= 0) {
						RotOffset = y * Rotated->Bps + x * Rotated->Bpp;
						ImgOffset = (ILuint)y1 * Image->Bps + (ILuint)x1 * Image->Bpp;
						for (c = 0; c < Image->Bpp; c++) {
							((ILushort*)(Rotated->Data))[RotOffset + c] = ShortPtr[ImgOffset + c];
						}
					}
				}
			}
			Image->Bps *= 2;
			Rotated->Bps *= 2;
			break;
		case 4:
			Image->Bps /= 4;
			Rotated->Bps /= 4;
			for (y = 0; y < Rotated->Height; y++) {
				y0 = y - HalfRotH;
				for (x = 0; x < Rotated->Width; x++) {
					x0 = x - HalfRotW;
					x1 = x0 * Cos - y0 * Sin;
					y1 = x0 * Sin + y0 * Cos;
					x1 += HalfImgW;
					y1 += HalfImgH;

					if (x1 < Image->Width && x1 >= 0 && y1 < Image->Height && y1 >= 0) {
						RotOffset = y * Rotated->Bps + x * Rotated->Bpp;
						ImgOffset = (ILuint)y1 * Image->Bps + (ILuint)x1 * Image->Bpp;
						for (c = 0; c < Image->Bpp; c++) {
							((ILuint*)(Rotated->Data))[RotOffset + c] = IntPtr[ImgOffset + c];
						}
					}
				}
			}
			Image->Bps *= 4;
			Rotated->Bps *= 4;
			break;
	}
	//}

	return Rotated;
}