source: abuse/trunk/src/imlib/image.h @ 481

Last change on this file since 481 was 481, checked in by Sam Hocevar, 12 years ago

Fuck the history, I'm renaming all .hpp files to .h for my own sanity.

  • Property svn:keywords set to Id
File size: 7.3 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.h"
15#include "palette.h"
16#include "system.h"
17#include "specs.h"
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    int16_t pitch()
160    {
161        return (int16_t)w; // FIXME: for now, pitch == width
162    }
163    void scroll(int16_t x1, int16_t y1, int16_t x2, int16_t y2,
164                int16_t xd, int16_t yd);
165    void fill_image(image *screen, int16_t x1, int16_t y1,
166                    int16_t x2, int16_t y2, int16_t align = 1);
167    void put_image(image *screen, int16_t x, int16_t y, char transparent = 0);
168    void put_part(image *screen, int16_t x, int16_t y, int16_t x1, int16_t y1,
169                  int16_t x2, int16_t y2, char transparent = 0);
170    void put_part_xrev(image *screen, int16_t x, int16_t y,
171                       int16_t x1, int16_t y1, int16_t x2, int16_t y2,
172                       char transparent = 0);
173    void put_part_masked(image *screen, image *mask, int16_t x, int16_t y,
174                         int16_t maskx, int16_t masky, int16_t x1, int16_t y1,
175                         int16_t x2, int16_t y2);
176    image *copy_part_dithered(int16_t x1, int16_t y1, int16_t x2, int16_t y2);
177    void bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color);
178    void xor_bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color);
179    void widget_bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2,
180                    uint8_t light, uint8_t med, uint8_t dark);
181    void line(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color);
182    void rectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2,
183                   uint8_t color);
184    void burn_led(int16_t x, int16_t y, int32_t num, int16_t color,
185                  int16_t scale = 1);
186    void set_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2);
187    void get_clip(int16_t &x1,int16_t &y1,int16_t &x2,int16_t &y2);
188    void in_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2);
189
190    void dirt_off()
191    {
192        if(special && special->keep_dirt) special->keep_dirt = 0;
193    }
194    void dirt_on()
195    {
196        if(special) special->keep_dirt = 1;
197    }
198
199    void add_dirty(int x1, int y1, int x2, int y2)
200    {
201        if(special) special->add_dirty(x1, y1, x2, y2);
202    }
203    void delete_dirty(int x1, int y1, int x2, int y2)
204    {
205        if(special) special->delete_dirty(x1, y1, x2, y2);
206    }
207    void clear_dirties()
208    {
209        if(special) special->clear_dirties();
210    }
211    void dither(palette *pal); // use a b&w palette!
212    void resize(int16_t new_width, int16_t new_height);
213    void change_size(int16_t new_width, int16_t new_height,
214                     uint8_t *page = NULL);
215    void flood_fill(int16_t x, int16_t y, uint8_t color);
216    image *create_smooth(int16_t smoothness = 1); // 0 no smoothness
217    void unpack_scanline(int16_t line, char bitsperpixel = 1);
218    uint8_t brightest_color(palette *pal);
219    void flip_x();
220    void flip_y();
221    void make_color(uint8_t color);
222    uint8_t darkest_color(palette *pal, int16_t noblack = 0);
223};
224
225class image_controller
226{
227public:
228    image_controller()
229    {
230        image_init();
231    }
232    ~image_controller()
233    {
234        image_uninit();
235    }
236};
237
238#endif /* _IMAGE_HPP_ */
239
Note: See TracBrowser for help on using the repository browser.