GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_4444argb_pixel_blend.c Lines: 33 33 100.0 %
Date: 2024-12-05 08:52:37 Branches: 4 4 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 _COLOR_FORMAT_ 565rgb /*what's this for??*/
22
#define PIXEL_LOC      USHORT
23
24
#define ALPHAVAL(_c)   (GX_UBYTE)(((_c) >> 12) & 0xf)
25
#define REDVAL(_c)     (GX_UBYTE)(((_c) >> 8) & 0xf)
26
#define GREENVAL(_c)   (GX_UBYTE)(((_c) >> 4) & 0xf)
27
#define BLUEVAL(_c)    (GX_UBYTE)((_c) & 0xf)
28
29
#define ASSEMBLECOLOR_4444ARGB(_a, _r, _g, _b) \
30
    (((_a) << 12)   |          \
31
     ((_r) << 8)    |          \
32
     ((_g) << 4)    |          \
33
     ((_b) & 0xf))
34
35
#define ExtendToByte(_a)  _a |= (GX_UBYTE)(_a << 4)
36
37
#define GX_SOURCE_CODE
38
39
40
/* Include necessary system files.  */
41
42
#include "gx_api.h"
43
#include "gx_display.h"
44
45
/**************************************************************************/
46
/*                                                                        */
47
/*  FUNCTION                                               RELEASE        */
48
/*                                                                        */
49
/*    _gx_display_driver_4444argb_pixel_blend            PORTABLE C       */
50
/*                                                           6.1          */
51
/*  AUTHOR                                                                */
52
/*                                                                        */
53
/*    Kenneth Maxwell, Microsoft Corporation                              */
54
/*                                                                        */
55
/*  DESCRIPTION                                                           */
56
/*                                                                        */
57
/*    Pixel blend function for 565rgb color format.                       */
58
/*                                                                        */
59
/*  INPUT                                                                 */
60
/*                                                                        */
61
/*    context                               Drawing context               */
62
/*    x                                     X coordinate                  */
63
/*    y                                     Y coordinate                  */
64
/*    color                                 Color of line to write        */
65
/*    alpha                                 Alpha value                   */
66
/*                                                                        */
67
/*  OUTPUT                                                                */
68
/*                                                                        */
69
/*    None                                                                */
70
/*                                                                        */
71
/*  CALLS                                                                 */
72
/*                                                                        */
73
/*    REDVAL                                Extract the red component     */
74
/*    GREENVAL                              Extract the green component   */
75
/*    BLUEVAL                               Extract the blue component    */
76
/*    ASSEMBLECOLOR                         Assemble color components     */
77
/*                                                                        */
78
/*  CALLED BY                                                             */
79
/*                                                                        */
80
/*    GUIX Internal Code                                                  */
81
/*                                                                        */
82
/*  RELEASE HISTORY                                                       */
83
/*                                                                        */
84
/*    DATE              NAME                      DESCRIPTION             */
85
/*                                                                        */
86
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
87
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
88
/*                                            resulting in version 6.1    */
89
/*                                                                        */
90
/**************************************************************************/
91
86699228
VOID _gx_display_driver_4444argb_pixel_blend(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha)
92
{
93
GX_UBYTE falpha, fred, fgreen, fblue;
94
GX_UBYTE balpha, bred, bgreen, bblue;
95
GX_UBYTE inv_alpha;
96
INT      combined_alpha;
97
USHORT   bcolor;
98
USHORT  *put;
99
100
101
86699228
    falpha = ALPHAVAL(fcolor);
102
86699228
    falpha = (GX_UBYTE)(falpha | (falpha << 4));
103
86699228
    combined_alpha = falpha * alpha;
104
86699228
    combined_alpha /= 255;
105
106
    /* Is the pixel non-transparent? */
107
86699228
    if (combined_alpha > 0)
108
    {
109
        /* calculate address of pixel */
110
78040207
        put = (USHORT *)context -> gx_draw_context_memory;
111
78040207
        put += context -> gx_draw_context_pitch * y;
112
78040207
        put += x;
113
114
        /* No need to blend if alpha value is 255. */
115
78040207
        if (combined_alpha == 255)
116
        {
117
67157787
            *put = (USHORT)fcolor;
118
67157787
            return;
119
        }
120
121
        /* split foreground into red, green, and blue components */
122
10882420
        fred = REDVAL(fcolor);
123
10882420
        ExtendToByte(fred);
124
10882420
        fgreen = GREENVAL(fcolor);
125
10882420
        ExtendToByte(fgreen);
126
10882420
        fblue = BLUEVAL(fcolor);
127
10882420
        ExtendToByte(fblue);
128
129
        /* read background color */
130
10882420
        bcolor = *put;
131
132
        /* split background color into red, green, and blue components */
133
10882420
        balpha = ALPHAVAL(bcolor);
134
10882420
        ExtendToByte(balpha);
135
10882420
        bred = REDVAL(bcolor);
136
10882420
        ExtendToByte(bred);
137
10882420
        bgreen = GREENVAL(bcolor);
138
10882420
        ExtendToByte(bgreen);
139
10882420
        bblue = BLUEVAL(bcolor);
140
10882420
        ExtendToByte(bblue);
141
142
        /* background alpha is inverse of foreground alpha */
143
10882420
        inv_alpha = (GX_UBYTE)(256 - combined_alpha);
144
145
        /* blend foreground and background, each color channel */
146
10882420
        falpha = (GX_UBYTE)(((balpha * inv_alpha) + (falpha * combined_alpha)) >> 12);
147
10882420
        fred = (GX_UBYTE)(((bred * inv_alpha) + (fred * combined_alpha)) >> 12);
148
10882420
        fgreen = (GX_UBYTE)(((bgreen * inv_alpha) + (fgreen * combined_alpha)) >> 12);
149
10882420
        fblue = (GX_UBYTE)(((bblue * inv_alpha) + (fblue * combined_alpha)) >> 12);
150
151
152
        /* re-assemble into 16-bit color and write it out */
153
10882420
        *put = (USHORT)ASSEMBLECOLOR_4444ARGB(falpha, fred, fgreen, fblue);
154
    }
155
}
156