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