source: abuse/branches/lol/src/imlib/image.h @ 737

Last change on this file since 737 was 737, checked in by Sam Hocevar, 8 years ago

build: sync with newer Lol Engine changes.

  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2013 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#ifndef _IMAGE_HPP_
12#define _IMAGE_HPP_
13
14#include <stdlib.h>
15
16#include "imlib/palette.h"
17#include "imlib/specs.h"
18
19#define MAX_DIRTY 200
20
21void image_init();
22void image_uninit();
23extern array<class AImage *> image_list;
24
25class ADirtyRect
26{
27public :
28    inline ADirtyRect() {}
29
30    ADirtyRect(ivec2 aa, ivec2 bb)
31    {
32        ASSERT(bb >= aa);
33        m_aa = aa;
34        m_bb = bb;
35    }
36
37    ivec2 m_aa, m_bb;
38};
39
40class image_descriptor
41{
42    friend class AImage;
43
44public:
45    uint8_t keep_dirt;
46
47    void *extended_descriptor;
48
49    image_descriptor(ivec2 size, int keep_dirties = 1);
50    int bound_x1(int x1) { return lol::max(x1, m_aa.x); }
51    int bound_y1(int y1) { return lol::max(y1, m_aa.y); }
52    int bound_x2(int x2) { return lol::min(x2, m_bb.x); }
53    int bound_y2(int y2) { return lol::min(y2, m_bb.y); }
54    inline int x1_clip() { return m_aa.x; }
55    inline int y1_clip() { return m_aa.y; }
56    inline int x2_clip() { return m_bb.x; }
57    inline int y2_clip() { return m_bb.y; }
58    void GetClip(ivec2 &aa, ivec2 &bb)
59    {
60        aa = m_aa; bb = m_bb;
61    }
62    void SetClip(ivec2 aa, ivec2 bb)
63    {
64        m_aa = lol::max(aa, ivec2(0));
65        m_bb = lol::min(lol::max(bb, m_aa + ivec2(1)), m_size);
66    }
67    void GetClip(int &x1, int &y1, int &x2, int &y2)
68    {
69        x1 = m_aa.x; y1 = m_aa.y; x2 = m_bb.x; y2 = m_bb.y;
70    }
71    void SetClip(int x1, int y1, int x2, int y2)
72    {
73        if(x2 < x1 + 1) x2 = x1 + 1;
74        if(y2 < y1 + 1) y2 = y1 + 1;
75        m_aa.x = lol::max(x1, 0); m_aa.y = lol::max(y1, 0);
76        m_bb.x = lol::min(x2, m_size.x); m_bb.y = lol::min(y2, m_size.y);
77    }
78    void ReduceDirties();
79    void AddDirty(ivec2 aa, ivec2 bb);
80    void DeleteDirty(ivec2 aa, ivec2 bb);
81    void Resize(ivec2 size)
82    {
83        m_size = size;
84        m_aa = ivec2(0);
85        m_bb = size;
86    }
87
88    array<ADirtyRect> m_dirties; /* Is public because of update_dirties() */
89
90private:
91    ivec2 m_size, m_aa, m_bb;
92};
93
94class AImage
95{
96public:
97    AImage(bFILE *fp, SpecEntry *e = NULL);
98    AImage(ivec2 size, int create_descriptor = 0);
99    ~AImage();
100
101    uint8_t Pixel(ivec2 pos);
102    void PutPixel(ivec2 pos, uint8_t color);
103
104    ivec2 Size() const { return m_size; }
105
106private:
107    array<uint8_t> m_data;
108    ivec2 m_size;
109
110public:
111    image_descriptor *m_special;
112
113    inline uint8_t *scan_line(int y)
114    {
115        /* FIXME: use the following construct for runtime checks */
116        //return &m_data[y * m_size.x];
117
118        return m_data.data() + y * m_size.x;
119    }
120    AImage *copy(); // makes a copy of an image
121    void clear(int color = -1); // -1 is background color
122
123    void PutImage(AImage *screen, ivec2 pos, int transparent = 0);
124    void PutPart(AImage *screen, ivec2 pos, ivec2 aa, ivec2 bb,
125                 int transparent = 0);
126    AImage *copy_part_dithered(int x1, int y1, int x2, int y2);
127    void Bar(ivec2 p1, ivec2 p2, uint8_t color);
128    void xor_bar(int x1, int y1, int x2, int y2, uint8_t color);
129    void WidgetBar(ivec2 p1, ivec2 p2,
130                   uint8_t light, uint8_t med, uint8_t dark);
131    void Line(ivec2 p1, ivec2 p2, uint8_t color);
132    void Rectangle(ivec2 p1, ivec2 p2, uint8_t color);
133    void burn_led(int x, int y, int32_t num, int color, int scale = 1);
134    void SetClip(ivec2 aa, ivec2 bb);
135    void GetClip(ivec2 &aa, ivec2 &bb);
136    void InClip(ivec2 aa, ivec2 bb);
137    void SetClip(int x1, int y1, int x2, int y2);
138    void GetClip(int &x1, int &y1, int &x2, int &y2);
139    void InClip(int x1, int y1, int x2, int y2);
140
141    void dirt_off()
142    {
143        if(m_special && m_special->keep_dirt) m_special->keep_dirt = 0;
144    }
145    void dirt_on()
146    {
147        if(m_special) m_special->keep_dirt = 1;
148    }
149
150    void AddDirty(ivec2 aa, ivec2 bb)
151    {
152        if (m_special) m_special->AddDirty(aa, bb);
153    }
154    void DeleteDirty(ivec2 aa, ivec2 bb)
155    {
156        if (m_special) m_special->DeleteDirty(aa, bb);
157    }
158    void dither(Palette *pal); // use a b&w palette!
159    void Scale(ivec2 size);
160    void SetSize(ivec2 size);
161    void flood_fill(int x, int y, uint8_t color);
162    AImage *create_smooth(int smoothness = 1); // 0 no smoothness
163    void unpack_scanline(int line, char bitsperpixel = 1);
164    void FlipX();
165    void FlipY();
166};
167
168class image_controller
169{
170public:
171    image_controller()
172    {
173        image_init();
174    }
175    ~image_controller()
176    {
177        image_uninit();
178    }
179};
180
181#endif /* _IMAGE_HPP_ */
182
Note: See TracBrowser for help on using the repository browser.