source: abuse/trunk/src/imlib/include/image.hpp @ 2

Last change on this file since 2 was 2, checked in by Sam Hocevar, 14 years ago
  • imported original 0.7.0 tarball
File size: 7.0 KB
Line 
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
11extern 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
21short current_error();
22void clear_errors();
23void set_error(short x);
24short last_error();
25void make_block(size_t size);
26void image_init();
27void image_uninit();
28extern linked_list image_list;
29
30typedef struct image_color_t
31{
32        unsigned short r;
33        unsigned short g;
34        unsigned short b;
35} image_color;
36
37class filter;
38
39
40class dirty_rect : public linked_node
41{
42public :
43  short dx1,dy1,dx2,dy2;
44  dirty_rect(short x1, short y1, short x2, short 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 short compare(void *n1, short field)
50  { return ((dirty_rect *)n1)->dy1>dy1; }
51} ;
52
53class image_descriptor
54{
55  short l,h;
56  short clipx1, clipy1, clipx2, clipy2;
57public : 
58  unsigned char 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(short length, short height,
65                  int keep_dirties=1, int static_memory=0);
66  short bound_x1(short x1)  { return x1<clipx1 ? clipx1 : x1; }
67  short bound_y1(short y1)  { return y1<clipy1 ? clipy1 : y1; }
68  short bound_x2(short x2)  { return x2>clipx2 ? clipx2 : x2; }
69  short bound_y2(short y2)  { return y2>clipy2 ? clipy2 : y2; }
70  short x1_clip() { return clipx1; }
71  short y1_clip() { return clipy1; }
72  short x2_clip() { return clipx2; }
73  short y2_clip() { return clipy2; }
74  void dirty_area(short x1, short y1, short x2, short y2) { ;}
75  void clean_area(short x1, short y1, short x2, short y2) { ; }
76  void clear_dirties();
77  short get_dirty_area(short &x1, short &y1, short &x2, short &y2) { return 0; }
78  void get_clip(short &x1, short &y1, short &x2, short &y2)
79    { x1=clipx1; y1=clipy1; x2=clipx2; y2=clipy2; }
80  void set_clip(short x1, short y1, short x2, short 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(short length, short height)
92   { l=length; h=height; clipx1=0; clipy1=0; clipx2=l-1; clipy2=h-1; }
93} ;
94
95class image : public linked_node
96{
97  unsigned char *data;
98  short w,h;
99  void make_page(short width, short height, unsigned char *page_buffer);
100  void delete_page();
101public :
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
165class image_controller
166{
167public :
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
Note: See TracBrowser for help on using the repository browser.