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