Example #1
0
// Internal function used to get the Psp header from the current file.
static ILboolean iGetPspHead(SIO *io, PSPHEAD *Header)
{
	if (!SIOread(io, Header, sizeof(*Header), 1))
		return IL_FALSE;

	UShort(&Header->MajorVersion);
	UShort(&Header->MinorVersion);
	
	return IL_TRUE;
}
Example #2
0
static ILboolean ParseChunks(PSP_CTX *ctx)
{
	BLOCKHEAD	Block;
	ILuint		Pos;

	do {
		if (SIOread(ctx->io, &Block, 1, sizeof(Block)) != sizeof(Block)) {
			iPopError();  // Get rid of the erroneous IL_FILE_READ_ERROR.
			break;
		}

		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 ) {
				break;
		}

		UShort(&Block.BlockID);
		UInt(&Block.BlockLen);

		Pos = SIOtell(ctx->io);

		switch (Block.BlockID)
		{
			case PSP_LAYER_START_BLOCK:
				if (!ReadLayerBlock(ctx))
					return IL_FALSE;
				break;

			case PSP_ALPHA_BANK_BLOCK:
				if (!ReadAlphaBlock(ctx))
					return IL_FALSE;
				break;

			case PSP_COLOR_BLOCK:
				if (!ReadPalette(ctx))
					return IL_FALSE;
				break;

			// Gets done in the next iseek, so this is now commented out.
			//default:
				//SIOseek(ctx->io, Block.BlockLen, IL_SEEK_CUR);
		}

		// Skip to next block just in case we didn't read the entire block.
		SIOseek(ctx->io, Pos + Block.BlockLen, IL_SEEK_SET);

		// @TODO: Do stuff here.

	} while (1);

	return IL_TRUE;
}
Example #3
0
ILuint GetShort(DICOMHEAD *Header, ILushort GroupNum)
{
	ILushort Num;

	iread(&Num, 1, 2);
	// The 0x02 group is always little endian.
	if (GroupNum == 0x02) {
		UShort(&Num);
		return Num;
	}
	// Now we have to swizzle it if it is not 0x02.
	if (Header->BigEndian)
		BigUShort(&Num);
	else
		UShort(&Num);

	return Num;
}
Example #4
0
// Internal function obtain the .pcx header from the current file.
ILboolean iGetPcxHead(PCXHEAD *Head)
{
	if (iread(Head, sizeof(PCXHEAD), 1) != 1)
		return IL_FALSE;

	UShort(&Head->Xmin);
	UShort(&Head->Ymin);
	UShort(&Head->Xmax);
	UShort(&Head->Ymax);
	UShort(&Head->HDpi);
	UShort(&Head->VDpi);
	UShort(&Head->Bps);
	UShort(&Head->PaletteInfo);
	UShort(&Head->HScreenSize);
	UShort(&Head->VScreenSize);

	return IL_TRUE;
}
Example #5
0
ILboolean ParseChunks(PspLoadState* state, ILimage* image)
{
	BLOCKHEAD	Block;

	do {
		if (image->io.read(&image->io, &Block, 1, sizeof(Block)) != sizeof(Block)) {
			il2GetError();  // Get rid of the erroneous IL_FILE_READ_ERROR.
			return IL_TRUE;
		}
		if (state->Header.MajorVersion == 3)
			Block.BlockLen = GetLittleUInt(&image->io);
		else
			UInt(&Block.BlockLen);

		if (Block.HeadID[0] != 0x7E || Block.HeadID[1] != 0x42 ||
			Block.HeadID[2] != 0x4B || Block.HeadID[3] != 0x00) {
				return IL_TRUE;
		}
		UShort(&Block.BlockID);
		UInt(&Block.BlockLen);

		auto Pos = image->io.tell(&image->io);

		switch (Block.BlockID)
		{
			case PSP_LAYER_START_BLOCK:
				if (!ReadLayerBlock(state, Block.BlockLen, image))
					return IL_FALSE;
				break;

			case PSP_ALPHA_BANK_BLOCK:
				if (!ReadAlphaBlock(state, Block.BlockLen, image))
					return IL_FALSE;
				break;

			case PSP_COLOR_BLOCK:
				if (!ReadPalette(state, Block.BlockLen, image))
					return IL_FALSE;
				break;

			// Gets done in the next iseek, so this is now commented out.
			//default:
				//image->io.seek(&image->io, Block.BlockLen, IL_SEEK_CUR);
		}

		// Skip to next block just in case we didn't read the entire block.
		image->io.seek(&image->io, Pos + Block.BlockLen, IL_SEEK_SET);

		// @TODO: Do stuff here.

	} while (1);

	return IL_TRUE;
}
Example #6
0
ILboolean iGetOS2Head(OS2_HEAD * const Header)
{
	if (iread(Header, sizeof(OS2_HEAD), 1) != 1)
		return IL_FALSE;

	UShort(&Header->bfType);
	UInt(&Header->biSize);
	Short(&Header->xHotspot);
	Short(&Header->yHotspot);
	UInt(&Header->DataOff);
	UInt(&Header->cbFix);

	//2003-09-01 changed to UShort according to MSDN
	UShort(&Header->cx);
	UShort(&Header->cy);
	UShort(&Header->cPlanes);
	UShort(&Header->cBitCount);

	iseek((ILint)Header->cbFix - 12, IL_SEEK_CUR);  // Skip rest of header, if any.

	return IL_TRUE;
}
Example #7
0
static void
realign_data(TERMTYPE *to, char **ext_Names,
	     int ext_Booleans,
	     int ext_Numbers,
	     int ext_Strings)
{
    int n, m, base;
    int limit = (to->ext_Booleans + to->ext_Numbers + to->ext_Strings);

    if (to->ext_Booleans != ext_Booleans) {
	EXTEND_NUM(num_Booleans, ext_Booleans);
	TYPE_REALLOC(NCURSES_SBOOL, to->num_Booleans, to->Booleans);
	for (n = to->ext_Booleans - 1,
	     m = ext_Booleans - 1,
	     base = to->num_Booleans - (m + 1); m >= 0; m--) {
	    if (find_name(to->ext_Names, limit, ext_Names[m])) {
		to->Booleans[base + m] = to->Booleans[base + n--];
	    } else {
		to->Booleans[base + m] = FALSE;
	    }
	}
	to->ext_Booleans = UShort(ext_Booleans);
    }

    if (to->ext_Numbers != ext_Numbers) {
	EXTEND_NUM(num_Numbers, ext_Numbers);
	TYPE_REALLOC(short, to->num_Numbers, to->Numbers);
	for (n = to->ext_Numbers - 1,
	     m = ext_Numbers - 1,
	     base = to->num_Numbers - (m + 1); m >= 0; m--) {
	    if (find_name(to->ext_Names, limit, ext_Names[m + ext_Booleans])) {
		to->Numbers[base + m] = to->Numbers[base + n--];
	    } else {
		to->Numbers[base + m] = ABSENT_NUMERIC;
	    }
	}
	to->ext_Numbers = UShort(ext_Numbers);
    }
Example #8
0
static ILboolean ReadGenAttributes(PSP_CTX *ctx)
{
	BLOCKHEAD		AttHead;
	ILint				Padding;
	ILuint			ChunkLen;

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

	UShort(&AttHead.BlockID);
	UInt(&AttHead.BlockLen);

	if (AttHead.HeadID[0] != 0x7E || AttHead.HeadID[1] != 0x42 ||
		AttHead.HeadID[2] != 0x4B || AttHead.HeadID[3] != 0x00) {
		iSetError(IL_INVALID_FILE_HEADER);
		return IL_FALSE;
	}
	if (AttHead.BlockID != PSP_IMAGE_BLOCK) {
		iSetError(IL_INVALID_FILE_HEADER);
		return IL_FALSE;
	}

	ChunkLen = GetLittleUInt(ctx->io);
	if (ctx->Header.MajorVersion != 3)
		ChunkLen -= 4;

	if (SIOread(ctx->io, &ctx->AttChunk, IL_MIN(sizeof(ctx->AttChunk), ChunkLen), 1) != 1)
		return IL_FALSE;

	// Can have new entries in newer versions of the spec (4.0).
	Padding = (ILint)(ChunkLen - sizeof(ctx->AttChunk));
	if (Padding > 0)
		SIOseek(ctx->io, Padding, IL_SEEK_CUR);

	// @TODO:  Anything but 24 not supported yet...
	if (ctx->AttChunk.BitDepth != 24 && ctx->AttChunk.BitDepth != 8) {
		iSetError(IL_INVALID_FILE_HEADER);
		return IL_FALSE;
	}

	// @TODO;  Add support for compression...
	if (ctx->AttChunk.Compression != PSP_COMP_NONE && ctx->AttChunk.Compression != PSP_COMP_RLE) {
		iSetError(IL_INVALID_FILE_HEADER);
		return IL_FALSE;
	}

	// @TODO: Check more things in the general attributes chunk here.

	return IL_TRUE;
}