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 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _gx_display_driver_generic_rotated_glyph_4bit_draw PORTABLE C */
37 /* 6.1.3 */
38 /* AUTHOR */
39 /* */
40 /* Kenneth Maxwell, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function draws the specified text using the current context, */
45 /* clipped to one viewport */
46 /* */
47 /* INPUT */
48 /* */
49 /* context Draw context */
50 /* draw_area The rectangle where the glyph */
51 /* is drawn to */
52 /* map_offset Offset from the glyph map */
53 /* glyph The glyph structure */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* None */
58 /* */
59 /* CALLS */
60 /* */
61 /* [gx_display_driver_pixel_blend] Call display driver pixel */
62 /* blend function */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* GUIX internal code */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 12-31-2020 Kenneth Maxwell Initial Version 6.1.3 */
73 /* */
74 /**************************************************************************/
_gx_display_driver_generic_rotated_glyph_4bit_draw(GX_DRAW_CONTEXT * context,GX_RECTANGLE * draw_area,GX_POINT * map_offset,GX_CONST GX_GLYPH * glyph)75 VOID _gx_display_driver_generic_rotated_glyph_4bit_draw(GX_DRAW_CONTEXT *context, GX_RECTANGLE *draw_area, GX_POINT *map_offset, GX_CONST GX_GLYPH *glyph)
76 {
77 GX_UBYTE *glyph_row;
78 GX_UBYTE *glyph_data;
79 UINT row;
80 UINT col;
81 UINT pixel_width = 0;
82 UINT leading_pixel;
83 UINT trailing_pixel;
84 GX_COLOR text_color;
85 UINT y_height;
86 GX_UBYTE alpha;
87 UINT pitch;
88 UINT index;
89 VOID (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR color, GX_UBYTE alpha);
90 GX_UBYTE brush_alpha = 0xff;
91 GX_VALUE rotated_map_offset_x;
92 GX_VALUE rotated_map_offset_y;
93 GX_VALUE rotated_left;
94 GX_VALUE rotated_top;
95
96 #if defined(GX_BRUSH_ALPHA_SUPPORT)
97 INT alpha_sum;
98 brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
99 if (brush_alpha == 0)
100 {
101 return;
102 }
103 #endif
104
105 text_color = context -> gx_draw_context_brush.gx_brush_line_color;
106
107 y_height = (UINT)(draw_area -> gx_rectangle_right - draw_area -> gx_rectangle_left + 1);
108
109 /* Find the width of the glyph */
110 pitch = glyph -> gx_glyph_height;
111 /* Make it byte-aligned. */
112 pitch = (pitch + 1) >> 1;
113
114 pixel_width = (UINT)(draw_area -> gx_rectangle_bottom - draw_area -> gx_rectangle_top + 1);
115
116 if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
117 {
118 rotated_left = draw_area -> gx_rectangle_top;
119 rotated_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - draw_area -> gx_rectangle_right - 1);
120
121 rotated_map_offset_x = map_offset -> gx_point_y;
122 rotated_map_offset_y = (GX_VALUE)(glyph -> gx_glyph_width - map_offset -> gx_point_x - (GX_VALUE)y_height);
123 }
124 else
125 {
126 rotated_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_display_offset_y - draw_area -> gx_rectangle_bottom - 1);
127 rotated_top = draw_area -> gx_rectangle_left;
128
129 rotated_map_offset_x = (GX_VALUE)(glyph -> gx_glyph_height - map_offset -> gx_point_y - (GX_VALUE)pixel_width);
130 rotated_map_offset_y = map_offset -> gx_point_x;
131 }
132
133 glyph_row = (GX_UBYTE *)glyph -> gx_glyph_map;
134
135 if (rotated_map_offset_y)
136 {
137 glyph_row = glyph_row + ((INT)pitch * rotated_map_offset_y);
138 }
139
140 glyph_row += (rotated_map_offset_x >> 1);
141
142 GX_SET_BLEND_FUNCTION(blend_func, context -> gx_draw_context_display -> gx_display_color_format)
143
144 leading_pixel = (rotated_map_offset_x & 1);
145
146 pixel_width -= leading_pixel;
147
148 trailing_pixel = pixel_width & 1;
149
150 pixel_width = pixel_width >> 1;
151
152 if (brush_alpha == 0xff)
153 {
154 for (row = 0; row < y_height; row++)
155 {
156 col = 0;
157 glyph_data = glyph_row;
158
159 if (leading_pixel)
160 {
161 alpha = (*glyph_data) & 0x0f;
162 alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha << 4));
163
164 if (alpha > 0)
165 {
166 blend_func(context,
167 rotated_left + (GX_VALUE)col,
168 rotated_top + (GX_VALUE)row,
169 text_color, (GX_UBYTE)alpha);
170 }
171 col++;
172 glyph_data++;
173 }
174
175 for (index = 0; index < pixel_width; index++)
176 {
177 alpha = (*glyph_data) & 0xf0;
178 alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha >> 4));
179
180 if (alpha > 0)
181 {
182 blend_func(context,
183 rotated_left + (GX_VALUE)col,
184 rotated_top + (GX_VALUE)row,
185 text_color, (GX_UBYTE)alpha);
186 }
187 col++;
188
189 alpha = (*glyph_data) & 0x0f;
190 alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha << 4));
191
192 if (alpha > 0)
193 {
194 blend_func(context,
195 rotated_left + (GX_VALUE)col,
196 rotated_top + (GX_VALUE)row,
197 text_color, (GX_UBYTE)alpha);
198 }
199 col++;
200 glyph_data++;
201 }
202
203 if (trailing_pixel)
204 {
205 alpha = (*glyph_data) & 0xf0;
206 alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha >> 4));
207
208 if (alpha > 0)
209 {
210 blend_func(context,
211 rotated_left + (GX_VALUE)col,
212 rotated_top + (GX_VALUE)row,
213 text_color, (GX_UBYTE)alpha);
214 }
215 }
216 glyph_row += pitch;
217 }
218 }
219 #if defined(GX_BRUSH_ALPHA_SUPPORT)
220 else
221 {
222 for (row = 0; row < y_height; row++)
223 {
224 col = 0;
225 glyph_data = glyph_row;
226
227 if (leading_pixel)
228 {
229 alpha = (*glyph_data) & 0x0f;
230 alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha << 4));
231
232 alpha_sum = alpha * brush_alpha / 255;
233
234 if (alpha_sum > 0)
235 {
236 blend_func(context,
237 rotated_left + (GX_VALUE)col,
238 rotated_top + (GX_VALUE)row,
239 text_color, (GX_UBYTE)alpha_sum);
240 }
241 col++;
242 glyph_data++;
243 }
244
245 for (index = 0; index < pixel_width; index++)
246 {
247 alpha = (*glyph_data) & 0xf0;
248 alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha >> 4));
249 alpha_sum = alpha * brush_alpha / 255;
250
251 if (alpha_sum > 0)
252 {
253 blend_func(context,
254 rotated_left + (GX_VALUE)col,
255 rotated_top + (GX_VALUE)row,
256 text_color, (GX_UBYTE)alpha_sum);
257 }
258 col++;
259
260 alpha = (*glyph_data) & 0x0f;
261 alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha << 4));
262 alpha_sum = alpha * brush_alpha / 255;
263
264 if (alpha_sum > 0)
265 {
266 blend_func(context,
267 rotated_left + (GX_VALUE)col,
268 rotated_top + (GX_VALUE)row,
269 text_color, (GX_UBYTE)alpha_sum);
270 }
271 col++;
272 glyph_data++;
273 }
274
275 if (trailing_pixel)
276 {
277 alpha = (*glyph_data) & 0xf0;
278 alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha >> 4));
279 alpha_sum = alpha * brush_alpha / 255;
280
281 if (alpha_sum > 0)
282 {
283 blend_func(context,
284 rotated_left + (GX_VALUE)col,
285 rotated_top + (GX_VALUE)row,
286 text_color, (GX_UBYTE)alpha_sum);
287 }
288 }
289 glyph_row += pitch;
290 }
291 }
292 #endif
293 }
294
295