RgbToClut.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //**************************************************************************
  2. // FILENAME : RGBToClut.hpp
  3. //
  4. // CLASSES : RGBToClut
  5. //
  6. // DESCRIPTION : Convert an RGB image into an 8 bit indexed image
  7. // with a specific Color LookUp Table
  8. //
  9. // ECOMPACS DICOM Network Transport Libraries * Version 0.1 Beta
  10. //**************************************************************************
  11. #ifndef _RGBTOCLUT_
  12. #define _RGBTOCLUT_
  13. //**************************************************************************
  14. // CONSTANTS - ENUMERATED TYPES
  15. //**************************************************************************
  16. enum teClutSelect {fixedClut, popularity, mediancut};
  17. struct mycol
  18. {
  19. long nb;
  20. int r;
  21. int g;
  22. int b;
  23. };
  24. //**************************************************************************
  25. // class RGBToClut
  26. //**************************************************************************
  27. class RGBToClut
  28. {
  29. private:
  30. BOOL RGBPixmaps; // RGB image is composed by 3 separate pixmaps
  31. unsigned char * Pix; // 8 bit indexed image
  32. unsigned char * Rgb; // 8 bit RGB image
  33. unsigned char * Red; // 8 bit Red channel
  34. unsigned char * Green; // 8 bit Green channel
  35. unsigned char * Blue; // 8 bit Blue channel
  36. RGBQUAD * Colors;
  37. int Width;
  38. int Height;
  39. short *Histo;
  40. long NbCol; // number of colors in the histogram
  41. public:
  42. RGBToClut ();
  43. ~RGBToClut ();
  44. //**************************************************************************
  45. // Purpose: the 3 RGB channels are mixed in the same buffer
  46. // histo indicates if the color histogram must be compiled
  47. // this parameter allows to take into account several images
  48. // to compute the histogram which will be used to generate the color palette
  49. //**************************************************************************
  50. void SetRGBImage ( unsigned char * image,
  51. int width,
  52. int height,
  53. BOOL histo = TRUE);
  54. //**************************************************************************
  55. // Purpose: the 3 RGB channels are separated
  56. // histo indicates if the color histogram must be compiled
  57. // this parameter allows to take into account several images
  58. // to compute the histogram which will be used to generate the color palette
  59. //**************************************************************************
  60. void SetRGBImage ( unsigned char * RChannel,
  61. unsigned char * GChannel,
  62. unsigned char * BChannel,
  63. int width,
  64. int height,
  65. BOOL histo = TRUE);
  66. //**************************************************************************
  67. // Purpose: compute the indexed image according to the various parameters
  68. // image and myClut must have been allocated
  69. // return 0 if everything OK
  70. //**************************************************************************
  71. int ComputeIndexedImage(unsigned char * image,
  72. RGBQUAD * Colors,
  73. teClutSelect method = popularity);
  74. private:
  75. void ComputeHistogram (); // compute the histogram of the image
  76. void ConvertRGBToIndexed (); // convert the RGB image into an 8 bit indexed image
  77. void Popularity (); // select colors according to their popularity
  78. void MedianCut (); // select palette colors according to the median cut algorithm
  79. void UpdatePaletteHisto (); // try to put palette colors in an acceptable order
  80. void InitHisto (short val); // initialize histogram with val
  81. void InitClut (int val); // initialize clut with val
  82. short MatchColor (int r, int g, int b); // find the best indexed color for an RGB entry
  83. };
  84. #endif