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