1 /* quantize.h: Quantize a high color bitmap
2 
3    Copyright (C) 2001, 2002 Martin Weber
4 
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public License
7    as published by the Free Software Foundation; either version 2.1 of
8    the License, or (at your option) any later version.
9 
10    This library is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18    USA. */
19 
20 #include "bitmap.h"
21 #include "color.h"
22 #include "exception.h"
23 
24 #ifndef QUANTIZE_H
25 #define QUANTIZE_H
26 
27 #define PRECISION_R 	7
28 #define PRECISION_G 	7
29 #define PRECISION_B 	7
30 
31 #define HIST_R_ELEMS 	(1<<PRECISION_R)
32 #define HIST_G_ELEMS 	(1<<PRECISION_G)
33 #define HIST_B_ELEMS 	(1<<PRECISION_B)
34 
35 #define MR 		HIST_G_ELEMS*HIST_B_ELEMS
36 #define MG 		HIST_B_ELEMS
37 
38 typedef unsigned long ColorFreq;
39 typedef ColorFreq *Histogram;
40 
41 typedef struct {
42     int             desired_number_of_colors; /* Number of colors we will allow */
43     int             actual_number_of_colors; /* Number of colors actually needed */
44     color_type      cmap[256]; /* colormap created by quantization */
45     ColorFreq       freq[256];
46     Histogram       histogram; /* holds the histogram */
47 } QuantizeObj;
48 
49 void quantize(bitmap_type*, long ncolors, const color_type *bgColor,
50     QuantizeObj**, at_exception_type * exp);
51 
52 void quantize_object_free(QuantizeObj * obj);
53 #endif /* NOT QUANTIZE_H */
54 
55