Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_03 / synfig-core / src / synfig / palette.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file Palette.h
3 **      \brief Template Header
4 **
5 **      $Id: palette.h,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_PALETTE_H
26 #define __SYNFIG_PALETTE_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include "color.h"
31 #include "string.h"
32 #include <vector>
33
34 /* === M A C R O S ========================================================= */
35
36 /* === T Y P E D E F S ===================================================== */
37
38 /* === C L A S S E S & S T R U C T S ======================================= */
39
40 namespace synfig {
41
42 class Surface;
43         
44 struct PaletteItem
45 {
46         Color color;
47         String name;
48         int weight;
49         
50         PaletteItem():weight(1) { }
51
52         PaletteItem(const Color& color, const String& name, int weight=1):
53                 color(color),name(name),weight(weight) { }
54
55         PaletteItem(const Color& color, int weight=1):
56                 color(color),weight(weight) { }
57                 
58         void add(const Color& x, int weight=1);
59                 
60         bool operator<(const PaletteItem& rhs)const { return weight<rhs.weight; }
61 }; // END of struct PaletteItem
62
63 class Palette : public std::vector<PaletteItem>
64 {
65         String name_;
66         
67 public:
68         Palette();
69         Palette(const String& name_);
70         
71         /*! Generates a palette for the given
72         **      surface
73         */
74         Palette(const Surface& surface, int size=256);
75
76         iterator find_closest(const Color& color, float* dist=0);
77         const_iterator find_closest(const Color& color, float* dist=0)const;
78
79         iterator find_heavy();
80         
81         iterator find_light();
82
83         static Palette grayscale(int steps=16);
84
85         void save_to_file(const synfig::String& filename)const;
86
87         static Palette load_from_file(const synfig::String& filename);
88 }; // END of class Palette
89
90 }; // END of namespace synfig
91
92 /* === E N D =============================================================== */
93
94 #endif