1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** GUIX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** Display Management (Display) */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define GX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
|
27 |
|
|
#include "gx_api.h" |
28 |
|
|
#include "gx_system.h" |
29 |
|
|
#include "gx_utility.h" |
30 |
|
|
#include "gx_display.h" |
31 |
|
|
|
32 |
|
|
#define DRAW_PIXEL if (alpha & mask) \ |
33 |
|
|
{ \ |
34 |
|
|
*put = text_color; \ |
35 |
|
|
} \ |
36 |
|
|
put++; \ |
37 |
|
|
mask = mask >> 1; |
38 |
|
|
|
39 |
|
|
|
40 |
|
|
#if defined (GX_BRUSH_ALPHA_SUPPORT) |
41 |
|
|
#define BLEND_PIXEL if (alpha & mask) \ |
42 |
|
|
{ \ |
43 |
|
|
blend_func(context, xval, yval, text_color, brush_alpha); \ |
44 |
|
|
} \ |
45 |
|
|
xval++; \ |
46 |
|
|
mask = mask >> 1; |
47 |
|
|
#endif |
48 |
|
|
|
49 |
|
|
/**************************************************************************/ |
50 |
|
|
/* */ |
51 |
|
|
/* FUNCTION RELEASE */ |
52 |
|
|
/* */ |
53 |
|
|
/* _gx_display_driver_8bpp_glyph_1bit_draw PORTABLE C */ |
54 |
|
|
/* 6.1.11 */ |
55 |
|
|
/* AUTHOR */ |
56 |
|
|
/* */ |
57 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
58 |
|
|
/* */ |
59 |
|
|
/* DESCRIPTION */ |
60 |
|
|
/* */ |
61 |
|
|
/* This function draws monochrome font to the 8bpp canvas, clipped */ |
62 |
|
|
/* to one viweport. */ |
63 |
|
|
/* */ |
64 |
|
|
/* INPUT */ |
65 |
|
|
/* */ |
66 |
|
|
/* context Draw context */ |
67 |
|
|
/* draw_area The region bound by the */ |
68 |
|
|
/* rectangle where the glyph */ |
69 |
|
|
/* is drawn */ |
70 |
|
|
/* map_offset X,Y offset into the glyph map */ |
71 |
|
|
/* glyph Pointer to the glyph */ |
72 |
|
|
/* */ |
73 |
|
|
/* OUTPUT */ |
74 |
|
|
/* */ |
75 |
|
|
/* None */ |
76 |
|
|
/* */ |
77 |
|
|
/* CALLS */ |
78 |
|
|
/* */ |
79 |
|
|
/* [gx_display_driver_pixel_blend] Basic display driver pixel */ |
80 |
|
|
/* blend function */ |
81 |
|
|
/* */ |
82 |
|
|
/* CALLED BY */ |
83 |
|
|
/* */ |
84 |
|
|
/* GUIX internal code */ |
85 |
|
|
/* */ |
86 |
|
|
/**************************************************************************/ |
87 |
|
1150498 |
VOID _gx_display_driver_8bpp_glyph_1bit_draw(GX_DRAW_CONTEXT *context, GX_RECTANGLE *draw_area, GX_POINT *map_offset, GX_CONST GX_GLYPH *glyph) |
88 |
|
|
{ |
89 |
|
|
/* GX_DISPLAY *display;*/ |
90 |
|
|
GX_UBYTE *glyph_row; |
91 |
|
|
GX_UBYTE *glyph_data; |
92 |
|
|
UINT row; |
93 |
|
|
UINT pixel_per_row; |
94 |
|
|
UINT pixel_in_first_byte; |
95 |
|
1150498 |
UINT pixel_in_last_byte = 0; |
96 |
|
|
GX_UBYTE text_color; |
97 |
|
|
UINT y_height; |
98 |
|
|
GX_UBYTE alpha; |
99 |
|
|
UINT glyph_width; |
100 |
|
|
GX_UBYTE *put; |
101 |
|
|
UINT num_bytes; |
102 |
|
|
UINT num_bits; |
103 |
|
|
GX_UBYTE *line_start; |
104 |
|
|
GX_UBYTE mask, init_mask; |
105 |
|
|
UINT i; |
106 |
|
1150498 |
GX_UBYTE brush_alpha = 0xff; |
107 |
|
|
#if defined (GX_BRUSH_ALPHA_SUPPORT) |
108 |
|
|
INT xval, yval; |
109 |
|
|
VOID (*blend_func)(GX_DRAW_CONTEXT *, INT, INT, GX_COLOR, GX_UBYTE); |
110 |
|
|
|
111 |
|
1150498 |
brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha; |
112 |
|
1150498 |
blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend; |
113 |
|
|
|
114 |
✓✓ |
1150498 |
if (blend_func == GX_NULL) |
115 |
|
|
{ |
116 |
|
|
/* Pixel blend function is null means alpha isn't supported in this driver. |
117 |
|
|
So set alpha value to 0xff to make it draw the original color in case GX_BRUSH_ALPHA_SUPPORT is defined. */ |
118 |
|
804583 |
brush_alpha = 0xff; |
119 |
|
|
} |
120 |
|
|
else |
121 |
|
|
{ |
122 |
✓✓ |
345915 |
if (brush_alpha == 0) |
123 |
|
2880 |
return; |
124 |
|
|
} |
125 |
|
|
#endif |
126 |
|
1147618 |
text_color = (GX_UBYTE)context -> gx_draw_context_brush.gx_brush_line_color; |
127 |
|
1147618 |
pixel_per_row = (UINT)draw_area -> gx_rectangle_right - (UINT)draw_area -> gx_rectangle_left + (UINT)1; |
128 |
|
|
|
129 |
|
|
/* pickup pointer to current dispaly driver */ |
130 |
|
|
/*display = context -> gx_draw_context_display;*/ |
131 |
|
|
|
132 |
|
|
/* Find the width of the glyph, in terms of bytes */ |
133 |
|
1147618 |
glyph_width = glyph -> gx_glyph_width; |
134 |
|
|
/* Make it byte-aligned. */ |
135 |
|
1147618 |
glyph_width = (glyph_width + 7) >> 3; |
136 |
|
|
|
137 |
|
|
/* Compute the number of useful bytes from the glyph this routine is going to use. |
138 |
|
|
Because of map_offset, the first byte may contain pixel bits we don't need to draw; |
139 |
|
|
And the width of the draw_area may produce part of the last byte in the row to be ignored. */ |
140 |
|
1147618 |
num_bytes = ((UINT)map_offset -> gx_point_x + pixel_per_row + 7) >> 3; |
141 |
|
|
/* Take into account if map_offset specifies the number of bytes to ignore from the beginning of the row. */ |
142 |
|
1147618 |
num_bytes -= (UINT)(map_offset -> gx_point_x) >> 3; |
143 |
|
|
|
144 |
|
|
/* Compute the number of pixels to draw from the first byte of the glyph data. */ |
145 |
|
1147618 |
pixel_in_first_byte = (UINT)(8 - ((map_offset -> gx_point_x) & 0x7)); |
146 |
|
1147618 |
init_mask = (GX_UBYTE)(1 << (pixel_in_first_byte - 1)); |
147 |
|
|
/* Compute the number of pixels to draw from the last byte, if there are more than one byte in a row. */ |
148 |
✓✓ |
1147618 |
if (num_bytes != 1) |
149 |
|
|
{ |
150 |
|
335105 |
pixel_in_last_byte = (map_offset -> gx_point_x + (INT)pixel_per_row) & 0x7; |
151 |
✓✓ |
335105 |
if (pixel_in_last_byte == 0) |
152 |
|
|
{ |
153 |
|
1 |
pixel_in_last_byte = 8; |
154 |
|
|
} |
155 |
|
|
} |
156 |
|
|
else |
157 |
|
|
{ |
158 |
✓✓ |
812513 |
if ((map_offset -> gx_point_x + (INT)pixel_per_row) < 8) |
159 |
|
|
{ |
160 |
|
561609 |
pixel_in_first_byte = pixel_per_row; |
161 |
|
|
} |
162 |
|
|
else |
163 |
|
|
{ |
164 |
|
250904 |
pixel_in_last_byte = 0; |
165 |
|
|
} |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
|
169 |
|
1147618 |
glyph_row = (GX_UBYTE *)glyph -> gx_glyph_map; |
170 |
|
|
|
171 |
✓✓ |
1147618 |
if (map_offset -> gx_point_y) |
172 |
|
|
{ |
173 |
|
3273 |
glyph_row = glyph_row + ((INT)glyph_width * map_offset -> gx_point_y); |
174 |
|
|
} |
175 |
|
|
|
176 |
|
1147618 |
glyph_row += (map_offset -> gx_point_x >> 3); |
177 |
|
|
|
178 |
|
1147618 |
y_height = (UINT)(draw_area -> gx_rectangle_bottom - draw_area -> gx_rectangle_top + 1); |
179 |
|
|
|
180 |
✓✓ |
1147618 |
if (brush_alpha == 0xff) |
181 |
|
|
{ |
182 |
|
|
|
183 |
|
1144599 |
line_start = (GX_UBYTE *)context -> gx_draw_context_memory; |
184 |
|
1144599 |
line_start += context -> gx_draw_context_pitch * (draw_area -> gx_rectangle_top); |
185 |
|
1144599 |
line_start += draw_area -> gx_rectangle_left; |
186 |
|
|
|
187 |
✓✓ |
13561453 |
for (row = 0; row < y_height; row++) |
188 |
|
|
{ |
189 |
|
12416854 |
glyph_data = glyph_row; |
190 |
|
12416854 |
mask = init_mask; |
191 |
|
12416854 |
num_bits = pixel_in_first_byte; |
192 |
|
12416854 |
put = line_start; |
193 |
|
|
|
194 |
✓✓ |
28771088 |
for (i = 0; i < num_bytes; i++) |
195 |
|
|
{ |
196 |
|
16354234 |
alpha = *(glyph_data++); |
197 |
|
|
|
198 |
✓✓✓✓
|
16354234 |
if ((i == (num_bytes - 1)) && (num_bytes > 1)) |
199 |
|
|
{ |
200 |
|
3924058 |
num_bits = pixel_in_last_byte; |
201 |
|
|
} |
202 |
✓✓✓✓ ✓✓✓✓
|
16354234 |
switch (num_bits) |
203 |
|
|
{ |
204 |
|
6725530 |
case 8: |
205 |
✓✓ |
6725530 |
DRAW_PIXEL; |
206 |
|
|
/* fallthrough */ |
207 |
|
8243002 |
case 7: |
208 |
✓✓ |
8243002 |
DRAW_PIXEL; |
209 |
|
|
/* fallthrough */ |
210 |
|
9846821 |
case 6: |
211 |
✓✓ |
9846821 |
DRAW_PIXEL; |
212 |
|
|
/* fallthrough */ |
213 |
|
10119233 |
case 5: |
214 |
✓✓ |
10119233 |
DRAW_PIXEL; |
215 |
|
|
/* fallthrough */ |
216 |
|
10428073 |
case 4: |
217 |
✓✓ |
10428073 |
DRAW_PIXEL; |
218 |
|
|
/* fallthrough */ |
219 |
|
10739367 |
case 3: |
220 |
✓✓ |
10739367 |
DRAW_PIXEL; |
221 |
|
|
/* fallthrough */ |
222 |
|
14289033 |
case 2: |
223 |
✓✓ |
14289033 |
DRAW_PIXEL; |
224 |
|
|
/* fallthrough */ |
225 |
|
|
|
226 |
|
16354234 |
default: |
227 |
✓✓ |
16354234 |
if (alpha & mask) |
228 |
|
|
{ |
229 |
|
9105132 |
*put = text_color; |
230 |
|
|
} |
231 |
|
16354234 |
put++; |
232 |
|
16354234 |
break; |
233 |
|
|
} |
234 |
|
16354234 |
num_bits = 8; |
235 |
|
16354234 |
mask = 0x80; |
236 |
|
|
} |
237 |
|
|
|
238 |
|
12416854 |
glyph_row += glyph_width; |
239 |
|
12416854 |
line_start += context -> gx_draw_context_pitch; |
240 |
|
|
} |
241 |
|
|
} |
242 |
|
|
#if defined (GX_BRUSH_ALPHA_SUPPORT) |
243 |
|
|
else |
244 |
|
|
{ |
245 |
|
3019 |
yval = draw_area -> gx_rectangle_top; |
246 |
✓✓ |
36627 |
for (row = 0; row < y_height; row++) |
247 |
|
|
{ |
248 |
|
33608 |
xval = draw_area -> gx_rectangle_left; |
249 |
|
33608 |
glyph_data = glyph_row; |
250 |
|
33608 |
mask = init_mask; |
251 |
|
33608 |
num_bits = pixel_in_first_byte; |
252 |
✓✓ |
76382 |
for (i = 0; i < num_bytes; i++) |
253 |
|
|
{ |
254 |
|
42774 |
alpha = *(glyph_data); |
255 |
✓✓✓✓
|
42774 |
if ((i == (num_bytes - 1)) && (num_bytes > 1)) |
256 |
|
|
{ |
257 |
|
9166 |
num_bits = pixel_in_last_byte; |
258 |
|
|
} |
259 |
✓✓✓✓ ✓✓✓✓
|
42774 |
switch (num_bits) |
260 |
|
|
{ |
261 |
|
29231 |
case 8: |
262 |
✓✓ |
29231 |
BLEND_PIXEL; |
263 |
|
|
/* fallthrough */ |
264 |
|
29257 |
case 7: |
265 |
✓✓ |
29257 |
BLEND_PIXEL; |
266 |
|
|
/* fallthrough */ |
267 |
|
33531 |
case 6: |
268 |
✓✓ |
33531 |
BLEND_PIXEL; |
269 |
|
|
/* fallthrough */ |
270 |
|
33541 |
case 5: |
271 |
✓✓ |
33541 |
BLEND_PIXEL; |
272 |
|
|
/* fallthrough */ |
273 |
|
33853 |
case 4: |
274 |
✓✓ |
33853 |
BLEND_PIXEL; |
275 |
|
|
/* fallthrough */ |
276 |
|
34152 |
case 3: |
277 |
✓✓ |
34152 |
BLEND_PIXEL; |
278 |
|
|
/* fallthrough */ |
279 |
|
37760 |
case 2: |
280 |
✓✓ |
37760 |
BLEND_PIXEL; |
281 |
|
|
/* fallthrough */ |
282 |
|
42774 |
default: |
283 |
✓✓ |
42774 |
if (alpha & mask) |
284 |
|
|
{ |
285 |
|
16611 |
blend_func(context, xval, yval, text_color, brush_alpha); |
286 |
|
|
} |
287 |
|
42774 |
xval++; |
288 |
|
42774 |
break; |
289 |
|
|
} |
290 |
|
42774 |
glyph_data++; |
291 |
|
42774 |
num_bits = 8; |
292 |
|
42774 |
mask = 0x80; |
293 |
|
|
} |
294 |
|
|
|
295 |
|
33608 |
glyph_row += glyph_width; |
296 |
|
33608 |
yval++; |
297 |
|
|
} |
298 |
|
|
} |
299 |
|
|
#endif |
300 |
|
1147618 |
return; |
301 |
|
|
} |
302 |
|
|
|