| TGX 1.0.4 A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.

Loading...
Searching...
No Matches
Image.h
Go to the documentation of this file.
1
5//
6// Copyright 2020 Arvind Singh
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11//version 2.1 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
16// Lesser General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public
19// License along with this library; If not, see <http://www.gnu.org/licenses/>.
20#ifndef _TGX_IMAGE_H_
21#define _TGX_IMAGE_H_
22
23#include "Fonts.h" // include this also when compiled as a C file
24
25// and now only C++, no more plain C
26#ifdef __cplusplus
27
28#include "Misc.h"
29#include "Vec2.h"
30#include "Vec3.h"
31#include "Vec4.h"
32#include "Box2.h"
33#include "Color.h"
34#include "ShaderParams.h"
35#include "Shaders.h"
36#include "Rasterizer.h"
37#include "bseg.h"
38
39#include <stdint.h>
40
41
42 namespace tgx
43{
50 enum EndPath
51 {
52 END_STRAIGHT = -1,
53 END_ROUNDED = 0,
54 END_ARROW_1 = 1,
55 END_ARROW_2 = 2,
56 END_ARROW_3 = 3,
57 END_ARROW_4 = 4,
58 END_ARROW_5 = 5,
59 END_ARROW_SKEWED_1 = 101,
60 END_ARROW_SKEWED_2 = 102,
61 END_ARROW_SKEWED_3 = 103,
62 END_ARROW_SKEWED_4 = 104,
63 END_ARROW_SKEWED_5 = 105,
64 };
65
66
67
68
141 template<typename color_t>
142 class Image
143 {
144
145 // make sure right away that the template parameter is admissible to prevent cryptic error message later.
146 static_assert(is_color<color_t>::value, "color_t must be one of the color types defined in Color.h");
147
148 // befriend all sister Image classes
149 template<typename> friend class Image;
150
151
152 public:
153
154 static const int DEFAULT_STRIDE = -1;
155
156
157 #if (MTOOLS_TGX_EXTENSIONS)
158 #include <mtools/extensions/tgx/tgx_ext_Image.inl>
159 #endif
160
161
162
163
164 //*************************************************************************************************************
165 //*************************************************************************************************************
166 //*************************************************************************************************************
178 //*************************************************************************************************************
179 //*************************************************************************************************************
180 //*************************************************************************************************************
181
182
183
189 Image();
190
191
200 template<typename T> Image(T* buffer, int lx, int ly, int stride = DEFAULT_STRIDE);
201
202
210 template<typename T> Image(T* buffer, iVec2 dim, int stride = DEFAULT_STRIDE);
211
212
219 Image(const Image<color_t>& im, iBox2 subbox);
220
221
229 Image(const Image<color_t> & im) = default;
230
231
241 Image& operator=(const Image<color_t> & im) = default;
242
243
252 template<typename T> void set(T* buffer, int lx, int ly, int stride = DEFAULT_STRIDE);
253
254
262 template<typename T> void set(T* buffer, iVec2 dim, int stride = DEFAULT_STRIDE);
263
264
275 void crop(const iBox2& subbox);
276
277
287 Image<color_t> getCrop(const iBox2& subbox) const;
288
289
299 Image<color_t> operator()(const iBox2& B) const;
300
301
314 Image<color_t> operator()(int min_x, int max_x, int min_y, int max_y) const;
315
316
317
319 //*************************************************************************************************************
320 //*************************************************************************************************************
321 //*************************************************************************************************************
328 //*************************************************************************************************************
329 //*************************************************************************************************************
330 //*************************************************************************************************************
331
332
338 inline TGX_INLINE bool isValid() const { return (_buffer != nullptr); }
339
340
346 void setInvalid();
347
348
354 inline TGX_INLINE int width() const { return _lx; }
355
356
362 inline TGX_INLINE int lx() const { return _lx; }
363
364
370 inline TGX_INLINE int height() const { return _ly; }
371
372
378 inline TGX_INLINE int ly() const { return _ly; }
379
380
386 inline TGX_INLINE int stride() const { return _stride; }
387
388
394 inline TGX_INLINE iVec2 dim() const { return iVec2{ _lx, _ly }; }
395
396
402 inline TGX_INLINE iBox2 imageBox() const { return iBox2(0, _lx - 1, 0, _ly - 1); }
403
404
412 inline TGX_INLINE const color_t * data() const { return _buffer; }
413
414
422 inline TGX_INLINE color_t * data() { return _buffer; }
423
424
425
426
427
428
430 //*************************************************************************************************************
431 //*************************************************************************************************************
432 //*************************************************************************************************************
439 //*************************************************************************************************************
440 //*************************************************************************************************************
441 //*************************************************************************************************************
442
443
444
445
453 template<bool CHECKRANGE = true> TGX_INLINE inline void drawPixel(iVec2 pos, color_t color) { if ((CHECKRANGE) && (!isValid())) return; _drawPixel<CHECKRANGE>(pos, color); }
454
455
465 template<bool CHECKRANGE = true> TGX_INLINE inline void drawPixelf(fVec2 pos, color_t color) { if ((CHECKRANGE) && (!isValid())) return; _drawPixel<CHECKRANGE>({ (int32_t)roundf(pos.x) , (int32_t)roundf(pos.y) }, color); }
466
467
479 template<bool CHECKRANGE = true> TGX_INLINE inline void drawPixel(iVec2 pos, color_t color, float opacity) { if ((CHECKRANGE) && (!isValid())) return; _drawPixel<CHECKRANGE,true>(pos, color, opacity); }
480
481
495 template<bool CHECKRANGE = true> TGX_INLINE inline void drawPixelf(fVec2 pos, color_t color, float opacity) { if ((CHECKRANGE) && (!isValid())) return; _drawPixel<CHECKRANGE, true>({ (int32_t)roundf(pos.x) , (int32_t)roundf(pos.y) }, color, opacity); }
496
497
508 template<bool CHECKRANGE = true> TGX_INLINE inline color_t readPixel(iVec2 pos, color_t outside_color = color_t()) const { if ((CHECKRANGE) && (!isValid())) return outside_color; return _readPixel(pos, outside_color); }
509
510
523 template<bool CHECKRANGE = true> TGX_INLINE inline color_t readPixelf(fVec2 pos, color_t outside_color = color_t()) const { if ((CHECKRANGE) && (!isValid())) return outside_color; return _readPixel({ (int32_t)roundf(pos.x) , (int32_t)roundf(pos.y) }, outside_color); }
524
525
535 TGX_INLINE inline const color_t& operator()(iVec2 pos) const { return _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)]; }
536
546 TGX_INLINE inline color_t& operator()(iVec2 pos) { return _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)]; }
547
548
559 TGX_INLINE inline const color_t& operator()(int x, int y) const { return _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)]; }
560
561
572 TGX_INLINE inline color_t& operator()(int x, int y) { return _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)];}
573
574
600 template<typename ITERFUN> void iterate(ITERFUN cb_fun);
601
602
617 template<typename ITERFUN> void iterate(ITERFUN cb_fun) const;
618
619
632 template<typename ITERFUN> void iterate(ITERFUN cb_fun, tgx::iBox2 B);
633
634
647 template<typename ITERFUN> void iterate(ITERFUN cb_fun, tgx::iBox2 B) const;
648
649
650
651
652
653
654
656 //*************************************************************************************************************
657 //*************************************************************************************************************
658 //*************************************************************************************************************
665 //*************************************************************************************************************
666 //*************************************************************************************************************
667 //*************************************************************************************************************
668
669
683 void blit(const Image<color_t>& sprite, iVec2 upperleftpos, float opacity = TGX_DEFAULT_NO_BLENDING);
684
685
707 template<typename color_t_src, typename BLEND_OPERATOR>
708 void blit(const Image<color_t_src>& sprite, iVec2 upperleftpos, const BLEND_OPERATOR& blend_op);
709
710
724 void blitRotated(const Image<color_t> & sprite, iVec2 upperleftpos, int angle, float opacity = TGX_DEFAULT_NO_BLENDING);
725
726
752 template<typename color_t_src, typename BLEND_OPERATOR>
753 void blitRotated(const Image<color_t_src>& sprite, iVec2 upperleftpos, int angle, const BLEND_OPERATOR& blend_op);
754
755
772 void blitMasked(const Image<color_t>& sprite, color_t transparent_color, iVec2 upperleftpos, float opacity = 1.0f);
773
774
785 void blitBackward(Image<color_t>& dst_sprite, iVec2 upperleftpos) const;
786
787
816 template<typename color_t_src, int CACHE_SIZE = TGX_PROGMEM_DEFAULT_CACHE_SIZE>
817 void blitScaledRotated(const Image<color_t_src> src_im, fVec2 anchor_src, fVec2 anchor_dst, float scale = 1.0f, float angle_degrees = 0.0f, float opacity = TGX_DEFAULT_NO_BLENDING);
818
819
844 template<typename color_t_src, typename BLEND_OPERATOR, int CACHE_SIZE = TGX_PROGMEM_DEFAULT_CACHE_SIZE>
845 void blitScaledRotated(const Image<color_t_src>& src_im, fVec2 anchor_src, fVec2 anchor_dst, float scale, float angle_degrees, const BLEND_OPERATOR& blend_op);
846
847
879 template<typename color_t_src, int CACHE_SIZE = TGX_PROGMEM_DEFAULT_CACHE_SIZE>
880 void blitScaledRotatedMasked(const Image<color_t_src>& src_im, color_t_src transparent_color, fVec2 anchor_src, fVec2 anchor_dst, float scale, float angle_degrees, float opacity = 1.0f);
881
882
897 template<typename src_color_t> void copyFrom(const Image<src_color_t>& src_im, float opacity = TGX_DEFAULT_NO_BLENDING);
898
899
925 template<typename src_color_t, typename BLEND_OPERATOR> void copyFrom(const Image<src_color_t>& src_im, const BLEND_OPERATOR& blend_op);
926
927
943 Image<color_t> copyReduceHalf(const Image<color_t> & src_image);
944
945
954 Image<color_t> reduceHalf();
955
956
974 template<typename color_dst>
975 Image<color_dst> convert();
976
977
978
980 //*************************************************************************************************************
981 //*************************************************************************************************************
982 //*************************************************************************************************************
989 //*************************************************************************************************************
990 //*************************************************************************************************************
991 //*************************************************************************************************************
992
993
994
1002 void fillScreen(color_t color);
1003
1011 void clear(color_t color);
1012
1013
1022 void fillScreenVGradient(color_t top_color, color_t bottom_color);
1023
1024
1033 void fillScreenHGradient(color_t left_color, color_t right_color);
1034
1035
1053 template<int STACK_SIZE = 1024> int fill(iVec2 start_pos, color_t new_color);
1054
1055
1078 template<int STACK_SIZE = 1024> int fill(iVec2 start_pos, color_t border_color, color_t new_color);
1079
1080
1081
1083 //*************************************************************************************************************
1084 //*************************************************************************************************************
1085 //*************************************************************************************************************
1092 //*************************************************************************************************************
1093 //*************************************************************************************************************
1094 //*************************************************************************************************************
1095
1096
1097
1107 void drawFastVLine(iVec2 pos, int h, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1108
1109
1119 void drawFastHLine(iVec2 pos, int w, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1120
1121
1131 void drawLine(iVec2 P1, iVec2 P2, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1132
1133
1146 void drawSegment(iVec2 P1, bool drawP1, iVec2 P2, bool drawP2, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1147
1148
1150 //*************************************************************************************************************
1157 //*************************************************************************************************************
1158
1159
1160
1171 void drawLineAA(fVec2 P1, fVec2 P2, color_t color, float opacity = 1.0f);
1172
1173
1189 void drawThickLineAA(fVec2 P1, fVec2 P2, float line_width, EndPath end_P1, EndPath end_P2, color_t color, float opacity = 1.0f);
1190
1191
1206 void drawWedgeLineAA(fVec2 P1, fVec2 P2, float line_width_P1, EndPath end_P1, float line_width_P2, EndPath end_P2, color_t color, float opacity = 1.0f);
1207
1208
1209
1210#ifndef DOXYGEN_EXCLUDE
1211
1212
1213
1215
1221
1222
1228 DEPRECATED("Use method drawThickLineAA() instead.")
1229 void drawWideLine(fVec2 PA, fVec2 PB, float w, color_t color, float opacity) { drawThickLineAA(PA, PB, w, END_ROUNDED, END_ROUNDED, color, opacity); }
1230
1231
1237 DEPRECATED("Use method drawWedgeLineAA() instead.")
1238 void drawWedgeLine(fVec2 PA, fVec2 PB, float aw, float bw, color_t color, float opacity) { drawWedgeLineAA(PA, PB, 2*aw, END_ROUNDED, 2*bw, END_ROUNDED, color, opacity); }
1239
1240
1246 DEPRECATED("Use method fillCircleAA() instead")
1247 void drawSpot(fVec2 center, float r, color_t color, float opacity) { fillCircleAA(center, r, color, opacity); }
1248
1249
1250#endif
1251
1252
1253
1254
1256 //*************************************************************************************************************
1257 //*************************************************************************************************************
1258 //*************************************************************************************************************
1265 //*************************************************************************************************************
1266 //*************************************************************************************************************
1267 //*************************************************************************************************************
1268
1269
1270
1279 void drawRect(const iBox2 & B, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1280
1281
1291 void drawThickRect(const iBox2& B, int thickness, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1292
1293
1302 void fillRect(const iBox2 & B, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1303
1304
1315 void fillThickRect(const iBox2& B, int thickness, color_t color_interior, color_t color_border, float opacity = TGX_DEFAULT_NO_BLENDING);
1316
1317
1327 void fillRectHGradient(iBox2 B, color_t color_left, color_t color_right, float opacity = TGX_DEFAULT_NO_BLENDING);
1328
1329
1339 void fillRectVGradient(iBox2 B, color_t color_top, color_t color_bottom, float opacity = TGX_DEFAULT_NO_BLENDING);
1340
1341
1342
1344 //*************************************************************************************************************
1363 //*************************************************************************************************************
1364
1365
1366
1367
1381 void drawThickRectAA(const fBox2& B, float thickness, color_t color, float opacity = 1.0f);
1382
1383
1396 void fillRectAA(const fBox2& B, color_t color, float opacity = 1.0f);
1397
1398
1413 void fillThickRectAA(const fBox2& B, float thickness, color_t color_interior, color_t color_border, float opacity = 1.0f);
1414
1415
1416
1417
1418
1419
1420
1422 //*************************************************************************************************************
1423 //*************************************************************************************************************
1424 //*************************************************************************************************************
1431 //*************************************************************************************************************
1432 //*************************************************************************************************************
1433 //*************************************************************************************************************
1434
1435
1436
1446 void drawRoundRect(const iBox2& B, int corner_radius, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1447
1448
1458 void fillRoundRect(const iBox2& B, int corner_radius, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1459
1460
1462 //*************************************************************************************************************
1469 //*************************************************************************************************************
1470
1471
1482 void drawRoundRectAA(const fBox2& B, float corner_radius, color_t color, float opacity = 1.0f);
1483
1484
1496 void drawThickRoundRectAA(const fBox2& B, float corner_radius, float thickness, color_t color, float opacity = 1.0f);
1497
1498
1509 void fillRoundRectAA(const fBox2& B, float corner_radius, color_t color, float opacity = 1.0f);
1510
1511
1524 void fillThickRoundRectAA(const fBox2& B, float corner_radius, float thickness, color_t color_interior, color_t color_border, float opacity = 1.0f);
1525
1526
1527
1528
1529
1530
1531
1533 //*************************************************************************************************************
1534 //*************************************************************************************************************
1535 //*************************************************************************************************************
1542 //*************************************************************************************************************
1543 //*************************************************************************************************************
1544 //*************************************************************************************************************
1545
1546
1557 void drawTriangle(const iVec2& P1, const iVec2& P2, const iVec2& P3, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1558
1559
1560
1572 void fillTriangle(const iVec2& P1, const iVec2& P2, const iVec2& P3, color_t interior_color, color_t outline_color, float opacity = TGX_DEFAULT_NO_BLENDING);
1573
1574
1575
1576
1578 //*************************************************************************************************************
1585 //*************************************************************************************************************
1586
1587
1588
1598 void drawTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, color_t color, float opacity = 1.0f);
1599
1600
1613 void drawThickTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, float thickness, color_t color, float opacity = 1.0f);
1614
1615
1627 void fillTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, color_t color, float opacity = 1.0f);
1628
1629
1643 void fillThickTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, float thickness, color_t color_interior, color_t color_border, float opacity = 1.0f);
1644
1645
1646
1647
1649 //*************************************************************************************************************
1660 //*************************************************************************************************************
1661
1662
1663
1676 template<typename color_alt>
1677 void drawGradientTriangle(fVec2 P1, fVec2 P2, fVec2 P3, color_alt colorP1, color_alt colorP2, color_alt colorP3, float opacity = TGX_DEFAULT_NO_BLENDING);
1678
1679
1703 template<typename color_t_tex>
1704 void drawTexturedTriangle(const Image<color_t_tex>& src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, float opacity = TGX_DEFAULT_NO_BLENDING);
1705
1706
1739 template<typename color_t_tex, typename BLEND_OPERATOR>
1740 void drawTexturedTriangle(const Image<color_t_tex>& src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, const BLEND_OPERATOR& blend_op);
1741
1742
1769 template<typename color_t_tex>
1770 void drawTexturedGradientTriangle(const Image<color_t_tex>& src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, color_t_tex C1, color_t_tex C2, color_t_tex C3, float opacity = TGX_DEFAULT_NO_BLENDING);
1771
1772
1794 template<typename color_t_tex>
1795 void drawTexturedMaskedTriangle(const Image<color_t_tex>& src_im, color_t_tex transparent_color, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, float opacity = 1.0f);
1796
1797
1825 template<typename color_t_tex>
1826 void drawTexturedGradientMaskedTriangle(const Image<color_t_tex>& src_im, color_t_tex transparent_color, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, color_t_tex C1, color_t_tex C2, color_t_tex C3, float opacity = 1.0f);
1827
1828
1829
1830
1831
1832
1833
1835 //*************************************************************************************************************
1836 //*************************************************************************************************************
1837 //*************************************************************************************************************
1844 //*************************************************************************************************************
1845 //*************************************************************************************************************
1846 //*************************************************************************************************************
1847
1848
1860 void drawQuad(iVec2 P1, iVec2 P2, iVec2 P3, iVec2 P4, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1861
1862
1876 void fillQuad(iVec2 P1, iVec2 P2, iVec2 P3, iVec2 P4, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1877
1878
1879
1880
1882 //*************************************************************************************************************
1889 //*************************************************************************************************************
1890
1891
1904 void drawQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, color_t color, float opacity = 1.0f);
1905
1906
1920 void drawThickQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, float thickness, color_t color, float opacity = 1.0f);
1921
1922
1937 void fillQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, color_t color, float opacity = 1.0f);
1938
1939
1956 void fillThickQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, float thickness, color_t color_interior, color_t color_border, float opacity = 1.0f);
1957
1958
1959
1961 //*************************************************************************************************************
1972 //*************************************************************************************************************
1973
1974
1975
1981 template<typename color_alt>
1982 void drawGradientQuad(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, color_alt colorP1, color_alt colorP2, color_alt colorP3, color_alt colorP4, float opacity = TGX_DEFAULT_NO_BLENDING);
1983
1984
1990 template<typename color_t_tex>
1991 void drawTexturedQuad(const Image<color_t_tex>& src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, float opacity = TGX_DEFAULT_NO_BLENDING);
1992
1993
1999 template<typename color_t_tex, typename BLEND_OPERATOR>
2000 void drawTexturedQuad(const Image<color_t_tex>& src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, const BLEND_OPERATOR& blend_op);
2001
2002
2008 template<typename color_t_tex>
2009 void drawTexturedGradientQuad(const Image<color_t_tex>& src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, color_t_tex C1, color_t_tex C2, color_t_tex C3, color_t_tex C4, float opacity = TGX_DEFAULT_NO_BLENDING);
2010
2011
2017 template<typename color_t_tex>
2018 void drawTexturedMaskedQuad(const Image<color_t_tex>& src_im, color_t_tex transparent_color, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, float opacity = 1.0f);
2019
2020
2026 template<typename color_t_tex>
2027 void drawTexturedGradientMaskedQuad(const Image<color_t_tex>& src_im, color_t_tex transparent_color, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, color_t_tex C1, color_t_tex C2, color_t_tex C3, color_t_tex C4, float opacity = 1.0f);
2028
2029
2030
2031
2032
2033
2034
2035
2036
2038 //*************************************************************************************************************
2039 //*************************************************************************************************************
2040 //*************************************************************************************************************
2047 //*************************************************************************************************************
2048 //*************************************************************************************************************
2049 //*************************************************************************************************************
2050
2051
2052
2062 void drawPolyline(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2063
2064
2082 template<typename FUNCTOR_NEXT>
2083 void drawPolyline(FUNCTOR_NEXT next_point, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2084
2085
2086
2087
2088
2090 //*************************************************************************************************************
2097 //*************************************************************************************************************
2098
2099
2100
2101
2112 void drawPolylineAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity = 1.0f);
2113
2114
2133 template<typename FUNCTOR_NEXT>
2134 void drawPolylineAA(FUNCTOR_NEXT next_point, color_t color, float opacity = 1.0f);
2135
2136
2150 void drawThickPolylineAA(int nbpoints, const fVec2 tabPoints[], float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity = 1.0f);
2151
2152
2153
2175 template<typename FUNCTOR_NEXT>
2176 void drawThickPolylineAA(FUNCTOR_NEXT next_point, float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity = 1.0f);
2177
2178
2179
2180
2181
2182
2184 //*************************************************************************************************************
2185 //*************************************************************************************************************
2186 //*************************************************************************************************************
2193 //*************************************************************************************************************
2194 //*************************************************************************************************************
2195 //*************************************************************************************************************
2196
2197
2198
2208 void drawPolygon(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2209
2210
2228 template<typename FUNCTOR_NEXT>
2229 void drawPolygon(FUNCTOR_NEXT next_point, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2230
2231
2243 void fillPolygon(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2244
2245
2268 template<typename FUNCTOR_NEXT>
2269 void fillPolygon(FUNCTOR_NEXT next_point, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2270
2271
2272
2273
2274
2276 //*************************************************************************************************************
2283 //*************************************************************************************************************
2284
2285
2286
2298 void drawPolygonAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity = 1.0f);
2299
2300
2320 template<typename FUNCTOR_NEXT>
2321 void drawPolygonAA(FUNCTOR_NEXT next_point, color_t color, float opacity = 1.0f);
2322
2323
2335 void drawThickPolygonAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t color, float opacity = 1.0f);
2336
2337
2361 template<typename FUNCTOR_NEXT>
2362 void drawThickPolygonAA(FUNCTOR_NEXT next_point, float thickness, color_t color, float opacity = 1.0f);
2363
2364
2377 void fillPolygonAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity = 1.0f);
2378
2379
2403 template<typename FUNCTOR_NEXT>
2404 void fillPolygonAA(FUNCTOR_NEXT next_point, color_t color, float opacity = 1.0f);
2405
2406
2419 void fillThickPolygonAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t interior_color, color_t border_color, float opacity = 1.0f);
2420
2421
2447 template<typename FUNCTOR_NEXT>
2448 void fillThickPolygonAA(FUNCTOR_NEXT next_point, float thickness, color_t interior_color, color_t border_color, float opacity = 1.0f);
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2460 //*************************************************************************************************************
2461 //*************************************************************************************************************
2462 //*************************************************************************************************************
2469 //*************************************************************************************************************
2470 //*************************************************************************************************************
2471 //*************************************************************************************************************
2472
2473
2474
2475
2485 void drawCircle(iVec2 center, int r, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2486
2487
2498 void fillCircle(iVec2 center, int r, color_t interior_color, color_t outline_color, float opacity = TGX_DEFAULT_NO_BLENDING);
2499
2500
2501
2503 //*************************************************************************************************************
2510 //*************************************************************************************************************
2511
2512
2513
2524 void drawCircleAA(fVec2 center, float r, color_t color, float opacity = 1.0f);
2525
2526
2538 void drawThickCircleAA(fVec2 center, float r, float thickness, color_t color, float opacity = 1.0f);
2539
2540
2551 void fillCircleAA(fVec2 center, float r, color_t color, float opacity = 1.0f);
2552
2553
2566 void fillThickCircleAA(fVec2 center, float r, float thickness, color_t color_interior, color_t color_border, float opacity = 1.0f);
2567
2568
2569
2570
2571
2573 //*************************************************************************************************************
2574 //*************************************************************************************************************
2575 //*************************************************************************************************************
2582 //*************************************************************************************************************
2583 //*************************************************************************************************************
2584 //*************************************************************************************************************
2585
2586
2607 void drawCircleArcAA(fVec2 center, float r, float angle_start, float angle_end, color_t color, float opacity = 1.0f);
2608
2609
2631 void drawThickCircleArcAA(fVec2 center, float r, float angle_start, float angle_end, float thickness, color_t color, float opacity = 1.0f);
2632
2633
2654 void fillCircleSectorAA(fVec2 center, float r, float angle_start, float angle_end, color_t color, float opacity = 1.0f);
2655
2656
2679 void fillThickCircleSectorAA(fVec2 center, float r, float angle_start, float angle_end, float thickness, color_t color_interior, color_t color_border, float opacity = 1.0f);
2680
2681
2682
2683
2684
2685
2687 //*************************************************************************************************************
2688 //*************************************************************************************************************
2689 //*************************************************************************************************************
2696 //*************************************************************************************************************
2697 //*************************************************************************************************************
2698 //*************************************************************************************************************
2699
2700
2701
2711 void drawEllipse(iVec2 center, iVec2 radiuses, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2712
2713
2724 void fillEllipse(iVec2 center, iVec2 radiuses, color_t interior_color, color_t outline_color, float opacity = TGX_DEFAULT_NO_BLENDING);
2725
2726
2727
2728
2730 //*************************************************************************************************************
2737 //*************************************************************************************************************
2738
2739
2740
2751 void drawEllipseAA(fVec2 center, fVec2 radiuses, color_t color, float opacity = 1.0f);
2752
2753
2765 void drawThickEllipseAA(fVec2 center, fVec2 radiuses, float thickness, color_t color, float opacity = 1.0f);
2766
2767
2778 void fillEllipseAA(fVec2 center, fVec2 radiuses, color_t color, float opacity = 1.0f);
2779
2780
2793 void fillThickEllipseAA(fVec2 center, fVec2 radiuses, float thickness, color_t color_interior, color_t color_border, float opacity = 1.0f);
2794
2795
2796
2797
2798
2800 //*************************************************************************************************************
2801 //*************************************************************************************************************
2802 //*************************************************************************************************************
2809 //*************************************************************************************************************
2810 //*************************************************************************************************************
2811 //*************************************************************************************************************
2812
2813
2814
2815
2828 void drawQuadBezier(iVec2 P1, iVec2 P2, iVec2 PC, float wc, bool drawP2, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2829
2830
2843 void drawCubicBezier(iVec2 P1, iVec2 P2, iVec2 PA, iVec2 PB, bool drawP2, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2844
2845
2863 template<int SPLINE_MAX_POINTS = 32>
2864 void drawQuadSpline(int nbpoints, const iVec2 tabPoints[], bool draw_last_point, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2865
2866
2884 template<int SPLINE_MAX_POINTS = 32>
2885 void drawCubicSpline(int nbpoints, const iVec2 tabPoints[], bool draw_last_point, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2886
2887
2904 template<int SPLINE_MAX_POINTS = 32>
2905 void drawClosedSpline(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2906
2907
2908
2909
2910
2912 //*************************************************************************************************************
2919 //*************************************************************************************************************
2920
2921
2938 void drawThickQuadBezierAA(fVec2 P1, fVec2 P2, fVec2 PC, float wc, float thickness, EndPath end_P1, EndPath end_P2, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2939
2940
2957 void drawThickCubicBezierAA(fVec2 P1, fVec2 P2, fVec2 PA, fVec2 PB, float thickness, EndPath end_P1, EndPath end_P2, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2958
2959
2981 template<int SPLINE_MAX_POINTS = 32>
2982 void drawThickQuadSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2983
2984
3006 template<int SPLINE_MAX_POINTS = 32>
3007 void drawThickCubicSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3008
3009
3029 template<int SPLINE_MAX_POINTS = 32>
3030 void drawThickClosedSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3031
3032
3054 template<int SPLINE_MAX_POINTS = 32>
3055 void fillClosedSplineAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3056
3057
3085 template<int SPLINE_MAX_POINTS = 32>
3086 void fillThickClosedSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t color_interior, color_t color_border, float opacity = TGX_DEFAULT_NO_BLENDING);
3087
3088
3089
3090
3091
3092
3094 //*************************************************************************************************************
3095 //*************************************************************************************************************
3096 //*************************************************************************************************************
3110 //*************************************************************************************************************
3111 //*************************************************************************************************************
3112 //*************************************************************************************************************
3113
3114
3115
3127 int fontHeight(const GFXfont & font) const;
3128
3129
3141 int fontHeight(const ILI9341_t3_font_t& font) const;
3142
3143
3161 iBox2 measureChar(char c, iVec2 pos, const GFXfont& font, Anchor anchor = DEFAULT_TEXT_ANCHOR, int* xadvance = nullptr) const;
3162
3163
3181 iBox2 measureChar(char c, iVec2 pos, const ILI9341_t3_font_t& font, Anchor anchor = DEFAULT_TEXT_ANCHOR, int* xadvance = nullptr) const;
3182
3183
3200 iBox2 measureText(const char * text, iVec2 pos, const GFXfont& font, Anchor anchor = DEFAULT_TEXT_ANCHOR, bool wrap_text = false, bool start_newline_at_0 = false) const;
3201
3202
3219 iBox2 measureText(const char * text, iVec2 pos, const ILI9341_t3_font_t& font, Anchor anchor = DEFAULT_TEXT_ANCHOR, bool wrap_text = false, bool start_newline_at_0 = false) const;
3220
3221
3238 iVec2 drawChar(char c, iVec2 pos, const GFXfont& font, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3239
3240
3257 iVec2 drawChar(char c, iVec2 pos, const ILI9341_t3_font_t& font, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3258
3259
3277 iVec2 drawText(const char* text, iVec2 pos, const GFXfont& font, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3278
3279
3297 iVec2 drawText(const char* text, iVec2 pos, const ILI9341_t3_font_t& font, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3298
3299
3300
3324 iVec2 drawTextEx(const char* text, iVec2 pos, const GFXfont& font, Anchor anchor, bool wrap_text, bool start_newline_at_0, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3325
3326
3350 iVec2 drawTextEx(const char* text, iVec2 pos, const ILI9341_t3_font_t& font, Anchor anchor, bool wrap_text, bool start_newline_at_0, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3351
3352
3353
3354
3355
3356#ifndef DOXYGEN_EXCLUDE
3357
3358
3359
3361 //*************************************************************************************************************
3367 //*************************************************************************************************************
3369
3370
3374 DEPRECATED("Use new signature: drawText(text, pos, font, color, opacity) or the new method drawTextEx()")
3375 iVec2 drawText(const char* text, iVec2 pos, color_t color, const ILI9341_t3_font_t& font, bool start_newline_at_0, float opacity = 1.0f) { return drawTextEx(text, pos, DEFAULT_TEXT_ANCHOR, font, false, start_newline_at_0, color, opacity); }
3376
3377
3381 DEPRECATED("Use new signature: drawText(text, pos, font, color, opacity) or the new method drawTextEx()")
3382 iVec2 drawText(const char* text, iVec2 pos, color_t color, const GFXfont& font, bool start_newline_at_0, float opacity = 1.0f) { return drawTextEx(text, pos, DEFAULT_TEXT_ANCHOR, font, false, start_newline_at_0, color, opacity); }
3383
3384
3388 DEPRECATED("Use new signature measureText(text,pos,font,anchor, wrap, newline_at_0)")
3389 iBox2 measureText(const char* text, iVec2 pos, const GFXfont& font, bool start_newline_at_0) { return measureText(text, pos, font, DEFAULT_TEXT_ANCHOR, false, start_newline_at_0); }
3390
3391
3395 DEPRECATED("Use new signature measureText(text,pos,font,anchor, wrap, newline_at_0)")
3396 iBox2 measureText(const char* text, iVec2 pos, const ILI9341_t3_font_t& font, bool start_newline_at_0) { return measureText(text, pos, font, DEFAULT_TEXT_ANCHOR, false, start_newline_at_0); }
3397
3398
3399#endif
3400
3401
3402
3403
3404
3406 //*************************************************************************************************************
3407 //*************************************************************************************************************
3408 //*************************************************************************************************************
3415 //*************************************************************************************************************
3416 //*************************************************************************************************************
3417 //*************************************************************************************************************
3418
3419
3420
3428 template<typename T> void setOpenFontRender(T& ofr, float opacity = TGX_DEFAULT_NO_BLENDING)
3429 {
3430 // for some strange reason, cannot put this method inside the .inl file when compiling with arduino IDE...
3431 // must have something to do with Arduino's mangling of .ino file...
3432 if ((opacity >= 0) && (opacity < 1))
3433 {
3434 ofr.set_drawPixel([&](int32_t x, int32_t y, uint16_t c) { drawPixel({ x,y }, color_t(RGB565(c)), opacity); return; });
3435 ofr.set_drawFastHLine([&](int32_t x, int32_t y, int32_t w, uint16_t c) { drawFastHLine({ x,y }, w, color_t(RGB565(c)), opacity); return; });
3436 }
3437 else
3438 {
3439 ofr.set_drawPixel([&](int32_t x, int32_t y, uint16_t c) { drawPixel({ x,y }, color_t(RGB565(c))); return; });
3440 ofr.set_drawFastHLine([&](int32_t x, int32_t y, int32_t w, uint16_t c) { drawFastHLine({ x,y }, w, color_t(RGB565(c))); return; });
3441 }
3442 ofr.set_startWrite([&](void) { return; });
3443 ofr.set_endWrite([&](void) { return; });
3444 }
3445
3446
3468 template<typename PNG_T> int PNGDecode(PNG_T& png, iVec2 topleft = iVec2(0, 0), float opacity = 1.0f);
3469
3470
3498 template<typename JPEG_T> int JPEGDecode(JPEG_T& jpeg, iVec2 topleft = iVec2(0, 0), int options = 0, float opacity = 1.0f);
3499
3500
3528 template<typename GIF_T> int GIFplayFrame(GIF_T& gif, iVec2 topleft = iVec2(0, 0), float opacity = 1.0f);
3529
3530
3531
3532
3533
3534
3536
3537
3538 //**************************************************************************************************************************************************
3539 //**************************************************************************************************************************************************
3540 //**************************************************************************************************************************************************
3541 //
3542 // IMPLEMENTATION
3543 //
3544 //
3545 // Don't you dare look below... this is private :-p
3546 //
3547 //***************************************************************************************************************************************************
3548 //***************************************************************************************************************************************************
3549 //***************************************************************************************************************************************************
3550
3551
3552
3553 private:
3554
3555 bool _collision(); // For debug
3556
3557 private:
3558
3559 inline void _checkvalid() { if ((_lx <= 0) || (_ly <= 0) || (_stride < _lx) || (_buffer == nullptr)) setInvalid(); } // Make sure the image parameters are ok, else mark the image as invalid.
3560
3561
3562
3563 /***************************************
3564 * COPY / RESIZE / BLIT
3565 ****************************************/
3566
3567 static inline void _fast_memset(color_t* p_dest, color_t color, int32_t len);
3568
3569 template<typename color_t_src> bool _blitClip(const Image<color_t_src>& sprite, int& dest_x, int& dest_y, int& sprite_x, int& sprite_y, int& sx, int& sy);
3570 bool _blitClip(int sprite_lx, int sprite_ly, int& dest_x, int& dest_y, int& sprite_x, int& sprite_y, int& sx, int& sy);
3571
3572 void _blit(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy);
3573 static void _blitRegion(color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy) { if ((size_t)pdest <= (size_t)psrc) _blitRegionUp(pdest, dest_stride, psrc, src_stride, sx, sy); else _blitRegionDown(pdest, dest_stride, psrc, src_stride, sx, sy); }
3574 static void _blitRegionUp(color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy);
3575 static void _blitRegionDown(color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy);
3576
3577 void _blit(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, float opacity);
3578 static void _blitRegion(color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy, float opacity) { if ((size_t)pdest <= (size_t)psrc) _blitRegionUp(pdest, dest_stride, psrc, src_stride, sx, sy, opacity); else _blitRegionDown(pdest, dest_stride, psrc, src_stride, sx, sy, opacity); }
3579 static void _blitRegionUp(color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy, float opacity);
3580 static void _blitRegionDown(color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy, float opacity);
3581
3582 template<typename color_t_src, typename BLEND_OPERATOR> void _blit(const Image<color_t_src>& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, const BLEND_OPERATOR& blend_op);
3583 template<typename color_t_src, typename BLEND_OPERATOR> static void _blitRegion(color_t* pdest, int dest_stride, color_t_src * psrc, int src_stride, int sx, int sy, const BLEND_OPERATOR& blend_op) { if ((size_t)pdest <= (size_t)psrc) _blitRegionUp(pdest, dest_stride, psrc, src_stride, sx, sy, blend_op); else _blitRegionDown(pdest, dest_stride, psrc, src_stride, sx, sy, blend_op); }
3584 template<typename color_t_src, typename BLEND_OPERATOR> static void _blitRegionUp(color_t* pdest, int dest_stride, color_t_src * psrc, int src_stride, int sx, int sy, const BLEND_OPERATOR& blend_op);
3585 template<typename color_t_src, typename BLEND_OPERATOR> static void _blitRegionDown(color_t* pdest, int dest_stride, color_t_src* psrc, int src_stride, int sx, int sy, const BLEND_OPERATOR& blend_op);
3586
3587 void _blitMasked(const Image& sprite, color_t transparent_color, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, float opacity);
3588 static void _maskRegion(color_t transparent_color, color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy, float opacity) { if ((size_t)pdest <= (size_t)psrc) _maskRegionUp(transparent_color, pdest, dest_stride, psrc, src_stride, sx, sy, opacity); else _maskRegionDown(transparent_color, pdest, dest_stride, psrc, src_stride, sx, sy, opacity); }
3589 static void _maskRegionUp(color_t transparent_color, color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy, float opacity);
3590 static void _maskRegionDown(color_t transparent_color, color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy, float opacity);
3591
3592 template<typename color_t_src, int CACHE_SIZE, bool USE_BLENDING, bool USE_MASK, bool USE_CUSTOM_OPERATOR, typename BLEND_OPERATOR>
3593 void _blitScaledRotated(const Image<color_t_src>& src_im, color_t_src transparent_color, fVec2 anchor_src, fVec2 anchor_dst, float scale, float angle_degrees, float opacity, const BLEND_OPERATOR& blend_op);
3594
3595 void _blitRotated90(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, float opacity);
3596 void _blitRotated180(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, float opacity);
3597 void _blitRotated270(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, float opacity);
3598
3599 template<typename color_t_src, typename BLEND_OPERATOR> void _blitRotated90blend(const Image<color_t_src>& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, const BLEND_OPERATOR& blend_op);
3600 template<typename color_t_src, typename BLEND_OPERATOR> void _blitRotated180blend(const Image<color_t_src>& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, const BLEND_OPERATOR& blend_op);
3601 template<typename color_t_src, typename BLEND_OPERATOR> void _blitRotated270blend(const Image<color_t_src>& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, const BLEND_OPERATOR& blend_op);
3602
3603
3604 /***************************************
3605 * FLOOD FILLING
3606 ****************************************/
3607
3608 template<bool UNICOLOR_COMP, int STACK_SIZE_BYTES> int _scanfill(int x, int y, color_t border_color, color_t new_color);
3609
3610
3611
3612 /***************************************
3613 * BRESENHAM
3614 ****************************************/
3615
3616 template<bool X_MAJOR, bool BLEND, int SIDE, bool CHECKRANGE = false> inline TGX_INLINE void _bseg_update_pixel(const BSeg & seg, color_t color, int32_t op)
3617 {
3618 const int x = seg.X(); const int y = seg.Y();
3619 if (CHECKRANGE) { if ((x < 0) || (y < 0) || (x >= _lx) || (y >= _ly)) return; }
3620 if (SIDE != 0) { const int32_t o = ((seg.AA<SIDE, X_MAJOR>()) * op) >> 8; _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)].blend256(color, (uint32_t)o); }
3621 else if (BLEND) { _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)].blend256(color, (uint32_t)op); }
3622 else { _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)] = color; }
3623 }
3624
3625 template<bool CHECKRANGE = false> inline TGX_INLINE void _bseg_update_pixel(const BSeg & seg, color_t color, int32_t op, int32_t aa)
3626 {
3627 const int x = seg.X(); const int y = seg.Y();
3628 if (CHECKRANGE) { if ((x < 0) || (y < 0) || (x >= _lx) || (y >= _ly)) return; }
3629 _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)].blend256(color, (uint32_t)((op * aa)>>8));
3630 }
3631
3632
3633 template<int SIDE> void _bseg_draw_template(BSeg& seg, bool draw_first, bool draw_last, color_t color, int32_t op, bool checkrange);
3634 void _bseg_draw(BSeg & seg, bool draw_first, bool draw_last, color_t color, int side, int32_t op, bool checkrange);
3635 void _bseg_draw_AA(BSeg & seg, bool draw_first, bool draw_last, color_t color, int32_t op, bool checkrange);
3636
3637 template<int SIDE> void _bseg_avoid1_template(BSeg& segA, bool lastA, BSeg& segB, bool lastB, color_t color, int32_t op, bool checkrange);
3638 void _bseg_avoid1(BSeg& PQ, BSeg& PA, bool drawP, bool drawQ, bool closedPA, color_t color, int side, int32_t op, bool checkrange);
3639 template<int SIDE> void _bseg_avoid2_template(BSeg& segA, bool lastA, BSeg& segB, bool lastB, BSeg& segC, bool lastC, color_t color, int32_t op, bool checkrange);
3640 void _bseg_avoid2(BSeg & PQ, BSeg & PA, BSeg & PB, bool drawQ, bool closedPA, bool closedPB, color_t color, int side, int32_t op, bool checkrange);
3641 template<int SIDE> void _bseg_avoid11_template(BSeg& segA, BSeg& segB, bool lastB, BSeg& segD, bool lastD, color_t color, int32_t op, bool checkrange);
3642 void _bseg_avoid11(BSeg & PQ, BSeg& PA, BSeg & QB, bool drawP, bool drawQ, bool closedPA, bool closedQB, color_t color, int side, int32_t op, bool checkrange);
3643 template<int SIDE> void _bseg_avoid21_template(BSeg& segA, BSeg& segB, bool lastB, BSeg& segC, bool lastC, BSeg& segD, bool lastD, color_t color, int32_t op, bool checkrange);
3644 void _bseg_avoid21(BSeg& PQ, BSeg& PA, BSeg& PB, BSeg& QC, bool closedPA, bool closedPB, bool closedQC, color_t color, int side, int32_t op, bool checkrange);
3645 template<int SIDE> void _bseg_avoid22_template(BSeg& segA, BSeg& segB, bool lastB, BSeg& segC, bool lastC, BSeg& segD, bool lastD, BSeg& segE, bool lastE, color_t color, int32_t op, bool checkrange);
3646 void _bseg_avoid22(BSeg& PQ, BSeg& PA, BSeg& PB, BSeg& QC, BSeg& QD, bool closedPA, bool closedPB, bool closedQC, bool closedQD, color_t color, int side, int32_t op, bool checkrange);
3647
3648
3649 // filling a triangle
3650
3651 //void _bseg_fill_triangle(iVec2 P1, iVec2 P2, iVec2 P3, color_t fillcolor, float opacity);
3652 void _bseg_fill_triangle(fVec2 fP1, fVec2 fP2, fVec2 fP3, color_t fillcolor, float opacity);
3653 void _bseg_fill_triangle_precomputed(fVec2 fP1, fVec2 fP2, fVec2 fP3, BSeg & seg12, BSeg & seg21, BSeg & seg23, BSeg & seg32, BSeg & seg31, BSeg & seg13, color_t fillcolor, float opacity);
3654 void _bseg_fill_triangle_precomputed_sub(fVec2 fP1, fVec2 fP2, fVec2 fP3, BSeg & seg12, BSeg & seg21, BSeg & seg23, BSeg & seg32, BSeg & seg31, BSeg & seg13, color_t fillcolor, float opacity);
3655 void _bseg_fill_interior_angle(iVec2 P, iVec2 Q1, iVec2 Q2, BSeg& seg1, BSeg& seg2, color_t color, bool fill_last, float opacity);
3656 void _bseg_fill_interior_angle_sub(int dir, int y, int ytarget, BSeg& sega, BSeg& segb, color_t color, float opacity);
3657
3658 void _triangle_hline(int x1, int x2, const int y, color_t color, float opacity)
3659 { // like drawFasthLine but used by _bseg_fill_interior_angle_sub
3660 x1 = tgx::max(0, x1); x2 = tgx::min(_lx - 1, x2);
3661 color_t* p = _buffer + TGX_CAST32(x1) + TGX_CAST32(y) * TGX_CAST32(_stride);
3662 if (opacity < 0) { while (x1++ <= x2) { (*p++) = color; } } else { while (x1++ <= x2) { (*p++).blend(color,opacity); } }
3663 }
3664
3665 template<typename T> static inline T _triangleAera(Vec2<T> P1, Vec2<T> P2, Vec2<T> P3) { return P1.x * (P2.y - P3.y) + P2.x * (P3.y - P1.y) + P3.x * (P1.y - P2.y); } // return twice the aera of the triangle.
3666
3667
3668
3669 /***************************************
3670 * DRAWING LINES
3671 ****************************************/
3672
3673 template<bool CHECKRANGE, bool CHECK_VALID_BLEND = true> TGX_INLINE inline void _drawPixel(iVec2 pos, color_t color, float opacity)
3674 {
3675 if (CHECKRANGE) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return; }
3676 if ((CHECK_VALID_BLEND) && ((opacity < 0)||(opacity>1))) _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)] = color; else _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)].blend(color, opacity);
3677 }
3678
3679 template<bool CHECKRANGE> TGX_INLINE inline void _drawPixel(iVec2 pos, color_t color)
3680 {
3681 if (CHECKRANGE) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return; }
3682 _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)] = color;
3683 }
3684
3685 TGX_INLINE inline void _drawPixel(bool checkrange, iVec2 pos, color_t color, float opacity)
3686 {
3687 if (checkrange) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return; }
3688 if ((opacity < 0)||(opacity>1)) _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)] = color; else _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)].blend(color, opacity);
3689 }
3690
3691 TGX_INLINE inline void _drawPixel(bool checkrange, iVec2 pos, color_t color)
3692 {
3693 if (checkrange) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return; }
3694 _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)] = color;
3695 }
3696
3697 template<bool CHECKRANGE = true> TGX_INLINE inline color_t _readPixel(iVec2 pos, color_t outside_color) const
3698 {
3699 if (CHECKRANGE) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return outside_color; }
3700 return _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)];
3701 }
3702
3703 template<bool CHECKRANGE> void _drawFastVLine(iVec2 pos, int h, color_t color, float opacity);
3704 template<bool CHECKRANGE> void _drawFastHLine(iVec2 pos, int w, color_t color, float opacity);
3705 template<bool CHECKRANGE> void _drawFastVLine(iVec2 pos, int h, color_t color);
3706 template<bool CHECKRANGE> void _drawFastHLine(iVec2 pos, int w, color_t color);
3707
3708 inline TGX_INLINE void _drawFastVLine(bool checkrange, iVec2 pos, int h, color_t color, float opacity) { if (checkrange) _drawFastVLine<true>(pos, h, color, opacity); else _drawFastVLine<false>(pos, h, color, opacity); }
3709 inline TGX_INLINE void _drawFastHLine(bool checkrange, iVec2 pos, int w, color_t color, float opacity) { if (checkrange) _drawFastHLine<true>(pos, w, color, opacity); else _drawFastHLine<false>(pos, w, color, opacity); }
3710 inline TGX_INLINE void _drawFastVLine(bool checkrange, iVec2 pos, int h, color_t color) { if (checkrange) _drawFastVLine<true>(pos, h, color); else _drawFastVLine<false>(pos, h, color); }
3711 inline TGX_INLINE void _drawFastHLine(bool checkrange, iVec2 pos, int w, color_t color) { if (checkrange) _drawFastHLine<true>(pos, w, color); else _drawFastHLine<false>(pos, w, color); }
3712 inline TGX_INLINE void _drawSeg(iVec2 P1, bool drawP1, iVec2 P2, bool drawP2, color_t color, float opacity) { BSeg seg(P1, P2); _bseg_draw(seg, drawP1, drawP2, color, 0, (int32_t)(opacity * 256), true); }
3713
3714
3715 void _drawEnd(float distAB, fVec2 A, fVec2 B, BSeg& segAB, BSeg& segBA, BSeg& segAP, BSeg& segBQ, EndPath end, int w, color_t color, float opacity);
3716
3717 // legacy (not used anymore)
3718 void _drawWedgeLine(float ax, float ay, float bx, float by, float aw, float bw, color_t color, float opacity);
3719 float _wedgeLineDistance(float pax, float pay, float bax, float bay, float dr);
3720
3721
3722
3723
3724 /***************************************
3725 * RECT AND ROUNDED RECT
3726 ****************************************/
3727
3728
3729 // low quality drawing
3730 void _fillRect(iBox2 B, color_t color, float opacity);
3731 template<bool CHECKRANGE> void _drawRoundRect(int x, int y, int w, int h, int r, color_t color);
3732 template<bool CHECKRANGE> void _drawRoundRect(int x, int y, int w, int h, int r, color_t color, float opacity);
3733 template<bool CHECKRANGE> void _fillRoundRect(int x, int y, int w, int h, int r, color_t color);
3734 template<bool CHECKRANGE> void _fillRoundRect(int x, int y, int w, int h, int r, color_t color, float opacity);
3735
3736
3737 // high quality drawing
3738 void _fillSmoothRect(const fBox2& B, color_t color, float opacity);
3739 void _fillSmoothRoundedRect(const tgx::iBox2& B, float corner_radius, color_t color, float opacity);
3740 void _drawSmoothRoundRect(const tgx::iBox2& B, float corner_radius, color_t color, float opacity);
3741 void _drawSmoothWideRoundRect(const tgx::iBox2& B, float corner_radius, float thickness, color_t color, float opacity);
3742
3743
3744
3745 /***************************************
3746 * TRIANGLES
3747 ****************************************/
3748
3749
3750 // methods using the 3D triangle rasterizer
3751 inline TGX_INLINE tgx::fVec2 _coord_texture(tgx::fVec2 pos, tgx::iVec2 size) { return tgx::fVec2(pos.x / ((float)size.x), pos.y / ((float)size.y)); } // Convert to texture coordinates
3752 inline TGX_INLINE tgx::fVec2 _coord_viewport(tgx::fVec2 pos, tgx::iVec2 size) { return tgx::fVec2((2.0f / ((float)size.x)) * (pos.x) - 1.0f, (2.0f / ((float)size.y)) * (pos.y) - 1.0f); } // Convert to viewport coordinates
3753
3754 template<typename color_alt, bool USE_BLENDING> void _drawGradientTriangle(fVec2 P1, fVec2 P2, fVec2 P3, color_alt colorP1, color_alt colorP2, color_alt colorP3, float opacity);
3755 template<typename color_t_tex, bool GRADIENT, bool USE_BLENDING, bool MASKED> void _drawTexturedTriangle(const Image<color_t_tex>& src_im, color_t_tex transparent_color, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, color_t_tex C1, color_t_tex C2, color_t_tex C3, float opacity);
3756
3757
3758
3759 /***************************************
3760 * QUADS
3761 ****************************************/
3762
3763
3764
3765 /***************************************
3766 * POLYGONS AND POLYLINES
3767 ****************************************/
3768
3769
3770
3771 /***************************************
3772 * CIRCLES, ARC AND PIES
3773 ****************************************/
3774
3775
3776 // low quality drawing for circles
3777 template<bool CHECKRANGE> void _drawCircleHelper(int x0, int y0, int r, int cornername, color_t color, float opacity); // adapted from Adafruit GFX library
3778 template<bool CHECKRANGE> void _fillCircleHelper(int x0, int y0, int r, int corners, int delta, color_t color, float opacity); // adapted from Adafruit GFX library
3779 template<bool OUTLINE, bool FILL, bool CHECKRANGE> void _drawFilledCircle(int xm, int ym, int r, color_t color, color_t fillcolor, float opacity); // filled circle drawing method
3780
3781
3782 // high quality drawing for circle, arc and pie
3783 static float _rectifyAngle(float a);
3784 static void _defaultQuarterVH(int quarter, int& v, int& h);
3785
3786 void _fillSmoothQuarterCircleInterHPsub(tgx::fVec2 C, float R, int quarter, bool vertical_center_line, bool horizontal_center_line, color_t color, float opacity, int nb_planes, int32_t kx1 = 0, int32_t ky1 = 0, int32_t off1 = 0, int32_t off1_full = 0, int32_t kx2 = 0, int32_t ky2 = 0, int32_t off2 = 0, int32_t off2_full = 0);
3787 void _fillSmoothQuarterCircleInterHP0(int quarter, tgx::fVec2 C, float R, color_t color, float opacity);
3788 void _fillSmoothQuarterCircleInterHP1(int quarter, tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg1, int side1);
3789 void _fillSmoothQuarterCircleInterHP2(int quarter, tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg1, int side1, const BSeg& seg2, int side2);
3790 void _fillSmoothCircleInterHP(tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg, int side); // used to draw rounded ends
3791
3792 void _drawSmoothQuarterCircleInterHPsub(tgx::fVec2 C, float R, int quarter, bool vertical_center_line, bool horizontal_center_line, color_t color, float opacity, int nb_planes, int32_t kx1 = 0, int32_t ky1 = 0, int32_t off1 = 0, int32_t off1_full = 0, int32_t kx2 = 0, int32_t ky2 = 0, int32_t off2 = 0, int32_t off2_full = 0);
3793 void _drawSmoothQuarterCircleInterHP0(int quarter, tgx::fVec2 C, float R, color_t color, float opacity);
3794 void _drawSmoothQuarterCircleInterHP1(int quarter, tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg1, int side1);
3795 void _drawSmoothQuarterCircleInterHP2(int quarter, tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg1, int side1, const BSeg& seg2, int side2);
3796
3797 void _drawSmoothThickQuarterCircleInterHPsub(tgx::fVec2 C, float R, float thickness, int quarter, bool vertical_center_line, bool horizontal_center_line, color_t color, float opacity, int nb_planes, int32_t kx1 = 0, int32_t ky1 = 0, int32_t off1 = 0, int32_t off1_full = 0, int32_t kx2 = 0, int32_t ky2 = 0, int32_t off2 = 0, int32_t off2_full = 0);
3798 void _drawSmoothThickQuarterCircleInterHP0(int quarter, tgx::fVec2 C, float R, float thickness, color_t color, float opacity);
3799 void _drawSmoothThickQuarterCircleInterHP1(int quarter, tgx::fVec2 C, float R, float thickness, color_t color, float opacity, const BSeg& seg1, int side1);
3800 void _drawSmoothThickQuarterCircleInterHP2(int quarter, tgx::fVec2 C, float R, float thickness, color_t color, float opacity, const BSeg& seg1, int side1, const BSeg& seg2, int side2);
3801
3802 void _fillSmoothThickQuarterCircleInterHPsub(tgx::fVec2 C, float R, float thickness, int quarter, bool vertical_center_line, bool horizontal_center_line, color_t color_interior, color_t color_border, float opacity, int nb_planes, int32_t kx1 = 0, int32_t ky1 = 0, int32_t off1 = 0, int32_t off1_full = 0, int32_t kx2 = 0, int32_t ky2 = 0, int32_t off2 = 0, int32_t off2_full = 0);
3803 void _fillSmoothThickQuarterCircleInterHP0(int quarter, tgx::fVec2 C, float R, float thickness, color_t color_interior, color_t color_border, float opacity);
3804 void _fillSmoothThickQuarterCircleInterHP1(int quarter, tgx::fVec2 C, float R, float thickness, color_t color_interior, color_t color_border, float opacity, const BSeg& seg1, int side1);
3805 void _fillSmoothThickQuarterCircleInterHP2(int quarter, tgx::fVec2 C, float R, float thickness, color_t color_interior, color_t color_border, float opacity, const BSeg& seg1, int side1, const BSeg& seg2, int side2);
3806
3807
3808
3809 /***************************************
3810 * ELLIPSES
3811 ****************************************/
3812
3813
3814 // low quality drawing for ellipses
3815 template<bool OUTLINE, bool FILL, bool CHECKRANGE> void _drawEllipse(int x0, int y0, int rx, int ry, color_t outline_color, color_t interior_color, float opacity); // adapted from bodmer e_tft library
3816
3817 // high quality drawing for ellipses
3818 void _drawSmoothQuarterEllipse(tgx::fVec2 C, float rx, float ry, int quarter, bool vertical_center_line, bool horizontal_center_line, color_t color, float opacity);
3819 void _drawSmoothThickQuarterEllipse(tgx::fVec2 C, float rx, float ry, float thickness, int quarter, bool vertical_center_line, bool horizontal_center_line, color_t color, float opacity);
3820 void _fillSmoothQuarterEllipse(tgx::fVec2 C, float rx, float ry, int quarter, bool vertical_center_line, bool horizontal_center_line, color_t color, float opacity);
3821 void _fillSmoothThickQuarterEllipse(tgx::fVec2 C, float rx, float ry, float thickness, int quarter, bool vertical_center_line, bool horizontal_center_line, color_t color_interior, color_t color_border, float opacity);
3822
3823
3824
3825 /***************************************
3826 * DRAWING BEZIER
3827 ****************************************/
3828
3829
3830 // low quality Bezier curves
3831 void _plotQuadRationalBezierSeg(const bool checkrange, int x0, int y0, int x1, int y1, int x2, int y2, float w, const color_t color, const float opacity);
3832 void _plotQuadRationalBezier(const bool checkrange, int x0, int y0, int x1, int y1, int x2, int y2, float w, const bool draw_P2, const color_t color, const float opacity);
3833 void _drawQuadBezier(iVec2 P1, iVec2 P2, iVec2 PC, float wc, bool drawP2, color_t color, float opacity);
3834
3835 void _plotCubicBezierSeg(const bool checkrange, int x0, int y0, float x1, float y1, float x2, float y2, int x3, int y3, const color_t color, const float opacity);
3836 void _plotCubicBezier(const bool checkrange, int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3, bool draw_P2, const color_t color, const float opacity);
3837 void _drawCubicBezier(iVec2 P1, iVec2 P2, iVec2 PA, iVec2 PB, bool drawP2, color_t color, float opacity);
3838
3839 void _plotQuadSpline(int n, int x[], int y[], bool draw_last, const color_t color, const float opacity);
3840 template<int SPLINE_MAX_POINTS> void _drawQuadSpline(int nbpoints, const iVec2* tabPoints, bool draw_last_point, color_t color, float opacity);
3841
3842 void _plotClosedSpline(int n, int x[], int y[], const color_t color, const float opacity);
3843 template<int SPLINE_MAX_POINTS> void _drawClosedSpline(int nbpoints, const iVec2* tabPoints, color_t color, float opacity);
3844
3845 void _plotCubicSpline(int n, int x[], int y[], bool draw_last, const color_t color, const float opacity);
3846 template<int SPLINE_MAX_POINTS> void _drawCubicSpline(int nbpoints, const iVec2* tabPoints, bool draw_last_point, color_t color, float opacity);
3847
3848
3849
3850 // high quality Bezier curves
3851 static bool _splitRationalQuadBezier(fVec2 P1, fVec2 P2, fVec2 PC, float w, fVec2& Q, fVec2& PB, float& wb);
3852 static bool _splitCubicBezier(fVec2 P1, fVec2 P2, fVec2 PPC1, fVec2 PPC2, fVec2& Q, fVec2& C, fVec2 & D);
3853
3854
3855
3856 /***************************************
3857 * DRAWING TEXT
3858 ****************************************/
3859
3860 bool _clipit(int& x, int& y, int& sx, int& sy, int& b_left, int& b_up);
3861
3862 template<bool BLEND> iVec2 _drawCharGFX(char c, iVec2 pos, color_t col, const GFXfont& font, float opacity);
3863 template<bool BLEND> iVec2 _drawCharILI(char c, iVec2 pos, color_t col, const ILI9341_t3_font_t& font, float opacity);
3864
3865 template<bool BLEND> iVec2 _drawTextGFX(const char* text, iVec2 pos, const GFXfont& font, color_t col, float opacity, bool wrap, bool start_newline_at_0);
3866 template<bool BLEND> iVec2 _drawTextILI(const char* text, iVec2 pos, const ILI9341_t3_font_t& font, color_t col, float opacity, bool wrap, bool start_newline_at_0);
3867
3868 template<bool BLEND> void _drawCharILI9341_t3(const uint8_t* bitmap, int32_t off, int rsx, int b_up, int b_left, int sx, int sy, int x, int y, color_t col, float opacity);
3869 template<bool BLEND> static void _drawcharline(const uint8_t* bitmap, int32_t off, color_t* p, int dx, color_t col, float opacity);
3870 template<bool BLEND> void _drawCharBitmap_1BPP(const uint8_t* bitmap, int rsx, int b_up, int b_left, int sx, int sy, int x, int y, color_t col, float opacity);
3871 template<bool BLEND> void _drawCharBitmap_2BPP(const uint8_t* bitmap, int rsx, int b_up, int b_left, int sx, int sy, int x, int y, color_t col, float opacity);
3872 template<bool BLEND> void _drawCharBitmap_4BPP(const uint8_t* bitmap, int rsx, int b_up, int b_left, int sx, int sy, int x, int y, color_t col, float opacity);
3873 template<bool BLEND> void _drawCharBitmap_8BPP(const uint8_t* bitmap, int rsx, int b_up, int b_left, int sx, int sy, int x, int y, color_t col, float opacity);
3874
3875
3876
3877
3878 /************************************************************************************************************
3879 *
3880 * Image members variables (16 bytes).
3881 *
3882 *************************************************************************************************************/
3883
3884 color_t* _buffer; // pointer to the pixel buffer - nullptr if the image is invalid.
3885 int _lx, _ly; // image size - (0,0) if the image is invalid
3886 int _stride; // image stride - 0 if the image is invalid
3887
3888
3889 };
3890
3891
3892
3893}
3894
3895
3896
3897
3898#include "Image.inl"
3899
3900
3901#endif
3902
3903#endif
3904
3906
3907
Box2.h
2D box class
tgx::iBox2
Box2< int > iBox2
Integer-valued 2D box.
Definition Box2.h:45
tgx::fBox2
Box2< float > fBox2
Floating point valued 2D box with single (float) precision.
Definition Box2.h:47
tgx::Anchor
Anchor
Define the placement of an anchor point inside a box.
Definition Box2.h:74
tgx::DEFAULT_TEXT_ANCHOR
@ DEFAULT_TEXT_ANCHOR
Default location for text anchoring.
Definition Box2.h:89
Color.h
Color classes [RGB565, RGB24, RGB32, RGB64, RGBf, HSV].
Fonts.h
Define the GFXFont anf ILI9341_t3 font format if needed.
tgx::EndPath
EndPath
Enumeration of end path shapes.
Definition Image.h:51
tgx::END_ARROW_SKEWED_1
@ END_ARROW_SKEWED_1
tiny skewed arrow head [extends = line thickness]
Definition Image.h:59
tgx::END_ARROW_SKEWED_4
@ END_ARROW_SKEWED_4
large skewed arrow head [extends = 4 x line thickness]
Definition Image.h:62
tgx::END_ARROW_3
@ END_ARROW_3
medium arrow head [extends = 3 x line thickness]
Definition Image.h:56
tgx::END_ROUNDED
@ END_ROUNDED
rounded end.
Definition Image.h:53
tgx::END_ARROW_5
@ END_ARROW_5
huge arrow head [extends = 5 x line thickness]
Definition Image.h:58
tgx::END_ARROW_SKEWED_3
@ END_ARROW_SKEWED_3
medium skewed arrow head [extends = 3 x line thickness]
Definition Image.h:61
tgx::END_STRAIGHT
@ END_STRAIGHT
straight end.
Definition Image.h:52
tgx::END_ARROW_SKEWED_2
@ END_ARROW_SKEWED_2
small skewed arrow head [extends = 2 x line thickness]
Definition Image.h:60
tgx::END_ARROW_1
@ END_ARROW_1
tiny arrow head [extends = line thickness]
Definition Image.h:54
tgx::END_ARROW_SKEWED_5
@ END_ARROW_SKEWED_5
huge skewed arrow head [extends = 5 x line thickness]
Definition Image.h:63
tgx::END_ARROW_4
@ END_ARROW_4
large arrow head [extends = 4 x line thickness]
Definition Image.h:57
tgx::END_ARROW_2
@ END_ARROW_2
small arrow head [extends = 2 x line thickness]
Definition Image.h:55
Misc.h
Utility/miscellaneous functions used throughout the library.
tgx::min
TGX_INLINE T min(const T &a, const T &b)
Don't know why but faster than fminf() for floats.
Definition Misc.h:180
tgx::max
TGX_INLINE T max(const T &a, const T &b)
Don't know why but much faster than fmaxf() for floats.
Definition Misc.h:184
TGX_DEFAULT_NO_BLENDING
#define TGX_DEFAULT_NO_BLENDING
Default blending operation for drawing primitive: overwrite instead of blending.
Definition Misc.h:67
Rasterizer.h
3D triangle rasterizer function.
ShaderParams.h
Triangle shader parameters.
Shaders.h
Triangle shader functions.
Vec2.h
2D vector.
tgx::fVec2
Vec2< float > fVec2
Floating point valued 2D vector with single (float) precision.
Definition Vec2.h:49
tgx::iVec2
Vec2< int > iVec2
Integer-valued 2D vector.
Definition Vec2.h:47
Vec3.h
3D vector.
Vec4.h
4D vector.
tgx::Image
Image class [MAIN CLASS FOR THE 2D API].
Definition Image.h:143
tgx::Image::drawLineAA
void drawLineAA(fVec2 P1, fVec2 P2, color_t color, float opacity=1.0f)
Draw a line segment between two points [High quality].
tgx::Image::iterate
void iterate(ITERFUN cb_fun, tgx::iBox2 B) const
Iterate over the pixel of the image inside a given region.
tgx::Image::drawText
iVec2 drawText(const char *text, iVec2 pos, const GFXfont &font, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a text at a given position with a given font.
tgx::Image::height
TGX_INLINE int height() const
Return the image height.
Definition Image.h:370
tgx::Image::drawPolygonAA
void drawPolygonAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity=1.0f)
Draw a closed polygon with vertices [P0,P2,,, PN] (High quality).
tgx::Image::drawTexturedTriangle
void drawTexturedTriangle(const Image< color_t_tex > &src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, const BLEND_OPERATOR &blend_op)
Blend a textured triangle onto the image.
tgx::Image::fillThickRectAA
void fillThickRectAA(const fBox2 &B, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled rectangle with a thick border of a different color [High quality].
tgx::Image::stride
TGX_INLINE int stride() const
Return the image stride.
Definition Image.h:386
tgx::Image::PNGDecode
int PNGDecode(PNG_T &png, iVec2 topleft=iVec2(0, 0), float opacity=1.0f)
Decode a PNG image into this image using the PNGDec library: https://github.com/bitbank2/PNGdec/.
tgx::Image::drawText
iVec2 drawText(const char *text, iVec2 pos, const ILI9341_t3_font_t &font, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a text at a given position with a given font.
tgx::Image::drawThickPolygonAA
void drawThickPolygonAA(FUNCTOR_NEXT next_point, float thickness, color_t color, float opacity=1.0f)
Draw a polygon with thick lines (High quality).
tgx::Image::operator()
TGX_INLINE const color_t & operator()(iVec2 pos) const
Get a reference to a pixel (no range check!)
Definition Image.h:535
tgx::Image::set
void set(T *buffer, int lx, int ly, int stride=DEFAULT_STRIDE)
Set/update the image parameters.
tgx::Image::drawRect
void drawRect(const iBox2 &B, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a rectangle.
tgx::Image::data
TGX_INLINE const color_t * data() const
Return a pointer to the pixel buffer.
Definition Image.h:412
tgx::Image::drawThickClosedSplineAA
void drawThickClosedSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a thick closed quadratic spline interpolating between a given set of points (high quality).
tgx::Image::iterate
void iterate(ITERFUN cb_fun)
Iterate over all the pixels of the image.
tgx::Image::drawCircle
void drawCircle(iVec2 center, int r, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a circle.
tgx::Image::fill
int fill(iVec2 start_pos, color_t new_color)
'Flood fill' a 4-connected region of the image.
tgx::Image::fillThickEllipseAA
void fillThickEllipseAA(fVec2 center, fVec2 radiuses, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled ellipse with a thick border of a different color (high quality).
tgx::Image::Image
Image(const Image< color_t > &im)=default
Default copy constructor.
tgx::Image::fillRectAA
void fillRectAA(const fBox2 &B, color_t color, float opacity=1.0f)
Draw a filled rectangle [High quality].
tgx::Image::readPixel
TGX_INLINE color_t readPixel(iVec2 pos, color_t outside_color=color_t()) const
Return the color of a pixel at a given position.
Definition Image.h:508
tgx::Image::fillCircleSectorAA
void fillCircleSectorAA(fVec2 center, float r, float angle_start, float angle_end, color_t color, float opacity=1.0f)
Draw a filled circle sector/slice/pie (high quality).
tgx::Image::drawThickRect
void drawThickRect(const iBox2 &B, int thickness, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a rectangle with a thick outline.
tgx::Image::drawFastVLine
void drawFastVLine(iVec2 pos, int h, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw an vertical segment of h pixels starting at pos.
tgx::Image::drawPolyline
void drawPolyline(FUNCTOR_NEXT next_point, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a polyline ie a sequence of consecutif segments [P0,P1] , [P1,P2],,, [Pn-1,Pn].
tgx::Image::drawThickRectAA
void drawThickRectAA(const fBox2 &B, float thickness, color_t color, float opacity=1.0f)
Draw a filled rectangle with a thick border [High quality].
tgx::Image::crop
void crop(const iBox2 &subbox)
Crop the image.
tgx::Image::Image
Image(T *buffer, iVec2 dim, int stride=DEFAULT_STRIDE)
Constructor.
tgx::Image::copyFrom
void copyFrom(const Image< src_color_t > &src_im, const BLEND_OPERATOR &blend_op)
Blend the src image onto the destination image with resizing and color conversion.
tgx::Image::drawFastHLine
void drawFastHLine(iVec2 pos, int w, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw an horizontal segment of w pixels starting at pos.
tgx::Image::Image
Image(T *buffer, int lx, int ly, int stride=DEFAULT_STRIDE)
Constructor.
tgx::Image::iterate
void iterate(ITERFUN cb_fun) const
Iterate over all the pixels of the image.
tgx::Image::fillThickPolygonAA
void fillThickPolygonAA(FUNCTOR_NEXT next_point, float thickness, color_t interior_color, color_t border_color, float opacity=1.0f)
Draw a filled polygon with a thick border of a different color (High quality).
tgx::Image::drawClosedSpline
void drawClosedSpline(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a closed quadratic spline interpolating between a given set of points.
tgx::Image::fillRoundRectAA
void fillRoundRectAA(const fBox2 &B, float corner_radius, color_t color, float opacity=1.0f)
Draw a filled rounded rectangle [High quality].
tgx::Image::drawThickCubicBezierAA
void drawThickCubicBezierAA(fVec2 P1, fVec2 P2, fVec2 PA, fVec2 PB, float thickness, EndPath end_P1, EndPath end_P2, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a thick cubic Bezier curve (high quality).
tgx::Image::drawEllipse
void drawEllipse(iVec2 center, iVec2 radiuses, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw an ellipse.
tgx::Image::setInvalid
void setInvalid()
Set the image as invalid.
tgx::Image::operator()
TGX_INLINE color_t & operator()(int x, int y)
Get a reference to a pixel (no range check!)
Definition Image.h:572
tgx::Image::drawTexturedGradientMaskedTriangle
void drawTexturedGradientMaskedTriangle(const Image< color_t_tex > &src_im, color_t_tex transparent_color, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, color_t_tex C1, color_t_tex C2, color_t_tex C3, float opacity=1.0f)
Blend textured triangle with a transparency mask (ie a specific color is treated as fully transparent...
tgx::Image::fillRectHGradient
void fillRectHGradient(iBox2 B, color_t color_left, color_t color_right, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a rectangle filled with an horizontal gradient of colors.
tgx::Image::setOpenFontRender
void setOpenFontRender(T &ofr, float opacity=TGX_DEFAULT_NO_BLENDING)
Link the image with Takkoa's OpenFontRender library : https://github.com/takkaO/OpenFontRender.
Definition Image.h:3428
tgx::Image::fillThickCircleSectorAA
void fillThickCircleSectorAA(fVec2 center, float r, float angle_start, float angle_end, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled circle sector/slice/pie with a thick border of a different color (high quality).
tgx::Image::drawTexturedGradientMaskedQuad
void drawTexturedGradientMaskedQuad(const Image< color_t_tex > &src_im, color_t_tex transparent_color, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, color_t_tex C1, color_t_tex C2, color_t_tex C3, color_t_tex C4, float opacity=1.0f)
Draw a textured quad using bilinear filtering and with a mask (ie a fixed transparent color) and comb...
tgx::Image::drawTexturedGradientTriangle
void drawTexturedGradientTriangle(const Image< color_t_tex > &src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, color_t_tex C1, color_t_tex C2, color_t_tex C3, float opacity=TGX_DEFAULT_NO_BLENDING)
Blend textured triangle on the image while combining it with a color gradient.
tgx::Image::drawThickCircleArcAA
void drawThickCircleArcAA(fVec2 center, float r, float angle_start, float angle_end, float thickness, color_t color, float opacity=1.0f)
Draw a circle arc with a thick border (high quality).
tgx::Image::drawTexturedGradientQuad
void drawTexturedGradientQuad(const Image< color_t_tex > &src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, color_t_tex C1, color_t_tex C2, color_t_tex C3, color_t_tex C4, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a textured quad using bilinear filtering combined with a color gradient.
tgx::Image::drawTexturedQuad
void drawTexturedQuad(const Image< color_t_tex > &src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, const BLEND_OPERATOR &blend_op)
Draw a textured quad with bilinear filtering and a custom blending operator.
tgx::Image::drawPixelf
TGX_INLINE void drawPixelf(fVec2 pos, color_t color, float opacity)
Blend a pixel with the current pixel color (floating point coord).
Definition Image.h:495
tgx::Image::operator()
TGX_INLINE color_t & operator()(iVec2 pos)
Get a reference to a pixel (no range check!)
Definition Image.h:546
tgx::Image::Image
Image()
Default constructor.
tgx::Image::drawLine
void drawLine(iVec2 P1, iVec2 P2, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a line segment between two points (uses Bresenham's algorithm).
tgx::Image::drawRoundRectAA
void drawRoundRectAA(const fBox2 &B, float corner_radius, color_t color, float opacity=1.0f)
Draw a rounded rectangle [High quality].
tgx::Image::width
TGX_INLINE int width() const
Return the image width.
Definition Image.h:354
tgx::Image::operator()
Image< color_t > operator()(const iBox2 &B) const
Return a sub-image of this image (sharing the same pixel buffer).
tgx::Image::getCrop
Image< color_t > getCrop(const iBox2 &subbox) const
Return a sub-image of this image (sharing the same pixel buffer).
tgx::Image::blitMasked
void blitMasked(const Image< color_t > &sprite, color_t transparent_color, iVec2 upperleftpos, float opacity=1.0f)
Blend a sprite at a given position on this image with a given mask.
tgx::Image::fillQuad
void fillQuad(iVec2 P1, iVec2 P2, iVec2 P3, iVec2 P4, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
draw a filled quad.
tgx::Image::drawTextEx
iVec2 drawTextEx(const char *text, iVec2 pos, const GFXfont &font, Anchor anchor, bool wrap_text, bool start_newline_at_0, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Advanced drawText method.
tgx::Image::fillRectVGradient
void fillRectVGradient(iBox2 B, color_t color_top, color_t color_bottom, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a rectangle filled with a vertical gradient of colors.
tgx::Image::drawPolylineAA
void drawPolylineAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity=1.0f)
Draw a polyline ie a sequence of consecutif segments [P0,P1] , [P1,P2],,, [Pn-1,Pn] (High quality).
tgx::Image::drawTexturedMaskedTriangle
void drawTexturedMaskedTriangle(const Image< color_t_tex > &src_im, color_t_tex transparent_color, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, float opacity=1.0f)
Blend textured triangle with a transparency mask (ie a specific color is treated as fully transparent...
tgx::Image::drawQuad
void drawQuad(iVec2 P1, iVec2 P2, iVec2 P3, iVec2 P4, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a quad.
tgx::Image::drawPixel
TGX_INLINE void drawPixel(iVec2 pos, color_t color, float opacity)
Blend a pixel with the current pixel color.
Definition Image.h:479
tgx::Image::blitRotated
void blitRotated(const Image< color_t_src > &sprite, iVec2 upperleftpos, int angle, const BLEND_OPERATOR &blend_op)
Blend a rotated sprite over this image at a given position using a custom blending operator.
tgx::Image::isValid
TGX_INLINE bool isValid() const
Query if the image is valid.
Definition Image.h:338
tgx::Image::blit
void blit(const Image< color_t > &sprite, iVec2 upperleftpos, float opacity=TGX_DEFAULT_NO_BLENDING)
Blit/blend a sprite over this image at a given position.
tgx::Image::fillRoundRect
void fillRoundRect(const iBox2 &B, int corner_radius, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled rounded rectangle in box B with radius corner_radius.
tgx::Image::fillPolygon
void fillPolygon(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled polygon with vertices [P0,P2,,, PN].
tgx::Image::drawPolygon
void drawPolygon(FUNCTOR_NEXT next_point, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a closed polygon with vertices [P0,P2,,, PN].
tgx::Image::fillScreenVGradient
void fillScreenVGradient(color_t top_color, color_t bottom_color)
Fill the whole image with a vertical color gradient between two colors.
tgx::Image::measureText
iBox2 measureText(const char *text, iVec2 pos, const ILI9341_t3_font_t &font, Anchor anchor=DEFAULT_TEXT_ANCHOR, bool wrap_text=false, bool start_newline_at_0=false) const
Compute the bounding box of a text.
tgx::Image::drawThickLineAA
void drawThickLineAA(fVec2 P1, fVec2 P2, float line_width, EndPath end_P1, EndPath end_P2, color_t color, float opacity=1.0f)
Draw a thick line segment between two points [High quality].
tgx::Image::operator()
TGX_INLINE const color_t & operator()(int x, int y) const
Get a reference to a pixel (no range check!)
Definition Image.h:559
tgx::Image::fillEllipse
void fillEllipse(iVec2 center, iVec2 radiuses, color_t interior_color, color_t outline_color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled ellipse with different colors for the outline and the interior.
tgx::Image::drawPixel
TGX_INLINE void drawPixel(iVec2 pos, color_t color)
Set a pixel at a given position.
Definition Image.h:453
tgx::Image::dim
TGX_INLINE iVec2 dim() const
Return the image dimensions as an iVec2.
Definition Image.h:394
tgx::Image::fontHeight
int fontHeight(const GFXfont &font) const
Query the height of a font.
tgx::Image::clear
void clear(color_t color)
Fill the whole image with a single color.
tgx::Image::fillThickRect
void fillThickRect(const iBox2 &B, int thickness, color_t color_interior, color_t color_border, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled rectangle with a thick border of a possibly different color.
tgx::Image::drawThickRoundRectAA
void drawThickRoundRectAA(const fBox2 &B, float corner_radius, float thickness, color_t color, float opacity=1.0f)
Draw a rounded rectangle with a thick border [High quality].
tgx::Image::drawThickQuadAA
void drawThickQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, float thickness, color_t color, float opacity=1.0f)
Draw a quad with a thick border [High quality].
tgx::Image::data
TGX_INLINE color_t * data()
Return a pointer to the pixel buffer.
Definition Image.h:422
tgx::Image::drawPolygonAA
void drawPolygonAA(FUNCTOR_NEXT next_point, color_t color, float opacity=1.0f)
Draw a closed polygon with vertices [P0,P2,,, PN] (High quality).
tgx::Image::drawGradientQuad
void drawGradientQuad(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, color_alt colorP1, color_alt colorP2, color_alt colorP3, color_alt colorP4, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a quad with a gradient color specified by the color at the four vertices.
tgx::Image::fillCircle
void fillCircle(iVec2 center, int r, color_t interior_color, color_t outline_color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled circle with different colors for outline and interior.
tgx::Image::imageBox
TGX_INLINE iBox2 imageBox() const
Return the image dimension as a box.
Definition Image.h:402
tgx::Image::drawPolylineAA
void drawPolylineAA(FUNCTOR_NEXT next_point, color_t color, float opacity=1.0f)
Draw a polyline ie a sequence of consecutif segments [P0,P1] , [P1,P2],,, [Pn-1,Pn] (High quality).
tgx::Image::blitScaledRotated
void blitScaledRotated(const Image< color_t_src > src_im, fVec2 anchor_src, fVec2 anchor_dst, float scale=1.0f, float angle_degrees=0.0f, float opacity=TGX_DEFAULT_NO_BLENDING)
Blit/blend a sprite onto this image after rescaling and rotation.
tgx::Image::fillRect
void fillRect(const iBox2 &B, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled rectangle.
tgx::Image::set
void set(T *buffer, iVec2 dim, int stride=DEFAULT_STRIDE)
Set/update the image parameters.
tgx::Image::drawRoundRect
void drawRoundRect(const iBox2 &B, int corner_radius, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a rounded rectangle in box B with radius corner_radius.
tgx::Image::drawThickCircleAA
void drawThickCircleAA(fVec2 center, float r, float thickness, color_t color, float opacity=1.0f)
Draw a circle with a thick border (high quality).
tgx::Image::drawPolyline
void drawPolyline(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a polyline ie a sequence of consecutif segments [P0,P1] , [P1,P2],,, [Pn-1,Pn].
tgx::Image::drawThickQuadSplineAA
void drawThickQuadSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a thick quadratic spline interpolating between a given set of points (high quality).
tgx::Image::fillScreenHGradient
void fillScreenHGradient(color_t left_color, color_t right_color)
Fill the whole screen with an horizontal color gradient between two colors.
tgx::Image::convert
Image< color_dst > convert()
Convert this image to another type.
tgx::Image::drawCircleArcAA
void drawCircleArcAA(fVec2 center, float r, float angle_start, float angle_end, color_t color, float opacity=1.0f)
Draw a circle arc (high quality).
tgx::Image::lx
TGX_INLINE int lx() const
Return the image width.
Definition Image.h:362
tgx::Image::drawTriangleAA
void drawTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, color_t color, float opacity=1.0f)
Draw a triangle [High quality].
tgx::Image::ly
TGX_INLINE int ly() const
Return the image height.
Definition Image.h:378
tgx::Image::fill
int fill(iVec2 start_pos, color_t border_color, color_t new_color)
'Flood fill' a 4-connected region of the image.
tgx::Image::measureChar
iBox2 measureChar(char c, iVec2 pos, const GFXfont &font, Anchor anchor=DEFAULT_TEXT_ANCHOR, int *xadvance=nullptr) const
Compute the bounding box of a character.
tgx::Image::copyFrom
void copyFrom(const Image< src_color_t > &src_im, float opacity=TGX_DEFAULT_NO_BLENDING)
Copy (or blend) the src image onto the destination image with resizing and color conversion.
tgx::Image::drawTextEx
iVec2 drawTextEx(const char *text, iVec2 pos, const ILI9341_t3_font_t &font, Anchor anchor, bool wrap_text, bool start_newline_at_0, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Advanced drawText method.
tgx::Image::drawThickPolylineAA
void drawThickPolylineAA(FUNCTOR_NEXT next_point, float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity=1.0f)
Draw a thick polyline ie a sequence of consecutif thick segments [P0,P1] , [P1,P2],...
tgx::Image::blit
void blit(const Image< color_t_src > &sprite, iVec2 upperleftpos, const BLEND_OPERATOR &blend_op)
Blend a sprite at a given position on the image using a custom blending operator.
tgx::Image::drawTexturedMaskedQuad
void drawTexturedMaskedQuad(const Image< color_t_tex > &src_im, color_t_tex transparent_color, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, float opacity=1.0f)
Draw a textured quad using bilinear filtering and with a mask (ie a fixed transparent color).
tgx::Image::drawThickPolygonAA
void drawThickPolygonAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t color, float opacity=1.0f)
Draw a polygon with thick lines (High quality).
tgx::Image::fillScreen
void fillScreen(color_t color)
Fill the whole image with a single color.
tgx::Image::copyReduceHalf
Image< color_t > copyReduceHalf(const Image< color_t > &src_image)
Copy the source image pixels into this image, reducing it by half in the process.
tgx::Image::blitBackward
void blitBackward(Image< color_t > &dst_sprite, iVec2 upperleftpos) const
Reverse blitting.
tgx::Image::drawWedgeLineAA
void drawWedgeLineAA(fVec2 P1, fVec2 P2, float line_width_P1, EndPath end_P1, float line_width_P2, EndPath end_P2, color_t color, float opacity=1.0f)
Draw a from P1 to P2 with with respective wideness line_width_P1 and line_width_P2 at both ends [High...
tgx::Image::fillThickQuadAA
void fillThickQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled quad with a thick border of a different color [High quality].
tgx::Image::drawTexturedQuad
void drawTexturedQuad(const Image< color_t_tex > &src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a textured quad using bilinear filtering.
tgx::Image::fillPolygon
void fillPolygon(FUNCTOR_NEXT next_point, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled polygon with vertices [P0,P2,,, PN].
tgx::Image::blitScaledRotatedMasked
void blitScaledRotatedMasked(const Image< color_t_src > &src_im, color_t_src transparent_color, fVec2 anchor_src, fVec2 anchor_dst, float scale, float angle_degrees, float opacity=1.0f)
Blend a sprite onto this image after rescaling and rotation and use a given color which is treated as...
tgx::Image::drawEllipseAA
void drawEllipseAA(fVec2 center, fVec2 radiuses, color_t color, float opacity=1.0f)
Draw an ellipse (high quality).
tgx::Image::Image
Image(const Image< color_t > &im, iBox2 subbox)
Constructor.
tgx::Image::fillThickClosedSplineAA
void fillThickClosedSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t color_interior, color_t color_border, float opacity=TGX_DEFAULT_NO_BLENDING)
Fill a region delimited by a closed thick quadratic spline where the interior and boundary can have d...
tgx::Image::fillQuadAA
void fillQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, color_t color, float opacity=1.0f)
Draw a filled quad [High quality].
tgx::Image::drawThickQuadBezierAA
void drawThickQuadBezierAA(fVec2 P1, fVec2 P2, fVec2 PC, float wc, float thickness, EndPath end_P1, EndPath end_P2, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a thick quadratic (rational) Bezier curve (high quality).
tgx::Image::measureText
iBox2 measureText(const char *text, iVec2 pos, const GFXfont &font, Anchor anchor=DEFAULT_TEXT_ANCHOR, bool wrap_text=false, bool start_newline_at_0=false) const
Compute the bounding box of a text.
tgx::Image::drawThickPolylineAA
void drawThickPolylineAA(int nbpoints, const fVec2 tabPoints[], float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity=1.0f)
Draw a thick polyline ie a sequence of consecutif thick segments [P0,P1] , [P1,P2],...
tgx::Image::blitScaledRotated
void blitScaledRotated(const Image< color_t_src > &src_im, fVec2 anchor_src, fVec2 anchor_dst, float scale, float angle_degrees, const BLEND_OPERATOR &blend_op)
Blend a sprite onto this image after rescaling and rotation using a custom blending operator.
tgx::Image::drawThickTriangleAA
void drawThickTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, float thickness, color_t color, float opacity=1.0f)
Draw a triangle with a thick border [High quality].
tgx::Image::readPixelf
TGX_INLINE color_t readPixelf(fVec2 pos, color_t outside_color=color_t()) const
Return the color of a pixel at a given position (floating point coord).
Definition Image.h:523
tgx::Image::fillPolygonAA
void fillPolygonAA(FUNCTOR_NEXT next_point, color_t color, float opacity=1.0f)
Draw a filled polygon (High quality).
tgx::Image::operator()
Image< color_t > operator()(int min_x, int max_x, int min_y, int max_y) const
Return a sub-image of this image (sharing the same pixel buffer).
tgx::Image::drawCubicBezier
void drawCubicBezier(iVec2 P1, iVec2 P2, iVec2 PA, iVec2 PB, bool drawP2, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a cubic Bezier curve.
tgx::Image::measureChar
iBox2 measureChar(char c, iVec2 pos, const ILI9341_t3_font_t &font, Anchor anchor=DEFAULT_TEXT_ANCHOR, int *xadvance=nullptr) const
Compute the bounding box of a character.
tgx::Image::drawThickCubicSplineAA
void drawThickCubicSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a thick cubic spline interpolating between a given set of points (high quality).
tgx::Image::fillTriangleAA
void fillTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, color_t color, float opacity=1.0f)
Draw a filled triangle [High quality].
tgx::Image::fillEllipseAA
void fillEllipseAA(fVec2 center, fVec2 radiuses, color_t color, float opacity=1.0f)
Draw a filled ellipse (high quality).
tgx::Image::drawTriangle
void drawTriangle(const iVec2 &P1, const iVec2 &P2, const iVec2 &P3, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a triangle.
tgx::Image::drawPolygon
void drawPolygon(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a closed polygon with vertices [P0,P2,,, PN].
tgx::Image::fillThickTriangleAA
void fillThickTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled triangle with a thick border of a different color [High quality].
tgx::Image::drawGradientTriangle
void drawGradientTriangle(fVec2 P1, fVec2 P2, fVec2 P3, color_alt colorP1, color_alt colorP2, color_alt colorP3, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a triangle with gradient color specified by the colors on its vertices.
tgx::Image::drawChar
iVec2 drawChar(char c, iVec2 pos, const GFXfont &font, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a single character at position pos on the image and return the position for the next character.
tgx::Image::drawCubicSpline
void drawCubicSpline(int nbpoints, const iVec2 tabPoints[], bool draw_last_point, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a cubic spline interpolating between a given set of points.
tgx::Image::fillThickCircleAA
void fillThickCircleAA(fVec2 center, float r, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled circle with a thick border of a different color (high quality).
tgx::Image::fillClosedSplineAA
void fillClosedSplineAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Fill a region delimited by a closed quadratic spline (high quality).
tgx::Image::fillTriangle
void fillTriangle(const iVec2 &P1, const iVec2 &P2, const iVec2 &P3, color_t interior_color, color_t outline_color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled triangle with different colors for the outline and the interior.
tgx::Image::drawQuadBezier
void drawQuadBezier(iVec2 P1, iVec2 P2, iVec2 PC, float wc, bool drawP2, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a quadratic (rational) Bezier curve.
tgx::Image::fillCircleAA
void fillCircleAA(fVec2 center, float r, color_t color, float opacity=1.0f)
Draw a filled circle (high quality).
tgx::Image::drawQuadAA
void drawQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, color_t color, float opacity=1.0f)
Draw a quad [High quality].
tgx::Image::fillThickRoundRectAA
void fillThickRoundRectAA(const fBox2 &B, float corner_radius, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled rounded rectangle with a thick border of another color [High quality].
tgx::Image::blitRotated
void blitRotated(const Image< color_t > &sprite, iVec2 upperleftpos, int angle, float opacity=TGX_DEFAULT_NO_BLENDING)
Blit/blend a rotated sprite over this image at a given position.
tgx::Image::drawCircleAA
void drawCircleAA(fVec2 center, float r, color_t color, float opacity=1.0f)
Draw a circle (high quality).
tgx::Image::JPEGDecode
int JPEGDecode(JPEG_T &jpeg, iVec2 topleft=iVec2(0, 0), int options=0, float opacity=1.0f)
Decode a JPEG image into this image using the JPEGDEC library: https://github.com/bitbank2/JPEGDEC/.
tgx::Image::drawSegment
void drawSegment(iVec2 P1, bool drawP1, iVec2 P2, bool drawP2, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a line segment between two points (using Bresenham's algorithm).
tgx::Image::fillPolygonAA
void fillPolygonAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity=1.0f)
Draw a filled polygon (High quality).
tgx::Image::reduceHalf
Image< color_t > reduceHalf()
Reduce this image by half.
tgx::Image::operator=
Image & operator=(const Image< color_t > &im)=default
Default assignement operator.
tgx::Image::drawPixelf
TGX_INLINE void drawPixelf(fVec2 pos, color_t color)
Set a pixel at a given position (floating point coord).
Definition Image.h:465
tgx::Image::drawQuadSpline
void drawQuadSpline(int nbpoints, const iVec2 tabPoints[], bool draw_last_point, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a quadratic spline interpolating between a given set of points.
tgx::Image::iterate
void iterate(ITERFUN cb_fun, tgx::iBox2 B)
Iterate over the pixel of the image inside a given region.
tgx::Image::fillThickPolygonAA
void fillThickPolygonAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t interior_color, color_t border_color, float opacity=1.0f)
Draw a filled polygon with a thick border of a different color (High quality).
tgx::Image::DEFAULT_STRIDE
static const int DEFAULT_STRIDE
If not specified, the stride of an image is equal to its width.
Definition Image.h:154
tgx::Image::drawTexturedTriangle
void drawTexturedTriangle(const Image< color_t_tex > &src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw textured triangle onto the image.
tgx::Image::GIFplayFrame
int GIFplayFrame(GIF_T &gif, iVec2 topleft=iVec2(0, 0), float opacity=1.0f)
Decode a (possibly animated) GIF image into this image using the AnimatedGIF library: https://github....
tgx::Image::drawThickEllipseAA
void drawThickEllipseAA(fVec2 center, fVec2 radiuses, float thickness, color_t color, float opacity=1.0f)
Draw an ellipse with a thick border (high quality).
tgx::Image::drawChar
iVec2 drawChar(char c, iVec2 pos, const ILI9341_t3_font_t &font, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a single character at position pos on the image and return the position for the next character.
tgx::Image::fontHeight
int fontHeight(const ILI9341_t3_font_t &font) const
Query the height of a font.
GFXfont
GFXFont font format.
Definition Fonts.h:74
ILI9341_t3_font_t
ILI9341_t3 PJRC font format.
Definition Fonts.h:105
tgx::RGB565
Color in R5/G6/B5 format.
Definition Color.h:216
tgx::Vec2::x
T x
'x' coordinate (first dimension)
Definition Vec2.h:72
tgx::Vec2::y
T y
'y' coordinate (second dimension)
Definition Vec2.h:73