1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
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 _gx_display_driver_24xrgb_pixel_blend(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_32bpp_glyph_1bit_draw PORTABLE C */
53 /* 6.1.11 */
54 /* AUTHOR */
55 /* */
56 /* Kenneth Maxwell, Microsoft Corporation */
57 /* */
58 /* DESCRIPTION */
59 /* */
60 /* This functions draw monochrome font on 32bpp 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_24xrgb_pixel_blend Display driver basic pixel */
79 /* blend function */
80 /* */
81 /* CALLED BY */
82 /* */
83 /* GUIX internal code */
84 /* */
85 /* RELEASE HISTORY */
86 /* */
87 /* DATE NAME DESCRIPTION */
88 /* */
89 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
90 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
91 /* resulting in version 6.1 */
92 /* 04-25-2022 Ting Zhu Modified comment(s), */
93 /* fixed access violation bug, */
94 /* resulting in version 6.1.11 */
95 /* */
96 /**************************************************************************/
_gx_display_driver_32bpp_glyph_1bit_draw(GX_DRAW_CONTEXT * context,GX_RECTANGLE * draw_area,GX_POINT * map_offset,GX_CONST GX_GLYPH * glyph)97 VOID _gx_display_driver_32bpp_glyph_1bit_draw(GX_DRAW_CONTEXT *context, GX_RECTANGLE *draw_area, GX_POINT *map_offset, GX_CONST GX_GLYPH *glyph)
98 {
99 GX_UBYTE *glyph_row;
100 GX_UBYTE *glyph_data;
101 UINT row;
102 UINT pixel_per_row;
103 UINT pixel_in_first_byte;
104 UINT pixel_in_last_byte = 0;
105 GX_COLOR text_color;
106 UINT y_height;
107 GX_UBYTE alpha;
108 UINT glyph_width;
109 UINT *put;
110 UINT num_bytes;
111 UINT num_bits;
112 UINT *line_start;
113 GX_UBYTE mask, init_mask;
114 UINT i;
115
116 #if defined (GX_BRUSH_ALPHA_SUPPORT)
117 GX_UBYTE brush_alpha;
118 INT xval, yval;
119
120 brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
121 if (brush_alpha == 0)
122 {
123 return;
124 }
125 #endif
126
127 text_color = context -> gx_draw_context_brush.gx_brush_line_color;
128 pixel_per_row = (UINT)(draw_area -> gx_rectangle_right - draw_area -> gx_rectangle_left + 1);
129
130 /* pickup pointer to current dispaly driver */
131 /*display = context -> gx_draw_context_display;*/
132
133 /* Find the width of the glyph, in terms of bytes */
134 glyph_width = glyph -> gx_glyph_width;
135 /* Make it byte-aligned. */
136 glyph_width = (glyph_width + 7) >> 3;
137
138 /* Compute the number of useful bytes from the glyph this routine is going to use.
139 Because of map_offset, the first byte may contain pixel bits we don't need to draw;
140 And the width of the draw_area may produce part of the last byte in the row to be ignored. */
141 num_bytes = (UINT)(((UINT)(map_offset -> gx_point_x) + pixel_per_row + 7) >> 3);
142 /* Take into account if map_offset specifies the number of bytes to ignore from the beginning of the row. */
143 num_bytes = num_bytes - (((UINT)(map_offset -> gx_point_x)) >> 3);
144
145 /* Compute the number of pixels to draw from the first byte of the glyph data. */
146 pixel_in_first_byte = 8 - (UINT)((map_offset -> gx_point_x) & 0x7);
147 init_mask = (GX_UBYTE)(1 << (pixel_in_first_byte - 1));
148 /* Compute the number of pixels to draw from the last byte, if there are more than one byte in a row. */
149 if (num_bytes != 1)
150 {
151 pixel_in_last_byte = (((UINT)(map_offset -> gx_point_x) + pixel_per_row) & 0x7);
152 if (pixel_in_last_byte == 0)
153 {
154 pixel_in_last_byte = 8;
155 }
156 }
157 else
158 {
159 if (((UINT)(map_offset -> gx_point_x) + pixel_per_row) < 8)
160 {
161 pixel_in_first_byte = pixel_per_row;
162 }
163 else
164 {
165 pixel_in_last_byte = 0;
166 }
167 }
168
169 glyph_row = (GX_UBYTE *)glyph -> gx_glyph_map;
170
171 if (map_offset -> gx_point_y)
172 {
173 glyph_row = glyph_row + ((INT)glyph_width * (INT)(map_offset -> gx_point_y));
174 }
175
176 glyph_row += (map_offset -> gx_point_x >> 3);
177
178 y_height = (UINT)(draw_area -> gx_rectangle_bottom - draw_area -> gx_rectangle_top + 1);
179
180 #if defined (GX_BRUSH_ALPHA_SUPPORT)
181 if (brush_alpha != 0xff)
182 {
183 yval = draw_area -> gx_rectangle_top;
184 for (row = 0; row < y_height; row++)
185 {
186 xval = draw_area -> gx_rectangle_left;
187 glyph_data = glyph_row;
188 mask = init_mask;
189 num_bits = pixel_in_first_byte;
190 for (i = 0; i < num_bytes; i++)
191 {
192 alpha = *(glyph_data++);
193
194 if ((i == (num_bytes - 1)) && (num_bytes > 1))
195 {
196 num_bits = pixel_in_last_byte;
197 }
198 switch (num_bits)
199 {
200 case 8:
201 BLEND_PIXEL;
202 /* fallthrough */
203 case 7:
204 BLEND_PIXEL;
205 /* fallthrough */
206 case 6:
207 BLEND_PIXEL;
208 /* fallthrough */
209 case 5:
210 BLEND_PIXEL;
211 /* fallthrough */
212 case 4:
213 BLEND_PIXEL;
214 /* fallthrough */
215 case 3:
216 BLEND_PIXEL;
217 /* fallthrough */
218 case 2:
219 BLEND_PIXEL;
220 /* fallthrough */
221 default:
222 if (alpha & mask)
223 {
224 _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, text_color, brush_alpha);
225 }
226 xval++;
227 break;
228 }
229 num_bits = 8;
230 mask = 0x80;
231 }
232
233 glyph_row += glyph_width;
234 yval++;
235 }
236 }
237 else
238 {
239 #endif
240 line_start = (UINT *)context -> gx_draw_context_memory;
241 line_start += context -> gx_draw_context_pitch * (draw_area -> gx_rectangle_top);
242 line_start += draw_area -> gx_rectangle_left;
243
244 for (row = 0; row < y_height; row++)
245 {
246 glyph_data = glyph_row;
247 mask = init_mask;
248 num_bits = pixel_in_first_byte;
249 put = line_start;
250 for (i = 0; i < num_bytes; i++)
251 {
252 alpha = *(glyph_data++);
253
254 if ((i == (num_bytes - 1)) && (num_bytes > 1))
255 {
256 num_bits = pixel_in_last_byte;
257 }
258 switch (num_bits)
259 {
260 case 8:
261 DRAW_PIXEL;
262 /* fallthrough */
263 case 7:
264 DRAW_PIXEL;
265 /* fallthrough */
266 case 6:
267 DRAW_PIXEL;
268 /* fallthrough */
269 case 5:
270 DRAW_PIXEL;
271 /* fallthrough */
272 case 4:
273 DRAW_PIXEL;
274 /* fallthrough */
275 case 3:
276 DRAW_PIXEL;
277 /* fallthrough */
278 case 2:
279 DRAW_PIXEL;
280 /* fallthrough */
281 default:
282 if (alpha & mask)
283 {
284 *put = text_color;
285 }
286 put++;
287 break;
288 }
289 num_bits = 8;
290 mask = 0x80;
291 }
292
293 glyph_row += glyph_width;
294 line_start += context -> gx_draw_context_pitch;
295 }
296 #if defined (GX_BRUSH_ALPHA_SUPPORT)
297 }
298 #endif
299 return;
300 }
301
302