当前位置: 首页>>代码示例>>C++>>正文


C++ ialloc函数代码示例

本文整理汇总了C++中ialloc函数的典型用法代码示例。如果您正苦于以下问题:C++ ialloc函数的具体用法?C++ ialloc怎么用?C++ ialloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ialloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetLittleUInt

static ILubyte *GetChannel(PSP_CTX *ctx)
{
	BLOCKHEAD		Block;
	CHANNEL_CHUNK	Channel;
	ILubyte			*CompData, *Data;
	ILuint			ChunkSize, Padding;

	if (SIOread(ctx->io, &Block, 1, sizeof(Block)) != sizeof(Block))
		return NULL;

	if (ctx->Header.MajorVersion == 3) {
		Block.BlockLen = GetLittleUInt(ctx->io);
	}	else {
		UInt(&Block.BlockLen);
	}

	if (Block.HeadID[0] != 0x7E || Block.HeadID[1] != 0x42 ||
		Block.HeadID[2] != 0x4B || Block.HeadID[3] != 0x00) {
			iSetError(IL_ILLEGAL_FILE_VALUE);
			return NULL;
	}
	if (Block.BlockID != PSP_CHANNEL_BLOCK) {
		iSetError(IL_ILLEGAL_FILE_VALUE);
		return NULL;
	}


	if (ctx->Header.MajorVersion >= 4) {
		ChunkSize = GetLittleUInt(ctx->io);
		if (SIOread(ctx->io, &Channel, sizeof(Channel), 1) != 1)
			return NULL;

		Padding = (ChunkSize - 4) - sizeof(Channel);
		if (Padding > 0)
			SIOseek(ctx->io, Padding, IL_SEEK_CUR);
	}
	else {
		if (SIOread(ctx->io, &Channel, sizeof(Channel), 1) != 1)
			return NULL;
	}


	CompData = (ILubyte*)ialloc(Channel.CompLen);
	Data = (ILubyte*)ialloc(ctx->AttChunk.Width * ctx->AttChunk.Height);
	if (CompData == NULL || Data == NULL) {
		ifree(Data);
		ifree(CompData);
		return NULL;
	}

	if (SIOread(ctx->io, CompData, 1, Channel.CompLen) != Channel.CompLen) {
		ifree(CompData);
		ifree(Data);
		return NULL;
	}

	switch (ctx->AttChunk.Compression)
	{
		case PSP_COMP_NONE:
			ifree(Data);
			return CompData;

		case PSP_COMP_RLE:
			if (!UncompRLE(CompData, Data, Channel.CompLen)) {
				ifree(CompData);
				ifree(Data);
				return NULL;
			}
			break;

		default:
			ifree(CompData);
			ifree(Data);
			iSetError(IL_INVALID_FILE_HEADER);
			return NULL;
	}

	ifree(CompData);

	return Data;
}
开发者ID:kolrabi,项目名称:kail,代码行数:81,代码来源:il_psp.c

示例2: ilApplyPal

ILboolean ILAPIENTRY ilApplyPal(ILconst_string FileName)
{
	ILimage		Image, *CurImage = iCurImage;
	ILubyte		*NewData;
	ILuint		*PalInfo, NumColours, NumPix, MaxDist, DistEntry=0, i, j;
	ILint		Dist1, Dist2, Dist3;
	ILboolean	Same;
	ILenum		Origin;
//	COL_CUBE	*Cubes;

    if( iCurImage == NULL || (iCurImage->Format != IL_BYTE || iCurImage->Format != IL_UNSIGNED_BYTE) ) {
    	ilSetError(IL_ILLEGAL_OPERATION);
        return IL_FALSE;
    }

	NewData = (ILubyte*)ialloc(iCurImage->Width * iCurImage->Height * iCurImage->Depth);
	if (NewData == NULL) {
		return IL_FALSE;
	}

	iCurImage = &Image;
	imemclear(&Image, sizeof(ILimage));
	// IL_PAL_RGB24, because we don't want to make parts transparent that shouldn't be.
	if (!ilLoadPal(FileName) || !ilConvertPal(IL_PAL_RGB24)) {
		ifree(NewData);
		iCurImage = CurImage;
		return IL_FALSE;
	}

	NumColours = Image.Pal.PalSize / 3;  // RGB24 is 3 bytes per entry.
	PalInfo = (ILuint*)ialloc(NumColours * sizeof(ILuint));
	if (PalInfo == NULL) {
		ifree(NewData);
		iCurImage = CurImage;
		return IL_FALSE;
	}

	NumPix = CurImage->SizeOfData / ilGetBppFormat(CurImage->Format);
	switch (CurImage->Format)
	{
		case IL_COLOUR_INDEX:
			iCurImage = CurImage;
			if (!ilConvertPal(IL_PAL_RGB24)) {
				ifree(NewData);
				ifree(PalInfo);
				return IL_FALSE;
			}

			NumPix = iCurImage->Pal.PalSize / ilGetBppPal(iCurImage->Pal.PalType);
			for (i = 0; i < NumPix; i++) {
				for (j = 0; j < Image.Pal.PalSize; j += 3) {
					// No need to perform a sqrt.
					Dist1 = (ILint)iCurImage->Pal.Palette[i] - (ILint)Image.Pal.Palette[j];
					Dist2 = (ILint)iCurImage->Pal.Palette[i+1] - (ILint)Image.Pal.Palette[j+1];
					Dist3 = (ILint)iCurImage->Pal.Palette[i+2] - (ILint)Image.Pal.Palette[j+2];
					PalInfo[j / 3] = Dist1 * Dist1 + Dist2 * Dist2 + Dist3 * Dist3;
				}
				MaxDist = UINT_MAX;
				DistEntry = 0;
				for (j = 0; j < NumColours; j++) {
					if (PalInfo[j] < MaxDist) {
						DistEntry = j;
						MaxDist = PalInfo[j];
					}
				}
				iCurImage->Pal.Palette[i] = DistEntry;
			}

			for (i = 0; i < iCurImage->SizeOfData; i++) {
				NewData[i] = iCurImage->Pal.Palette[iCurImage->Data[i]];
			}
			break;
		case IL_RGB:
		case IL_RGBA:
			/*Cube = (COL_CUBE*)ialloc(NumColours * sizeof(COL_CUBE));
			// @TODO:  Check if ialloc failed here!
			for (i = 0; i < NumColours; i++)
				memcpy(&Cubes[i].Val, Image.Pal.Palette[i * 3], 3);
			for (j = 0; j < 3; j++) {
				qsort(Cubes, NumColours, sizeof(COL_CUBE), sort_func);
				Cubes[0].Min = 0;
				Cubes[NumColours-1] = UCHAR_MAX;
				NumColours--;
				for (i = 1; i < NumColours; i++) {
					Cubes[i].Min[CurSort] = Cubes[i-1].Val[CurSort] + 1;
					Cubes[i-1].Max[CurSort] = Cubes[i].Val[CurSort] - 1;
				}
				CurSort++;
				NumColours++;
			}*/
			for (i = 0; i < CurImage->SizeOfData; i += CurImage->Bpp) {
				Same = IL_TRUE;
				if (i != 0) {
					for (j = 0; j < CurImage->Bpp; j++) {
						if (CurImage->Data[i-CurImage->Bpp+j] != CurImage->Data[i+j]) {
							Same = IL_FALSE;
							break;
						}
					}
				}
//.........这里部分代码省略.........
开发者ID:SylviaTanenbaum,项目名称:3d-simulation-and-game,代码行数:101,代码来源:il_pal.c

示例3: add_dir

int
add_dir(DIR *cur_dir, int cur_inode, int parent_inode) {
	int r;
	int child_inode;
	int cur_fd, child_fd;
	struct xv6_dirent de;
	struct dinode din;
	struct dirent dir_buf;
	struct dirent *entry;
	struct stat st;
	int bytes_read;
	char buf[BLOCK_SIZE];
	int off;

	bzero(&de, sizeof(de));
	de.inum = xshort(cur_inode);
	strcpy(de.name, ".");
	iappend(cur_inode, &de, sizeof(de));

	bzero(&de, sizeof(de));
	de.inum = xshort(parent_inode);
	strcpy(de.name, "..");
	iappend(cur_inode, &de, sizeof(de));

	if (cur_dir == NULL) {
		return 0;
	}

	cur_fd = dirfd(cur_dir);
	if (cur_fd == -1){
		perror("add_dir");
		exit(EXIT_FAILURE);
	}

	if (fchdir(cur_fd) != 0){
		perror("add_dir");
		return -1;
	}

	while (true) {
		r = readdir_r(cur_dir, &dir_buf, &entry);

		if (r != 0) {
			perror("add_dir");
			return -1;
		}

		if (entry == NULL)
			break;

		if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
			continue;

		printf("%s\n", entry->d_name);

		child_fd = open(entry->d_name, O_RDONLY);
		if (child_fd == -1) {
			perror("open");
			return -1;
		}

		r = fstat(child_fd, &st);
		if (r != 0) {
			perror("stat");
			return -1;
		}

		if (S_ISDIR(st.st_mode)) {
      child_inode = ialloc(T_DIR);
			r = add_dir(fdopendir(child_fd), child_inode, cur_inode);
			if (r != 0) return r;
			if (fchdir(cur_fd) != 0) {
				perror("chdir");
				return -1;
			}
		} else {
			bytes_read = 0;
	  		child_inode = ialloc(T_FILE);
			bzero(&de, sizeof(de));
			while((bytes_read = read(child_fd, buf, sizeof(buf))) > 0) {
				iappend(child_inode, buf, bytes_read);
			}
		}
		close(child_fd);

		de.inum = xshort(child_inode);
		strncpy(de.name, entry->d_name, DIRSIZ);
		iappend(cur_inode, &de, sizeof(de));

	}

	// fix size of inode cur_dir
	rinode(cur_inode, &din);
	off = xint(din.size);
	off = ((off/BSIZE) + 1) * BSIZE;
	din.size = xint(off);
	winode(cur_inode, &din);
	return 0;
}
开发者ID:guneetsinghmehta,项目名称:CS537_OS,代码行数:99,代码来源:mkfs.c

示例4: ilSavePal

ILboolean ILAPIENTRY ilSavePal(ILconst_string FileName)
{
	ILstring Ext = iGetExtension(FileName);

	if (iCurImage == NULL) {
		ilSetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}

#ifndef _UNICODE
	if (FileName == NULL || strlen(FileName) < 1 || Ext == NULL) {
#else
	if (FileName == NULL || wcslen(FileName) < 1 || Ext == NULL) {
#endif//_UNICODE
		ilSetError(IL_INVALID_PARAM);
		return IL_FALSE;
	}

	if (!iCurImage->Pal.Palette || !iCurImage->Pal.PalSize || iCurImage->Pal.PalType == IL_PAL_NONE) {
		ilSetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}

	if (!iStrCmp(Ext, IL_TEXT("pal"))) {
		return ilSaveJascPal(FileName);
	}

	ilSetError(IL_INVALID_EXTENSION);
	return IL_FALSE;
}


//! Saves a Paint Shop Pro formatted palette (.pal) file.
ILboolean ilSaveJascPal(ILconst_string FileName)
{
	FILE	*PalFile;
	ILuint	i, PalBpp, NumCols = ilGetInteger(IL_PALETTE_NUM_COLS);
	ILubyte	*CurPal;

	if (iCurImage == NULL || NumCols == 0 || NumCols > 256) {
		ilSetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}
	
#ifndef _UNICODE
	if (FileName == NULL || strlen(FileName) < 5) {
#else
	if (FileName == NULL || wcslen(FileName) < 5) {
#endif//_UNICODE
		ilSetError(IL_INVALID_VALUE);
		return IL_FALSE;
	}

	if (!iCheckExtension(FileName, IL_TEXT("pal"))) {
		ilSetError(IL_INVALID_EXTENSION);
		return IL_FALSE;
	}

	if (ilGetBoolean(IL_FILE_MODE) == IL_FALSE) {
		if (iFileExists(FileName)) {
			ilSetError(IL_FILE_ALREADY_EXISTS);
			return IL_FALSE;
		}
	}

	// Create a copy of the current palette and convert it to RGB24 format.
	CurPal = iCurImage->Pal.Palette;
	iCurImage->Pal.Palette = (ILubyte*)ialloc(iCurImage->Pal.PalSize);
	if (!iCurImage->Pal.Palette) {
		iCurImage->Pal.Palette = CurPal;
		return IL_FALSE;
	}

	memcpy(iCurImage->Pal.Palette, CurPal, iCurImage->Pal.PalSize);
	if (!ilConvertPal(IL_PAL_RGB24)) {
		ifree(iCurImage->Pal.Palette);
		iCurImage->Pal.Palette = CurPal;
		return IL_FALSE;
	}

#ifndef _UNICODE
	PalFile = fopen(FileName, "wt");
#else
	PalFile = _wfopen(FileName, L"wt");
#endif//_UNICODE
	if (!PalFile) {
		ilSetError(IL_COULD_NOT_OPEN_FILE);
		return IL_FALSE;
	}

	// Header needed on all .pal files
	fputs("JASC-PAL\n0100\n256\n", PalFile);

	PalBpp = ilGetBppPal(iCurImage->Pal.PalType);
	for (i = 0; i < iCurImage->Pal.PalSize; i += PalBpp) {
		fprintf(PalFile, "%d %d %d\n",
			iCurImage->Pal.Palette[i], iCurImage->Pal.Palette[i+1], iCurImage->Pal.Palette[i+2]);
	}

	NumCols = 256 - NumCols;
//.........这里部分代码省略.........
开发者ID:SylviaTanenbaum,项目名称:3d-simulation-and-game,代码行数:101,代码来源:il_pal.c

示例5: iConvertPal

// Converts the palette to the DestFormat format.
ILAPI ILpal* ILAPIENTRY iConvertPal(ILpal *Pal, ILenum DestFormat)
{
	ILpal	*NewPal = NULL;
	ILuint	i, j, NewPalSize;

	// Checks to see if the current image is valid and has a palette
	if (Pal == NULL || Pal->PalSize == 0 || Pal->Palette == NULL || Pal->PalType == IL_PAL_NONE) {
		ilSetError(IL_ILLEGAL_OPERATION);
		return NULL;
	}

	/*if (Pal->PalType == DestFormat) {
		return NULL;
	}*/

	NewPal = (ILpal*)ialloc(sizeof(ILpal));
	if (NewPal == NULL) {
		return NULL;
	}
	NewPal->PalSize = Pal->PalSize;
	NewPal->PalType = Pal->PalType;

	switch (DestFormat)
	{
		case IL_PAL_RGB24:
		case IL_PAL_BGR24:
			switch (Pal->PalType)
			{
				case IL_PAL_RGB24:
					NewPal->Palette = (ILubyte*)ialloc(Pal->PalSize);
					if (NewPal->Palette == NULL)
						goto alloc_error;
					if (DestFormat == IL_PAL_BGR24) {
						j = ilGetBppPal(Pal->PalType);
						for (i = 0; i < Pal->PalSize; i += j) {
							NewPal->Palette[i] = Pal->Palette[i+2];
							NewPal->Palette[i+1] = Pal->Palette[i+1];
							NewPal->Palette[i+2] = Pal->Palette[i];
						}
					}
					else {
						memcpy(NewPal->Palette, Pal->Palette, Pal->PalSize);
					}
					NewPal->PalType = DestFormat;
					break;

				case IL_PAL_BGR24:
					NewPal->Palette = (ILubyte*)ialloc(Pal->PalSize);
					if (NewPal->Palette == NULL)
						goto alloc_error;
					if (DestFormat == IL_PAL_RGB24) {
						j = ilGetBppPal(Pal->PalType);
						for (i = 0; i < Pal->PalSize; i += j) {
							NewPal->Palette[i] = Pal->Palette[i+2];
							NewPal->Palette[i+1] = Pal->Palette[i+1];
							NewPal->Palette[i+2] = Pal->Palette[i];
						}
					}
					else {
						memcpy(NewPal->Palette, Pal->Palette, Pal->PalSize);
					}
					NewPal->PalType = DestFormat;
					break;

				case IL_PAL_BGR32:
				case IL_PAL_BGRA32:
					NewPalSize = (ILuint)((ILfloat)Pal->PalSize * 3.0f / 4.0f);
					NewPal->Palette = (ILubyte*)ialloc(NewPalSize);
					if (NewPal->Palette == NULL)
						goto alloc_error;
					if (DestFormat == IL_PAL_RGB24) {
						for (i = 0, j = 0; i < Pal->PalSize; i += 4, j += 3) {
							NewPal->Palette[j]   = Pal->Palette[i+2];
							NewPal->Palette[j+1] = Pal->Palette[i+1];
							NewPal->Palette[j+2] = Pal->Palette[i];
						}
					}
					else {
						for (i = 0, j = 0; i < Pal->PalSize; i += 4, j += 3) {
							NewPal->Palette[j]   = Pal->Palette[i];
							NewPal->Palette[j+1] = Pal->Palette[i+1];
							NewPal->Palette[j+2] = Pal->Palette[i+2];
						}
					}
					NewPal->PalSize = NewPalSize;
					NewPal->PalType = DestFormat;
					break;

				case IL_PAL_RGB32:
				case IL_PAL_RGBA32:
					NewPalSize = (ILuint)((ILfloat)Pal->PalSize * 3.0f / 4.0f);
					NewPal->Palette = (ILubyte*)ialloc(NewPalSize);
					if (NewPal->Palette == NULL)
						goto alloc_error;
					if (DestFormat == IL_PAL_RGB24) {
						for (i = 0, j = 0; i < Pal->PalSize; i += 4, j += 3) {
							NewPal->Palette[j]   = Pal->Palette[i];
							NewPal->Palette[j+1] = Pal->Palette[i+1];
							NewPal->Palette[j+2] = Pal->Palette[i+2];
//.........这里部分代码省略.........
开发者ID:SylviaTanenbaum,项目名称:3d-simulation-and-game,代码行数:101,代码来源:il_pal.c

示例6: iLoadPcdInternal

ILboolean iLoadPcdInternal(ILimage* image)
{
	ILubyte	VertOrientation;
	ILuint	Width, Height, i, Total, x, CurPos = 0;
	ILubyte	*Y1=NULL, *Y2=NULL, *CbCr=NULL, r = 0, g = 0, b = 0;
	ILuint	PicNum;

	if (image == NULL) {
		il2SetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}

	image->io.seek(&image->io, 72, IL_SEEK_CUR);
	if (image->io.read(&image->io, &VertOrientation, 1, 1) != 1)
		return IL_FALSE;

	image->io.seek(&image->io, -72, IL_SEEK_CUR);  // Can't rewind

	PicNum = iGetInt(IL_PCD_PICNUM);

	switch (PicNum)
	{
		case 0:
			image->io.seek(&image->io, 0x02000, IL_SEEK_CUR);
			Width = 192;
			Height = 128;
			break;
		case 1:
			image->io.seek(&image->io, 0x0b800, IL_SEEK_CUR);
			Width = 384;
			Height = 256;
			break;
		case 2:
			image->io.seek(&image->io, 0x30000, IL_SEEK_CUR);
			Width = 768;
			Height = 512;
			break;
		default:
			il2SetError(IL_INVALID_PARAM);
			return IL_FALSE;
	}

	if (image->io.tell(&image->io) == IL_EOF)  // Supposed to have data here.
		return IL_FALSE;

	Y1 = (ILubyte*)ialloc(Width);
	Y2 = (ILubyte*)ialloc(Width);
	CbCr = (ILubyte*)ialloc(Width);
	if (Y1 == NULL || Y2 == NULL || CbCr == NULL) {
		ifree(Y1);
		ifree(Y2);
		ifree(CbCr);
		return IL_FALSE;
	}

	if (!il2TexImage(image, Width, Height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, NULL)) {
		return IL_FALSE;
	}
	image->Origin = IL_ORIGIN_LOWER_LEFT;

	Total = Height >> 1;
	for (i = 0; i < Total; i++) {
		image->io.read(&image->io, Y1, 1, Width);
		image->io.read(&image->io, Y2, 1, Width);
		if (image->io.read(&image->io, CbCr, 1, Width) != Width) {  // Only really need to check the last one.
			ifree(Y1);
			ifree(Y2);
			ifree(CbCr);
			return IL_FALSE;
		}

		for (x = 0; x < Width; x++) {
			YCbCr2RGB(Y1[x], CbCr[x / 2], CbCr[(Width / 2) + (x / 2)], &r, &g, &b);
			image->Data[CurPos++] = r;
			image->Data[CurPos++] = g;
			image->Data[CurPos++] = b;
		}

		for (x = 0; x < Width; x++) {
			YCbCr2RGB(Y2[x], CbCr[x / 2], CbCr[(Width / 2) + (x / 2)], &r, &g, &b);
			image->Data[CurPos++] = r;
			image->Data[CurPos++] = g;
			image->Data[CurPos++] = b;
		}
	}

	ifree(Y1);
	ifree(Y2);
	ifree(CbCr);

	// Not sure how it is...the documentation is hard to understand
	if ((VertOrientation & 0x3F) != 8)
		image->Origin = IL_ORIGIN_LOWER_LEFT;
	else
		image->Origin = IL_ORIGIN_UPPER_LEFT;

	return il2FixImage(image);
}
开发者ID:KFreon,项目名称:KFreon_s-ResIL,代码行数:98,代码来源:il_pcd.cpp

示例7: EndianSwapData

ILvoid EndianSwapData(void *_Image) {
	ILuint		i;
	ILubyte		*temp, *s, *d;
	ILushort	*ShortS, *ShortD;
	ILuint		*IntS, *IntD;
	ILfloat		*FltS, *FltD;
	ILdouble	*DblS, *DblD;

	ILimage *Image = (ILimage*)_Image;

	switch (Image->Type) {
		case IL_BYTE:
		case IL_UNSIGNED_BYTE:
			switch (Image->Bpp) {
				case 3:
					temp = ialloc(Image->SizeOfData);
					if (temp == NULL)
						return;
					s = Image->Data;
					d = temp;

					for( i = Image->Width * Image->Height; i > 0; i-- ) {
						*d++ = *(s+2);
						*d++ = *(s+1);
						*d++ = *s;
						s += 3;
					}

					ifree(Image->Data);
					Image->Data = temp;
					break;

				case 4:
					temp = ialloc(Image->SizeOfData);
					if (temp == NULL)
						return;
					s = Image->Data;
					d = temp;

					for (i = Image->Width * Image->Height; i > 0; i--) {
						*d++ = *(s+3);
						*d++ = *(s+2);
						*d++ = *(s+1);
						*d++ = *s;
						s += 4;
					}

					ifree(Image->Data);
					Image->Data = temp;
					break;
			}
			break;

		case IL_SHORT:
		case IL_UNSIGNED_SHORT:
			switch (Image->Bpp) {
				case 3:
					temp = ialloc(Image->SizeOfData);
					if (temp == NULL)
						return;
					ShortS = (ILushort*)Image->Data;
					ShortD = (ILushort*)temp;

					for (i = Image->Width * Image->Height; i > 0; i--) {
						*ShortD = *ShortS++; iSwapUShort(ShortD++);
						*ShortD = *ShortS++; iSwapUShort(ShortD++);
						*ShortD = *ShortS++; iSwapUShort(ShortD++);
					}

					ifree(Image->Data);
					Image->Data = temp;
					break;

				case 4:
					temp = ialloc(Image->SizeOfData);
					if (temp == NULL)
						return;
					ShortS = (ILushort*)Image->Data;
					ShortD = (ILushort*)temp;

					for (i = Image->Width * Image->Height; i > 0; i--) {
						*ShortD = *ShortS++; iSwapUShort(ShortD++);
						*ShortD = *ShortS++; iSwapUShort(ShortD++);
						*ShortD = *ShortS++; iSwapUShort(ShortD++);
						*ShortD = *ShortS++; iSwapUShort(ShortD++);
					}

					ifree(Image->Data);
					Image->Data = temp;
					break;
			}
			break;

		case IL_INT:
		case IL_UNSIGNED_INT:
			switch (Image->Bpp)
			{
				case 3:
					temp = ialloc(Image->SizeOfData);
					if (temp == NULL)
//.........这里部分代码省略.........
开发者ID:aickau,项目名称:spectra-clustering-tool,代码行数:101,代码来源:il_endian.c

示例8: il2GetAlpha

ILAPI ILubyte* ILAPIENTRY il2GetAlpha(ILimage* image, ILenum Type)
{
	ILimage		*TempImage;
	ILubyte		*Alpha;
	ILushort	*AlphaShort;
	ILuint		*AlphaInt;
	ILdouble	*AlphaDbl;
	ILuint		i, j, Bpc, Size, AlphaOff;

	if (image == NULL) {
		il2SetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}

	Bpc = ilGetBpcType(Type);
	if (Bpc == 0) {
		il2SetError(IL_INVALID_PARAM);
		return NULL;
	}

	if (image->Type == Type) {
		TempImage = image;
	} else {
		TempImage = iConvertImage(image, image->Format, Type);
		if (TempImage == NULL)
			return NULL;
	}

	Size = image->Width * image->Height * image->Depth * TempImage->Bpp;
	Alpha = (ILubyte*)ialloc(Size / TempImage->Bpp * Bpc);
	if (Alpha == NULL) {
		if (TempImage != image)
			ilCloseImage(TempImage);
		return NULL;
	}

	switch (TempImage->Format)
	{
		case IL_RGB:
		case IL_BGR:
		case IL_LUMINANCE:
		case IL_COLOUR_INDEX:  // @TODO: Make IL_COLOUR_INDEX separate.
			memset(Alpha, 0xFF, Size / TempImage->Bpp * Bpc);
			if (TempImage != image)
				ilCloseImage(TempImage);
			return Alpha;
	}

	// If our format is alpha, just return a copy.
	if (TempImage->Format == IL_ALPHA) {
		memcpy(Alpha, TempImage->Data, TempImage->SizeOfData);
		return Alpha;
	}
		
	if (TempImage->Format == IL_LUMINANCE_ALPHA)
		AlphaOff = 2;
	else
		AlphaOff = 4;

	switch (TempImage->Type)
	{
		case IL_BYTE:
		case IL_UNSIGNED_BYTE:
			for (i = AlphaOff-1, j = 0; i < Size; i += AlphaOff, j++)
				Alpha[j] = TempImage->Data[i];
			break;

		case IL_SHORT:
		case IL_UNSIGNED_SHORT:
			AlphaShort = (ILushort*)Alpha;
			for (i = AlphaOff-1, j = 0; i < Size; i += AlphaOff, j++)
				AlphaShort[j] = ((ILushort*)TempImage->Data)[i];
			break;

		case IL_INT:
		case IL_UNSIGNED_INT:
		case IL_FLOAT:  // Can throw float in here, because it's the same size.
			AlphaInt = (ILuint*)Alpha;
			for (i = AlphaOff-1, j = 0; i < Size; i += AlphaOff, j++)
				AlphaInt[j] = ((ILuint*)TempImage->Data)[i];
			break;

		case IL_DOUBLE:
			AlphaDbl = (ILdouble*)Alpha;
			for (i = AlphaOff-1, j = 0; i < Size; i += AlphaOff, j++)
				AlphaDbl[j] = ((ILdouble*)TempImage->Data)[i];
			break;
	}

	if (TempImage != image)
		ilCloseImage(TempImage);

	return Alpha;
}
开发者ID:KFreon,项目名称:KFreon_s-ResIL,代码行数:94,代码来源:il_manip.cpp

示例9: iMirror

//@JASON New routine created 28/03/2001
//! Mirrors an image over its y axis
ILboolean ILAPIENTRY iMirror(ILimage* image) {
	ILubyte		*Data, *DataPtr, *Temp;
	ILuint		y, d, PixLine;
	ILint		x, c;
	ILushort	*ShortPtr, *TempShort;
	ILuint		*IntPtr, *TempInt;
	ILdouble	*DblPtr, *TempDbl;

	if (image == NULL) {
		il2SetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}

	Data = (ILubyte*)ialloc(image->SizeOfData);
	if (Data == NULL)
		return IL_FALSE;

	PixLine = image->Bps / image->Bpc;
	switch (image->Bpc)
	{
		case 1:
			Temp = image->Data;
			for (d = 0; d < image->Depth; d++) {
				DataPtr = Data + d * image->SizeOfPlane;
				for (y = 0; y < image->Height; y++) {
					for (x = image->Width - 1; x >= 0; x--) {
						for (c = 0; c < image->Bpp; c++, Temp++) {
							DataPtr[y * PixLine + x * image->Bpp + c] = *Temp;
						}
					}
				}
			}
			break;

		case 2:
			TempShort = (ILushort*)image->Data;
			for (d = 0; d < image->Depth; d++) {
				ShortPtr = (ILushort*)(Data + d * image->SizeOfPlane);
				for (y = 0; y < image->Height; y++) {
					for (x = image->Width - 1; x >= 0; x--) {
						for (c = 0; c < image->Bpp; c++, TempShort++) {
							ShortPtr[y * PixLine + x * image->Bpp + c] = *TempShort;
						}
					}
				}
			}
			break;

		case 4:
			TempInt = (ILuint*)image->Data;
			for (d = 0; d < image->Depth; d++) {
				IntPtr = (ILuint*)(Data + d * image->SizeOfPlane);
				for (y = 0; y < image->Height; y++) {
					for (x = image->Width - 1; x >= 0; x--) {
						for (c = 0; c < image->Bpp; c++, TempInt++) {
							IntPtr[y * PixLine + x * image->Bpp + c] = *TempInt;
						}
					}
				}
			}
			break;

		case 8:
			TempDbl = (ILdouble*)image->Data;
			for (d = 0; d < image->Depth; d++) {
				DblPtr = (ILdouble*)(Data + d * image->SizeOfPlane);
				for (y = 0; y < image->Height; y++) {
					for (x = image->Width - 1; x >= 0; x--) {
						for (c = 0; c < image->Bpp; c++, TempDbl++) {
							DblPtr[y * PixLine + x * image->Bpp + c] = *TempDbl;
						}
					}
				}
			}
			break;
	}

	ifree(image->Data);
	image->Data = Data;

	return IL_TRUE;
}
开发者ID:KFreon,项目名称:KFreon_s-ResIL,代码行数:84,代码来源:il_manip.cpp

示例10: iLoadBlp1

ILboolean iLoadBlp1()
{
    BLP1HEAD	Header;
    ILubyte		*DataAndAlpha, *Palette;
    ILuint		i;
    ILimage		*Image = iCurImage;
    ILboolean	BaseCreated = IL_FALSE;
#ifndef IL_NO_JPG
    ILubyte		*JpegHeader, *JpegData;
    ILuint		JpegHeaderSize;
#endif//IL_NO_JPG

    if (!iGetBlp1Head(&Header))
        return IL_FALSE;
    if (!iCheckBlp1(&Header)) {
        ilSetError(IL_INVALID_FILE_HEADER);
        return IL_FALSE;
    }

    //@TODO: Remove this.
    i = 0;

    switch (Header.Compression)
    {
    case BLP_TYPE_JPG:
#ifdef IL_NO_JPG
        // We can only do the Jpeg decoding if we do not have IL_NO_JPEG defined.
        return IL_FALSE;
#else
        JpegHeaderSize = GetLittleUInt();
        JpegHeader = (ILubyte*)ialloc(JpegHeaderSize);
        if (JpegHeader == NULL)
            return IL_FALSE;
        // Read the shared Jpeg header.
        if (iread(JpegHeader, 1, JpegHeaderSize) != JpegHeaderSize) {
            ifree(JpegHeader);
            return IL_FALSE;
        }

        //for (i = 0; i < 16; i++) {  // Possible maximum of 16 mipmaps
        //@TODO: Check return value?
        iseek(Header.MipOffsets[i], IL_SEEK_SET);
        JpegData = (ILubyte*)ialloc(JpegHeaderSize + Header.MipLengths[i]);
        if (JpegData == NULL) {
            ifree(JpegHeader);
            return IL_FALSE;
        }
        memcpy(JpegData, JpegHeader, JpegHeaderSize);
        if (iread(JpegData + JpegHeaderSize, Header.MipLengths[i], 1) != 1)
            return IL_FALSE;

        // Just send the data straight to the Jpeg loader.
        if (!ilLoadJpegL(JpegData, JpegHeaderSize + Header.MipLengths[i]))
            return IL_FALSE;

        // The image data is in BGR(A) order, even though it is Jpeg-compressed.
        if (Image->Format == IL_RGBA)
            Image->Format = IL_BGRA;
        if (Image->Format == IL_RGB)
            Image->Format = IL_BGR;

        ifree(JpegData);
        //}
        ifree(JpegHeader);
#endif//IL_NO_JPG
        break;

    case BLP_RAW:
        switch (Header.PictureType)
        {
        // There is no alpha list, so we just read like a normal indexed image.
        case BLP_RAW_NO_ALPHA:
            for (i = 0; i < 16; i++) {  // Possible maximum of 16 mipmaps
                if (!BaseCreated) {  // Have not created the base image yet, so use ilTexImage.
                    if (!ilTexImage(Header.Width, Header.Height, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL))
                        return IL_FALSE;
                    Image = iCurImage;
                    BaseCreated = IL_TRUE;

                    // We have a BGRA palette.
                    Image->Pal.Palette = (ILubyte*)ialloc(256 * 4);
                    if (Image->Pal.Palette == NULL)
                        return IL_FALSE;
                    Image->Pal.PalSize = 1024;
                    Image->Pal.PalType = IL_PAL_BGRA32;

                    // Read in the palette ...
                    if (iread(Image->Pal.Palette, 1, 1024) != 1024)
                        return IL_FALSE;
                }
                else {
                    if (Image->Width == 1 && Image->Height == 1)  // Already at the smallest mipmap (1x1), so we are done.
                        break;
                    if (Header.MipOffsets[i] == 0 || Header.MipLengths[i] == 0)  // No more mipmaps in the file.
                        break;

                    Image->Mipmaps = ilNewImageFull(Image->Width >> 1, Image->Height >> 1, 1, 1, IL_COLOR_INDEX, IL_UNSIGNED_BYTE, NULL);
                    if (Image->Mipmaps == NULL)
                        return IL_FALSE;

//.........这里部分代码省略.........
开发者ID:damucz,项目名称:devil,代码行数:101,代码来源:il_blp.cpp

示例11: il2CopyPixels

ILAPI ILuint ILAPIENTRY il2CopyPixels(ILimage* image, ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width, ILuint Height, ILuint Depth, ILenum Format, ILenum Type, void *Data)
{
	void	*Converted = NULL;
	ILubyte	*TempBuff = NULL;
	ILuint	SrcSize, DestSize;

	if (image == NULL) {
		il2SetError(IL_ILLEGAL_OPERATION);
		return 0;
	}
	DestSize = Width * Height * Depth * ilGetBppFormat(Format) * ilGetBpcType(Type);
	if (DestSize == 0) {
		return DestSize;
	}
	if (Data == NULL || Format == IL_COLOUR_INDEX) {
		il2SetError(IL_INVALID_PARAM);
		return 0;
	}
	SrcSize = Width * Height * Depth * image->Bpp * image->Bpc;

	if (Format == image->Format && Type == image->Type) {
		TempBuff = (ILubyte*)Data;
	}
	else {
		TempBuff = (ILubyte*)ialloc(SrcSize);
		if (TempBuff == NULL) {
			return 0;
		}
	}

	if (YOff + Height <= 1) {
		if (!ilCopyPixels1D(image, XOff, Width, TempBuff)) {
			goto failed;
		}
	}
	else if (ZOff + Depth <= 1) {
		if (!ilCopyPixels2D(image, XOff, YOff, Width, Height, TempBuff)) {
			goto failed;
		}
	}
	else {
		if (!ilCopyPixels3D(image, XOff, YOff, ZOff, Width, Height, Depth, TempBuff)) {
			goto failed;
		}
	}

	if (Format == image->Format && Type == image->Type) {
		return DestSize;
	}

	Converted = ilConvertBuffer(SrcSize, image->Format, Format, image->Type, Type, &image->Pal, TempBuff);
	if (Converted == NULL)
		goto failed;

	memcpy(Data, Converted, DestSize);

	ifree(Converted);
	if (TempBuff != Data)
		ifree(TempBuff);

	return DestSize;

failed:
	if (TempBuff != Data)
		ifree(TempBuff);
	ifree(Converted);
	return 0;
}
开发者ID:KFreon,项目名称:KFreon_s-ResIL,代码行数:68,代码来源:il_manip.cpp

示例12: iLoadBlpInternal

// Internal function used to load the BLP.
ILboolean iLoadBlpInternal(void)
{
    BLP2HEAD	Header;
    ILubyte		*CompData;
    ILimage		*Image;
    ILuint		Mip, j, x, CompSize, AlphaSize, AlphaOff;
    ILint		y;
    ILboolean	BaseCreated = IL_FALSE;
    ILubyte		*DataAndAlpha = NULL, *Palette = NULL, AlphaMask; //, *JpegHeader, *JpegData;

    if (iCurImage == NULL) {
        ilSetError(IL_ILLEGAL_OPERATION);
        return IL_FALSE;
    }

    if (!iGetBlp2Head(&Header)) {
        ilSetError(IL_INVALID_FILE_HEADER);
        return IL_FALSE;
    }
    if (!iCheckBlp2(&Header)) {
        goto check_blp1;
    }

//@TODO: Remove this!
    if (Header.Type != BLP_TYPE_DXTC_RAW)
        return IL_FALSE;

    switch (Header.Compression)
    {
    case BLP_RAW:
        for (Mip = 0; Mip < 16; Mip++) {  // Possible maximum of 16 mipmaps
            if (BaseCreated) {
                if (Header.HasMips == 0)  // Does not have mipmaps, so we are done.
                    break;
                if (Image->Width == 1 && Image->Height == 1)  // Already at the smallest mipmap (1x1), so we are done.
                    break;
                if (Header.MipOffsets[Mip] == 0 || Header.MipLengths == 0)  // No more mipmaps in the file.
                    break;
            }

            switch (Header.AlphaBits)
            {
            case 0:
                if (!BaseCreated) {  // Have not created the base image yet, so use ilTexImage.
                    if (!ilTexImage(Header.Width, Header.Height, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL))
                        return IL_FALSE;
                    Image = iCurImage;
                    BaseCreated = IL_TRUE;

                    Image->Pal.Palette = (ILubyte*)ialloc(256 * 4);  // 256 entries of ARGB8888 values (1024).
                    if (Image->Pal.Palette == NULL)
                        return IL_FALSE;
                    Image->Pal.PalSize = 1024;
                    Image->Pal.PalType = IL_PAL_BGRA32;  //@TODO: Find out if this is really BGRA data.
                    if (iread(Image->Pal.Palette, 1, 1024) != 1024)  // Read in the palette.
                        return IL_FALSE;
                }
                else {
                    Image->Mipmaps = ilNewImageFull(Image->Width >> 1, Image->Height >> 1, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL);
                    if (Image->Mipmaps == NULL)
                        return IL_FALSE;

                    // Copy the palette from the first image before we change our Image pointer.
                    iCopyPalette(&Image->Mipmaps->Pal, &Image->Pal);
                    // Move to the next mipmap in the linked list.
                    Image = Image->Mipmaps;
                }
                // The origin should be in the upper left.
                Image->Origin = IL_ORIGIN_UPPER_LEFT;

                // These two should be the same (tells us how much data is in the file for this mipmap level).
                if (Header.MipLengths[Mip] != Image->SizeOfData) {
                    ilSetError(IL_INVALID_FILE_HEADER);
                    return IL_FALSE;
                }
                // Finally read in the image data.
                iseek(Header.MipOffsets[Mip], IL_SEEK_SET);
                if (iread(Image->Data, 1, Image->SizeOfData) != Image->SizeOfData)
                    return IL_FALSE;
                break;

            case 1:
                if (!BaseCreated) {  // Have not created the base image yet, so use ilTexImage.
                    if (!ilTexImage(Header.Width, Header.Height, 1, 4, IL_BGRA, IL_UNSIGNED_BYTE, NULL))
                        return IL_FALSE;
                    Image = iCurImage;
                    BaseCreated = IL_TRUE;

                    Palette = (ILubyte*)ialloc(256 * 4);
                    if (Palette == NULL)
                        return IL_FALSE;

                    // Read in the palette.
                    if (iread(Palette, 1, 1024) != 1024) {
                        ifree(Palette);
                        return IL_FALSE;
                    }

                    // We only allocate this once and reuse this buffer with every mipmap (since successive ones are smaller).
//.........这里部分代码省略.........
开发者ID:damucz,项目名称:devil,代码行数:101,代码来源:il_blp.cpp

示例13: iIcnsReadData

ILboolean iIcnsReadData(ILboolean *BaseCreated, ILboolean IsAlpha, ILint Width, ICNSDATA *Entry, ILimage **Image)
{
	ILint		Position = 0, RLEPos = 0, Channel, i;
	ILubyte		RLERead, *Data = NULL;
	ILimage		*TempImage = NULL;
	ILboolean	ImageAlreadyExists = IL_FALSE;

	// The .icns format stores the alpha and RGB as two separate images, so this
	//  checks to see if one exists for that particular size.  Unfortunately,
	//	there is no guarantee that they are in any particular order.
	if (*BaseCreated && iCurImage != NULL)
	{
		TempImage = iCurImage;
		while (TempImage != NULL)
		{
			if ((ILuint)Width == TempImage->Width)
			{
				ImageAlreadyExists = IL_TRUE;
				break;
			}
			TempImage = TempImage->Next;
		}
	}

	Data = ialloc(Entry->Size - 8);
	if (Data == NULL)
		return IL_FALSE;

	if (!ImageAlreadyExists)
	{
		if (!*BaseCreated)  // Create base image
		{
			ilTexImage(Width, Width, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, NULL);
			iCurImage->Origin = IL_ORIGIN_UPPER_LEFT;
			*Image = iCurImage;
			*BaseCreated = IL_TRUE;
		}
		else  // Create next image in list
		{
			(*Image)->Next = ilNewImage(Width, Width, 1, 4, 1);
			*Image = (*Image)->Next;
			(*Image)->Format = IL_RGBA;
			(*Image)->Origin = IL_ORIGIN_UPPER_LEFT;
		}

		TempImage = *Image;
	}

	if (IsAlpha)  // Alpha is never compressed.
	{
		iread(Data, Entry->Size - 8, 1);  // Size includes the header
		if (Entry->Size - 8 != Width * Width)
		{
			ifree(Data);
			return IL_FALSE;
		}

		for (i = 0; i < Width * Width; i++)
		{
			TempImage->Data[(i * 4) + 3] = Data[i];
		}
	}
	else if (Width == 256 || Width == 512)  // JPEG2000 encoded - uses JasPer
	{
#ifndef IL_NO_JP2
		iread(Data, Entry->Size - 8, 1);  // Size includes the header
		if (ilLoadJp2LInternal(Data, Entry->Size - 8, TempImage) == IL_FALSE)
		{
			ifree(Data);
			ilSetError(IL_LIB_JP2_ERROR);
			return IL_TRUE;
		}
#else  // Cannot handle this size.
		ilSetError(IL_LIB_JP2_ERROR);  //@TODO: Handle this better...just skip the data.
		return IL_FALSE;
#endif//IL_NO_JP2
	}
	else  // RGB data
	{
		iread(Data, Entry->Size - 8, 1);  // Size includes the header
		if (Width == 128)
			RLEPos += 4;  // There are an extra 4 bytes here of zeros.
		//@TODO: Should we check to make sure they are all 0?

		if (Entry->Size - 8 == Width * Width * 4) // Uncompressed
		{
			//memcpy(TempImage->Data, Data, Entry->Size);
			for (i = 0; i < Width * Width; i++, Position += 4)
			{
				TempImage->Data[i * 4 + 0] = Data[Position+1];
				TempImage->Data[i * 4 + 1] = Data[Position+2];
				TempImage->Data[i * 4 + 2] = Data[Position+3];
			}
		}
		else  // RLE decoding
		{
			for (Channel = 0; Channel < 3; Channel++)
			{
				Position = 0;
				while (Position < Width * Width)
//.........这里部分代码省略.........
开发者ID:AlfiyaZi,项目名称:DevIL,代码行数:101,代码来源:il_icns.c

示例14: ilClearImage_

ILAPI ILboolean ILAPIENTRY ilClearImage_(ILimage *Image)
{
	ILuint		i, c, NumBytes;
	ILubyte 	Colours[32];  // Maximum is sizeof(double) * 4 = 32
	ILubyte 	*BytePtr;
	ILushort	*ShortPtr;
	ILuint		*IntPtr;
	ILfloat 	*FloatPtr;
	ILdouble	*DblPtr;
	
	NumBytes = Image->Bpp * Image->Bpc;
	ilGetClear(Colours, Image->Format, Image->Type);
	
	if (Image->Format != IL_COLOUR_INDEX) {
		switch (Image->Type)
		{
			case IL_BYTE:
			case IL_UNSIGNED_BYTE:
				BytePtr = (ILubyte*)Colours;
				for (c = 0; c < NumBytes; c += Image->Bpc) {
					for (i = c; i < Image->SizeOfData; i += NumBytes) {
						Image->Data[i] = BytePtr[c];
					}
				}
					break;
				
			case IL_SHORT:
			case IL_UNSIGNED_SHORT:
				ShortPtr = (ILushort*)Colours;
				for (c = 0; c < NumBytes; c += Image->Bpc) {
					for (i = c; i < Image->SizeOfData; i += NumBytes) {
						*((ILushort*)(Image->Data + i)) = ShortPtr[c];
					}
				}
					break;
				
			case IL_INT:
			case IL_UNSIGNED_INT:
				IntPtr = (ILuint*)Colours;
				for (c = 0; c < NumBytes; c += Image->Bpc) {
					for (i = c; i < Image->SizeOfData; i += NumBytes) {
						*((ILuint*)(Image->Data + i)) = IntPtr[c];
					}
				}
					break;
				
			case IL_FLOAT:
				FloatPtr = (ILfloat*)Colours;
				for (c = 0; c < NumBytes; c += Image->Bpc) {
					for (i = c; i < Image->SizeOfData; i += NumBytes) {
						*((ILfloat*)(Image->Data + i)) = FloatPtr[c];
					}
				}
					break;
				
			case IL_DOUBLE:
				DblPtr = (ILdouble*)Colours;
				for (c = 0; c < NumBytes; c += Image->Bpc) {
					for (i = c; i < Image->SizeOfData; i += NumBytes) {
						*((ILdouble*)(Image->Data + i)) = DblPtr[c];
					}
				}
					break;
		}
	}
	else {
		imemclear(Image->Data, Image->SizeOfData);
		
		if (Image->Pal.Palette)
			ifree(Image->Pal.Palette);
		Image->Pal.Palette = (ILubyte*)ialloc(4);
		if (Image->Pal.Palette == NULL) {
			return IL_FALSE;
		}
		
		Image->Pal.PalType = IL_PAL_RGBA32;
		Image->Pal.PalSize = 4;
		
		Image->Pal.Palette[0] = Colours[0] * UCHAR_MAX;
		Image->Pal.Palette[1] = Colours[1] * UCHAR_MAX;
		Image->Pal.Palette[2] = Colours[2] * UCHAR_MAX;
		Image->Pal.Palette[3] = Colours[3] * UCHAR_MAX;
	}
	
	return IL_TRUE;
}
开发者ID:aickau,项目名称:spectra-clustering-tool,代码行数:86,代码来源:il_devil.c

示例15: channels

/*! \param Image Specifies the image. The function fails if this is zero. 
   \param Width Specifies the new image width.  This cannot be 0.
	\param Height Specifies the new image height.  This cannot be 0.
	\param Depth Specifies the new image depth.  This cannot be 0.
	\param Bpp Number of channels (ex. 3 for RGB)
	\param Format Enum of the desired format.  Any format values are accepted.
	\param Type Enum of the desired type.  Any type values are accepted.
	\param Data Specifies data that should be copied to the new image. If this parameter is NULL, no data is copied, and the new image data consists of undefined values.
	\exception IL_ILLEGAL_OPERATION No currently bound image.
	\exception IL_INVALID_PARAM One of the parameters is incorrect, such as one of the dimensions being 0.
	\exception IL_OUT_OF_MEMORY Could not allocate enough memory.
	\return Boolean value of failure or success*/
ILAPI ILboolean ILAPIENTRY il2TexImage(ILimage *Image, ILuint Width, 
	ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, 
	void *Data)
{
	if (Image == NULL) {
		il2SetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}

	ILubyte BpcType = ilGetBpcType(Type);
	if (BpcType == 0) {
		il2SetError(IL_INVALID_PARAM);
		return IL_FALSE;
	}

	// Reset palette
	Image->Pal.clear();

	ilCloseImage(Image->Mipmaps);
	Image->Mipmaps = NULL;

	ilCloseImage(Image->Next);
	Image->Next = NULL;

	ilCloseImage(Image->Faces);
	Image->Faces = NULL; 

	ilCloseImage(Image->Layers);
	Image->Layers = NULL;

	if (Image->AnimList) ifree(Image->AnimList);
	if (Image->Profile)  ifree(Image->Profile);
	if (Image->DxtcData) ifree(Image->DxtcData);
	if (Image->Data)	 ifree(Image->Data);

	////

	//@TODO: Also check against format?
	/*if (Width == 0 || Height == 0 || Depth == 0 || Bpp == 0) {
		il2SetError(IL_INVALID_PARAM);
	return IL_FALSE;
	}*/

	////
	if (Width  == 0) Width = 1;
	if (Height == 0) Height = 1;
	if (Depth  == 0) Depth = 1;
	Image->Width	   = Width;
	Image->Height	   = Height;
	Image->Depth	   = Depth;
	Image->Bpp		   = Bpp;
	Image->Bpc		   = BpcType;
	Image->Bps		   = Width * Bpp * Image->Bpc;
	Image->SizeOfPlane = Image->Bps * Height;
	Image->SizeOfData  = Image->SizeOfPlane * Depth;
	Image->Format      = Format;
	Image->Type        = Type;
	Image->Data = (ILubyte*)ialloc(Image->SizeOfData);

	if (Image->Data != NULL) {
		if (Data != NULL) {
			memcpy(Image->Data, Data, Image->SizeOfData);
		}

		return IL_TRUE;
	} else {
		return IL_FALSE;
	}
}
开发者ID:Enseed,项目名称:ResIL,代码行数:81,代码来源:il_devil.cpp


注:本文中的ialloc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。