Changeset 115 for abuse/trunk/src/imlib/image.hpp
 Timestamp:
 Mar 16, 2008, 10:51:54 PM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

abuse/trunk/src/imlib/image.hpp
r112 r115 8 8 */ 9 9 10 #ifndef _IMGAE_HPP_ 11 #define _IMGAE_HPP_ 10 #ifndef _IMAGE_HPP_ 11 #define _IMAGE_HPP_ 12 12 13 #include <stdlib.h> 13 14 #include "linked.hpp" … … 19 20 20 21 extern char const *imerr_messages[]; // correspond to imERRORS 21 #define imREAD_ERROR 22 #define imREAD_ERROR 1 22 23 #define imINCORRECT_FILETYPE 2 23 24 #define imFILE_CORRUPTED 3 … … 26 27 #define imNOT_SUPPORTED 6 27 28 #define imWRITE_ERROR 7 28 #define imMAX_ERROR 29 #define imMAX_ERROR 7 29 30 30 31 int16_t current_error(); … … 39 40 typedef struct image_color_t 40 41 { 41 42 43 42 uint16_t r; 43 uint16_t g; 44 uint16_t b; 44 45 } image_color; 45 46 … … 52 53 int16_t dx1,dy1,dx2,dy2; 53 54 dirty_rect(int16_t x1, int16_t y1, int16_t x2, int16_t y2) 54 { dx1=x1; dy1=y1; dx2=x2; dy2=y2; 55 if (x2<x1  y2<y1)55 { dx1=x1; dy1=y1; dx2=x2; dy2=y2; 56 if(x2<x1  y2<y1) 56 57 printf("add inccorect dirty\n"); 57 58 } 58 59 virtual int16_t compare(void *n1, int16_t field) 59 { return 60 { return((dirty_rect *)n1)>dy1>dy1; } 60 61 } ; 61 62 62 63 class image_descriptor 63 64 { 64 int16_t l,h; 65 int16_t clipx1, clipy1, clipx2, clipy2; 66 public : 67 uint8_t keep_dirt, 68 static_mem; // if this flag is set then don't free memory on exit 69 70 linked_list dirties; 71 void *extended_descriptor; // type depends on current system 72 73 image_descriptor(int16_t length, int16_t height, 74 int keep_dirties=1, int static_memory=0); 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) { ; } 85 void clear_dirties(); 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) 88 { x1=clipx1; y1=clipy1; x2=clipx2; y2=clipy2; } 89 void set_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2) 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=l1; else clipx2=x2; 95 if (y2>=h) clipy2=h1; 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); 100 void resize(int16_t length, int16_t height) 101 { l=length; h=height; clipx1=0; clipy1=0; clipx2=l1; clipy2=h1; } 102 } ; 65 private: 66 int16_t l, h; 67 int16_t clipx1, clipy1, clipx2, clipy2; 68 69 public: 70 uint8_t keep_dirt, 71 static_mem; // if set, don't free memory on exit 72 73 linked_list dirties; 74 void *extended_descriptor; 75 76 image_descriptor(int16_t length, int16_t height, 77 int keep_dirties = 1, int static_memory = 0); 78 int16_t bound_x1(int16_t x1) { return x1 < clipx1 ? clipx1 : x1; } 79 int16_t bound_y1(int16_t y1) { return y1 < clipy1 ? clipy1 : y1; } 80 int16_t bound_x2(int16_t x2) { return x2 > clipx2 ? clipx2 : x2; } 81 int16_t bound_y2(int16_t y2) { return y2 > clipy2 ? clipy2 : y2; } 82 int16_t x1_clip() { return clipx1; } 83 int16_t y1_clip() { return clipy1; } 84 int16_t x2_clip() { return clipx2; } 85 int16_t y2_clip() { return clipy2; } 86 void dirty_area(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { ; } 87 void clean_area(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { ; } 88 void clear_dirties(); 89 int16_t get_dirty_area(int16_t &x1, int16_t &y1, int16_t &x2, int16_t &y2) 90 { 91 return 0; 92 } 93 void get_clip(int16_t &x1, int16_t &y1, int16_t &x2, int16_t &y2) 94 { 95 x1 = clipx1; y1 = clipy1; x2 = clipx2; y2 = clipy2; 96 } 97 void set_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2) 98 { 99 if(x2 < x1) x2 = x1; 100 if(y2 < y1) y2 = y1; 101 if(x1 < 0) clipx1 = 0; else clipx1 = x1; 102 if(y1 < 0) clipy1 = 0; else clipy1 = y1; 103 if(x2 >= l) clipx2 = l  1; else clipx2 = x2; 104 if(y2 >= h) clipy2 = h  1; else clipy2 = y2; 105 } 106 void reduce_dirties(); 107 void add_dirty(int x1, int y1, int x2, int y2); 108 void delete_dirty(int x1, int y1, int x2, int y2); 109 void resize(int16_t length, int16_t height) 110 { 111 l = length; h = height; 112 clipx1 = 0; clipy1 = 0; clipx2 = l  1; clipy2 = h  1; 113 } 114 }; 103 115 104 116 class image : public linked_node 105 { 106 uint8_t *data; 107 int16_t w,h; 108 void make_page(int16_t width, int16_t height, uint8_t *page_buffer); 109 void delete_page(); 110 public : 111 image_descriptor *special; 112 image(spec_entry *e, bFILE *fp); 113 image(bFILE *fp); 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) 121 { return last_scan+w; } 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, 130 int16_t align=1); 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); 141 void widget_bar (int16_t x1, int16_t y1, int16_t x2, int16_t y2, 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); 149 150 void dirt_off () { if (special && special>keep_dirt) special>keep_dirt=0; } 151 void dirt_on () { if (special) special>keep_dirt=1; } 152 153 void add_dirty (int x1, int y1, int x2, int y2) 154 { if (special) special>add_dirty(x1,y1,x2,y2); } 155 void delete_dirty (int x1, int y1, int x2, int y2) 156 { if (special) special>delete_dirty(x1,y1,x2,y2); } 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); 169 170 ~image(); 171 } ; 172 117 { 118 private: 119 uint8_t *data; 120 int16_t w, h; 121 void make_page(int16_t width, int16_t height, uint8_t *page_buffer); 122 void delete_page(); 123 bool _locked; 124 125 public: 126 image_descriptor *special; 127 128 image(spec_entry *e, bFILE *fp); 129 image(bFILE *fp); 130 image(int16_t width, int16_t height, 131 uint8_t *page_buffer = NULL, int16_t create_descriptor = 0); 132 ~image(); 133 134 void lock(); 135 void unlock(); 136 137 uint8_t pixel(int16_t x, int16_t y); 138 void putpixel(int16_t x, int16_t y, char color); 139 uint8_t *scan_line(int16_t y) 140 { 141 return data + y * w; 142 } 143 uint8_t *next_line(int16_t lasty, uint8_t *last_scan) 144 { 145 return last_scan + w; 146 } 147 int32_t total_pixels(uint8_t background=0); 148 image *copy(); // makes a copy of an image 149 void clear(int16_t color = 1); // 1 is background color 150 void to_24bit(palette &pal); 151 int16_t width() 152 { 153 return (int16_t)w; 154 } 155 int16_t height() 156 { 157 return (int16_t)h; 158 } 159 void scroll(int16_t x1, int16_t y1, int16_t x2, int16_t y2, 160 int16_t xd, int16_t yd); 161 void fill_image(image *screen, int16_t x1, int16_t y1, 162 int16_t x2, int16_t y2, int16_t align = 1); 163 void put_image(image *screen, int16_t x, int16_t y, char transparent = 0); 164 void put_part(image *screen, int16_t x, int16_t y, int16_t x1, int16_t y1, 165 int16_t x2, int16_t y2, char transparent = 0); 166 void put_part_xrev(image *screen, int16_t x, int16_t y, 167 int16_t x1, int16_t y1, int16_t x2, int16_t y2, 168 char transparent = 0); 169 void put_part_masked(image *screen, image *mask, int16_t x, int16_t y, 170 int16_t maskx, int16_t masky, int16_t x1, int16_t y1, 171 int16_t x2, int16_t y2); 172 image *copy_part_dithered(int16_t x1, int16_t y1, int16_t x2, int16_t y2); 173 void bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); 174 void xor_bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); 175 void widget_bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2, 176 uint8_t light, uint8_t med, uint8_t dark); 177 void line(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); 178 void rectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, 179 uint8_t color); 180 void burn_led(int16_t x, int16_t y, int32_t num, int16_t color, 181 int16_t scale = 1); 182 void set_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2); 183 void get_clip(int16_t &x1,int16_t &y1,int16_t &x2,int16_t &y2); 184 void in_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2); 185 186 void dirt_off() 187 { 188 if(special && special>keep_dirt) special>keep_dirt = 0; 189 } 190 void dirt_on() 191 { 192 if(special) special>keep_dirt = 1; 193 } 194 195 void add_dirty(int x1, int y1, int x2, int y2) 196 { 197 if(special) special>add_dirty(x1, y1, x2, y2); 198 } 199 void delete_dirty(int x1, int y1, int x2, int y2) 200 { 201 if(special) special>delete_dirty(x1, y1, x2, y2); 202 } 203 void clear_dirties() 204 { 205 if(special) special>clear_dirties(); 206 } 207 void dither(palette *pal); // use a b&w palette! 208 void resize(int16_t new_width, int16_t new_height); 209 void change_size(int16_t new_width, int16_t new_height, 210 uint8_t *page = NULL); 211 void flood_fill(int16_t x, int16_t y, uint8_t color); 212 image *create_smooth(int16_t smoothness = 1); // 0 no smoothness 213 void unpack_scanline(int16_t line, char bitsperpixel = 1); 214 uint8_t brightest_color(palette *pal); 215 void flip_x(); 216 void flip_y(); 217 void make_color(uint8_t color); 218 uint8_t darkest_color(palette *pal, int16_t noblack = 0); 219 }; 173 220 174 221 class image_controller 175 222 { 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 223 public: 224 image_controller() 225 { 226 image_init(); 227 } 228 ~image_controller() 229 { 230 image_uninit(); 231 } 232 }; 233 234 #endif /* _IMAGE_HPP_ */ 235
Note: See TracChangeset
for help on using the changeset viewer.