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