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
|
/*
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
=============================================================================
*/
#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_FreeTempMem( x )
#else
#define IMG_AllocPixels( x ) R_Malloc( x )
#define IMG_FreePixels( x ) Z_Free( x )
#endif
#if USE_REF == REF_SOFT
#define MIPSIZE(c) ((c)*(256+64+16+4)/256)
#else
#define MIPSIZE(c) (c)
#endif
// absolute limit for OpenGL renderer
#if USE_REF == REF_GL
#define MAX_TEXTURE_SIZE 2048
#else
#define MAX_TEXTURE_SIZE 512
#endif
// size of GL_Upload8 internal buffer
#define MAX_PALETTED_PIXELS (512*256)
/*
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 )
} imageflags_t;
typedef enum {
it_skin,
it_sprite,
it_wall,
it_pic,
it_sky,
it_charset
} imagetype_t;
typedef enum {
im_pcx,
im_wal,
#if USE_TGA
im_tga,
#endif
#if USE_JPG
im_jpg,
#endif
#if USE_PNG
im_png,
#endif
im_unknown
} imageformat_t;
typedef struct image_s {
list_t entry;
char name[MAX_QPATH]; // game path, without extension
imagetype_t type;
imageflags_t flags;
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
} image_t;
#define MAX_RIMAGES 1024
extern image_t r_images[MAX_RIMAGES];
extern int r_numImages;
extern int registration_sequence;
#define R_NOTEXTURE &r_images[0]
extern uint32_t d_8to24table[256];
// these are implemented in r_images.c
image_t *IMG_Find( const char *name, imagetype_t type );
void IMG_FreeUnused( void );
void IMG_FreeAll( void );
void IMG_Init( void );
void IMG_Shutdown( void );
byte *IMG_GetPalette( void );
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 _R_RegisterPic( const char *name, qhandle_t *handle );
qerror_t _R_RegisterFont( const char *name, qhandle_t *handle );
// 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 );
#if USE_REF == REF_SOFT
byte *IMG_ReadPixels( byte **palette, int *width, int *height, int *rowbytes );
#else
byte *IMG_ReadPixels( qboolean reverse, int *width, int *height );
#endif
|