~ubuntu-branches/ubuntu/hoary/devil/hoary

« back to all changes in this revision

Viewing changes to src-IL/src/il_rawdata.c

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2005-01-03 19:57:42 UTC
  • Revision ID: james.westby@ubuntu.com-20050103195742-4ipkplcwygu3irv0
Tags: upstream-1.6.7
ImportĀ upstreamĀ versionĀ 1.6.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//-----------------------------------------------------------------------------
 
2
//
 
3
// ImageLib Sources
 
4
// Copyright (C) 2000-2001 by Denton Woods
 
5
// Last modified: 05/25/2001 <--Y2K Compliant! =]
 
6
//
 
7
// Filename: src-IL/src/rawdata.c
 
8
//
 
9
// Description: "Raw" file functions
 
10
//
 
11
//-----------------------------------------------------------------------------
 
12
 
 
13
 
 
14
#include "il_internal.h"
 
15
//#ifndef IL_NO_DATA
 
16
#include "il_manip.h"
 
17
 
 
18
 
 
19
ILboolean iLoadDataInternal(ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp);
 
20
 
 
21
 
 
22
//! Reads a raw data file
 
23
ILboolean ILAPIENTRY ilLoadData(const ILstring FileName, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp)
 
24
{
 
25
        ILHANDLE        RawFile;
 
26
        ILboolean       bRaw = IL_FALSE;
 
27
 
 
28
        // No need to check for raw data
 
29
        /*if (!iCheckExtension(FileName, "raw")) {
 
30
                ilSetError(IL_INVALID_EXTENSION);
 
31
                return bRaw;
 
32
        }*/
 
33
 
 
34
        RawFile = iopenr(FileName);
 
35
        if (RawFile == NULL) {
 
36
                ilSetError(IL_COULD_NOT_OPEN_FILE);
 
37
                return bRaw;
 
38
        }
 
39
 
 
40
        bRaw = ilLoadDataF(RawFile, Width, Height, Depth, Bpp);
 
41
        icloser(RawFile);
 
42
 
 
43
        return bRaw;
 
44
}
 
45
 
 
46
 
 
47
//! Reads an already-opened raw data file
 
48
ILboolean ILAPIENTRY ilLoadDataF(ILHANDLE File, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp)
 
49
{
 
50
        ILuint          FirstPos;
 
51
        ILboolean       bRet;
 
52
 
 
53
        iSetInputFile(File);
 
54
        FirstPos = itell();
 
55
        bRet = iLoadDataInternal(Width, Height, Depth, Bpp);
 
56
        iseek(FirstPos, IL_SEEK_SET);
 
57
 
 
58
        return bRet;
 
59
}
 
60
 
 
61
 
 
62
//! Reads from a raw data memory "lump"
 
63
ILboolean ILAPIENTRY ilLoadDataL(ILvoid *Lump, ILuint Size, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp)
 
64
{
 
65
        iSetInputLump(Lump, Size);
 
66
        return iLoadDataInternal(Width, Height, Depth, Bpp);
 
67
}
 
68
 
 
69
 
 
70
// Internal function to load a raw data image
 
71
ILboolean iLoadDataInternal(ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp)
 
72
{
 
73
        if (iCurImage == NULL || ((Bpp != 1) && (Bpp != 3) && (Bpp != 4))) {
 
74
                ilSetError(IL_ILLEGAL_OPERATION);
 
75
                return IL_FALSE;
 
76
        }
 
77
 
 
78
        if (!ilTexImage(Width, Height, Depth, Bpp, 0, IL_UNSIGNED_BYTE, NULL)) {
 
79
                return IL_FALSE;
 
80
        }
 
81
        iCurImage->Origin = IL_ORIGIN_UPPER_LEFT;
 
82
 
 
83
        // Tries to read the correct amount of data
 
84
        if (iread(iCurImage->Data, Width * Height * Depth * Bpp, 1) != 1)
 
85
                return IL_FALSE;
 
86
 
 
87
        if (iCurImage->Bpp == 1)
 
88
                iCurImage->Format = IL_LUMINANCE;
 
89
        else if (iCurImage->Bpp == 3)
 
90
                iCurImage->Format = IL_RGB;
 
91
        else  // 4
 
92
                iCurImage->Format = IL_RGBA;
 
93
 
 
94
        ilFixImage();
 
95
 
 
96
        return IL_TRUE;
 
97
}
 
98
 
 
99
 
 
100
//! Save the current image to FileName as raw data
 
101
ILboolean ILAPIENTRY ilSaveData(const ILstring FileName)
 
102
{
 
103
        ILHANDLE DataFile;
 
104
 
 
105
        if (iCurImage == NULL) {
 
106
                ilSetError(IL_ILLEGAL_OPERATION);
 
107
                return IL_FALSE;
 
108
        }
 
109
 
 
110
        DataFile = iopenr(FileName);
 
111
        if (DataFile == NULL) {
 
112
                ilSetError(IL_COULD_NOT_OPEN_FILE);
 
113
                return IL_FALSE;
 
114
        }
 
115
 
 
116
        iwrite(iCurImage->Data, 1, iCurImage->SizeOfData);
 
117
        icloser(DataFile);
 
118
 
 
119
        return IL_TRUE;
 
120
}
 
121
 
 
122
 
 
123
//#endif//IL_NO_DATA