GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_1555xrgb_canvas_blend.c Lines: 33 33 100.0 %
Date: 2026-03-06 19:21:09 Branches: 6 6 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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
#define REDVAL(_c)   (GX_UBYTE)(((_c) >> 10) & 0x1f)
31
#define GREENVAL(_c) (GX_UBYTE)(((_c) >> 5) & 0x1f)
32
#define BLUEVAL(_c)  (GX_UBYTE)(((_c)) & 0x1f)
33
34
35
/* Define macros for assembling a 15-bit r:g:b value from 3 components.  */
36
37
#define ASSEMBLECOLOR(_r, _g, _b) \
38
    ((((_r) & 0x7c) << 10) |      \
39
     (((_g) & 0x3e) << 5) |       \
40
     (((_b) & 0x1f)))
41
42
43
/**************************************************************************/
44
/*                                                                        */
45
/*  FUNCTION                                               RELEASE        */
46
/*                                                                        */
47
/*    _gx_display_driver_1555xrgb_canvas_blend            PORTABLE C      */
48
/*                                                           6.1          */
49
/*  AUTHOR                                                                */
50
/*                                                                        */
51
/*    Kenneth Maxwell, Microsoft Corporation                              */
52
/*                                                                        */
53
/*  DESCRIPTION                                                           */
54
/*                                                                        */
55
/*    Canvas blend function for 1555xrgb color foramt.                    */
56
/*                                                                        */
57
/*  INPUT                                                                 */
58
/*                                                                        */
59
/*   canvas                                 The canvas to blend to        */
60
/*   composite                              The canvas to blend from      */
61
/*                                                                        */
62
/*  OUTPUT                                                                */
63
/*                                                                        */
64
/*    None                                                                */
65
/*                                                                        */
66
/*  CALLS                                                                 */
67
/*                                                                        */
68
/*    _gx_utility_rectangle_shift           Shift rectangle by specified  */
69
/*                                            value                       */
70
/*    _gx_utility_rectangle_overlap_detect  Detect overlaps of specified  */
71
/*                                            rectangles                  */
72
/*    REDVAL                                Extrace Red from canvas       */
73
/*    GREENVAL                              Extrace Green from canvas     */
74
/*    BLUEVAL                               Extrace Blue from canvas      */
75
/*    ASSEMBLECOLOR                         Compose the RGB color         */
76
/*                                                                        */
77
/*  CALLED BY                                                             */
78
/*                                                                        */
79
/*    GUIX Internal Code                                                  */
80
/*                                                                        */
81
/**************************************************************************/
82
256
VOID _gx_display_driver_1555xrgb_canvas_blend(GX_CANVAS *canvas, GX_CANVAS *composite)
83
{
84
GX_RECTANGLE dirty;
85
GX_RECTANGLE overlap;
86
USHORT      *read;
87
USHORT      *read_start;
88
USHORT      *write;
89
USHORT      *write_start;
90
USHORT       fcolor;
91
GX_UBYTE     fred, fgreen, fblue;
92
GX_UBYTE     bred, bgreen, bblue;
93
GX_UBYTE     alpha, balpha;
94
95
USHORT       bcolor;
96
INT          row;
97
INT          col;
98
99
256
    dirty.gx_rectangle_left = dirty.gx_rectangle_top = 0;
100
256
    dirty.gx_rectangle_right = (GX_VALUE)(canvas -> gx_canvas_x_resolution - 1);
101
256
    dirty.gx_rectangle_bottom = (GX_VALUE)(canvas -> gx_canvas_y_resolution - 1);
102
103
256
    _gx_utility_rectangle_shift(&dirty, canvas -> gx_canvas_display_offset_x, canvas -> gx_canvas_display_offset_y);
104
105
256
    if (_gx_utility_rectangle_overlap_detect(&dirty, &composite -> gx_canvas_dirty_area, &overlap))
106
    {
107
255
        alpha = canvas -> gx_canvas_alpha;
108
255
        balpha = (GX_UBYTE)(256 - alpha);
109
110
255
        read_start = (USHORT *)canvas -> gx_canvas_memory;
111
112
        /* index into starting row */
113
255
        read_start += (overlap.gx_rectangle_top - dirty.gx_rectangle_top) * canvas -> gx_canvas_x_resolution;
114
115
        /* index into pixel */
116
117
255
        read_start += overlap.gx_rectangle_left - dirty.gx_rectangle_left;
118
119
        /* calculate the write pointer */
120
255
        write_start = (USHORT *)composite -> gx_canvas_memory;
121
255
        write_start += overlap.gx_rectangle_top * composite -> gx_canvas_x_resolution;
122
255
        write_start += overlap.gx_rectangle_left;
123
124
18870
        for (row = overlap.gx_rectangle_top; row <= overlap.gx_rectangle_bottom; row++)
125
        {
126
18615
            read = read_start;
127
18615
            write = write_start;
128
129
1768425
            for (col = overlap.gx_rectangle_left; col <= overlap.gx_rectangle_right; col++)
130
            {
131
                /* read the foreground color */
132
1749810
                fcolor = *read++;
133
134
                /* split foreground into red, green, and blue components */
135
1749810
                fred = REDVAL(fcolor);
136
1749810
                fgreen = GREENVAL(fcolor);
137
1749810
                fblue = BLUEVAL(fcolor);
138
139
                /* read background color */
140
1749810
                bcolor = *write;
141
142
                /* split background color into red, green, and blue components */
143
1749810
                bred = REDVAL(bcolor);
144
1749810
                bgreen = GREENVAL(bcolor);
145
1749810
                bblue = BLUEVAL(bcolor);
146
147
                /* blend foreground and background, each color channel */
148
1749810
                fred = (GX_UBYTE)(((bred * balpha) + (fred * alpha)) >> 8);
149
1749810
                fgreen = (GX_UBYTE)(((bgreen * balpha) + (fgreen * alpha)) >> 8);
150
1749810
                fblue = (GX_UBYTE)(((bblue * balpha) + (fblue * alpha)) >> 8);
151
152
                /* re-assemble into 16-bit color and write it out */
153
1749810
                *write++ = (USHORT)ASSEMBLECOLOR(fred, fgreen, fblue);
154
            }
155
18615
            write_start += composite -> gx_canvas_x_resolution;
156
18615
            read_start += canvas -> gx_canvas_x_resolution;
157
        }
158
    }
159
256
}
160