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 REDVAL(_c) (GX_UBYTE)(((_c) >> 5) & 0x07) |
22 |
|
|
#define GREENVAL(_c) (GX_UBYTE)(((_c) >> 2) & 0x07) |
23 |
|
|
#define BLUEVAL(_c) (GX_UBYTE)(((_c)) & 0x03) |
24 |
|
|
|
25 |
|
|
#define ASSEMBLECOLOR(_r, _g, _b) \ |
26 |
|
|
((((_r) & 0x07) << 5) | \ |
27 |
|
|
(((_g) & 0x07) << 2) | \ |
28 |
|
|
(((_b) & 0x03))) |
29 |
|
|
|
30 |
|
|
#define GX_SOURCE_CODE |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/* Include necessary system files. */ |
34 |
|
|
|
35 |
|
|
#include "gx_api.h" |
36 |
|
|
#include "gx_display.h" |
37 |
|
|
|
38 |
|
|
|
39 |
|
|
/**************************************************************************/ |
40 |
|
|
/* */ |
41 |
|
|
/* FUNCTION RELEASE */ |
42 |
|
|
/* */ |
43 |
|
|
/* _gx_display_driver_332rgb_pixel_blend PORTABLE C */ |
44 |
|
|
/* 6.1 */ |
45 |
|
|
/* AUTHOR */ |
46 |
|
|
/* */ |
47 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
48 |
|
|
/* */ |
49 |
|
|
/* DESCRIPTION */ |
50 |
|
|
/* */ |
51 |
|
|
/* Pixel blend function for 332rgb 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 |
|
|
/* */ |
84 |
|
|
/**************************************************************************/ |
85 |
|
138336282 |
VOID _gx_display_driver_332rgb_pixel_blend(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha) |
86 |
|
|
{ |
87 |
|
|
GX_UBYTE fred, fgreen, fblue; |
88 |
|
|
GX_UBYTE bred, bgreen, bblue; |
89 |
|
|
GX_UBYTE balpha; |
90 |
|
|
|
91 |
|
|
GX_UBYTE bcolor; |
92 |
|
|
GX_UBYTE *put; |
93 |
|
|
|
94 |
|
|
/* Is the pixel non-transparent? */ |
95 |
✓✓ |
138336282 |
if (alpha > 0) |
96 |
|
|
{ |
97 |
|
|
/* calculate address of pixel */ |
98 |
|
92227233 |
put = (GX_UBYTE *)context -> gx_draw_context_memory; |
99 |
|
92227233 |
put += context -> gx_draw_context_pitch * y; |
100 |
|
92227233 |
put += x; |
101 |
|
|
|
102 |
|
|
/* No need to blend if alpha value is 255. */ |
103 |
✓✓ |
92227233 |
if (alpha == 255) |
104 |
|
|
{ |
105 |
|
75268869 |
*put = (GX_UBYTE)fcolor; |
106 |
|
|
|
107 |
|
75268869 |
return; |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
/* split foreground into red, green, and blue components */ |
111 |
|
16958364 |
fred = REDVAL(fcolor); |
112 |
|
16958364 |
fgreen = GREENVAL(fcolor); |
113 |
|
16958364 |
fblue = BLUEVAL(fcolor); |
114 |
|
|
|
115 |
|
|
/* read background color */ |
116 |
|
16958364 |
bcolor = *put; |
117 |
|
|
|
118 |
|
|
/* split background color into red, green, and blue components */ |
119 |
|
16958364 |
bred = REDVAL(bcolor); |
120 |
|
16958364 |
bgreen = GREENVAL(bcolor); |
121 |
|
16958364 |
bblue = BLUEVAL(bcolor); |
122 |
|
|
|
123 |
|
|
/* background alpha is inverse of foreground alpha */ |
124 |
|
16958364 |
balpha = (GX_UBYTE)(256 - alpha); |
125 |
|
|
|
126 |
|
|
/* blend foreground and background, each color channel */ |
127 |
|
16958364 |
fred = (GX_UBYTE)(((bred * balpha) + (fred * alpha)) >> 8); |
128 |
|
16958364 |
fgreen = (GX_UBYTE)(((bgreen * balpha) + (fgreen * alpha)) >> 8); |
129 |
|
16958364 |
fblue = (GX_UBYTE)(((bblue * balpha) + (fblue * alpha)) >> 8); |
130 |
|
|
|
131 |
|
|
/* re-assemble into 8-bit color and write it out */ |
132 |
|
16958364 |
*put = (GX_UBYTE)ASSEMBLECOLOR(fred, fgreen, fblue); |
133 |
|
|
} |
134 |
|
|
} |
135 |
|
|
|