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

Last change on this file since 682 was 653, checked in by Sam Hocevar, 9 years ago

imlib: remove unused code and tag unused method arguments.

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