1 /** \file
2  * \brief Palette Generators
3  *
4  * See Copyright Notice in im_lib.d
5  */
6 
7 module im.palette;
8 
9 extern (C) @safe nothrow:
10 
11 /** \defgroup palette Palette Generators
12  * \par
13  * Creates several standard palettes. The palette is just an array of encoded color values.
14  * See also \ref colorutl.
15  * \par
16  * In Lua, to create a palette you can call im.PaletteCreate.
17  * \verbatim im.PaletteCreate([count: number]) -> pal: imPalette [in Lua 5] \endverbatim
18  * Default count is 256.
19  * IMLua and CDLua palettes are 100% compatible. The IM palette metatable name is "imPalette". \n
20  * When converted to a string will return "imPalete(%p)" where %p is replaced by the userdata address.
21  * If the palette is already destroyed by im.PaletteDestroy, then it will return also the suffix "-destroyed".
22  * \par
23  * In Lua, to destroy a palette you can call im.PaletteDestroy.
24  * If this function is not called, the palette is destroyed by the garbage collector.
25  * \verbatim im.PaletteDestroy(pal: imPalette) [in Lua 5] \endverbatim
26  * \par
27  * In Lua, array access is enabled so you can do:.
28  * \verbatim color = pal[index] \endverbatim
29  * \verbatim pal[index] = color \endverbatim
30  * \verbatim count = #pal \endverbatim
31  * \par
32  * See \ref im_palette.h
33  * \ingroup util */
34 
35 
36 /** Allocates memory for the palette data.
37  * This ensures allocation and release in the same module by the correct functions.
38  * \ingroup palette */
39 long* imPaletteNew(int count);
40 
41 /** Releases memory for the palette data.
42  * This ensures allocation and release in the same module by the correct functions.
43  * \ingroup palette */
44 void imPaletteRelease(long* palette);
45 
46 /** Duplicate a palette data using imPaletteNew.
47  * \ingroup palette */
48 long* imPaletteDuplicate(const(long) * palette, int count);
49 
50 
51 /** Searches for the nearest color on the table and returns the color index if successful.
52  * It looks in all palette entries and finds the minimum euclidian square distance.
53  * If the color matches the given color it returns immediately.
54  * See also \ref colorutl.
55  *
56  * \verbatim im.PaletteFindNearest(pal: imPalette, color: lightuserdata) -> index: number [in Lua 5] \endverbatim
57  * \ingroup palette */
58 int imPaletteFindNearest(const(long) *palette, int palette_count, long color);
59 
60 /** Searches for the color on the table and returns the color index if successful.
61  * If the tolerance is 0 search for the exact match in the palette else search for the
62  * first color that fits in the tolerance range.
63  * See also \ref colorutl.
64  *
65  * \verbatim im.PaletteFindColor(pal: imPalette, color: lightuserdata, tol: number) -> index: number [in Lua 5] \endverbatim
66  * \ingroup palette */
67 int imPaletteFindColor(const(long) *palette, int palette_count, long color, ubyte tol);
68 
69 /** Creates a palette of gray scale values.
70  * The colors are arranged from black to white.
71  *
72  * \verbatim im.PaletteGray() -> pal: imPalette [in Lua 5] \endverbatim
73  * \ingroup palette */
74 long* imPaletteGray();
75 
76 /** Creates a palette of a gradient of red colors.
77  * The colors are arranged from black to pure red.
78  *
79  * \verbatim im.PaletteRed() -> pal: imPalette [in Lua 5] \endverbatim
80  * \ingroup palette */
81 long* imPaletteRed();
82 
83 /** Creates a palette of a gradient of green colors.
84  * The colors are arranged from black to pure green.
85  *
86  * \verbatim im.PaletteGreen() -> pal: imPalette [in Lua 5] \endverbatim
87  * \ingroup palette */
88 long* imPaletteGreen();
89 
90 /** Creates a palette of a gradient of blue colors.
91  * The colors are arranged from black to pure blue.
92  *
93  * \verbatim im.PaletteBlue() -> pal: imPalette [in Lua 5] \endverbatim
94  * \ingroup palette */
95 long* imPaletteBlue();
96 
97 /** Creates a palette of a gradient of yellow colors.
98  * The colors are arranged from black to pure yellow.
99  *
100  * \verbatim im.PaletteYellow() -> pal: imPalette [in Lua 5] \endverbatim
101  * \ingroup palette */
102 long* imPaletteYellow();
103 
104 /** Creates a palette of a gradient of magenta colors.
105  * The colors are arranged from black to pure magenta.
106  *
107  * \verbatim im.PaletteMagenta() -> pal: imPalette [in Lua 5] \endverbatim
108  * \ingroup palette */
109 long* imPaletteMagenta();
110 
111 /** Creates a palette of a gradient of cian colors.
112  * The colors are arranged from black to pure cian.
113  *
114  * \verbatim im.PaletteCian() -> pal: imPalette [in Lua 5] \endverbatim
115  * \ingroup palette */
116 long* imPaletteCian();
117 
118 /** Creates a palette of rainbow colors.
119  * The colors are arranged in the light wave length spectrum order (starting from purple).
120  *
121  * \verbatim im.PaletteRainbow() -> pal: imPalette [in Lua 5] \endverbatim
122  * \ingroup palette */
123 long* imPaletteRainbow();
124 
125 /** Creates a palette of hues with maximum saturation.
126  *
127  * \verbatim im.PaletteHues() -> pal: imPalette [in Lua 5] \endverbatim
128  * \ingroup palette */
129 long* imPaletteHues();
130 
131 /** Creates a palette of a gradient of blue colors.
132  * The colors are arranged from pure blue to white.
133  *
134  * \verbatim im.PaletteBlueIce() -> pal: imPalette [in Lua 5] \endverbatim
135  * \ingroup palette */
136 long* imPaletteBlueIce();
137 
138 /** Creates a palette of a gradient from black to white passing trough red and orange.
139  *
140  * \verbatim im.PaletteHotIron() -> pal: imPalette [in Lua 5] \endverbatim
141  * \ingroup palette */
142 long* imPaletteHotIron();
143 
144 /** Creates a palette of a gradient from black to white passing trough red and yellow.
145  *
146  * \verbatim im.PaletteBlackBody() -> pal: imPalette [in Lua 5] \endverbatim
147  * \ingroup palette */
148 long* imPaletteBlackBody();
149 
150 /** Creates a palette with high contrast colors.
151  *
152  * \verbatim im.PaletteHighContrast() -> pal: imPalette [in Lua 5] \endverbatim
153  * \ingroup palette */
154 long* imPaletteHighContrast();
155 
156 /** Creates a palette of a sequence of colors from black to white
157  *  with 32 linear intensity values combined with 8 hue variations.
158  *
159  * \verbatim im.PaletteLinear() -> pal: imPalette [in Lua 5] \endverbatim
160  * \ingroup palette */
161 long* imPaletteLinear();
162 
163 /** Creates a palette of an uniform sub-division of colors from black to white.
164 *  This is a 2^(2.6) bits per pixel palette.
165 *
166 * \verbatim im.PaletteUniform() -> pal: imPalette [in Lua 5] \endverbatim
167 * \ingroup palette */
168 long* imPaletteUniform();
169 
170 /** Returns the index of the correspondent RGB color of an uniform palette.
171  *
172  * \verbatim im.PaletteUniformIndex(color: lightuserdata) -> index: number [in Lua 5] \endverbatim
173  * \ingroup palette */
174 int imPaletteUniformIndex(long color);
175 
176 /** Returns the index of the correspondent RGB color of an uniform palette.
177  * Uses an 8x8 ordered dither to lookup the index in a halftone matrix.
178  * The spatial position used by the halftone method.
179  *
180  * \verbatim im.PaletteUniformIndexHalftoned(color: lightuserdata, x: number, y: number) -> index: number [in Lua 5] \endverbatim
181  * \ingroup palette */
182 int imPaletteUniformIndexHalftoned(long color, int x, int y);