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