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 /* Include necessary system files.  */
24 
25 #include "gx_api.h"
26 #include "gx_display.h"
27 #include "gx_utility.h"
28 
29 /**************************************************************************/
30 /*                                                                        */
31 /*  FUNCTION                                               RELEASE        */
32 /*                                                                        */
33 /*    _gx_display_driver_24xrgb_rotated_canvas_blend      PORTABLE C      */
34 /*                                                           6.1.4        */
35 /*  AUTHOR                                                                */
36 /*                                                                        */
37 /*    Kenneth Maxwell, Microsoft Corporation                              */
38 /*                                                                        */
39 /*  DESCRIPTION                                                           */
40 /*                                                                        */
41 /*    Rotated canvas blend function for 24xrgb color format.              */
42 /*                                                                        */
43 /*  INPUT                                                                 */
44 /*                                                                        */
45 /*   canvas                                 The canvas to blend to        */
46 /*   composite                              The canvas to blend from      */
47 /*                                                                        */
48 /*  OUTPUT                                                                */
49 /*                                                                        */
50 /*    None                                                                */
51 /*                                                                        */
52 /*  CALLS                                                                 */
53 /*                                                                        */
54 /*    _gx_utility_rectangle_shift           Adjust the rectangle          */
55 /*    _gx_utility_recttangle_overlap_detect Detect whether two areas      */
56 /*                                            overlap                     */
57 /*    REDVAL_24BPP                          Extrace Red from canvas       */
58 /*    GREENVAL_24BPP                        Extrace Green from canvas     */
59 /*    BLUEVAL_24BPP                         Extrace Blue from canvas      */
60 /*    ASSEMBLECOLOR_24BPP                   Compose the RGB color         */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    GUIX Internal Code                                                  */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  02-02-2021     Kenneth Maxwell          Initial Version 6.1.4         */
71 /*                                                                        */
72 /**************************************************************************/
_gx_display_driver_24xrgb_rotated_canvas_blend(GX_CANVAS * canvas,GX_CANVAS * composite)73 VOID _gx_display_driver_24xrgb_rotated_canvas_blend(GX_CANVAS *canvas, GX_CANVAS *composite)
74 {
75 GX_RECTANGLE dirty;
76 GX_RECTANGLE overlap;
77 ULONG       *read;
78 ULONG       *read_start;
79 ULONG       *write;
80 ULONG       *write_start;
81 ULONG        fcolor;
82 GX_UBYTE     fred, fgreen, fblue;
83 GX_UBYTE     bred, bgreen, bblue;
84 GX_UBYTE     alpha, balpha;
85 
86 ULONG        bcolor;
87 INT          row;
88 INT          col;
89 
90     dirty.gx_rectangle_left = dirty.gx_rectangle_top = 0;
91     dirty.gx_rectangle_right = (GX_VALUE)(canvas -> gx_canvas_x_resolution - 1);
92     dirty.gx_rectangle_bottom = (GX_VALUE)(canvas -> gx_canvas_y_resolution - 1);
93 
94     _gx_utility_rectangle_shift(&dirty, canvas -> gx_canvas_display_offset_x, canvas -> gx_canvas_display_offset_y);
95 
96     if (_gx_utility_rectangle_overlap_detect(&dirty, &composite -> gx_canvas_dirty_area, &overlap))
97     {
98         alpha = canvas -> gx_canvas_alpha;
99         balpha = (GX_UBYTE)(256 - alpha);
100 
101         read_start = (ULONG *)canvas -> gx_canvas_memory;
102         write_start = (ULONG *)composite -> gx_canvas_memory;
103 
104         if (canvas -> gx_canvas_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
105         {
106             /* Index into starting row.  */
107             read_start += (dirty.gx_rectangle_right - overlap.gx_rectangle_right) * canvas -> gx_canvas_y_resolution;
108 
109             /* Index into pixel.  */
110             read_start += overlap.gx_rectangle_top - dirty.gx_rectangle_top;
111 
112             /* Calculate the write pointer.  */
113             write_start += (composite -> gx_canvas_x_resolution - overlap.gx_rectangle_right - 1) * composite -> gx_canvas_y_resolution;
114             write_start += overlap.gx_rectangle_top;
115         }
116         else
117         {
118             /* Index into starting row.  */
119             read_start += (overlap.gx_rectangle_left - dirty.gx_rectangle_left) * canvas -> gx_canvas_y_resolution;
120 
121             /* Index into pixel.  */
122             read_start += dirty.gx_rectangle_bottom - overlap.gx_rectangle_bottom;
123 
124             /* Calculate the write pointer.  */
125             write_start += overlap.gx_rectangle_left * composite -> gx_canvas_y_resolution;
126             write_start += (composite -> gx_canvas_y_resolution - overlap.gx_rectangle_bottom - 1);
127         }
128 
129         for (row = overlap.gx_rectangle_left; row <= overlap.gx_rectangle_right; row++)
130         {
131             read = read_start;
132             write = write_start;
133 
134             for (col = overlap.gx_rectangle_top; col <= overlap.gx_rectangle_bottom; col++)
135             {
136                 /* Read the foreground color.  */
137                 fcolor = *read++;
138 
139                 /* Split foreground into red, green, and blue components.  */
140                 fred = REDVAL_24BPP(fcolor);
141                 fgreen = GREENVAL_24BPP(fcolor);
142                 fblue = BLUEVAL_24BPP(fcolor);
143 
144                 /* Read background color.  */
145                 bcolor = *write;
146 
147                 /* Split background color into red, green, and blue components.  */
148                 bred = REDVAL_24BPP(bcolor);
149                 bgreen = GREENVAL_24BPP(bcolor);
150                 bblue = BLUEVAL_24BPP(bcolor);
151 
152                 /* Blend foreground and background, each color channel.  */
153                 fred = (GX_UBYTE)(((bred * balpha) + (fred * alpha)) >> 8);
154                 fgreen = (GX_UBYTE)(((bgreen * balpha) + (fgreen * alpha)) >> 8);
155                 fblue = (GX_UBYTE)(((bblue * balpha) + (fblue * alpha)) >> 8);
156 
157                 /* Re-assemble into 16-bit color and write it out.  */
158                 *write++ = ASSEMBLECOLOR_32ARGB((ULONG)0xff, (ULONG)fred, (ULONG)fgreen, (ULONG)fblue);
159             }
160 
161             write_start += composite -> gx_canvas_y_resolution;
162             read_start += canvas -> gx_canvas_y_resolution;
163         }
164     }
165 }
166 
167