GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_canvas_pixelmap_blend.c Lines: 27 27 100.0 %
Date: 2026-03-06 19:21:09 Branches: 12 12 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
/**   Screen Management (Screen)                                          */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_system.h"
29
#include "gx_utility.h"
30
#include "gx_display.h"
31
#include "gx_canvas.h"
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_canvas_pixelmap_blend                           PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function prepares to blend the specified pixelmap with         */
46
/*      background at the requested position.                             */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    x_position                            Top-left x-coord to place     */
51
/*                                            pixelmap                    */
52
/*    y_position                            Top-left y-coord to place     */
53
/*                                            pixelmap                    */
54
/*    pixelmap                              Pointer to actual pixelmap    */
55
/*                                            to draw                     */
56
/*    alpha                                 blending value 0-255          */
57
/*                                                                        */
58
/*  OUTPUT                                                                */
59
/*                                                                        */
60
/*    status                                Completion status             */
61
/*                                                                        */
62
/*  CALLS                                                                 */
63
/*                                                                        */
64
/*    _gx_utility_rectangle_define          Define a rectangle            */
65
/*    _gx_utility_rectangle_overlap_detect  Detect rectangle overlap      */
66
/*    [gx_display_driver_pixelmap_draw]     Driver level pixelmap blend   */
67
/*                                            function                    */
68
/*                                                                        */
69
/*  CALLED BY                                                             */
70
/*                                                                        */
71
/*    Application Code                                                    */
72
/*    _gx_sprite_draw                                                     */
73
/*                                                                        */
74
/**************************************************************************/
75
1123
UINT  _gx_canvas_pixelmap_blend(GX_VALUE x_position, GX_VALUE y_position,
76
                                GX_PIXELMAP *pixelmap, GX_UBYTE alpha)
77
{
78
GX_DRAW_CONTEXT *context;
79
GX_DISPLAY      *display;
80
GX_RECTANGLE     clip_rect;
81
GX_RECTANGLE     bound;
82
GX_VIEW         *view;
83
GX_UBYTE         old_alpha;
84
VOID             (*pmp_function)(GX_DRAW_CONTEXT *, INT, INT, GX_PIXELMAP *);
85
86
1123
    if (alpha == 0)
87
    {
88
2
        return GX_SUCCESS;
89
    }
90
91
    /* pick up the current drawing context */
92
1121
    context = _gx_system_current_draw_context;
93
94
    /* calculate rectangle that bounds the pixelmap */
95
1121
    _gx_utility_rectangle_define(&bound, x_position, y_position,
96
1121
                                 (GX_VALUE)(x_position + pixelmap -> gx_pixelmap_width - 1),
97
1121
                                 (GX_VALUE)(y_position + pixelmap -> gx_pixelmap_height - 1));
98
99
    /* clip the line bounding box to the dirty rectangle */
100
1121
    if (!_gx_utility_rectangle_overlap_detect(&bound, &context -> gx_draw_context_dirty, &bound))
101
    {
102
        /* nothing to draw, return */
103
4
        return GX_SUCCESS;
104
    }
105
106
    /* pick up current display driver */
107
1117
    display = context -> gx_draw_context_display;
108
109
    /* pickup pointer to correct pixelmap blending function */
110
1117
    if (pixelmap -> gx_pixelmap_format == GX_COLOR_FORMAT_8BIT_ALPHAMAP)
111
    {
112
2
        pmp_function = display -> gx_display_driver_alphamap_draw;
113
    }
114
    else
115
    {
116
1115
        pmp_function = display -> gx_display_driver_pixelmap_draw;
117
    }
118
119
1117
    if (pmp_function == GX_NULL)
120
    {
121
1
        return GX_NOT_SUPPORTED;
122
    }
123
124
    /* Set the parameter alpha to brush alpha value. */
125
1116
    old_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
126
1116
    context -> gx_draw_context_brush.gx_brush_alpha = alpha;
127
128
    /* test to determine if the bounding rectangle overlaps the region we are allowed to draw
129
       into. For each view that overlaps the bounding rectangle, do some drawing.
130
     */
131
1116
    view = context -> gx_draw_context_view_head;
132
133
2232
    while (view)
134
    {
135
1116
        if (!_gx_utility_rectangle_overlap_detect(&view -> gx_view_rectangle, &bound, &clip_rect))
136
        {
137
3
            view = view -> gx_view_next;
138
3
            continue;
139
        }
140
141
        /* we have a view into which we can draw the pixelmap, do it */
142
        /* first, set the context clip rectangle */
143
1113
        context -> gx_draw_context_clip = &clip_rect;
144
145
        /* now pass the context and drawing params to driver level function */
146
1113
        pmp_function(context, x_position, y_position, pixelmap);
147
148
        /* go to the next view */
149
1113
        view = view -> gx_view_next;
150
    }
151
152
1116
    context -> gx_draw_context_brush.gx_brush_alpha = old_alpha;
153
154
    /* Return successful completion.  */
155
1116
    return(GX_SUCCESS);
156
}
157