TGX 1.0.8
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
42namespace tgx
43{
51 {
64 };
65
66
67
68
143 template<typename color_t>
144 class Image
145 {
146
147 // make sure right away that the template parameter is admissible to prevent cryptic error message later.
148 static_assert(is_color<color_t>::value, "color_t must be one of the color types defined in Color.h");
149
150 // befriend all sister Image classes
151 template<typename> friend class Image;
152
153
154 public:
155
156 static const int DEFAULT_STRIDE = -1;
157
158
159 #if (MTOOLS_TGX_EXTENSIONS)
160 #include <mtools/extensions/tgx/tgx_ext_Image.inl>
161 #endif
162
163
164
165
166 //*************************************************************************************************************
167 //*************************************************************************************************************
168 //*************************************************************************************************************
179
180 //*************************************************************************************************************
181 //*************************************************************************************************************
182 //*************************************************************************************************************
183
184
185
192
193
202 template<typename T> Image(T* buffer, int lx, int ly, int stride = DEFAULT_STRIDE);
203
204
212 template<typename T> Image(T* buffer, iVec2 dim, int stride = DEFAULT_STRIDE);
213
214
221 Image(const Image<color_t>& im, iBox2 subbox);
222
223
231 Image(const Image<color_t> & im) = default;
232
233
243 Image& operator=(const Image<color_t> & im) = default;
244
245
254 template<typename T> void set(T* buffer, int lx, int ly, int stride = DEFAULT_STRIDE);
255
256
264 template<typename T> void set(T* buffer, iVec2 dim, int stride = DEFAULT_STRIDE);
265
266
277 void crop(const iBox2& subbox);
278
279
289 Image<color_t> getCrop(const iBox2& subbox) const;
290
291
302
303
316 Image<color_t> operator()(int min_x, int max_x, int min_y, int max_y) const;
317
318
319
321 //*************************************************************************************************************
322 //*************************************************************************************************************
323 //*************************************************************************************************************
329
330 //*************************************************************************************************************
331 //*************************************************************************************************************
332 //*************************************************************************************************************
333
334
340 inline TGX_INLINE bool isValid() const { return (_buffer != nullptr); }
341
342
349
350
356 inline TGX_INLINE int width() const { return _lx; }
357
358
364 inline TGX_INLINE int lx() const { return _lx; }
365
366
372 inline TGX_INLINE int height() const { return _ly; }
373
374
380 inline TGX_INLINE int ly() const { return _ly; }
381
382
388 inline TGX_INLINE int stride() const { return _stride; }
389
390
396 inline TGX_INLINE iVec2 dim() const { return iVec2{ _lx, _ly }; }
397
398
404 inline TGX_INLINE iBox2 imageBox() const { return iBox2(0, _lx - 1, 0, _ly - 1); }
405
406
414 inline TGX_INLINE const color_t * data() const { return _buffer; }
415
416
424 inline TGX_INLINE color_t * data() { return _buffer; }
425
426
427
428
429
430
432 //*************************************************************************************************************
433 //*************************************************************************************************************
434 //*************************************************************************************************************
440
441 //*************************************************************************************************************
442 //*************************************************************************************************************
443 //*************************************************************************************************************
444
445
446
447
455 template<bool CHECKRANGE = true> TGX_INLINE inline void drawPixel(iVec2 pos, color_t color) { if ((CHECKRANGE) && (!isValid())) return; _drawPixel<CHECKRANGE>(pos, color); }
456
457
467 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); }
468
469
481 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); }
482
483
497 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); }
498
499
510 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); }
511
512
525 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); }
526
527
537 TGX_INLINE inline const color_t& operator()(iVec2 pos) const { return _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)]; }
538
548 TGX_INLINE inline color_t& operator()(iVec2 pos) { return _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)]; }
549
550
561 TGX_INLINE inline const color_t& operator()(int x, int y) const { return _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)]; }
562
563
574 TGX_INLINE inline color_t& operator()(int x, int y) { return _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)];}
575
576
602 template<typename ITERFUN> void iterate(ITERFUN cb_fun);
603
604
619 template<typename ITERFUN> void iterate(ITERFUN cb_fun) const;
620
621
634 template<typename ITERFUN> void iterate(ITERFUN cb_fun, tgx::iBox2 B);
635
636
649 template<typename ITERFUN> void iterate(ITERFUN cb_fun, tgx::iBox2 B) const;
650
651
652
653
654
655
656
658 //*************************************************************************************************************
659 //*************************************************************************************************************
660 //*************************************************************************************************************
666
667 //*************************************************************************************************************
668 //*************************************************************************************************************
669 //*************************************************************************************************************
670
671
685 void blit(const Image<color_t>& sprite, iVec2 upperleftpos, float opacity = TGX_DEFAULT_NO_BLENDING);
686
687
709 template<typename color_t_src, typename BLEND_OPERATOR>
710 void blit(const Image<color_t_src>& sprite, iVec2 upperleftpos, const BLEND_OPERATOR& blend_op);
711
712
726 void blitRotated(const Image<color_t> & sprite, iVec2 upperleftpos, int angle, float opacity = TGX_DEFAULT_NO_BLENDING);
727
728
754 template<typename color_t_src, typename BLEND_OPERATOR>
755 void blitRotated(const Image<color_t_src>& sprite, iVec2 upperleftpos, int angle, const BLEND_OPERATOR& blend_op);
756
757
774 void blitMasked(const Image<color_t>& sprite, color_t transparent_color, iVec2 upperleftpos, float opacity = 1.0f);
775
776
787 void blitBackward(Image<color_t>& dst_sprite, iVec2 upperleftpos) const;
788
789
818 template<typename color_t_src, int CACHE_SIZE = TGX_PROGMEM_DEFAULT_CACHE_SIZE>
819 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);
820
821
846 template<typename color_t_src, typename BLEND_OPERATOR, int CACHE_SIZE = TGX_PROGMEM_DEFAULT_CACHE_SIZE>
847 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);
848
849
881 template<typename color_t_src, int CACHE_SIZE = TGX_PROGMEM_DEFAULT_CACHE_SIZE>
882 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);
883
884
899 template<typename src_color_t> void copyFrom(const Image<src_color_t>& src_im, float opacity = TGX_DEFAULT_NO_BLENDING);
900
901
927 template<typename src_color_t, typename BLEND_OPERATOR> void copyFrom(const Image<src_color_t>& src_im, const BLEND_OPERATOR& blend_op);
928
929
946
947
957
958
976 template<typename color_dst>
978
979
980
982 //*************************************************************************************************************
983 //*************************************************************************************************************
984 //*************************************************************************************************************
990
991 //*************************************************************************************************************
992 //*************************************************************************************************************
993 //*************************************************************************************************************
994
995
996
1004 void fillScreen(color_t color);
1005
1013 void clear(color_t color);
1014
1015
1024 void fillScreenVGradient(color_t top_color, color_t bottom_color);
1025
1026
1035 void fillScreenHGradient(color_t left_color, color_t right_color);
1036
1037
1055 template<int STACK_SIZE = 1024> int fill(iVec2 start_pos, color_t new_color);
1056
1057
1080 template<int STACK_SIZE = 1024> int fill(iVec2 start_pos, color_t border_color, color_t new_color);
1081
1082
1083
1085 //*************************************************************************************************************
1086 //*************************************************************************************************************
1087 //*************************************************************************************************************
1093
1094 //*************************************************************************************************************
1095 //*************************************************************************************************************
1096 //*************************************************************************************************************
1097
1098
1099
1109 void drawFastVLine(iVec2 pos, int h, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1110
1111
1121 void drawFastHLine(iVec2 pos, int w, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1122
1123
1133 void drawLine(iVec2 P1, iVec2 P2, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1134
1135
1148 void drawSegment(iVec2 P1, bool drawP1, iVec2 P2, bool drawP2, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1149
1150
1152 //*************************************************************************************************************
1158
1159 //*************************************************************************************************************
1160
1161
1162
1173 void drawLineAA(fVec2 P1, fVec2 P2, color_t color, float opacity = 1.0f);
1174
1175
1191 void drawThickLineAA(fVec2 P1, fVec2 P2, float line_width, EndPath end_P1, EndPath end_P2, color_t color, float opacity = 1.0f);
1192
1193
1208 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);
1209
1210
1211
1212#ifndef DOXYGEN_EXCLUDE
1213
1214
1215
1217
1223
1224
1230 DEPRECATED("Use method drawThickLineAA() instead.")
1231 void drawWideLine(fVec2 PA, fVec2 PB, float w, color_t color, float opacity) { drawThickLineAA(PA, PB, w, END_ROUNDED, END_ROUNDED, color, opacity); }
1232
1233
1239 DEPRECATED("Use method drawWedgeLineAA() instead.")
1240 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); }
1241
1242
1248 DEPRECATED("Use method fillCircleAA() instead")
1249 void drawSpot(fVec2 center, float r, color_t color, float opacity) { fillCircleAA(center, r, color, opacity); }
1250
1251
1252#endif
1253
1254
1255
1256
1258 //*************************************************************************************************************
1259 //*************************************************************************************************************
1260 //*************************************************************************************************************
1266
1267 //*************************************************************************************************************
1268 //*************************************************************************************************************
1269 //*************************************************************************************************************
1270
1271
1272
1281 void drawRect(const iBox2 & B, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1282
1283
1293 void drawThickRect(const iBox2& B, int thickness, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1294
1295
1304 void fillRect(const iBox2 & B, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1305
1306
1317 void fillThickRect(const iBox2& B, int thickness, color_t color_interior, color_t color_border, float opacity = TGX_DEFAULT_NO_BLENDING);
1318
1319
1329 void fillRectHGradient(iBox2 B, color_t color_left, color_t color_right, float opacity = TGX_DEFAULT_NO_BLENDING);
1330
1331
1341 void fillRectVGradient(iBox2 B, color_t color_top, color_t color_bottom, float opacity = TGX_DEFAULT_NO_BLENDING);
1342
1343
1344
1346 //*************************************************************************************************************
1364
1365 //*************************************************************************************************************
1366
1367
1368
1369
1383 void drawThickRectAA(const fBox2& B, float thickness, color_t color, float opacity = 1.0f);
1384
1385
1398 void fillRectAA(const fBox2& B, color_t color, float opacity = 1.0f);
1399
1400
1415 void fillThickRectAA(const fBox2& B, float thickness, color_t color_interior, color_t color_border, float opacity = 1.0f);
1416
1417
1418
1419
1420
1421
1422
1424 //*************************************************************************************************************
1425 //*************************************************************************************************************
1426 //*************************************************************************************************************
1432
1433 //*************************************************************************************************************
1434 //*************************************************************************************************************
1435 //*************************************************************************************************************
1436
1437
1438
1448 void drawRoundRect(const iBox2& B, int corner_radius, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1449
1450
1460 void fillRoundRect(const iBox2& B, int corner_radius, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1461
1462
1464 //*************************************************************************************************************
1470
1471 //*************************************************************************************************************
1472
1473
1484 void drawRoundRectAA(const fBox2& B, float corner_radius, color_t color, float opacity = 1.0f);
1485
1486
1498 void drawThickRoundRectAA(const fBox2& B, float corner_radius, float thickness, color_t color, float opacity = 1.0f);
1499
1500
1511 void fillRoundRectAA(const fBox2& B, float corner_radius, color_t color, float opacity = 1.0f);
1512
1513
1526 void fillThickRoundRectAA(const fBox2& B, float corner_radius, float thickness, color_t color_interior, color_t color_border, float opacity = 1.0f);
1527
1528
1529
1530
1531
1532
1533
1535 //*************************************************************************************************************
1536 //*************************************************************************************************************
1537 //*************************************************************************************************************
1543
1544 //*************************************************************************************************************
1545 //*************************************************************************************************************
1546 //*************************************************************************************************************
1547
1548
1559 void drawTriangle(const iVec2& P1, const iVec2& P2, const iVec2& P3, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1560
1561
1562
1574 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);
1575
1576
1577
1578
1580 //*************************************************************************************************************
1586
1587 //*************************************************************************************************************
1588
1589
1590
1600 void drawTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, color_t color, float opacity = 1.0f);
1601
1602
1615 void drawThickTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, float thickness, color_t color, float opacity = 1.0f);
1616
1617
1629 void fillTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, color_t color, float opacity = 1.0f);
1630
1631
1645 void fillThickTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, float thickness, color_t color_interior, color_t color_border, float opacity = 1.0f);
1646
1647
1648
1649
1651 //*************************************************************************************************************
1661
1662 //*************************************************************************************************************
1663
1664
1665
1678 template<typename color_alt>
1679 void drawGradientTriangle(fVec2 P1, fVec2 P2, fVec2 P3, color_alt colorP1, color_alt colorP2, color_alt colorP3, float opacity = TGX_DEFAULT_NO_BLENDING);
1680
1681
1705 template<typename color_t_tex>
1706 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);
1707
1708
1741 template<typename color_t_tex, typename BLEND_OPERATOR>
1742 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);
1743
1744
1771 template<typename color_t_tex>
1772 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);
1773
1774
1800 template<typename color_t_tex>
1801 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);
1802
1803
1835 template<typename color_t_tex>
1836 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);
1837
1838
1839
1840
1841
1842
1843
1845 //*************************************************************************************************************
1846 //*************************************************************************************************************
1847 //*************************************************************************************************************
1853
1854 //*************************************************************************************************************
1855 //*************************************************************************************************************
1856 //*************************************************************************************************************
1857
1858
1870 void drawQuad(iVec2 P1, iVec2 P2, iVec2 P3, iVec2 P4, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1871
1872
1886 void fillQuad(iVec2 P1, iVec2 P2, iVec2 P3, iVec2 P4, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
1887
1888
1889
1890
1892 //*************************************************************************************************************
1898
1899 //*************************************************************************************************************
1900
1901
1914 void drawQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, color_t color, float opacity = 1.0f);
1915
1916
1930 void drawThickQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, float thickness, color_t color, float opacity = 1.0f);
1931
1932
1947 void fillQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, color_t color, float opacity = 1.0f);
1948
1949
1966 void fillThickQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, float thickness, color_t color_interior, color_t color_border, float opacity = 1.0f);
1967
1968
1969
1971 //*************************************************************************************************************
1981
1982 //*************************************************************************************************************
1983
1984
1985
1991 template<typename color_alt>
1992 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);
1993
1994
2000 template<typename color_t_tex>
2001 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);
2002
2003
2009 template<typename color_t_tex, typename BLEND_OPERATOR>
2010 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);
2011
2012
2018 template<typename color_t_tex>
2019 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);
2020
2021
2027 template<typename color_t_tex>
2028 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);
2029
2030
2036 template<typename color_t_tex>
2037 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);
2038
2039
2040
2041
2042
2043
2044
2045
2046
2048 //*************************************************************************************************************
2049 //*************************************************************************************************************
2050 //*************************************************************************************************************
2056
2057 //*************************************************************************************************************
2058 //*************************************************************************************************************
2059 //*************************************************************************************************************
2060
2061
2062
2072 void drawPolyline(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2073
2074
2092 template<typename FUNCTOR_NEXT>
2093 void drawPolyline(FUNCTOR_NEXT next_point, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2094
2095
2096
2097
2098
2100 //*************************************************************************************************************
2106
2107 //*************************************************************************************************************
2108
2109
2110
2111
2122 void drawPolylineAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity = 1.0f);
2123
2124
2143 template<typename FUNCTOR_NEXT>
2144 void drawPolylineAA(FUNCTOR_NEXT next_point, color_t color, float opacity = 1.0f);
2145
2146
2160 void drawThickPolylineAA(int nbpoints, const fVec2 tabPoints[], float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity = 1.0f);
2161
2162
2163
2185 template<typename FUNCTOR_NEXT>
2186 void drawThickPolylineAA(FUNCTOR_NEXT next_point, float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity = 1.0f);
2187
2188
2189
2190
2191
2192
2194 //*************************************************************************************************************
2195 //*************************************************************************************************************
2196 //*************************************************************************************************************
2202
2203 //*************************************************************************************************************
2204 //*************************************************************************************************************
2205 //*************************************************************************************************************
2206
2207
2208
2218 void drawPolygon(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2219
2220
2238 template<typename FUNCTOR_NEXT>
2239 void drawPolygon(FUNCTOR_NEXT next_point, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2240
2241
2253 void fillPolygon(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2254
2255
2278 template<typename FUNCTOR_NEXT>
2279 void fillPolygon(FUNCTOR_NEXT next_point, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2280
2281
2282
2283
2284
2286 //*************************************************************************************************************
2292
2293 //*************************************************************************************************************
2294
2295
2296
2308 void drawPolygonAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity = 1.0f);
2309
2310
2330 template<typename FUNCTOR_NEXT>
2331 void drawPolygonAA(FUNCTOR_NEXT next_point, color_t color, float opacity = 1.0f);
2332
2333
2345 void drawThickPolygonAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t color, float opacity = 1.0f);
2346
2347
2371 template<typename FUNCTOR_NEXT>
2372 void drawThickPolygonAA(FUNCTOR_NEXT next_point, float thickness, color_t color, float opacity = 1.0f);
2373
2374
2387 void fillPolygonAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity = 1.0f);
2388
2389
2413 template<typename FUNCTOR_NEXT>
2414 void fillPolygonAA(FUNCTOR_NEXT next_point, color_t color, float opacity = 1.0f);
2415
2416
2429 void fillThickPolygonAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t interior_color, color_t border_color, float opacity = 1.0f);
2430
2431
2457 template<typename FUNCTOR_NEXT>
2458 void fillThickPolygonAA(FUNCTOR_NEXT next_point, float thickness, color_t interior_color, color_t border_color, float opacity = 1.0f);
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2470 //*************************************************************************************************************
2471 //*************************************************************************************************************
2472 //*************************************************************************************************************
2478
2479 //*************************************************************************************************************
2480 //*************************************************************************************************************
2481 //*************************************************************************************************************
2482
2483
2484
2485
2495 void drawCircle(iVec2 center, int r, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2496
2497
2508 void fillCircle(iVec2 center, int r, color_t interior_color, color_t outline_color, float opacity = TGX_DEFAULT_NO_BLENDING);
2509
2510
2511
2513 //*************************************************************************************************************
2519
2520 //*************************************************************************************************************
2521
2522
2523
2534 void drawCircleAA(fVec2 center, float r, color_t color, float opacity = 1.0f);
2535
2536
2548 void drawThickCircleAA(fVec2 center, float r, float thickness, color_t color, float opacity = 1.0f);
2549
2550
2561 void fillCircleAA(fVec2 center, float r, color_t color, float opacity = 1.0f);
2562
2563
2576 void fillThickCircleAA(fVec2 center, float r, float thickness, color_t color_interior, color_t color_border, float opacity = 1.0f);
2577
2578
2579
2580
2581
2583 //*************************************************************************************************************
2584 //*************************************************************************************************************
2585 //*************************************************************************************************************
2591
2592 //*************************************************************************************************************
2593 //*************************************************************************************************************
2594 //*************************************************************************************************************
2595
2596
2617 void drawCircleArcAA(fVec2 center, float r, float angle_start, float angle_end, color_t color, float opacity = 1.0f);
2618
2619
2641 void drawThickCircleArcAA(fVec2 center, float r, float angle_start, float angle_end, float thickness, color_t color, float opacity = 1.0f);
2642
2643
2664 void fillCircleSectorAA(fVec2 center, float r, float angle_start, float angle_end, color_t color, float opacity = 1.0f);
2665
2666
2689 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);
2690
2691
2692
2693
2694
2695
2697 //*************************************************************************************************************
2698 //*************************************************************************************************************
2699 //*************************************************************************************************************
2705
2706 //*************************************************************************************************************
2707 //*************************************************************************************************************
2708 //*************************************************************************************************************
2709
2710
2711
2721 void drawEllipse(iVec2 center, iVec2 radiuses, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2722
2723
2734 void fillEllipse(iVec2 center, iVec2 radiuses, color_t interior_color, color_t outline_color, float opacity = TGX_DEFAULT_NO_BLENDING);
2735
2736
2737
2738
2740 //*************************************************************************************************************
2746
2747 //*************************************************************************************************************
2748
2749
2750
2761 void drawEllipseAA(fVec2 center, fVec2 radiuses, color_t color, float opacity = 1.0f);
2762
2763
2775 void drawThickEllipseAA(fVec2 center, fVec2 radiuses, float thickness, color_t color, float opacity = 1.0f);
2776
2777
2788 void fillEllipseAA(fVec2 center, fVec2 radiuses, color_t color, float opacity = 1.0f);
2789
2790
2803 void fillThickEllipseAA(fVec2 center, fVec2 radiuses, float thickness, color_t color_interior, color_t color_border, float opacity = 1.0f);
2804
2805
2806
2807
2808
2810 //*************************************************************************************************************
2811 //*************************************************************************************************************
2812 //*************************************************************************************************************
2818
2819 //*************************************************************************************************************
2820 //*************************************************************************************************************
2821 //*************************************************************************************************************
2822
2823
2824
2825
2838 void drawQuadBezier(iVec2 P1, iVec2 P2, iVec2 PC, float wc, bool drawP2, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2839
2840
2853 void drawCubicBezier(iVec2 P1, iVec2 P2, iVec2 PA, iVec2 PB, bool drawP2, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2854
2855
2873 template<int SPLINE_MAX_POINTS = 32>
2874 void drawQuadSpline(int nbpoints, const iVec2 tabPoints[], bool draw_last_point, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2875
2876
2894 template<int SPLINE_MAX_POINTS = 32>
2895 void drawCubicSpline(int nbpoints, const iVec2 tabPoints[], bool draw_last_point, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2896
2897
2914 template<int SPLINE_MAX_POINTS = 32>
2915 void drawClosedSpline(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2916
2917
2918
2919
2920
2922 //*************************************************************************************************************
2928
2929 //*************************************************************************************************************
2930
2931
2948 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);
2949
2950
2967 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);
2968
2969
2991 template<int SPLINE_MAX_POINTS = 32>
2992 void drawThickQuadSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
2993
2994
3016 template<int SPLINE_MAX_POINTS = 32>
3017 void drawThickCubicSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3018
3019
3039 template<int SPLINE_MAX_POINTS = 32>
3040 void drawThickClosedSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3041
3042
3064 template<int SPLINE_MAX_POINTS = 32>
3065 void fillClosedSplineAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3066
3067
3095 template<int SPLINE_MAX_POINTS = 32>
3096 void fillThickClosedSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t color_interior, color_t color_border, float opacity = TGX_DEFAULT_NO_BLENDING);
3097
3098
3099
3100
3101
3102
3104 //*************************************************************************************************************
3105 //*************************************************************************************************************
3106 //*************************************************************************************************************
3119
3120 //*************************************************************************************************************
3121 //*************************************************************************************************************
3122 //*************************************************************************************************************
3123
3124
3125
3137 int fontHeight(const GFXfont & font) const;
3138
3139
3151 int fontHeight(const ILI9341_t3_font_t& font) const;
3152
3153
3171 iBox2 measureChar(char c, iVec2 pos, const GFXfont& font, Anchor anchor = DEFAULT_TEXT_ANCHOR, int* xadvance = nullptr) const;
3172
3173
3191 iBox2 measureChar(char c, iVec2 pos, const ILI9341_t3_font_t& font, Anchor anchor = DEFAULT_TEXT_ANCHOR, int* xadvance = nullptr) const;
3192
3193
3210 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;
3211
3212
3229 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;
3230
3231
3248 iVec2 drawChar(char c, iVec2 pos, const GFXfont& font, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3249
3250
3267 iVec2 drawChar(char c, iVec2 pos, const ILI9341_t3_font_t& font, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3268
3269
3287 iVec2 drawText(const char* text, iVec2 pos, const GFXfont& font, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3288
3289
3307 iVec2 drawText(const char* text, iVec2 pos, const ILI9341_t3_font_t& font, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3308
3309
3310
3334 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);
3335
3336
3360 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);
3361
3362
3363
3364
3365
3366#ifndef DOXYGEN_EXCLUDE
3367
3368
3369
3371 //*************************************************************************************************************
3377 //*************************************************************************************************************
3379
3380
3384 DEPRECATED("Use new signature: drawText(text, pos, font, color, opacity) or the new method drawTextEx()")
3385 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, font, DEFAULT_TEXT_ANCHOR, false, start_newline_at_0, color, opacity); }
3386
3387
3391 DEPRECATED("Use new signature: drawText(text, pos, font, color, opacity) or the new method drawTextEx()")
3392 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, font, DEFAULT_TEXT_ANCHOR, false, start_newline_at_0, color, opacity); }
3393
3394
3398 DEPRECATED("Use new signature measureText(text,pos,font,anchor, wrap, newline_at_0)")
3399 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); }
3400
3401
3405 DEPRECATED("Use new signature measureText(text,pos,font,anchor, wrap, newline_at_0)")
3406 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); }
3407
3408
3409#endif
3410
3411
3412
3413
3414
3416 //*************************************************************************************************************
3417 //*************************************************************************************************************
3418 //*************************************************************************************************************
3424
3425 //*************************************************************************************************************
3426 //*************************************************************************************************************
3427 //*************************************************************************************************************
3428
3429
3430
3438 template<typename T> void setOpenFontRender(T& ofr, float opacity = TGX_DEFAULT_NO_BLENDING)
3439 {
3440 // for some strange reason, cannot put this method inside the .inl file when compiling with arduino IDE...
3441 // must have something to do with Arduino's mangling of .ino file...
3442 if ((opacity >= 0) && (opacity < 1))
3443 {
3444 ofr.set_drawPixel([&](int32_t x, int32_t y, uint16_t c) { drawPixel({ x,y }, color_t(RGB565(c)), opacity); return; });
3445 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; });
3446 }
3447 else
3448 {
3449 ofr.set_drawPixel([&](int32_t x, int32_t y, uint16_t c) { drawPixel({ x,y }, color_t(RGB565(c))); return; });
3450 ofr.set_drawFastHLine([&](int32_t x, int32_t y, int32_t w, uint16_t c) { drawFastHLine({ x,y }, w, color_t(RGB565(c))); return; });
3451 }
3452 ofr.set_startWrite([&](void) { return; });
3453 ofr.set_endWrite([&](void) { return; });
3454 }
3455
3456
3478 template<typename PNG_T> int PNGDecode(PNG_T& png, iVec2 topleft = iVec2(0, 0), float opacity = 1.0f);
3479
3480
3508 template<typename JPEG_T> int JPEGDecode(JPEG_T& jpeg, iVec2 topleft = iVec2(0, 0), int options = 0, float opacity = 1.0f);
3509
3510
3538 template<typename GIF_T> int GIFplayFrame(GIF_T& gif, iVec2 topleft = iVec2(0, 0), float opacity = 1.0f);
3539
3540
3541
3542
3543
3544
3546
3547
3548 //**************************************************************************************************************************************************
3549 //**************************************************************************************************************************************************
3550 //**************************************************************************************************************************************************
3551 //
3552 // IMPLEMENTATION
3553 //
3554 //
3555 // Don't you dare look below... this is private :-p
3556 //
3557 //***************************************************************************************************************************************************
3558 //***************************************************************************************************************************************************
3559 //***************************************************************************************************************************************************
3560
3561
3562
3563private:
3564
3565 bool _collision(); // For debug
3566
3567private:
3568
3569 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.
3570
3571
3572
3573 /***************************************
3574 * COPY / RESIZE / BLIT
3575 ****************************************/
3576
3577 static inline void _fast_memset(color_t* p_dest, color_t color, int32_t len);
3578
3579 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);
3580 bool _blitClip(int sprite_lx, int sprite_ly, int& dest_x, int& dest_y, int& sprite_x, int& sprite_y, int& sx, int& sy);
3581
3582 void _blit(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy);
3583 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); }
3584 static void _blitRegionUp(color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy);
3585 static void _blitRegionDown(color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy);
3586
3587 void _blit(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, float opacity);
3588 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); }
3589 static void _blitRegionUp(color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy, float opacity);
3590 static void _blitRegionDown(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, 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);
3593 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); }
3594 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);
3595 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);
3596
3597 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);
3598 static void _maskRegion(color_t transparent_color, color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy) { if ((size_t)pdest <= (size_t)psrc) _maskRegionUp(transparent_color, pdest, dest_stride, psrc, src_stride, sx, sy); else _maskRegionDown(transparent_color, pdest, dest_stride, psrc, src_stride, sx, sy); }
3599 static void _maskRegionUp(color_t transparent_color, color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy);
3600 static void _maskRegionDown(color_t transparent_color, color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy);
3601 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); }
3602 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);
3603 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);
3604
3605 template<typename color_t_src, int CACHE_SIZE, bool USE_BLENDING, bool USE_MASK, bool USE_CUSTOM_OPERATOR, typename BLEND_OPERATOR>
3606 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);
3607
3608 void _blitRotated90(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, float opacity);
3609 void _blitRotated180(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, float opacity);
3610 void _blitRotated270(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, float opacity);
3611
3612 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);
3613 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);
3614 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);
3615
3616
3617 /***************************************
3618 * FLOOD FILLING
3619 ****************************************/
3620
3621 template<bool UNICOLOR_COMP, int STACK_SIZE_BYTES> int _scanfill(int x, int y, color_t border_color, color_t new_color);
3622
3623
3624
3625 /***************************************
3626 * BRESENHAM
3627 ****************************************/
3628
3629 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)
3630 {
3631 const int x = seg.X(); const int y = seg.Y();
3632 if (CHECKRANGE) { if ((x < 0) || (y < 0) || (x >= _lx) || (y >= _ly)) return; }
3633 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); }
3634 else if (BLEND) { _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)].blend256(color, (uint32_t)op); }
3635 else { _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)] = color; }
3636 }
3637
3638 template<bool CHECKRANGE = false> inline TGX_INLINE void _bseg_update_pixel(const BSeg & seg, color_t color, int32_t op, int32_t aa)
3639 {
3640 const int x = seg.X(); const int y = seg.Y();
3641 if (CHECKRANGE) { if ((x < 0) || (y < 0) || (x >= _lx) || (y >= _ly)) return; }
3642 _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)].blend256(color, (uint32_t)((op * aa)>>8));
3643 }
3644
3645
3646 template<int SIDE> void _bseg_draw_template(BSeg& seg, bool draw_first, bool draw_last, color_t color, int32_t op, bool checkrange);
3647 void _bseg_draw(BSeg & seg, bool draw_first, bool draw_last, color_t color, int side, int32_t op, bool checkrange);
3648 void _bseg_draw_AA(BSeg & seg, bool draw_first, bool draw_last, color_t color, int32_t op, bool checkrange);
3649
3650 template<int SIDE> void _bseg_avoid1_template(BSeg& segA, bool lastA, BSeg& segB, bool lastB, color_t color, int32_t op, bool checkrange);
3651 void _bseg_avoid1(BSeg& PQ, BSeg& PA, bool drawP, bool drawQ, bool closedPA, color_t color, int side, int32_t op, bool checkrange);
3652 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);
3653 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);
3654 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);
3655 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);
3656 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);
3657 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);
3658 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);
3659 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);
3660
3661
3662 // filling a triangle
3663
3664 //void _bseg_fill_triangle(iVec2 P1, iVec2 P2, iVec2 P3, color_t fillcolor, float opacity);
3665 void _bseg_fill_triangle(fVec2 fP1, fVec2 fP2, fVec2 fP3, color_t fillcolor, float opacity);
3666 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);
3667 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);
3668 void _bseg_fill_interior_angle(iVec2 P, iVec2 Q1, iVec2 Q2, BSeg& seg1, BSeg& seg2, color_t color, bool fill_last, float opacity);
3669 void _bseg_fill_interior_angle_sub(int dir, int y, int ytarget, BSeg& sega, BSeg& segb, color_t color, float opacity);
3670
3671 void _triangle_hline(int x1, int x2, const int y, color_t color, float opacity)
3672 { // like drawFasthLine but used by _bseg_fill_interior_angle_sub
3673 x1 = tgx::max(0, x1); x2 = tgx::min(_lx - 1, x2);
3674 if (x1 > x2) return;
3675 color_t* p = _buffer + TGX_CAST32(x1) + TGX_CAST32(y) * TGX_CAST32(_stride);
3676 if (opacity < 0) { while (x1++ <= x2) { (*p++) = color; } } else { while (x1++ <= x2) { (*p++).blend(color,opacity); } }
3677 }
3678
3679 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.
3680
3681
3682
3683 /***************************************
3684 * DRAWING LINES
3685 ****************************************/
3686
3687 template<bool CHECKRANGE, bool CHECK_VALID_BLEND = true> TGX_INLINE inline void _drawPixel(iVec2 pos, color_t color, float opacity)
3688 {
3689 if (CHECKRANGE) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return; }
3690 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);
3691 }
3692
3693 template<bool CHECKRANGE> TGX_INLINE inline void _drawPixel(iVec2 pos, color_t color)
3694 {
3695 if (CHECKRANGE) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return; }
3696 _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)] = color;
3697 }
3698
3699 TGX_INLINE inline void _drawPixel(bool checkrange, iVec2 pos, color_t color, float opacity)
3700 {
3701 if (checkrange) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return; }
3702 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);
3703 }
3704
3705 TGX_INLINE inline void _drawPixel(bool checkrange, iVec2 pos, color_t color)
3706 {
3707 if (checkrange) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return; }
3708 _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)] = color;
3709 }
3710
3711 template<bool CHECKRANGE = true> TGX_INLINE inline color_t _readPixel(iVec2 pos, color_t outside_color) const
3712 {
3713 if (CHECKRANGE) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return outside_color; }
3714 return _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)];
3715 }
3716
3717 template<bool CHECKRANGE> void _drawFastVLine(iVec2 pos, int h, color_t color, float opacity);
3718 template<bool CHECKRANGE> void _drawFastHLine(iVec2 pos, int w, color_t color, float opacity);
3719 template<bool CHECKRANGE> void _drawFastVLine(iVec2 pos, int h, color_t color);
3720 template<bool CHECKRANGE> void _drawFastHLine(iVec2 pos, int w, color_t color);
3721
3722 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); }
3723 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); }
3724 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); }
3725 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); }
3726 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); }
3727
3728
3729 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);
3730
3731 // legacy (not used anymore)
3732 void _drawWedgeLine(float ax, float ay, float bx, float by, float aw, float bw, color_t color, float opacity);
3733 float _wedgeLineDistance(float pax, float pay, float bax, float bay, float dr);
3734
3735
3736
3737
3738 /***************************************
3739 * RECT AND ROUNDED RECT
3740 ****************************************/
3741
3742
3743 // low quality drawing
3744 void _fillRect(iBox2 B, color_t color, float opacity);
3745 template<bool CHECKRANGE> void _drawRoundRect(int x, int y, int w, int h, int r, color_t color);
3746 template<bool CHECKRANGE> void _drawRoundRect(int x, int y, int w, int h, int r, color_t color, float opacity);
3747 template<bool CHECKRANGE> void _fillRoundRect(int x, int y, int w, int h, int r, color_t color);
3748 template<bool CHECKRANGE> void _fillRoundRect(int x, int y, int w, int h, int r, color_t color, float opacity);
3749
3750
3751 // high quality drawing
3752 void _fillSmoothRect(const fBox2& B, color_t color, float opacity);
3753 void _fillSmoothRoundedRect(const tgx::iBox2& B, float corner_radius, color_t color, float opacity);
3754 void _drawSmoothRoundRect(const tgx::iBox2& B, float corner_radius, color_t color, float opacity);
3755 void _drawSmoothWideRoundRect(const tgx::iBox2& B, float corner_radius, float thickness, color_t color, float opacity);
3756
3757
3758
3759 /***************************************
3760 * TRIANGLES
3761 ****************************************/
3762
3763
3764 // methods using the 3D triangle rasterizer
3765 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
3766 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
3767
3768 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);
3769 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);
3770
3771
3772
3773 /***************************************
3774 * QUADS
3775 ****************************************/
3776
3777
3778
3779 /***************************************
3780 * POLYGONS AND POLYLINES
3781 ****************************************/
3782
3783
3784
3785 /***************************************
3786 * CIRCLES, ARC AND PIES
3787 ****************************************/
3788
3789
3790 // low quality drawing for circles
3791 template<bool CHECKRANGE> void _drawCircleHelper(int x0, int y0, int r, int cornername, color_t color, float opacity); // adapted from Adafruit GFX library
3792 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
3793 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
3794
3795
3796 // high quality drawing for circle, arc and pie
3797 static float _rectifyAngle(float a);
3798 static void _defaultQuarterVH(int quarter, int& v, int& h);
3799
3800 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);
3801 void _fillSmoothQuarterCircleInterHP0(int quarter, tgx::fVec2 C, float R, color_t color, float opacity);
3802 void _fillSmoothQuarterCircleInterHP1(int quarter, tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg1, int side1);
3803 void _fillSmoothQuarterCircleInterHP2(int quarter, tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg1, int side1, const BSeg& seg2, int side2);
3804 void _fillSmoothCircleInterHP(tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg, int side); // used to draw rounded ends
3805
3806 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);
3807 void _drawSmoothQuarterCircleInterHP0(int quarter, tgx::fVec2 C, float R, color_t color, float opacity);
3808 void _drawSmoothQuarterCircleInterHP1(int quarter, tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg1, int side1);
3809 void _drawSmoothQuarterCircleInterHP2(int quarter, tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg1, int side1, const BSeg& seg2, int side2);
3810
3811 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);
3812 void _drawSmoothThickQuarterCircleInterHP0(int quarter, tgx::fVec2 C, float R, float thickness, color_t color, float opacity);
3813 void _drawSmoothThickQuarterCircleInterHP1(int quarter, tgx::fVec2 C, float R, float thickness, color_t color, float opacity, const BSeg& seg1, int side1);
3814 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);
3815
3816 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);
3817 void _fillSmoothThickQuarterCircleInterHP0(int quarter, tgx::fVec2 C, float R, float thickness, color_t color_interior, color_t color_border, float opacity);
3818 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);
3819 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);
3820
3821
3822
3823 /***************************************
3824 * ELLIPSES
3825 ****************************************/
3826
3827
3828 // low quality drawing for ellipses
3829 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
3830
3831 // high quality drawing for ellipses
3832 void _drawSmoothQuarterEllipse(tgx::fVec2 C, float rx, float ry, int quarter, bool vertical_center_line, bool horizontal_center_line, color_t color, float opacity);
3833 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);
3834 void _fillSmoothQuarterEllipse(tgx::fVec2 C, float rx, float ry, int quarter, bool vertical_center_line, bool horizontal_center_line, color_t color, float opacity);
3835 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);
3836
3837
3838
3839 /***************************************
3840 * DRAWING BEZIER
3841 ****************************************/
3842
3843
3844 // low quality Bezier curves
3845 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);
3846 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);
3847 void _drawQuadBezier(iVec2 P1, iVec2 P2, iVec2 PC, float wc, bool drawP2, color_t color, float opacity);
3848
3849 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);
3850 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);
3851 void _drawCubicBezier(iVec2 P1, iVec2 P2, iVec2 PA, iVec2 PB, bool drawP2, color_t color, float opacity);
3852
3853 void _plotQuadSpline(int n, int x[], int y[], bool draw_last, const color_t color, const float opacity);
3854 template<int SPLINE_MAX_POINTS> void _drawQuadSpline(int nbpoints, const iVec2* tabPoints, bool draw_last_point, color_t color, float opacity);
3855
3856 void _plotClosedSpline(int n, int x[], int y[], const color_t color, const float opacity);
3857 template<int SPLINE_MAX_POINTS> void _drawClosedSpline(int nbpoints, const iVec2* tabPoints, color_t color, float opacity);
3858
3859 void _plotCubicSpline(int n, int x[], int y[], bool draw_last, const color_t color, const float opacity);
3860 template<int SPLINE_MAX_POINTS> void _drawCubicSpline(int nbpoints, const iVec2* tabPoints, bool draw_last_point, color_t color, float opacity);
3861
3862
3863
3864 // high quality Bezier curves
3865 static bool _splitRationalQuadBezier(fVec2 P1, fVec2 P2, fVec2 PC, float w, fVec2& Q, fVec2& PB, float& wb);
3866 static bool _splitCubicBezier(fVec2 P1, fVec2 P2, fVec2 PPC1, fVec2 PPC2, fVec2& Q, fVec2& C, fVec2 & D);
3867
3868
3869
3870 /***************************************
3871 * DRAWING TEXT
3872 ****************************************/
3873
3874 bool _clipit(int& x, int& y, int& sx, int& sy, int& b_left, int& b_up);
3875
3876 template<bool BLEND> iVec2 _drawCharGFX(char c, iVec2 pos, color_t col, const GFXfont& font, float opacity);
3877 template<bool BLEND> iVec2 _drawCharILI(char c, iVec2 pos, color_t col, const ILI9341_t3_font_t& font, float opacity);
3878
3879 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);
3880 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);
3881
3882 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);
3883 template<bool BLEND> static void _drawcharline(const uint8_t* bitmap, int32_t off, color_t* p, int dx, color_t col, float opacity);
3884 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);
3885 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);
3886 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);
3887 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);
3888
3889 template<bool BLEND> static TGX_INLINE inline void _drawFontPixel(color_t* p, color_t col, uint32_t alpha256)
3890 {
3891 if (BLEND)
3892 {
3893 p->blend256(col, alpha256);
3894 }
3895 else if (alpha256 >= 256)
3896 {
3897 *p = col;
3898 }
3899 else if (alpha256 > 0)
3900 {
3901 p->blend256(col, alpha256);
3902 }
3903 }
3904
3905
3906
3907
3908 /************************************************************************************************************
3909 *
3910 * Image members variables (16 bytes).
3911 *
3912 *************************************************************************************************************/
3913
3914 color_t* _buffer; // pointer to the pixel buffer - nullptr if the image is invalid.
3915 int _lx, _ly; // image size - (0,0) if the image is invalid
3916 int _stride; // image stride - 0 if the image is invalid
3917
3918
3919 };
3920
3921
3922
3923}
3924
3925
3926
3927
3928#include "Image.inl"
3929
3930
3931#endif
3932
3933#endif
3934
2D box class
Anchor
Define the placement of an anchor point inside a box.
Definition: Box2.h:74
Color classes [RGB565, RGB24, RGB32, RGB64, RGBf, HSV].
Define the GFXFont anf ILI9341_t3 font format if needed.
EndPath
Enumeration of end path shapes.
Definition: Image.h:51
@ END_ARROW_SKEWED_1
tiny skewed arrow head [extends = line thickness]
Definition: Image.h:59
@ END_ARROW_SKEWED_4
large skewed arrow head [extends = 4 x line thickness]
Definition: Image.h:62
@ END_ARROW_3
medium arrow head [extends = 3 x line thickness]
Definition: Image.h:56
@ END_ROUNDED
rounded end.
Definition: Image.h:53
@ END_ARROW_5
huge arrow head [extends = 5 x line thickness]
Definition: Image.h:58
@ END_ARROW_SKEWED_3
medium skewed arrow head [extends = 3 x line thickness]
Definition: Image.h:61
@ END_STRAIGHT
straight end.
Definition: Image.h:52
@ END_ARROW_SKEWED_2
small skewed arrow head [extends = 2 x line thickness]
Definition: Image.h:60
@ END_ARROW_1
tiny arrow head [extends = line thickness]
Definition: Image.h:54
@ END_ARROW_SKEWED_5
huge skewed arrow head [extends = 5 x line thickness]
Definition: Image.h:63
@ END_ARROW_4
large arrow head [extends = 4 x line thickness]
Definition: Image.h:57
@ END_ARROW_2
small arrow head [extends = 2 x line thickness]
Definition: Image.h:55
Utility/miscellaneous functions used throughout the library.
TGX_INLINE T min(const T &a, const T &b)
Don't know why but faster than fminf() for floats.
Definition: Misc.h:132
TGX_INLINE T max(const T &a, const T &b)
Don't know why but much faster than fmaxf() for floats.
Definition: Misc.h:136
3D triangle rasterizer function.
Triangle shader parameters.
Triangle shader functions.
2D vector.
Vec2< int > iVec2
Integer-valued 2D vector.
Definition: Vec2.h:47
3D vector.
4D vector.
Image class [MAIN CLASS FOR THE 2D API].
Definition: Image.h:145
void drawLineAA(fVec2 P1, fVec2 P2, color_t color, float opacity=1.0f)
Draw a line segment between two points [High quality].
void iterate(ITERFUN cb_fun, tgx::iBox2 B) const
Iterate over the pixel of the image inside a given region.
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_INLINE int height() const
Return the image height.
Definition: Image.h:372
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).
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.
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_INLINE int stride() const
Return the image stride.
Definition: Image.h:388
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/.
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.
void drawThickPolygonAA(FUNCTOR_NEXT next_point, float thickness, color_t color, float opacity=1.0f)
Draw a polygon with thick lines (High quality).
TGX_INLINE const color_t & operator()(iVec2 pos) const
Get a reference to a pixel (no range check!)
Definition: Image.h:537
void set(T *buffer, int lx, int ly, int stride=DEFAULT_STRIDE)
Set/update the image parameters.
void drawRect(const iBox2 &B, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a rectangle.
TGX_INLINE const color_t * data() const
Return a pointer to the pixel buffer.
Definition: Image.h:414
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).
void iterate(ITERFUN cb_fun)
Iterate over all the pixels of the image.
void drawCircle(iVec2 center, int r, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a circle.
int fill(iVec2 start_pos, color_t new_color)
'Flood fill' a 4-connected region of the image.
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).
Image(const Image< color_t > &im)=default
Default copy constructor.
void fillRectAA(const fBox2 &B, color_t color, float opacity=1.0f)
Draw a filled rectangle [High quality].
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:510
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).
void drawThickRect(const iBox2 &B, int thickness, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a rectangle with a thick outline.
void drawFastVLine(iVec2 pos, int h, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a vertical segment of h pixels starting at pos.
void drawPolyline(FUNCTOR_NEXT next_point, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a polyline ie a sequence of consecutive segments [P0,P1] , [P1,P2],,, [Pn-1,Pn].
void drawThickRectAA(const fBox2 &B, float thickness, color_t color, float opacity=1.0f)
Draw a filled rectangle with a thick border [High quality].
void crop(const iBox2 &subbox)
Crop the image.
Image(T *buffer, iVec2 dim, int stride=DEFAULT_STRIDE)
Constructor.
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.
void drawFastHLine(iVec2 pos, int w, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a horizontal segment of w pixels starting at pos.
Image(T *buffer, int lx, int ly, int stride=DEFAULT_STRIDE)
Constructor.
void iterate(ITERFUN cb_fun) const
Iterate over all the pixels of the image.
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).
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.
void fillRoundRectAA(const fBox2 &B, float corner_radius, color_t color, float opacity=1.0f)
Draw a filled rounded rectangle [High quality].
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).
void drawEllipse(iVec2 center, iVec2 radiuses, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw an ellipse.
void setInvalid()
Set the image as invalid.
TGX_INLINE color_t & operator()(int x, int y)
Get a reference to a pixel (no range check!)
Definition: Image.h:574
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...
void fillRectHGradient(iBox2 B, color_t color_left, color_t color_right, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a rectangle filled with a horizontal gradient of colors.
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:3438
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).
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...
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.
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).
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.
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_INLINE void drawPixelf(fVec2 pos, color_t color, float opacity)
Blend a pixel with the current pixel color (floating point coord).
Definition: Image.h:497
TGX_INLINE color_t & operator()(iVec2 pos)
Get a reference to a pixel (no range check!)
Definition: Image.h:548
Image()
Default constructor.
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).
void drawRoundRectAA(const fBox2 &B, float corner_radius, color_t color, float opacity=1.0f)
Draw a rounded rectangle [High quality].
TGX_INLINE int width() const
Return the image width.
Definition: Image.h:356
Image< color_t > operator()(const iBox2 &B) const
Return a sub-image of this image (sharing the same pixel buffer).
Image< color_t > getCrop(const iBox2 &subbox) const
Return a sub-image of this image (sharing the same pixel buffer).
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.
void fillQuad(iVec2 P1, iVec2 P2, iVec2 P3, iVec2 P4, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
draw a filled quad.
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.
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.
void drawPolylineAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity=1.0f)
Draw a polyline ie a sequence of consecutive segments [P0,P1] , [P1,P2],,, [Pn-1,Pn] (High quality).
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...
void drawQuad(iVec2 P1, iVec2 P2, iVec2 P3, iVec2 P4, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a quad.
TGX_INLINE void drawPixel(iVec2 pos, color_t color, float opacity)
Blend a pixel with the current pixel color.
Definition: Image.h:481
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_INLINE bool isValid() const
Query if the image is valid.
Definition: Image.h:340
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.
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.
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].
void drawPolygon(FUNCTOR_NEXT next_point, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a closed polygon with vertices [P0,P2,,, PN].
void fillScreenVGradient(color_t top_color, color_t bottom_color)
Fill the whole image with a vertical color gradient between two colors.
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.
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_INLINE const color_t & operator()(int x, int y) const
Get a reference to a pixel (no range check!)
Definition: Image.h:561
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_INLINE void drawPixel(iVec2 pos, color_t color)
Set a pixel at a given position.
Definition: Image.h:455
TGX_INLINE iVec2 dim() const
Return the image dimensions as an iVec2.
Definition: Image.h:396
int fontHeight(const GFXfont &font) const
Query the height of a font.
void clear(color_t color)
Fill the whole image with a single color.
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.
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].
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_INLINE color_t * data()
Return a pointer to the pixel buffer.
Definition: Image.h:424
void drawPolygonAA(FUNCTOR_NEXT next_point, color_t color, float opacity=1.0f)
Draw a closed polygon with vertices [P0,P2,,, PN] (High quality).
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.
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_INLINE iBox2 imageBox() const
Return the image dimension as a box.
Definition: Image.h:404
void drawPolylineAA(FUNCTOR_NEXT next_point, color_t color, float opacity=1.0f)
Draw a polyline ie a sequence of consecutive segments [P0,P1] , [P1,P2],,, [Pn-1,Pn] (High quality).
void fillRect(const iBox2 &B, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled rectangle.
void set(T *buffer, iVec2 dim, int stride=DEFAULT_STRIDE)
Set/update the image parameters.
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.
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.
void drawThickCircleAA(fVec2 center, float r, float thickness, color_t color, float opacity=1.0f)
Draw a circle with a thick border (high quality).
void drawPolyline(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a polyline ie a sequence of consecutive segments [P0,P1] , [P1,P2],,, [Pn-1,Pn].
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).
void fillScreenHGradient(color_t left_color, color_t right_color)
Fill the whole screen with a horizontal color gradient between two colors.
Image< color_dst > convert()
Convert this image to another type.
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_INLINE int lx() const
Return the image width.
Definition: Image.h:364
void drawTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, color_t color, float opacity=1.0f)
Draw a triangle [High quality].
TGX_INLINE int ly() const
Return the image height.
Definition: Image.h:380
int fill(iVec2 start_pos, color_t border_color, color_t new_color)
'Flood fill' a 4-connected region of the image.
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.
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.
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.
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 consecutive thick segments [P0,P1] , [P1,P2],...
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.
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).
void drawThickPolygonAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t color, float opacity=1.0f)
Draw a polygon with thick lines (High quality).
void fillScreen(color_t color)
Fill the whole image with a single color.
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.
void blitBackward(Image< color_t > &dst_sprite, iVec2 upperleftpos) const
Reverse blitting.
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...
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].
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.
void fillPolygon(FUNCTOR_NEXT next_point, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled polygon with vertices [P0,P2,,, PN].
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...
void drawEllipseAA(fVec2 center, fVec2 radiuses, color_t color, float opacity=1.0f)
Draw an ellipse (high quality).
Image(const Image< color_t > &im, iBox2 subbox)
Constructor.
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...
void fillQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, color_t color, float opacity=1.0f)
Draw a filled quad [High quality].
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).
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.
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 consecutive thick segments [P0,P1] , [P1,P2],...
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.
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_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:525
void fillPolygonAA(FUNCTOR_NEXT next_point, color_t color, float opacity=1.0f)
Draw a filled polygon (High quality).
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).
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.
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.
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).
void fillTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, color_t color, float opacity=1.0f)
Draw a filled triangle [High quality].
void fillEllipseAA(fVec2 center, fVec2 radiuses, color_t color, float opacity=1.0f)
Draw a filled ellipse (high quality).
void drawTriangle(const iVec2 &P1, const iVec2 &P2, const iVec2 &P3, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a triangle.
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].
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].
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.
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.
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.
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).
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).
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.
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.
void fillCircleAA(fVec2 center, float r, color_t color, float opacity=1.0f)
Draw a filled circle (high quality).
void drawQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, color_t color, float opacity=1.0f)
Draw a quad [High quality].
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].
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.
void drawCircleAA(fVec2 center, float r, color_t color, float opacity=1.0f)
Draw a circle (high quality).
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/.
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).
void fillPolygonAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity=1.0f)
Draw a filled polygon (High quality).
Image< color_t > reduceHalf()
Reduce this image by half.
Image & operator=(const Image< color_t > &im)=default
Default assignment operator.
TGX_INLINE void drawPixelf(fVec2 pos, color_t color)
Set a pixel at a given position (floating point coord).
Definition: Image.h:467
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.
void iterate(ITERFUN cb_fun, tgx::iBox2 B)
Iterate over the pixel of the image inside a given region.
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).
static const int DEFAULT_STRIDE
If not specified, the stride of an image is equal to its width.
Definition: Image.h:156
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.
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....
void drawThickEllipseAA(fVec2 center, fVec2 radiuses, float thickness, color_t color, float opacity=1.0f)
Draw an ellipse with a thick border (high quality).
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.
int fontHeight(const ILI9341_t3_font_t &font) const
Query the height of a font.
GFXFont font format.
Definition: Fonts.h:74
ILI9341_t3 PJRC font format.
Definition: Fonts.h:105
Generic 2D Box [specializations iBox2 , fBox2, dBox2].
Definition: Box2.h:151
Color in R5/G6/B5 format.
Definition: Color.h:216
Generic 2D vector [specializations iVec2, fVec2, dVec2].
Definition: Vec2.h:64
T x
'x' coordinate (first dimension)
Definition: Vec2.h:72
T y
'y' coordinate (second dimension)
Definition: Vec2.h:73
#define TGX_DEFAULT_NO_BLENDING
Default opacity sentinel used by drawing primitives to request overwrite/no-blending mode.
Definition: tgx_config.h:242