1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Display Management (Display)                                        */
19 /**                                                                       */
20 /**************************************************************************/
21 #define GX_SOURCE_CODE
22 
23 
24 #include "gx_api.h"
25 #include "gx_display.h"
26 
27 /**************************************************************************/
28 /*                                                                        */
29 /*  FUNCTION                                               RELEASE        */
30 /*                                                                        */
31 /*    _gx_display_driver_32argb_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 32argb 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                                 blending value 0 to 255       */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    None                                                                */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    None                                                                */
56 /*                                                                        */
57 /*  CALLED BY                                                             */
58 /*                                                                        */
59 /*    GUIX Internal Code                                                  */
60 /*                                                                        */
61 /*  RELEASE HISTORY                                                       */
62 /*                                                                        */
63 /*    DATE              NAME                      DESCRIPTION             */
64 /*                                                                        */
65 /*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
66 /*                                                                        */
67 /**************************************************************************/
_gx_display_driver_32argb_rotated_pixel_blend(GX_DRAW_CONTEXT * context,INT x,INT y,GX_COLOR fcolor,GX_UBYTE alpha)68 VOID _gx_display_driver_32argb_rotated_pixel_blend(GX_DRAW_CONTEXT *context, INT x, INT y, GX_COLOR fcolor, GX_UBYTE alpha)
69 {
70 GX_UBYTE falpha, fred, fgreen, fblue;
71 GX_UBYTE balpha, bred, bgreen, bblue;
72 GX_UBYTE oalpha;
73 ULONG    bcolor;
74 ULONG   *put;
75 INT      combined_alpha;
76 
77 
78     falpha = ALPHAVAL_32BPP(fcolor);
79     falpha = (GX_UBYTE)((falpha * alpha) / 255);
80 
81     /* Is the pixel non-transparent?  */
82     if (falpha > 0)
83     {
84 
85         /* Calculate address of pixel.  */
86         put = (ULONG *)context -> gx_draw_context_memory;
87 
88         GX_SWAP_VALS(x, y);
89         if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
90         {
91             y = context -> gx_draw_context_canvas -> gx_canvas_x_resolution - y - 1;
92         }
93         else
94         {
95             x = context -> gx_draw_context_canvas -> gx_canvas_y_resolution - x - 1;
96         }
97 
98         put += context -> gx_draw_context_pitch * y;
99         put += x;
100 
101         /* No need to blend if alpha value is 255.  */
102         if (falpha == 255)
103         {
104             *put = (ULONG)fcolor;
105             return;
106         }
107 
108         /* Split foreground into alpha, red, green, and blue components.  */
109         fred = REDVAL_32BPP(fcolor);
110         fgreen = GREENVAL_32BPP(fcolor);
111         fblue = BLUEVAL_32BPP(fcolor);
112 
113         /* Read background color.  */
114         bcolor = *put;
115 
116         /* Split background color into red, green, and blue components.  */
117         balpha = ALPHAVAL_32BPP(bcolor);
118         bred = REDVAL_32BPP(bcolor);
119         bgreen = GREENVAL_32BPP(bcolor);
120         bblue = BLUEVAL_32BPP(bcolor);
121 
122         /* Background alpha is inverse of foreground alpha.  */
123         combined_alpha = (falpha * balpha) / 0xff;
124 
125         /* Blend foreground and background, each color channel.  */
126         oalpha = (GX_UBYTE)(falpha + balpha - combined_alpha);
127         fred = (GX_UBYTE)((fred * falpha + bred * balpha - bred * combined_alpha) / oalpha);
128         fgreen = (GX_UBYTE)((fgreen * falpha + bgreen * balpha - bgreen * combined_alpha) / oalpha);
129         fblue = (GX_UBYTE)((fblue * falpha + bblue * balpha - bblue * combined_alpha) / oalpha);
130 
131         /* Re-assemble into 16-bit color and write it out.  */
132         *put = (ULONG)ASSEMBLECOLOR_32ARGB(oalpha, fred, fgreen, fblue);
133     }
134 }
135 
136