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

Last change on this file was 682, checked in by Sam Hocevar, 11 years ago

core: rename vec2i to ivec2 and update matrix.h from Lol Engine.

  • Property svn:keywords set to Id
File size: 5.1 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]5 *
6 *  This software was released into the Public Domain. As with most public
[555]7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
[56]9 */
10
[115]11#ifndef _IMAGE_HPP_
12#define _IMAGE_HPP_
13
[2]14#include <stdlib.h>
[481]15#include "linked.h"
16#include "palette.h"
17#include "specs.h"
[2]18#define MAX_DIRTY 200
19
20void image_init();
21void image_uninit();
22extern linked_list image_list;
23
24class dirty_rect : public linked_node
25{
26public :
[682]27    dirty_rect(ivec2 aa, ivec2 bb)
[653]28    {
[670]29        m_aa = aa;
30        m_bb = bb;
31        if (!(bb >= aa))
[653]32            printf("add incorrect dirty\n");
33    }
[670]34    virtual int compare(void *n1)
35    {
36        return ((dirty_rect *)n1)->m_aa.y > m_aa.y;
37    }
38
[682]39    ivec2 m_aa, m_bb;
[653]40};
[2]41
42class image_descriptor
43{
[115]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
[682]51    image_descriptor(ivec2 size, int keep_dirties = 1, int static_memory = 0);
[664]52    int bound_x1(int x1) { return Max(x1, m_aa.x); }
53    int bound_y1(int y1) { return Max(y1, m_aa.y); }
54    int bound_x2(int x2) { return Min(x2, m_bb.x); }
55    int bound_y2(int y2) { return Min(y2, m_bb.y); }
56    inline int x1_clip() { return m_aa.x; }
57    inline int y1_clip() { return m_aa.y; }
58    inline int x2_clip() { return m_bb.x; }
59    inline int y2_clip() { return m_bb.y; }
[518]60    void ClearDirties();
[682]61    void GetClip(ivec2 &aa, ivec2 &bb)
[665]62    {
63        aa = m_aa; bb = m_bb;
64    }
[682]65    void SetClip(ivec2 aa, ivec2 bb)
[665]66    {
[682]67        m_aa = Max(aa, ivec2(0));
68        m_bb = Min(Max(bb, m_aa + ivec2(1)), m_size);
[665]69    }
[518]70    void GetClip(int &x1, int &y1, int &x2, int &y2)
[115]71    {
[664]72        x1 = m_aa.x; y1 = m_aa.y; x2 = m_bb.x; y2 = m_bb.y;
[2]73    }
[518]74    void SetClip(int x1, int y1, int x2, int y2)
[115]75    {
[518]76        if(x2 < x1 + 1) x2 = x1 + 1;
77        if(y2 < y1 + 1) y2 = y1 + 1;
[664]78        m_aa.x = Max(x1, 0); m_aa.y = Max(y1, 0);
79        m_bb.x = Min(x2, m_size.x); m_bb.y = Min(y2, m_size.y);
[115]80    }
[518]81    void ReduceDirties();
[682]82    void AddDirty(ivec2 aa, ivec2 bb);
83    void DeleteDirty(ivec2 aa, ivec2 bb);
84    void Resize(ivec2 size)
[115]85    {
[664]86        m_size = size;
[682]87        m_aa = ivec2(0);
[664]88        m_bb = size;
[115]89    }
[670]90
91private:
[682]92    ivec2 m_size, m_aa, m_bb;
[115]93};
[2]94
95class image : public linked_node
96{
[115]97private:
[513]98    uint8_t *m_data;
[682]99    ivec2 m_size;
[513]100    bool m_locked;
[2]101
[682]102    void MakePage(ivec2 size, uint8_t *page_buffer);
[515]103    void DeletePage();
104
[115]105public:
[515]106    image_descriptor *m_special;
[2]107
[523]108    image(bFILE *fp, spec_entry *e = NULL);
[682]109    image(ivec2 size, uint8_t *page_buffer = NULL, int create_descriptor = 0);
[115]110    ~image();
[2]111
[515]112    void Lock();
113    void Unlock();
[2]114
[682]115    uint8_t Pixel(ivec2 pos);
116    void PutPixel(ivec2 pos, uint8_t color);
[515]117
118    inline uint8_t *scan_line(int16_t y)
[115]119    {
[513]120        return m_data + y * m_size.x;
[115]121    }
122    image *copy(); // makes a copy of an image
123    void clear(int16_t color = -1); // -1 is background color
[512]124
[682]125    ivec2 Size() const { return m_size; }
[512]126
[115]127    void scroll(int16_t x1, int16_t y1, int16_t x2, int16_t y2,
128                int16_t xd, int16_t yd);
[682]129    void PutImage(image *screen, ivec2 pos, int transparent = 0);
130    void PutPart(image *screen, ivec2 pos, ivec2 aa, ivec2 bb,
[661]131                 int transparent = 0);
[115]132    image *copy_part_dithered(int16_t x1, int16_t y1, int16_t x2, int16_t y2);
[682]133    void Bar(ivec2 p1, ivec2 p2, uint8_t color);
[115]134    void xor_bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color);
[682]135    void WidgetBar(ivec2 p1, ivec2 p2,
[655]136                   uint8_t light, uint8_t med, uint8_t dark);
[682]137    void Line(ivec2 p1, ivec2 p2, uint8_t color);
138    void Rectangle(ivec2 p1, ivec2 p2, uint8_t color);
[115]139    void burn_led(int16_t x, int16_t y, int32_t num, int16_t color,
140                  int16_t scale = 1);
[682]141    void SetClip(ivec2 aa, ivec2 bb);
142    void GetClip(ivec2 &aa, ivec2 &bb);
143    void InClip(ivec2 aa, ivec2 bb);
[518]144    void SetClip(int x1, int y1, int x2, int y2);
145    void GetClip(int &x1, int &y1, int &x2, int &y2);
146    void InClip(int x1, int y1, int x2, int y2);
[2]147
[115]148    void dirt_off()
149    {
[515]150        if(m_special && m_special->keep_dirt) m_special->keep_dirt = 0;
[115]151    }
152    void dirt_on()
153    {
[515]154        if(m_special) m_special->keep_dirt = 1;
[115]155    }
[2]156
[682]157    void AddDirty(ivec2 aa, ivec2 bb)
[115]158    {
[670]159        if (m_special) m_special->AddDirty(aa, bb);
[115]160    }
[682]161    void DeleteDirty(ivec2 aa, ivec2 bb)
[115]162    {
[670]163        if(m_special) m_special->DeleteDirty(aa, bb);
[115]164    }
[518]165    void ClearDirties()
[115]166    {
[518]167        if (m_special) m_special->ClearDirties();
[115]168    }
169    void dither(palette *pal); // use a b&w palette!
[682]170    void Scale(ivec2 size);
171    void SetSize(ivec2 size, uint8_t *page = NULL);
[115]172    void flood_fill(int16_t x, int16_t y, uint8_t color);
173    image *create_smooth(int16_t smoothness = 1); // 0 no smoothness
174    void unpack_scanline(int16_t line, char bitsperpixel = 1);
[526]175    void FlipX();
176    void FlipY();
[115]177};
[2]178
[115]179class image_controller
180{
181public:
182    image_controller()
183    {
184        image_init();
185    }
186    ~image_controller()
187    {
188        image_uninit();
189    }
190};
[2]191
[115]192#endif /* _IMAGE_HPP_ */
[2]193
Note: See TracBrowser for help on using the repository browser.