1 //---------------------------------------------------------------------------- 2 // EDGE Generalised Image Handling 3 //---------------------------------------------------------------------------- 4 // 5 // Copyright (c) 1999-2009 The EDGE Team. 6 // 7 // This program is free software; you can redistribute it and/or 8 // modify it under the terms of the GNU General Public License 9 // as published by the Free Software Foundation; either version 2 10 // of the License, or (at your option) any later version. 11 // 12 // This program is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 // 17 //---------------------------------------------------------------------------- 18 // 19 // Based on the DOOM source code, released by Id Software under the 20 // following copyright: 21 // 22 // Copyright (C) 1993-1996 by id Software, Inc. 23 // 24 //---------------------------------------------------------------------------- 25 26 #ifndef __R_IMAGE__ 27 #define __R_IMAGE__ 28 29 #include <vector> 30 31 #include "ddf/main.h" 32 #include "ddf/image.h" 33 34 #include "r_defs.h" 35 #include "r_state.h" 36 37 struct texturedef_s; 38 39 40 // the transparent pixel value we use 41 #define TRANS_PIXEL 247 42 43 // Post end marker 44 #define P_SENTINEL 0xFF 45 46 // dynamic light sizing factor 47 #define DL_OUTER 64.0f 48 #define DL_OUTER_SQRT 8.0f 49 50 51 typedef enum 52 { 53 OPAC_Unknown = 0, 54 55 OPAC_Solid = 1, // utterly solid (alpha = 255 everywhere) 56 OPAC_Masked = 2, // only uses alpha 255 and 0 57 OPAC_Complex = 3, // uses full range of alpha values 58 } 59 image_opacity_e; 60 61 62 class image_c 63 { 64 public: 65 // actual image size. Images that are smaller than their total size 66 // are located in the bottom left corner, cannot tile, and are padded 67 // with black pixels if solid, or transparent pixels otherwise. 68 unsigned short actual_w; 69 unsigned short actual_h; 70 71 // total image size, must be a power of two on each axis. 72 unsigned short total_w; 73 unsigned short total_h; 74 75 // offset values. Only used for sprites and on-screen patches. 76 short offset_x; 77 short offset_y; 78 79 // scale values, where 1.0f is normal. Higher values stretch the 80 // image (on the wall/floor), lower values shrink it. 81 float scale_x; 82 float scale_y; 83 84 // one of the OPAC_XXX values 85 int opacity; 86 87 88 //!!!!!! private: 89 90 // --- information about where this image came from --- 91 char name[16]; 92 93 int source_type; // image_source_e 94 95 union 96 { 97 // case IMSRC_Graphic: 98 // case IMSRC_Sprite: 99 // case IMSRC_TX_HI: 100 struct { int lump; bool is_png; } graphic; 101 102 // case IMSRC_Flat: 103 // case IMSRC_Raw320x200: 104 struct { int lump; } flat; 105 106 // case IMSRC_Texture: 107 struct { struct texturedef_s *tdef; } texture; 108 109 // case IMSRC_Dummy: 110 struct { rgbcol_t fg; rgbcol_t bg; } dummy; 111 112 // case IMSRC_User: 113 struct { imagedef_c *def; } user; 114 } 115 source; 116 117 // palette lump, or -1 to use the "GLOBAL" palette 118 int source_palette; 119 120 // --- information about caching --- 121 122 std::vector< struct cached_image_s * > cache; 123 124 // --- animation info --- 125 126 struct 127 { 128 // current version of this image in the animation. Initially points 129 // to self. For non-animated images, doesn't change. Otherwise 130 // when the animation flips over, it becomes cur->next. 131 image_c *cur; 132 133 // next image in the animation, or NULL. 134 image_c *next; 135 136 // tics before next anim change, or 0 if non-animated. 137 unsigned short count; 138 139 // animation speed (in tics), or 0 if non-animated. 140 unsigned short speed; 141 } 142 anim; 143 144 public: 145 image_c(); 146 ~image_c(); 147 148 /* TODO: add methods here... */ 149 }; 150 151 152 // macro for converting image_c sizes to cached_image_t sizes 153 #define MIP_SIZE(size,mip) MAX(1, (size) >> (mip)) 154 155 // utility macros (FIXME: replace with class methods) 156 #define IM_RIGHT(image) (float((image)->actual_w) / (image)->total_w) 157 #define IM_TOP(image) (float((image)->actual_h) / (image)->total_h) 158 159 #define IM_WIDTH(image) ((image)->actual_w * (image)->scale_x) 160 #define IM_HEIGHT(image) ((image)->actual_h * (image)->scale_y) 161 162 #define IM_OFFSETX(image) ((image)->offset_x * (image)->scale_x) 163 #define IM_OFFSETY(image) ((image)->offset_y * (image)->scale_y) 164 165 // deliberately long, should not be used (except for special cases) 166 #define IM_TOTAL_WIDTH(image) ((image)->total_w * (image)->scale_x) 167 #define IM_TOTAL_HEIGHT(image) ((image)->total_h * (image)->scale_y) 168 169 170 // 171 // IMAGE LOOKUP 172 // 173 typedef enum 174 { 175 ILF_Null = 0x0001, // return NULL rather than a dummy image 176 ILF_Exact = 0x0002, // type must be exactly the same 177 ILF_NoNew = 0x0004, // image must already exist (don't create it) 178 ILF_Font = 0x0008, // font character (be careful with backups) 179 } 180 image_lookup_flags_e; 181 182 const image_c *W_ImageLookup(const char *name, image_namespace_e = INS_Graphic, 183 int flags = 0); 184 185 const image_c *W_ImageForDummySprite(void); 186 const image_c *W_ImageForDummySkin(void); 187 const image_c *W_ImageForHOMDetect(void); 188 189 // savegame code (Only) 190 const image_c *W_ImageParseSaveString(char type, const char *name); 191 void W_ImageMakeSaveString(const image_c *image, char *type, char *namebuf); 192 193 194 // 195 // IMAGE USAGE 196 // 197 198 extern int var_mipmapping; 199 extern int var_smoothing; 200 extern bool var_dithering; 201 extern int hq2x_scaling; 202 203 bool W_InitImages(void); 204 void W_UpdateImageAnims(void); 205 void W_DeleteAllImages(void); 206 207 void W_ImageCreateFlats(int *lumps, int number); 208 void W_ImageCreateTextures(struct texturedef_s ** defs, int number); 209 const image_c *W_ImageCreateSprite(const char *name, int lump, bool is_weapon); 210 void W_ImageCreateUser(void); 211 void W_ImageAddTX(int lump, const char *name, bool hires); 212 void W_AnimateImageSet(const image_c ** images, int number, int speed); 213 void W_DrawSavePic(const byte *pixels); 214 215 #ifdef USING_GL_TYPES 216 GLuint W_ImageCache(const image_c *image, bool anim = true, 217 const colourmap_c *trans = NULL); 218 #endif 219 void W_ImagePreCache(const image_c *image); 220 221 222 // -AJA- planned.... 223 // rgbcol_t W_ImageGetHue(const image_c *c); 224 225 const char *W_ImageGetName(const image_c *image); 226 227 // this only needed during initialisation -- r_things.cpp 228 const image_c ** W_ImageGetUserSprites(int *count); 229 230 // internal routines -- only needed by rgl_wipe.c 231 int W_MakeValidSize(int value); 232 233 234 typedef enum 235 { 236 // Source was a graphic name 237 IMSRC_Graphic = 0, 238 239 // INTERNAL ONLY: Source was a raw block of 320x200 bytes (Heretic/Hexen) 240 IMSRC_Raw320x200, 241 242 // Source was a sprite name 243 IMSRC_Sprite, 244 245 // Source was a flat name 246 IMSRC_Flat, 247 248 // Source was a texture name 249 IMSRC_Texture, 250 251 // INTERNAL ONLY: Source is from IMAGE.DDF 252 IMSRC_User, 253 254 // INTERNAL ONLY: Source is from TX_START/END or HI_START/END 255 IMSRC_TX_HI, 256 257 // INTERNAL ONLY: Source is dummy image 258 IMSRC_Dummy, 259 } 260 image_source_e; 261 262 263 #endif // __R_IMAGE__ 264 265 //--- editor settings --- 266 // vi:ts=4:sw=4:noexpandtab 267