more updates
[synfig.git] / synfig-core / trunk / src / synfig / palette.h
1 /* === S I N F 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 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SINFG_PALETTE_H
25 #define __SINFG_PALETTE_H
26
27 /* === H E A D E R S ======================================================= */
28
29 #include "color.h"
30 #include "string.h"
31 #include <vector>
32
33 /* === M A C R O S ========================================================= */
34
35 /* === T Y P E D E F S ===================================================== */
36
37 /* === C L A S S E S & S T R U C T S ======================================= */
38
39 namespace sinfg {
40
41 class Surface;
42         
43 struct PaletteItem
44 {
45         Color color;
46         String name;
47         int weight;
48         
49         PaletteItem():weight(1) { }
50
51         PaletteItem(const Color& color, const String& name, int weight=1):
52                 color(color),name(name),weight(weight) { }
53
54         PaletteItem(const Color& color, int weight=1):
55                 color(color),weight(weight) { }
56                 
57         void add(const Color& x, int weight=1);
58                 
59         bool operator<(const PaletteItem& rhs)const { return weight<rhs.weight; }
60 }; // END of struct PaletteItem
61
62 class Palette : public std::vector<PaletteItem>
63 {
64         String name_;
65         
66 public:
67         Palette();
68         Palette(const String& name_);
69         
70         /*! Generates a palette for the given
71         **      surface
72         */
73         Palette(const Surface& surface, int size=256);
74
75         iterator find_closest(const Color& color, float* dist=0);
76         const_iterator find_closest(const Color& color, float* dist=0)const;
77
78         iterator find_heavy();
79         
80         iterator find_light();
81
82         static Palette grayscale(int steps=16);
83
84         void save_to_file(const sinfg::String& filename)const;
85
86         static Palette load_from_file(const sinfg::String& filename);
87 }; // END of class Palette
88
89 }; // END of namespace sinfg
90
91 /* === E N D =============================================================== */
92
93 #endif