1 /* === C R E D I T S & D I S C L A I M E R S ==============
2 * Permission is given by the author to freely redistribute and include
3 * this code in any program as long as this credit is given where due.
5 * CQuantizer (c) 1996-1997 Jeff Prosise
7 * 31/08/2003 Davide Pizzolato - www.xdp.it
8 * - fixed minor bug in ProcessImage when bpp<=8
9 * - better color reduction to less than 16 colors
11 * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT
12 * WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT
13 * LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF DEFECTS,
14 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE
15 * RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE IS WITH YOU.
16 * SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL
17 * DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
18 * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN
19 * ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED
20 * HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
22 * Use at your own risk!
23 * ==========================================================
25 * Modified for use with Haiku by David Powell & Stephan Aßmus.
27 #ifndef COLOR_QUANTIZER_H
28 #define COLOR_QUANTIZER_H
31 #include <SupportDefs.h>
36 typedef struct _RGBA
{
43 class BColorQuantizer
{
45 BColorQuantizer(uint32 maxColors
,
47 virtual ~BColorQuantizer();
49 bool ProcessImage(const uint8
* const * rowPtrs
, int width
,
52 uint32
GetColorCount() const;
53 void GetColorTable(RGBA
* table
) const;
59 void _AddColor(Node
** _node
, uint8 r
, uint8 g
, uint8 b
,
60 uint8 a
, uint32 bitsPerColor
, uint32 level
,
61 uint32
* _leafCount
, Node
** reducibleNodes
);
62 Node
* _CreateNode(uint32 level
, uint32 bitsPerColor
,
63 uint32
* _leafCount
, Node
** reducibleNodes
);
64 void _ReduceTree(uint32 bitsPerColor
, uint32
* _leafCount
,
65 Node
** reducibleNodes
);
66 void _DeleteTree(Node
** _node
);
68 void _GetPaletteColors(Node
* node
, RGBA
* table
,
69 uint32
* pIndex
, uint32
* pSum
) const;
74 Node
* fReducibleNodes
[9];
76 uint32 fOutputMaxColors
;
80 } // namespace BPrivate
82 using BPrivate::BColorQuantizer
;
85 #endif // COLOR_QUANTIZER_H