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