GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_565rgb_canvas_blend.c Lines: 33 33 100.0 %
Date: 2024-12-05 08:52:37 Branches: 6 6 100.0 %

Line Branch Exec Source
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
#define REDVAL(_c)   (GX_UBYTE)(((_c) >> 11) & 0x1f)
30
#define GREENVAL(_c) (GX_UBYTE)(((_c) >> 5) & 0x3f)
31
#define BLUEVAL(_c)  (GX_UBYTE)(((_c)) & 0x1f)
32
33
34
/* Define macros for assembling a 16-bit r:g:b value from 3 components.  */
35
36
#define ASSEMBLECOLOR(_r, _g, _b) \
37
    ((((_r) & 0x1f) << 11) |      \
38
     (((_g) & 0x3f) << 5) |       \
39
     (((_b) & 0x1f)))
40
41
42
/**************************************************************************/
43
/*                                                                        */
44
/*  FUNCTION                                               RELEASE        */
45
/*                                                                        */
46
/*    _gx_display_driver_565rgb_canvas_blend              PORTABLE C      */
47
/*                                                           6.3.0        */
48
/*  AUTHOR                                                                */
49
/*                                                                        */
50
/*    Kenneth Maxwell, Microsoft Corporation                              */
51
/*                                                                        */
52
/*  DESCRIPTION                                                           */
53
/*                                                                        */
54
/*    Canvas blend function for 565rgb color foramt.                      */
55
/*                                                                        */
56
/*  INPUT                                                                 */
57
/*                                                                        */
58
/*   canvas                                 The canvas to blend to        */
59
/*   composite                              The canvas to blend from      */
60
/*                                                                        */
61
/*  OUTPUT                                                                */
62
/*                                                                        */
63
/*    None                                                                */
64
/*                                                                        */
65
/*  CALLS                                                                 */
66
/*                                                                        */
67
/*    _gx_utility_rectangle_shift           Adjust the rectangle          */
68
/*    _gx_utility_recttangle_overlap_detect Detect whether two areas      */
69
/*                                            overlap                     */
70
/*    REDVAL                                Extrace Red from canvas       */
71
/*    GREENVAL                              Extrace Green from canvas     */
72
/*    BLUEVAL                               Extrace Blue from canvas      */
73
/*    ASSEMBLECOLOR                         Compose the RGB color         */
74
/*                                                                        */
75
/*  CALLED BY                                                             */
76
/*                                                                        */
77
/*    GUIX Internal Code                                                  */
78
/*                                                                        */
79
/*  RELEASE HISTORY                                                       */
80
/*                                                                        */
81
/*    DATE              NAME                      DESCRIPTION             */
82
/*                                                                        */
83
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
84
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
85
/*  10-31-2023     Ting Zhu                 Modified comment(s),          */
86
/*                                            added canvas status check,  */
87
/*                                            resulting in version 6.3.0  */
88
/*                                                                        */
89
/**************************************************************************/
90
276
VOID _gx_display_driver_565rgb_canvas_blend(GX_CANVAS *canvas, GX_CANVAS *composite)
91
{
92
GX_RECTANGLE dirty;
93
GX_RECTANGLE overlap;
94
USHORT      *read;
95
USHORT      *read_start;
96
USHORT      *write;
97
USHORT      *write_start;
98
USHORT       fcolor;
99
GX_UBYTE     fred, fgreen, fblue;
100
GX_UBYTE     bred, bgreen, bblue;
101
GX_UBYTE     alpha, balpha;
102
103
USHORT       bcolor;
104
INT          row;
105
INT          col;
106
107
#ifdef GX_ENABLE_CANVAS_PARTIAL_FRAME_BUFFER
108
    if (canvas -> gx_canvas_status & GX_CANVAS_PARTIAL_FRAME_BUFFER)
109
    {
110
        /* Not supported. */
111
        return;
112
    }
113
#endif
114
115
276
    dirty.gx_rectangle_left = dirty.gx_rectangle_top = 0;
116
276
    dirty.gx_rectangle_right = (GX_VALUE)(canvas -> gx_canvas_x_resolution - 1);
117
276
    dirty.gx_rectangle_bottom = (GX_VALUE)(canvas -> gx_canvas_y_resolution - 1);
118
119
276
    _gx_utility_rectangle_shift(&dirty, canvas -> gx_canvas_display_offset_x, canvas -> gx_canvas_display_offset_y);
120
121
276
    if (_gx_utility_rectangle_overlap_detect(&dirty, &composite -> gx_canvas_dirty_area, &overlap))
122
    {
123
275
        alpha = canvas -> gx_canvas_alpha;
124
275
        balpha = (GX_UBYTE)(256 - alpha);
125
126
275
        read_start = (USHORT *)canvas -> gx_canvas_memory;
127
128
        /* index into starting row */
129
275
        read_start += (overlap.gx_rectangle_top - dirty.gx_rectangle_top) * canvas -> gx_canvas_x_resolution;
130
131
        /* index into pixel */
132
133
275
        read_start += overlap.gx_rectangle_left - dirty.gx_rectangle_left;
134
135
        /* calculate the write pointer */
136
275
        write_start = (USHORT *)composite -> gx_canvas_memory;
137
275
        write_start += overlap.gx_rectangle_top * composite -> gx_canvas_x_resolution;
138
275
        write_start += overlap.gx_rectangle_left;
139
140
20350
        for (row = overlap.gx_rectangle_top; row <= overlap.gx_rectangle_bottom; row++)
141
        {
142
20075
            read = read_start;
143
20075
            write = write_start;
144
145
1907125
            for (col = overlap.gx_rectangle_left; col <= overlap.gx_rectangle_right; col++)
146
            {
147
                /* read the foreground color */
148
1887050
                fcolor = *read++;
149
150
                /* split foreground into red, green, and blue components */
151
1887050
                fred = REDVAL(fcolor);
152
1887050
                fgreen = GREENVAL(fcolor);
153
1887050
                fblue = BLUEVAL(fcolor);
154
155
                /* read background color */
156
1887050
                bcolor = *write;
157
158
                /* split background color into red, green, and blue components */
159
1887050
                bred = REDVAL(bcolor);
160
1887050
                bgreen = GREENVAL(bcolor);
161
1887050
                bblue = BLUEVAL(bcolor);
162
163
                /* blend foreground and background, each color channel */
164
1887050
                fred = (GX_UBYTE)(((bred * balpha) + (fred * alpha)) >> 8);
165
1887050
                fgreen = (GX_UBYTE)(((bgreen * balpha) + (fgreen * alpha)) >> 8);
166
1887050
                fblue = (GX_UBYTE)(((bblue * balpha) + (fblue * alpha)) >> 8);
167
168
                /* re-assemble into 16-bit color and write it out */
169
1887050
                *write++ = (USHORT)ASSEMBLECOLOR(fred, fgreen, fblue);
170
            }
171
20075
            write_start += composite -> gx_canvas_x_resolution;
172
20075
            read_start += canvas -> gx_canvas_x_resolution;
173
        }
174
    }
175
276
}
176