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

« back to all changes in this revision

Viewing changes to src-IL/src/il_utility.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-2002 by Denton Woods
 
5
// Last modified: 05/25/2001 <--Y2K Compliant! =]
 
6
//
 
7
// Filename: src-IL/src/il_utility.c
 
8
//
 
9
// Description: Utility functions
 
10
//
 
11
//-----------------------------------------------------------------------------
 
12
 
 
13
 
 
14
#include "il_internal.h"
 
15
 
 
16
 
 
17
// Returns the bpp of any Format
 
18
ILAPI ILubyte ILAPIENTRY ilGetBppFormat(ILenum Format)
 
19
{
 
20
        switch (Format)
 
21
        {
 
22
                case IL_COLOUR_INDEX:
 
23
                        return 1;
 
24
                case IL_LUMINANCE:
 
25
                        return 1;
 
26
                case IL_LUMINANCE_ALPHA:
 
27
                        return 2;
 
28
                case IL_RGB:
 
29
                        return 3;
 
30
                case IL_BGR:
 
31
                        return 3;
 
32
                case IL_RGBA:
 
33
                        return 4;
 
34
                case IL_BGRA:
 
35
                        return 4;
 
36
        }
 
37
        return 0;
 
38
}
 
39
 
 
40
 
 
41
// Returns the format of any bpp
 
42
ILAPI ILenum ILAPIENTRY ilGetFormatBpp(ILubyte Bpp)
 
43
{
 
44
        switch (Bpp)
 
45
        {
 
46
        case 1:
 
47
                return IL_LUMINANCE;
 
48
        case 2:
 
49
                return IL_LUMINANCE_ALPHA;
 
50
        case 3:
 
51
                return IL_RGB;
 
52
        case 4:
 
53
                return IL_RGBA;
 
54
        }
 
55
        return 0;
 
56
}
 
57
 
 
58
 
 
59
// Returns the bpc of any Type
 
60
ILAPI ILubyte ILAPIENTRY ilGetBpcType(ILenum Type)
 
61
{
 
62
        switch (Type)
 
63
        {
 
64
                case IL_BYTE:
 
65
                        return 1;
 
66
                case IL_UNSIGNED_BYTE:
 
67
                        return 1;
 
68
                case IL_SHORT:
 
69
                        return 2;
 
70
                case IL_UNSIGNED_SHORT:
 
71
                        return 2;
 
72
                case IL_INT:
 
73
                        return 4;
 
74
                case IL_UNSIGNED_INT:
 
75
                        return 4;
 
76
                case IL_FLOAT:
 
77
                        return 4;
 
78
                case IL_DOUBLE:
 
79
                        return 8;
 
80
        }
 
81
        return 0;
 
82
}
 
83
 
 
84
 
 
85
// Returns the type matching a bpc
 
86
ILAPI ILenum ILAPIENTRY ilGetTypeBpc(ILubyte Bpc)
 
87
{
 
88
        switch (Bpc)
 
89
        {
 
90
                case 1:
 
91
                        return IL_UNSIGNED_BYTE;
 
92
                case 2:
 
93
                        return IL_UNSIGNED_SHORT;
 
94
                case 4:
 
95
                        return IL_UNSIGNED_INT;
 
96
                case 8:
 
97
                        return IL_DOUBLE;
 
98
        }
 
99
        return 0;
 
100
}
 
101
 
 
102
 
 
103
// Returns the bpp of any palette type (PalType)
 
104
ILAPI ILubyte ILAPIENTRY ilGetBppPal(ILenum PalType)
 
105
{
 
106
        switch (PalType)
 
107
        {
 
108
                case IL_PAL_RGB24:
 
109
                        return 3;
 
110
                case IL_PAL_BGR24:
 
111
                        return 3;
 
112
                case IL_PAL_RGB32:
 
113
                        return 4;
 
114
                case IL_PAL_RGBA32:
 
115
                        return 4;
 
116
                case IL_PAL_BGR32:
 
117
                        return 4;
 
118
                case IL_PAL_BGRA32:
 
119
                        return 4;
 
120
        }
 
121
        return 0;
 
122
}
 
123
 
 
124
 
 
125
// Returns the base format of a palette type (PalType)
 
126
ILAPI ILenum ILAPIENTRY ilGetPalBaseType(ILenum PalType)
 
127
{
 
128
        switch (PalType)
 
129
        {
 
130
                case IL_PAL_RGB24:
 
131
                        return IL_RGB;
 
132
                case IL_PAL_RGB32:
 
133
                        return IL_RGBA;  // Not sure
 
134
                case IL_PAL_RGBA32:
 
135
                        return IL_RGBA;
 
136
                case IL_PAL_BGR24:
 
137
                        return IL_BGR;
 
138
                case IL_PAL_BGR32:
 
139
                        return IL_BGRA;  // Not sure
 
140
                case IL_PAL_BGRA32:
 
141
                        return IL_BGRA;
 
142
        }
 
143
 
 
144
        return 0;
 
145
}
 
146
 
 
147
 
 
148
// Returns the next power of 2 if Num isn't 2^n or returns Num if Num is 2^n
 
149
ILAPI ILuint ILAPIENTRY ilNextPower2(ILuint Num)
 
150
{
 
151
        ILuint Power2 = 1;
 
152
        if (Num == 0) return 1;
 
153
        for (; Power2 < Num; Power2 <<= 1);
 
154
        return Power2;
 
155
}