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_rotated_pixel_blend PORTABLE C */
46 /* 6.1.3 */
47 /* AUTHOR */
48 /* */
49 /* Kenneth Maxwell, Microsoft Corporation */
50 /* */
51 /* DESCRIPTION */
52 /* */
53 /* Rotated 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 /* 12-31-2020 Kenneth Maxwell Initial Version 6.1.3 */
83 /* */
84 /**************************************************************************/
_gx_display_driver_565rgb_rotated_pixel_blend(GX_DRAW_CONTEXT * context,INT x,INT y,GX_COLOR fcolor,GX_UBYTE alpha)85 VOID _gx_display_driver_565rgb_rotated_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 USHORT bcolor;
92 USHORT *put;
93
94
95 /* Is the pixel non-transparent? */
96 if (alpha > 0)
97 {
98 put = (USHORT *)context -> gx_draw_context_memory;
99
100 /* calculate address of pixel */
101 if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
102 {
103 put += context -> gx_draw_context_pitch * (context -> gx_draw_context_canvas -> gx_canvas_x_resolution - x - 1);
104 put += y;
105 }
106 else
107 {
108 put += context -> gx_draw_context_pitch * x;
109 put += (context -> gx_draw_context_canvas -> gx_canvas_y_resolution - y - 1);
110 }
111
112 /* No need to blend if alpha value is 255. */
113 if (alpha == 255)
114 {
115 *put = (USHORT)fcolor;
116 return;
117 }
118
119 /* split foreground into red, green, and blue components */
120 fred = REDVAL(fcolor);
121 fgreen = GREENVAL(fcolor);
122 fblue = BLUEVAL(fcolor);
123
124 /* read background color */
125 bcolor = *put;
126
127 /* split background color into red, green, and blue components */
128 bred = REDVAL(bcolor);
129 bgreen = GREENVAL(bcolor);
130 bblue = BLUEVAL(bcolor);
131
132 /* background alpha is inverse of foreground alpha */
133 balpha = (GX_UBYTE)(256 - alpha);
134
135 /* blend foreground and background, each color channel */
136 fred = (GX_UBYTE)(((bred * balpha) + (fred * alpha)) >> 8);
137 fgreen = (GX_UBYTE)(((bgreen * balpha) + (fgreen * alpha)) >> 8);
138 fblue = (GX_UBYTE)(((bblue * balpha) + (fblue * alpha)) >> 8);
139
140 /* re-assemble into 16-bit color and write it out */
141 *put = (USHORT)ASSEMBLECOLOR(fred, fgreen, fblue);
142 }
143 }
144
145