GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_utility_pixelmap_rotate.c Lines: 71 71 100.0 %
Date: 2026-03-06 19:21:09 Branches: 46 46 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
/**   Utility (Utility)                                                   */
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
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_utility_pixelmap_rotation                       PORTABLE C      */
36
/*                                                           6.1.3        */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This service rotate a pixelmap.                                     */
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    src                                   The pixelmap to rotate        */
48
/*    angle                                 The angle to rotate           */
49
/*    destination                           Destination buffer for        */
50
/*                                            rotated pixelmap.           */
51
/*    rot_cx                                X coordinate of rotation      */
52
/*                                            center                      */
53
/*    rot_cy                                Y coordinate of rotation      */
54
/*                                            center                      */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    status                                Completion status             */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    _gx_utility_32argb_pixelmap_rotate    Rotate 32bpp pixelmap         */
63
/*    _gx_utility_565rgb_pixelmap_rotate    Rotate 565rgb pixelmap        */
64
/*    _gx_utility_4444argb_pixelmap_rotate  Rotate 4444argb pixelmap      */
65
/*    _gx_utility_8bpp_pixelmap_rotate      Rotate 8bit palette pixelmap  */
66
/*    _gx_utility_332rgb_pixelmap_rotate    Rotate 332rgb pixelmap        */
67
/*    _gx_utility_8bit_alphamap_rotate      Rotate 8bit alphamap          */
68
/*    _gx_utility_4bpp_pixelmap_rotate      Rotate 4bpp pixelmap          */
69
/*    _gx_utility_1bpp_pixelmap_rotate      Rotate 1bpp pixelmap          */
70
/*                                                                        */
71
/*  CALLED BY                                                             */
72
/*                                                                        */
73
/*    Application Code                                                    */
74
/*    GUIX Internal Code                                                  */
75
/*                                                                        */
76
/**************************************************************************/
77
14732
UINT _gx_utility_pixelmap_rotate(GX_PIXELMAP *src, INT angle, GX_PIXELMAP *destination, INT *rot_cx, INT *rot_cy)
78
{
79
14732
UINT        status = GX_SUCCESS;
80
GX_PIXELMAP rotated_src;
81
82
    /* Limit pixelmap width to 14bits. */
83
14732
    if (src -> gx_pixelmap_width > GX_MAX_PIXELMAP_RESOLUTION)
84
    {
85
1
        return GX_INVALID_WIDTH;
86
    }
87
88
    /* Limit pixelmap height to 14bits. */
89
14731
    if (src -> gx_pixelmap_height > GX_MAX_PIXELMAP_RESOLUTION)
90
    {
91
1
        return GX_INVALID_HEIGHT;
92
    }
93
94
14730
    if ((src -> gx_pixelmap_flags & GX_PIXELMAP_ROTATED_90) ||
95
11766
        (src -> gx_pixelmap_flags & GX_PIXELMAP_ROTATED_270))
96
    {
97
5200
        rotated_src = (*src);
98
5200
        GX_SWAP_VALS(rotated_src.gx_pixelmap_width, rotated_src.gx_pixelmap_height);
99
5200
        src = &rotated_src;
100
101

5200
        if (rot_cx && rot_cy)
102
        {
103
5192
            GX_SWAP_VALS(*rot_cx, *rot_cy);
104
105
5192
            if (src -> gx_pixelmap_flags & GX_PIXELMAP_ROTATED_90)
106
            {
107
2956
                *rot_cy = src -> gx_pixelmap_height - 1 - (*rot_cy);
108
            }
109
            else
110
            {
111
2236
                *rot_cx = src -> gx_pixelmap_width - 1 - (*rot_cx);
112
            }
113
        }
114
    }
115
116
14730
    angle = angle % 360;
117
118
14730
    if (angle == 0)
119
    {
120
16
        return GX_INVALID_VALUE;
121
    }
122
14714
    else if (angle < 0)
123
    {
124
1750
        angle += 360;
125
    }
126
127

14714
    if ((_gx_system_memory_allocator == GX_NULL) || (_gx_system_memory_free == GX_NULL))
128
    {
129
3
        return GX_SYSTEM_MEMORY_ERROR;
130
    }
131
132
14711
    if (src -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
133
    {
134
2
        return GX_INVALID_FORMAT;
135
    }
136
137
14709
    if ((angle % 90) == 0)
138
    {
139
413
        _gx_utility_pixelmap_simple_rotate(src, angle, destination, rot_cx, rot_cy);
140
    }
141
    else
142
    {
143
14296
        memset(destination, 0, sizeof(GX_PIXELMAP));
144
14296
        destination -> gx_pixelmap_format = src -> gx_pixelmap_format;
145
14296
        destination -> gx_pixelmap_version_major = src -> gx_pixelmap_version_major;
146
14296
        destination -> gx_pixelmap_version_minor = src -> gx_pixelmap_version_major;
147
14296
        destination -> gx_pixelmap_flags = src -> gx_pixelmap_flags;
148
149


14296
        switch (src -> gx_pixelmap_format)
150
        {
151
4457
        case GX_COLOR_FORMAT_32ARGB:
152
        case GX_COLOR_FORMAT_24XRGB:
153
            /* Call 32argb pixelmap rotate. */
154
4457
            status = _gx_utility_32argb_pixelmap_rotate(src, angle, destination, rot_cx, rot_cy);
155
4457
            break;
156
157
2350
        case GX_COLOR_FORMAT_565RGB:
158
        case GX_COLOR_FORMAT_565BGR:
159
            /* Call 565rgb pixelmap rotate.  */
160
2350
            status = _gx_utility_565rgb_pixelmap_rotate(src, angle, destination, rot_cx, rot_cy);
161
2350
            break;
162
163
988
        case GX_COLOR_FORMAT_1555XRGB:
164
988
            status = _gx_utility_1555xrgb_pixelmap_rotate(src, angle, destination, rot_cx, rot_cy);
165
988
            break;
166
167
730
        case GX_COLOR_FORMAT_4444ARGB:
168
730
            status = _gx_utility_4444argb_pixelmap_rotate(src, angle, destination, rot_cx, rot_cy);
169
730
            break;
170
171
730
        case GX_COLOR_FORMAT_8BIT_PACKED_PIXEL:
172
730
            status = _gx_utility_332rgb_pixelmap_rotate(src, angle, destination, rot_cx, rot_cy);
173
730
            break;
174
175
2144
        case GX_COLOR_FORMAT_8BIT_PALETTE:
176
            /* Call 8bpp pixelmap rotate.  */
177
2144
            status = _gx_utility_8bpp_pixelmap_rotate(src, angle, destination, rot_cx, rot_cy);
178
2144
            break;
179
180
1445
        case GX_COLOR_FORMAT_8BIT_ALPHAMAP:
181
            /* Call 8bit alphamap rotate.  */
182
1445
            status = _gx_utility_8bit_alphamap_rotate(src, angle, destination, rot_cx, rot_cy);
183
1445
            break;
184
185
730
        case GX_COLOR_FORMAT_4BIT_GRAY:
186
730
            status = _gx_utility_4bpp_pixelmap_rotate(src, angle, destination, rot_cx, rot_cy);
187
730
            break;
188
189
720
        case GX_COLOR_FORMAT_MONOCHROME:
190
720
            status = _gx_utility_1bpp_pixelmap_rotate(src, angle, destination, rot_cx, rot_cy);
191
720
            break;
192
193
2
        default:
194
2
            return GX_INVALID_FORMAT;
195
        }
196
    }
197
198
14707
    if ((src -> gx_pixelmap_flags & GX_PIXELMAP_ROTATED_90) ||
199
11743
        (src -> gx_pixelmap_flags & GX_PIXELMAP_ROTATED_270))
200
    {
201
5200
        GX_SWAP_VALS(destination -> gx_pixelmap_width, destination -> gx_pixelmap_height);
202
203

5200
        if (rot_cx && rot_cy)
204
        {
205
5192
            GX_SWAP_VALS(*rot_cx, *rot_cy);
206
207
5192
            if (src -> gx_pixelmap_flags & GX_PIXELMAP_ROTATED_90)
208
            {
209
2956
                *rot_cx = destination -> gx_pixelmap_width - 1 - (*rot_cx);
210
            }
211
            else
212
            {
213
2236
                *rot_cy = destination -> gx_pixelmap_height - 1 - (*rot_cy);
214
            }
215
        }
216
    }
217
218
14707
    return status;
219
}
220