CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

quantize.h

Go to the documentation of this file.
00001 /*
00002     RGB to paletted image quantization routine
00003     Copyright (C) 2000 by Andrew Zabolotny <bit@eltech.ru>
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 
00034 #include "csgfx/rgbpixel.h"
00035 
00036 struct csColorBox;
00037 
00130 class csColorQuantizer
00131 {
00132 private:
00133   friend struct csColorBox;
00134 
00135   // The storage for color usage histogram.
00136   uint16 *hist;
00137   // Total number of colors that were used to create the histogram.
00138   unsigned int hist_pixels;
00139 
00140   // The storage for color space boxes.
00141   csColorBox *box;
00142   // Number of valid color boxes.
00143   int boxcount;
00144   // The storage for color indices.
00145   uint8 *color_index;
00146 
00147   // The state of quantization variables
00148   enum
00149   {
00150     // Uninitialized: initial state
00151     qsNone,
00152     // Counting color frequencies
00153     qsCount,
00154     // Remapping input images to output
00155     qsRemap
00156   } qState;
00157 
00158   static int compare_boxes (const void *i1, const void *i2);
00159 
00160 public:
00162   csColorQuantizer ();
00164   ~csColorQuantizer ();
00165 
00188   void DoRGB (csRGBpixel *image, int pixels, int pixperline,
00189     uint8 *&outimage, csRGBpixel *&outpalette, int &maxcolors, bool dither);
00190 
00192   void Begin ();
00194   void End ();
00196   void Count (csRGBpixel *image, int pixels, csRGBpixel *transp = NULL);
00198   void Bias (csRGBpixel *colors, int count, int weight);
00200   void Palette (csRGBpixel *&outpalette, int &maxcolors,
00201     csRGBpixel *transp = NULL);
00203   void Remap (csRGBpixel *image, int pixels, uint8 *&outimage,
00204     csRGBpixel *transp = NULL);
00206   void RemapDither (csRGBpixel *image, int pixels, int pixperline,
00207     csRGBpixel *palette, int colors, uint8 *&outimage,
00208     csRGBpixel *transp = NULL);
00209 };
00210 
00213 #endif // __CS_QUANTIZE_H__

Generated for Crystal Space by doxygen 1.2.14