palette.h

Go to the documentation of this file.
00001 /* === S Y N F I G ========================================================= */
00021 /* ========================================================================= */
00022 
00023 /* === S T A R T =========================================================== */
00024 
00025 #ifndef __SYNFIG_PALETTE_H
00026 #define __SYNFIG_PALETTE_H
00027 
00028 /* === H E A D E R S ======================================================= */
00029 
00030 #include "color.h"
00031 #include "string.h"
00032 #include <vector>
00033 
00034 /* === M A C R O S ========================================================= */
00035 
00036 /* === T Y P E D E F S ===================================================== */
00037 
00038 /* === C L A S S E S & S T R U C T S ======================================= */
00039 
00040 namespace synfig {
00041 
00042 class Surface;
00043 
00044 struct PaletteItem
00045 {
00046     Color color;
00047     String name;
00048     int weight;
00049 
00050     PaletteItem():weight(1) { }
00051 
00052     PaletteItem(const Color& color, const String& name, int weight=1):
00053         color(color),name(name),weight(weight) { }
00054 
00055     PaletteItem(const Color& color, int weight=1):
00056         color(color),weight(weight) { }
00057 
00058     void add(const Color& x, int weight=1);
00059 
00060     bool operator<(const PaletteItem& rhs)const { return weight<rhs.weight; }
00061 }; // END of struct PaletteItem
00062 
00063 class Palette : public std::vector<PaletteItem>
00064 {
00065     String name_;
00066 
00067 public:
00068     Palette();
00069     Palette(const String& name_);
00070 
00074     Palette(const Surface& surface, int size=256);
00075 
00076     iterator find_closest(const Color& color, float* dist=0);
00077     const_iterator find_closest(const Color& color, float* dist=0)const;
00078 
00079     iterator find_heavy();
00080 
00081     iterator find_light();
00082 
00083     static Palette grayscale(int steps=16);
00084 
00085     void save_to_file(const synfig::String& filename)const;
00086 
00087     static Palette load_from_file(const synfig::String& filename);
00088 }; // END of class Palette
00089 
00090 }; // END of namespace synfig
00091 
00092 /* === E N D =============================================================== */
00093 
00094 #endif

Generated on Wed Aug 15 05:00:23 2007 for synfig by  doxygen 1.5.3