00001
00021
00022
00023
00024
00025 #ifndef __SYNFIG_PALETTE_H
00026 #define __SYNFIG_PALETTE_H
00027
00028
00029
00030 #include "color.h"
00031 #include "string.h"
00032 #include <vector>
00033
00034
00035
00036
00037
00038
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 };
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 };
00089
00090 };
00091
00092
00093
00094 #endif