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 | int16_t current_error(); |
---|
22 | void clear_errors(); |
---|
23 | void set_error(int16_t x); |
---|
24 | int16_t 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 | typedef struct image_color_t |
---|
31 | { |
---|
32 | uint16_t r; |
---|
33 | uint16_t g; |
---|
34 | uint16_t b; |
---|
35 | } image_color; |
---|
36 | |
---|
37 | class filter; |
---|
38 | |
---|
39 | |
---|
40 | class dirty_rect : public linked_node |
---|
41 | { |
---|
42 | public : |
---|
43 | int16_t dx1,dy1,dx2,dy2; |
---|
44 | dirty_rect(int16_t x1, int16_t y1, int16_t x2, int16_t y2) |
---|
45 | { dx1=x1; dy1=y1; dx2=x2; dy2=y2; |
---|
46 | if (x2<x1 || y2<y1) |
---|
47 | printf("add inccorect dirty\n"); |
---|
48 | } |
---|
49 | virtual int16_t compare(void *n1, int16_t field) |
---|
50 | { return ((dirty_rect *)n1)->dy1>dy1; } |
---|
51 | } ; |
---|
52 | |
---|
53 | class image_descriptor |
---|
54 | { |
---|
55 | int16_t l,h; |
---|
56 | int16_t clipx1, clipy1, clipx2, clipy2; |
---|
57 | public : |
---|
58 | uint8_t keep_dirt, |
---|
59 | static_mem; // if this flag is set then don't free memory on exit |
---|
60 | |
---|
61 | linked_list dirties; |
---|
62 | void *extended_descriptor; // type depends on current system |
---|
63 | |
---|
64 | image_descriptor(int16_t length, int16_t height, |
---|
65 | int keep_dirties=1, int static_memory=0); |
---|
66 | int16_t bound_x1(int16_t x1) { return x1<clipx1 ? clipx1 : x1; } |
---|
67 | int16_t bound_y1(int16_t y1) { return y1<clipy1 ? clipy1 : y1; } |
---|
68 | int16_t bound_x2(int16_t x2) { return x2>clipx2 ? clipx2 : x2; } |
---|
69 | int16_t bound_y2(int16_t y2) { return y2>clipy2 ? clipy2 : y2; } |
---|
70 | int16_t x1_clip() { return clipx1; } |
---|
71 | int16_t y1_clip() { return clipy1; } |
---|
72 | int16_t x2_clip() { return clipx2; } |
---|
73 | int16_t y2_clip() { return clipy2; } |
---|
74 | void dirty_area(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { ;} |
---|
75 | void clean_area(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { ; } |
---|
76 | void clear_dirties(); |
---|
77 | int16_t get_dirty_area(int16_t &x1, int16_t &y1, int16_t &x2, int16_t &y2) { return 0; } |
---|
78 | void get_clip(int16_t &x1, int16_t &y1, int16_t &x2, int16_t &y2) |
---|
79 | { x1=clipx1; y1=clipy1; x2=clipx2; y2=clipy2; } |
---|
80 | void set_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2) |
---|
81 | { if (x2<x1) x2=x1; |
---|
82 | if (y2<y1) y2=y1; |
---|
83 | if (x1<0) clipx1=0; else clipx1=x1; |
---|
84 | if (y1<0) clipy1=0; else clipy1=y1; |
---|
85 | if (x2>=l) clipx2=l-1; else clipx2=x2; |
---|
86 | if (y2>=h) clipy2=h-1; else clipy2=y2; |
---|
87 | } |
---|
88 | void reduce_dirties(); |
---|
89 | void add_dirty(int x1, int y1, int x2, int y2); |
---|
90 | void delete_dirty(int x1, int y1, int x2, int y2); |
---|
91 | void resize(int16_t length, int16_t height) |
---|
92 | { l=length; h=height; clipx1=0; clipy1=0; clipx2=l-1; clipy2=h-1; } |
---|
93 | } ; |
---|
94 | |
---|
95 | class image : public linked_node |
---|
96 | { |
---|
97 | uint8_t *data; |
---|
98 | int16_t w,h; |
---|
99 | void make_page(int16_t width, int16_t height, uint8_t *page_buffer); |
---|
100 | void delete_page(); |
---|
101 | public : |
---|
102 | image_descriptor *special; |
---|
103 | image(spec_entry *e, bFILE *fp); |
---|
104 | image(bFILE *fp); |
---|
105 | image(int16_t width, int16_t height, // required |
---|
106 | uint8_t *page_buffer=NULL, |
---|
107 | int16_t create_descriptor=0); // 0=no, 1=yes, 2=yes & keep dirties |
---|
108 | uint8_t pixel (int16_t x, int16_t y); |
---|
109 | void putpixel (int16_t x, int16_t y, char color); |
---|
110 | uint8_t *scan_line (int16_t y) { return data+y*w; } |
---|
111 | uint8_t *next_line (int16_t lasty, uint8_t *last_scan) |
---|
112 | { return last_scan+w; } |
---|
113 | int32_t total_pixels (uint8_t background=0); |
---|
114 | image *copy (); // makes a copy of an image |
---|
115 | void clear (int16_t color=-1); // -1 is background color |
---|
116 | void to_24bit (palette &pal); |
---|
117 | int16_t width () { return (int16_t)w; } |
---|
118 | int16_t height () { return (int16_t)h; } |
---|
119 | void scroll (int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t xd, int16_t yd); |
---|
120 | void fill_image (image *screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, |
---|
121 | int16_t align=1); |
---|
122 | void put_image (image *screen, int16_t x, int16_t y, char transparent=0); |
---|
123 | void put_part (image *screen, int16_t x, int16_t y, int16_t x1, int16_t y1, |
---|
124 | int16_t x2, int16_t y2, char transparent=0); |
---|
125 | void put_part_xrev (image *screen, int16_t x, int16_t y, int16_t x1, int16_t y1, |
---|
126 | int16_t x2, int16_t y2, char transparent=0); |
---|
127 | void put_part_masked (image *screen, image *mask, int16_t x, int16_t y, |
---|
128 | int16_t maskx, int16_t masky, int16_t x1, int16_t y1, int16_t x2, int16_t y2); |
---|
129 | image *copy_part_dithered (int16_t x1, int16_t y1, int16_t x2, int16_t y2); |
---|
130 | void bar (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); |
---|
131 | void xor_bar (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); |
---|
132 | void wiget_bar (int16_t x1, int16_t y1, int16_t x2, int16_t y2, |
---|
133 | uint8_t light, uint8_t med, uint8_t dark); |
---|
134 | void line (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); |
---|
135 | void rectangle (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); |
---|
136 | void burn_led (int16_t x, int16_t y, int32_t num, int16_t color, int16_t scale=1); |
---|
137 | void set_clip (int16_t x1, int16_t y1, int16_t x2, int16_t y2); |
---|
138 | void get_clip (int16_t &x1,int16_t &y1,int16_t &x2,int16_t &y2); |
---|
139 | void in_clip (int16_t x1, int16_t y1, int16_t x2, int16_t 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 (int16_t new_width, int16_t new_height); |
---|
151 | void change_size (int16_t new_width, int16_t new_height, uint8_t *page=NULL); |
---|
152 | void flood_fill (int16_t x, int16_t y, uint8_t color); |
---|
153 | image *create_smooth (int16_t smoothness=1); // 0 no smoothness |
---|
154 | void unpack_scanline (int16_t line, char bitsperpixel=1); |
---|
155 | uint8_t brightest_color (palette *pal); |
---|
156 | void flip_x (); |
---|
157 | void flip_y (); |
---|
158 | void make_color (uint8_t color); |
---|
159 | uint8_t darkest_color (palette *pal, int16_t 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 | |
---|