source: abuse/trunk/src/imlib/palette.h @ 481

Last change on this file since 481 was 481, checked in by Sam Hocevar, 11 years ago

Fuck the history, I'm renaming all .hpp files to .h for my own sanity.

  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *
5 *  This software was released into the Public Domain. As with most public
6 *  domain software, no warranty is made or implied by Crack dot Com or
7 *  Jonathan Clark.
8 */
9
10#ifndef _PALETTE_H_
11#define _PALETTE_H_
12#include "linked.h"
13#include "specs.h"
14#define COLOR_BITS 6    // On PC-6, most others -8
15#define COLOR_SHIFT (8-COLOR_BITS)
16#define MAX_COLOR ((1<<COLOR_BITS)-1)
17#define RED3(x)  (unsigned char) ((((int)x&(7<<5))>>5)*(int)255/(int)7)
18#define GREEN3(x) (unsigned char) (((x&(7<<2))>>2)*(int)255/(int)7)
19#define BLUE2(x) (unsigned char) ((x&3)*(int)255/(int)3)
20
21
22struct color
23{
24  unsigned char red,green,blue;
25} ;
26
27class palette : public linked_node
28{
29  color *pal;
30  unsigned char *usd;           // bit array
31  short ncolors;
32  int bg;
33public :
34  palette(int number_colors=256);
35  palette(spec_entry *e, bFILE *fp);
36  palette(bFILE *fp);
37  void set(int x, unsigned char red, unsigned char green, unsigned char blue);
38  void get(int x, unsigned char &red, unsigned char &green, unsigned char &blue);
39  uint32_t getquad(int x);
40  unsigned int red(int x) { return pal[x].red; }
41  unsigned int green(int x) { return pal[x].green; }
42  unsigned int blue(int x) { return pal[x].blue; }
43  void *addr() { return (void *) pal; }
44  void shift(int amount);
45  void load();
46  void load_nice();
47  void fade_to(int total_fades, int fade_on, int dest_r, int dest_g, int dest_b);
48
49  void defaults();
50  void set_rgbs();
51  void make_black_white();
52  void black_white();
53
54  int pal_size() { return ncolors; }
55  void set_used(int color_num);
56  void set_unused(int color_num);
57  int used(int color_num);
58  void set_all_used();
59  void set_all_unused();
60  void set_background(unsigned char b)  { bg=b; }
61  int background(unsigned char b)  { return bg; }
62  int add_color(unsigned int r, unsigned int g, unsigned int b,
63             int closest_only=0);
64  int find_color(unsigned char r, unsigned char g, unsigned char b);
65  int find_closest(unsigned char r, unsigned char g, unsigned char b);
66  int find_closest_non0(unsigned char r, unsigned char g, unsigned char b);
67  palette *copy();
68  unsigned char brightest(int all=0);
69  unsigned char darkest(int all=0, int noblack=1);
70  int write(bFILE *fp);
71  int size();
72  ~palette();
73} ;
74
75class quant_node : public linked_node
76{
77  quant_node *padre;
78public :
79  unsigned tot;
80  quant_node *children[8];
81  int is_leaf() { return children[0]==this; }
82  void be_childish() { children[0]=this; }
83  quant_node *father() { return padre; }
84  quant_node(int level, quant_node *dad,
85    unsigned char r=0, unsigned char g=0, unsigned char b=0);
86  void total(int &tnodes, int &tr, int &tg, int &tb);
87//  void prune();
88  void set(int r,int g,int b) {red=r; green=g; blue=b; }
89  unsigned char red,green,blue;
90  ~quant_node();
91} ;
92
93
94class quant_palette
95{
96  linked_list level[8];
97  quant_node *root;
98  int nc,mx;
99  void prune();
100  void re_delete(quant_node *who, int lev);
101public :
102  void add_color(unsigned char r, unsigned char g, unsigned char b);
103  quant_palette(int max_colors=256);
104  palette *create_pal();
105  ~quant_palette();
106} ;
107
108palette *last_loaded();
109#endif
Note: See TracBrowser for help on using the repository browser.