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 |
22 |
|
|
#define PIXEL_LOC USHORT |
23 |
|
|
|
24 |
|
|
#define REDVAL(_c) (GX_UBYTE)(((_c) >> 11) & 0x1f) |
25 |
|
|
#define GREENVAL(_c) (GX_UBYTE)(((_c) >> 5) & 0x3f) |
26 |
|
|
#define BLUEVAL(_c) (GX_UBYTE)(((_c)) & 0x1f) |
27 |
|
|
|
28 |
|
|
#define ASSEMBLECOLOR(_r, _g, _b) \ |
29 |
|
|
((((_r) & 0x1f) << 11) | \ |
30 |
|
|
(((_g) & 0x3f) << 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_565rgb_pixel_blend PORTABLE C */ |
46 |
|
|
/* 6.3.0 */ |
47 |
|
|
/* AUTHOR */ |
48 |
|
|
/* */ |
49 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
50 |
|
|
/* */ |
51 |
|
|
/* DESCRIPTION */ |
52 |
|
|
/* */ |
53 |
|
|
/* Pixel blend function for 565rgb 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 |
|
|
/* 10-31-2023 Ting Zhu Modified comment(s), */ |
86 |
|
|
/* added partial canvas buffer */ |
87 |
|
|
/* support, */ |
88 |
|
|
/* resulting in version 6.3.0 */ |
89 |
|
|
/* */ |
90 |
|
|
/**************************************************************************/ |
91 |
|
1133688106 |
VOID _gx_display_driver_565rgb_pixel_blend(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha) |
92 |
|
|
{ |
93 |
|
|
GX_UBYTE fred, fgreen, fblue; |
94 |
|
|
GX_UBYTE bred, bgreen, bblue; |
95 |
|
|
GX_UBYTE balpha; |
96 |
|
|
|
97 |
|
|
USHORT bcolor; |
98 |
|
|
USHORT *put; |
99 |
|
|
|
100 |
|
|
/* Is the pixel non-transparent? */ |
101 |
✓✓ |
1133688106 |
if (alpha > 0) |
102 |
|
|
{ |
103 |
|
|
/* calculate address of pixel */ |
104 |
|
1009856516 |
put = (USHORT *)context -> gx_draw_context_memory; |
105 |
|
1009856516 |
GX_CALCULATE_PUTROW(put, x, y, context); |
106 |
|
|
|
107 |
|
|
/* No need to blend if alpha value is 255. */ |
108 |
✓✓ |
1009856516 |
if (alpha == 255) |
109 |
|
|
{ |
110 |
|
215553100 |
*put = (USHORT)fcolor; |
111 |
|
215553100 |
return; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
/* split foreground into red, green, and blue components */ |
115 |
|
794303416 |
fred = REDVAL(fcolor); |
116 |
|
794303416 |
fgreen = GREENVAL(fcolor); |
117 |
|
794303416 |
fblue = BLUEVAL(fcolor); |
118 |
|
|
|
119 |
|
|
/* read background color */ |
120 |
|
794303416 |
bcolor = *put; |
121 |
|
|
|
122 |
|
|
/* split background color into red, green, and blue components */ |
123 |
|
794303416 |
bred = REDVAL(bcolor); |
124 |
|
794303416 |
bgreen = GREENVAL(bcolor); |
125 |
|
794303416 |
bblue = BLUEVAL(bcolor); |
126 |
|
|
|
127 |
|
|
/* background alpha is inverse of foreground alpha */ |
128 |
|
794303416 |
balpha = (GX_UBYTE)(256 - alpha); |
129 |
|
|
|
130 |
|
|
/* blend foreground and background, each color channel */ |
131 |
|
794303416 |
fred = (GX_UBYTE)(((bred * balpha) + (fred * alpha)) >> 8); |
132 |
|
794303416 |
fgreen = (GX_UBYTE)(((bgreen * balpha) + (fgreen * alpha)) >> 8); |
133 |
|
794303416 |
fblue = (GX_UBYTE)(((bblue * balpha) + (fblue * alpha)) >> 8); |
134 |
|
|
|
135 |
|
|
/* re-assemble into 16-bit color and write it out */ |
136 |
|
794303416 |
*put = (USHORT)ASSEMBLECOLOR(fred, fgreen, fblue); |
137 |
|
|
} |
138 |
|
|
} |
139 |
|
|
|