Odamex
Setting the Standard in Multiplayer Doom
common/v_palette.h
Go to the documentation of this file.
00001 // Emacs style mode select   -*- C++ -*- 
00002 //-----------------------------------------------------------------------------
00003 //
00004 // $Id: v_palette.h 1788 2010-08-24 04:42:57Z russellrice $
00005 //
00006 // Copyright (C) 1998-2006 by Randy Heit (ZDoom 1.22).
00007 // Copyright (C) 2006-2010 by The Odamex Team.
00008 //
00009 // This program is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU General Public License
00011 // as published by the Free Software Foundation; either version 2
00012 // of the License, or (at your option) any later version.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // DESCRIPTION:
00020 //      V_PALETTE
00021 //
00022 //-----------------------------------------------------------------------------
00023 
00024 #ifndef __V_PALETTE_H__
00025 #define __V_PALETTE_H__
00026 
00027 #include "doomtype.h"
00028 
00029 #define MAKERGB(r,g,b)          (((r)<<16)|((g)<<8)|(b))
00030 #define MAKEARGB(a,r,g,b)       (((a)<<24)|((r)<<16)|((g)<<8)|(b))
00031 
00032 #define APART(c)                        (((c)>>24)&0xff)
00033 #define RPART(c)                        (((c)>>16)&0xff)
00034 #define GPART(c)                        (((c)>>8)&0xff)
00035 #define BPART(c)                        ((c)&0xff)
00036 
00037 struct palette_s {
00038         struct palette_s *next, *prev;
00039 
00040         union {
00041                 // Which of these is used is determined by screen.is8bit
00042 
00043                 byte            *colormaps;             // Colormaps for 8-bit graphics
00044                 DWORD           *shades;                // ARGB8888 values for 32-bit graphics
00045         } maps;
00046         byte                    *colormapsbase;
00047         union {
00048                 char            name[8];
00049                 int                     nameint[2];
00050         } name;
00051         DWORD                   *colors;                // gamma corrected colors
00052         DWORD                   *basecolors;    // non-gamma corrected colors
00053         unsigned                numcolors;
00054         unsigned                flags;
00055         unsigned                shadeshift;
00056         int                             usecount;
00057 };
00058 typedef struct palette_s palette_t;
00059 
00060 // Generate shading ramps for lighting
00061 #define PALETTEB_SHADE          (0)
00062 #define PALETTEF_SHADE          (1<<PALETTEB_SHADE)
00063 
00064 // Apply blend color specified in V_SetBlend()
00065 #define PALETTEB_BLEND          (1)
00066 #define PALETTEF_BLEND          (1<<PALETTEB_SHADE)
00067 
00068 // Default palette when none is specified (Do not set directly!)
00069 #define PALETTEB_DEFAULT        (30)
00070 #define PALETTEF_DEFAULT        (1<<PALETTEB_DEFAULT)
00071 
00072 
00073 
00074 // Type values for LoadAttachedPalette():
00075 #define LAP_PALETTE                     (~0)    // Just pass thru to LoadPalette()
00076 #define LAP_PATCH                       (0)
00077 #define LAP_SPRITE                      (1)
00078 #define LAP_FLAT                        (2)
00079 #define LAP_TEXTURE                     (3)
00080 
00081 
00082 struct dyncolormap_s {
00083         byte *maps;
00084         unsigned int color;
00085         unsigned int fade;
00086         struct dyncolormap_s *next;
00087 };
00088 typedef struct dyncolormap_s dyncolormap_t;
00089 
00090 
00091 // InitPalettes()
00092 //      input: name:  the name of the default palette lump
00093 //                                (normally GAMEPAL)
00094 //
00095 // Returns a pointer to the default palette.
00096 palette_t *InitPalettes (const char *name);
00097 
00098 // GetDefaultPalette()
00099 //
00100 //      Returns the palette created through InitPalettes()
00101 palette_t *GetDefaultPalette (void);
00102 
00103 //
00104 // V_RestoreScreenPalette
00105 //
00106 // Restore original screen palette from current gamma level
00107 void V_RestoreScreenPalette(void);
00108 
00109 // MakePalette()
00110 //      input: colors: ptr to 256 3-byte RGB values
00111 //                 name:   the palette's name (not checked for duplicates)
00112 //                 flags:  the flags for the new palette
00113 //
00114 palette_t *MakePalette (byte *colors, char *name, unsigned flags);
00115 
00116 // LoadPalette()
00117 //      input: name:  the name of the palette lump
00118 //                 flags: the flags for the palette
00119 //
00120 //      This function will try and find an already loaded
00121 //      palette and return that if possible.
00122 palette_t *LoadPalette (char *name, unsigned flags);
00123 
00124 // LoadAttachedPalette()
00125 //      input: name:  the name of a graphic whose palette should be loaded
00126 //                 type:  the type of graphic whose palette is being requested
00127 //                 flags: the flags for the palette
00128 //
00129 //      This function looks through the PALETTES lump for a palette
00130 //      associated with the given graphic and returns that if possible.
00131 palette_t *LoadAttachedPalette (char *name, int type, unsigned flags);
00132 
00133 // FreePalette()
00134 //      input: palette: the palette to free
00135 //
00136 //      This function decrements the palette's usecount and frees it
00137 //      when it hits zero.
00138 void FreePalette (palette_t *palette);
00139 
00140 // FindPalette()
00141 //      input: name:  the name of the palette
00142 //                 flags: the flags to match on (~0 if it doesn't matter)
00143 //
00144 palette_t *FindPalette (char *name, unsigned flags);
00145 
00146 // RefreshPalette()
00147 //      input: pal: the palette to refresh
00148 //
00149 // Generates all colormaps or shadings for the specified palette
00150 // with the current blending levels.
00151 void RefreshPalette (palette_t *pal);
00152 
00153 // RefreshPalettes()
00154 //
00155 // Calls RefreshPalette() for all palettes.
00156 void RefreshPalettes (void);
00157 
00158 // GammaAdjustPalette()
00159 //
00160 // Builds the colors table for the specified palette based
00161 // on the current gamma correction setting. It will not rebuild
00162 // the shading table if the palette has one.
00163 void GammaAdjustPalette (palette_t *pal);
00164 
00165 // GammaAdjustPalettes()
00166 //
00167 // Calls GammaAdjustPalette() for all palettes.
00168 void GammaAdjustPalettes (void);
00169 
00170 // V_SetBlend()
00171 //      input: blendr: red component of blend
00172 //                 blendg: green component of blend
00173 //                 blendb: blue component of blend
00174 //                 blenda: alpha component of blend
00175 //
00176 // Applies the blend to all palettes with PALETTEF_BLEND flag
00177 void V_SetBlend (int blendr, int blendg, int blendb, int blenda);
00178 
00179 // V_ForceBlend()
00180 //
00181 // Normally, V_SetBlend() does nothing if the new blend is the
00182 // same as the old. This function will performing the blending
00183 // even if the blend hasn't changed.
00184 void V_ForceBlend (int blendr, int blendg, int blendb, int blenda);
00185 
00186 
00187 // Colorspace conversion RGB <-> HSV
00188 void RGBtoHSV (float r, float g, float b, float *h, float *s, float *v);
00189 void HSVtoRGB (float *r, float *g, float *b, float h, float s, float v);
00190 
00191 dyncolormap_t *GetSpecialLights (int lr, int lg, int lb, int fr, int fg, int fb);
00192 
00193 #endif //__V_PALETTE_H__
00194 
00195 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends