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 |
|
|
#if defined (GX_BRUSH_ALPHA_SUPPORT) |
40 |
|
|
#define BLEND_PIXEL if (alpha & mask) \ |
41 |
|
|
{ \ |
42 |
|
|
blend_func(context, xval, yval, text_color, brush_alpha); \ |
43 |
|
|
} \ |
44 |
|
|
xval++; \ |
45 |
|
|
mask = mask >> 1; |
46 |
|
|
#endif |
47 |
|
|
|
48 |
|
|
/**************************************************************************/ |
49 |
|
|
/* */ |
50 |
|
|
/* FUNCTION RELEASE */ |
51 |
|
|
/* */ |
52 |
|
|
/* _gx_display_driver_16bpp_glyph_1bit_draw PORTABLE C */ |
53 |
|
|
/* 6.3.0 */ |
54 |
|
|
/* AUTHOR */ |
55 |
|
|
/* */ |
56 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
57 |
|
|
/* */ |
58 |
|
|
/* DESCRIPTION */ |
59 |
|
|
/* */ |
60 |
|
|
/* This functions draw monochrome font on 16bpp canvas, clipped to */ |
61 |
|
|
/* one viewport. */ |
62 |
|
|
/* */ |
63 |
|
|
/* INPUT */ |
64 |
|
|
/* */ |
65 |
|
|
/* context Draw context */ |
66 |
|
|
/* draw_area The region bound by the */ |
67 |
|
|
/* rectangle where the glyph */ |
68 |
|
|
/* is drawn */ |
69 |
|
|
/* map_offset X,Y offset into the glyph map */ |
70 |
|
|
/* glyph Pointer to the glyph */ |
71 |
|
|
/* */ |
72 |
|
|
/* OUTPUT */ |
73 |
|
|
/* */ |
74 |
|
|
/* None */ |
75 |
|
|
/* */ |
76 |
|
|
/* CALLS */ |
77 |
|
|
/* */ |
78 |
|
|
/* [gx_display_driver_pixel_blend] Basic display driver pixel */ |
79 |
|
|
/* blend function */ |
80 |
|
|
/* */ |
81 |
|
|
/* CALLED BY */ |
82 |
|
|
/* */ |
83 |
|
|
/* GUIX internal code */ |
84 |
|
|
/* */ |
85 |
|
|
/**************************************************************************/ |
86 |
|
295398 |
VOID _gx_display_driver_16bpp_glyph_1bit_draw(GX_DRAW_CONTEXT *context, GX_RECTANGLE *draw_area, GX_POINT *map_offset, GX_CONST GX_GLYPH *glyph) |
87 |
|
|
{ |
88 |
|
|
/* GX_DISPLAY *display;*/ |
89 |
|
|
GX_UBYTE *glyph_row; |
90 |
|
|
GX_UBYTE *glyph_data; |
91 |
|
|
UINT row; |
92 |
|
|
UINT pixel_per_row; |
93 |
|
|
UINT pixel_in_first_byte; |
94 |
|
295398 |
UINT pixel_in_last_byte = 0; |
95 |
|
|
USHORT text_color; |
96 |
|
|
UINT y_height; |
97 |
|
|
GX_UBYTE alpha; |
98 |
|
|
UINT glyph_width; |
99 |
|
|
USHORT *put; |
100 |
|
|
UINT num_bytes; |
101 |
|
|
UINT num_bits; |
102 |
|
|
USHORT *line_start; |
103 |
|
|
GX_UBYTE mask, init_mask; |
104 |
|
|
UINT i; |
105 |
|
|
#if defined (GX_BRUSH_ALPHA_SUPPORT) |
106 |
|
|
GX_UBYTE brush_alpha; |
107 |
|
|
INT xval, yval; |
108 |
|
|
VOID (*blend_func)(GX_DRAW_CONTEXT *, INT, INT, GX_COLOR, GX_UBYTE); |
109 |
|
|
|
110 |
|
295398 |
brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha; |
111 |
|
295398 |
blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend; |
112 |
|
|
|
113 |
✓✓ |
295398 |
if (blend_func == GX_NULL) |
114 |
|
|
{ |
115 |
|
|
/* Pixel blend function is null means alpha isn't supported in this driver. |
116 |
|
|
So set alpha value to 0xff to make it draw the original color in case GX_BRUSH_ALPHA_SUPPORT is defined. */ |
117 |
|
12 |
brush_alpha = 0xff; |
118 |
|
|
} |
119 |
|
|
else |
120 |
|
|
{ |
121 |
✓✓ |
295386 |
if (brush_alpha == 0) |
122 |
|
60 |
return; |
123 |
|
|
} |
124 |
|
|
#endif |
125 |
|
295338 |
text_color = (USHORT)context -> gx_draw_context_brush.gx_brush_line_color; |
126 |
|
295338 |
pixel_per_row = (UINT)(draw_area -> gx_rectangle_right - draw_area -> gx_rectangle_left + 1); |
127 |
|
|
|
128 |
|
|
/* pickup pointer to current dispaly driver */ |
129 |
|
|
/*display = context -> gx_draw_context_display;*/ |
130 |
|
|
|
131 |
|
|
/* Find the width of the glyph, in terms of bytes */ |
132 |
|
295338 |
glyph_width = glyph -> gx_glyph_width; |
133 |
|
|
/* Make it byte-aligned. */ |
134 |
|
295338 |
glyph_width = (glyph_width + 7) >> 3; |
135 |
|
|
|
136 |
|
|
/* Compute the number of useful bytes from the glyph this routine is going to use. |
137 |
|
|
Because of map_offset, the first byte may contain pixel bits we don't need to draw; |
138 |
|
|
And the width of the draw_area may produce part of the last byte in the row to be ignored. */ |
139 |
|
295338 |
num_bytes = (UINT)(((INT)map_offset -> gx_point_x + (INT)pixel_per_row + 7) >> 3); |
140 |
|
|
/* Take into account if map_offset specifies the number of bytes to ignore from the beginning of the row. */ |
141 |
|
295338 |
num_bytes -= ((UINT)(map_offset -> gx_point_x)) >> 3; |
142 |
|
|
|
143 |
|
|
/* Compute the number of pixels to draw from the first byte of the glyph data. */ |
144 |
|
295338 |
pixel_in_first_byte = (UINT)(8 - ((map_offset -> gx_point_x) & 0x7)); |
145 |
|
295338 |
init_mask = (GX_UBYTE)(1 << (pixel_in_first_byte - 1)); |
146 |
|
|
/* Compute the number of pixels to draw from the last byte, if there are more than one byte in a row. */ |
147 |
✓✓ |
295338 |
if (num_bytes != 1) |
148 |
|
|
{ |
149 |
|
39933 |
pixel_in_last_byte = ((UINT)map_offset -> gx_point_x + pixel_per_row) & 0x7; |
150 |
✓✓ |
39933 |
if (pixel_in_last_byte == 0) |
151 |
|
|
{ |
152 |
|
70 |
pixel_in_last_byte = 8; |
153 |
|
|
} |
154 |
|
|
} |
155 |
|
|
else |
156 |
|
|
{ |
157 |
✓✓ |
255405 |
if ((map_offset -> gx_point_x + (INT)pixel_per_row) < 8) |
158 |
|
|
{ |
159 |
|
208651 |
pixel_in_first_byte = pixel_per_row; |
160 |
|
|
} |
161 |
|
|
else |
162 |
|
|
{ |
163 |
|
46754 |
pixel_in_last_byte = 0; |
164 |
|
|
} |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
|
168 |
|
295338 |
glyph_row = (GX_UBYTE *)glyph -> gx_glyph_map; |
169 |
|
|
|
170 |
✓✓ |
295338 |
if (map_offset -> gx_point_y) |
171 |
|
|
{ |
172 |
|
2304 |
glyph_row = (GX_UBYTE *)(glyph_row + ((INT)glyph_width * (INT)(map_offset -> gx_point_y))); |
173 |
|
|
} |
174 |
|
|
|
175 |
|
295338 |
glyph_row += (map_offset -> gx_point_x >> 3); |
176 |
|
|
|
177 |
|
295338 |
y_height = (UINT)(draw_area -> gx_rectangle_bottom - draw_area -> gx_rectangle_top + 1); |
178 |
|
|
|
179 |
|
295338 |
line_start = (USHORT *)context -> gx_draw_context_memory; |
180 |
|
295338 |
GX_CALCULATE_PUTROW(line_start, draw_area -> gx_rectangle_left, draw_area -> gx_rectangle_top, context); |
181 |
|
|
|
182 |
|
|
#if defined(GX_BRUSH_ALPHA_SUPPORT) |
183 |
✓✓ |
295338 |
if (brush_alpha != 0xff) |
184 |
|
|
{ |
185 |
|
146518 |
yval = draw_area -> gx_rectangle_top; |
186 |
✓✓ |
1380962 |
for (row = 0; row < y_height; row++) |
187 |
|
|
{ |
188 |
|
1234444 |
xval = draw_area -> gx_rectangle_left; |
189 |
|
1234444 |
glyph_data = glyph_row; |
190 |
|
1234444 |
mask = init_mask; |
191 |
|
1234444 |
num_bits = pixel_in_first_byte; |
192 |
✓✓ |
2688282 |
for (i = 0; i < num_bytes; i++) |
193 |
|
|
{ |
194 |
|
1453838 |
alpha = *(glyph_data++); |
195 |
|
|
|
196 |
✓✓✓✓
|
1453838 |
if ((i == (num_bytes - 1)) && (num_bytes > 1)) |
197 |
|
|
{ |
198 |
|
219394 |
num_bits = pixel_in_last_byte; |
199 |
|
|
} |
200 |
✓✓✓✓ ✓✓✓✓
|
1453838 |
switch (num_bits) |
201 |
|
|
{ |
202 |
|
485574 |
case 8: |
203 |
✓✓ |
485574 |
BLEND_PIXEL; |
204 |
|
|
/* fallthrough */ |
205 |
|
787820 |
case 7: |
206 |
✓✓ |
787820 |
BLEND_PIXEL; |
207 |
|
|
/* fallthrough */ |
208 |
|
916716 |
case 6: |
209 |
✓✓ |
916716 |
BLEND_PIXEL; |
210 |
|
|
/* fallthrough */ |
211 |
|
985352 |
case 5: |
212 |
✓✓ |
985352 |
BLEND_PIXEL; |
213 |
|
|
/* fallthrough */ |
214 |
|
1086654 |
case 4: |
215 |
✓✓ |
1086654 |
BLEND_PIXEL; |
216 |
|
|
/* fallthrough */ |
217 |
|
1175960 |
case 3: |
218 |
✓✓ |
1175960 |
BLEND_PIXEL; |
219 |
|
|
/* fallthrough */ |
220 |
|
1283032 |
case 2: |
221 |
✓✓ |
1283032 |
BLEND_PIXEL; |
222 |
|
|
/* fallthrough */ |
223 |
|
1453838 |
default: |
224 |
✓✓ |
1453838 |
if (alpha & mask) |
225 |
|
|
{ |
226 |
|
514830 |
blend_func(context, xval, yval, text_color, brush_alpha); |
227 |
|
|
} |
228 |
|
1453838 |
xval++; |
229 |
|
1453838 |
break; |
230 |
|
|
} |
231 |
|
1453838 |
num_bits = 8; |
232 |
|
1453838 |
mask = 0x80; |
233 |
|
|
} |
234 |
|
|
|
235 |
|
1234444 |
glyph_row += glyph_width; |
236 |
|
1234444 |
yval++; |
237 |
|
|
} |
238 |
|
|
} |
239 |
|
|
else |
240 |
|
|
{ |
241 |
|
|
#endif |
242 |
✓✓ |
1409185 |
for (row = 0; row < y_height; row++) |
243 |
|
|
{ |
244 |
|
1260365 |
glyph_data = glyph_row; |
245 |
|
1260365 |
mask = init_mask; |
246 |
|
1260365 |
num_bits = pixel_in_first_byte; |
247 |
|
1260365 |
put = line_start; |
248 |
✓✓ |
2752689 |
for (i = 0; i < num_bytes; i++) |
249 |
|
|
{ |
250 |
|
1492324 |
alpha = *(glyph_data++); |
251 |
|
|
|
252 |
✓✓✓✓
|
1492324 |
if ((i == (num_bytes - 1)) && (num_bytes > 1)) |
253 |
|
|
{ |
254 |
|
230161 |
num_bits = pixel_in_last_byte; |
255 |
|
|
} |
256 |
✓✓✓✓ ✓✓✓✓
|
1492324 |
switch (num_bits) |
257 |
|
|
{ |
258 |
|
503667 |
case 8: |
259 |
✓✓ |
503667 |
DRAW_PIXEL; |
260 |
|
|
/* fallthrough */ |
261 |
|
810772 |
case 7: |
262 |
✓✓ |
810772 |
DRAW_PIXEL; |
263 |
|
|
/* fallthrough */ |
264 |
|
944567 |
case 6: |
265 |
✓✓ |
944567 |
DRAW_PIXEL; |
266 |
|
|
/* fallthrough */ |
267 |
|
1014681 |
case 5: |
268 |
✓✓ |
1014681 |
DRAW_PIXEL; |
269 |
|
|
/* fallthrough */ |
270 |
|
1117934 |
case 4: |
271 |
✓✓ |
1117934 |
DRAW_PIXEL; |
272 |
|
|
/* fallthrough */ |
273 |
|
1209490 |
case 3: |
274 |
✓✓ |
1209490 |
DRAW_PIXEL; |
275 |
|
|
/* fallthrough */ |
276 |
|
1319560 |
case 2: |
277 |
✓✓ |
1319560 |
DRAW_PIXEL; |
278 |
|
|
/* fallthrough */ |
279 |
|
1492324 |
default: |
280 |
✓✓ |
1492324 |
if (alpha & mask) |
281 |
|
|
{ |
282 |
|
529339 |
*put = text_color; |
283 |
|
|
} |
284 |
|
1492324 |
put++; |
285 |
|
1492324 |
break; |
286 |
|
|
} |
287 |
|
1492324 |
num_bits = 8; |
288 |
|
1492324 |
mask = 0x80; |
289 |
|
|
} |
290 |
|
|
|
291 |
|
1260365 |
glyph_row += glyph_width; |
292 |
|
1260365 |
line_start += context -> gx_draw_context_pitch; |
293 |
|
|
} |
294 |
|
|
#if defined (GX_BRUSH_ALPHA_SUPPORT) |
295 |
|
|
} |
296 |
|
|
#endif |
297 |
|
295338 |
return; |
298 |
|
|
} |
299 |
|
|
|