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 #define GX_SOURCE_CODE
21 
22 /* Include necessary system files.  */
23 
24 #include "gx_api.h"
25 #include "gx_display.h"
26 
27 /**************************************************************************/
28 /*                                                                        */
29 /*  FUNCTION                                               RELEASE        */
30 /*                                                                        */
31 /*    _gx_display_driver_24xrgb_rotated_pixel_blend       PORTABLE C      */
32 /*                                                           6.1.4        */
33 /*  AUTHOR                                                                */
34 /*                                                                        */
35 /*    Kenneth Maxwell, Microsoft Corporation                              */
36 /*                                                                        */
37 /*  DESCRIPTION                                                           */
38 /*                                                                        */
39 /*    Rotated pixel blend function for 24xrgb color format.               */
40 /*                                                                        */
41 /*  INPUT                                                                 */
42 /*                                                                        */
43 /*    context                               Drawing context               */
44 /*    x                                     X coordinate                  */
45 /*    y                                     Y coordinate                  */
46 /*    color                                 Color of line to write        */
47 /*    alpha                                 Alpha value                   */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    None                                                                */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    REDVAL_24BPP                          Extract the red component     */
56 /*    GREENVAL_24BPP                        Extract the green component   */
57 /*    BLUEVAL_24BPP                         Extract the blue component    */
58 /*    ASSEMBLECOLOR_24BPP                   Assemble color components     */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    GUIX Internal Code                                                  */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
69 /*                                                                        */
70 /**************************************************************************/
_gx_display_driver_24xrgb_rotated_pixel_blend(GX_DRAW_CONTEXT * context,INT x,INT y,GX_COLOR fcolor,GX_UBYTE alpha)71 VOID _gx_display_driver_24xrgb_rotated_pixel_blend(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha)
72 {
73 GX_UBYTE fred, fgreen, fblue;
74 GX_UBYTE bred, bgreen, bblue;
75 GX_UBYTE balpha;
76 ULONG    bcolor;
77 ULONG   *put;
78 
79 
80     /* Is the pixel non-transparent?  */
81     if (alpha > 0)
82     {
83         /* Calculate address of pixel.  */
84         put = (ULONG *)context -> gx_draw_context_memory;
85 
86         if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
87         {
88             put += context -> gx_draw_context_pitch * (context -> gx_draw_context_canvas -> gx_canvas_x_resolution - x - 1);
89             put += y;
90         }
91         else
92         {
93             put += context -> gx_draw_context_pitch * x;
94             put += (context -> gx_draw_context_canvas -> gx_canvas_y_resolution - y - 1);
95         }
96 
97         /* No need to blend if alpha value is 255.  */
98         if (alpha == 255)
99         {
100             *put = (ULONG)(fcolor | 0xff000000);
101 
102             return;
103         }
104 
105         /* Split foreground into red, green, and blue components.  */
106         fred = REDVAL_24BPP(fcolor);
107         fgreen = GREENVAL_24BPP(fcolor);
108         fblue = BLUEVAL_24BPP(fcolor);
109 
110         /* Read background color.  */
111         bcolor = *put;
112 
113         /* Split background color into red, green, and blue components.  */
114         bred = REDVAL_24BPP(bcolor);
115         bgreen = GREENVAL_24BPP(bcolor);
116         bblue = BLUEVAL_24BPP(bcolor);
117 
118         /* Background alpha is inverse of foreground alpha.  */
119         balpha = (GX_UBYTE)(256 - alpha);
120 
121         /* Blend foreground and background, each color channel.  */
122         fred = (GX_UBYTE)(((bred * balpha) + (fred * alpha)) >> 8);
123         fgreen = (GX_UBYTE)(((bgreen * balpha) + (fgreen * alpha)) >> 8);
124         fblue = (GX_UBYTE)(((bblue * balpha) + (fblue * alpha)) >> 8);
125 
126         /* Re-assemble into 32-bit color and write it out.  */
127         *put = (ULONG)(ASSEMBLECOLOR_32ARGB(0xff, fred, fgreen, fblue));
128     }
129 }
130 
131