GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_canvas_pixelmap_draw.c Lines: 28 28 100.0 %
Date: 2026-03-06 19:21:09 Branches: 18 18 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_draw                            PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function prepares to draw the specified pixelmap at the        */
46
/*    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
/*                                                                        */
57
/*  OUTPUT                                                                */
58
/*                                                                        */
59
/*    status                                Completion status             */
60
/*                                                                        */
61
/*  CALLS                                                                 */
62
/*    _gx_utility_rectangle_define          Define a rectangle            */
63
/*    _gx_utility_rectangle_overlap_detect  Detect rectangle overlap      */
64
/*    [gx_display_driver_pixelmap_draw]     The display driver pixelmap   */
65
/*                                            draw routine                */
66
/*    [gx_display_driver_jpeg_draw]         The display driver JPEG draw  */
67
/*                                            routine                     */
68
/*    [gx_display_driver_png_draw]          The display driver PNG draw   */
69
/*                                            routine                     */
70
/*                                                                        */
71
/*  CALLED BY                                                             */
72
/*                                                                        */
73
/*    _gx_canvas_pixelmap_blend                                           */
74
/*    _gx_canvas_pixelmap_tile                                            */
75
/*    _gx_checkbox_draw                                                   */
76
/*    _gx_icon_button_draw                                                */
77
/*    _gx_icon_draw                                                       */
78
/*    _gx_pixelmap_button_draw                                            */
79
/*    _gx_pixelmap_prompt_draw                                            */
80
/*    _gx_pixelmap_slider_draw                                            */
81
/*    _gx_radio_button_draw                                               */
82
/*    _gx_scroll_thumb_draw                                               */
83
/*    _gx_scrollbar_draw                                                  */
84
/*    _gx_window_draw                                                     */
85
/*    _gx_scroll_thumb_draw                                               */
86
/*                                                                        */
87
/**************************************************************************/
88
1488028
UINT  _gx_canvas_pixelmap_draw(GX_VALUE x_position, GX_VALUE y_position, GX_PIXELMAP *pixelmap)
89
{
90
GX_DRAW_CONTEXT *context;
91
GX_DISPLAY      *display;
92
GX_RECTANGLE     clip_rect;
93
GX_RECTANGLE     bound;
94
GX_VIEW         *view;
95
VOID             (*pmp_function)(GX_DRAW_CONTEXT *, INT, INT, GX_PIXELMAP *);
96
97
    /* pick up the current drawing context */
98
1488028
    context = _gx_system_current_draw_context;
99
100
    /* pick up current display driver */
101
1488028
    display = context -> gx_draw_context_display;
102
103
    /* calculate rectangle that bounds the pixelmap */
104
1488028
    _gx_utility_rectangle_define(&bound, x_position, y_position,
105
1488028
                                 (GX_VALUE)(x_position + pixelmap -> gx_pixelmap_width - 1),
106
1488028
                                 (GX_VALUE)(y_position + pixelmap -> gx_pixelmap_height - 1));
107
108
    /* clip the line bounding box to the dirty rectangle */
109
1488028
    if (!_gx_utility_rectangle_overlap_detect(&bound, &context -> gx_draw_context_dirty, &bound))
110
    {
111
        /* nothing to draw, return */
112
21654
        return GX_SUCCESS;
113
    }
114
115
    /* pickup pointer to correct pixelmap drawing function */
116
1466374
    pmp_function = GX_NULL;
117
118
1466374
    if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_RAW_FORMAT)
119
    {
120
#if defined(GX_SOFTWARE_DECODER_SUPPORT)
121

1033
        if ((pixelmap->gx_pixelmap_data[0] == 0xff) && (pixelmap->gx_pixelmap_data[1] == 0xd8))
122
        {
123
            /* JPEG */
124
412
            pmp_function = display -> gx_display_driver_jpeg_draw;
125
        }
126
        else
127
        {
128
621
            if (pixelmap -> gx_pixelmap_data[1] == 'P')
129
            {
130
                /* PNG */
131
618
                pmp_function = display -> gx_display_driver_png_draw;
132
            }
133
        }
134
#endif
135
    }
136
    else
137
    {
138
1465341
        if (pixelmap -> gx_pixelmap_format == GX_COLOR_FORMAT_8BIT_ALPHAMAP)
139
        {
140
60064
            pmp_function = display -> gx_display_driver_alphamap_draw;
141
        }
142
        else
143
        {
144
1405277
            pmp_function = display -> gx_display_driver_pixelmap_draw;
145
        }
146
    }
147
148
1466374
    if (!pmp_function)
149
    {
150
        /* display driver does not support requested action */
151
1681
        return GX_FAILURE;
152
    }
153
154
    /* test to determine if the bounding rectangle overlaps the region we are allowed to draw
155
       into. For each view that overlaps the bounding rectangle, do some drawing.
156
     */
157
1464693
    view = context -> gx_draw_context_view_head;
158
159
2954308
    while (view)
160
    {
161
1489615
        if (!_gx_utility_rectangle_overlap_detect(&view -> gx_view_rectangle, &bound, &clip_rect))
162
        {
163
31212
            view = view -> gx_view_next;
164
31212
            continue;
165
        }
166
167
        /* we have a view into which we can draw the pixelmap, do it */
168
169
        /* first, set the context clip rectangle */
170
1458403
        context -> gx_draw_context_clip = &clip_rect;
171
172
        /* now pass the context and drawing params to driver level function */
173
1458403
        pmp_function(context, x_position, y_position, pixelmap);
174
175
        /* go to the next view */
176
1458403
        view = view -> gx_view_next;
177
    }
178
179
    /* Return successful completion.  */
180
1464693
    return(GX_SUCCESS);
181
}
182