acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
image32.h
1// Refactored by camilo on 2023-06-09 19:06 <3ThomasBorregaardSorensen!!
2// Merge with _image32.cpp From pixmap.h by
3// camilo on 2023-10-09 12:11 <3ThomasBorregaardSorensen!!
4#pragma once
5
6
7#include "acme/graphics/draw2d/color.h"
8#include "acme/prototype/geometry2d/size.h"
9#include "acme/prototype/geometry2d/rectangle.h"
10
11
12
13namespace image
14{
15
16
17 enum enum_copy_disposition
18 {
19
20 e_copy_disposition_none,
21 e_copy_disposition_y_swap,
22
23 };
24
25
26} // namespace image
27
28
29struct CLASS_DECL_ACME image32_t
30{
31
32
33 union
34 {
35
36 ::u32 m_u32;
37 ::u8 m_ua[4];
38
39 };
40
41
42 constexpr image32_t() { m_u32 = 0; }
43 constexpr image32_t(::color::color color, color_indexes indexes);
44 constexpr image32_t(const ::image32_t & image32) : m_u32(image32.m_u32) {}
45
46
47 constexpr ::u8 u8_red(color_indexes indexes) const { return m_ua[indexes.red()]; }
48 constexpr ::u8 u8_green(color_indexes indexes) const { return m_ua[indexes.green()]; }
49 constexpr ::u8 u8_blue(color_indexes indexes) const { return m_ua[indexes.blue()]; }
50 constexpr ::u8 u8_opacity(color_indexes indexes) const { return m_ua[indexes.opacity()]; }
51
52
53 constexpr ::u8 & u8_red(color_indexes indexes) { return m_ua[indexes.red()]; }
54 constexpr ::u8 & u8_green(color_indexes indexes) { return m_ua[indexes.green()]; }
55 constexpr ::u8 & u8_blue(color_indexes indexes) { return m_ua[indexes.blue()]; }
56 constexpr ::u8 & u8_opacity(color_indexes indexes) { return m_ua[indexes.opacity()]; }
57
58
59 constexpr ::color::color color(color_indexes indexes) const;
60 constexpr void assign(::color::color color, color_indexes indexes);
61
62 constexpr ::color::color raw_color(color_indexes indexes) const;
63 constexpr void raw_assign(::color::color color, color_indexes indexes);
64
65 constexpr bool operator == (const image32_t & image) const { return m_u32 == image.m_u32; }
66
67 constexpr rgba_t rgb(color_indexes indexes) const { return { make_u32(u8_red(indexes), u8_green(indexes), u8_blue(indexes), 0) }; }
68
69
70
71 inline ::color::color get_pixel(color_indexes indexes, ::i32 iScan, ::i32 iHeight, ::i32 x, ::i32 y);
72 void vertical_swap_copy( ::i32 cx, ::i32 cy, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc);
73 inline void vertical_swap_copy(const ::i32_size & size, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc)
74 {
75 vertical_swap_copy(size.cx, size.cy, iStrideDst, pimage32Src, iStrideSrc);
76 }
77 ::image32_t * offset(::i32 x, ::i32 y, ::i32 iStrideDst)
78 {
79 return (::image32_t *)((::u8 *)this + x * sizeof(::image32_t) + y * iStrideDst);
80
81 }
82 void copy(::i32 x, ::i32 y, ::i32 cx, ::i32 cy, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc)
83 {
84 return offset(x, y, iStrideDst)->copy(cx, cy, iStrideDst, pimage32Src, iStrideSrc);
85 }
86 void copy(::i32 cx, ::i32 cy, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc);
87 inline void copy(const ::i32_size & size, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc)
88 {
89 copy(size.cx, size.cy, iStrideDst, pimage32Src, iStrideSrc);
90 }
91
92 //void vertical_swap_copy(::i32 cx, ::i32 cy, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc = -1);
93 void vertical_swap_copy_swap_red_blue(::i32 cx, ::i32 cy, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc = -1);
94 inline void vertical_swap_copy_swap_red_blue(const ::i32_size & size, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc = -1)
95 {
96 vertical_swap_copy_swap_red_blue(size.cx, size.cy, iStrideDst, pimage32Src, iStrideSrc);
97 }
98 //void copy(::i32 cx, ::i32 cy, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc = -1);
99 //void copy(::i32 x, ::i32 y, ::i32 cx, ::i32 cy, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc = -1);
100 //void copy(const i32_size & size, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc = -1);
101 inline void copy(const ::i32_point & point, const i32_size & size, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc = -1)
102 {
103 copy(point.x, point.y, size.cx, size.cy, iStrideDst, pimage32Src, iStrideSrc);
104 }
105 inline void copy(const ::i32_rectangle & rectangle, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc = -1)
106 {
107 copy(rectangle.top_left(), rectangle.size(), iStrideDst, pimage32Src, iStrideSrc);
108 }
109 inline void copy(const ::pixmap* p);
110 void copy_swap_red_blue(::i32 cx, ::i32 cy, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc = -1);
111 void swap_red_blue(::i32 cx, ::i32 cy, ::i32 iStride = 0);
112 void _001ProperCopyColorref(::i32 cx, ::i32 cy, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc = -1);
113
114 inline void copy(const ::i32_size & size, ::i32 iStrideDst, const ::pixmap * ppixmapSrc);
115
116 void set_rectangle(::i32 x, ::i32 y, ::i32 w, ::i32 h, ::i32 s, const ::image32_t & source);
117 void blend_rectangle(::i32 x, ::i32 y, ::i32 w, ::i32 h, ::i32 s, const ::image32_t & source);
118
119
120 void copy_3_channel_data(const ::i32_size & size, ::i32 stride, const void * pdata, ::i32 inputStride);
121
122 void copy_1_channel_data(const ::i32_size & size, ::i32 stride, const void * pdata, ::i32 inputStride);
123
124
125 static image32_t * create_copy_of(
126 ::memory &memoryAllocation,
127 const i32_size & size,
128 ::i32 stride,
129 const void *pdata,
130 ::i32 channels,
131 ::i32 inputStride = -1);
132
133
134};
135
136
137//
138//#if defined(WINDOWS) || defined(LINUX) || defined(__i386__) || defined(FREEBSD) || defined(OPENBSD)
139//
140//
141//constexpr ::u32 argb_image32_u32(::u8 u8Opacity, ::u8 u8Red, ::u8 u8Green, ::u8 u8Blue)
142//{
143//
144// return u8Blue
145// | ((::u16)(u8Green) << 8)
146// | (((::u32)(u8Red)) << 16)
147// | (((::u32)(u8Opacity)) << 24);
148//
149//}
150//
151//
157//
158//#else
159//
160//
161//constexpr ::u32 argb_image32_u32(::u8 u8Opacity, ::u8 u8Red, ::u8 u8Green, ::u8 u8Blue)
162//{
163//
164// return u8Red
165// | (((::u16)u8Green) << 8)
166// | (((::u32)u8Blue) << 16)
167// | (((::u32)u8Opacity) << 24);
168//
169//}
170//
176//
177//
178//#endif
179
180
181constexpr image32_t::image32_t(::color::color color, color_indexes indexes)
182{
183
184 assign(color, indexes);
185
186}
187
188
189constexpr ::color::color image32_t::color(color_indexes indexes) const
190{
191
192 return u8_opacity(indexes) == 0 ? ::color::transparent : rgba(u8_red(indexes) * 255 / u8_opacity(indexes), u8_green(indexes) * 255 / u8_opacity(indexes), u8_blue(indexes) * 255 / u8_opacity(indexes), u8_opacity(indexes));
193
194}
195
196
197constexpr void image32_t::assign(::color::color color, color_indexes indexes)
198{
199
200 u8_red(indexes) = color.m_u8Red * color.m_u8Opacity / 255;
201 u8_green(indexes) = color.m_u8Green * color.m_u8Opacity / 255;
202 u8_blue(indexes) = color.m_u8Blue * color.m_u8Opacity / 255;
203 u8_opacity(indexes) = color.m_u8Opacity;
204
205}
206
207
208constexpr ::color::color image32_t::raw_color(color_indexes indexes) const
209{
210
211 return rgba(u8_red(indexes), u8_green(indexes), u8_blue(indexes), u8_opacity(indexes));
212
213}
214
215
216constexpr void image32_t::raw_assign(::color::color color, color_indexes indexes)
217{
218
219 u8_red(indexes) = color.m_u8Red;
220 u8_green(indexes) = color.m_u8Green;
221 u8_blue(indexes) = color.m_u8Blue;
222 u8_opacity(indexes) = color.m_u8Opacity;
223
224}
225
226
227
228
229
230
231
232
233
234
235class color_array;
236
237
238CLASS_DECL_ACME void colora_from_quada(color_array & colora, WINRGBQUAD * prgbquad, ::i32 iCount);
239
240
241CLASS_DECL_ACME void vertical_swap(pixmap * ppixmap);
242
243
244
245namespace draw2d
246{
247
248
249 CLASS_DECL_ACME void image_copy(::image::image *imagethis, ::image::image *pimage);
250 CLASS_DECL_ACME void image_create(::particle * pparticle, ::image::image *& image);
251 CLASS_DECL_ACME void image_create_image(::image::image *pimage, const i32_size & size);
252 CLASS_DECL_ACME ::u32 * image_get_data(::image::image *pimage);
253 CLASS_DECL_ACME graphics * image_get_graphics(::image::image *pimage);
254
255
256} // namespace draw2d
257
258
259inline ::color::color image32_get_pixel(const ::image32_t * pdata, color_indexes indexes, ::i32 iScan, ::i32 iHeight, ::i32 x, ::i32 y)
260{
261
262 ::color::color color;
263
264 //#ifdef __APPLE__
265 //
266 // color = ((::image32_t*)&((::u8*)pdata)[iScan * (iHeight - y - 1)])[x];
267 //
268 //#else
269 //
270 color = ((::image32_t *)&((::u8 *)pdata)[iScan * y])[x].color(indexes);
271 //
272 //#endif
273
274 return color;
275
276}
277
278inline void image32_set_pixel(const ::image32_t * pdata, color_indexes indexes, ::i32 iScan, ::i32 iHeight, ::i32 x, ::i32 y, ::color::color color)
279{
280
281 //#ifdef __APPLE__
282 //
283 // color = ((::image32_t*)&((::u8*)pdata)[iScan * (iHeight - y - 1)])[x];
284 //
285 //#else
286 //
287 ((::image32_t *)&((::u8 *)pdata)[iScan * y])[x].assign(color, indexes);
288 //
289 //#endif
290
291
292}
293
294
295inline ::color::color image32_raw_pixel(const ::image32_t * pdata, color_indexes indexes, ::i32 iScan, ::i32 iHeight, ::i32 x, ::i32 y)
296{
297
298 ::color::color color;
299
300 //#ifdef __APPLE__
301 //
302 // color = ((::image32_t*)&((::u8*)pdata)[iScan * (iHeight - y - 1)])[x];
303 //
304 //#else
305 //
306 color = ((::image32_t *)&((::u8 *)pdata)[iScan * y])[x].raw_color(indexes);
307 //
308 //#endif
309
310 return color;
311
312}
313
314inline void image32_set_raw_pixel(const ::image32_t * pdata, color_indexes indexes, ::i32 iScan, ::i32 iHeight, ::i32 x, ::i32 y, ::color::color color)
315{
316
317 //#ifdef __APPLE__
318 //
319 // color = ((::image32_t*)&((::u8*)pdata)[iScan * (iHeight - y - 1)])[x];
320 //
321 //#else
322 //
323 ((::image32_t *)&((::u8 *)pdata)[iScan * y])[x].raw_assign(color, indexes);
324 //
325 //#endif
326
327
328}
329
330//CLASS_DECL_ACME void copy_image32(::image32_t * pimage32Dst, const ::i32_point & point, const i32_size & size, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc);
331//CLASS_DECL_ACME void copy_image32(::image32_t * pimage32Dst, const ::i32_rectangle & rectangle, ::i32 iStrideDst, const ::image32_t * pimage32Src, ::i32 iStrideSrc);
332
333
334//inline void copy_image32(::image32_t * pimage32Dst, const ::i32_size & size, ::i32 iStrideDst, const ::pixmap * ppixmapSrc);
335
336
337using image32_callback = ::function< void(const ::image32_t*, ::i32, ::i32, ::i32) >;
338
339
340
341
Definition color.h:162
Definition color_array.h:25
Definition _template_forward_declaration.h:297
Definition memory.h:33
source is originator of subjects
Definition source.h:11
Definition color_indexes.h:9
Definition image32.h:30
Definition pixmap.h:25
Definition color.h:10