Select one of the symbols to view example projects that use it.
 
Outline
#include <gui/graph_screen/PainterVerticalAlpha.hpp>
#include <touchgfx/Color.hpp>
PainterVerticalAlpha::PainterVerticalAlpha(colortype, int)
PainterVerticalAlpha::setColor(colortype, int)
PainterVerticalAlpha::renderInit()
PainterVerticalAlpha::render(uint8_t *, int, int, int, unsigned int, const uint8_t *)
PainterVerticalAlpha::renderNext(uint8_t &, uint8_t &, uint8_t &, uint8_t &)
Files
loading...
CodeScopeSTM32 Libraries and SamplesTouchGFXGui/gui/src/graph_screen/PainterVerticalAlpha.cpp
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * This file is part of the TouchGFX 4.10.0 distribution. * * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ #include <gui/graph_screen/PainterVerticalAlpha.hpp> #include <touchgfx/Color.hpp> using namespace touchgfx; PainterVerticalAlpha::PainterVerticalAlpha(colortype color /*= 0*/, int alpha0atY /*= 100*/) { setColor(color, alpha0atY); }{ ... } void PainterVerticalAlpha::setColor(colortype color, int alphaZeroAt) { #if !defined(USE_BPP) || USE_BPP==16 || USE_BPP==24 painterRed = Color::getRedColor(color); painterGreen = Color::getGreenColor(color); painterBlue = Color::getBlueColor(color);/* ... */ #elif USE_BPP==4 || USE_BPP==2 painterGray = (uint8_t)color; #else #error Unknown USE_BPP #endif alpha0atY = alphaZeroAt; }{ ... } bool PainterVerticalAlpha::renderInit() { int gradientAlpha = 255 - (currentY * 255 / alpha0atY); if (gradientAlpha < 0) { gradientAlpha = 0; }if (gradientAlpha < 0) { ... } if (gradientAlpha > 255) { gradientAlpha = 255; }if (gradientAlpha > 255) { ... } painterAlpha = gradientAlpha; return true; }{ ... } void PainterVerticalAlpha::render(uint8_t* ptr, int x, int xAdjust, int y, unsigned count, const uint8_t* covers) { currentY = y + areaOffsetY; renderInit(); // re-use code to set painterAlpha #if !defined(USE_BPP) || USE_BPP==16 || USE_BPP==24 #if !defined(USE_BPP) || USE_BPP==16 uint16_t* p = reinterpret_cast<uint16_t*>(ptr) + (x + xAdjust); currentX = x + areaOffsetX; // CurrentX is not used in 24bpp/* ... */ #else uint8_t* p = ptr + ((x + xAdjust) * 3); #endif uint8_t totalAlpha = (widgetAlpha * painterAlpha) / 255u; do { uint32_t combinedAlpha = (*covers) * totalAlpha; covers++; #if !defined(USE_BPP) || USE_BPP==16 uint8_t p_red = (*p & RMASK) >> 8; uint8_t p_green = (*p & GMASK) >> 3; uint8_t p_blue = (*p & BMASK) << 3; uint8_t pixelRed = static_cast<uint8_t>((((painterRed - p_red) * combinedAlpha) >> 16) + p_red); uint8_t pixelGreen = static_cast<uint8_t>((((painterGreen - p_green) * combinedAlpha) >> 16) + p_green); uint8_t pixelBlue = static_cast<uint8_t>((((painterBlue - p_blue) * combinedAlpha) >> 16) + p_blue); #define fastrand(g_seed) ((214013*(uint32_t)(g_seed)+2531011)>>16) uint8_t rand = fastrand((currentX + *p) * (currentY + *p)); if (pixelRed < 0xF8) { pixelRed = pixelRed + ((rand >> 5)); // Add bit 7-5 of rand to red to get rounding }if (pixelRed < 0xF8) { ... } if (pixelGreen < 0xFC) { pixelGreen = pixelGreen + ((rand >> 3) & 0x3); // Add bit 4-3 of rand to green to get rounding }if (pixelGreen < 0xFC) { ... } if (pixelBlue < 0xF8) { pixelBlue = pixelBlue + ((rand) & 0x7); // Add bit 2-0 of rand to blue to get rounding }if (pixelBlue < 0xF8) { ... } *p++ = ((pixelRed << 8) & RMASK) | ((pixelGreen << 3) & GMASK) | ((pixelBlue >> 3) & BMASK); currentX++;/* ... */ #else uint8_t pixelBlue = static_cast<uint8_t>((((painterBlue - *p) * combinedAlpha) >> 16) + *p); *p++ = pixelBlue; uint8_t pixelGreen = static_cast<uint8_t>((((painterGreen - *p) * combinedAlpha) >> 16) + *p); *p++ = pixelGreen; uint8_t pixelRed = static_cast<uint8_t>((((painterRed - *p) * combinedAlpha) >> 16) + *p); *p++ = pixelRed;/* ... */ #endif ...} while (--count != 0);/* ... */ #elif USE_BPP==4 x += xAdjust; uint8_t totalAlpha = (widgetAlpha * painterAlpha) / 255u; do { uint16_t combinedAlpha = (*covers) * totalAlpha; covers++; if (combinedAlpha != 0) { uint8_t p_gray = LCD4getPixel(ptr, x); LCD4setPixel(ptr, x, static_cast<uint8_t>((((painterGray - p_gray) * combinedAlpha) >> 16) + p_gray)); }if (combinedAlpha != 0) { ... } x++; ...} while (--count != 0);/* ... */ #elif USE_BPP==2 x += xAdjust; uint8_t totalAlpha = (widgetAlpha * painterAlpha) / 255u; do { uint8_t combinedAlpha = (*covers) * totalAlpha; covers++; if (combinedAlpha != 0) { uint8_t p_gray = LCD2getPixel(ptr, x); LCD2setPixel(ptr, x, static_cast<uint8_t>((((painterGray - p_gray) * combinedAlpha) >> 16) + p_gray)); }if (combinedAlpha != 0) { ... } x++; ...} while (--count != 0);/* ... */ #else #error Unknown USE_BPP #endif }{ ... } #if !defined(USE_BPP) || USE_BPP==16 || USE_BPP==24 bool PainterVerticalAlpha::renderNext(uint8_t& pixelRed, uint8_t& pixelGreen, uint8_t& pixelBlue, uint8_t& pixelAlpha) { return false; }{ ... } /* ... */#elif USE_BPP==4 || USE_BPP==2 bool PainterVerticalAlpha::renderNext(uint8_t& pixelGray, uint8_t& pixelAlpha) { return false; }renderNext (uint8_t& pixelGray, uint8_t& pixelAlpha) { ... } /* ... */#else #error Unknown USE_BPP #endif