1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** GUIX Component */
16 /** */
17 /** Utility (Utility) */
18 /** */
19 /**************************************************************************/
20
21 #define GX_SOURCE_CODE
22
23
24 /* Include necessary system files. */
25
26 #include "gx_api.h"
27 #include "gx_context.h"
28 #include "gx_system.h"
29 #include "gx_utility.h"
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _gx_utility_pixelmap_simple_rotation PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* Kenneth Maxwell, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This service rotate a pixelmap by 90, 180 or 270 degree. */
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_simple_rotate */
63 /* Rotate 32bpp pixelmap with */
64 /* simple case */
65 /* _gx_utility_565rgb_pixelmap_simple_rotate */
66 /* Rotate 565rgb pixelmap with */
67 /* simple case */
68 /* _gx_utility_4444argb_pixelmap_simple_rotate */
69 /* Rotate 4444argb pixelmap with */
70 /* simple case */
71 /* _gx_utility_8bpp_pixelmap_simple_rotate */
72 /* Rotate 8bit palette pixelmap */
73 /* with simple case */
74 /* _gx_utility_332rgb_pixelmap_simple_rotate */
75 /* Rotate 332rgb pixelmap with */
76 /* simple case */
77 /* _gx_utility_4bpp_pixelmap_simple_rotate */
78 /* Rotate 4bpp pixelmap with */
79 /* simple case */
80 /* _gx_utility_1bpp_pixelmap_simple_rotate */
81 /* Rotate 1bpp pixelmap with */
82 /* simple case */
83 /* */
84 /* CALLED BY */
85 /* */
86 /* Application Code */
87 /* GUIX Internal Code */
88 /* */
89 /* RELEASE HISTORY */
90 /* */
91 /* DATE NAME DESCRIPTION */
92 /* */
93 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
94 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
95 /* added 565bgr format support,*/
96 /* resulting in version 6.1 */
97 /* */
98 /**************************************************************************/
_gx_utility_pixelmap_simple_rotate(GX_PIXELMAP * src,INT angle,GX_PIXELMAP * destination,INT * rot_cx,INT * rot_cy)99 UINT _gx_utility_pixelmap_simple_rotate(GX_PIXELMAP *src, INT angle, GX_PIXELMAP *destination, INT *rot_cx, INT *rot_cy)
100 {
101 angle = angle % 360;
102
103 if ((angle == 0) || (angle % 90))
104 {
105 return GX_INVALID_VALUE;
106 }
107 else if (angle < 0)
108 {
109 angle += 360;
110 }
111
112 if ((_gx_system_memory_allocator == GX_NULL) || (_gx_system_memory_free == GX_NULL))
113 {
114 return GX_SYSTEM_MEMORY_ERROR;
115 }
116
117 if (src -> gx_pixelmap_flags & GX_PIXELMAP_COMPRESSED)
118 {
119 return GX_INVALID_FORMAT;
120 }
121
122 memset(destination, 0, sizeof(GX_PIXELMAP));
123 destination -> gx_pixelmap_format = src -> gx_pixelmap_format;
124 destination -> gx_pixelmap_version_major = src -> gx_pixelmap_version_major;
125 destination -> gx_pixelmap_version_minor = src -> gx_pixelmap_version_major;
126 destination -> gx_pixelmap_flags = src -> gx_pixelmap_flags;
127
128 switch (src -> gx_pixelmap_format)
129 {
130 case GX_COLOR_FORMAT_32ARGB:
131 case GX_COLOR_FORMAT_24XRGB:
132 /* Call 32argb pixelmap rotate. */
133 _gx_utility_32argb_pixelmap_simple_rotate(src, angle, destination, rot_cx, rot_cy);
134 break;
135
136 case GX_COLOR_FORMAT_565RGB:
137 case GX_COLOR_FORMAT_565BGR:
138 case GX_COLOR_FORMAT_1555XRGB:
139 /* Call 565rgb pixelmap rotate. */
140 _gx_utility_565rgb_pixelmap_simple_rotate(src, angle, destination, rot_cx, rot_cy);
141 break;
142
143 case GX_COLOR_FORMAT_4444ARGB:
144 _gx_utility_4444argb_pixelmap_simple_rotate(src, angle, destination, rot_cx, rot_cy);
145 break;
146
147 case GX_COLOR_FORMAT_8BIT_PACKED_PIXEL:
148 /* Call 332rgb pixelmap rotate. */
149 _gx_utility_332rgb_pixelmap_simple_rotate(src, angle, destination, rot_cx, rot_cy);
150 break;
151
152 case GX_COLOR_FORMAT_8BIT_PALETTE:
153 case GX_COLOR_FORMAT_8BIT_ALPHAMAP:
154 /* Call 8bpp pixelmap rotate. */
155 _gx_utility_8bpp_pixelmap_simple_rotate(src, angle, destination, rot_cx, rot_cy);
156 break;
157
158 case GX_COLOR_FORMAT_4BIT_GRAY:
159 _gx_utility_4bpp_pixelmap_simple_rotate(src, angle, destination, rot_cx, rot_cy);
160 break;
161
162 case GX_COLOR_FORMAT_MONOCHROME:
163 _gx_utility_1bpp_pixelmap_simple_rotate(src, angle, destination, rot_cx, rot_cy);
164 break;
165
166 default:
167 return GX_INVALID_FORMAT;
168 }
169 if (destination -> gx_pixelmap_data)
170 {
171 return GX_SUCCESS;
172 }
173 return GX_FAILURE;
174 }
175
176