GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_24xrgb_pixel_blend.c Lines: 20 20 100.0 %
Date: 2026-03-06 19:21:09 Branches: 4 4 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
#define GX_SOURCE_CODE
22
23
#define REDVAL(_c)   (GX_UBYTE)((_c) >> 16)
24
#define GREENVAL(_c) (GX_UBYTE)((_c) >> 8)
25
#define BLUEVAL(_c)  (GX_UBYTE)(_c)
26
27
#define ASSEMBLECOLOR(_r, _g, _b) \
28
    ((0xff << 24) |               \
29
     ((_r) << 16) |               \
30
     ((_g) << 8) |                \
31
     (_b))
32
#define GX_SOURCE_CODE
33
34
35
/* Include necessary system files.  */
36
37
#include "gx_api.h"
38
#include "gx_display.h"
39
40
/**************************************************************************/
41
/*                                                                        */
42
/*  FUNCTION                                               RELEASE        */
43
/*                                                                        */
44
/*    _gx_display_driver_24xrgb_pixel_blend               PORTABLE C      */
45
/*                                                           6.1.3        */
46
/*  AUTHOR                                                                */
47
/*                                                                        */
48
/*    Kenneth Maxwell, Microsoft Corporation                              */
49
/*                                                                        */
50
/*  DESCRIPTION                                                           */
51
/*                                                                        */
52
/*    Pixel blend function for 24xrgb color format.                       */
53
/*                                                                        */
54
/*  INPUT                                                                 */
55
/*                                                                        */
56
/*    context                               Drawing context               */
57
/*    x                                     X coordinate                  */
58
/*    y                                     Y coordinate                  */
59
/*    color                                 Color of line to write        */
60
/*    alpha                                 Alpha value                   */
61
/*                                                                        */
62
/*  OUTPUT                                                                */
63
/*                                                                        */
64
/*    None                                                                */
65
/*                                                                        */
66
/*  CALLS                                                                 */
67
/*                                                                        */
68
/*    REDVAL                                Extract the red component     */
69
/*    GREENVAL                              Extract the green component   */
70
/*    BLUEVAL                               Extract the blue component    */
71
/*    ASSEMBLECOLOR                         Assemble color components     */
72
/*                                                                        */
73
/*  CALLED BY                                                             */
74
/*                                                                        */
75
/*    GUIX Internal Code                                                  */
76
/*                                                                        */
77
/**************************************************************************/
78
1824647791
VOID _gx_display_driver_24xrgb_pixel_blend(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha)
79
{
80
GX_UBYTE fred, fgreen, fblue;
81
GX_UBYTE bred, bgreen, bblue;
82
GX_UBYTE balpha;
83
84
ULONG    bcolor;
85
ULONG   *put;
86
87
88
    /* Is the pixel non-transparent? */
89
1824647791
    if (alpha > 0)
90
    {
91
        /* calculate address of pixel */
92
1781608272
        put = (ULONG *)context -> gx_draw_context_memory;
93
1781608272
        put += context -> gx_draw_context_pitch * y;
94
1781608272
        put += x;
95
96
        /* No need to blend if alpha value is 255. */
97
1781608272
        if (alpha == 255)
98
        {
99
369424550
            *put = (ULONG)(fcolor | 0xff000000);
100
101
369424550
            return;
102
        }
103
104
        /* split foreground into red, green, and blue components */
105
1412183722
        fred = REDVAL(fcolor);
106
1412183722
        fgreen = GREENVAL(fcolor);
107
1412183722
        fblue = BLUEVAL(fcolor);
108
109
        /* read background color */
110
1412183722
        bcolor = *put;
111
112
        /* split background color into red, green, and blue components */
113
1412183722
        bred = REDVAL(bcolor);
114
1412183722
        bgreen = GREENVAL(bcolor);
115
1412183722
        bblue = BLUEVAL(bcolor);
116
117
        /* background alpha is inverse of foreground alpha */
118
1412183722
        balpha = (GX_UBYTE)(256 - alpha);
119
120
        /* blend foreground and background, each color channel */
121
1412183722
        fred = (GX_UBYTE)(((bred * balpha) + (fred * alpha)) >> 8);
122
1412183722
        fgreen = (GX_UBYTE)(((bgreen * balpha) + (fgreen * alpha)) >> 8);
123
1412183722
        fblue = (GX_UBYTE)(((bblue * balpha) + (fblue * alpha)) >> 8);
124
125
        /* re-assemble into 32-bit color and write it out */
126
1412183722
        *put = (ULONG)(ASSEMBLECOLOR(fred, fgreen, fblue));
127
    }
128
}
129