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

2691928
            if ((i == (num_bytes - 1)) && (num_bytes > 1))
182
            {
183
755192
                num_bits = pixel_in_last_byte;
184
            }
185


2691928
            switch (num_bits)
186
            {
187
1114030
            case 8:
188

1114030
                WRITE_PIXEL;
189
1114030
                mask >>= 1;
190
                /* fallthrough */
191
1256791
            case 7:
192

1256791
                WRITE_PIXEL;
193
1256791
                mask >>= 1;
194
                /* fallthrough */
195
1595866
            case 6:
196

1595866
                WRITE_PIXEL;
197
1595866
                mask >>= 1;
198
                /* fallthrough */
199
1666250
            case 5:
200

1666250
                WRITE_PIXEL;
201
1666250
                mask >>= 1;
202
                /* fallthrough */
203
1678393
            case 4:
204

1678393
                WRITE_PIXEL;
205
1678393
                mask >>= 1;
206
                /* fallthrough */
207
1688733
            case 3:
208

1688733
                WRITE_PIXEL;
209
1688733
                mask >>= 1;
210
                /* fallthrough */
211
2378685
            case 2:
212

2378685
                WRITE_PIXEL;
213
2378685
                mask >>= 1;
214
                /* fallthrough */
215
2691928
            default:
216

2691928
                WRITE_PIXEL;
217
            }
218
2691928
            glyph_data++;
219
2691928
            alpha = *(glyph_data);
220
2691928
            num_bits = 8;
221
2691928
            mask = 0x80;
222
        }
223
224
1936682
        glyph_row +=  glyph_width;
225
1936682
        line_start += putstride;
226
    }
227
228
163700
    return;
229
}
230