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

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

imlib: remove dead code.

  • Property svn:keywords set to Id
File size: 5.8 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 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 or
8 *  Jonathan Clark.
9 */
10
11#ifndef _IMAGE_HPP_
12#define _IMAGE_HPP_
13
14#include <stdlib.h>
15#include "linked.h"
16#include "palette.h"
17#include "system.h"
18#include "specs.h"
19#define MAX_DIRTY 200
20
21void image_init();
22void image_uninit();
23extern linked_list image_list;
24
25class dirty_rect : public linked_node
26{
27public :
28  int16_t dx1,dy1,dx2,dy2;
29  dirty_rect(int16_t x1, int16_t y1, int16_t x2, int16_t y2)
30  { dx1=x1; dy1=y1; dx2=x2; dy2=y2;
31    if(x2<x1 || y2<y1)
32      printf("add incorrect dirty\n");
33  }
34  virtual int16_t compare(void *n1, int16_t field)
35  { return((dirty_rect *)n1)->dy1>dy1; }
36} ;
37
38class image_descriptor
39{
40private:
41    int m_l, m_h;
42    int m_clipx1, m_clipy1, m_clipx2, m_clipy2;
43
44public:
45    uint8_t keep_dirt,
46            static_mem; // if set, don't free memory on exit
47
48    linked_list dirties;
49    void *extended_descriptor;
50
51    image_descriptor(vec2i size, int keep_dirties = 1, int static_memory = 0);
52    int bound_x1(int x1) { return x1 < m_clipx1 ? m_clipx1 : x1; }
53    int bound_y1(int y1) { return y1 < m_clipy1 ? m_clipy1 : y1; }
54    int bound_x2(int x2) { return x2 > m_clipx2 ? m_clipx2 : x2; }
55    int bound_y2(int y2) { return y2 > m_clipy2 ? m_clipy2 : y2; }
56    inline int x1_clip() { return m_clipx1; }
57    inline int y1_clip() { return m_clipy1; }
58    inline int x2_clip() { return m_clipx2; }
59    inline int y2_clip() { return m_clipy2; }
60    void ClearDirties();
61    void GetClip(int &x1, int &y1, int &x2, int &y2)
62    {
63        x1 = m_clipx1; y1 = m_clipy1; x2 = m_clipx2; y2 = m_clipy2;
64    }
65    void SetClip(int x1, int y1, int x2, int y2)
66    {
67        if(x2 < x1 + 1) x2 = x1 + 1;
68        if(y2 < y1 + 1) y2 = y1 + 1;
69        m_clipx1 = Max(x1, 0); m_clipy1 = Max(y1, 0);
70        m_clipx2 = Min(x2, m_l); m_clipy2 = Min(y2, m_h);
71    }
72    void ReduceDirties();
73    void AddDirty(int x1, int y1, int x2, int y2);
74    void delete_dirty(int x1, int y1, int x2, int y2);
75    void Resize(vec2i size)
76    {
77        m_l = size.x; m_h = size.y;
78        m_clipx1 = 0; m_clipy1 = 0; m_clipx2 = m_l; m_clipy2 = m_h;
79    }
80};
81
82class image : public linked_node
83{
84private:
85    uint8_t *m_data;
86    vec2i m_size;
87    bool m_locked;
88
89    void MakePage(vec2i size, uint8_t *page_buffer);
90    void DeletePage();
91
92public:
93    image_descriptor *m_special;
94
95    image(bFILE *fp, spec_entry *e = NULL);
96    image(vec2i size, uint8_t *page_buffer = NULL, int create_descriptor = 0);
97    ~image();
98
99    void Lock();
100    void Unlock();
101
102    uint8_t Pixel(vec2i pos);
103    void PutPixel(vec2i pos, uint8_t color);
104
105    inline uint8_t *scan_line(int16_t y)
106    {
107        return m_data + y * m_size.x;
108    }
109    inline uint8_t *next_line(int16_t lasty, uint8_t *last_scan)
110    {
111        return last_scan + m_size.x;
112    }
113    image *copy(); // makes a copy of an image
114    void clear(int16_t color = -1); // -1 is background color
115
116    vec2i Size() const { return m_size; }
117
118    void scroll(int16_t x1, int16_t y1, int16_t x2, int16_t y2,
119                int16_t xd, int16_t yd);
120    void fill_image(image *screen, int16_t x1, int16_t y1,
121                    int16_t x2, int16_t y2, int16_t align = 1);
122    void put_image(image *screen, int16_t x, int16_t y, char transparent = 0);
123    void put_part(image *screen, int16_t x, int16_t y, int16_t x1, int16_t y1,
124                  int16_t x2, int16_t y2, char transparent = 0);
125    void put_part_xrev(image *screen, int16_t x, int16_t y,
126                       int16_t x1, int16_t y1, int16_t x2, int16_t y2,
127                       char transparent = 0);
128    void put_part_masked(image *screen, image *mask, int16_t x, int16_t y,
129                         int16_t maskx, int16_t masky, int16_t x1, int16_t y1,
130                         int16_t x2, int16_t y2);
131    image *copy_part_dithered(int16_t x1, int16_t y1, int16_t x2, int16_t y2);
132    void bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color);
133    void xor_bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color);
134    void widget_bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2,
135                    uint8_t light, uint8_t med, uint8_t dark);
136    void line(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color);
137    void rectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2,
138                   uint8_t color);
139    void burn_led(int16_t x, int16_t y, int32_t num, int16_t color,
140                  int16_t scale = 1);
141    void SetClip(int x1, int y1, int x2, int y2);
142    void GetClip(int &x1, int &y1, int &x2, int &y2);
143    void InClip(int x1, int y1, int x2, int y2);
144
145    void dirt_off()
146    {
147        if(m_special && m_special->keep_dirt) m_special->keep_dirt = 0;
148    }
149    void dirt_on()
150    {
151        if(m_special) m_special->keep_dirt = 1;
152    }
153
154    void AddDirty(int x1, int y1, int x2, int y2)
155    {
156        if (m_special) m_special->AddDirty(x1, y1, x2, y2);
157    }
158    void delete_dirty(int x1, int y1, int x2, int y2)
159    {
160        if(m_special) m_special->delete_dirty(x1, y1, x2, y2);
161    }
162    void ClearDirties()
163    {
164        if (m_special) m_special->ClearDirties();
165    }
166    void dither(palette *pal); // use a b&w palette!
167    void Scale(vec2i size);
168    void SetSize(vec2i size, uint8_t *page = NULL);
169    void flood_fill(int16_t x, int16_t y, uint8_t color);
170    image *create_smooth(int16_t smoothness = 1); // 0 no smoothness
171    void unpack_scanline(int16_t line, char bitsperpixel = 1);
172    void flip_x();
173    void flip_y();
174};
175
176class image_controller
177{
178public:
179    image_controller()
180    {
181        image_init();
182    }
183    ~image_controller()
184    {
185        image_uninit();
186    }
187};
188
189#endif /* _IMAGE_HPP_ */
190
Note: See TracBrowser for help on using the repository browser.