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