1
//-----------------------------------------------------------------------------
4
// Copyright (C) 2000-2001 by Denton Woods
5
// Last modified: 05/25/2001 <--Y2K Compliant! =]
7
// Filename: src-IL/src/rawdata.c
9
// Description: "Raw" file functions
11
//-----------------------------------------------------------------------------
14
#include "il_internal.h"
19
ILboolean iLoadDataInternal(ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp);
22
//! Reads a raw data file
23
ILboolean ILAPIENTRY ilLoadData(const ILstring FileName, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp)
26
ILboolean bRaw = IL_FALSE;
28
// No need to check for raw data
29
/*if (!iCheckExtension(FileName, "raw")) {
30
ilSetError(IL_INVALID_EXTENSION);
34
RawFile = iopenr(FileName);
35
if (RawFile == NULL) {
36
ilSetError(IL_COULD_NOT_OPEN_FILE);
40
bRaw = ilLoadDataF(RawFile, Width, Height, Depth, Bpp);
47
//! Reads an already-opened raw data file
48
ILboolean ILAPIENTRY ilLoadDataF(ILHANDLE File, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp)
55
bRet = iLoadDataInternal(Width, Height, Depth, Bpp);
56
iseek(FirstPos, IL_SEEK_SET);
62
//! Reads from a raw data memory "lump"
63
ILboolean ILAPIENTRY ilLoadDataL(ILvoid *Lump, ILuint Size, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp)
65
iSetInputLump(Lump, Size);
66
return iLoadDataInternal(Width, Height, Depth, Bpp);
70
// Internal function to load a raw data image
71
ILboolean iLoadDataInternal(ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp)
73
if (iCurImage == NULL || ((Bpp != 1) && (Bpp != 3) && (Bpp != 4))) {
74
ilSetError(IL_ILLEGAL_OPERATION);
78
if (!ilTexImage(Width, Height, Depth, Bpp, 0, IL_UNSIGNED_BYTE, NULL)) {
81
iCurImage->Origin = IL_ORIGIN_UPPER_LEFT;
83
// Tries to read the correct amount of data
84
if (iread(iCurImage->Data, Width * Height * Depth * Bpp, 1) != 1)
87
if (iCurImage->Bpp == 1)
88
iCurImage->Format = IL_LUMINANCE;
89
else if (iCurImage->Bpp == 3)
90
iCurImage->Format = IL_RGB;
92
iCurImage->Format = IL_RGBA;
100
//! Save the current image to FileName as raw data
101
ILboolean ILAPIENTRY ilSaveData(const ILstring FileName)
105
if (iCurImage == NULL) {
106
ilSetError(IL_ILLEGAL_OPERATION);
110
DataFile = iopenr(FileName);
111
if (DataFile == NULL) {
112
ilSetError(IL_COULD_NOT_OPEN_FILE);
116
iwrite(iCurImage->Data, 1, iCurImage->SizeOfData);