csgfx/quantize.h
Go to the documentation of this file.00001 /* 00002 RGB to paletted image quantization routine 00003 Copyright (C) 2000 by Andrew Zabolotny <[email protected]> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_QUANTIZE_H__ 00021 #define __CS_QUANTIZE_H__ 00022 00031 #include "csextern.h" 00032 00033 #include "csgfx/rgbpixel.h" 00034 00035 struct csColorBox; 00036 00129 class CS_CRYSTALSPACE_EXPORT csColorQuantizer 00130 { 00131 private: 00132 friend struct csColorBox; 00133 struct ColorIndex 00134 { 00135 int index; 00136 csColorBox* box; 00137 00138 ColorIndex() : box(0) {} 00139 }; 00140 00141 // The storage for color usage histogram. 00142 uint16 *hist; 00143 // Total number of colors that were used to create the histogram. 00144 unsigned int hist_pixels; 00145 00146 // The storage for color space boxes. 00147 csColorBox *box; 00148 // Number of valid color boxes. 00149 int boxcount; 00150 // The storage for color indices. 00151 ColorIndex* color_index; 00152 00153 // The state of quantization variables 00154 enum 00155 { 00156 // Uninitialized: initial state 00157 qsNone, 00158 // Counting color frequencies 00159 qsCount, 00160 // Remapping input images to output 00161 qsRemap 00162 } qState; 00163 00164 static int compare_boxes (const void *i1, const void *i2); 00165 00166 public: 00168 csColorQuantizer (); 00170 ~csColorQuantizer (); 00171 00194 void DoRGB (csRGBpixel *image, int pixels, int pixperline, 00195 uint8 *&outimage, csRGBpixel *&outpalette, int &maxcolors, bool dither); 00196 00198 void Begin (); 00200 void End (); 00202 void Count (csRGBpixel *image, int pixels, csRGBpixel *transp = 0); 00204 void Bias (csRGBpixel *colors, int count, int weight); 00206 void Palette (csRGBpixel *&outpalette, int &maxcolors, 00207 csRGBpixel *transp = 0); 00209 void Remap (csRGBpixel *image, int pixels, uint8 *&outimage, 00210 csRGBpixel *transp = 0); 00212 void RemapDither (csRGBpixel *image, int pixels, int pixperline, 00213 csRGBpixel *palette, int colors, uint8 *&outimage, 00214 csRGBpixel *transp = 0); 00215 }; 00216 00219 #endif // __CS_QUANTIZE_H__
Generated for Crystal Space by doxygen 1.4.7