1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
/*
Copyright (C) 2003-2006 Andrey Nazarov
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
=============================================================================
IMAGE MANAGER
=============================================================================
*/
#if USE_BGRA
#define MakeColor( r, g, b, a ) MakeRawLong( b, g, r, a )
#else
#define MakeColor( r, g, b, a ) MakeRawLong( r, g, b, a )
#endif
#define R_Malloc( size ) Z_TagMalloc( size, TAG_RENDERER )
#define R_Mallocz( size ) Z_TagMallocz( size, TAG_RENDERER )
#if USE_REF == REF_GL
#define IMG_AllocPixels( x ) FS_AllocTempMem( x )
#define IMG_FreePixels( x ) FS_FreeFile( x )
#else
#define IMG_AllocPixels( x ) R_Malloc( x )
#define IMG_FreePixels( x ) Z_Free( x )
#endif
// absolute limit for OpenGL renderer
#if USE_REF == REF_GL
#define MAX_TEXTURE_SIZE 2048
#else
#define MAX_TEXTURE_SIZE 512
#endif
/*
skins will be outline flood filled and mip mapped
pics and sprites with alpha will be outline flood filled
pic won't be mip mapped
model skin
sprite frame
wall texture
pic
*/
typedef enum {
if_transparent = ( 1 << 0 ),
if_paletted = ( 1 << 1 ),
if_scrap = ( 1 << 2 ),
if_replace_wal = ( 1 << 3 ),
if_replace_pcx = ( 1 << 4 ),
if_auto = ( 1 << 5 )
} imageflags_t;
typedef enum {
it_skin,
it_sprite,
it_wall,
it_pic,
it_sky,
it_charset
} imagetype_t;
#define EXTENSION_PNG MakeRawLong( '.', 'p', 'n', 'g' )
#define EXTENSION_TGA MakeRawLong( '.', 't', 'g', 'a' )
#define EXTENSION_JPG MakeRawLong( '.', 'j', 'p', 'g' )
#define EXTENSION_PCX MakeRawLong( '.', 'p', 'c', 'x' )
#define EXTENSION_WAL MakeRawLong( '.', 'w', 'a', 'l' )
typedef struct image_s {
list_t entry;
char name[MAX_QPATH]; // game path, without extension
//int baselength; // length of the path without extension
imagetype_t type;
int width, height; // source image
int upload_width, upload_height; // after power of two and picmip
int registration_sequence; // 0 = free
#if USE_REF == REF_GL
unsigned texnum; // gl texture binding
float sl, sh, tl, th;
#else
byte *pixels[4]; // mip levels
#endif
imageflags_t flags;
} image_t;
#define MAX_RIMAGES 1024
extern image_t r_images[MAX_RIMAGES];
extern int r_numImages;
extern int registration_sequence;
extern image_t *r_notexture;
extern uint32_t d_8to24table[256];
// these are implemented in r_images.c
image_t *IMG_Alloc( const char *name );
image_t *IMG_Find( const char *name, imagetype_t type );
image_t *IMG_Create( const char *name, byte *pic, int width, int height,
imagetype_t type, imageflags_t flags );
void IMG_FreeUnused( void );
void IMG_FreeAll( void );
void IMG_Init( void );
void IMG_Shutdown( void );
void IMG_GetPalette( byte **dest );
image_t *IMG_ForHandle( qhandle_t h );
qhandle_t R_RegisterSkin( const char *name );
qhandle_t R_RegisterPic( const char *name );
qhandle_t R_RegisterFont( const char *name );
qerror_t IMG_LoadPCX( const char *filename, byte **pic, byte *palette,
int *width, int *height );
qerror_t IMG_WritePCX( qhandle_t f, const char *filename, const byte *data, int width,
int height, int rowbytes, byte *palette );
#if USE_TGA || USE_JPG || USE_PNG
typedef qerror_t (img_load_t)( const char *, byte **, int *, int * );
typedef qerror_t (img_save_t)( qhandle_t, const char *, const byte *, int, int, int );
#endif
#if USE_TGA
qerror_t IMG_LoadTGA( const char *filename, byte **pic, int *width, int *height );
qerror_t IMG_SaveTGA( qhandle_t f, const char *filename, const byte *bgr,
int width, int height, int unused );
#endif
#if USE_JPG
qerror_t IMG_LoadJPG( const char *filename, byte **pic, int *width, int *height );
qerror_t IMG_SaveJPG( qhandle_t f, const char *filename, const byte *rgb,
int width, int height, int quality );
#endif
#if USE_PNG
qerror_t IMG_LoadPNG( const char *filename, byte **pic, int *width, int *height );
qerror_t IMG_SavePNG( qhandle_t f, const char *filename, const byte *rgb,
int width, int height, int compression );
#endif
// these are implemented in [gl,sw]_images.c
void IMG_Unload( image_t *image );
void IMG_Load( image_t *image, byte *pic, int width, int height,
imagetype_t type, imageflags_t flags );
image_t *IMG_LoadWAL( const char *name );
|