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) >> 16)
22 #define GREENVAL(_c) (GX_UBYTE)((_c) >> 8)
23 #define BLUEVAL(_c) (GX_UBYTE)(_c)
24
25
26 /* Define macros for assembling a 24-bit r:g:b value from 3 components. */
27
28 #define ASSEMBLECOLOR(_r, _g, _b) \
29 (((_r) << 16) | \
30 ((_g) << 8) | \
31 (_b))
32
33 #define GX_SOURCE_CODE
34
35 /* Include necessary system files. */
36
37 #include "gx_api.h"
38 #include "gx_display.h"
39 #include "gx_utility.h"
40
41
42 /**************************************************************************/
43 /* */
44 /* FUNCTION RELEASE */
45 /* */
46 /* _gx_display_driver_24xrgb_canvas_blend PORTABLE C */
47 /* 6.1 */
48 /* AUTHOR */
49 /* */
50 /* Kenneth Maxwell, Microsoft Corporation */
51 /* */
52 /* DESCRIPTION */
53 /* */
54 /* Canvas blend function for 24xrgb color format. */
55 /* */
56 /* INPUT */
57 /* */
58 /* canvas The canvas to blend to */
59 /* composite The canvas to blend from */
60 /* */
61 /* OUTPUT */
62 /* */
63 /* None */
64 /* */
65 /* CALLS */
66 /* */
67 /* _gx_utility_rectangle_shift Adjust the rectangle */
68 /* _gx_utility_recttangle_overlap_detect Detect whether two areas */
69 /* overlap */
70 /* REDVAL Extrace Red from canvas */
71 /* GREENVAL Extrace Green from canvas */
72 /* BLUEVAL Extrace Blue from canvas */
73 /* ASSEMBLECOLOR Compose the RGB color */
74 /* */
75 /* CALLED BY */
76 /* */
77 /* GUIX Internal Code */
78 /* */
79 /* RELEASE HISTORY */
80 /* */
81 /* DATE NAME DESCRIPTION */
82 /* */
83 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
84 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
85 /* resulting in version 6.1 */
86 /* */
87 /**************************************************************************/
_gx_display_driver_24xrgb_canvas_blend(GX_CANVAS * canvas,GX_CANVAS * composite)88 VOID _gx_display_driver_24xrgb_canvas_blend(GX_CANVAS *canvas, GX_CANVAS *composite)
89 {
90 GX_RECTANGLE dirty;
91 GX_RECTANGLE overlap;
92 ULONG *read;
93 ULONG *read_start;
94 ULONG *write;
95 ULONG *write_start;
96 ULONG fcolor;
97 GX_UBYTE fred, fgreen, fblue;
98 GX_UBYTE bred, bgreen, bblue;
99 GX_UBYTE alpha, balpha;
100
101 ULONG bcolor;
102 INT row;
103 INT col;
104
105 dirty.gx_rectangle_left = dirty.gx_rectangle_top = 0;
106 dirty.gx_rectangle_right = (GX_VALUE)(canvas -> gx_canvas_x_resolution - 1);
107 dirty.gx_rectangle_bottom = (GX_VALUE)(canvas -> gx_canvas_y_resolution - 1);
108
109 _gx_utility_rectangle_shift(&dirty, canvas -> gx_canvas_display_offset_x, canvas -> gx_canvas_display_offset_y);
110
111 if (_gx_utility_rectangle_overlap_detect(&dirty, &composite -> gx_canvas_dirty_area, &overlap))
112 {
113 alpha = canvas -> gx_canvas_alpha;
114 balpha = (GX_UBYTE)(256 - alpha);
115
116 read_start = (ULONG *)canvas -> gx_canvas_memory;
117
118 /* index into starting row */
119 read_start += (overlap.gx_rectangle_top - dirty.gx_rectangle_top) * canvas -> gx_canvas_x_resolution;
120
121 /* index into pixel */
122
123 read_start += overlap.gx_rectangle_left - dirty.gx_rectangle_left;
124
125 /* calculate the write pointer */
126 write_start = (ULONG *)composite -> gx_canvas_memory;
127 write_start += overlap.gx_rectangle_top * composite -> gx_canvas_x_resolution;
128 write_start += overlap.gx_rectangle_left;
129
130 for (row = overlap.gx_rectangle_top; row <= overlap.gx_rectangle_bottom; row++)
131 {
132 read = read_start;
133 write = write_start;
134
135 for (col = overlap.gx_rectangle_left; col <= overlap.gx_rectangle_right; col++)
136 {
137 /* read the foreground color */
138 fcolor = *read++;
139
140 /* split foreground into red, green, and blue components */
141 fred = REDVAL(fcolor);
142 fgreen = GREENVAL(fcolor);
143 fblue = BLUEVAL(fcolor);
144
145 /* read background color */
146 bcolor = *write;
147
148 /* split background color into red, green, and blue components */
149 bred = REDVAL(bcolor);
150 bgreen = GREENVAL(bcolor);
151 bblue = BLUEVAL(bcolor);
152
153 /* blend foreground and background, each color channel */
154 fred = (GX_UBYTE)(((bred * balpha) + (fred * alpha)) >> 8);
155 fgreen = (GX_UBYTE)(((bgreen * balpha) + (fgreen * alpha)) >> 8);
156 fblue = (GX_UBYTE)(((bblue * balpha) + (fblue * alpha)) >> 8);
157
158 /* re-assemble into 16-bit color and write it out */
159 *write++ = ASSEMBLECOLOR((ULONG)fred, (ULONG)fgreen, (ULONG)fblue);
160 }
161 write_start += composite -> gx_canvas_x_resolution;
162 read_start += canvas -> gx_canvas_x_resolution;
163 }
164 }
165 }
166
167