GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_8bpp_pixelmap_blend.c Lines: 45 45 100.0 %
Date: 2026-03-06 19:21:09 Branches: 22 22 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_display.h"
29
#include "gx_context.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_display_driver_8bpp_pixelmap_raw_blend          PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    Internal helper function that handles blending of uncompressed      */
45
/*    pixlemap file.                                                      */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    context                               Drawing context               */
50
/*    xpos                                  x-coord of top-left draw point*/
51
/*    ypos                                  y-coord of top-left draw point*/
52
/*    pixelmap                              Pointer to GX_PIXELMAP struct */
53
/*    alpha                                 blending value 0 to 255       */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    None                                                                */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    [gx_display_driver_pixel_blend]       Basic display driver pixel    */
62
/*                                            blend function              */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    _gx_display_driver_8bpp_pixelmap_blend                              */
67
/*                                                                        */
68
/**************************************************************************/
69
9
static VOID _gx_display_driver_8bpp_pixelmap_raw_blend(GX_DRAW_CONTEXT *context,
70
                                                       INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
71
{
72
INT           xval;
73
INT           yval;
74
GX_UBYTE     *get;
75
GX_UBYTE     *getrow;
76
GX_UBYTE      pixel;
77
78
9
GX_RECTANGLE *clip = context -> gx_draw_context_clip;
79
VOID          (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha);
80
81
9
    blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend;
82
9
    if (!blend_func)
83
    {
84
1
        return;
85
    }
86
87
8
    getrow = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data + (INT)sizeof(GX_UBYTE) * pixelmap -> gx_pixelmap_width * (clip -> gx_rectangle_top - ypos));
88
8
    getrow += (clip -> gx_rectangle_left - xpos);
89
2360
    for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
90
    {
91
2352
        get = getrow;
92
227754
        for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
93
        {
94
225402
            pixel = *get++;
95
225402
            blend_func(context, xval, yval, pixel, alpha);
96
        }
97
2352
        getrow += pixelmap -> gx_pixelmap_width;
98
    }
99
}
100
101
/**************************************************************************/
102
/*                                                                        */
103
/*  FUNCTION                                               RELEASE        */
104
/*                                                                        */
105
/*    _gx_display_driver_8bpp_pixelmap_alpha_blend        PORTABLE C      */
106
/*                                                           6.1          */
107
/*  AUTHOR                                                                */
108
/*                                                                        */
109
/*    Kenneth Maxwell, Microsoft Corporation                              */
110
/*                                                                        */
111
/*  DESCRIPTION                                                           */
112
/*                                                                        */
113
/*    Internal helper function that handles blending of uncompressed      */
114
/*    pixelmap file with alpha channel.                                   */
115
/*                                                                        */
116
/*  INPUT                                                                 */
117
/*                                                                        */
118
/*    context                               Drawing context               */
119
/*    xpos                                  x-coord of top-left draw point*/
120
/*    ypos                                  y-coord of top-left draw point*/
121
/*    pixelmap                              Pointer to GX_PIXELMAP struct */
122
/*    alpha                                 blending value 0 to 255       */
123
/*                                                                        */
124
/*  OUTPUT                                                                */
125
/*                                                                        */
126
/*    None                                                                */
127
/*                                                                        */
128
/*  CALLS                                                                 */
129
/*                                                                        */
130
/*    [gx_display_driver_pixel_blend]       Basic display driver pixel    */
131
/*                                            blend function              */
132
/*                                                                        */
133
/*  CALLED BY                                                             */
134
/*                                                                        */
135
/*    _gx_display_driver_8bpp_pixelmap_blend                              */
136
/*                                                                        */
137
/**************************************************************************/
138
15
static VOID _gx_display_driver_8bpp_pixelmap_alpha_blend(GX_DRAW_CONTEXT *context,
139
                                                         INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
140
{
141
INT           skipcount;
142
INT           xval;
143
INT           yval;
144
GX_UBYTE     *getrow;
145
GX_UBYTE     *getrowalpha;
146
GX_UBYTE     *get;
147
GX_UBYTE      pixel;
148
GX_UBYTE     *getalpha;
149
INT           combined_alpha;
150
GX_UBYTE      internal_alpha;
151
VOID          (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha);
152
15
GX_RECTANGLE *clip = context -> gx_draw_context_clip;
153
154
15
    blend_func = context -> gx_draw_context_display -> gx_display_driver_pixel_blend;
155
15
    if (GX_NULL == blend_func)
156
    {
157
2
        return;
158
    }
159
160
    /* calculate how many pixels to skip */
161
13
    skipcount = (pixelmap -> gx_pixelmap_width) * (clip -> gx_rectangle_top - ypos);
162
13
    skipcount += (clip -> gx_rectangle_left - xpos);
163
13
    getrow = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data);
164
13
    getrow += skipcount;
165
166
13
    getrowalpha = (GX_UBYTE *)(pixelmap -> gx_pixelmap_aux_data);
167
13
    getrowalpha += skipcount;
168
169
2471
    for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
170
    {
171
2458
        get = getrow;
172
2458
        getalpha = getrowalpha;
173
174
255394
        for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
175
        {
176
252936
            internal_alpha = *getalpha++;
177
252936
            if (internal_alpha)
178
            {
179
181572
                combined_alpha = internal_alpha * alpha;
180
181572
                combined_alpha /= 255;
181
181572
                pixel = *get;
182
181572
                blend_func(context, xval, yval, pixel, (GX_UBYTE)combined_alpha);
183
            }
184
252936
            get++;
185
        }
186
2458
        getrow += pixelmap -> gx_pixelmap_width;
187
2458
        getrowalpha += pixelmap -> gx_pixelmap_width;
188
    }
189
}
190
191
/**************************************************************************/
192
/*                                                                        */
193
/*  FUNCTION                                               RELEASE        */
194
/*                                                                        */
195
/*    _gx_display_driver_8bpp_pixelmap_blend              PORTABLE C      */
196
/*                                                           6.1          */
197
/*  AUTHOR                                                                */
198
/*                                                                        */
199
/*    Kenneth Maxwell, Microsoft Corporation                              */
200
/*                                                                        */
201
/*  DESCRIPTION                                                           */
202
/*                                                                        */
203
/*    Driver entry point for pixelmap blending function that handles      */
204
/*    compressed or uncompress, with or without alpha channel.            */
205
/*                                                                        */
206
/*  INPUT                                                                 */
207
/*                                                                        */
208
/*    context                               Drawing context               */
209
/*    xpos                                  x-coord of top-left draw point*/
210
/*    ypos                                  y-coord of top-left draw point*/
211
/*    pixelmap                              Pointer to GX_PIXELMAP struct */
212
/*    alpha                                 blending value 0 to 255       */
213
/*                                                                        */
214
/*  OUTPUT                                                                */
215
/*                                                                        */
216
/*    None                                                                */
217
/*                                                                        */
218
/*  CALLS                                                                 */
219
/*                                                                        */
220
/*    _gx_display_driver_8bpp_pixelmap_alpha_blend                        */
221
/*                                          Real display driver pixelmap  */
222
/*                                            blend function for 8bpp     */
223
/*    _gx_display_driver_8bpp_pixelmap_raw_blend                          */
224
/*                                          Real display driver pixelmap  */
225
/*                                            blend function for 8bpp     */
226
/*                                                                        */
227
/*  CALLED BY                                                             */
228
/*                                                                        */
229
/*    GUIX Internal Code                                                  */
230
/*                                                                        */
231
/**************************************************************************/
232
27
VOID _gx_display_driver_8bpp_pixelmap_blend(GX_DRAW_CONTEXT *context,
233
                                            INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
234
{
235

27
    if ((pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_TRANSPARENT) || (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED))
236
    {
237
        /* Wrong format. */
238
2
        return;
239
    }
240
241
25
    if (pixelmap -> gx_pixelmap_format != GX_COLOR_FORMAT_8BIT_PACKED_PIXEL)
242
    {
243
        /* wrong color format for this driver */
244
1
        return;
245
    }
246
247
24
    if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)
248
    {
249
        /* alpha, no compression */
250
15
        _gx_display_driver_8bpp_pixelmap_alpha_blend(context,
251
                                                     xpos, ypos, pixelmap, alpha);
252
    }
253
    else
254
    {
255
        /* no compression or alpha */
256
9
        _gx_display_driver_8bpp_pixelmap_raw_blend(context,
257
                                                   xpos, ypos, pixelmap, alpha);
258
    }
259
}
260