GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_32bpp_glyph_1bit_draw.c Lines: 97 97 100.0 %
Date: 2026-03-06 19:21:09 Branches: 76 76 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
#if defined (GX_BRUSH_ALPHA_SUPPORT)
40
#define BLEND_PIXEL if (alpha & mask)                                                        \
41
    {                                                                                        \
42
        _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, text_color, brush_alpha); \
43
    }                                                                                        \
44
    xval++;                                                                                  \
45
    mask = mask >> 1;
46
#endif
47
48
/**************************************************************************/
49
/*                                                                        */
50
/*  FUNCTION                                               RELEASE        */
51
/*                                                                        */
52
/*    _gx_display_driver_32bpp_glyph_1bit_draw            PORTABLE C      */
53
/*                                                           6.1.11       */
54
/*  AUTHOR                                                                */
55
/*                                                                        */
56
/*    Kenneth Maxwell, Microsoft Corporation                              */
57
/*                                                                        */
58
/*  DESCRIPTION                                                           */
59
/*                                                                        */
60
/*    This functions draw monochrome font on 32bpp canvas, clipped to     */
61
/*    one viewport.                                                       */
62
/*                                                                        */
63
/*  INPUT                                                                 */
64
/*                                                                        */
65
/*    context                               Draw context                  */
66
/*    draw_area                             The region bound by the       */
67
/*                                            rectangle where the glyph   */
68
/*                                            is drawn                    */
69
/*    map_offset                            X,Y offset into the glyph map */
70
/*    glyph                                 Pointer to the glyph          */
71
/*                                                                        */
72
/*  OUTPUT                                                                */
73
/*                                                                        */
74
/*    None                                                                */
75
/*                                                                        */
76
/*  CALLS                                                                 */
77
/*                                                                        */
78
/*    _gx_display_driver_24xrgb_pixel_blend Display driver basic pixel    */
79
/*                                            blend function              */
80
/*                                                                        */
81
/*  CALLED BY                                                             */
82
/*                                                                        */
83
/*    GUIX internal code                                                  */
84
/*                                                                        */
85
/**************************************************************************/
86
297866
VOID _gx_display_driver_32bpp_glyph_1bit_draw(GX_DRAW_CONTEXT *context, GX_RECTANGLE *draw_area, GX_POINT *map_offset, GX_CONST GX_GLYPH *glyph)
87
{
88
GX_UBYTE *glyph_row;
89
GX_UBYTE *glyph_data;
90
UINT      row;
91
UINT      pixel_per_row;
92
UINT      pixel_in_first_byte;
93
297866
UINT      pixel_in_last_byte = 0;
94
GX_COLOR  text_color;
95
UINT      y_height;
96
GX_UBYTE  alpha;
97
UINT      glyph_width;
98
UINT     *put;
99
UINT      num_bytes;
100
UINT      num_bits;
101
UINT     *line_start;
102
GX_UBYTE  mask, init_mask;
103
UINT      i;
104
105
#if defined (GX_BRUSH_ALPHA_SUPPORT)
106
GX_UBYTE  brush_alpha;
107
INT       xval, yval;
108
109
297866
    brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
110
297866
    if (brush_alpha == 0)
111
    {
112
67
        return;
113
    }
114
#endif
115
116
297799
    text_color = context -> gx_draw_context_brush.gx_brush_line_color;
117
297799
    pixel_per_row = (UINT)(draw_area -> gx_rectangle_right - draw_area -> gx_rectangle_left + 1);
118
119
    /* pickup pointer to current dispaly driver */
120
    /*display = context -> gx_draw_context_display;*/
121
122
    /* Find the width of the glyph, in terms of bytes */
123
297799
    glyph_width = glyph -> gx_glyph_width;
124
    /* Make it byte-aligned. */
125
297799
    glyph_width = (glyph_width + 7) >> 3;
126
127
    /* Compute the number of useful bytes from the glyph this routine is going to use.
128
       Because of map_offset, the first byte may contain pixel bits we don't need to draw;
129
       And the width of the draw_area may produce part of the last byte in the row to be ignored. */
130
297799
    num_bytes = (UINT)(((UINT)(map_offset -> gx_point_x) + pixel_per_row + 7) >> 3);
131
    /* Take into account if map_offset specifies the number of bytes to ignore from the beginning of the row. */
132
297799
    num_bytes = num_bytes - (((UINT)(map_offset -> gx_point_x)) >> 3);
133
134
    /* Compute the number of pixels to draw from the first byte of the glyph data. */
135
297799
    pixel_in_first_byte = 8 - (UINT)((map_offset -> gx_point_x) & 0x7);
136
297799
    init_mask = (GX_UBYTE)(1 << (pixel_in_first_byte - 1));
137
    /* Compute the number of pixels to draw from the last byte, if there are more than one byte in a row. */
138
297799
    if (num_bytes != 1)
139
    {
140
39840
        pixel_in_last_byte = (((UINT)(map_offset -> gx_point_x) + pixel_per_row) & 0x7);
141
39840
        if (pixel_in_last_byte == 0)
142
        {
143
56
            pixel_in_last_byte = 8;
144
        }
145
    }
146
    else
147
    {
148
257959
        if (((UINT)(map_offset -> gx_point_x) + pixel_per_row) < 8)
149
        {
150
209130
            pixel_in_first_byte = pixel_per_row;
151
        }
152
        else
153
        {
154
48829
            pixel_in_last_byte = 0;
155
        }
156
    }
157
158
297799
    glyph_row = (GX_UBYTE *)glyph -> gx_glyph_map;
159
160
297799
    if (map_offset -> gx_point_y)
161
    {
162
2450
        glyph_row = glyph_row + ((INT)glyph_width * (INT)(map_offset -> gx_point_y));
163
    }
164
165
297799
    glyph_row += (map_offset -> gx_point_x >> 3);
166
167
297799
    y_height = (UINT)(draw_area -> gx_rectangle_bottom - draw_area -> gx_rectangle_top + 1);
168
169
#if defined (GX_BRUSH_ALPHA_SUPPORT)
170
297799
    if (brush_alpha != 0xff)
171
    {
172
145262
        yval = draw_area -> gx_rectangle_top;
173
1377653
        for (row = 0; row < y_height; row++)
174
        {
175
1232391
            xval = draw_area -> gx_rectangle_left;
176
1232391
            glyph_data = glyph_row;
177
1232391
            mask = init_mask;
178
1232391
            num_bits = pixel_in_first_byte;
179
2683983
            for (i = 0; i < num_bytes; i++)
180
            {
181
1451592
                alpha = *(glyph_data++);
182
183

1451592
                if ((i == (num_bytes - 1)) && (num_bytes > 1))
184
                {
185
219201
                    num_bits = pixel_in_last_byte;
186
                }
187


1451592
                switch (num_bits)
188
                {
189
485217
                case 8:
190
485217
                    BLEND_PIXEL;
191
                    /* fallthrough */
192
787293
                case 7:
193
787293
                    BLEND_PIXEL;
194
                    /* fallthrough */
195
916077
                case 6:
196
916077
                    BLEND_PIXEL;
197
                    /* fallthrough */
198
984654
                case 5:
199
984654
                    BLEND_PIXEL;
200
                    /* fallthrough */
201
1085868
                case 4:
202
1085868
                    BLEND_PIXEL;
203
                    /* fallthrough */
204
1175097
                case 3:
205
1175097
                    BLEND_PIXEL;
206
                    /* fallthrough */
207
1282077
                case 2:
208
1282077
                    BLEND_PIXEL;
209
                    /* fallthrough */
210
1451592
                default:
211
1451592
                    if (alpha & mask)
212
                    {
213
514418
                        _gx_display_driver_24xrgb_pixel_blend(context, xval, yval, text_color, brush_alpha);
214
                    }
215
1451592
                    xval++;
216
1451592
                    break;
217
                }
218
1451592
                num_bits = 8;
219
1451592
                mask = 0x80;
220
            }
221
222
1232391
            glyph_row += glyph_width;
223
1232391
            yval++;
224
        }
225
    }
226
    else
227
    {
228
#endif
229
152537
        line_start = (UINT *)context -> gx_draw_context_memory;
230
152537
        line_start += context -> gx_draw_context_pitch * (draw_area -> gx_rectangle_top);
231
152537
        line_start += draw_area -> gx_rectangle_left;
232
233
1469944
        for (row = 0; row < y_height; row++)
234
        {
235
1317407
            glyph_data = glyph_row;
236
1317407
            mask = init_mask;
237
1317407
            num_bits = pixel_in_first_byte;
238
1317407
            put = line_start;
239
2865400
            for (i = 0; i < num_bytes; i++)
240
            {
241
1547993
                alpha = *(glyph_data++);
242
243

1547993
                if ((i == (num_bytes - 1)) && (num_bytes > 1))
244
                {
245
228874
                    num_bits = pixel_in_last_byte;
246
                }
247


1547993
                switch (num_bits)
248
                {
249
526841
                case 8:
250
526841
                    DRAW_PIXEL;
251
                    /* fallthrough */
252
860691
                case 7:
253
860691
                    DRAW_PIXEL;
254
                    /* fallthrough */
255
991867
                case 6:
256
991867
                    DRAW_PIXEL;
257
                    /* fallthrough */
258
1066358
                case 5:
259
1066358
                    DRAW_PIXEL;
260
                    /* fallthrough */
261
1168745
                case 4:
262
1168745
                    DRAW_PIXEL;
263
                    /* fallthrough */
264
1258658
                case 3:
265
1258658
                    DRAW_PIXEL;
266
                    /* fallthrough */
267
1377185
                case 2:
268
1377185
                    DRAW_PIXEL;
269
                    /* fallthrough */
270
1547993
                default:
271
1547993
                    if (alpha & mask)
272
                    {
273
550862
                        *put = text_color;
274
                    }
275
1547993
                    put++;
276
1547993
                    break;
277
                }
278
1547993
                num_bits = 8;
279
1547993
                mask = 0x80;
280
            }
281
282
1317407
            glyph_row += glyph_width;
283
1317407
            line_start += context -> gx_draw_context_pitch;
284
        }
285
#if defined (GX_BRUSH_ALPHA_SUPPORT)
286
    }
287
#endif
288
297799
    return;
289
}
290