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) >> 11) & 0x1f)
30 #define GREENVAL(_c) (GX_UBYTE)(((_c) >> 5) & 0x3f)
31 #define BLUEVAL(_c) (GX_UBYTE)(((_c)) & 0x1f)
32
33
34 /* Define macros for assembling a 16-bit r:g:b value from 3 components. */
35
36 #define ASSEMBLECOLOR(_r, _g, _b) \
37 ((((_r) & 0x1f) << 11) | \
38 (((_g) & 0x3f) << 5) | \
39 (((_b) & 0x1f)))
40
41
42 /**************************************************************************/
43 /* */
44 /* FUNCTION RELEASE */
45 /* */
46 /* _gx_display_driver_565rgb_rotated_canvas_blend PORTABLE C */
47 /* 6.1.3 */
48 /* AUTHOR */
49 /* */
50 /* Kenneth Maxwell, Microsoft Corporation */
51 /* */
52 /* DESCRIPTION */
53 /* */
54 /* Rotated canvas blend function for 565rgb 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 /* 12-31-2020 Kenneth Maxwell Initial Version 6.1.3 */
84 /* */
85 /**************************************************************************/
_gx_display_driver_565rgb_rotated_canvas_blend(GX_CANVAS * canvas,GX_CANVAS * composite)86 VOID _gx_display_driver_565rgb_rotated_canvas_blend(GX_CANVAS *canvas, GX_CANVAS *composite)
87 {
88 GX_RECTANGLE dirty;
89 GX_RECTANGLE overlap;
90 USHORT *read;
91 USHORT *read_start;
92 USHORT *write;
93 USHORT *write_start;
94 USHORT fcolor;
95 GX_UBYTE fred, fgreen, fblue;
96 GX_UBYTE bred, bgreen, bblue;
97 GX_UBYTE alpha, balpha;
98
99 USHORT bcolor;
100 INT row;
101 INT col;
102
103 dirty.gx_rectangle_left = dirty.gx_rectangle_top = 0;
104 dirty.gx_rectangle_right = (GX_VALUE)(canvas -> gx_canvas_x_resolution - 1);
105 dirty.gx_rectangle_bottom = (GX_VALUE)(canvas -> gx_canvas_y_resolution - 1);
106
107 _gx_utility_rectangle_shift(&dirty, canvas -> gx_canvas_display_offset_x, canvas -> gx_canvas_display_offset_y);
108
109 if (_gx_utility_rectangle_overlap_detect(&dirty, &composite -> gx_canvas_dirty_area, &overlap))
110 {
111 alpha = canvas -> gx_canvas_alpha;
112 balpha = (GX_UBYTE)(256 - alpha);
113
114 read_start = (USHORT *)canvas -> gx_canvas_memory;
115 write_start = (USHORT *)composite -> gx_canvas_memory;
116
117 if (canvas -> gx_canvas_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
118 {
119 /* index into starting row */
120 read_start += (dirty.gx_rectangle_right - overlap.gx_rectangle_right) * canvas -> gx_canvas_y_resolution;
121
122 /* index into pixel */
123 read_start += overlap.gx_rectangle_top - dirty.gx_rectangle_top;
124
125 /* calculate the write pointer */
126 write_start += (composite -> gx_canvas_x_resolution - overlap.gx_rectangle_right - 1) * composite -> gx_canvas_y_resolution;
127 write_start += overlap.gx_rectangle_top;
128 }
129 else
130 {
131 /* index into starting row */
132 read_start += (overlap.gx_rectangle_left - dirty.gx_rectangle_left) * canvas -> gx_canvas_y_resolution;
133
134 /* index into pixel */
135 read_start += dirty.gx_rectangle_bottom - overlap.gx_rectangle_bottom;
136
137 /* calculate the write pointer */
138 write_start += overlap.gx_rectangle_left * composite -> gx_canvas_y_resolution;
139 write_start += (composite -> gx_canvas_y_resolution - overlap.gx_rectangle_bottom - 1);
140 }
141
142 for (row = overlap.gx_rectangle_left; row <= overlap.gx_rectangle_right; row++)
143 {
144 read = read_start;
145 write = write_start;
146
147 for (col = overlap.gx_rectangle_top; col <= overlap.gx_rectangle_bottom; col++)
148 {
149 /* read the foreground color */
150 fcolor = *read++;
151
152 /* split foreground into red, green, and blue components */
153 fred = REDVAL(fcolor);
154 fgreen = GREENVAL(fcolor);
155 fblue = BLUEVAL(fcolor);
156
157 /* read background color */
158 bcolor = *write;
159
160 /* split background color into red, green, and blue components */
161 bred = REDVAL(bcolor);
162 bgreen = GREENVAL(bcolor);
163 bblue = BLUEVAL(bcolor);
164
165 /* blend foreground and background, each color channel */
166 fred = (GX_UBYTE)(((bred * balpha) + (fred * alpha)) >> 8);
167 fgreen = (GX_UBYTE)(((bgreen * balpha) + (fgreen * alpha)) >> 8);
168 fblue = (GX_UBYTE)(((bblue * balpha) + (fblue * alpha)) >> 8);
169
170 /* re-assemble into 16-bit color and write it out */
171 *write++ = (USHORT)ASSEMBLECOLOR(fred, fgreen, fblue);
172 }
173 write_start += composite -> gx_canvas_y_resolution;
174 read_start += canvas -> gx_canvas_y_resolution;
175 }
176 }
177 }
178
179