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

Loading...
Searching...
No Matches
Image.h
Go to the documentation of this file.
1
5//
6// Copyright 2020 Arvind Singh
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11//version 2.1 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
16// Lesser General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public
19// License along with this library; If not, see <http://www.gnu.org/licenses/>.
20#ifndef _TGX_IMAGE_H_
21#define _TGX_IMAGE_H_
22
23#include "Fonts.h" // include this also when compiled as a C file
24
25// and now only C++, no more plain C
26#ifdef __cplusplus
27
28#include "Misc.h"
29#include "Vec2.h"
30#include "Vec3.h"
31#include "Vec4.h"
32#include "Box2.h"
33#include "Color.h"
34#include "ShaderParams.h"
35#include "Shaders.h"
36#include "Rasterizer.h"
37#include "bseg.h"
38
39#include <stdint.h>
40
41
42 namespace tgx
43{
50 enum EndPath
51 {
52 END_STRAIGHT = -1,
53 END_ROUNDED = 0,
54 END_ARROW_1 = 1,
55 END_ARROW_2 = 2,
56 END_ARROW_3 = 3,
57 END_ARROW_4 = 4,
58 END_ARROW_5 = 5,
59 END_ARROW_SKEWED_1 = 101,
60 END_ARROW_SKEWED_2 = 102,
61 END_ARROW_SKEWED_3 = 103,
62 END_ARROW_SKEWED_4 = 104,
63 END_ARROW_SKEWED_5 = 105,
64 };
65
66
67
68
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
191 Image();
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
301 Image<color_t> operator()(const iBox2& B) const;
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
348 void setInvalid();
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
945 Image<color_t> copyReduceHalf(const Image<color_t> & src_image);
946
947
956 Image<color_t> reduceHalf();
957
958
976 template<typename color_dst>
977 Image<color_dst> convert();
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 //*************************************************************************************************************
3122
3123 //*************************************************************************************************************
3124 //*************************************************************************************************************
3125 //*************************************************************************************************************
3126
3127
3128
3140 int fontHeight(const GFXfont & font) const;
3141
3142
3154 int fontHeight(const ILI9341_t3_font_t& font) const;
3155
3156
3174 iBox2 measureChar(char c, iVec2 pos, const GFXfont& font, Anchor anchor = DEFAULT_TEXT_ANCHOR, int* xadvance = nullptr) const;
3175
3176
3194 iBox2 measureChar(char c, iVec2 pos, const ILI9341_t3_font_t& font, Anchor anchor = DEFAULT_TEXT_ANCHOR, int* xadvance = nullptr) const;
3195
3196
3213 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;
3214
3215
3232 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;
3233
3234
3251 iVec2 drawChar(char c, iVec2 pos, const GFXfont& font, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3252
3253
3270 iVec2 drawChar(char c, iVec2 pos, const ILI9341_t3_font_t& font, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3271
3272
3290 iVec2 drawText(const char* text, iVec2 pos, const GFXfont& font, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3291
3292
3310 iVec2 drawText(const char* text, iVec2 pos, const ILI9341_t3_font_t& font, color_t color, float opacity = TGX_DEFAULT_NO_BLENDING);
3311
3312
3313
3337 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);
3338
3339
3363 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);
3364
3365
3366
3367
3368
3369#ifndef DOXYGEN_EXCLUDE
3370
3371
3372
3374 //*************************************************************************************************************
3380 //*************************************************************************************************************
3382
3383
3387 DEPRECATED("Use new signature: drawText(text, pos, font, color, opacity) or the new method drawTextEx()")
3388 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); }
3389
3390
3394 DEPRECATED("Use new signature: drawText(text, pos, font, color, opacity) or the new method drawTextEx()")
3395 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); }
3396
3397
3401 DEPRECATED("Use new signature measureText(text,pos,font,anchor, wrap, newline_at_0)")
3402 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); }
3403
3404
3408 DEPRECATED("Use new signature measureText(text,pos,font,anchor, wrap, newline_at_0)")
3409 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); }
3410
3411
3412#endif
3413
3414
3415
3416
3417
3419 //*************************************************************************************************************
3420 //*************************************************************************************************************
3421 //*************************************************************************************************************
3427
3428 //*************************************************************************************************************
3429 //*************************************************************************************************************
3430 //*************************************************************************************************************
3431
3432
3433
3441 template<typename T> void setOpenFontRender(T& ofr, float opacity = TGX_DEFAULT_NO_BLENDING)
3442 {
3443 // for some strange reason, cannot put this method inside the .inl file when compiling with arduino IDE...
3444 // must have something to do with Arduino's mangling of .ino file...
3445 if ((opacity >= 0) && (opacity < 1))
3446 {
3447 ofr.set_drawPixel([&](int32_t x, int32_t y, uint16_t c) { drawPixel({ x,y }, color_t(RGB565(c)), opacity); return; });
3448 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; });
3449 }
3450 else
3451 {
3452 ofr.set_drawPixel([&](int32_t x, int32_t y, uint16_t c) { drawPixel({ x,y }, color_t(RGB565(c))); return; });
3453 ofr.set_drawFastHLine([&](int32_t x, int32_t y, int32_t w, uint16_t c) { drawFastHLine({ x,y }, w, color_t(RGB565(c))); return; });
3454 }
3455 ofr.set_startWrite([&](void) { return; });
3456 ofr.set_endWrite([&](void) { return; });
3457 }
3458
3459
3481 template<typename PNG_T> int PNGDecode(PNG_T& png, iVec2 topleft = iVec2(0, 0), float opacity = 1.0f);
3482
3483
3511 template<typename JPEG_T> int JPEGDecode(JPEG_T& jpeg, iVec2 topleft = iVec2(0, 0), int options = 0, float opacity = 1.0f);
3512
3513
3541 template<typename GIF_T> int GIFplayFrame(GIF_T& gif, iVec2 topleft = iVec2(0, 0), float opacity = 1.0f);
3542
3543
3544
3545
3546
3547
3549
3550
3551 //**************************************************************************************************************************************************
3552 //**************************************************************************************************************************************************
3553 //**************************************************************************************************************************************************
3554 //
3555 // IMPLEMENTATION
3556 //
3557 //
3558 // Don't you dare look below... this is private :-p
3559 //
3560 //***************************************************************************************************************************************************
3561 //***************************************************************************************************************************************************
3562 //***************************************************************************************************************************************************
3563
3564
3565
3566 private:
3567
3568 bool _collision(); // For debug
3569
3570 private:
3571
3572 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.
3573
3574
3575
3576 /***************************************
3577 * COPY / RESIZE / BLIT
3578 ****************************************/
3579
3580 static inline void _fast_memset(color_t* p_dest, color_t color, int32_t len);
3581
3582 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);
3583 bool _blitClip(int sprite_lx, int sprite_ly, int& dest_x, int& dest_y, int& sprite_x, int& sprite_y, int& sx, int& sy);
3584
3585 void _blit(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy);
3586 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); }
3587 static void _blitRegionUp(color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy);
3588 static void _blitRegionDown(color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy);
3589
3590 void _blit(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, float opacity);
3591 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); }
3592 static void _blitRegionUp(color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy, float opacity);
3593 static void _blitRegionDown(color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy, float opacity);
3594
3595 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);
3596 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); }
3597 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);
3598 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);
3599
3600 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);
3601 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); }
3602 static void _maskRegionUp(color_t transparent_color, color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy);
3603 static void _maskRegionDown(color_t transparent_color, color_t* pdest, int dest_stride, color_t* psrc, int src_stride, int sx, int sy);
3604 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); }
3605 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);
3606 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);
3607
3608 template<typename color_t_src, int CACHE_SIZE, bool USE_BLENDING, bool USE_MASK, bool USE_CUSTOM_OPERATOR, typename BLEND_OPERATOR>
3609 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);
3610
3611 void _blitRotated90(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, float opacity);
3612 void _blitRotated180(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, float opacity);
3613 void _blitRotated270(const Image& sprite, int dest_x, int dest_y, int sprite_x, int sprite_y, int sx, int sy, float opacity);
3614
3615 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);
3616 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);
3617 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);
3618
3619
3620 /***************************************
3621 * FLOOD FILLING
3622 ****************************************/
3623
3624 template<bool UNICOLOR_COMP, int STACK_SIZE_BYTES> int _scanfill(int x, int y, color_t border_color, color_t new_color);
3625
3626
3627
3628 /***************************************
3629 * BRESENHAM
3630 ****************************************/
3631
3632 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)
3633 {
3634 const int x = seg.X(); const int y = seg.Y();
3635 if (CHECKRANGE) { if ((x < 0) || (y < 0) || (x >= _lx) || (y >= _ly)) return; }
3636 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); }
3637 else if (BLEND) { _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)].blend256(color, (uint32_t)op); }
3638 else { _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)] = color; }
3639 }
3640
3641 template<bool CHECKRANGE = false> inline TGX_INLINE void _bseg_update_pixel(const BSeg & seg, color_t color, int32_t op, int32_t aa)
3642 {
3643 const int x = seg.X(); const int y = seg.Y();
3644 if (CHECKRANGE) { if ((x < 0) || (y < 0) || (x >= _lx) || (y >= _ly)) return; }
3645 _buffer[TGX_CAST32(x) + TGX_CAST32(_stride) * TGX_CAST32(y)].blend256(color, (uint32_t)((op * aa)>>8));
3646 }
3647
3648
3649 template<int SIDE> void _bseg_draw_template(BSeg& seg, bool draw_first, bool draw_last, color_t color, int32_t op, bool checkrange);
3650 void _bseg_draw(BSeg & seg, bool draw_first, bool draw_last, color_t color, int side, int32_t op, bool checkrange);
3651 void _bseg_draw_AA(BSeg & seg, bool draw_first, bool draw_last, color_t color, int32_t op, bool checkrange);
3652
3653 template<int SIDE> void _bseg_avoid1_template(BSeg& segA, bool lastA, BSeg& segB, bool lastB, color_t color, int32_t op, bool checkrange);
3654 void _bseg_avoid1(BSeg& PQ, BSeg& PA, bool drawP, bool drawQ, bool closedPA, color_t color, int side, int32_t op, bool checkrange);
3655 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);
3656 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);
3657 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);
3658 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);
3659 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);
3660 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);
3661 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);
3662 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);
3663
3664
3665 // filling a triangle
3666
3667 //void _bseg_fill_triangle(iVec2 P1, iVec2 P2, iVec2 P3, color_t fillcolor, float opacity);
3668 void _bseg_fill_triangle(fVec2 fP1, fVec2 fP2, fVec2 fP3, color_t fillcolor, float opacity);
3669 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);
3670 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);
3671 void _bseg_fill_interior_angle(iVec2 P, iVec2 Q1, iVec2 Q2, BSeg& seg1, BSeg& seg2, color_t color, bool fill_last, float opacity);
3672 void _bseg_fill_interior_angle_sub(int dir, int y, int ytarget, BSeg& sega, BSeg& segb, color_t color, float opacity);
3673
3674 void _triangle_hline(int x1, int x2, const int y, color_t color, float opacity)
3675 { // like drawFasthLine but used by _bseg_fill_interior_angle_sub
3676 x1 = tgx::max(0, x1); x2 = tgx::min(_lx - 1, x2);
3677 if (x1 > x2) return;
3678 color_t* p = _buffer + TGX_CAST32(x1) + TGX_CAST32(y) * TGX_CAST32(_stride);
3679 if (opacity < 0) { while (x1++ <= x2) { (*p++) = color; } } else { while (x1++ <= x2) { (*p++).blend(color,opacity); } }
3680 }
3681
3682 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.
3683
3684
3685
3686 /***************************************
3687 * DRAWING LINES
3688 ****************************************/
3689
3690 template<bool CHECKRANGE, bool CHECK_VALID_BLEND = true> TGX_INLINE inline void _drawPixel(iVec2 pos, color_t color, float opacity)
3691 {
3692 if (CHECKRANGE) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return; }
3693 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);
3694 }
3695
3696 template<bool CHECKRANGE> TGX_INLINE inline void _drawPixel(iVec2 pos, color_t color)
3697 {
3698 if (CHECKRANGE) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return; }
3699 _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)] = color;
3700 }
3701
3702 TGX_INLINE inline void _drawPixel(bool checkrange, iVec2 pos, color_t color, float opacity)
3703 {
3704 if (checkrange) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return; }
3705 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);
3706 }
3707
3708 TGX_INLINE inline void _drawPixel(bool checkrange, iVec2 pos, color_t color)
3709 {
3710 if (checkrange) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return; }
3711 _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)] = color;
3712 }
3713
3714 template<bool CHECKRANGE = true> TGX_INLINE inline color_t _readPixel(iVec2 pos, color_t outside_color) const
3715 {
3716 if (CHECKRANGE) { if ((pos.x < 0) || (pos.y < 0) || (pos.x >= _lx) || (pos.y >= _ly)) return outside_color; }
3717 return _buffer[TGX_CAST32(pos.x) + TGX_CAST32(_stride) * TGX_CAST32(pos.y)];
3718 }
3719
3720 template<bool CHECKRANGE> void _drawFastVLine(iVec2 pos, int h, color_t color, float opacity);
3721 template<bool CHECKRANGE> void _drawFastHLine(iVec2 pos, int w, color_t color, float opacity);
3722 template<bool CHECKRANGE> void _drawFastVLine(iVec2 pos, int h, color_t color);
3723 template<bool CHECKRANGE> void _drawFastHLine(iVec2 pos, int w, color_t color);
3724
3725 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); }
3726 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); }
3727 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); }
3728 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); }
3729 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); }
3730
3731
3732 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);
3733
3734 // legacy (not used anymore)
3735 void _drawWedgeLine(float ax, float ay, float bx, float by, float aw, float bw, color_t color, float opacity);
3736 float _wedgeLineDistance(float pax, float pay, float bax, float bay, float dr);
3737
3738
3739
3740
3741 /***************************************
3742 * RECT AND ROUNDED RECT
3743 ****************************************/
3744
3745
3746 // low quality drawing
3747 void _fillRect(iBox2 B, color_t color, float opacity);
3748 template<bool CHECKRANGE> void _drawRoundRect(int x, int y, int w, int h, int r, color_t color);
3749 template<bool CHECKRANGE> void _drawRoundRect(int x, int y, int w, int h, int r, color_t color, float opacity);
3750 template<bool CHECKRANGE> void _fillRoundRect(int x, int y, int w, int h, int r, color_t color);
3751 template<bool CHECKRANGE> void _fillRoundRect(int x, int y, int w, int h, int r, color_t color, float opacity);
3752
3753
3754 // high quality drawing
3755 void _fillSmoothRect(const fBox2& B, color_t color, float opacity);
3756 void _fillSmoothRoundedRect(const tgx::iBox2& B, float corner_radius, color_t color, float opacity);
3757 void _drawSmoothRoundRect(const tgx::iBox2& B, float corner_radius, color_t color, float opacity);
3758 void _drawSmoothWideRoundRect(const tgx::iBox2& B, float corner_radius, float thickness, color_t color, float opacity);
3759
3760
3761
3762 /***************************************
3763 * TRIANGLES
3764 ****************************************/
3765
3766
3767 // methods using the 3D triangle rasterizer
3768 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
3769 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
3770
3771 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);
3772 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);
3773
3774
3775
3776 /***************************************
3777 * QUADS
3778 ****************************************/
3779
3780
3781
3782 /***************************************
3783 * POLYGONS AND POLYLINES
3784 ****************************************/
3785
3786
3787
3788 /***************************************
3789 * CIRCLES, ARC AND PIES
3790 ****************************************/
3791
3792
3793 // low quality drawing for circles
3794 template<bool CHECKRANGE> void _drawCircleHelper(int x0, int y0, int r, int cornername, color_t color, float opacity); // adapted from Adafruit GFX library
3795 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
3796 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
3797
3798
3799 // high quality drawing for circle, arc and pie
3800 static float _rectifyAngle(float a);
3801 static void _defaultQuarterVH(int quarter, int& v, int& h);
3802
3803 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);
3804 void _fillSmoothQuarterCircleInterHP0(int quarter, tgx::fVec2 C, float R, color_t color, float opacity);
3805 void _fillSmoothQuarterCircleInterHP1(int quarter, tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg1, int side1);
3806 void _fillSmoothQuarterCircleInterHP2(int quarter, tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg1, int side1, const BSeg& seg2, int side2);
3807 void _fillSmoothCircleInterHP(tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg, int side); // used to draw rounded ends
3808
3809 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);
3810 void _drawSmoothQuarterCircleInterHP0(int quarter, tgx::fVec2 C, float R, color_t color, float opacity);
3811 void _drawSmoothQuarterCircleInterHP1(int quarter, tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg1, int side1);
3812 void _drawSmoothQuarterCircleInterHP2(int quarter, tgx::fVec2 C, float R, color_t color, float opacity, const BSeg& seg1, int side1, const BSeg& seg2, int side2);
3813
3814 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);
3815 void _drawSmoothThickQuarterCircleInterHP0(int quarter, tgx::fVec2 C, float R, float thickness, color_t color, float opacity);
3816 void _drawSmoothThickQuarterCircleInterHP1(int quarter, tgx::fVec2 C, float R, float thickness, color_t color, float opacity, const BSeg& seg1, int side1);
3817 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);
3818
3819 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);
3820 void _fillSmoothThickQuarterCircleInterHP0(int quarter, tgx::fVec2 C, float R, float thickness, color_t color_interior, color_t color_border, float opacity);
3821 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);
3822 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);
3823
3824
3825
3826 /***************************************
3827 * ELLIPSES
3828 ****************************************/
3829
3830
3831 // low quality drawing for ellipses
3832 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
3833
3834 // high quality drawing for ellipses
3835 void _drawSmoothQuarterEllipse(tgx::fVec2 C, float rx, float ry, int quarter, bool vertical_center_line, bool horizontal_center_line, color_t color, float opacity);
3836 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);
3837 void _fillSmoothQuarterEllipse(tgx::fVec2 C, float rx, float ry, int quarter, bool vertical_center_line, bool horizontal_center_line, color_t color, float opacity);
3838 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);
3839
3840
3841
3842 /***************************************
3843 * DRAWING BEZIER
3844 ****************************************/
3845
3846
3847 // low quality Bezier curves
3848 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);
3849 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);
3850 void _drawQuadBezier(iVec2 P1, iVec2 P2, iVec2 PC, float wc, bool drawP2, color_t color, float opacity);
3851
3852 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);
3853 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);
3854 void _drawCubicBezier(iVec2 P1, iVec2 P2, iVec2 PA, iVec2 PB, bool drawP2, color_t color, float opacity);
3855
3856 void _plotQuadSpline(int n, int x[], int y[], bool draw_last, const color_t color, const float opacity);
3857 template<int SPLINE_MAX_POINTS> void _drawQuadSpline(int nbpoints, const iVec2* tabPoints, bool draw_last_point, color_t color, float opacity);
3858
3859 void _plotClosedSpline(int n, int x[], int y[], const color_t color, const float opacity);
3860 template<int SPLINE_MAX_POINTS> void _drawClosedSpline(int nbpoints, const iVec2* tabPoints, color_t color, float opacity);
3861
3862 void _plotCubicSpline(int n, int x[], int y[], bool draw_last, const color_t color, const float opacity);
3863 template<int SPLINE_MAX_POINTS> void _drawCubicSpline(int nbpoints, const iVec2* tabPoints, bool draw_last_point, color_t color, float opacity);
3864
3865
3866
3867 // high quality Bezier curves
3868 static bool _splitRationalQuadBezier(fVec2 P1, fVec2 P2, fVec2 PC, float w, fVec2& Q, fVec2& PB, float& wb);
3869 static bool _splitCubicBezier(fVec2 P1, fVec2 P2, fVec2 PPC1, fVec2 PPC2, fVec2& Q, fVec2& C, fVec2 & D);
3870
3871
3872
3873 /***************************************
3874 * DRAWING TEXT
3875 ****************************************/
3876
3877 bool _clipit(int& x, int& y, int& sx, int& sy, int& b_left, int& b_up);
3878
3879 template<bool BLEND> iVec2 _drawCharGFX(char c, iVec2 pos, color_t col, const GFXfont& font, float opacity);
3880 template<bool BLEND> iVec2 _drawCharILI(char c, iVec2 pos, color_t col, const ILI9341_t3_font_t& font, float opacity);
3881
3882 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);
3883 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);
3884
3885 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);
3886 template<bool BLEND> static void _drawcharline(const uint8_t* bitmap, int32_t off, color_t* p, int dx, color_t col, float opacity);
3887 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);
3888 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);
3889 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);
3890 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);
3891
3892 template<bool BLEND> static TGX_INLINE inline void _drawFontPixel(color_t* p, color_t col, uint32_t alpha256)
3893 {
3894 if (BLEND)
3895 {
3896 p->blend256(col, alpha256);
3897 }
3898 else if (alpha256 >= 256)
3899 {
3900 *p = col;
3901 }
3902 else if (alpha256 > 0)
3903 {
3904 p->blend256(col, alpha256);
3905 }
3906 }
3907
3908
3909
3910
3911 /************************************************************************************************************
3912 *
3913 * Image members variables (16 bytes).
3914 *
3915 *************************************************************************************************************/
3916
3917 color_t* _buffer; // pointer to the pixel buffer - nullptr if the image is invalid.
3918 int _lx, _ly; // image size - (0,0) if the image is invalid
3919 int _stride; // image stride - 0 if the image is invalid
3920
3921
3922 };
3923
3924
3925
3926}
3927
3928
3929
3930
3931#include "Image.inl"
3932
3933
3934#endif
3935
3936#endif
3937
Box2.h
2D box class
tgx::Anchor
Anchor
Define the placement of an anchor point inside a box.
Definition: Box2.h:74
Color.h
Color classes [RGB565, RGB24, RGB32, RGB64, RGBf, HSV].
Fonts.h
Define the GFXFont anf ILI9341_t3 font format if needed.
tgx::EndPath
EndPath
Enumeration of end path shapes.
Definition: Image.h:51
tgx::END_ARROW_SKEWED_1
@ END_ARROW_SKEWED_1
tiny skewed arrow head [extends = line thickness]
Definition: Image.h:59
tgx::END_ARROW_SKEWED_4
@ END_ARROW_SKEWED_4
large skewed arrow head [extends = 4 x line thickness]
Definition: Image.h:62
tgx::END_ARROW_3
@ END_ARROW_3
medium arrow head [extends = 3 x line thickness]
Definition: Image.h:56
tgx::END_ROUNDED
@ END_ROUNDED
rounded end.
Definition: Image.h:53
tgx::END_ARROW_5
@ END_ARROW_5
huge arrow head [extends = 5 x line thickness]
Definition: Image.h:58
tgx::END_ARROW_SKEWED_3
@ END_ARROW_SKEWED_3
medium skewed arrow head [extends = 3 x line thickness]
Definition: Image.h:61
tgx::END_STRAIGHT
@ END_STRAIGHT
straight end.
Definition: Image.h:52
tgx::END_ARROW_SKEWED_2
@ END_ARROW_SKEWED_2
small skewed arrow head [extends = 2 x line thickness]
Definition: Image.h:60
tgx::END_ARROW_1
@ END_ARROW_1
tiny arrow head [extends = line thickness]
Definition: Image.h:54
tgx::END_ARROW_SKEWED_5
@ END_ARROW_SKEWED_5
huge skewed arrow head [extends = 5 x line thickness]
Definition: Image.h:63
tgx::END_ARROW_4
@ END_ARROW_4
large arrow head [extends = 4 x line thickness]
Definition: Image.h:57
tgx::END_ARROW_2
@ END_ARROW_2
small arrow head [extends = 2 x line thickness]
Definition: Image.h:55
Misc.h
Utility/miscellaneous functions used throughout the library.
tgx::min
TGX_INLINE T min(const T &a, const T &b)
Don't know why but faster than fminf() for floats.
Definition: Misc.h:149
tgx::max
TGX_INLINE T max(const T &a, const T &b)
Don't know why but much faster than fmaxf() for floats.
Definition: Misc.h:153
Rasterizer.h
3D triangle rasterizer function.
ShaderParams.h
Triangle shader parameters.
Shaders.h
Triangle shader functions.
Vec2.h
2D vector.
tgx::iVec2
Vec2< int > iVec2
Integer-valued 2D vector.
Definition: Vec2.h:47
Vec3.h
3D vector.
Vec4.h
4D vector.
tgx::Image
Image class [MAIN CLASS FOR THE 2D API].
Definition: Image.h:145
tgx::Image::drawLineAA
void drawLineAA(fVec2 P1, fVec2 P2, color_t color, float opacity=1.0f)
Draw a line segment between two points [High quality].
tgx::Image::iterate
void iterate(ITERFUN cb_fun, tgx::iBox2 B) const
Iterate over the pixel of the image inside a given region.
tgx::Image::drawText
iVec2 drawText(const char *text, iVec2 pos, const GFXfont &font, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a text at a given position with a given font.
tgx::Image::height
TGX_INLINE int height() const
Return the image height.
Definition: Image.h:372
tgx::Image::drawPolygonAA
void drawPolygonAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity=1.0f)
Draw a closed polygon with vertices [P0, P1, ..., PN] (High quality).
tgx::Image::drawTexturedTriangle
void drawTexturedTriangle(const Image< color_t_tex > &src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, const BLEND_OPERATOR &blend_op)
Blend a textured triangle onto the image.
tgx::Image::fillThickRectAA
void fillThickRectAA(const fBox2 &B, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled rectangle with a thick border of a different color [High quality].
tgx::Image::stride
TGX_INLINE int stride() const
Return the image stride.
Definition: Image.h:388
tgx::Image::PNGDecode
int PNGDecode(PNG_T &png, iVec2 topleft=iVec2(0, 0), float opacity=1.0f)
Decode a PNG image into this image using the PNGDec library: https://github.com/bitbank2/PNGdec/.
tgx::Image::drawText
iVec2 drawText(const char *text, iVec2 pos, const ILI9341_t3_font_t &font, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a text at a given position with a given font.
tgx::Image::drawThickPolygonAA
void drawThickPolygonAA(FUNCTOR_NEXT next_point, float thickness, color_t color, float opacity=1.0f)
Draw a polygon with thick lines (High quality).
tgx::Image::operator()
TGX_INLINE const color_t & operator()(iVec2 pos) const
Get a reference to a pixel (no range check!)
Definition: Image.h:537
tgx::Image::set
void set(T *buffer, int lx, int ly, int stride=DEFAULT_STRIDE)
Set/update the image parameters.
tgx::Image::drawRect
void drawRect(const iBox2 &B, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a rectangle.
tgx::Image::data
TGX_INLINE const color_t * data() const
Return a pointer to the pixel buffer.
Definition: Image.h:414
tgx::Image::drawThickClosedSplineAA
void drawThickClosedSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a thick closed quadratic spline interpolating between a given set of points (high quality).
tgx::Image::iterate
void iterate(ITERFUN cb_fun)
Iterate over all the pixels of the image.
tgx::Image::drawCircle
void drawCircle(iVec2 center, int r, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a circle.
tgx::Image::fill
int fill(iVec2 start_pos, color_t new_color)
'Flood fill' a 4-connected region of the image.
tgx::Image::fillThickEllipseAA
void fillThickEllipseAA(fVec2 center, fVec2 radiuses, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled ellipse with a thick border of a different color (high quality).
tgx::Image::Image
Image(const Image< color_t > &im)=default
Default copy constructor.
tgx::Image::fillRectAA
void fillRectAA(const fBox2 &B, color_t color, float opacity=1.0f)
Draw a filled rectangle [High quality].
tgx::Image::readPixel
TGX_INLINE color_t readPixel(iVec2 pos, color_t outside_color=color_t()) const
Return the color of a pixel at a given position.
Definition: Image.h:510
tgx::Image::fillCircleSectorAA
void fillCircleSectorAA(fVec2 center, float r, float angle_start, float angle_end, color_t color, float opacity=1.0f)
Draw a filled circle sector/slice/pie (high quality).
tgx::Image::drawThickRect
void drawThickRect(const iBox2 &B, int thickness, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a rectangle with a thick outline.
tgx::Image::drawFastVLine
void drawFastVLine(iVec2 pos, int h, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a vertical segment of h pixels starting at pos.
tgx::Image::drawPolyline
void drawPolyline(FUNCTOR_NEXT next_point, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a polyline ie a sequence of consecutive segments [P0,P1] , [P1,P2],,, [Pn-1,Pn].
tgx::Image::drawThickRectAA
void drawThickRectAA(const fBox2 &B, float thickness, color_t color, float opacity=1.0f)
Draw a filled rectangle with a thick border [High quality].
tgx::Image::crop
void crop(const iBox2 &subbox)
Crop the image.
tgx::Image::Image
Image(T *buffer, iVec2 dim, int stride=DEFAULT_STRIDE)
Constructor.
tgx::Image::copyFrom
void copyFrom(const Image< src_color_t > &src_im, const BLEND_OPERATOR &blend_op)
Blend the src image onto the destination image with resizing and color conversion.
tgx::Image::drawFastHLine
void drawFastHLine(iVec2 pos, int w, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a horizontal segment of w pixels starting at pos.
tgx::Image::Image
Image(T *buffer, int lx, int ly, int stride=DEFAULT_STRIDE)
Constructor.
tgx::Image::iterate
void iterate(ITERFUN cb_fun) const
Iterate over all the pixels of the image.
tgx::Image::fillThickPolygonAA
void fillThickPolygonAA(FUNCTOR_NEXT next_point, float thickness, color_t interior_color, color_t border_color, float opacity=1.0f)
Draw a filled polygon with a thick border of a different color (High quality).
tgx::Image::drawClosedSpline
void drawClosedSpline(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a closed quadratic spline interpolating between a given set of points.
tgx::Image::fillRoundRectAA
void fillRoundRectAA(const fBox2 &B, float corner_radius, color_t color, float opacity=1.0f)
Draw a filled rounded rectangle [High quality].
tgx::Image::drawThickCubicBezierAA
void drawThickCubicBezierAA(fVec2 P1, fVec2 P2, fVec2 PA, fVec2 PB, float thickness, EndPath end_P1, EndPath end_P2, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a thick cubic Bezier curve (high quality).
tgx::Image::drawEllipse
void drawEllipse(iVec2 center, iVec2 radiuses, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw an ellipse.
tgx::Image::setInvalid
void setInvalid()
Set the image as invalid.
tgx::Image::operator()
TGX_INLINE color_t & operator()(int x, int y)
Get a reference to a pixel (no range check!)
Definition: Image.h:574
tgx::Image::drawTexturedGradientMaskedTriangle
void drawTexturedGradientMaskedTriangle(const Image< color_t_tex > &src_im, color_t_tex transparent_color, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, color_t_tex C1, color_t_tex C2, color_t_tex C3, float opacity=1.0f)
Blend textured triangle with a transparency mask (ie a specific color is treated as fully transparent...
tgx::Image::fillRectHGradient
void fillRectHGradient(iBox2 B, color_t color_left, color_t color_right, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a rectangle filled with a horizontal gradient of colors.
tgx::Image::setOpenFontRender
void setOpenFontRender(T &ofr, float opacity=TGX_DEFAULT_NO_BLENDING)
Link the image with Takkoa's OpenFontRender library : https://github.com/takkaO/OpenFontRender.
Definition: Image.h:3441
tgx::Image::fillThickCircleSectorAA
void fillThickCircleSectorAA(fVec2 center, float r, float angle_start, float angle_end, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled circle sector/slice/pie with a thick border of a different color (high quality).
tgx::Image::drawTexturedGradientMaskedQuad
void drawTexturedGradientMaskedQuad(const Image< color_t_tex > &src_im, color_t_tex transparent_color, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, color_t_tex C1, color_t_tex C2, color_t_tex C3, color_t_tex C4, float opacity=1.0f)
Draw a textured quad using bilinear filtering and with a mask (ie a fixed transparent color) and comb...
tgx::Image::drawTexturedGradientTriangle
void drawTexturedGradientTriangle(const Image< color_t_tex > &src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, color_t_tex C1, color_t_tex C2, color_t_tex C3, float opacity=TGX_DEFAULT_NO_BLENDING)
Blend textured triangle on the image while combining it with a color gradient.
tgx::Image::drawThickCircleArcAA
void drawThickCircleArcAA(fVec2 center, float r, float angle_start, float angle_end, float thickness, color_t color, float opacity=1.0f)
Draw a circle arc with a thick border (high quality).
tgx::Image::drawTexturedGradientQuad
void drawTexturedGradientQuad(const Image< color_t_tex > &src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, color_t_tex C1, color_t_tex C2, color_t_tex C3, color_t_tex C4, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a textured quad using bilinear filtering combined with a color gradient.
tgx::Image::drawTexturedQuad
void drawTexturedQuad(const Image< color_t_tex > &src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, const BLEND_OPERATOR &blend_op)
Draw a textured quad with bilinear filtering and a custom blending operator.
tgx::Image::drawPixelf
TGX_INLINE void drawPixelf(fVec2 pos, color_t color, float opacity)
Blend a pixel with the current pixel color (floating point coord).
Definition: Image.h:497
tgx::Image::operator()
TGX_INLINE color_t & operator()(iVec2 pos)
Get a reference to a pixel (no range check!)
Definition: Image.h:548
tgx::Image::Image
Image()
Default constructor.
tgx::Image::drawLine
void drawLine(iVec2 P1, iVec2 P2, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a line segment between two points (uses Bresenham's algorithm).
tgx::Image::drawRoundRectAA
void drawRoundRectAA(const fBox2 &B, float corner_radius, color_t color, float opacity=1.0f)
Draw a rounded rectangle [High quality].
tgx::Image::width
TGX_INLINE int width() const
Return the image width.
Definition: Image.h:356
tgx::Image::operator()
Image< color_t > operator()(const iBox2 &B) const
Return a sub-image of this image (sharing the same pixel buffer).
tgx::Image::getCrop
Image< color_t > getCrop(const iBox2 &subbox) const
Return a sub-image of this image (sharing the same pixel buffer).
tgx::Image::blitMasked
void blitMasked(const Image< color_t > &sprite, color_t transparent_color, iVec2 upperleftpos, float opacity=1.0f)
Blend a sprite at a given position on this image with a given mask.
tgx::Image::fillQuad
void fillQuad(iVec2 P1, iVec2 P2, iVec2 P3, iVec2 P4, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
draw a filled quad.
tgx::Image::drawTextEx
iVec2 drawTextEx(const char *text, iVec2 pos, const GFXfont &font, Anchor anchor, bool wrap_text, bool start_newline_at_0, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Advanced drawText method.
tgx::Image::fillRectVGradient
void fillRectVGradient(iBox2 B, color_t color_top, color_t color_bottom, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a rectangle filled with a vertical gradient of colors.
tgx::Image::drawPolylineAA
void drawPolylineAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity=1.0f)
Draw a polyline ie a sequence of consecutive segments [P0,P1] , [P1,P2],,, [Pn-1,Pn] (High quality).
tgx::Image::drawTexturedMaskedTriangle
void drawTexturedMaskedTriangle(const Image< color_t_tex > &src_im, color_t_tex transparent_color, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, float opacity=1.0f)
Blend textured triangle with a transparency mask (ie a specific color is treated as fully transparent...
tgx::Image::drawQuad
void drawQuad(iVec2 P1, iVec2 P2, iVec2 P3, iVec2 P4, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a quad.
tgx::Image::drawPixel
TGX_INLINE void drawPixel(iVec2 pos, color_t color, float opacity)
Blend a pixel with the current pixel color.
Definition: Image.h:481
tgx::Image::blitRotated
void blitRotated(const Image< color_t_src > &sprite, iVec2 upperleftpos, int angle, const BLEND_OPERATOR &blend_op)
Blend a rotated sprite over this image at a given position using a custom blending operator.
tgx::Image::isValid
TGX_INLINE bool isValid() const
Query if the image is valid.
Definition: Image.h:340
tgx::Image::blit
void blit(const Image< color_t > &sprite, iVec2 upperleftpos, float opacity=TGX_DEFAULT_NO_BLENDING)
Blit/blend a sprite over this image at a given position.
tgx::Image::fillRoundRect
void fillRoundRect(const iBox2 &B, int corner_radius, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled rounded rectangle in box B with radius corner_radius.
tgx::Image::fillPolygon
void fillPolygon(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled polygon with vertices [P0, P1, ..., PN].
tgx::Image::drawPolygon
void drawPolygon(FUNCTOR_NEXT next_point, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a closed polygon with vertices [P0, P1, ..., PN].
tgx::Image::fillScreenVGradient
void fillScreenVGradient(color_t top_color, color_t bottom_color)
Fill the whole image with a vertical color gradient between two colors.
tgx::Image::measureText
iBox2 measureText(const char *text, iVec2 pos, const ILI9341_t3_font_t &font, Anchor anchor=DEFAULT_TEXT_ANCHOR, bool wrap_text=false, bool start_newline_at_0=false) const
Compute the bounding box of a text.
tgx::Image::drawThickLineAA
void drawThickLineAA(fVec2 P1, fVec2 P2, float line_width, EndPath end_P1, EndPath end_P2, color_t color, float opacity=1.0f)
Draw a thick line segment between two points [High quality].
tgx::Image::operator()
TGX_INLINE const color_t & operator()(int x, int y) const
Get a reference to a pixel (no range check!)
Definition: Image.h:561
tgx::Image::fillEllipse
void fillEllipse(iVec2 center, iVec2 radiuses, color_t interior_color, color_t outline_color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled ellipse with different colors for the outline and the interior.
tgx::Image::drawPixel
TGX_INLINE void drawPixel(iVec2 pos, color_t color)
Set a pixel at a given position.
Definition: Image.h:455
tgx::Image::dim
TGX_INLINE iVec2 dim() const
Return the image dimensions as an iVec2.
Definition: Image.h:396
tgx::Image::fontHeight
int fontHeight(const GFXfont &font) const
Query the height of a font.
tgx::Image::clear
void clear(color_t color)
Fill the whole image with a single color.
tgx::Image::fillThickRect
void fillThickRect(const iBox2 &B, int thickness, color_t color_interior, color_t color_border, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled rectangle with a thick border of a possibly different color.
tgx::Image::drawThickRoundRectAA
void drawThickRoundRectAA(const fBox2 &B, float corner_radius, float thickness, color_t color, float opacity=1.0f)
Draw a rounded rectangle with a thick border [High quality].
tgx::Image::drawThickQuadAA
void drawThickQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, float thickness, color_t color, float opacity=1.0f)
Draw a quad with a thick border [High quality].
tgx::Image::data
TGX_INLINE color_t * data()
Return a pointer to the pixel buffer.
Definition: Image.h:424
tgx::Image::drawPolygonAA
void drawPolygonAA(FUNCTOR_NEXT next_point, color_t color, float opacity=1.0f)
Draw a closed polygon with vertices [P0, P1, ..., PN] (High quality).
tgx::Image::drawGradientQuad
void drawGradientQuad(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, color_alt colorP1, color_alt colorP2, color_alt colorP3, color_alt colorP4, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a quad with a gradient color specified by the color at the four vertices.
tgx::Image::fillCircle
void fillCircle(iVec2 center, int r, color_t interior_color, color_t outline_color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled circle with different colors for outline and interior.
tgx::Image::imageBox
TGX_INLINE iBox2 imageBox() const
Return the image dimension as a box.
Definition: Image.h:404
tgx::Image::drawPolylineAA
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).
tgx::Image::fillRect
void fillRect(const iBox2 &B, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled rectangle.
tgx::Image::set
void set(T *buffer, iVec2 dim, int stride=DEFAULT_STRIDE)
Set/update the image parameters.
tgx::Image::blitScaledRotated
void blitScaledRotated(const Image< color_t_src > &src_im, fVec2 anchor_src, fVec2 anchor_dst, float scale=1.0f, float angle_degrees=0.0f, float opacity=TGX_DEFAULT_NO_BLENDING)
Blit/blend a sprite onto this image after rescaling and rotation.
tgx::Image::drawRoundRect
void drawRoundRect(const iBox2 &B, int corner_radius, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a rounded rectangle in box B with radius corner_radius.
tgx::Image::drawThickCircleAA
void drawThickCircleAA(fVec2 center, float r, float thickness, color_t color, float opacity=1.0f)
Draw a circle with a thick border (high quality).
tgx::Image::drawPolyline
void drawPolyline(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a polyline ie a sequence of consecutive segments [P0,P1] , [P1,P2],,, [Pn-1,Pn].
tgx::Image::drawThickQuadSplineAA
void drawThickQuadSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a thick quadratic spline interpolating between a given set of points (high quality).
tgx::Image::fillScreenHGradient
void fillScreenHGradient(color_t left_color, color_t right_color)
Fill the whole screen with a horizontal color gradient between two colors.
tgx::Image::convert
Image< color_dst > convert()
Convert this image to another type.
tgx::Image::drawCircleArcAA
void drawCircleArcAA(fVec2 center, float r, float angle_start, float angle_end, color_t color, float opacity=1.0f)
Draw a circle arc (high quality).
tgx::Image::lx
TGX_INLINE int lx() const
Return the image width.
Definition: Image.h:364
tgx::Image::drawTriangleAA
void drawTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, color_t color, float opacity=1.0f)
Draw a triangle [High quality].
tgx::Image::ly
TGX_INLINE int ly() const
Return the image height.
Definition: Image.h:380
tgx::Image::fill
int fill(iVec2 start_pos, color_t border_color, color_t new_color)
'Flood fill' a 4-connected region of the image.
tgx::Image::measureChar
iBox2 measureChar(char c, iVec2 pos, const GFXfont &font, Anchor anchor=DEFAULT_TEXT_ANCHOR, int *xadvance=nullptr) const
Compute the bounding box of a character.
tgx::Image::copyFrom
void copyFrom(const Image< src_color_t > &src_im, float opacity=TGX_DEFAULT_NO_BLENDING)
Copy (or blend) the src image onto the destination image with resizing and color conversion.
tgx::Image::drawTextEx
iVec2 drawTextEx(const char *text, iVec2 pos, const ILI9341_t3_font_t &font, Anchor anchor, bool wrap_text, bool start_newline_at_0, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Advanced drawText method.
tgx::Image::drawThickPolylineAA
void drawThickPolylineAA(FUNCTOR_NEXT next_point, float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity=1.0f)
Draw a thick polyline ie a sequence of consecutive thick segments [P0,P1] , [P1,P2],...
tgx::Image::blit
void blit(const Image< color_t_src > &sprite, iVec2 upperleftpos, const BLEND_OPERATOR &blend_op)
Blend a sprite at a given position on the image using a custom blending operator.
tgx::Image::drawTexturedMaskedQuad
void drawTexturedMaskedQuad(const Image< color_t_tex > &src_im, color_t_tex transparent_color, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, float opacity=1.0f)
Draw a textured quad using bilinear filtering and with a mask (ie a fixed transparent color).
tgx::Image::drawThickPolygonAA
void drawThickPolygonAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t color, float opacity=1.0f)
Draw a polygon with thick lines (High quality).
tgx::Image::fillScreen
void fillScreen(color_t color)
Fill the whole image with a single color.
tgx::Image::copyReduceHalf
Image< color_t > copyReduceHalf(const Image< color_t > &src_image)
Copy the source image pixels into this image, reducing it by half in the process.
tgx::Image::blitBackward
void blitBackward(Image< color_t > &dst_sprite, iVec2 upperleftpos) const
Reverse blitting.
tgx::Image::drawWedgeLineAA
void drawWedgeLineAA(fVec2 P1, fVec2 P2, float line_width_P1, EndPath end_P1, float line_width_P2, EndPath end_P2, color_t color, float opacity=1.0f)
Draw a from P1 to P2 with with respective wideness line_width_P1 and line_width_P2 at both ends [High...
tgx::Image::fillThickQuadAA
void fillThickQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled quad with a thick border of a different color [High quality].
tgx::Image::drawTexturedQuad
void drawTexturedQuad(const Image< color_t_tex > &src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 srcP4, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, fVec2 dstP4, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a textured quad using bilinear filtering.
tgx::Image::fillPolygon
void fillPolygon(FUNCTOR_NEXT next_point, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled polygon with vertices [P0, P1, ..., PN].
tgx::Image::blitScaledRotatedMasked
void blitScaledRotatedMasked(const Image< color_t_src > &src_im, color_t_src transparent_color, fVec2 anchor_src, fVec2 anchor_dst, float scale, float angle_degrees, float opacity=1.0f)
Blend a sprite onto this image after rescaling and rotation and use a given color which is treated as...
tgx::Image::drawEllipseAA
void drawEllipseAA(fVec2 center, fVec2 radiuses, color_t color, float opacity=1.0f)
Draw an ellipse (high quality).
tgx::Image::Image
Image(const Image< color_t > &im, iBox2 subbox)
Constructor.
tgx::Image::fillThickClosedSplineAA
void fillThickClosedSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t color_interior, color_t color_border, float opacity=TGX_DEFAULT_NO_BLENDING)
Fill a region delimited by a closed thick quadratic spline where the interior and boundary can have d...
tgx::Image::fillQuadAA
void fillQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, color_t color, float opacity=1.0f)
Draw a filled quad [High quality].
tgx::Image::drawThickQuadBezierAA
void drawThickQuadBezierAA(fVec2 P1, fVec2 P2, fVec2 PC, float wc, float thickness, EndPath end_P1, EndPath end_P2, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a thick quadratic (rational) Bezier curve (high quality).
tgx::Image::measureText
iBox2 measureText(const char *text, iVec2 pos, const GFXfont &font, Anchor anchor=DEFAULT_TEXT_ANCHOR, bool wrap_text=false, bool start_newline_at_0=false) const
Compute the bounding box of a text.
tgx::Image::drawThickPolylineAA
void drawThickPolylineAA(int nbpoints, const fVec2 tabPoints[], float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity=1.0f)
Draw a thick polyline ie a sequence of consecutive thick segments [P0,P1] , [P1,P2],...
tgx::Image::blitScaledRotated
void blitScaledRotated(const Image< color_t_src > &src_im, fVec2 anchor_src, fVec2 anchor_dst, float scale, float angle_degrees, const BLEND_OPERATOR &blend_op)
Blend a sprite onto this image after rescaling and rotation using a custom blending operator.
tgx::Image::drawThickTriangleAA
void drawThickTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, float thickness, color_t color, float opacity=1.0f)
Draw a triangle with a thick border [High quality].
tgx::Image::readPixelf
TGX_INLINE color_t readPixelf(fVec2 pos, color_t outside_color=color_t()) const
Return the color of a pixel at a given position (floating point coord).
Definition: Image.h:525
tgx::Image::fillPolygonAA
void fillPolygonAA(FUNCTOR_NEXT next_point, color_t color, float opacity=1.0f)
Draw a filled polygon (High quality).
tgx::Image::operator()
Image< color_t > operator()(int min_x, int max_x, int min_y, int max_y) const
Return a sub-image of this image (sharing the same pixel buffer).
tgx::Image::drawCubicBezier
void drawCubicBezier(iVec2 P1, iVec2 P2, iVec2 PA, iVec2 PB, bool drawP2, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a cubic Bezier curve.
tgx::Image::measureChar
iBox2 measureChar(char c, iVec2 pos, const ILI9341_t3_font_t &font, Anchor anchor=DEFAULT_TEXT_ANCHOR, int *xadvance=nullptr) const
Compute the bounding box of a character.
tgx::Image::drawThickCubicSplineAA
void drawThickCubicSplineAA(int nbpoints, const fVec2 tabPoints[], float thickness, EndPath end_P0, EndPath end_Pn, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a thick cubic spline interpolating between a given set of points (high quality).
tgx::Image::fillTriangleAA
void fillTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, color_t color, float opacity=1.0f)
Draw a filled triangle [High quality].
tgx::Image::fillEllipseAA
void fillEllipseAA(fVec2 center, fVec2 radiuses, color_t color, float opacity=1.0f)
Draw a filled ellipse (high quality).
tgx::Image::drawTriangle
void drawTriangle(const iVec2 &P1, const iVec2 &P2, const iVec2 &P3, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a triangle.
tgx::Image::drawPolygon
void drawPolygon(int nbpoints, const iVec2 tabPoints[], color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a closed polygon with vertices [P0, P1, ..., PN].
tgx::Image::fillThickTriangleAA
void fillThickTriangleAA(fVec2 P1, fVec2 P2, fVec2 P3, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled triangle with a thick border of a different color [High quality].
tgx::Image::drawGradientTriangle
void drawGradientTriangle(fVec2 P1, fVec2 P2, fVec2 P3, color_alt colorP1, color_alt colorP2, color_alt colorP3, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a triangle with gradient color specified by the colors on its vertices.
tgx::Image::drawChar
iVec2 drawChar(char c, iVec2 pos, const GFXfont &font, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a single character at position pos on the image and return the position for the next character.
tgx::Image::drawCubicSpline
void drawCubicSpline(int nbpoints, const iVec2 tabPoints[], bool draw_last_point, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a cubic spline interpolating between a given set of points.
tgx::Image::fillThickCircleAA
void fillThickCircleAA(fVec2 center, float r, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled circle with a thick border of a different color (high quality).
tgx::Image::fillClosedSplineAA
void fillClosedSplineAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Fill a region delimited by a closed quadratic spline (high quality).
tgx::Image::fillTriangle
void fillTriangle(const iVec2 &P1, const iVec2 &P2, const iVec2 &P3, color_t interior_color, color_t outline_color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a filled triangle with different colors for the outline and the interior.
tgx::Image::drawQuadBezier
void drawQuadBezier(iVec2 P1, iVec2 P2, iVec2 PC, float wc, bool drawP2, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a quadratic (rational) Bezier curve.
tgx::Image::fillCircleAA
void fillCircleAA(fVec2 center, float r, color_t color, float opacity=1.0f)
Draw a filled circle (high quality).
tgx::Image::drawQuadAA
void drawQuadAA(fVec2 P1, fVec2 P2, fVec2 P3, fVec2 P4, color_t color, float opacity=1.0f)
Draw a quad [High quality].
tgx::Image::fillThickRoundRectAA
void fillThickRoundRectAA(const fBox2 &B, float corner_radius, float thickness, color_t color_interior, color_t color_border, float opacity=1.0f)
Draw a filled rounded rectangle with a thick border of another color [High quality].
tgx::Image::blitRotated
void blitRotated(const Image< color_t > &sprite, iVec2 upperleftpos, int angle, float opacity=TGX_DEFAULT_NO_BLENDING)
Blit/blend a rotated sprite over this image at a given position.
tgx::Image::drawCircleAA
void drawCircleAA(fVec2 center, float r, color_t color, float opacity=1.0f)
Draw a circle (high quality).
tgx::Image::JPEGDecode
int JPEGDecode(JPEG_T &jpeg, iVec2 topleft=iVec2(0, 0), int options=0, float opacity=1.0f)
Decode a JPEG image into this image using the JPEGDEC library: https://github.com/bitbank2/JPEGDEC/.
tgx::Image::drawSegment
void drawSegment(iVec2 P1, bool drawP1, iVec2 P2, bool drawP2, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a line segment between two points (using Bresenham's algorithm).
tgx::Image::fillPolygonAA
void fillPolygonAA(int nbpoints, const fVec2 tabPoints[], color_t color, float opacity=1.0f)
Draw a filled polygon (High quality).
tgx::Image::reduceHalf
Image< color_t > reduceHalf()
Reduce this image by half.
tgx::Image::operator=
Image & operator=(const Image< color_t > &im)=default
Default assignment operator.
tgx::Image::drawPixelf
TGX_INLINE void drawPixelf(fVec2 pos, color_t color)
Set a pixel at a given position (floating point coord).
Definition: Image.h:467
tgx::Image::drawQuadSpline
void drawQuadSpline(int nbpoints, const iVec2 tabPoints[], bool draw_last_point, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a quadratic spline interpolating between a given set of points.
tgx::Image::iterate
void iterate(ITERFUN cb_fun, tgx::iBox2 B)
Iterate over the pixel of the image inside a given region.
tgx::Image::fillThickPolygonAA
void fillThickPolygonAA(int nbpoints, const fVec2 tabPoints[], float thickness, color_t interior_color, color_t border_color, float opacity=1.0f)
Draw a filled polygon with a thick border of a different color (High quality).
tgx::Image::DEFAULT_STRIDE
static const int DEFAULT_STRIDE
If not specified, the stride of an image is equal to its width.
Definition: Image.h:156
tgx::Image::drawTexturedTriangle
void drawTexturedTriangle(const Image< color_t_tex > &src_im, fVec2 srcP1, fVec2 srcP2, fVec2 srcP3, fVec2 dstP1, fVec2 dstP2, fVec2 dstP3, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw textured triangle onto the image.
tgx::Image::GIFplayFrame
int GIFplayFrame(GIF_T &gif, iVec2 topleft=iVec2(0, 0), float opacity=1.0f)
Decode a (possibly animated) GIF image into this image using the AnimatedGIF library: https://github....
tgx::Image::drawThickEllipseAA
void drawThickEllipseAA(fVec2 center, fVec2 radiuses, float thickness, color_t color, float opacity=1.0f)
Draw an ellipse with a thick border (high quality).
tgx::Image::drawChar
iVec2 drawChar(char c, iVec2 pos, const ILI9341_t3_font_t &font, color_t color, float opacity=TGX_DEFAULT_NO_BLENDING)
Draw a single character at position pos on the image and return the position for the next character.
tgx::Image::fontHeight
int fontHeight(const ILI9341_t3_font_t &font) const
Query the height of a font.
GFXfont
GFXFont font format.
Definition: Fonts.h:74
ILI9341_t3_font_t
ILI9341_t3 PJRC font format.
Definition: Fonts.h:105
tgx::Box2
Generic 2D Box [specializations iBox2 , fBox2, dBox2].
Definition: Box2.h:151
tgx::RGB565
Color in R5/G6/B5 format.
Definition: Color.h:216
tgx::Vec2
Generic 2D vector [specializations iVec2, fVec2, dVec2].
Definition: Vec2.h:64
tgx::Vec2::x
T x
'x' coordinate (first dimension)
Definition: Vec2.h:72
tgx::Vec2::y
T y
'y' coordinate (second dimension)
Definition: Vec2.h:73
TGX_DEFAULT_NO_BLENDING
#define TGX_DEFAULT_NO_BLENDING
Default opacity sentinel used by drawing primitives to request overwrite/no-blending mode.
Definition: tgx_config.h:268