[56] | 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 | |
---|
[2] | 10 | #ifndef _IMGAE_HPP_ |
---|
| 11 | #define _IMGAE_HPP_ |
---|
| 12 | #include <stdlib.h> |
---|
| 13 | #include "linked.hpp" |
---|
| 14 | #include "palette.hpp" |
---|
| 15 | #include "system.h" |
---|
| 16 | #include "specs.hpp" |
---|
| 17 | #define MAX_DIRTY 200 |
---|
| 18 | #define Inew(pointer,type); { make_block(sizeof(type)); pointer=new type; } |
---|
| 19 | |
---|
[39] | 20 | extern char const *imerr_messages[]; // correspond to imERRORS |
---|
[2] | 21 | #define imREAD_ERROR 1 |
---|
| 22 | #define imINCORRECT_FILETYPE 2 |
---|
| 23 | #define imFILE_CORRUPTED 3 |
---|
| 24 | #define imFILE_NOT_FOUND 4 |
---|
| 25 | #define imMEMORY_ERROR 5 |
---|
| 26 | #define imNOT_SUPPORTED 6 |
---|
| 27 | #define imWRITE_ERROR 7 |
---|
| 28 | #define imMAX_ERROR 7 |
---|
| 29 | |
---|
[17] | 30 | int16_t current_error(); |
---|
[2] | 31 | void clear_errors(); |
---|
[17] | 32 | void set_error(int16_t x); |
---|
| 33 | int16_t last_error(); |
---|
[2] | 34 | void make_block(size_t size); |
---|
| 35 | void image_init(); |
---|
| 36 | void image_uninit(); |
---|
| 37 | extern linked_list image_list; |
---|
| 38 | |
---|
| 39 | typedef struct image_color_t |
---|
| 40 | { |
---|
[17] | 41 | uint16_t r; |
---|
| 42 | uint16_t g; |
---|
| 43 | uint16_t b; |
---|
[2] | 44 | } image_color; |
---|
| 45 | |
---|
| 46 | class filter; |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | class dirty_rect : public linked_node |
---|
| 50 | { |
---|
| 51 | public : |
---|
[17] | 52 | int16_t dx1,dy1,dx2,dy2; |
---|
| 53 | dirty_rect(int16_t x1, int16_t y1, int16_t x2, int16_t y2) |
---|
[2] | 54 | { dx1=x1; dy1=y1; dx2=x2; dy2=y2; |
---|
| 55 | if (x2<x1 || y2<y1) |
---|
| 56 | printf("add inccorect dirty\n"); |
---|
| 57 | } |
---|
[17] | 58 | virtual int16_t compare(void *n1, int16_t field) |
---|
[2] | 59 | { return ((dirty_rect *)n1)->dy1>dy1; } |
---|
| 60 | } ; |
---|
| 61 | |
---|
| 62 | class image_descriptor |
---|
| 63 | { |
---|
[17] | 64 | int16_t l,h; |
---|
| 65 | int16_t clipx1, clipy1, clipx2, clipy2; |
---|
[2] | 66 | public : |
---|
[17] | 67 | uint8_t keep_dirt, |
---|
| 68 | static_mem; // if this flag is set then don't free memory on exit |
---|
[2] | 69 | |
---|
| 70 | linked_list dirties; |
---|
| 71 | void *extended_descriptor; // type depends on current system |
---|
| 72 | |
---|
[17] | 73 | image_descriptor(int16_t length, int16_t height, |
---|
[2] | 74 | int keep_dirties=1, int static_memory=0); |
---|
[17] | 75 | int16_t bound_x1(int16_t x1) { return x1<clipx1 ? clipx1 : x1; } |
---|
| 76 | int16_t bound_y1(int16_t y1) { return y1<clipy1 ? clipy1 : y1; } |
---|
| 77 | int16_t bound_x2(int16_t x2) { return x2>clipx2 ? clipx2 : x2; } |
---|
| 78 | int16_t bound_y2(int16_t y2) { return y2>clipy2 ? clipy2 : y2; } |
---|
| 79 | int16_t x1_clip() { return clipx1; } |
---|
| 80 | int16_t y1_clip() { return clipy1; } |
---|
| 81 | int16_t x2_clip() { return clipx2; } |
---|
| 82 | int16_t y2_clip() { return clipy2; } |
---|
| 83 | void dirty_area(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { ;} |
---|
| 84 | void clean_area(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { ; } |
---|
[2] | 85 | void clear_dirties(); |
---|
[17] | 86 | int16_t get_dirty_area(int16_t &x1, int16_t &y1, int16_t &x2, int16_t &y2) { return 0; } |
---|
| 87 | void get_clip(int16_t &x1, int16_t &y1, int16_t &x2, int16_t &y2) |
---|
[2] | 88 | { x1=clipx1; y1=clipy1; x2=clipx2; y2=clipy2; } |
---|
[17] | 89 | void set_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2) |
---|
[2] | 90 | { if (x2<x1) x2=x1; |
---|
| 91 | if (y2<y1) y2=y1; |
---|
| 92 | if (x1<0) clipx1=0; else clipx1=x1; |
---|
| 93 | if (y1<0) clipy1=0; else clipy1=y1; |
---|
| 94 | if (x2>=l) clipx2=l-1; else clipx2=x2; |
---|
| 95 | if (y2>=h) clipy2=h-1; else clipy2=y2; |
---|
| 96 | } |
---|
| 97 | void reduce_dirties(); |
---|
| 98 | void add_dirty(int x1, int y1, int x2, int y2); |
---|
| 99 | void delete_dirty(int x1, int y1, int x2, int y2); |
---|
[17] | 100 | void resize(int16_t length, int16_t height) |
---|
[2] | 101 | { l=length; h=height; clipx1=0; clipy1=0; clipx2=l-1; clipy2=h-1; } |
---|
| 102 | } ; |
---|
| 103 | |
---|
| 104 | class image : public linked_node |
---|
| 105 | { |
---|
[17] | 106 | uint8_t *data; |
---|
| 107 | int16_t w,h; |
---|
| 108 | void make_page(int16_t width, int16_t height, uint8_t *page_buffer); |
---|
[2] | 109 | void delete_page(); |
---|
| 110 | public : |
---|
| 111 | image_descriptor *special; |
---|
| 112 | image(spec_entry *e, bFILE *fp); |
---|
| 113 | image(bFILE *fp); |
---|
[17] | 114 | image(int16_t width, int16_t height, // required |
---|
| 115 | uint8_t *page_buffer=NULL, |
---|
| 116 | int16_t create_descriptor=0); // 0=no, 1=yes, 2=yes & keep dirties |
---|
| 117 | uint8_t pixel (int16_t x, int16_t y); |
---|
| 118 | void putpixel (int16_t x, int16_t y, char color); |
---|
| 119 | uint8_t *scan_line (int16_t y) { return data+y*w; } |
---|
| 120 | uint8_t *next_line (int16_t lasty, uint8_t *last_scan) |
---|
[2] | 121 | { return last_scan+w; } |
---|
[17] | 122 | int32_t total_pixels (uint8_t background=0); |
---|
| 123 | image *copy (); // makes a copy of an image |
---|
| 124 | void clear (int16_t color=-1); // -1 is background color |
---|
| 125 | void to_24bit (palette &pal); |
---|
| 126 | int16_t width () { return (int16_t)w; } |
---|
| 127 | int16_t height () { return (int16_t)h; } |
---|
| 128 | void scroll (int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t xd, int16_t yd); |
---|
| 129 | void fill_image (image *screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, |
---|
[19] | 130 | int16_t align=1); |
---|
[17] | 131 | void put_image (image *screen, int16_t x, int16_t y, char transparent=0); |
---|
| 132 | void put_part (image *screen, int16_t x, int16_t y, int16_t x1, int16_t y1, |
---|
| 133 | int16_t x2, int16_t y2, char transparent=0); |
---|
| 134 | void put_part_xrev (image *screen, int16_t x, int16_t y, int16_t x1, int16_t y1, |
---|
| 135 | int16_t x2, int16_t y2, char transparent=0); |
---|
| 136 | void put_part_masked (image *screen, image *mask, int16_t x, int16_t y, |
---|
| 137 | int16_t maskx, int16_t masky, int16_t x1, int16_t y1, int16_t x2, int16_t y2); |
---|
| 138 | image *copy_part_dithered (int16_t x1, int16_t y1, int16_t x2, int16_t y2); |
---|
| 139 | void bar (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); |
---|
| 140 | void xor_bar (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); |
---|
[112] | 141 | void widget_bar (int16_t x1, int16_t y1, int16_t x2, int16_t y2, |
---|
[17] | 142 | uint8_t light, uint8_t med, uint8_t dark); |
---|
| 143 | void line (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); |
---|
| 144 | void rectangle (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); |
---|
| 145 | void burn_led (int16_t x, int16_t y, int32_t num, int16_t color, int16_t scale=1); |
---|
| 146 | void set_clip (int16_t x1, int16_t y1, int16_t x2, int16_t y2); |
---|
| 147 | void get_clip (int16_t &x1,int16_t &y1,int16_t &x2,int16_t &y2); |
---|
| 148 | void in_clip (int16_t x1, int16_t y1, int16_t x2, int16_t y2); |
---|
[2] | 149 | |
---|
[17] | 150 | void dirt_off () { if (special && special->keep_dirt) special->keep_dirt=0; } |
---|
| 151 | void dirt_on () { if (special) special->keep_dirt=1; } |
---|
[2] | 152 | |
---|
[17] | 153 | void add_dirty (int x1, int y1, int x2, int y2) |
---|
[2] | 154 | { if (special) special->add_dirty(x1,y1,x2,y2); } |
---|
[17] | 155 | void delete_dirty (int x1, int y1, int x2, int y2) |
---|
[2] | 156 | { if (special) special->delete_dirty(x1,y1,x2,y2); } |
---|
[17] | 157 | void clear_dirties () { if (special) special->clear_dirties(); } |
---|
| 158 | void dither (palette *pal); // use a b&w palette! |
---|
| 159 | void resize (int16_t new_width, int16_t new_height); |
---|
| 160 | void change_size (int16_t new_width, int16_t new_height, uint8_t *page=NULL); |
---|
| 161 | void flood_fill (int16_t x, int16_t y, uint8_t color); |
---|
| 162 | image *create_smooth (int16_t smoothness=1); // 0 no smoothness |
---|
| 163 | void unpack_scanline (int16_t line, char bitsperpixel=1); |
---|
| 164 | uint8_t brightest_color (palette *pal); |
---|
| 165 | void flip_x (); |
---|
| 166 | void flip_y (); |
---|
| 167 | void make_color (uint8_t color); |
---|
| 168 | uint8_t darkest_color (palette *pal, int16_t noblack=0); |
---|
[2] | 169 | |
---|
| 170 | ~image(); |
---|
| 171 | } ; |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | class image_controller |
---|
| 175 | { |
---|
| 176 | public : |
---|
| 177 | image_controller() { image_init(); } |
---|
| 178 | ~image_controller() |
---|
| 179 | { |
---|
| 180 | image_uninit(); |
---|
| 181 | } |
---|
| 182 | } ; |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | #endif |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | |
---|
| 194 | |
---|