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 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_565rgb_rotated_glyph_1bit_draw PORTABLE C */
53 /* 6.1.3 */
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 /* RELEASE HISTORY */
86 /* */
87 /* DATE NAME DESCRIPTION */
88 /* */
89 /* 12-31-2020 Kenneth Maxwell Initial Version 6.1.3 */
90 /* */
91 /**************************************************************************/
_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 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)
93 {
94 /* GX_DISPLAY *display;*/
95 GX_UBYTE *glyph_row;
96 GX_UBYTE *glyph_data;
97 UINT row;
98 UINT pixel_per_row;
99 UINT pixel_in_first_byte;
100 UINT pixel_in_last_byte = 0;
101 USHORT text_color;
102 UINT y_height;
103 GX_UBYTE alpha;
104 UINT glyph_width;
105 USHORT *put;
106 UINT num_bytes;
107 UINT num_bits;
108 USHORT *line_start;
109 GX_UBYTE mask, init_mask;
110 UINT i;
111 GX_VALUE rotated_map_offset_x;
112 GX_VALUE rotated_map_offset_y;
113 GX_VALUE rotated_draw_left;
114 GX_VALUE rotated_draw_top;
115
116 #if defined(GX_BRUSH_ALPHA_SUPPORT)
117 GX_UBYTE brush_alpha;
118 INT xval, yval;
119 VOID (*blend_func)(GX_DRAW_CONTEXT *, INT, INT, GX_COLOR, GX_UBYTE);
120
121 brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
122
123 if (brush_alpha == 0)
124 {
125 return;
126 }
127
128 blend_func = _gx_display_driver_565rgb_pixel_blend;
129 #endif
130 text_color = (USHORT)context -> gx_draw_context_brush.gx_brush_line_color;
131 pixel_per_row = (UINT)(draw_area -> gx_rectangle_bottom - draw_area -> gx_rectangle_top + 1);
132 y_height = (UINT)(draw_area -> gx_rectangle_right - draw_area -> gx_rectangle_left + 1);
133
134 /* Find the width of the glyph, in terms of bytes */
135 glyph_width = glyph -> gx_glyph_height;
136
137 /* Make it byte-aligned. */
138 glyph_width = (glyph_width + 7) >> 3;
139
140 if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
141 {
142 rotated_draw_left = draw_area -> gx_rectangle_top;
143 rotated_draw_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - draw_area -> gx_rectangle_right - 1);
144
145 rotated_map_offset_x = map_offset -> gx_point_y;
146 rotated_map_offset_y = (GX_VALUE)(glyph -> gx_glyph_width - map_offset -> gx_point_x - (GX_VALUE)y_height);
147 }
148 else
149 {
150 rotated_draw_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_display_offset_y - draw_area -> gx_rectangle_bottom - 1);
151 rotated_draw_top = draw_area -> gx_rectangle_left;
152
153 rotated_map_offset_x = (GX_VALUE)(glyph -> gx_glyph_height - map_offset -> gx_point_y - (GX_VALUE)pixel_per_row);
154 rotated_map_offset_y = map_offset -> gx_point_x;
155 }
156
157 /* Compute the number of useful bytes from the glyph this routine is going to use.
158 Because of map_offset, the first byte may contain pixel bits we don't need to draw;
159 And the width of the draw_area may produce part of the last byte in the row to be ignored. */
160 num_bytes = (UINT)(((INT)rotated_map_offset_x + (INT)pixel_per_row + 7) >> 3);
161
162 /* Take into account if map_offset specifies the number of bytes to ignore from the beginning of the row. */
163 num_bytes -= ((UINT)(rotated_map_offset_x)) >> 3;
164
165 /* Compute the number of pixels to draw from the first byte of the glyph data. */
166 pixel_in_first_byte = (UINT)(8 - ((rotated_map_offset_x) & 0x7));
167 init_mask = (GX_UBYTE)(1 << (pixel_in_first_byte - 1));
168
169 /* Compute the number of pixels to draw from the last byte, if there are more than one byte in a row. */
170 if (num_bytes != 1)
171 {
172 pixel_in_last_byte = ((UINT)rotated_map_offset_x + pixel_per_row) & 0x7;
173 if (pixel_in_last_byte == 0)
174 {
175 pixel_in_last_byte = 8;
176 }
177 }
178 else
179 {
180 pixel_in_first_byte = pixel_per_row;
181 }
182
183
184 glyph_row = (GX_UBYTE *)glyph -> gx_glyph_map;
185
186 if (rotated_map_offset_y)
187 {
188 glyph_row = (GX_UBYTE *)(glyph_row + ((INT)glyph_width * (INT)(rotated_map_offset_y)));
189 }
190
191 glyph_row += (rotated_map_offset_x >> 3);
192
193 line_start = (USHORT *)context -> gx_draw_context_memory;
194 line_start += context -> gx_draw_context_pitch * (rotated_draw_top);
195 line_start += rotated_draw_left;
196
197 #if defined(GX_BRUSH_ALPHA_SUPPORT)
198 if (brush_alpha != 0xff)
199 {
200 yval = rotated_draw_top;
201 for (row = 0; row < y_height; row++)
202 {
203 xval = rotated_draw_left;
204 glyph_data = glyph_row;
205 alpha = *(glyph_data);
206 mask = init_mask;
207 num_bits = pixel_in_first_byte;
208 for (i = 0; i < num_bytes; i++)
209 {
210 if ((i == (num_bytes - 1)) && (num_bytes > 1))
211 {
212 num_bits = pixel_in_last_byte;
213 }
214 switch (num_bits)
215 {
216 case 8:
217 BLEND_PIXEL;
218 /* fallthrough */
219 case 7:
220 BLEND_PIXEL;
221 /* fallthrough */
222 case 6:
223 BLEND_PIXEL;
224 /* fallthrough */
225 case 5:
226 BLEND_PIXEL;
227 /* fallthrough */
228 case 4:
229 BLEND_PIXEL;
230 /* fallthrough */
231 case 3:
232 BLEND_PIXEL;
233 /* fallthrough */
234 case 2:
235 BLEND_PIXEL;
236 /* fallthrough */
237 default:
238 if (alpha & mask)
239 {
240 blend_func(context, xval, yval, text_color, brush_alpha);
241 }
242 xval++;
243 break;
244 }
245 glyph_data++;
246 alpha = *(glyph_data);
247 num_bits = 8;
248 mask = 0x80;
249 }
250
251 glyph_row += glyph_width;
252 yval++;
253 }
254 }
255 else
256 {
257 #endif
258 for (row = 0; row < y_height; row++)
259 {
260 glyph_data = glyph_row;
261 alpha = *(glyph_data);
262 mask = init_mask;
263 num_bits = pixel_in_first_byte;
264 put = line_start;
265 for (i = 0; i < num_bytes; i++)
266 {
267 if ((i == (num_bytes - 1)) && (num_bytes > 1))
268 {
269 num_bits = pixel_in_last_byte;
270 }
271 switch (num_bits)
272 {
273 case 8:
274 DRAW_PIXEL;
275 /* fallthrough */
276 case 7:
277 DRAW_PIXEL;
278 /* fallthrough */
279 case 6:
280 DRAW_PIXEL;
281 /* fallthrough */
282 case 5:
283 DRAW_PIXEL;
284 /* fallthrough */
285 case 4:
286 DRAW_PIXEL;
287 /* fallthrough */
288 case 3:
289 DRAW_PIXEL;
290 /* fallthrough */
291 case 2:
292 DRAW_PIXEL;
293 /* fallthrough */
294 default:
295 if (alpha & mask)
296 {
297 *put = text_color;
298 }
299 put++;
300 break;
301 }
302 glyph_data++;
303 alpha = *(glyph_data);
304 num_bits = 8;
305 mask = 0x80;
306 }
307
308 glyph_row += glyph_width;
309 line_start += context -> gx_draw_context_pitch;
310 }
311 #if defined(GX_BRUSH_ALPHA_SUPPORT)
312 }
313 #endif
314 return;
315 }
316
317