//************************************************************************** // FILENAME : RGBToClut.hpp // // CLASSES : RGBToClut // // DESCRIPTION : Convert an RGB image into an 8 bit indexed image // with a specific Color LookUp Table // // ECOMPACS DICOM Network Transport Libraries * Version 0.1 Beta //************************************************************************** #ifndef _RGBTOCLUT_ #define _RGBTOCLUT_ //************************************************************************** // CONSTANTS - ENUMERATED TYPES //************************************************************************** enum teClutSelect {fixedClut, popularity, mediancut}; struct mycol { long nb; int r; int g; int b; }; //************************************************************************** // class RGBToClut //************************************************************************** class RGBToClut { private: BOOL RGBPixmaps; // RGB image is composed by 3 separate pixmaps unsigned char * Pix; // 8 bit indexed image unsigned char * Rgb; // 8 bit RGB image unsigned char * Red; // 8 bit Red channel unsigned char * Green; // 8 bit Green channel unsigned char * Blue; // 8 bit Blue channel RGBQUAD * Colors; int Width; int Height; short *Histo; long NbCol; // number of colors in the histogram public: RGBToClut (); ~RGBToClut (); //************************************************************************** // Purpose: the 3 RGB channels are mixed in the same buffer // histo indicates if the color histogram must be compiled // this parameter allows to take into account several images // to compute the histogram which will be used to generate the color palette //************************************************************************** void SetRGBImage ( unsigned char * image, int width, int height, BOOL histo = TRUE); //************************************************************************** // Purpose: the 3 RGB channels are separated // histo indicates if the color histogram must be compiled // this parameter allows to take into account several images // to compute the histogram which will be used to generate the color palette //************************************************************************** void SetRGBImage ( unsigned char * RChannel, unsigned char * GChannel, unsigned char * BChannel, int width, int height, BOOL histo = TRUE); //************************************************************************** // Purpose: compute the indexed image according to the various parameters // image and myClut must have been allocated // return 0 if everything OK //************************************************************************** int ComputeIndexedImage(unsigned char * image, RGBQUAD * Colors, teClutSelect method = popularity); private: void ComputeHistogram (); // compute the histogram of the image void ConvertRGBToIndexed (); // convert the RGB image into an 8 bit indexed image void Popularity (); // select colors according to their popularity void MedianCut (); // select palette colors according to the median cut algorithm void UpdatePaletteHisto (); // try to put palette colors in an acceptable order void InitHisto (short val); // initialize histogram with val void InitClut (int val); // initialize clut with val short MatchColor (int r, int g, int b); // find the best indexed color for an RGB entry }; #endif