1 /* 2 ** v_palette.h 3 ** 4 **--------------------------------------------------------------------------- 5 ** Copyright 1998-2006 Randy Heit 6 ** All rights reserved. 7 ** 8 ** Redistribution and use in source and binary forms, with or without 9 ** modification, are permitted provided that the following conditions 10 ** are met: 11 ** 12 ** 1. Redistributions of source code must retain the above copyright 13 ** notice, this list of conditions and the following disclaimer. 14 ** 2. Redistributions in binary form must reproduce the above copyright 15 ** notice, this list of conditions and the following disclaimer in the 16 ** documentation and/or other materials provided with the distribution. 17 ** 3. The name of the author may not be used to endorse or promote products 18 ** derived from this software without specific prior written permission. 19 ** 20 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 **--------------------------------------------------------------------------- 31 ** 32 */ 33 34 #ifndef __V_PALETTE_H__ 35 #define __V_PALETTE_H__ 36 37 #include "wl_def.h" 38 #include "tarray.h" 39 40 #define MAKERGB(r,g,b) DWORD(((r)<<16)|((g)<<8)|(b)) 41 #define MAKEARGB(a,r,g,b) DWORD(((a)<<24)|((r)<<16)|((g)<<8)|(b)) 42 43 #define APART(c) (((c)>>24)&0xff) 44 #define RPART(c) (((c)>>16)&0xff) 45 #define GPART(c) (((c)>>8)&0xff) 46 #define BPART(c) ((c)&0xff) 47 48 struct PalEntry 49 { PalEntryPalEntry50 PalEntry () {} PalEntryPalEntry51 PalEntry (uint32 argb) { d = argb; } uint32PalEntry52 operator uint32 () const { return d; } 53 PalEntry &operator= (uint32 other) { d = other; return *this; } InverseColorPalEntry54 PalEntry InverseColor() const { PalEntry nc; nc.a = a; nc.r = 255 - r; nc.g = 255 - g; nc.b = 255 - b; return nc; } 55 #ifdef __BIG_ENDIAN__ PalEntryPalEntry56 PalEntry (BYTE ir, BYTE ig, BYTE ib) : a(0), r(ir), g(ig), b(ib) {} PalEntryPalEntry57 PalEntry (BYTE ia, BYTE ir, BYTE ig, BYTE ib) : a(ia), r(ir), g(ig), b(ib) {} 58 union 59 { 60 struct 61 { 62 BYTE a,r,g,b; 63 }; 64 uint32 d; 65 }; 66 #else PalEntryPalEntry67 PalEntry (BYTE ir, BYTE ig, BYTE ib) : b(ib), g(ig), r(ir), a(0) {} PalEntryPalEntry68 PalEntry (BYTE ia, BYTE ir, BYTE ig, BYTE ib) : b(ib), g(ig), r(ir), a(ia) {} 69 union 70 { 71 struct 72 { 73 BYTE b,g,r,a; 74 }; 75 uint32 d; 76 }; 77 #endif 78 }; 79 80 struct FPalette 81 { 82 FPalette (); 83 FPalette (const BYTE *colors); 84 85 void SetPalette (const BYTE *colors); 86 87 void MakeGoodRemap (); 88 89 PalEntry BaseColors[256]; // non-gamma corrected palette 90 BYTE Remap[256]; // remap original palette indices to in-game indices 91 92 BYTE WhiteIndex; // white in original palette index 93 BYTE BlackIndex; // black in original palette index 94 95 // Given an array of colors, fills in remap with values to remap the 96 // passed array of colors to this palette. 97 void MakeRemap (const DWORD *colors, BYTE *remap, const BYTE *useful, int numcolors) const; 98 }; 99 100 extern FPalette GPalette; 101 // The color overlay to use for depleted items 102 #define DIM_OVERLAY MAKEARGB(170,0,0,0) 103 104 int BestColor (const uint32 *pal, int r, int g, int b, int first=1, int num=255); 105 void DoBlending (const PalEntry *from, PalEntry *to, int count, int r, int g, int b, int a); 106 107 void InitPalette (const char* defpalette); 108 109 // V_SetBlend() 110 // input: blendr: red component of blend 111 // blendg: green component of blend 112 // blendb: blue component of blend 113 // blenda: alpha component of blend 114 // 115 // Applies the blend to all palettes with PALETTEF_BLEND flag 116 void V_SetBlend (int blendr, int blendg, int blendb, int blenda); 117 118 // V_ForceBlend() 119 // 120 // Normally, V_SetBlend() does nothing if the new blend is the 121 // same as the old. This function will perform the blending 122 // even if the blend hasn't changed. 123 void V_ForceBlend (int blendr, int blendg, int blendb, int blenda); 124 125 126 // Colorspace conversion RGB <-> HSV 127 void RGBtoHSV (float r, float g, float b, float *h, float *s, float *v); 128 void HSVtoRGB (float *r, float *g, float *b, float h, float s, float v); 129 130 #endif //__V_PALETTE_H__ 131