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_32bpp_rotated_pixelmap_raw_blend                 */
34 /*                                                        PORTABLE C      */
35 /*                                                           6.1.5        */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Kenneth Maxwell, Microsoft Corporation                              */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    Internal helper function that handles blending of rotated           */
43 /*    uncompressed pixlemap data without alpha channel.                   */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    context                               Drawing context               */
48 /*    xpos                                  x-coord of top-left draw point*/
49 /*    ypos                                  y-coord of top-left draw point*/
50 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
51 /*    alpha                                 blending value 0 to 255       */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    None                                                                */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _gx_display_driver_24xrgb_pixel_blend                               */
60 /*    _gx_display_driver_32argb_pixel_blend                               */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    _gx_display_driver_32bpp_rotated_pixelmap_blend                     */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
71 /*  03-02-2021     Ting Zhu                 Modified comment(s), changed  */
72 /*                                            blend function set macro,   */
73 /*                                            resulting in version 6.1.5  */
74 /*                                                                        */
75 /**************************************************************************/
_gx_display_driver_32bpp_rotated_pixelmap_raw_blend(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap,GX_UBYTE alpha)76 static VOID _gx_display_driver_32bpp_rotated_pixelmap_raw_blend(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
77 {
78 INT           yval;
79 INT           xval;
80 ULONG        *get;
81 ULONG        *getrow;
82 GX_RECTANGLE *clip = context -> gx_draw_context_clip;
83 GX_RECTANGLE  rotated_clip;
84 VOID          (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha);
85 
86     GX_SET_32BPP_BLEND_FUNCTION(blend_func, context -> gx_draw_context_display -> gx_display_color_format);
87 
88     GX_SWAP_VALS(xpos, ypos);
89 
90     if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
91     {
92         rotated_clip.gx_rectangle_left = clip -> gx_rectangle_top;
93         rotated_clip.gx_rectangle_right = clip -> gx_rectangle_bottom;
94         rotated_clip.gx_rectangle_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_right - 1);
95         rotated_clip.gx_rectangle_bottom = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_left - 1);
96         ypos = (context -> gx_draw_context_canvas -> gx_canvas_x_resolution - ypos - pixelmap -> gx_pixelmap_width);
97     }
98     else
99     {
100         rotated_clip.gx_rectangle_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_bottom - 1);
101         rotated_clip.gx_rectangle_right = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_top - 1);
102         rotated_clip.gx_rectangle_top = clip -> gx_rectangle_left;
103         rotated_clip.gx_rectangle_bottom = clip -> gx_rectangle_right;
104         xpos = (context -> gx_draw_context_canvas -> gx_canvas_y_resolution - xpos - pixelmap -> gx_pixelmap_height);
105     }
106 
107     getrow = (GX_COLOR *)pixelmap -> gx_pixelmap_data;
108     getrow +=  pixelmap -> gx_pixelmap_height * (rotated_clip.gx_rectangle_top - ypos);
109     getrow += (rotated_clip.gx_rectangle_left - xpos);
110 
111     for (yval = rotated_clip.gx_rectangle_top; yval <= rotated_clip.gx_rectangle_bottom; yval++)
112     {
113         get = getrow;
114         for (xval = rotated_clip.gx_rectangle_left; xval <= rotated_clip.gx_rectangle_right; xval++)
115         {
116             blend_func(context, xval, yval, (*get++), alpha);
117         }
118         getrow += pixelmap -> gx_pixelmap_height;
119     }
120 }
121 
122 /**************************************************************************/
123 /*                                                                        */
124 /*  FUNCTION                                               RELEASE        */
125 /*                                                                        */
126 /*    _gx_display_driver_32bpp_rotated_pixelmap_alpha_blend               */
127 /*                                                        PORTABLE C      */
128 /*                                                           6.1.5        */
129 /*  AUTHOR                                                                */
130 /*                                                                        */
131 /*    Kenneth Maxwell, Microsoft Corporation                              */
132 /*                                                                        */
133 /*  DESCRIPTION                                                           */
134 /*                                                                        */
135 /*    Internal helper function that handles blending of rotated           */
136 /*    uncompressed pixlemap data with alpha channel.                      */
137 /*                                                                        */
138 /*  INPUT                                                                 */
139 /*                                                                        */
140 /*    context                               Drawing context               */
141 /*    xpos                                  x-coord of top-left draw point*/
142 /*    ypos                                  y-coord of top-left draw point*/
143 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
144 /*    alpha                                 blending value 0 to 255       */
145 /*                                                                        */
146 /*  OUTPUT                                                                */
147 /*                                                                        */
148 /*    None                                                                */
149 /*                                                                        */
150 /*  CALLS                                                                 */
151 /*                                                                        */
152 /*    _gx_display_driver_24xrgb_pixel_blend                               */
153 /*    _gx_display_driver_32argb_pixel_blend                               */
154 /*                                                                        */
155 /*  CALLED BY                                                             */
156 /*                                                                        */
157 /*    _gx_display_driver_32bpp_rotated_pixelmap_blend                     */
158 /*                                                                        */
159 /*  RELEASE HISTORY                                                       */
160 /*                                                                        */
161 /*    DATE              NAME                      DESCRIPTION             */
162 /*                                                                        */
163 /*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
164 /*  03-02-2021     Ting Zhu                 Modified comment(s), changed  */
165 /*                                            blend function set macro,   */
166 /*                                            resulting in version 6.1.5  */
167 /*                                                                        */
168 /**************************************************************************/
_gx_display_driver_32bpp_rotated_pixelmap_alpha_blend(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap,GX_UBYTE alpha)169 static VOID _gx_display_driver_32bpp_rotated_pixelmap_alpha_blend(GX_DRAW_CONTEXT *context,
170                                                                   INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
171 {
172 int           xval;
173 int           yval;
174 ULONG        *get;
175 ULONG        *getrow;
176 UCHAR         alpha_value;
177 ULONG         combined_alpha;
178 ULONG         color;
179 GX_RECTANGLE *clip = context -> gx_draw_context_clip;
180 GX_RECTANGLE  rotated_clip;
181 VOID          (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha);
182 
183     GX_SET_32BPP_BLEND_FUNCTION(blend_func, context -> gx_draw_context_display -> gx_display_color_format);
184 
185     GX_SWAP_VALS(xpos, ypos);
186 
187     if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
188     {
189         rotated_clip.gx_rectangle_left = clip -> gx_rectangle_top;
190         rotated_clip.gx_rectangle_right = clip -> gx_rectangle_bottom;
191         rotated_clip.gx_rectangle_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_right - 1);
192         rotated_clip.gx_rectangle_bottom = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_left - 1);
193         ypos = (context -> gx_draw_context_canvas -> gx_canvas_x_resolution - ypos - pixelmap -> gx_pixelmap_width);
194     }
195     else
196     {
197         rotated_clip.gx_rectangle_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_bottom - 1);
198         rotated_clip.gx_rectangle_right = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_top - 1);
199         rotated_clip.gx_rectangle_top = clip -> gx_rectangle_left;
200         rotated_clip.gx_rectangle_bottom = clip -> gx_rectangle_right;
201         xpos = (context -> gx_draw_context_canvas -> gx_canvas_y_resolution - xpos - pixelmap -> gx_pixelmap_height);
202     }
203 
204     getrow = (GX_COLOR *)(pixelmap -> gx_pixelmap_data);
205     getrow += (pixelmap -> gx_pixelmap_height * (rotated_clip.gx_rectangle_top - ypos));
206     getrow += (rotated_clip.gx_rectangle_left - xpos);
207 
208     for (yval = rotated_clip.gx_rectangle_top; yval <= rotated_clip.gx_rectangle_bottom; yval++)
209     {
210         get = getrow;
211         for (xval = rotated_clip.gx_rectangle_left; xval <= rotated_clip.gx_rectangle_right; xval++)
212         {
213             color = (*get);
214             alpha_value = ALPHAVAL_32BPP(color);
215 
216             if (alpha_value)
217             {
218                 combined_alpha = alpha_value;
219                 combined_alpha *= alpha;
220                 combined_alpha /= 255;
221 
222                 if (combined_alpha)
223                 {
224                     color |= 0xff000000;
225                     blend_func(context, xval, yval, color, (GX_UBYTE)combined_alpha);
226                 }
227             }
228             get++;
229         }
230         getrow += pixelmap -> gx_pixelmap_height;
231     }
232 }
233 
234 
235 /**************************************************************************/
236 /*                                                                        */
237 /*  FUNCTION                                               RELEASE        */
238 /*                                                                        */
239 /*    _gx_display_driver_32bpp_rotated_palette_pixelmap_blend             */
240 /*                                                          PORTABLE C    */
241 /*                                                           6.1.5        */
242 /*  AUTHOR                                                                */
243 /*                                                                        */
244 /*    Kenneth Maxwell, Microsoft Corporation                              */
245 /*                                                                        */
246 /*  DESCRIPTION                                                           */
247 /*                                                                        */
248 /*    Internal helper function that handles writing of rotated            */
249 /*    uncompressed palette pixlemap data without transparent.             */
250 /*                                                                        */
251 /*  INPUT                                                                 */
252 /*                                                                        */
253 /*    context                               Drawing context               */
254 /*    xpos                                  x-coord of top-left draw point*/
255 /*    ypos                                  y-coord of top-left draw point*/
256 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
257 /*    alpha                                 blending value 0 to 255       */
258 /*                                                                        */
259 /*  OUTPUT                                                                */
260 /*                                                                        */
261 /*    None                                                                */
262 /*                                                                        */
263 /*  CALLS                                                                 */
264 /*                                                                        */
265 /*    _gx_display_driver_24xrgb_pixel_blend                               */
266 /*    _gx_display_driver_32argb_pixel_blend                               */
267 /*                                                                        */
268 /*  CALLED BY                                                             */
269 /*                                                                        */
270 /*    _gx_display_driver_32bpp_rotated_pixelmap_blend                     */
271 /*                                                                        */
272 /*  RELEASE HISTORY                                                       */
273 /*                                                                        */
274 /*    DATE              NAME                      DESCRIPTION             */
275 /*                                                                        */
276 /*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
277 /*  03-02-2021     Ting Zhu                 Modified comment(s), changed  */
278 /*                                            blend function set macro,   */
279 /*                                            resulting in version 6.1.5  */
280 /*                                                                        */
281 /**************************************************************************/
_gx_display_driver_32bpp_rotated_palette_pixelmap_blend(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap,GX_UBYTE alpha)282 static VOID _gx_display_driver_32bpp_rotated_palette_pixelmap_blend(GX_DRAW_CONTEXT *context,
283                                                                     INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
284 {
285 INT           xval;
286 INT           yval;
287 GX_UBYTE     *getrow;
288 GX_UBYTE     *get;
289 GX_COLOR     *palette;
290 GX_RECTANGLE *clip = context -> gx_draw_context_clip;
291 GX_RECTANGLE  rotated_clip;
292 VOID          (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha);
293 
294     GX_SET_32BPP_BLEND_FUNCTION(blend_func, context -> gx_draw_context_display -> gx_display_color_format);
295 
296     GX_SWAP_VALS(xpos, ypos);
297 
298     if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
299     {
300         rotated_clip.gx_rectangle_left = clip -> gx_rectangle_top;
301         rotated_clip.gx_rectangle_right = clip -> gx_rectangle_bottom;
302         rotated_clip.gx_rectangle_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_right - 1);
303         rotated_clip.gx_rectangle_bottom = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_left - 1);
304         ypos = (context -> gx_draw_context_canvas -> gx_canvas_x_resolution - ypos - pixelmap -> gx_pixelmap_width);
305     }
306     else
307     {
308         rotated_clip.gx_rectangle_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_bottom - 1);
309         rotated_clip.gx_rectangle_right = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_top - 1);
310         rotated_clip.gx_rectangle_top = clip -> gx_rectangle_left;
311         rotated_clip.gx_rectangle_bottom = clip -> gx_rectangle_right;
312         xpos = (context -> gx_draw_context_canvas -> gx_canvas_y_resolution - xpos - pixelmap -> gx_pixelmap_height);
313     }
314 
315     getrow = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data);
316     getrow += pixelmap -> gx_pixelmap_height * (rotated_clip.gx_rectangle_top - ypos);
317     getrow += (rotated_clip.gx_rectangle_left - xpos);
318 
319 
320     palette = (GX_COLOR *)pixelmap -> gx_pixelmap_aux_data;
321 
322     for (yval = rotated_clip.gx_rectangle_top; yval <= rotated_clip.gx_rectangle_bottom; yval++)
323     {
324         get = getrow;
325         for (xval = rotated_clip.gx_rectangle_left; xval <= rotated_clip.gx_rectangle_right; xval++)
326         {
327             blend_func(context, xval, yval, palette[*get++], alpha);
328         }
329 
330         getrow += pixelmap -> gx_pixelmap_height;
331     }
332 }
333 
334 /**************************************************************************/
335 /*                                                                        */
336 /*  FUNCTION                                               RELEASE        */
337 /*                                                                        */
338 /*    _gx_display_driver_32bpp_rotated_palette_pixelmap_transparent_blend */
339 /*                                                                        */
340 /*                                                         PORTABLE C     */
341 /*                                                           6.1.5        */
342 /*  AUTHOR                                                                */
343 /*                                                                        */
344 /*    Kenneth Maxwell, Microsoft Corporation                              */
345 /*                                                                        */
346 /*  DESCRIPTION                                                           */
347 /*                                                                        */
348 /*    Internal helper function that handles writing of rotated            */
349 /*    uncompressed palette pixlemap data with transparent.                */
350 /*                                                                        */
351 /*  INPUT                                                                 */
352 /*                                                                        */
353 /*    context                               Drawing context               */
354 /*    xpos                                  x-coord of top-left draw point*/
355 /*    ypos                                  y-coord of top-left draw point*/
356 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
357 /*    alpha                                 blending value 0 to 255       */
358 /*                                                                        */
359 /*  OUTPUT                                                                */
360 /*                                                                        */
361 /*    None                                                                */
362 /*                                                                        */
363 /*  CALLS                                                                 */
364 /*                                                                        */
365 /*    _gx_display_driver_24xrgb_pixel_blend                               */
366 /*    _gx_display_driver_32argb_pixel_blend                               */
367 /*                                                                        */
368 /*  CALLED BY                                                             */
369 /*                                                                        */
370 /*    GUIX Internal Code                                                  */
371 /*                                                                        */
372 /*  RELEASE HISTORY                                                       */
373 /*                                                                        */
374 /*    DATE              NAME                      DESCRIPTION             */
375 /*                                                                        */
376 /*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
377 /*  03-02-2021     Ting Zhu                 Modified comment(s), changed  */
378 /*                                            blend function set macro,   */
379 /*                                            resulting in version 6.1.5  */
380 /*                                                                        */
381 /**************************************************************************/
_gx_display_driver_32bpp_rotated_palette_pixelmap_transparent_blend(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap,GX_UBYTE alpha)382 static VOID _gx_display_driver_32bpp_rotated_palette_pixelmap_transparent_blend(GX_DRAW_CONTEXT *context,
383                                                                                 INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
384 {
385 INT           xval;
386 INT           yval;
387 GX_UBYTE     *getrow;
388 GX_UBYTE     *get;
389 GX_COLOR     *palette;
390 GX_RECTANGLE *clip = context -> gx_draw_context_clip;
391 GX_RECTANGLE  rotated_clip;
392 VOID          (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha);
393 
394     GX_SET_32BPP_BLEND_FUNCTION(blend_func, context -> gx_draw_context_display -> gx_display_color_format);
395 
396     GX_SWAP_VALS(xpos, ypos);
397 
398     if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
399     {
400         rotated_clip.gx_rectangle_left = clip -> gx_rectangle_top;
401         rotated_clip.gx_rectangle_right = clip -> gx_rectangle_bottom;
402         rotated_clip.gx_rectangle_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_right - 1);
403         rotated_clip.gx_rectangle_bottom = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_left - 1);
404         ypos = (context -> gx_draw_context_canvas -> gx_canvas_x_resolution - ypos - pixelmap -> gx_pixelmap_width);
405     }
406     else
407     {
408         rotated_clip.gx_rectangle_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_bottom - 1);
409         rotated_clip.gx_rectangle_right = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_top - 1);
410         rotated_clip.gx_rectangle_top = clip -> gx_rectangle_left;
411         rotated_clip.gx_rectangle_bottom = clip -> gx_rectangle_right;
412         xpos = (context -> gx_draw_context_canvas -> gx_canvas_y_resolution - xpos - pixelmap -> gx_pixelmap_height);
413     }
414 
415     getrow = (GX_UBYTE *)(pixelmap -> gx_pixelmap_data);
416     getrow += pixelmap -> gx_pixelmap_height * (rotated_clip.gx_rectangle_top - ypos);
417     getrow += (rotated_clip.gx_rectangle_left - xpos);
418     palette = (GX_COLOR *)pixelmap -> gx_pixelmap_aux_data;
419 
420     for (yval = rotated_clip.gx_rectangle_top; yval <= rotated_clip.gx_rectangle_bottom; yval++)
421     {
422         get = getrow;
423         for (xval = rotated_clip.gx_rectangle_left; xval <= rotated_clip.gx_rectangle_right; xval++)
424         {
425             if ((*get) != pixelmap -> gx_pixelmap_transparent_color)
426             {
427                 blend_func(context, xval, yval, palette[*get], alpha);
428             }
429             get++;
430         }
431 
432         getrow += pixelmap -> gx_pixelmap_height;
433     }
434 }
435 
436 /**************************************************************************/
437 /*                                                                        */
438 /*  FUNCTION                                               RELEASE        */
439 /*                                                                        */
440 /*    _gx_display_driver_32bpp_rotated_4444argb_pixelmap_alpha_blend      */
441 /*                                                                        */
442 /*                                                         PORTABLE C     */
443 /*                                                           6.1.5        */
444 /*  AUTHOR                                                                */
445 /*                                                                        */
446 /*    Kenneth Maxwell, Microsoft Corporation                              */
447 /*                                                                        */
448 /*  DESCRIPTION                                                           */
449 /*                                                                        */
450 /*    Internal helper function that handles writing of rotated            */
451 /*    uncompressed 4444argb format pixlemap data with alpha channel.      */
452 /*                                                                        */
453 /*  INPUT                                                                 */
454 /*                                                                        */
455 /*    context                               Drawing context               */
456 /*    xpos                                  x-coord of top-left draw point*/
457 /*    ypos                                  y-coord of top-left draw point*/
458 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
459 /*    alpha                                 blending value 0 to 255       */
460 /*                                                                        */
461 /*  OUTPUT                                                                */
462 /*                                                                        */
463 /*    None                                                                */
464 /*                                                                        */
465 /*  CALLS                                                                 */
466 /*                                                                        */
467 /*    _gx_display_driver_24xrgb_pixel_blend                               */
468 /*                                                                        */
469 /*  CALLED BY                                                             */
470 /*                                                                        */
471 /*    _gx_display_driver_32bpp_rotated_pixelmap_blend                     */
472 /*                                                                        */
473 /*  RELEASE HISTORY                                                       */
474 /*                                                                        */
475 /*    DATE              NAME                      DESCRIPTION             */
476 /*                                                                        */
477 /*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
478 /*  03-02-2021     Ting Zhu                 Modified comment(s), changed  */
479 /*                                            blend function set macro,   */
480 /*                                            resulting in version 6.1.5  */
481 /*                                                                        */
482 /**************************************************************************/
_gx_display_driver_32bpp_rotated_4444argb_pixelmap_alpha_blend(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap,GX_UBYTE alpha)483 static VOID _gx_display_driver_32bpp_rotated_4444argb_pixelmap_alpha_blend(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
484 {
485 INT              xval;
486 INT              yval;
487 USHORT          *getrow;
488 GX_CONST USHORT *get;
489 UCHAR            falpha;
490 GX_UBYTE         combined_alpha;
491 ULONG            pixel;
492 
493 GX_RECTANGLE    *clip = context -> gx_draw_context_clip;
494 GX_RECTANGLE     rotated_clip;
495 VOID             (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha);
496 
497     GX_SET_32BPP_BLEND_FUNCTION(blend_func, context -> gx_draw_context_display -> gx_display_color_format);
498 
499     GX_SWAP_VALS(xpos, ypos);
500 
501     if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
502     {
503         rotated_clip.gx_rectangle_left = clip -> gx_rectangle_top;
504         rotated_clip.gx_rectangle_right = clip -> gx_rectangle_bottom;
505         rotated_clip.gx_rectangle_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_right - 1);
506         rotated_clip.gx_rectangle_bottom = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_left - 1);
507         ypos = (context -> gx_draw_context_canvas -> gx_canvas_x_resolution - ypos - pixelmap -> gx_pixelmap_width);
508     }
509     else
510     {
511         rotated_clip.gx_rectangle_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_bottom - 1);
512         rotated_clip.gx_rectangle_right = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_top - 1);
513         rotated_clip.gx_rectangle_top = clip -> gx_rectangle_left;
514         rotated_clip.gx_rectangle_bottom = clip -> gx_rectangle_right;
515         xpos = (context -> gx_draw_context_canvas -> gx_canvas_y_resolution - xpos - pixelmap -> gx_pixelmap_height);
516     }
517 
518     /* Calculate how many pixels to skip.  */
519     getrow = (USHORT *)(pixelmap -> gx_pixelmap_data);
520     getrow += pixelmap -> gx_pixelmap_height * (rotated_clip.gx_rectangle_top - ypos);
521     getrow += (rotated_clip.gx_rectangle_left - xpos);
522 
523     for (yval = rotated_clip.gx_rectangle_top; yval <= rotated_clip.gx_rectangle_bottom; yval++)
524     {
525         get = getrow;
526 
527         for (xval = rotated_clip.gx_rectangle_left; xval <= rotated_clip.gx_rectangle_right; xval++)
528         {
529 
530             /* Pick alpha value from 4444argb color.  */
531             falpha = (UCHAR)(((*get) & 0xf000) >> 8);
532 
533             if (falpha)
534             {
535                 /* Extend alpha value to improve accuracy.  */
536                 falpha = (GX_UBYTE)(falpha | (falpha >> 4));
537 
538                 /* Convert 4444argb color to 24xrgb color.  */
539                 pixel = (GX_COLOR)((((*get) & 0x0f00) << 12) | (((*get) & 0x00f0) << 8) | (((*get) & 0x000f) << 4));
540                 pixel |= 0xff000000;
541 
542                 /* Calulate combined alpha.  */
543                 combined_alpha = (GX_UBYTE)(falpha * alpha / 255);
544 
545                 /* Blend color to background.  */
546                 blend_func(context, xval, yval, pixel, combined_alpha);
547             }
548             get++;
549         }
550         getrow += pixelmap -> gx_pixelmap_height;
551     }
552 }
553 
554 /**************************************************************************/
555 /*                                                                        */
556 /*  FUNCTION                                               RELEASE        */
557 /*                                                                        */
558 /*    _gx_display_driver_32bpp_rotated_565rgb_pixelmap_alpha_blend        */
559 /*                                                                        */
560 /*                                                        PORTABLE C      */
561 /*                                                           6.1.5        */
562 /*  AUTHOR                                                                */
563 /*                                                                        */
564 /*    Kenneth Maxwell, Microsoft Corporation                              */
565 /*                                                                        */
566 /*  DESCRIPTION                                                           */
567 /*                                                                        */
568 /*    Internal helper function that handles writing of rotated            */
569 /*    uncompressed 565rgb format pixelmap data with alpha channel.        */
570 /*                                                                        */
571 /*  INPUT                                                                 */
572 /*                                                                        */
573 /*    context                               Drawing context               */
574 /*    xpos                                  x-coord of top-left draw point*/
575 /*    ypos                                  y-coord of top-left draw point*/
576 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
577 /*    alpha                                 blending value 0 to 255       */
578 /*                                                                        */
579 /*  OUTPUT                                                                */
580 /*                                                                        */
581 /*    None                                                                */
582 /*                                                                        */
583 /*  CALLS                                                                 */
584 /*                                                                        */
585 /*    _gx_display_driver_24xrgb_pixel_blend                               */
586 /*    _gx_display_driver_32argb_pixel_blend                               */
587 /*                                                                        */
588 /*  CALLED BY                                                             */
589 /*                                                                        */
590 /*    _gx_display_driver_32bpp_rotated_pixelmap_blend                     */
591 /*                                                                        */
592 /*  RELEASE HISTORY                                                       */
593 /*                                                                        */
594 /*    DATE              NAME                      DESCRIPTION             */
595 /*                                                                        */
596 /*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
597 /*  03-02-2021     Ting Zhu                 Modified comment(s), changed  */
598 /*                                            blend function set macro,   */
599 /*                                            resulting in version 6.1.5  */
600 /*                                                                        */
601 /**************************************************************************/
_gx_display_driver_32bpp_rotated_565rgb_pixelmap_alpha_blend(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap,GX_UBYTE alpha)602 static VOID _gx_display_driver_32bpp_rotated_565rgb_pixelmap_alpha_blend(GX_DRAW_CONTEXT *context,
603                                                                          INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
604 {
605 INT                skipcount;
606 INT                xval;
607 INT                yval;
608 GX_CONST GX_UBYTE *getalpha;
609 GX_CONST USHORT   *get;
610 USHORT            *getrow;
611 GX_UBYTE          *getrowalpha;
612 GX_COLOR           pixel;
613 GX_UBYTE           falpha;
614 GX_UBYTE           combined_alpha;
615 GX_RECTANGLE      *clip = context -> gx_draw_context_clip;
616 GX_RECTANGLE       rotated_clip;
617 VOID               (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha);
618 
619     GX_SET_32BPP_BLEND_FUNCTION(blend_func, context -> gx_draw_context_display -> gx_display_color_format);
620 
621     GX_SWAP_VALS(xpos, ypos);
622 
623     if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
624     {
625         rotated_clip.gx_rectangle_left = clip -> gx_rectangle_top;
626         rotated_clip.gx_rectangle_right = clip -> gx_rectangle_bottom;
627         rotated_clip.gx_rectangle_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_right - 1);
628         rotated_clip.gx_rectangle_bottom = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_left - 1);
629         ypos = (context -> gx_draw_context_canvas -> gx_canvas_x_resolution - ypos - pixelmap -> gx_pixelmap_width);
630     }
631     else
632     {
633         rotated_clip.gx_rectangle_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_bottom - 1);
634         rotated_clip.gx_rectangle_right = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_top - 1);
635         rotated_clip.gx_rectangle_top = clip -> gx_rectangle_left;
636         rotated_clip.gx_rectangle_bottom = clip -> gx_rectangle_right;
637         xpos = (context -> gx_draw_context_canvas -> gx_canvas_y_resolution - xpos - pixelmap -> gx_pixelmap_height);
638     }
639 
640     skipcount = (pixelmap -> gx_pixelmap_height) * (rotated_clip.gx_rectangle_top - ypos);
641     skipcount += (rotated_clip.gx_rectangle_left - xpos);
642     getrow = (USHORT *)(pixelmap -> gx_pixelmap_data);
643     getrow += skipcount;
644 
645     getrowalpha = (GX_UBYTE *)(pixelmap -> gx_pixelmap_aux_data);
646     getrowalpha += skipcount;
647 
648     for (yval = rotated_clip.gx_rectangle_top; yval <= rotated_clip.gx_rectangle_bottom; yval++)
649     {
650         get = getrow;
651         getalpha = getrowalpha;
652 
653         for (xval = rotated_clip.gx_rectangle_left; xval <= rotated_clip.gx_rectangle_right; xval++)
654         {
655             falpha = *getalpha++;
656             if (falpha)
657             {
658                 combined_alpha = (GX_UBYTE)(falpha * alpha / 255);
659                 pixel = *get;
660 
661                 /* Convert 565rgb color to 24xrgb color.  */
662                 pixel = (GX_COLOR)ASSEMBLECOLOR_32ARGB(0xff,
663                                                        REDVAL_16BPP(pixel) << 3,
664                                                        GREENVAL_16BPP(pixel) << 2,
665                                                        BLUEVAL_16BPP(pixel) << 3);
666 
667                 /* Blend 24xrgb color to background.  */
668                 blend_func(context, xval, yval, pixel, combined_alpha);
669             }
670             get++;
671         }
672 
673         getrow += pixelmap -> gx_pixelmap_height;
674         getrowalpha += pixelmap -> gx_pixelmap_height;
675     }
676 }
677 
678 /**************************************************************************/
679 /*                                                                        */
680 /*  FUNCTION                                               RELEASE        */
681 /*                                                                        */
682 /*    _gx_display_driver_32bpp_rotated_565rgb_pixelmap_raw_blend          */
683 /*                                                        PORTABLE C      */
684 /*                                                           6.1.5        */
685 /*  AUTHOR                                                                */
686 /*                                                                        */
687 /*    Kenneth Maxwell, Microsoft Corporation                              */
688 /*                                                                        */
689 /*  DESCRIPTION                                                           */
690 /*                                                                        */
691 /*    Internal helper function that handles writing of rotated            */
692 /*    uncompressed 565rgb format pixlemap data without alpha channel.     */
693 /*                                                                        */
694 /*  INPUT                                                                 */
695 /*                                                                        */
696 /*    context                               Drawing context               */
697 /*    xpos                                  x-coord of top-left draw point*/
698 /*    ypos                                  y-coord of top-left draw point*/
699 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
700 /*    alpha                                 blending value 0 to 255       */
701 /*                                                                        */
702 /*  OUTPUT                                                                */
703 /*                                                                        */
704 /*    None                                                                */
705 /*                                                                        */
706 /*  CALLS                                                                 */
707 /*                                                                        */
708 /*    _gx_display_driver_24xrgb_pixel_blend                               */
709 /*    _gx_display_driver_32argb_pixel_blend                               */
710 /*                                                                        */
711 /*  CALLED BY                                                             */
712 /*                                                                        */
713 /*    _gx_display_driver_32bpp_rotated_pixelmap_blend                     */
714 /*                                                                        */
715 /*  RELEASE HISTORY                                                       */
716 /*                                                                        */
717 /*    DATE              NAME                      DESCRIPTION             */
718 /*                                                                        */
719 /*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
720 /*  03-02-2021     Ting Zhu                 Modified comment(s), changed  */
721 /*                                            blend function set macro,   */
722 /*                                            resulting in version 6.1.5  */
723 /*                                                                        */
724 /**************************************************************************/
_gx_display_driver_32bpp_rotated_565rgb_pixelmap_raw_blend(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap,GX_UBYTE alpha)725 static VOID _gx_display_driver_32bpp_rotated_565rgb_pixelmap_raw_blend(GX_DRAW_CONTEXT *context, INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
726 {
727 INT              xval;
728 INT              yval;
729 USHORT          *getrow;
730 GX_CONST USHORT *get;
731 GX_COLOR         pixel;
732 GX_RECTANGLE    *clip = context -> gx_draw_context_clip;
733 GX_RECTANGLE     rotated_clip;
734 VOID             (*blend_func)(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha);
735 
736     GX_SET_32BPP_BLEND_FUNCTION(blend_func, context -> gx_draw_context_display -> gx_display_color_format);
737 
738     GX_SWAP_VALS(xpos, ypos);
739 
740     if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
741     {
742         rotated_clip.gx_rectangle_left = clip -> gx_rectangle_top;
743         rotated_clip.gx_rectangle_right = clip -> gx_rectangle_bottom;
744         rotated_clip.gx_rectangle_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_right - 1);
745         rotated_clip.gx_rectangle_bottom = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - clip -> gx_rectangle_left - 1);
746         ypos = (context -> gx_draw_context_canvas -> gx_canvas_x_resolution - ypos - pixelmap -> gx_pixelmap_width);
747     }
748     else
749     {
750         rotated_clip.gx_rectangle_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_bottom - 1);
751         rotated_clip.gx_rectangle_right = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - clip -> gx_rectangle_top - 1);
752         rotated_clip.gx_rectangle_top = clip -> gx_rectangle_left;
753         rotated_clip.gx_rectangle_bottom = clip -> gx_rectangle_right;
754         xpos = (context -> gx_draw_context_canvas -> gx_canvas_y_resolution - xpos - pixelmap -> gx_pixelmap_height);
755     }
756 
757     getrow = (USHORT *)(pixelmap -> gx_pixelmap_data);
758     getrow += pixelmap -> gx_pixelmap_height * (rotated_clip.gx_rectangle_top - ypos);
759     getrow += (rotated_clip.gx_rectangle_left - xpos);
760 
761     for (yval = rotated_clip.gx_rectangle_top; yval <= rotated_clip.gx_rectangle_bottom; yval++)
762     {
763         get = getrow;
764 
765         for (xval = rotated_clip.gx_rectangle_left; xval <= rotated_clip.gx_rectangle_right; xval++)
766         {
767             /* Convert 565rgb color to 24xrgb color.  */
768             pixel = (GX_COLOR)ASSEMBLECOLOR_32ARGB(0xff,
769                                                    REDVAL_16BPP(*get) << 3,
770                                                    GREENVAL_16BPP(*get) << 2,
771                                                    BLUEVAL_16BPP(*get) << 3);
772 
773             blend_func(context, xval, yval, pixel, alpha);
774             get++;
775         }
776 
777         getrow += pixelmap -> gx_pixelmap_height;
778     }
779 }
780 
781 /**************************************************************************/
782 /*                                                                        */
783 /*  FUNCTION                                               RELEASE        */
784 /*                                                                        */
785 /*    _gx_display_driver_32bpp_rotated_pixelmap_blend    PORTABLE C       */
786 /*                                                           6.1.4        */
787 /*  AUTHOR                                                                */
788 /*                                                                        */
789 /*    Kenneth Maxwell, Microsoft Corporation                              */
790 /*                                                                        */
791 /*  DESCRIPTION                                                           */
792 /*                                                                        */
793 /*    24xrgb format screen driver pixelmap blending function that         */
794 /*    handles uncompressed pixelmap blend, with or without alpha channel. */
795 /*                                                                        */
796 /*  INPUT                                                                 */
797 /*                                                                        */
798 /*    context                               Drawing context               */
799 /*    xpos                                  x-coord of top-left draw point*/
800 /*    ypos                                  y-coord of top-left draw point*/
801 /*    pixelmap                              Pointer to GX_PIXELMAP struct */
802 /*    alpha                                 blending value 0 to 255       */
803 /*                                                                        */
804 /*  OUTPUT                                                                */
805 /*                                                                        */
806 /*    None                                                                */
807 /*                                                                        */
808 /*  CALLS                                                                 */
809 /*                                                                        */
810 /*    _gx_display_driver_32bpp_rotated_palette_pixelmap_transparent_blend */
811 /*    _gx_display_driver_32bpp_rotated_palette_pixelmap_blend             */
812 /*    _gx_display_driver_32bpp_rotated_4444argb_pixelmap_alpha_blend      */
813 /*    _gx_display_driver_32bpp_rotated_565rgb_pixelmap_alpha_blend        */
814 /*    _gx_display_driver_32bpp_rotated_565rgb_pixelmap_raw_blend          */
815 /*    _gx_display_driver_32bpp_rotated_pixelmap_alpha_blend               */
816 /*    _gx_display_driver_32bpp_rotated_pixelmap_raw_blend                 */
817 /*                                                                        */
818 /*  CALLED BY                                                             */
819 /*                                                                        */
820 /*    GUIX Internal Code                                                  */
821 /*                                                                        */
822 /*  RELEASE HISTORY                                                       */
823 /*                                                                        */
824 /*    DATE              NAME                      DESCRIPTION             */
825 /*                                                                        */
826 /*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
827 /*                                                                        */
828 /**************************************************************************/
_gx_display_driver_32bpp_rotated_pixelmap_blend(GX_DRAW_CONTEXT * context,INT xpos,INT ypos,GX_PIXELMAP * pixelmap,GX_UBYTE alpha)829 VOID _gx_display_driver_32bpp_rotated_pixelmap_blend(GX_DRAW_CONTEXT *context,
830                                                      INT xpos, INT ypos, GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
831 {
832     if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
833     {
834         return;
835     }
836 
837     switch (pixelmap -> gx_pixelmap_format)
838     {
839     case GX_COLOR_FORMAT_8BIT_PALETTE:
840         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_TRANSPARENT)
841         {
842             _gx_display_driver_32bpp_rotated_palette_pixelmap_transparent_blend(context, xpos, ypos, pixelmap, alpha);
843         }
844         else
845         {
846             _gx_display_driver_32bpp_rotated_palette_pixelmap_blend(context, xpos, ypos, pixelmap, alpha);
847         }
848         break;
849 
850     case GX_COLOR_FORMAT_4444ARGB:
851         _gx_display_driver_32bpp_rotated_4444argb_pixelmap_alpha_blend(context, xpos, ypos, pixelmap, alpha);
852         break;
853 
854     case GX_COLOR_FORMAT_565RGB:
855         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)
856         {
857             _gx_display_driver_32bpp_rotated_565rgb_pixelmap_alpha_blend(context, xpos, ypos, pixelmap, alpha);
858         }
859         else
860         {
861             _gx_display_driver_32bpp_rotated_565rgb_pixelmap_raw_blend(context, xpos, ypos, pixelmap, alpha);
862         }
863         break;
864 
865     case GX_COLOR_FORMAT_24XRGB:
866     case GX_COLOR_FORMAT_32ARGB:
867         if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA)
868         {
869             _gx_display_driver_32bpp_rotated_pixelmap_alpha_blend(context, xpos, ypos, pixelmap, alpha);
870         }
871         else
872         {
873             _gx_display_driver_32bpp_rotated_pixelmap_raw_blend(context, xpos, ypos, pixelmap, alpha);
874         }
875         break;
876     }
877 
878     return;
879 }
880 
881