GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_24xrgb_rotated_canvas_blend.c Lines: 38 38 100.0 %
Date: 2026-03-06 19:21:09 Branches: 8 8 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
/**************************************************************************/
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
/**************************************************************************/
68
765
VOID _gx_display_driver_24xrgb_rotated_canvas_blend(GX_CANVAS *canvas, GX_CANVAS *composite)
69
{
70
GX_RECTANGLE dirty;
71
GX_RECTANGLE overlap;
72
ULONG       *read;
73
ULONG       *read_start;
74
ULONG       *write;
75
ULONG       *write_start;
76
ULONG        fcolor;
77
GX_UBYTE     fred, fgreen, fblue;
78
GX_UBYTE     bred, bgreen, bblue;
79
GX_UBYTE     alpha, balpha;
80
81
ULONG        bcolor;
82
INT          row;
83
INT          col;
84
85
765
    dirty.gx_rectangle_left = dirty.gx_rectangle_top = 0;
86
765
    dirty.gx_rectangle_right = (GX_VALUE)(canvas -> gx_canvas_x_resolution - 1);
87
765
    dirty.gx_rectangle_bottom = (GX_VALUE)(canvas -> gx_canvas_y_resolution - 1);
88
89
765
    _gx_utility_rectangle_shift(&dirty, canvas -> gx_canvas_display_offset_x, canvas -> gx_canvas_display_offset_y);
90
91
765
    if (_gx_utility_rectangle_overlap_detect(&dirty, &composite -> gx_canvas_dirty_area, &overlap))
92
    {
93
762
        alpha = canvas -> gx_canvas_alpha;
94
762
        balpha = (GX_UBYTE)(256 - alpha);
95
96
762
        read_start = (ULONG *)canvas -> gx_canvas_memory;
97
762
        write_start = (ULONG *)composite -> gx_canvas_memory;
98
99
762
        if (canvas -> gx_canvas_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
100
        {
101
            /* Index into starting row.  */
102
508
            read_start += (dirty.gx_rectangle_right - overlap.gx_rectangle_right) * canvas -> gx_canvas_y_resolution;
103
104
            /* Index into pixel.  */
105
508
            read_start += overlap.gx_rectangle_top - dirty.gx_rectangle_top;
106
107
            /* Calculate the write pointer.  */
108
508
            write_start += (composite -> gx_canvas_x_resolution - overlap.gx_rectangle_right - 1) * composite -> gx_canvas_y_resolution;
109
508
            write_start += overlap.gx_rectangle_top;
110
        }
111
        else
112
        {
113
            /* Index into starting row.  */
114
254
            read_start += (overlap.gx_rectangle_left - dirty.gx_rectangle_left) * canvas -> gx_canvas_y_resolution;
115
116
            /* Index into pixel.  */
117
254
            read_start += dirty.gx_rectangle_bottom - overlap.gx_rectangle_bottom;
118
119
            /* Calculate the write pointer.  */
120
254
            write_start += overlap.gx_rectangle_left * composite -> gx_canvas_y_resolution;
121
254
            write_start += (composite -> gx_canvas_y_resolution - overlap.gx_rectangle_bottom - 1);
122
        }
123
124
72390
        for (row = overlap.gx_rectangle_left; row <= overlap.gx_rectangle_right; row++)
125
        {
126
71628
            read = read_start;
127
71628
            write = write_start;
128
129
5300472
            for (col = overlap.gx_rectangle_top; col <= overlap.gx_rectangle_bottom; col++)
130
            {
131
                /* Read the foreground color.  */
132
5228844
                fcolor = *read++;
133
134
                /* Split foreground into red, green, and blue components.  */
135
5228844
                fred = REDVAL_24BPP(fcolor);
136
5228844
                fgreen = GREENVAL_24BPP(fcolor);
137
5228844
                fblue = BLUEVAL_24BPP(fcolor);
138
139
                /* Read background color.  */
140
5228844
                bcolor = *write;
141
142
                /* Split background color into red, green, and blue components.  */
143
5228844
                bred = REDVAL_24BPP(bcolor);
144
5228844
                bgreen = GREENVAL_24BPP(bcolor);
145
5228844
                bblue = BLUEVAL_24BPP(bcolor);
146
147
                /* Blend foreground and background, each color channel.  */
148
5228844
                fred = (GX_UBYTE)(((bred * balpha) + (fred * alpha)) >> 8);
149
5228844
                fgreen = (GX_UBYTE)(((bgreen * balpha) + (fgreen * alpha)) >> 8);
150
5228844
                fblue = (GX_UBYTE)(((bblue * balpha) + (fblue * alpha)) >> 8);
151
152
                /* Re-assemble into 16-bit color and write it out.  */
153
5228844
                *write++ = ASSEMBLECOLOR_32ARGB((ULONG)0xff, (ULONG)fred, (ULONG)fgreen, (ULONG)fblue);
154
            }
155
156
71628
            write_start += composite -> gx_canvas_y_resolution;
157
71628
            read_start += canvas -> gx_canvas_y_resolution;
158
        }
159
    }
160
765
}
161