GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_1555xrgb_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) >> 10) & 0x1f)
30
#define GREENVAL(_c) (GX_UBYTE)(((_c) >> 5) & 0x1f)
31
#define BLUEVAL(_c)  (GX_UBYTE)(((_c)) & 0x1f)
32
33
34
/* Define macros for assembling a 15-bit r:g:b value from 3 components.  */
35
36
#define ASSEMBLECOLOR(_r, _g, _b) \
37
    ((((_r) & 0x7c) << 10) |      \
38
     (((_g) & 0x3e) << 5) |       \
39
     (((_b) & 0x1f)))
40
41
42
/**************************************************************************/
43
/*                                                                        */
44
/*  FUNCTION                                               RELEASE        */
45
/*                                                                        */
46
/*    _gx_display_driver_1555xrgb_canvas_blend            PORTABLE C      */
47
/*                                                           6.1          */
48
/*  AUTHOR                                                                */
49
/*                                                                        */
50
/*    Kenneth Maxwell, Microsoft Corporation                              */
51
/*                                                                        */
52
/*  DESCRIPTION                                                           */
53
/*                                                                        */
54
/*    Canvas blend function for 1555xrgb 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           Shift rectangle by specified  */
68
/*                                            value                       */
69
/*    _gx_utility_rectangle_overlap_detect  Detect overlaps of specified  */
70
/*                                            rectangles                  */
71
/*    REDVAL                                Extrace Red from canvas       */
72
/*    GREENVAL                              Extrace Green from canvas     */
73
/*    BLUEVAL                               Extrace Blue from canvas      */
74
/*    ASSEMBLECOLOR                         Compose the RGB color         */
75
/*                                                                        */
76
/*  CALLED BY                                                             */
77
/*                                                                        */
78
/*    GUIX Internal Code                                                  */
79
/*                                                                        */
80
/*  RELEASE HISTORY                                                       */
81
/*                                                                        */
82
/*    DATE              NAME                      DESCRIPTION             */
83
/*                                                                        */
84
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
85
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
86
/*                                            resulting in version 6.1    */
87
/*                                                                        */
88
/**************************************************************************/
89
256
VOID _gx_display_driver_1555xrgb_canvas_blend(GX_CANVAS *canvas, GX_CANVAS *composite)
90
{
91
GX_RECTANGLE dirty;
92
GX_RECTANGLE overlap;
93
USHORT      *read;
94
USHORT      *read_start;
95
USHORT      *write;
96
USHORT      *write_start;
97
USHORT       fcolor;
98
GX_UBYTE     fred, fgreen, fblue;
99
GX_UBYTE     bred, bgreen, bblue;
100
GX_UBYTE     alpha, balpha;
101
102
USHORT       bcolor;
103
INT          row;
104
INT          col;
105
106
256
    dirty.gx_rectangle_left = dirty.gx_rectangle_top = 0;
107
256
    dirty.gx_rectangle_right = (GX_VALUE)(canvas -> gx_canvas_x_resolution - 1);
108
256
    dirty.gx_rectangle_bottom = (GX_VALUE)(canvas -> gx_canvas_y_resolution - 1);
109
110
256
    _gx_utility_rectangle_shift(&dirty, canvas -> gx_canvas_display_offset_x, canvas -> gx_canvas_display_offset_y);
111
112
256
    if (_gx_utility_rectangle_overlap_detect(&dirty, &composite -> gx_canvas_dirty_area, &overlap))
113
    {
114
255
        alpha = canvas -> gx_canvas_alpha;
115
255
        balpha = (GX_UBYTE)(256 - alpha);
116
117
255
        read_start = (USHORT *)canvas -> gx_canvas_memory;
118
119
        /* index into starting row */
120
255
        read_start += (overlap.gx_rectangle_top - dirty.gx_rectangle_top) * canvas -> gx_canvas_x_resolution;
121
122
        /* index into pixel */
123
124
255
        read_start += overlap.gx_rectangle_left - dirty.gx_rectangle_left;
125
126
        /* calculate the write pointer */
127
255
        write_start = (USHORT *)composite -> gx_canvas_memory;
128
255
        write_start += overlap.gx_rectangle_top * composite -> gx_canvas_x_resolution;
129
255
        write_start += overlap.gx_rectangle_left;
130
131
18870
        for (row = overlap.gx_rectangle_top; row <= overlap.gx_rectangle_bottom; row++)
132
        {
133
18615
            read = read_start;
134
18615
            write = write_start;
135
136
1768425
            for (col = overlap.gx_rectangle_left; col <= overlap.gx_rectangle_right; col++)
137
            {
138
                /* read the foreground color */
139
1749810
                fcolor = *read++;
140
141
                /* split foreground into red, green, and blue components */
142
1749810
                fred = REDVAL(fcolor);
143
1749810
                fgreen = GREENVAL(fcolor);
144
1749810
                fblue = BLUEVAL(fcolor);
145
146
                /* read background color */
147
1749810
                bcolor = *write;
148
149
                /* split background color into red, green, and blue components */
150
1749810
                bred = REDVAL(bcolor);
151
1749810
                bgreen = GREENVAL(bcolor);
152
1749810
                bblue = BLUEVAL(bcolor);
153
154
                /* blend foreground and background, each color channel */
155
1749810
                fred = (GX_UBYTE)(((bred * balpha) + (fred * alpha)) >> 8);
156
1749810
                fgreen = (GX_UBYTE)(((bgreen * balpha) + (fgreen * alpha)) >> 8);
157
1749810
                fblue = (GX_UBYTE)(((bblue * balpha) + (fblue * alpha)) >> 8);
158
159
                /* re-assemble into 16-bit color and write it out */
160
1749810
                *write++ = (USHORT)ASSEMBLECOLOR(fred, fgreen, fblue);
161
            }
162
18615
            write_start += composite -> gx_canvas_x_resolution;
163
18615
            read_start += canvas -> gx_canvas_x_resolution;
164
        }
165
    }
166
256
}
167