acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
pixmap.h
1#pragma once
2
3
4#include "acme/graphics/image/header.h"
5#include "acme/graphics/image/image32.h"
6#include "acme/graphics/image/_configuration.h"
7//#include "acme/prototype/geometry2d/_geometry2d.h"
8#include "acme/prototype/geometry2d/rectangle.h"
9#include "acme/prototype/prototype/concrete.h"
10
11
12#define __sizeof(TYPE) ((memsize)sizeof(TYPE))
13
14
15//#pragma pack(push, pixmap)
16
17// POD
18
19#ifdef __cplusplus
20struct CLASS_DECL_ACME pixmap :
21 public image_header
22#else
23struct pixmap
24#endif
25{
26
27
28#ifndef __cplusplus
29 struct image_header m_header;
30#endif
31
32 ::i32 m_iRedLower;
33 ::i32 m_iScan;
34 ::image32_t * m_pimage32;
35 ::i32_point m_point;
36 ::image32_t * m_pimage32Raw;
37 ::i32_size m_sizeRaw;
38 ::color_indexes m_colorindexes = common_system_image_color_indexes();
39 mutable bool m_bTrans; // optionally used by implementation
40 mutable bool m_bMapped; // optionally used by implementation
41 bool m_bReduced; // optionally used by implementation
42
43 static ::i32 g_iRedLowerDefault;
44
45#ifdef __cplusplus
46
47 pixmap()
48 {
49 m_iRedLower = g_iRedLowerDefault;
50 m_iScan = 0;
51 m_pimage32 = nullptr;
52 m_pimage32Raw = nullptr;
53 m_bMapped = false;
54 m_bReduced = false;
55 m_bTrans = false;
56
57 }
58
59
60 void clear()
61 {
62
63 reset();
64
65 m_iScan = 0;
66 m_pimage32 = nullptr;
67 m_pimage32Raw = nullptr;
68
69 }
70
71
72 void initialize(const ::i32_size & size, ::image32_t * pimage32, ::i32 iScan)
73 {
74
75 m_size = size;
76
77 m_sizeRaw = size;
78
79 m_pimage32Raw = pimage32;
80
81 m_iScan = iScan;
82
83 m_point.clear();
84
85 map();
86
87 }
88
89
90
91 ::i32 scan_size() const { return m_iScan; }
92
93 inline ::image32_t * image32() { return m_pimage32; }
94 inline ::image32_t * image32() const { return m_pimage32; }
95
96
97 inline ::image32_t * data() { return m_pimage32; }
98 inline ::image32_t * data() const { return m_pimage32; }
99
100
101 inline operator pixmap * () { return this; }
102 inline operator const pixmap * () const { return this; }
103
104
105 inline bool is_ok() const { return ::is_set(this) && area() > 0; }
106
107 inline bool nok() const { return !is_ok(); }
108
109 bool create(::memory& memory, const ::i32_size& size, ::i32 stride = -1);
110
111 inline ::i32_rectangle rectangle() const { return ::i32_rectangle(m_point, m_size); }
112
113 inline ::i32_rectangle rectangle(const ::i32_point & point) const { return ::i32_rectangle(point, m_size); }
114
115 inline ::i32_point top_left() const noexcept { return m_point; }
116 inline ::i32_point origin() const noexcept { return top_left(); }
117 //inline concrete < ::i32_size > size() const noexcept { return m_size; }
118 inline ::i32_size size() const noexcept { return m_size; }
119 inline ::i32 width() const noexcept { return m_size.cx; }
120 inline ::i32 height() const noexcept { return m_size.cy; }
121 inline ::i32 area() const noexcept { return m_size.area(); }
122 inline ::i32 scan_area() const noexcept { return height() * scan_size(); }
123
124
125 inline ::color::color get_pixel(::i32 x, ::i32 y) const
126 {
127
128 return ::image32_get_pixel(image32(), m_colorindexes, scan_size(), height(), x, y);
129
130 }
131
132 inline void set_pixel(::i32 x, ::i32 y, ::color::color color)
133 {
134
135 return ::image32_set_pixel(image32(), m_colorindexes, scan_size(), height(), x, y, color);
136
137 }
138
139 inline ::color::color raw_pixel(::i32 x, ::i32 y) const
140 {
141
142 return ::image32_raw_pixel(image32(), m_colorindexes, scan_size(), height(), x, y);
143
144 }
145
146 inline void set_raw_pixel(::i32 x, ::i32 y, ::color::color color)
147 {
148
149 return ::image32_set_raw_pixel(image32(), m_colorindexes, scan_size(), height(), x, y, color);
150
151 }
152
153 inline ::color::color get_pixel(const ::i32_point & point) const { return get_pixel(point.x, point.y); }
154
155 inline pixmap & operator =(const pixmap & pixmap);
156 inline pixmap & operator =(const ::i32_rectangle & rectangle) { map(rectangle); return *this; }
157
158 void reference(const pixmap& pixmap);
159
160 void map(const ::i32_rectangle & rectangle)
161 {
162
163 m_point = rectangle.origin();
164
165 m_size = rectangle.size();
166
167 map();
168
169 }
170
171 void map() const
172 {
173
174 if (::is_set(m_pimage32Raw))
175 {
176
177 ((pixmap *)this)->m_pimage32 = m_pimage32Raw + (m_point.x + m_iScan * m_point.y);
178
179 }
180
181 }
182
183 void unmap()
184 {
185
186 m_pimage32 = m_pimage32Raw;
187 m_size = m_sizeRaw;
188
189 }
190
191 void mult_alpha();
192
193
194 void vertical_swap();
195
196
197 void copy(const ::i32_size & size, const ::pixmap * ppixmapSrc);
198
199 void y_swap_copy(const ::i32_size& size, const ::pixmap* ppixmapSrc);
200
201 void copy(const ::pixmap * ppixmapSrc);
202
203 void copy(const ::pixmap* ppixmapSrc, const ::image::enum_copy_disposition & ecopydisposition);
204
205 void y_swap_copy(const ::pixmap* ppixmapSrc);
206
207 ::color::color average_color();
208
209#endif
210
211};
212
213//#pragma pack(pop, pixmap)
214
215
216
217
218
219inline void image32_t::copy(const ::i32_size & size, ::i32 iStrideDst, const ::pixmap * ppixmapSrc)
220{
221
222 copy(size.minimum(ppixmapSrc->size()), iStrideDst, ppixmapSrc->m_pimage32, ppixmapSrc->m_iScan);
223
224}
225
226
227
228inline void image32_t::copy(const ::pixmap* p)
229{
230 copy(::i32_point(), p->size(), p->width() * 4, p->image32(), p->m_iScan);
231}
Definition color.h:162
Definition memory.h:33
Definition color_indexes.h:9
Definition image32.h:30
Definition header.h:17
Definition pixmap.h:25