GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_32argb_rotated_pixel_blend.c Lines: 28 28 100.0 %
Date: 2026-03-06 19:21:09 Branches: 6 6 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
24
#include "gx_api.h"
25
#include "gx_display.h"
26
27
/**************************************************************************/
28
/*                                                                        */
29
/*  FUNCTION                                               RELEASE        */
30
/*                                                                        */
31
/*    _gx_display_driver_32argb_rotated_pixel_blend       PORTABLE C      */
32
/*                                                           6.1.4        */
33
/*  AUTHOR                                                                */
34
/*                                                                        */
35
/*    Kenneth Maxwell, Microsoft Corporation                              */
36
/*                                                                        */
37
/*  DESCRIPTION                                                           */
38
/*                                                                        */
39
/*    Rotated Pixel blend function for 32argb color format.               */
40
/*                                                                        */
41
/*  INPUT                                                                 */
42
/*                                                                        */
43
/*    context                               Drawing context               */
44
/*    x                                     X coordinate                  */
45
/*    y                                     Y coordinate                  */
46
/*    color                                 Color of line to write        */
47
/*    alpha                                 blending value 0 to 255       */
48
/*                                                                        */
49
/*  OUTPUT                                                                */
50
/*                                                                        */
51
/*    None                                                                */
52
/*                                                                        */
53
/*  CALLS                                                                 */
54
/*                                                                        */
55
/*    None                                                                */
56
/*                                                                        */
57
/*  CALLED BY                                                             */
58
/*                                                                        */
59
/*    GUIX Internal Code                                                  */
60
/*                                                                        */
61
/**************************************************************************/
62
750524
VOID _gx_display_driver_32argb_rotated_pixel_blend(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha)
63
{
64
GX_UBYTE falpha, fred, fgreen, fblue;
65
GX_UBYTE balpha, bred, bgreen, bblue;
66
GX_UBYTE oalpha;
67
ULONG    bcolor;
68
ULONG   *put;
69
INT      combined_alpha;
70
71
72
750524
    falpha = ALPHAVAL_32BPP(fcolor);
73
750524
    falpha = (GX_UBYTE)((falpha * alpha) / 255);
74
75
    /* Is the pixel non-transparent?  */
76
750524
    if (falpha > 0)
77
    {
78
79
        /* Calculate address of pixel.  */
80
748906
        put = (ULONG *)context -> gx_draw_context_memory;
81
82
748906
        GX_SWAP_VALS(x, y);
83
748906
        if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
84
        {
85
744552
            y = context -> gx_draw_context_canvas -> gx_canvas_x_resolution - y - 1;
86
        }
87
        else
88
        {
89
4354
            x = context -> gx_draw_context_canvas -> gx_canvas_y_resolution - x - 1;
90
        }
91
92
748906
        put += context -> gx_draw_context_pitch * y;
93
748906
        put += x;
94
95
        /* No need to blend if alpha value is 255.  */
96
748906
        if (falpha == 255)
97
        {
98
1730
            *put = (ULONG)fcolor;
99
1730
            return;
100
        }
101
102
        /* Split foreground into alpha, red, green, and blue components.  */
103
747176
        fred = REDVAL_32BPP(fcolor);
104
747176
        fgreen = GREENVAL_32BPP(fcolor);
105
747176
        fblue = BLUEVAL_32BPP(fcolor);
106
107
        /* Read background color.  */
108
747176
        bcolor = *put;
109
110
        /* Split background color into red, green, and blue components.  */
111
747176
        balpha = ALPHAVAL_32BPP(bcolor);
112
747176
        bred = REDVAL_32BPP(bcolor);
113
747176
        bgreen = GREENVAL_32BPP(bcolor);
114
747176
        bblue = BLUEVAL_32BPP(bcolor);
115
116
        /* Background alpha is inverse of foreground alpha.  */
117
747176
        combined_alpha = (falpha * balpha) / 0xff;
118
119
        /* Blend foreground and background, each color channel.  */
120
747176
        oalpha = (GX_UBYTE)(falpha + balpha - combined_alpha);
121
747176
        fred = (GX_UBYTE)((fred * falpha + bred * balpha - bred * combined_alpha) / oalpha);
122
747176
        fgreen = (GX_UBYTE)((fgreen * falpha + bgreen * balpha - bgreen * combined_alpha) / oalpha);
123
747176
        fblue = (GX_UBYTE)((fblue * falpha + bblue * balpha - bblue * combined_alpha) / oalpha);
124
125
        /* Re-assemble into 16-bit color and write it out.  */
126
747176
        *put = (ULONG)ASSEMBLECOLOR_32ARGB(oalpha, fred, fgreen, fblue);
127
    }
128
}
129