[56] | 1 | /* |
---|
| 2 | * Abuse - dark 2D side-scrolling platform game |
---|
| 3 | * Copyright (c) 1995 Crack dot Com |
---|
[494] | 4 | * Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
[56] | 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 or |
---|
| 8 | * Jonathan Clark. |
---|
| 9 | */ |
---|
| 10 | |
---|
[2] | 11 | #ifndef _PALETTE_H_ |
---|
| 12 | #define _PALETTE_H_ |
---|
[481] | 13 | #include "linked.h" |
---|
| 14 | #include "specs.h" |
---|
[2] | 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 | |
---|
| 23 | struct color |
---|
| 24 | { |
---|
| 25 | unsigned char red,green,blue; |
---|
| 26 | } ; |
---|
| 27 | |
---|
| 28 | class palette : public linked_node |
---|
| 29 | { |
---|
| 30 | color *pal; |
---|
| 31 | unsigned char *usd; // bit array |
---|
| 32 | short ncolors; |
---|
| 33 | int bg; |
---|
| 34 | public : |
---|
| 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); |
---|
[15] | 40 | uint32_t getquad(int x); |
---|
[2] | 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 | void set_background(unsigned char b) { bg=b; } |
---|
| 62 | int background(unsigned char b) { return bg; } |
---|
| 63 | int add_color(unsigned int r, unsigned int g, unsigned int b, |
---|
[124] | 64 | int closest_only=0); |
---|
[2] | 65 | int find_color(unsigned char r, unsigned char g, unsigned char b); |
---|
| 66 | int find_closest(unsigned char r, unsigned char g, unsigned char b); |
---|
| 67 | int find_closest_non0(unsigned char r, unsigned char g, unsigned char b); |
---|
| 68 | palette *copy(); |
---|
| 69 | unsigned char brightest(int all=0); |
---|
| 70 | unsigned char darkest(int all=0, int noblack=1); |
---|
| 71 | int write(bFILE *fp); |
---|
| 72 | int size(); |
---|
| 73 | ~palette(); |
---|
| 74 | } ; |
---|
| 75 | |
---|
| 76 | class quant_node : public linked_node |
---|
[124] | 77 | { |
---|
[2] | 78 | quant_node *padre; |
---|
| 79 | public : |
---|
| 80 | unsigned tot; |
---|
| 81 | quant_node *children[8]; |
---|
| 82 | int is_leaf() { return children[0]==this; } |
---|
| 83 | void be_childish() { children[0]=this; } |
---|
| 84 | quant_node *father() { return padre; } |
---|
| 85 | quant_node(int level, quant_node *dad, |
---|
[124] | 86 | unsigned char r=0, unsigned char g=0, unsigned char b=0); |
---|
[2] | 87 | void total(int &tnodes, int &tr, int &tg, int &tb); |
---|
| 88 | // void prune(); |
---|
[494] | 89 | void set(int r,int g,int b) { red=r; green=g; blue=b; } |
---|
[2] | 90 | unsigned char red,green,blue; |
---|
| 91 | ~quant_node(); |
---|
| 92 | } ; |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | class quant_palette |
---|
| 96 | { |
---|
| 97 | linked_list level[8]; |
---|
| 98 | quant_node *root; |
---|
| 99 | int nc,mx; |
---|
| 100 | void prune(); |
---|
| 101 | void re_delete(quant_node *who, int lev); |
---|
| 102 | public : |
---|
| 103 | void add_color(unsigned char r, unsigned char g, unsigned char b); |
---|
| 104 | quant_palette(int max_colors=256); |
---|
| 105 | palette *create_pal(); |
---|
| 106 | ~quant_palette(); |
---|
| 107 | } ; |
---|
| 108 | |
---|
| 109 | palette *last_loaded(); |
---|
| 110 | #endif |
---|