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 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _gx_display_driver_generic_rotated_glyph_8bit_draw  PORTABLE C      */
38 /*                                                           6.1.3        */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function draws the specified text using the current context,   */
46 /*    clipped to one viewport                                             */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    context                               Draw context                  */
51 /*    draw_position                         The X and Y coordinate where  */
52 /*                                            the glyph is drawn to       */
53 /*    string                                String to draw                */
54 /*    count                                 Count of string characters    */
55 /*    view                                  view to clip drawing within   */
56 /*                                                                        */
57 /*  OUTPUT                                                                */
58 /*                                                                        */
59 /*    None                                                                */
60 /*                                                                        */
61 /*  CALLS                                                                 */
62 /*                                                                        */
63 /*    _gx_display_driver_565rgb_pixel_blend Call display driver pixel     */
64 /*                                            blend function              */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    GUIX internal code                                                  */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  12-31-2020     Kenneth Maxwell          Initial Version 6.1.3         */
75 /*                                                                        */
76 /**************************************************************************/
_gx_display_driver_generic_rotated_glyph_8bit_draw(GX_DRAW_CONTEXT * context,GX_RECTANGLE * draw_area,GX_POINT * map_offset,GX_CONST GX_GLYPH * glyph)77 VOID _gx_display_driver_generic_rotated_glyph_8bit_draw(GX_DRAW_CONTEXT *context, GX_RECTANGLE *draw_area, GX_POINT *map_offset, GX_CONST GX_GLYPH *glyph)
78 {
79 GX_UBYTE *glyph_row;
80 GX_UBYTE *glyph_data;
81 UINT      row;
82 UINT      col;
83 UINT      pixel_width = 0;
84 GX_COLOR  text_color;
85 UINT      y_height;
86 GX_UBYTE  alpha1;
87 GX_UBYTE  brush_alpha = 0xff;
88 GX_VALUE  rotated_map_offset_x;
89 GX_VALUE  rotated_map_offset_y;
90 GX_VALUE  rotated_left;
91 GX_VALUE  rotated_top;
92 VOID     (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR color, GX_UBYTE alpha);
93 
94 #if defined(GX_BRUSH_ALPHA_SUPPORT)
95     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
96     if (brush_alpha == 0)
97     {
98         return;
99     }
100 #endif
101 
102     GX_SET_BLEND_FUNCTION(blend_func, context->gx_draw_context_display->gx_display_color_format)
103 
104     text_color = context -> gx_draw_context_brush.gx_brush_line_color;
105 
106     pixel_width = (UINT)(draw_area -> gx_rectangle_bottom - draw_area -> gx_rectangle_top + 1);
107     y_height = (UINT)(draw_area -> gx_rectangle_right - draw_area -> gx_rectangle_left + 1);
108 
109     if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
110     {
111         rotated_left = draw_area -> gx_rectangle_top;
112         rotated_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - draw_area -> gx_rectangle_right - 1);
113 
114         rotated_map_offset_x = map_offset -> gx_point_y;
115         rotated_map_offset_y = (GX_VALUE)(glyph -> gx_glyph_width - map_offset -> gx_point_x - (GX_VALUE)y_height);
116     }
117     else
118     {
119         rotated_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_display_offset_y - draw_area -> gx_rectangle_bottom - 1);
120         rotated_top = draw_area -> gx_rectangle_left;
121 
122         rotated_map_offset_x = (GX_VALUE)(glyph -> gx_glyph_height - map_offset -> gx_point_y - (GX_VALUE)pixel_width);
123         rotated_map_offset_y = map_offset -> gx_point_x;
124     }
125 
126     glyph_row = (GX_UBYTE *)glyph -> gx_glyph_map;
127 
128     if (rotated_map_offset_y)
129     {
130         glyph_row = glyph_row + (glyph -> gx_glyph_height * rotated_map_offset_y);
131     }
132 
133     glyph_row += rotated_map_offset_x;
134 
135     if (brush_alpha == 0xff)
136     {
137         for (row = 0; row < y_height; row++)
138         {
139             glyph_data = glyph_row;
140 
141             for (col = 0; col < pixel_width; col++)
142             {
143                 alpha1 = *glyph_data;
144 
145                 if (alpha1 > 0)
146                 {
147                     blend_func(context,
148                                rotated_left + (GX_VALUE)col,
149                                rotated_top + (GX_VALUE)row,
150                                text_color, (GX_UBYTE)alpha1);
151                 }
152                 glyph_data++;
153             }
154             glyph_row += glyph -> gx_glyph_height;
155         }
156     }
157 #if defined(GX_BRUSH_ALPHA_SUPPORT)
158     else
159     {
160         for (row = 0; row < y_height; row++)
161         {
162             glyph_data = glyph_row;
163 
164             for (col = 0; col < pixel_width; col++)
165             {
166                 alpha1 = *glyph_data;
167                 alpha1 = (GX_UBYTE)(alpha1 * brush_alpha / 255);
168 
169                 if (alpha1 > 0)
170                 {
171                     blend_func(context,
172                                rotated_left + (GX_VALUE)col,
173                                rotated_top + (GX_VALUE)row,
174                                text_color, (GX_UBYTE)alpha1);
175                 }
176 
177                 glyph_data++;
178             }
179             glyph_row += glyph -> gx_glyph_height;
180         }
181     }
182 #endif
183 }
184 
185