source: abuse/trunk/src/imlib/include/palette.hpp @ 2

Last change on this file since 2 was 2, checked in by Sam Hocevar, 14 years ago
  • imported original 0.7.0 tarball
File size: 2.8 KB
Line 
1#ifndef _PALETTE_H_
2#define _PALETTE_H_
3#include "linked.hpp"
4#include "specs.hpp"
5#define COLOR_BITS 6    // On PC-6, most others -8
6#define COLOR_SHIFT (8-COLOR_BITS)
7#define MAX_COLOR ((1<<COLOR_BITS)-1)
8#define RED3(x)  (unsigned char) ((((int)x&(7<<5))>>5)*(int)255/(int)7)
9#define GREEN3(x) (unsigned char) (((x&(7<<2))>>2)*(int)255/(int)7)
10#define BLUE2(x) (unsigned char) ((x&3)*(int)255/(int)3)
11
12
13struct color
14{
15  unsigned char red,green,blue;
16} ;
17
18class palette : public linked_node
19{
20  color *pal;
21  unsigned char *usd;           // bit array
22  short ncolors;
23  int bg;
24public :
25  palette(int number_colors=256);
26  palette(spec_entry *e, bFILE *fp);
27  palette(bFILE *fp);
28  void set(int x, unsigned char red, unsigned char green, unsigned char blue);
29  void get(int x, unsigned char &red, unsigned char &green, unsigned char &blue);
30  long getquad(int x);
31  unsigned int red(int x) { return pal[x].red; }
32  unsigned int green(int x) { return pal[x].green; }
33  unsigned int blue(int x) { return pal[x].blue; }
34  void *addr() { return (void *) pal; }
35  void shift(int amount);
36  void load();
37  void load_nice();
38  void fade_to(int total_fades, int fade_on, int dest_r, int dest_g, int dest_b);
39
40  void defaults();
41  void set_rgbs();
42  void make_black_white();
43  void black_white();
44
45  int pal_size() { return ncolors; }
46  void set_used(int color_num);
47  void set_unused(int color_num);
48  int used(int color_num);
49  void set_all_used();
50  void set_all_unused();
51  void set_background(unsigned char b)  { bg=b; }
52  int background(unsigned char b)  { return bg; }
53  int add_color(unsigned int r, unsigned int g, unsigned int b,
54                 int closest_only=0);
55  int find_color(unsigned char r, unsigned char g, unsigned char b);
56  int find_closest(unsigned char r, unsigned char g, unsigned char b);
57  int find_closest_non0(unsigned char r, unsigned char g, unsigned char b);
58  palette *copy();
59  unsigned char brightest(int all=0);
60  unsigned char darkest(int all=0, int noblack=1);
61  int write(bFILE *fp);
62  int size();
63  ~palette();
64} ;
65
66class quant_node : public linked_node
67
68  quant_node *padre;
69public :
70  unsigned tot;
71  quant_node *children[8];
72  int is_leaf() { return children[0]==this; }
73  void be_childish() { children[0]=this; }
74  quant_node *father() { return padre; }
75  quant_node(int level, quant_node *dad,
76        unsigned char r=0, unsigned char g=0, unsigned char b=0);
77  void total(int &tnodes, int &tr, int &tg, int &tb);
78//  void prune();
79  void set(int r,int g,int b) {red=r; green=g; blue=b; }
80  unsigned char red,green,blue;
81  ~quant_node();
82} ;
83
84
85class quant_palette
86{
87  linked_list level[8];
88  quant_node *root;
89  int nc,mx;
90  void prune();
91  void re_delete(quant_node *who, int lev);
92public :
93  void add_color(unsigned char r, unsigned char g, unsigned char b);
94  quant_palette(int max_colors=256);
95  palette *create_pal();
96  ~quant_palette();
97} ;
98
99palette *last_loaded();
100#endif
Note: See TracBrowser for help on using the repository browser.