1 //////////////////////////////////////////////////////////////////////////////// 2 // 3 // File: SavePalette.h 4 // 5 // Date: December 1999 6 // 7 // Author: Daniel Switkin 8 // 9 // Copyright 2003 (c) by Daniel Switkin. This file is made publically available 10 // under the BSD license, with the stipulations that this complete header must 11 // remain at the top of the file indefinitely, and credit must be given to the 12 // original author in any about box using this software. 13 // 14 //////////////////////////////////////////////////////////////////////////////// 15 16 #ifndef SAVE_PALETTE_H 17 #define SAVE_PALETTE_H 18 19 #include "SFHash.h" 20 #include <GraphicsDefs.h> 21 class BBitmap; 22 23 enum { 24 WEB_SAFE_PALETTE = 0, 25 BEOS_SYSTEM_PALETTE, 26 GREYSCALE_PALETTE, 27 OPTIMAL_PALETTE 28 }; 29 30 enum { 31 NO_TRANSPARENCY = 0, 32 AUTO_TRANSPARENCY, 33 COLOR_KEY_TRANSPARENCY 34 }; 35 36 class SavePalette { 37 public: 38 SavePalette(int mode); 39 SavePalette(BBitmap *bitmap, 40 int32 maxSizeInBits = 8); 41 virtual ~SavePalette(); 42 43 inline bool IsValid() const 44 { return !fFatalError; } 45 46 uint8 IndexForColor(uint8 red, uint8 green, 47 uint8 blue, uint8 alpha = 255); 48 inline uint8 IndexForColor(const rgb_color& color); 49 50 inline bool UseTransparent() const 51 { return fTransparentMode > NO_TRANSPARENCY; } 52 53 void PrepareForAutoTransparency(); 54 inline int TransparentIndex() const 55 { return fTransparentIndex; } 56 void SetTransparentColor(uint8 red, 57 uint8 green, 58 uint8 blue); 59 60 inline int SizeInBits() const 61 { return fSizeInBits; } 62 63 inline int BackgroundIndex() const 64 { return fBackgroundIndex; } 65 66 void GetColors(uint8* buffer, int size) const; 67 68 rgb_color* pal; 69 70 private: 71 int fSize; 72 int fSizeInBits; 73 int fMode; 74 uint32 fTransparentMode; 75 int fTransparentIndex; 76 int fBackgroundIndex; 77 bool fFatalError; 78 }; 79 80 // IndexForColor 81 inline uint8 82 SavePalette::IndexForColor(const rgb_color& color) 83 { 84 return IndexForColor(color.red, color.green, color.blue, color.alpha); 85 } 86 87 88 #endif 89 90 91