source: abuse/trunk/src/imlib/image.hpp @ 124

Last change on this file since 124 was 124, checked in by Sam Hocevar, 11 years ago
  • Get rid of ugly tabs and trailing spaces everywhere.
File size: 7.2 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *
5 *  This software was released into the Public Domain. As with most public
6 *  domain software, no warranty is made or implied by Crack dot Com or
7 *  Jonathan Clark.
8 */
9
10#ifndef _IMAGE_HPP_
11#define _IMAGE_HPP_
12
13#include <stdlib.h>
14#include "linked.hpp"
15#include "palette.hpp"
16#include "system.h"
17#include "specs.hpp"
18#define MAX_DIRTY 200
19#define Inew(pointer,type); { make_block(sizeof(type)); pointer=new type; }
20
21extern char const *imerr_messages[];  // correspond to imERRORS
22#define imREAD_ERROR            1
23#define imINCORRECT_FILETYPE   2
24#define imFILE_CORRUPTED       3
25#define imFILE_NOT_FOUND       4
26#define imMEMORY_ERROR         5
27#define imNOT_SUPPORTED        6
28#define imWRITE_ERROR          7
29#define imMAX_ERROR            7
30
31int16_t current_error();
32void clear_errors();
33void set_error(int16_t x);
34int16_t last_error();
35void make_block(size_t size);
36void image_init();
37void image_uninit();
38extern linked_list image_list;
39
40typedef struct image_color_t
41{
42    uint16_t r;
43    uint16_t g;
44    uint16_t b;
45} image_color;
46
47class filter;
48
49
50class dirty_rect : public linked_node
51{
52public :
53  int16_t dx1,dy1,dx2,dy2;
54  dirty_rect(int16_t x1, int16_t y1, int16_t x2, int16_t y2)
55  { dx1=x1; dy1=y1; dx2=x2; dy2=y2;
56    if(x2<x1 || y2<y1)
57      printf("add inccorect dirty\n");
58  }
59  virtual int16_t compare(void *n1, int16_t field)
60  { return((dirty_rect *)n1)->dy1>dy1; }
61} ;
62
63class image_descriptor
64{
65private:
66    int16_t l, h;
67    int16_t clipx1, clipy1, clipx2, clipy2;
68
69public:
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};
115
116class image : public linked_node
117{
118private:
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
125public:
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};
220
221class image_controller
222{
223public:
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 TracBrowser for help on using the repository browser.