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_8bpp_glyph_4bit_draw             PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This 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 /*    None                                                                */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    _gx_canvas_text_draw                                                */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
74 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_gx_display_driver_8bpp_glyph_4bit_draw(GX_DRAW_CONTEXT * context,GX_RECTANGLE * draw_area,GX_POINT * map_offset,GX_CONST GX_GLYPH * glyph)78 VOID _gx_display_driver_8bpp_glyph_4bit_draw(GX_DRAW_CONTEXT *context, GX_RECTANGLE *draw_area, GX_POINT *map_offset, GX_CONST GX_GLYPH *glyph)
79 {
80 GX_UBYTE *glyph_row;
81 GX_UBYTE *glyph_data;
82 UINT      row;
83 UINT      pixel_width = 0;
84 UINT      leading_pixel;
85 UINT      trailing_pixel;
86 GX_UBYTE  text_color;
87 UINT      y_height;
88 GX_UBYTE  alpha;
89 UINT      pitch;
90 UINT      index;
91 GX_UBYTE *put;
92 GX_UBYTE *draw_start;
93 
94     text_color =  (GX_UBYTE)(context -> gx_draw_context_brush.gx_brush_line_color + 15);
95     pixel_width = (UINT)(draw_area -> gx_rectangle_right - draw_area -> gx_rectangle_left + 1);
96 
97     /* Find the width of the glyph */
98     pitch = glyph -> gx_glyph_width;
99     /* Make it byte-aligned. */
100     pitch = (pitch + 1) >> 1;
101 
102     glyph_row = (GX_UBYTE *)glyph -> gx_glyph_map;
103 
104     if (map_offset -> gx_point_y)
105     {
106         glyph_row = glyph_row + ((INT)pitch * map_offset -> gx_point_y);
107     }
108 
109     glyph_row += (map_offset -> gx_point_x >> 1);
110 
111     y_height = (UINT)(draw_area -> gx_rectangle_bottom - draw_area -> gx_rectangle_top + 1);
112 
113     leading_pixel = (map_offset -> gx_point_x & 1);
114 
115     pixel_width -= leading_pixel;
116 
117     trailing_pixel = pixel_width & 1;
118 
119     pixel_width = pixel_width >> 1;
120 
121 
122     draw_start = (GX_UBYTE *)context -> gx_draw_context_memory;
123     draw_start += context -> gx_draw_context_pitch * draw_area -> gx_rectangle_top;
124     draw_start += draw_area -> gx_rectangle_left;
125 
126     for (row = 0; row < y_height; row++)
127     {
128         glyph_data = glyph_row;
129 
130         put = draw_start;
131 
132         if (leading_pixel)
133         {
134             alpha = (*glyph_data) & 0x0f;
135 
136             *put = (GX_UBYTE)(text_color - alpha);
137             put++;
138 
139             glyph_data++;
140         }
141         for (index = 0; index < pixel_width; index++)
142         {
143             alpha = (*glyph_data) & 0xf0;
144 
145             *put = (GX_UBYTE)(text_color - (alpha >> 4));
146             put++;
147 
148             alpha = (*glyph_data) & 0x0f;
149             *put = (GX_UBYTE)(text_color - alpha);
150             put++;
151             glyph_data++;
152         }
153 
154         if (trailing_pixel)
155         {
156             alpha = (*glyph_data) & 0xf0;
157             *put = (GX_UBYTE)(text_color - (alpha >> 4));
158             put++;
159         }
160 
161         glyph_row += pitch;
162         draw_start += context -> gx_draw_context_pitch;
163     }
164 }
165 
166