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_glyph_8bit_draw          PORTABLE C      */
38 /*                                                           6.1          */
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_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 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
75 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
76 /*                                            resulting in version 6.1    */
77 /*                                                                        */
78 /**************************************************************************/
_gx_display_driver_generic_glyph_8bit_draw(GX_DRAW_CONTEXT * context,GX_RECTANGLE * draw_area,GX_POINT * map_offset,GX_CONST GX_GLYPH * glyph)79 VOID _gx_display_driver_generic_glyph_8bit_draw(GX_DRAW_CONTEXT *context, GX_RECTANGLE *draw_area, GX_POINT *map_offset, GX_CONST GX_GLYPH *glyph)
80 {
81 GX_DISPLAY *display;
82 GX_UBYTE   *glyph_row;
83 GX_UBYTE   *glyph_data;
84 UINT        row;
85 UINT        col;
86 UINT        pixel_width = 0;
87 GX_COLOR    text_color;
88 UINT        y_height;
89 GX_UBYTE    alpha1;
90 GX_UBYTE    brush_alpha = 0xff;
91 
92 #if defined (GX_BRUSH_ALPHA_SUPPORT)
93     brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
94     if (brush_alpha == 0)
95     {
96         return;
97     }
98 #endif
99 
100     text_color =  context -> gx_draw_context_brush.gx_brush_line_color;
101     pixel_width = (UINT)(draw_area -> gx_rectangle_right - draw_area -> gx_rectangle_left + 1);
102 
103     /* pickup pointer to current display driver */
104     display = context -> gx_draw_context_display;
105 
106     if (display -> gx_display_driver_pixel_blend == GX_NULL)
107     {
108         return;
109     }
110 
111     glyph_row = (GX_UBYTE *)glyph -> gx_glyph_map;
112 
113     if (map_offset -> gx_point_y)
114     {
115         glyph_row = glyph_row + (glyph -> gx_glyph_width * map_offset -> gx_point_y);
116     }
117 
118     glyph_row += map_offset -> gx_point_x;
119 
120     y_height = (UINT)(draw_area -> gx_rectangle_bottom - draw_area -> gx_rectangle_top + 1);
121 
122     if (brush_alpha == 0xff)
123     {
124         for (row = 0; row < y_height; row++)
125         {
126             glyph_data = glyph_row;
127 
128             for (col = 0; col < pixel_width; col++)
129             {
130                 alpha1 = *glyph_data;
131 
132                 if (alpha1 > 0)
133                 {
134                     display -> gx_display_driver_pixel_blend(context,
135                                                            draw_area -> gx_rectangle_left + (GX_VALUE)col,
136                                                            draw_area -> gx_rectangle_top + (GX_VALUE)row,
137                                                            text_color, (GX_UBYTE)alpha1);
138                 }
139                 glyph_data++;
140             }
141             glyph_row += glyph -> gx_glyph_width;
142         }
143     }
144 #if defined (GX_BRUSH_ALPHA_SUPPORT)
145     else
146     {
147         for (row = 0; row < y_height; row++)
148         {
149             glyph_data = glyph_row;
150 
151             for (col = 0; col < pixel_width; col++)
152             {
153                 alpha1 = *glyph_data;
154                 alpha1 = (GX_UBYTE)(alpha1 * brush_alpha / 255);
155 
156                 if (alpha1 > 0)
157                 {
158                     display -> gx_display_driver_pixel_blend(context,
159                                                            draw_area -> gx_rectangle_left + (GX_VALUE)col,
160                                                            draw_area -> gx_rectangle_top + (GX_VALUE)row,
161                                                            text_color, (GX_UBYTE)alpha1);
162                 }
163 
164                 glyph_data++;
165             }
166             glyph_row += glyph -> gx_glyph_width;
167         }
168     }
169 #endif
170 }
171 
172