Exemplo n.º 1
0
// Internal function to load a raw image
ILboolean iLoadRawInternal(ILimage* image)
{
	if (image == NULL) {
		il2SetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}


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

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

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

	image->Bpp = (ILubyte)image->io.getc(&image->io);

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

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

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

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

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

	return il2FixImage(image);
}
Exemplo n.º 2
0
// Creates a new ILimage based on the specifications given
ILAPI ILimage* ILAPIENTRY ilNewImage(ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILubyte Bpc)
{
	ILimage *Image;

	if (Bpp == 0 || Bpp > 4) {
		return NULL;
	}

    Image = (ILimage*)ialloc(sizeof(ILimage));
    if (Image == NULL) {
        return NULL;
    }

	if (!ilInitImage (Image, Width, Height, Depth, Bpp, ilGetFormatBpp(Bpp), ilGetTypeBpc(Bpc), NULL)) {
		if (Image->Data != NULL) {
			ifree(Image->Data);
		}
		ifree(Image);
		return NULL;
	}
    
    return Image;
}
Exemplo n.º 3
0
// Internal function to load a raw image
ILboolean iLoadRawInternal()
{
	if (iCurImage == NULL) {
		ilSetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}

	iCurImage->Width = GetLittleUInt();
	iCurImage->Height = GetLittleUInt();
	iCurImage->Depth = GetLittleUInt();
	iCurImage->Bpp = igetc();
	if (iread(&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 (iread(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;

	ilFixImage();

	return IL_TRUE;
}