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 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_display.h"
28 
29 /**************************************************************************/
30 /*                                                                        */
31 /*  FUNCTION                                               RELEASE        */
32 /*                                                                        */
33 /*    _gx_display_driver_32argb_pixelmap_raw_blend        PORTABLE C      */
34 /*                                                           6.1.7        */
35 /*  AUTHOR                                                                */
36 /*                                                                        */
37 /*    Kenneth Maxwell, Microsoft Corporation                              */
38 /*                                                                        */
39 /*  DESCRIPTION                                                           */
40 /*                                                                        */
41 /*    Internal helper function that handles blending of uncompressed      */
42 /*    pixlemap file without alpha channel.                                */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    context                               Drawing context               */
47 /*    xpos                                  x-coord of top-left draw point*/
48 /*    ypos                                  y-coord of top-left draw point*/
49 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
50 /*    alpha                                 blending value 0 to 255       */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    None                                                                */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _gx_display_driver_32xrgb_pixel_blend Display driver pixel blend    */
59 /*                                            function                    */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    _gx_display_driver_32argb_pixelmap_blend                            */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
70 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*  06-02-2021     Kenneth Maxwell          Modified comment(s),          */
73 /*                                            removed unused variable     */
74 /*                                            assignment,                 */
75 /*                                            resulting in version 6.1.7  */
76 /*                                                                        */
77 /**************************************************************************/
_gx_display_driver_32argb_pixelmap_raw_blend(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap,GX_UBYTE alpha)78 static VOID _gx_display_driver_32argb_pixelmap_raw_blend(GX_DRAW_CONTEXT *context,
79                                                          INT xpos, INT ypos,
80                                                          GX_PIXELMAP *pixelmap,
81                                                          GX_UBYTE alpha)
82 {
83 INT           yval;
84 INT           xval;
85 GX_COLOR      color;
86 GX_COLOR     *get;
87 GX_COLOR     *getrow;
88 
89 GX_RECTANGLE *clip = context -> gx_draw_context_clip;
90 
91     getrow = (GX_COLOR *)((UINT)(pixelmap -> gx_pixelmap_data) + sizeof(GX_COLOR) * (UINT)(pixelmap -> gx_pixelmap_width) * (UINT)((INT)(clip -> gx_rectangle_top) - ypos));
92     getrow += (clip -> gx_rectangle_left - xpos);
93 
94     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
95     {
96         get = getrow;
97 
98         for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
99         {
100             color = *get;
101             get++;
102             _gx_display_driver_32argb_pixel_blend(context, xval, yval, color, alpha);
103         }
104 
105         getrow += pixelmap -> gx_pixelmap_width;
106     }
107 }
108 
109 /**************************************************************************/
110 /*                                                                        */
111 /*  FUNCTION                                               RELEASE        */
112 /*                                                                        */
113 /*    _gx_display_driver_32argb_pixelmap_alpha_blend      PORTABLE C      */
114 /*                                                           6.1.7        */
115 /*  AUTHOR                                                                */
116 /*                                                                        */
117 /*    Kenneth Maxwell, Microsoft Corporation                              */
118 /*                                                                        */
119 /*  DESCRIPTION                                                           */
120 /*                                                                        */
121 /*    Internal helper function that handles blending of uncompressed      */
122 /*    pixlemap file with alpha channel.                                   */
123 /*                                                                        */
124 /*  INPUT                                                                 */
125 /*                                                                        */
126 /*    context                               Drawing context               */
127 /*    xpos                                  x-coord of top-left draw point*/
128 /*    ypos                                  y-coord of top-left draw point*/
129 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
130 /*    alpha                                 blending value 0 to 255       */
131 /*                                                                        */
132 /*  OUTPUT                                                                */
133 /*                                                                        */
134 /*    None                                                                */
135 /*                                                                        */
136 /*  CALLS                                                                 */
137 /*                                                                        */
138 /*    _gx_display_driver_32xrgb_pixel_blend Display driver pixel blend    */
139 /*                                            function                    */
140 /*                                                                        */
141 /*  CALLED BY                                                             */
142 /*                                                                        */
143 /*    _gx_display_driver_32argb_pixelmap_blend                            */
144 /*                                                                        */
145 /*  RELEASE HISTORY                                                       */
146 /*                                                                        */
147 /*    DATE              NAME                      DESCRIPTION             */
148 /*                                                                        */
149 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
150 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
151 /*                                            resulting in version 6.1    */
152 /*  06-02-2021     Kenneth Maxwell          Modified comment(s),          */
153 /*                                            removed unused variable     */
154 /*                                            assignment,                 */
155 /*                                            resulting in version 6.1.7  */
156 /*                                                                        */
157 /**************************************************************************/
_gx_display_driver_32argb_pixelmap_alpha_blend(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap,GX_UBYTE alpha)158 static VOID _gx_display_driver_32argb_pixelmap_alpha_blend(GX_DRAW_CONTEXT *context,
159                                                            INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
160 {
161 int           xval;
162 int           yval;
163 int           color;
164 int           width;
165 ULONG        *get;
166 
167 GX_RECTANGLE *clip = context -> gx_draw_context_clip;
168 
169     get = (ULONG *)((pixelmap -> gx_pixelmap_data) + sizeof(GX_COLOR) * (UINT)pixelmap -> gx_pixelmap_width * (UINT)((INT)clip -> gx_rectangle_top - ypos));
170     get += (clip -> gx_rectangle_left - xpos);
171     width = clip -> gx_rectangle_right - clip -> gx_rectangle_left + 1;
172 
173     for (yval = clip -> gx_rectangle_top; yval <= clip -> gx_rectangle_bottom; yval++)
174     {
175         for (xval = clip -> gx_rectangle_left; xval <= clip -> gx_rectangle_right; xval++)
176         {
177             color = (int)(*get);
178             _gx_display_driver_32argb_pixel_blend(context, xval, yval, (GX_COLOR)color, alpha);
179             get++;
180         }
181         get += pixelmap -> gx_pixelmap_width - width;
182     }
183 }
184 
185 /**************************************************************************/
186 /*                                                                        */
187 /*  FUNCTION                                               RELEASE        */
188 /*                                                                        */
189 /*    _gx_display_driver_32argb_pixelmap_blend            PORTABLE C      */
190 /*                                                           6.1          */
191 /*  AUTHOR                                                                */
192 /*                                                                        */
193 /*    Kenneth Maxwell, Microsoft Corporation                              */
194 /*                                                                        */
195 /*  DESCRIPTION                                                           */
196 /*                                                                        */
197 /*    32xrgb format screen driver pixelmap blending function that         */
198 /*    handles compressed or uncompress, with or without alpha channel.    */
199 /*                                                                        */
200 /*  INPUT                                                                 */
201 /*                                                                        */
202 /*    context                               Drawing context               */
203 /*    xpos                                  x-coord of top-left draw point*/
204 /*    ypos                                  y-coord of top-left draw point*/
205 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
206 /*    alpha                                 blending value 0 to 255       */
207 /*                                                                        */
208 /*  OUTPUT                                                                */
209 /*                                                                        */
210 /*    None                                                                */
211 /*                                                                        */
212 /*  CALLS                                                                 */
213 /*                                                                        */
214 /*     _gx_display_driver_32argb_pixelmap_alpha_blend                     */
215 /*                                          Real pixelmap blend function  */
216 /*     _gx_display_driver_32argb_pixelmap_raw_blend                       */
217 /*                                          Real pixelmap blend function  */
218 /*                                                                        */
219 /*  CALLED BY                                                             */
220 /*                                                                        */
221 /*    GUIX Internal Code                                                  */
222 /*                                                                        */
223 /*  RELEASE HISTORY                                                       */
224 /*                                                                        */
225 /*    DATE              NAME                      DESCRIPTION             */
226 /*                                                                        */
227 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
228 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
229 /*                                            resulting in version 6.1    */
230 /*                                                                        */
231 /**************************************************************************/
_gx_display_driver_32argb_pixelmap_blend(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap,GX_UBYTE alpha)232 VOID _gx_display_driver_32argb_pixelmap_blend(GX_DRAW_CONTEXT *context,
233                                               INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
234 {
235     if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_TRANSPARENT)
236     {
237         /* Not supported yet. */
238         return;
239     }
240 
241     if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
242     {
243         return;
244     }
245 
246     if (pixelmap -> gx_pixelmap_format != GX_COLOR_FORMAT_32ARGB)
247     {
248         /* wrong color format for this driver */
249         return;
250     }
251 
252     if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)
253     {
254         /* alpha, no compression */
255         _gx_display_driver_32argb_pixelmap_alpha_blend(context, xpos, ypos, pixelmap, alpha);
256 
257     }
258     else
259     {
260         /* no compression or alpha */
261         _gx_display_driver_32argb_pixelmap_raw_blend(context, xpos, ypos, pixelmap, alpha);
262     }
263 }
264 
265