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_utility.h"
28
29 /**************************************************************************/
30 /* */
31 /* FUNCTION RELEASE */
32 /* */
33 /* _gx_utility_pixelmap_resize PORTABLE C */
34 /* 6.1.3 */
35 /* AUTHOR */
36 /* */
37 /* Kenneth Maxwell, Microsoft Corporation */
38 /* */
39 /* DESCRIPTION */
40 /* */
41 /* This service resize a pixelmap and return the resized pixelmap. */
42 /* */
43 /* INPUT */
44 /* */
45 /* src The source pixelmap */
46 /* destination The resized pixelmap to be */
47 /* returned */
48 /* width New width */
49 /* height New height */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* status Completion status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _gx_utility_32argb_pixelmap_resize Resize 32bpp pixelmap */
58 /* _gx_utility_16bpp_pixelmap_resize Resize 565rgb pixelmap */
59 /* _gx_utility_1555xrgb_pixelmap_resize Resize 1555xrgb pixelmap */
60 /* _gx_utility_4444argb_pixelmap_resize Resize 4444argb pixelmap */
61 /* _gx_utility_8bpp_pixelmap_resize Resize 8bpp pixelmap */
62 /* _gx_utility_8bit_alphamap_resize Resize 8bit alphamap */
63 /* _gx_utility_4bpp_pixelmap_resize Resize 4bpp pixelmap */
64 /* _gx_utility_1bpp_pixelmap_resize Resize 1bpp pixelmap */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* Application Code */
69 /* GUIX Internal Code */
70 /* */
71 /* RELEASE HISTORY */
72 /* */
73 /* DATE NAME DESCRIPTION */
74 /* */
75 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
76 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
77 /* added 565bgr format support,*/
78 /* resulting in version 6.1 */
79 /* 12-31-2020 Kenneth Maxwell Modified comment(s), added */
80 /* display rotation support, */
81 /* resulting in version 6.1.3 */
82 /* */
83 /**************************************************************************/
_gx_utility_pixelmap_resize(GX_PIXELMAP * src,GX_PIXELMAP * destination,INT width,INT height)84 UINT _gx_utility_pixelmap_resize(GX_PIXELMAP *src, GX_PIXELMAP *destination, INT width, INT height)
85 {
86 UINT status = GX_SUCCESS;
87 GX_PIXELMAP rotated_src;
88
89 memset(destination, 0, sizeof(GX_PIXELMAP));
90
91 /* Limited pixelmap width to 14 bits. */
92 if (src -> gx_pixelmap_width > GX_MAX_PIXELMAP_RESOLUTION)
93 {
94 return GX_INVALID_WIDTH;
95 }
96
97 /* Limited pixelmap height to 14 bits. */
98 if (src -> gx_pixelmap_height > GX_MAX_PIXELMAP_RESOLUTION)
99 {
100 return GX_INVALID_HEIGHT;
101 }
102
103 if ((src -> gx_pixelmap_flags & GX_PIXELMAP_ROTATED_90) ||
104 (src -> gx_pixelmap_flags & GX_PIXELMAP_ROTATED_270))
105 {
106 rotated_src = (*src);
107 GX_SWAP_VALS(rotated_src.gx_pixelmap_width, rotated_src.gx_pixelmap_height);
108 GX_SWAP_VALS(width, height);
109
110 src = &rotated_src;
111 }
112
113 switch (src -> gx_pixelmap_format)
114 {
115 case GX_COLOR_FORMAT_32ARGB:
116 case GX_COLOR_FORMAT_24XRGB:
117
118 /* Call 32argb pixelmap resize. */
119 status = _gx_utility_32argb_pixelmap_resize(src, destination, width, height);
120 break;
121 case GX_COLOR_FORMAT_565RGB:
122 case GX_COLOR_FORMAT_565BGR:
123 /* Call 16bpp pixelmap resize. */
124 status = _gx_utility_16bpp_pixelmap_resize(src, destination, width, height);
125 break;
126
127 case GX_COLOR_FORMAT_1555XRGB:
128 status = _gx_utility_1555xrgb_pixelmap_resize(src, destination, width, height);
129 break;
130
131 case GX_COLOR_FORMAT_4444ARGB:
132 status = _gx_utility_4444argb_pixelmap_resize(src, destination, width, height);
133 break;
134
135 case GX_COLOR_FORMAT_8BIT_PACKED_PIXEL:
136 case GX_COLOR_FORMAT_8BIT_PALETTE:
137 /* Call 8bpp pixelmap resize. */
138 status = _gx_utility_8bpp_pixelmap_resize(src, destination, width, height);
139 break;
140
141 case GX_COLOR_FORMAT_8BIT_ALPHAMAP:
142 status = _gx_utility_8bit_alphamap_resize(src, destination, width, height);
143 break;
144
145 case GX_COLOR_FORMAT_4BIT_GRAY:
146 status = _gx_utility_4bpp_pixelmap_resize(src, destination, width, height);
147 break;
148
149 case GX_COLOR_FORMAT_MONOCHROME:
150 status = _gx_utility_1bpp_pixelmap_resize(src, destination, width, height);
151 break;
152
153 default:
154 status = GX_NOT_SUPPORTED;
155 break;
156 }
157
158 if ((src -> gx_pixelmap_flags & GX_PIXELMAP_ROTATED_90) ||
159 (src -> gx_pixelmap_flags & GX_PIXELMAP_ROTATED_270))
160 {
161 GX_SWAP_VALS(destination -> gx_pixelmap_width, destination -> gx_pixelmap_height);
162 }
163
164 return status;
165 }
166
167