1 #pragma once
2 #include "studiox_includes.h"
3 
4 #define HIST_RED_BITS 5
5 #define HIST_GREEN_BITS 6
6 #define HIST_BLUE_BITS 5
7 
8 #define HIST_RED_SHIFT   3
9 #define HIST_GREEN_SHIFT 2
10 #define HIST_BLUE_SHIFT  3
11 
12 #define RED_SCALE 2    // scale red distance by this much
13 #define GREEN_SCALE 3  // scale green distance by this much
14 #define BLUE_SCALE 1
15 
16 typedef struct{
17     int  rmin;
18     int  rmax;
19     int  gmin;
20     int  gmax;
21     int  bmin;
22     int  bmax;
23     int  volume;//color volume
24     long color_count;//color population
25 }BOX;
26 
27 
28 class palette_creater
29 {
30 public:
31     palette_creater();
32     ~palette_creater();
33 
34 public:
35     void CreatePaletteForOnePixelmap(res_info *resource, palette_info *info, int count = -1);
36     void CreatePaletteForPixelmaps(res_info *resource, palette_info *info, BOOL recursive = TRUE, int count = -1);
37 
38 protected:
39     BOX *FindLargestColorPop(int numboxes);
40     BOX *FindLargestColorVolume(int numboxes);
41     void UpdateBox(BOX *boxp);
42     void AccumulateSharedHistogram(res_info *info);
43     void AccumulateOneMapHistogram(res_info *info);
44     int  median_cut(int desired_colors_num);
45     void ComputeColor(palette_info *info, BOX *boxp, int index);
46 
47 private:
48     ULONG *histogram;
49     BOX   *boxlist;
50 };
51 
52