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 // Additional authors: John Scipione, <jscipione@gmail.com> 17 18 #ifndef SAVE_PALETTE_H 19 #define SAVE_PALETTE_H 20 21 22 #include "SFHash.h" 23 #include <GraphicsDefs.h> 24 25 enum { 26 WEB_SAFE_PALETTE = 0, 27 BEOS_SYSTEM_PALETTE, 28 GREYSCALE_PALETTE, 29 OPTIMAL_PALETTE 30 }; 31 32 enum { 33 NO_TRANSPARENCY = 0, 34 AUTO_TRANSPARENCY, 35 COLOR_KEY_TRANSPARENCY 36 }; 37 38 39 class BBitmap; 40 41 class SavePalette { 42 public: 43 SavePalette(int mode); 44 SavePalette(BBitmap* bitmap, 45 int32 maxSizeInBits = 8); 46 virtual ~SavePalette(); 47 48 inline bool IsValid() const 49 { return !fFatalError; } 50 51 uint8 IndexForColor(uint8 red, uint8 green, 52 uint8 blue, uint8 alpha = 255); 53 inline uint8 IndexForColor(const rgb_color& color); 54 55 inline bool UseTransparent() const 56 { return fTransparentMode > NO_TRANSPARENCY; } 57 58 void PrepareForAutoTransparency(); 59 inline int TransparentIndex() const 60 { return fTransparentIndex; } 61 void SetTransparentColor(uint8 red, 62 uint8 green, uint8 blue); 63 64 inline int SizeInBits() const { return fSizeInBits; } 65 66 inline int BackgroundIndex() const 67 { return fBackgroundIndex; } 68 69 void GetColors(uint8* buffer, int size) const; 70 71 rgb_color* pal; 72 73 private: 74 int fSize; 75 int fSizeInBits; 76 int fMode; 77 uint32 fTransparentMode; 78 int fTransparentIndex; 79 int fBackgroundIndex; 80 bool fFatalError; 81 }; 82 83 84 inline uint8 85 SavePalette::IndexForColor(const rgb_color& color) 86 { 87 return IndexForColor(color.red, color.green, color.blue, color.alpha); 88 } 89 90 91 #endif // SAVE_PALETTE_H 92