GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_8bpp_rotated_glyph_1bit_draw.c Lines: 68 68 100.0 %
Date: 2026-03-06 19:21:09 Branches: 40 40 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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
40
#if defined(GX_BRUSH_ALPHA_SUPPORT)
41
#define BLEND_PIXEL if (alpha & mask)                             \
42
    {                                                             \
43
        blend_func(context, xval, yval, text_color, brush_alpha); \
44
    }                                                             \
45
    xval++;                                                       \
46
    mask = mask >> 1;
47
#endif
48
49
/**************************************************************************/
50
/*                                                                        */
51
/*  FUNCTION                                               RELEASE        */
52
/*                                                                        */
53
/*    _gx_display_driver_8bpp_rotated_glyph_1bit_draw     PORTABLE C      */
54
/*                                                           6.1.4        */
55
/*  AUTHOR                                                                */
56
/*                                                                        */
57
/*    Kenneth Maxwell, Microsoft Corporation                              */
58
/*                                                                        */
59
/*  DESCRIPTION                                                           */
60
/*                                                                        */
61
/*    This function draws monochrome font to the 8bpp canvas, clipped     */
62
/*    to one viweport.                                                    */
63
/*                                                                        */
64
/*  INPUT                                                                 */
65
/*                                                                        */
66
/*    context                               Draw context                  */
67
/*    draw_area                             The region bound by the       */
68
/*                                            rectangle where the glyph   */
69
/*                                            is drawn                    */
70
/*    map_offset                            X,Y offset into the glyph map */
71
/*    glyph                                 Pointer to the glyph          */
72
/*                                                                        */
73
/*  OUTPUT                                                                */
74
/*                                                                        */
75
/*    None                                                                */
76
/*                                                                        */
77
/*  CALLS                                                                 */
78
/*                                                                        */
79
/*    [gx_display_driver_pixel_blend]       Basic display driver pixel    */
80
/*                                            blend function              */
81
/*                                                                        */
82
/*  CALLED BY                                                             */
83
/*                                                                        */
84
/*    GUIX internal code                                                  */
85
/*                                                                        */
86
/**************************************************************************/
87
248928
VOID _gx_display_driver_8bpp_rotated_glyph_1bit_draw(GX_DRAW_CONTEXT *context, GX_RECTANGLE *draw_area, GX_POINT *map_offset, GX_CONST GX_GLYPH *glyph)
88
{
89
GX_UBYTE *glyph_row;
90
GX_UBYTE *glyph_data;
91
UINT      row;
92
UINT      pixel_per_row;
93
UINT      pixel_in_first_byte;
94
248928
UINT      pixel_in_last_byte = 0;
95
GX_UBYTE  text_color;
96
UINT      y_height;
97
GX_UBYTE  alpha;
98
UINT      glyph_width;
99
GX_UBYTE *put;
100
UINT      num_bytes;
101
UINT      num_bits;
102
GX_UBYTE *line_start;
103
GX_UBYTE  mask, init_mask;
104
UINT      i;
105
GX_VALUE  rotated_map_offset_x;
106
GX_VALUE  rotated_map_offset_y;
107
GX_VALUE  rotated_draw_left;
108
GX_VALUE  rotated_draw_top;
109
110
248928
    text_color =  (GX_UBYTE)context -> gx_draw_context_brush.gx_brush_line_color;
111
248928
    pixel_per_row = (UINT)draw_area -> gx_rectangle_bottom - (UINT)draw_area -> gx_rectangle_top + (UINT)1;
112
248928
    y_height = (UINT)(draw_area -> gx_rectangle_right - draw_area -> gx_rectangle_left + 1);
113
114
    /* Find the width of the glyph, in terms of bytes */
115
248928
    glyph_width = glyph -> gx_glyph_height;
116
117
    /* Make it byte-aligned. */
118
248928
    glyph_width = (glyph_width + 7) >> 3;
119
120
248928
    if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
121
    {
122
125957
        rotated_draw_left = draw_area -> gx_rectangle_top;
123
125957
        rotated_draw_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - draw_area -> gx_rectangle_right - 1);
124
125
125957
        rotated_map_offset_x = map_offset -> gx_point_y;
126
125957
        rotated_map_offset_y = (GX_VALUE)(glyph -> gx_glyph_width - map_offset -> gx_point_x - (GX_VALUE)y_height);
127
    }
128
    else
129
    {
130
122971
        rotated_draw_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_display_offset_y - draw_area -> gx_rectangle_bottom - 1);
131
122971
        rotated_draw_top = draw_area -> gx_rectangle_left;
132
133
122971
        rotated_map_offset_x = (GX_VALUE)(glyph -> gx_glyph_height - map_offset -> gx_point_y - (GX_VALUE)pixel_per_row);
134
122971
        rotated_map_offset_y = map_offset -> gx_point_x;
135
    }
136
137
    /* Compute the number of useful bytes from the glyph this routine is going to use.
138
       Because of map_offset, the first byte may contain pixel bits we don't need to draw;
139
       And the width of the draw_area may produce part of the last byte in the row to be ignored.  */
140
248928
    num_bytes = ((UINT)rotated_map_offset_x  + pixel_per_row + 7) >> 3;
141
142
    /* Take into account if map_offset specifies the number of bytes to ignore from the beginning of the row.  */
143
248928
    num_bytes -= (UINT)(rotated_map_offset_x) >> 3;
144
145
    /* Compute the number of pixels to draw from the first byte of the glyph data.  */
146
248928
    pixel_in_first_byte = (UINT)(8 - (rotated_map_offset_x & 0x7));
147
248928
    init_mask = (GX_UBYTE)(1 << (pixel_in_first_byte - 1));
148
149
    /* Compute the number of pixels to draw from the last byte, if there are more than one byte in a row.  */
150
248928
    if (num_bytes != 1)
151
    {
152
236969
        pixel_in_last_byte = (rotated_map_offset_x + (INT)pixel_per_row) & 0x7;
153
236969
        if (pixel_in_last_byte == 0)
154
        {
155
9
            pixel_in_last_byte = 8;
156
        }
157
    }
158
    else
159
    {
160
11959
        pixel_in_first_byte = pixel_per_row;
161
    }
162
163
164
248928
    glyph_row = (GX_UBYTE *)glyph -> gx_glyph_map;
165
166
248928
    if (rotated_map_offset_y)
167
    {
168
59
        glyph_row = glyph_row + ((INT)glyph_width * rotated_map_offset_y);
169
    }
170
171
248928
    glyph_row += (rotated_map_offset_x >> 3);
172
173
248928
    line_start = (GX_UBYTE *)context -> gx_draw_context_memory;
174
248928
    line_start += context -> gx_draw_context_pitch * rotated_draw_top;
175
248928
    line_start += rotated_draw_left;
176
177
2001917
    for (row = 0; row < y_height; row++)
178
    {
179
1752989
        glyph_data = glyph_row;
180
1752989
        alpha = *(glyph_data);
181
1752989
        mask = init_mask;
182
1752989
        num_bits = pixel_in_first_byte;
183
1752989
        put = line_start;
184
185
5248655
        for (i = 0; i < num_bytes; i++)
186
        {
187

3495666
            if ((i == (num_bytes - 1)) && (num_bytes > 1))
188
            {
189
1737754
                num_bits = pixel_in_last_byte;
190
            }
191


3495666
            switch (num_bits)
192
            {
193
1742525
            case 8:
194
1742525
                DRAW_PIXEL;
195
            /* fallthrough */
196
1743427
            case 7:
197
1743427
                DRAW_PIXEL;
198
            /* fallthrough */
199
2101478
            case 6:
200
2101478
                DRAW_PIXEL;
201
            /* fallthrough */
202
2574651
            case 5:
203
2574651
                DRAW_PIXEL;
204
            /* fallthrough */
205
2577954
            case 4:
206
2577954
                DRAW_PIXEL;
207
            /* fallthrough */
208
2578089
            case 3:
209
2578089
                DRAW_PIXEL;
210
            /* fallthrough */
211
3474738
            case 2:
212
3474738
                DRAW_PIXEL;
213
            /* fallthrough */
214
215
3495666
            default:
216
3495666
                if (alpha & mask)
217
                {
218
1592545
                    *put = text_color;
219
                }
220
3495666
                put++;
221
3495666
                break;
222
            }
223
3495666
            glyph_data++;
224
3495666
            alpha = *(glyph_data);
225
3495666
            num_bits = 8;
226
3495666
            mask = 0x80;
227
        }
228
229
1752989
        glyph_row += glyph_width;
230
1752989
        line_start += context -> gx_draw_context_pitch;
231
    }
232
233
248928
    return;
234
}
235