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