GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_generic_glyph_4bpp_draw.c Lines: 104 104 100.0 %
Date: 2024-12-05 08:52:37 Branches: 40 40 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** GUIX Component                                                        */
16
/**                                                                       */
17
/**   Display Management (Display)                                        */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_system.h"
28
#include "gx_utility.h"
29
#include "gx_display.h"
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_display_driver_generic_glyph_4bit_draw          PORTABLE C      */
36
/*                                                           6.1          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function draws the specified text using the current context,   */
44
/*    clipped to one viewport                                             */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    context                               Draw context                  */
49
/*    draw_area                             The rectangle where the glyph */
50
/*                                            is drawn to                 */
51
/*    map_offset                            Offset from the glyph map     */
52
/*    glyph                                 The glyph structure           */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    None                                                                */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    [gx_display_driver_pixel_blend]       Call display driver pixel     */
61
/*                                            blend function              */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    GUIX internal code                                                  */
66
/*                                                                        */
67
/*  RELEASE HISTORY                                                       */
68
/*                                                                        */
69
/*    DATE              NAME                      DESCRIPTION             */
70
/*                                                                        */
71
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
72
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
73
/*                                            resulting in version 6.1    */
74
/*                                                                        */
75
/**************************************************************************/
76
448976
VOID _gx_display_driver_generic_glyph_4bit_draw(GX_DRAW_CONTEXT *context, GX_RECTANGLE *draw_area, GX_POINT *map_offset, GX_CONST GX_GLYPH *glyph)
77
{
78
GX_DISPLAY *display;
79
GX_UBYTE   *glyph_row;
80
GX_UBYTE   *glyph_data;
81
UINT        row;
82
UINT        col;
83
448976
UINT        pixel_width = 0;
84
UINT        leading_pixel;
85
UINT        trailing_pixel;
86
GX_COLOR    text_color;
87
UINT        y_height;
88
GX_UBYTE    alpha;
89
UINT        pitch;
90
UINT        index;
91
VOID        (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR color, GX_UBYTE alpha);
92
448976
GX_UBYTE    brush_alpha = 0xff;
93
94
#if defined (GX_BRUSH_ALPHA_SUPPORT)
95
INT         alpha_sum;
96
448976
    brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
97
448976
    if (brush_alpha == 0)
98
    {
99
2964
        return;
100
    }
101
#endif
102
103
446012
    text_color =  context -> gx_draw_context_brush.gx_brush_line_color;
104
446012
    pixel_width = (UINT)(draw_area -> gx_rectangle_right - draw_area -> gx_rectangle_left + 1);
105
106
    /* pickup pointer to current dispaly driver */
107
446012
    display = context -> gx_draw_context_display;
108
109
446012
    if (display -> gx_display_driver_pixel_blend == GX_NULL)
110
    {
111
196
        return;
112
    }
113
114
    /* Find the width of the glyph */
115
445816
    pitch = glyph -> gx_glyph_width;
116
    /* Make it byte-aligned. */
117
445816
    pitch = (pitch + 1) >> 1;
118
119
445816
    glyph_row = (GX_UBYTE *)glyph -> gx_glyph_map;
120
121
445816
    if (map_offset -> gx_point_y)
122
    {
123
4134
        glyph_row = glyph_row + ((INT)pitch * map_offset -> gx_point_y);
124
    }
125
126
445816
    glyph_row += (map_offset -> gx_point_x >> 1);
127
128
445816
    y_height = (UINT)(draw_area -> gx_rectangle_bottom - draw_area -> gx_rectangle_top + 1);
129
130
445816
    blend_func = display -> gx_display_driver_pixel_blend;
131
132
445816
    leading_pixel = (map_offset -> gx_point_x & 1);
133
134
445816
    pixel_width -= leading_pixel;
135
136
445816
    trailing_pixel = pixel_width & 1;
137
138
445816
    pixel_width = pixel_width >> 1;
139
140
445816
    if (brush_alpha == 0xff)
141
    {
142
2747197
        for (row = 0; row < y_height; row++)
143
        {
144
2521900
            col = 0;
145
2521900
            glyph_data = glyph_row;
146
147
2521900
            if (leading_pixel)
148
            {
149
6828
                alpha = (*glyph_data) & 0x0f;
150
6828
                alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha << 4));
151
152
6828
                if (alpha > 0)
153
                {
154
4076
                    blend_func(context,
155
4076
                        draw_area -> gx_rectangle_left + (GX_VALUE)col,
156
4076
                        draw_area -> gx_rectangle_top + (GX_VALUE)row,
157
                        text_color, (GX_UBYTE)alpha);
158
                }
159
6828
                col++;
160
6828
                glyph_data++;
161
            }
162
163
11796242
            for (index = 0; index < pixel_width; index++)
164
            {
165
9274342
                alpha = (*glyph_data) & 0xf0;
166
9274342
                alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha >> 4));
167
168
9274342
                if (alpha > 0)
169
                {
170
4948529
                    blend_func(context,
171
4948529
                        draw_area -> gx_rectangle_left + (GX_VALUE)col,
172
4948529
                        draw_area -> gx_rectangle_top + (GX_VALUE)row,
173
                        text_color, (GX_UBYTE)alpha);
174
                }
175
9274342
                col++;
176
177
9274342
                alpha = (*glyph_data) & 0x0f;
178
9274342
                alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha << 4));
179
180
9274342
                if (alpha > 0)
181
                {
182
5093194
                    blend_func(context,
183
5093194
                        draw_area -> gx_rectangle_left + (GX_VALUE)col,
184
5093194
                        draw_area -> gx_rectangle_top + (GX_VALUE)row,
185
                        text_color, (GX_UBYTE)alpha);
186
                }
187
9274342
                col++;
188
9274342
                glyph_data++;
189
            }
190
191
2521900
            if (trailing_pixel)
192
            {
193
1446213
                alpha = (*glyph_data) & 0xf0;
194
1446213
                alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha >> 4));
195
196
1446213
                if (alpha > 0)
197
                {
198
466142
                    blend_func(context,
199
466142
                        draw_area -> gx_rectangle_left + (GX_VALUE)col,
200
466142
                        draw_area -> gx_rectangle_top + (GX_VALUE)row,
201
                        text_color, (GX_UBYTE)alpha);
202
                }
203
            }
204
2521900
            glyph_row += pitch;
205
        }
206
    }
207
#if defined (GX_BRUSH_ALPHA_SUPPORT)
208
    else
209
    {
210
2687188
        for (row = 0; row < y_height; row++)
211
        {
212
2466669
            col = 0;
213
2466669
            glyph_data = glyph_row;
214
215
2466669
            if (leading_pixel)
216
            {
217
6828
                alpha = (*glyph_data) & 0x0f;
218
6828
                alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha << 4));
219
220
6828
                alpha_sum = alpha * brush_alpha / 255;
221
222
6828
                if (alpha_sum > 0)
223
                {
224
4072
                    blend_func(context,
225
4072
                        draw_area->gx_rectangle_left + (GX_VALUE)col,
226
4072
                        draw_area->gx_rectangle_top + (GX_VALUE)row,
227
4072
                        text_color, (GX_UBYTE)alpha_sum);
228
                }
229
6828
                col++;
230
6828
                glyph_data++;
231
            }
232
233
11478714
            for (index = 0; index < pixel_width; index++)
234
            {
235
9012045
                alpha = (*glyph_data) & 0xf0;
236
9012045
                alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha >> 4));
237
9012045
                alpha_sum = alpha * brush_alpha / 255;
238
239
9012045
                if (alpha_sum > 0)
240
                {
241
4804379
                    blend_func(context,
242
4804379
                        draw_area -> gx_rectangle_left + (GX_VALUE)col,
243
4804379
                        draw_area -> gx_rectangle_top + (GX_VALUE)row,
244
4804379
                        text_color, (GX_UBYTE)alpha_sum);
245
                }
246
9012045
                col++;
247
248
9012045
                alpha = (*glyph_data) & 0x0f;
249
9012045
                alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha << 4));
250
9012045
                alpha_sum = alpha * brush_alpha / 255;
251
252
9012045
                if (alpha_sum > 0)
253
                {
254
4962546
                    blend_func(context,
255
4962546
                        draw_area -> gx_rectangle_left + (GX_VALUE)col,
256
4962546
                        draw_area -> gx_rectangle_top + (GX_VALUE)row,
257
4962546
                        text_color, (GX_UBYTE)alpha_sum);
258
                }
259
9012045
                col++;
260
9012045
                glyph_data++;
261
            }
262
263
2466669
            if (trailing_pixel)
264
            {
265
1418227
                alpha = (*glyph_data) & 0xf0;
266
1418227
                alpha = (GX_UBYTE)(alpha | (GX_UBYTE)(alpha >> 4));
267
1418227
                alpha_sum = alpha * brush_alpha / 255;
268
269
1418227
                if (alpha_sum > 0)
270
                {
271
456124
                    blend_func(context,
272
456124
                        draw_area -> gx_rectangle_left + (GX_VALUE)col,
273
456124
                        draw_area -> gx_rectangle_top + (GX_VALUE)row,
274
456124
                        text_color, (GX_UBYTE)alpha_sum);
275
                }
276
            }
277
2466669
            glyph_row += pitch;
278
        }
279
    }
280
#endif
281
282
}
283