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 |
|
|
#define GX_SOURCE_CODE |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#include "gx_api.h" |
27 |
|
|
#include "gx_utility.h" |
28 |
|
|
#include "gx_system.h" |
29 |
|
|
|
30 |
|
|
/**************************************************************************/ |
31 |
|
|
/* */ |
32 |
|
|
/* FUNCTION RELEASE */ |
33 |
|
|
/* */ |
34 |
|
|
/* _gx_utility_4bpp_pixelmap_raw_resize PORTABLE C */ |
35 |
|
|
/* 6.1.7 */ |
36 |
|
|
/* AUTHOR */ |
37 |
|
|
/* */ |
38 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
39 |
|
|
/* */ |
40 |
|
|
/* DESCRIPTION */ |
41 |
|
|
/* */ |
42 |
|
|
/* 4bpp pixelmap resize function that handles uncompress, with or */ |
43 |
|
|
/* transparent channel. */ |
44 |
|
|
/* */ |
45 |
|
|
/* INPUT */ |
46 |
|
|
/* */ |
47 |
|
|
/* src The source pixelmap */ |
48 |
|
|
/* destination The resized pixelmap to be */ |
49 |
|
|
/* returned */ |
50 |
|
|
/* width New width */ |
51 |
|
|
/* height New height */ |
52 |
|
|
/* */ |
53 |
|
|
/* OUTPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* status Completion status */ |
56 |
|
|
/* */ |
57 |
|
|
/* CALLS */ |
58 |
|
|
/* */ |
59 |
|
|
/* _gx_system_memory_allocator Memory Allocation routine */ |
60 |
|
|
/* */ |
61 |
|
|
/* CALLED BY */ |
62 |
|
|
/* */ |
63 |
|
|
/* _gx_utility_4bpp_pixelmap_resize */ |
64 |
|
|
/* */ |
65 |
|
|
/**************************************************************************/ |
66 |
|
103 |
static UINT _gx_utility_4bpp_pixelmap_raw_resize(GX_PIXELMAP *src, GX_PIXELMAP *destination, INT width, INT height) |
67 |
|
|
{ |
68 |
|
|
/* The pixelmap resize function is implemented from nearest neighbor |
69 |
|
|
image scaling algorithm. */ |
70 |
|
|
|
71 |
|
|
GX_UBYTE *get; |
72 |
|
|
GX_UBYTE *put; |
73 |
|
|
GX_UBYTE *putrow; |
74 |
|
|
GX_UBYTE putmask; |
75 |
|
|
INT putstride; |
76 |
|
|
INT getstride; |
77 |
|
|
GX_UBYTE pixel; |
78 |
|
|
INT xradio; |
79 |
|
|
INT yradio; |
80 |
|
|
INT x; |
81 |
|
|
INT y; |
82 |
|
|
INT xx; |
83 |
|
|
INT yy; |
84 |
|
|
|
85 |
|
|
/* Calculate scale ratio and enlarge it by 256 times to keep precision. */ |
86 |
|
103 |
xradio = ((src -> gx_pixelmap_width) << 8) / width; |
87 |
|
103 |
yradio = ((src -> gx_pixelmap_height) << 8) / height; |
88 |
|
|
|
89 |
|
103 |
putstride = (width + 1) >> 1; |
90 |
|
103 |
getstride = (src -> gx_pixelmap_width + 1) >> 1; |
91 |
|
|
|
92 |
|
|
/* Fill property values into destination pixelmap structure. */ |
93 |
|
103 |
destination -> gx_pixelmap_flags = src -> gx_pixelmap_flags; |
94 |
|
103 |
destination -> gx_pixelmap_format = src -> gx_pixelmap_format; |
95 |
|
103 |
destination -> gx_pixelmap_transparent_color = src -> gx_pixelmap_transparent_color; |
96 |
|
103 |
destination -> gx_pixelmap_version_major = src -> gx_pixelmap_version_major; |
97 |
|
103 |
destination -> gx_pixelmap_version_minor = src -> gx_pixelmap_version_minor; |
98 |
|
|
|
99 |
|
103 |
destination -> gx_pixelmap_height = (GX_VALUE)height; |
100 |
|
103 |
destination -> gx_pixelmap_width = (GX_VALUE)width; |
101 |
|
|
|
102 |
|
|
/* Safe int math is not required here, calling function limits max width, height to 14 bits so |
103 |
|
|
overflow cannot occur. */ |
104 |
|
103 |
destination -> gx_pixelmap_data_size = (UINT)(height * putstride) * sizeof(GX_UBYTE); |
105 |
|
|
|
106 |
|
|
/* Allocate memory to load pixelmap data. */ |
107 |
|
103 |
destination -> gx_pixelmap_data = (GX_UBYTE *)_gx_system_memory_allocator(destination -> gx_pixelmap_data_size); |
108 |
|
|
|
109 |
✓✓ |
103 |
if (destination -> gx_pixelmap_data == GX_NULL) |
110 |
|
|
{ |
111 |
|
2 |
return GX_SYSTEM_MEMORY_ERROR; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
101 |
putrow = (GX_UBYTE *)destination -> gx_pixelmap_data; |
115 |
|
|
|
116 |
|
|
/* Loop through destination's pixel and fill each pixel with the nearest neighbor. */ |
117 |
✓✓ |
12220 |
for (y = 0; y < height; y++) |
118 |
|
|
{ |
119 |
|
12119 |
put = putrow; |
120 |
|
12119 |
putmask = 0xf0; |
121 |
✓✓ |
2800199 |
for (x = 0; x < width; x++) |
122 |
|
|
{ |
123 |
|
2788080 |
xx = (xradio * x) >> 8; |
124 |
|
2788080 |
yy = (yradio * y) >> 8; |
125 |
|
|
|
126 |
|
2788080 |
get = (GX_UBYTE *)src -> gx_pixelmap_data; |
127 |
|
2788080 |
get += yy * getstride; |
128 |
|
2788080 |
get += xx >> 1; |
129 |
✓✓ |
2788080 |
if (xx & 1) |
130 |
|
|
{ |
131 |
|
1325484 |
pixel = *get & 0x0f; |
132 |
|
|
} |
133 |
|
|
else |
134 |
|
|
{ |
135 |
|
1462596 |
pixel = *get >> 4; |
136 |
|
|
} |
137 |
|
2788080 |
pixel |= (GX_UBYTE)(pixel << 4); |
138 |
|
|
|
139 |
|
2788080 |
*put &= (GX_UBYTE)(~putmask); |
140 |
|
2788080 |
*put |= putmask & pixel; |
141 |
|
|
|
142 |
|
2788080 |
putmask >>= 4; |
143 |
✓✓ |
2788080 |
if (putmask == 0) |
144 |
|
|
{ |
145 |
|
1394040 |
put++; |
146 |
|
1394040 |
putmask = 0xf0; |
147 |
|
|
} |
148 |
|
|
} |
149 |
|
12119 |
putrow += putstride; |
150 |
|
|
} |
151 |
|
|
|
152 |
|
101 |
return GX_SUCCESS; |
153 |
|
|
} |
154 |
|
|
/**************************************************************************/ |
155 |
|
|
/* */ |
156 |
|
|
/* FUNCTION RELEASE */ |
157 |
|
|
/* */ |
158 |
|
|
/* _gx_utility_4bpp_pixelmap_transparent_resize PORTABLE C */ |
159 |
|
|
/* 6.1 */ |
160 |
|
|
/* AUTHOR */ |
161 |
|
|
/* */ |
162 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
163 |
|
|
/* */ |
164 |
|
|
/* DESCRIPTION */ |
165 |
|
|
/* */ |
166 |
|
|
/* 4bpp pixelmap resize function that handles uncompress, with or */ |
167 |
|
|
/* transparent channel. */ |
168 |
|
|
/* */ |
169 |
|
|
/* INPUT */ |
170 |
|
|
/* */ |
171 |
|
|
/* src The source pixelmap */ |
172 |
|
|
/* destination The resized pixelmap to be */ |
173 |
|
|
/* returned */ |
174 |
|
|
/* width New width */ |
175 |
|
|
/* height New height */ |
176 |
|
|
/* */ |
177 |
|
|
/* OUTPUT */ |
178 |
|
|
/* */ |
179 |
|
|
/* status Completion status */ |
180 |
|
|
/* */ |
181 |
|
|
/* CALLS */ |
182 |
|
|
/* */ |
183 |
|
|
/* _gx_system_memory_allocator Memory Allocation routine */ |
184 |
|
|
/* */ |
185 |
|
|
/* CALLED BY */ |
186 |
|
|
/* */ |
187 |
|
|
/* GUIX Internal Code */ |
188 |
|
|
/* */ |
189 |
|
|
/**************************************************************************/ |
190 |
|
339 |
static UINT _gx_utility_4bpp_pixelmap_transparent_resize(GX_PIXELMAP *src, GX_PIXELMAP *destination, INT width, INT height) |
191 |
|
|
{ |
192 |
|
|
/* The pixelmap resize function is implemented from nearest neighbor |
193 |
|
|
image scaling algorithm. */ |
194 |
|
|
GX_UBYTE *get; |
195 |
|
|
GX_UBYTE *getaux; |
196 |
|
|
GX_UBYTE *put; |
197 |
|
|
GX_UBYTE *putrow; |
198 |
|
|
GX_UBYTE *putaux; |
199 |
|
|
GX_UBYTE *putauxrow; |
200 |
|
|
GX_UBYTE putmask; |
201 |
|
|
INT putstride; |
202 |
|
|
INT putauxstride; |
203 |
|
|
INT getstride; |
204 |
|
|
INT getauxstride; |
205 |
|
|
GX_UBYTE transmask; |
206 |
|
|
GX_UBYTE putauxmask; |
207 |
|
|
GX_UBYTE pixel; |
208 |
|
|
INT xradio; |
209 |
|
|
INT yradio; |
210 |
|
|
INT x; |
211 |
|
|
INT y; |
212 |
|
|
INT xx; |
213 |
|
|
INT yy; |
214 |
|
|
|
215 |
|
|
/* Calculate scale ratio and enlarge it by 256 times to keep precision. */ |
216 |
|
339 |
xradio = ((src -> gx_pixelmap_width) << 8) / width; |
217 |
|
339 |
yradio = ((src -> gx_pixelmap_height) << 8) / height; |
218 |
|
|
|
219 |
|
339 |
putstride = (width + 1) >> 1; |
220 |
|
339 |
putauxstride = (width + 7) >> 3; |
221 |
|
339 |
getstride = (src -> gx_pixelmap_width + 1) >> 1; |
222 |
|
339 |
getauxstride = (src -> gx_pixelmap_width + 7) >> 3; |
223 |
|
|
|
224 |
|
|
/* Fill property values into destination pixelmap structure. */ |
225 |
|
339 |
destination -> gx_pixelmap_flags = src -> gx_pixelmap_flags; |
226 |
|
339 |
destination -> gx_pixelmap_format = src -> gx_pixelmap_format; |
227 |
|
339 |
destination -> gx_pixelmap_transparent_color = src -> gx_pixelmap_transparent_color; |
228 |
|
339 |
destination -> gx_pixelmap_version_major = src -> gx_pixelmap_version_major; |
229 |
|
339 |
destination -> gx_pixelmap_version_minor = src -> gx_pixelmap_version_minor; |
230 |
|
|
|
231 |
|
339 |
destination -> gx_pixelmap_height = (GX_VALUE)height; |
232 |
|
339 |
destination -> gx_pixelmap_width = (GX_VALUE)width; |
233 |
|
|
|
234 |
|
|
/* Safe int math is not required here, calling function limits max width, height to 14 bits so |
235 |
|
|
overflow cannot occur. */ |
236 |
|
339 |
destination -> gx_pixelmap_data_size = (UINT)(height * putstride) * sizeof(GX_UBYTE); |
237 |
|
|
|
238 |
|
|
/* Allocate memory to load pixelmap data. */ |
239 |
|
339 |
destination -> gx_pixelmap_data = (GX_UBYTE *)_gx_system_memory_allocator(destination -> gx_pixelmap_data_size); |
240 |
|
|
|
241 |
✓✓ |
339 |
if (destination -> gx_pixelmap_data == GX_NULL) |
242 |
|
|
{ |
243 |
|
3 |
return GX_SYSTEM_MEMORY_ERROR; |
244 |
|
|
} |
245 |
|
|
|
246 |
|
|
/* Safe int math is not required here, calling function limits max width, height to 14 bits so |
247 |
|
|
overflow cannot occur. */ |
248 |
|
336 |
destination -> gx_pixelmap_aux_data_size = (UINT)(height * putauxstride) * sizeof(GX_UBYTE); |
249 |
|
336 |
destination -> gx_pixelmap_aux_data = (GX_UBYTE *)_gx_system_memory_allocator(destination -> gx_pixelmap_aux_data_size); |
250 |
|
|
|
251 |
✓✓ |
336 |
if (destination -> gx_pixelmap_aux_data == GX_NULL) |
252 |
|
|
{ |
253 |
|
3 |
_gx_system_memory_free((void *)destination -> gx_pixelmap_data); |
254 |
|
3 |
return GX_SYSTEM_MEMORY_ERROR; |
255 |
|
|
} |
256 |
|
|
|
257 |
|
333 |
putrow = (GX_UBYTE *)destination -> gx_pixelmap_data; |
258 |
|
333 |
putauxrow = (GX_UBYTE *)destination -> gx_pixelmap_aux_data; |
259 |
|
|
|
260 |
|
|
/* Loop through destination's pixel and fill each pixel with the nearest neighbor. */ |
261 |
✓✓ |
75616 |
for (y = 0; y < height; y++) |
262 |
|
|
{ |
263 |
|
75283 |
put = putrow; |
264 |
|
75283 |
putaux = putauxrow; |
265 |
|
75283 |
putmask = 0xf0; |
266 |
|
75283 |
putauxmask = 0x80; |
267 |
✓✓ |
14331263 |
for (x = 0; x < width; x++) |
268 |
|
|
{ |
269 |
|
14255980 |
xx = (xradio * x) >> 8; |
270 |
|
14255980 |
yy = (yradio * y) >> 8; |
271 |
|
|
|
272 |
|
|
/* set bits first. */ |
273 |
|
14255980 |
*put &= (GX_UBYTE)(~putmask); |
274 |
|
14255980 |
getaux = (GX_UBYTE *)src -> gx_pixelmap_aux_data; |
275 |
|
14255980 |
getaux += yy * getauxstride; |
276 |
|
14255980 |
getaux += xx >> 3; |
277 |
|
|
|
278 |
|
14255980 |
transmask = (GX_UBYTE)(0x80 >> (xx & 0x07)); |
279 |
✓✓ |
14255980 |
if (transmask & (*getaux)) |
280 |
|
|
{ |
281 |
|
|
/* set tranparent aux bit first. */ |
282 |
|
5022450 |
*putaux |= putauxmask; |
283 |
|
|
} |
284 |
|
|
else |
285 |
|
|
{ |
286 |
|
9233530 |
*putaux &= (GX_UBYTE)(~putauxmask); |
287 |
|
|
|
288 |
|
|
/* get pixel data */ |
289 |
|
9233530 |
get = (GX_UBYTE *)src -> gx_pixelmap_data; |
290 |
|
9233530 |
get += yy * getstride; |
291 |
|
9233530 |
get += xx >> 1; |
292 |
✓✓ |
9233530 |
if (xx & 1) |
293 |
|
|
{ |
294 |
|
4587633 |
pixel = *get & 0x0f; |
295 |
|
|
} |
296 |
|
|
else |
297 |
|
|
{ |
298 |
|
4645897 |
pixel = *get >> 4; |
299 |
|
|
} |
300 |
|
9233530 |
pixel |= (GX_UBYTE)(pixel << 4); |
301 |
|
9233530 |
*put |= putmask & pixel; |
302 |
|
|
} |
303 |
|
14255980 |
putauxmask >>= 1; |
304 |
✓✓ |
14255980 |
if (putauxmask == 0) |
305 |
|
|
{ |
306 |
|
1761169 |
putauxmask = 0x80; |
307 |
|
1761169 |
putaux++; |
308 |
|
|
} |
309 |
|
|
|
310 |
|
14255980 |
putmask >>= 4; |
311 |
✓✓ |
14255980 |
if (putmask == 0) |
312 |
|
|
{ |
313 |
|
7127831 |
put++; |
314 |
|
7127831 |
putmask = 0xf0; |
315 |
|
|
} |
316 |
|
|
} |
317 |
|
75283 |
putrow += putstride; |
318 |
|
75283 |
putauxrow += putauxstride; |
319 |
|
|
} |
320 |
|
|
|
321 |
|
333 |
return GX_SUCCESS; |
322 |
|
|
} |
323 |
|
|
/**************************************************************************/ |
324 |
|
|
/* */ |
325 |
|
|
/* FUNCTION RELEASE */ |
326 |
|
|
/* */ |
327 |
|
|
/* _gx_utility_4bpp_pixelmap_resize PORTABLE C */ |
328 |
|
|
/* 6.1 */ |
329 |
|
|
/* AUTHOR */ |
330 |
|
|
/* */ |
331 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
332 |
|
|
/* */ |
333 |
|
|
/* DESCRIPTION */ |
334 |
|
|
/* */ |
335 |
|
|
/* 4bpp pixelmap resize function that handles uncompress, with or */ |
336 |
|
|
/* without transparent channel. */ |
337 |
|
|
/* */ |
338 |
|
|
/* INPUT */ |
339 |
|
|
/* */ |
340 |
|
|
/* src The source pixelmap */ |
341 |
|
|
/* destination The resized pixelmap to be */ |
342 |
|
|
/* returned */ |
343 |
|
|
/* width New width */ |
344 |
|
|
/* height New height */ |
345 |
|
|
/* */ |
346 |
|
|
/* OUTPUT */ |
347 |
|
|
/* */ |
348 |
|
|
/* status Completion status */ |
349 |
|
|
/* */ |
350 |
|
|
/* CALLS */ |
351 |
|
|
/* */ |
352 |
|
|
/* _gx_utility_4bpp_pixelmap_transparent_resize */ |
353 |
|
|
/* Real pixelmap resize routine */ |
354 |
|
|
/* _gx_utility_4bpp_pixelmap_raw_resize Real pixelmap resize routine */ |
355 |
|
|
/* */ |
356 |
|
|
/* CALLED BY */ |
357 |
|
|
/* */ |
358 |
|
|
/* GUIX Internal Code */ |
359 |
|
|
/* */ |
360 |
|
|
/**************************************************************************/ |
361 |
|
442 |
UINT _gx_utility_4bpp_pixelmap_resize(GX_PIXELMAP *src, GX_PIXELMAP *destination, INT width, INT height) |
362 |
|
|
{ |
363 |
|
|
UINT status; |
364 |
|
|
|
365 |
✓✓ |
442 |
if (src -> gx_pixelmap_flags & GX_PIXELMAP_TRANSPARENT) |
366 |
|
|
{ |
367 |
|
|
/* transparent, no compression */ |
368 |
|
339 |
status = _gx_utility_4bpp_pixelmap_transparent_resize(src, destination, width, height); |
369 |
|
|
} |
370 |
|
|
else |
371 |
|
|
{ |
372 |
|
|
/* no compression or alpha */ |
373 |
|
103 |
status = _gx_utility_4bpp_pixelmap_raw_resize(src, destination, width, height); |
374 |
|
|
} |
375 |
|
|
|
376 |
|
442 |
return status; |
377 |
|
|
} |
378 |
|
|
|