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 REDVAL(_c) (GX_UBYTE)(((_c) >> 10) & 0x1f) |
22 |
|
|
#define GREENVAL(_c) (GX_UBYTE)(((_c) >> 5) & 0x1f) |
23 |
|
|
#define BLUEVAL(_c) (GX_UBYTE)(((_c)) & 0x1f) |
24 |
|
|
|
25 |
|
|
#define ASSEMBLECOLOR(_r, _g, _b) \ |
26 |
|
|
(USHORT)((((_r) & 0x1f) << 10) | \ |
27 |
|
|
(((_g) & 0x1f) << 5) | \ |
28 |
|
|
((_b) & 0x1f)) |
29 |
|
|
|
30 |
|
|
#define BYTE_RANGE(_c) _c > 255 ? 255 : _c |
31 |
|
|
|
32 |
|
|
#define GX_SOURCE_CODE |
33 |
|
|
|
34 |
|
|
|
35 |
|
|
/* Include necessary system files. */ |
36 |
|
|
|
37 |
|
|
#include "gx_api.h" |
38 |
|
|
#include "gx_utility.h" |
39 |
|
|
#include "gx_system.h" |
40 |
|
|
|
41 |
|
|
/**************************************************************************/ |
42 |
|
|
/* */ |
43 |
|
|
/* FUNCTION RELEASE */ |
44 |
|
|
/* */ |
45 |
|
|
/* _gx_utility_1555xrgb_pixelmap_raw_resize PORTABLE C */ |
46 |
|
|
/* 6.1.7 */ |
47 |
|
|
/* AUTHOR */ |
48 |
|
|
/* */ |
49 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
50 |
|
|
/* */ |
51 |
|
|
/* DESCRIPTION */ |
52 |
|
|
/* */ |
53 |
|
|
/* Internal helper function that resize an 1555xrgb format pixelmap */ |
54 |
|
|
/* without alpha. */ |
55 |
|
|
/* */ |
56 |
|
|
/* INPUT */ |
57 |
|
|
/* */ |
58 |
|
|
/* src The source pixelmap */ |
59 |
|
|
/* destination The resized pixelmap to be */ |
60 |
|
|
/* returned */ |
61 |
|
|
/* width New width */ |
62 |
|
|
/* height New height */ |
63 |
|
|
/* */ |
64 |
|
|
/* OUTPUT */ |
65 |
|
|
/* */ |
66 |
|
|
/* status Completion status */ |
67 |
|
|
/* */ |
68 |
|
|
/* CALLS */ |
69 |
|
|
/* */ |
70 |
|
|
/* _gx_system_memory_allocator */ |
71 |
|
|
/* */ |
72 |
|
|
/* CALLED BY */ |
73 |
|
|
/* */ |
74 |
|
|
/* GUIX Internal Code */ |
75 |
|
|
/* */ |
76 |
|
|
/* RELEASE HISTORY */ |
77 |
|
|
/* */ |
78 |
|
|
/* DATE NAME DESCRIPTION */ |
79 |
|
|
/* */ |
80 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
81 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
82 |
|
|
/* resulting in version 6.1 */ |
83 |
|
|
/* 06-02-2021 Kenneth Maxwell Modified comment(s), */ |
84 |
|
|
/* removed unused variable */ |
85 |
|
|
/* assignment, */ |
86 |
|
|
/* resulting in version 6.1.7 */ |
87 |
|
|
/* */ |
88 |
|
|
/**************************************************************************/ |
89 |
|
103 |
static UINT _gx_utility_1555xrgb_pixelmap_raw_resize(GX_PIXELMAP *src, GX_PIXELMAP *destination, INT width, INT height) |
90 |
|
|
{ |
91 |
|
|
/* The pixelmap resize function is implemented from bilinear interpolation |
92 |
|
|
image scaling algorithm. */ |
93 |
|
|
|
94 |
|
|
USHORT *get; |
95 |
|
|
USHORT *put; |
96 |
|
|
INT xdiff; |
97 |
|
|
INT ydiff; |
98 |
|
|
INT xradio; |
99 |
|
|
INT yradio; |
100 |
|
|
INT x; |
101 |
|
|
INT y; |
102 |
|
|
INT xx; |
103 |
|
|
INT yy; |
104 |
|
|
USHORT neighbor_pixels[2][2]; |
105 |
|
|
GX_COLOR red; |
106 |
|
|
GX_COLOR green; |
107 |
|
|
GX_COLOR blue; |
108 |
|
|
|
109 |
|
|
/* Calculate scale ratio and enlarge it by 256 times to keep precision. */ |
110 |
|
103 |
xradio = ((src -> gx_pixelmap_width) << 8) / width; |
111 |
|
103 |
yradio = ((src -> gx_pixelmap_height) << 8) / height; |
112 |
|
|
|
113 |
|
|
/* Fill property values into destination pixelmap structure. */ |
114 |
|
103 |
destination -> gx_pixelmap_flags = src -> gx_pixelmap_flags; |
115 |
|
103 |
destination -> gx_pixelmap_format = src -> gx_pixelmap_format; |
116 |
|
|
|
117 |
|
103 |
destination -> gx_pixelmap_height = (GX_VALUE)height; |
118 |
|
103 |
destination -> gx_pixelmap_width = (GX_VALUE)width; |
119 |
|
|
|
120 |
|
|
/* Safe int math is not required here, calling function limits max width, height to 14 bits so |
121 |
|
|
overflow cannot occur. */ |
122 |
|
103 |
destination -> gx_pixelmap_data_size = (UINT)(height * width) * sizeof(USHORT); |
123 |
|
|
|
124 |
|
|
/* Allocate memory for destination pixelmap. */ |
125 |
|
103 |
destination -> gx_pixelmap_data = (GX_UBYTE *)_gx_system_memory_allocator(destination -> gx_pixelmap_data_size); |
126 |
|
103 |
destination -> gx_pixelmap_aux_data = GX_NULL; |
127 |
|
|
|
128 |
✓✓ |
103 |
if (destination -> gx_pixelmap_data == GX_NULL) |
129 |
|
|
{ |
130 |
|
2 |
return GX_SYSTEM_MEMORY_ERROR; |
131 |
|
|
} |
132 |
|
|
|
133 |
|
101 |
put = (USHORT *)destination -> gx_pixelmap_data; |
134 |
|
|
|
135 |
|
|
/* Loop through destination's pixel and fill each pixel with |
136 |
|
|
the interpolation of 4 nearest neighboring pixels.*/ |
137 |
✓✓ |
12220 |
for (y = 0; y < height; y++) |
138 |
|
|
{ |
139 |
✓✓ |
2800199 |
for (x = 0; x < width; x++) |
140 |
|
|
{ |
141 |
|
|
/* Find the original source pixel that the destination pixel conrespond to. */ |
142 |
|
2788080 |
xx = (xradio * x) >> 8; |
143 |
|
2788080 |
yy = (yradio * y) >> 8; |
144 |
|
|
|
145 |
|
|
/* The coordinates of the original source pixel are truncate value, |
146 |
|
|
calucate their distance between the mathematical coordinates. */ |
147 |
|
2788080 |
xdiff = (xradio * x) & 0xff; |
148 |
|
2788080 |
ydiff = (yradio * y) & 0xff; |
149 |
|
|
|
150 |
|
2788080 |
get = (USHORT *)src -> gx_pixelmap_data; |
151 |
|
2788080 |
get += yy * src -> gx_pixelmap_width; |
152 |
|
2788080 |
get += xx; |
153 |
|
|
|
154 |
|
|
/* Calculate 4 nearest neighboring pixels around the mathematical point of original pixel. */ |
155 |
|
2788080 |
neighbor_pixels[0][0] = *get; |
156 |
|
|
|
157 |
✓✓✓✓
|
2788080 |
if ((xx < src -> gx_pixelmap_width - 1) && (yy < src -> gx_pixelmap_height - 1)) |
158 |
|
|
{ |
159 |
|
2782329 |
neighbor_pixels[0][1] = *(get + 1); |
160 |
|
2782329 |
neighbor_pixels[1][0] = *(get + src -> gx_pixelmap_width); |
161 |
|
2782329 |
neighbor_pixels[1][1] = *(get + src -> gx_pixelmap_width + 1); |
162 |
|
|
} |
163 |
|
|
else |
164 |
|
|
{ |
165 |
|
|
|
166 |
✓✓ |
5751 |
if ((xx == src -> gx_pixelmap_width - 1) && |
167 |
✓✓ |
1193 |
(yy == src -> gx_pixelmap_height - 1)) |
168 |
|
|
{ |
169 |
|
|
/* Handle pixels in right bottom corner. */ |
170 |
|
2 |
neighbor_pixels[0][1] = neighbor_pixels[0][0]; |
171 |
|
2 |
neighbor_pixels[1][0] = neighbor_pixels[0][0]; |
172 |
|
2 |
neighbor_pixels[1][1] = neighbor_pixels[0][0]; |
173 |
|
|
} |
174 |
✓✓ |
5749 |
else if (xx == src -> gx_pixelmap_width - 1) |
175 |
|
|
{ |
176 |
|
|
/* Handle pixels in right edge. */ |
177 |
|
1191 |
neighbor_pixels[0][1] = neighbor_pixels[0][0]; |
178 |
|
1191 |
neighbor_pixels[1][0] = *(get + src -> gx_pixelmap_width); |
179 |
|
1191 |
neighbor_pixels[1][1] = neighbor_pixels[1][0]; |
180 |
|
|
} |
181 |
|
|
else |
182 |
|
|
{ |
183 |
|
|
/* Handle pixels in bottom edge. */ |
184 |
|
4558 |
neighbor_pixels[0][1] = *(get + 1); |
185 |
|
4558 |
neighbor_pixels[1][0] = neighbor_pixels[0][0]; |
186 |
|
4558 |
neighbor_pixels[1][1] = neighbor_pixels[0][1]; |
187 |
|
|
} |
188 |
|
|
} |
189 |
|
|
|
190 |
|
|
|
191 |
|
|
/* Calulate pixel values by interpolating 4 neighboring pixels. */ |
192 |
|
2788080 |
red = (REDVAL(neighbor_pixels[0][0]) * (256 - (GX_COLOR)xdiff) * (256 - (GX_COLOR)ydiff) + \ |
193 |
|
2788080 |
REDVAL(neighbor_pixels[0][1]) * (GX_COLOR)xdiff * (256 - (GX_COLOR)ydiff) + \ |
194 |
|
2788080 |
REDVAL(neighbor_pixels[1][0]) * (GX_COLOR)ydiff * (256 - (GX_COLOR)xdiff) + \ |
195 |
|
2788080 |
REDVAL(neighbor_pixels[1][1]) * (GX_COLOR)xdiff * (GX_COLOR)ydiff) >> 16; |
196 |
|
|
|
197 |
|
2788080 |
green = (GREENVAL(neighbor_pixels[0][0]) * (256 - (GX_COLOR)xdiff) * (256 - (GX_COLOR)ydiff) + \ |
198 |
|
2788080 |
GREENVAL(neighbor_pixels[0][1]) * (GX_COLOR)xdiff * (256 - (GX_COLOR)ydiff) + \ |
199 |
|
2788080 |
GREENVAL(neighbor_pixels[1][0]) * (GX_COLOR)ydiff * (256 - (GX_COLOR)xdiff) + \ |
200 |
|
2788080 |
GREENVAL(neighbor_pixels[1][1]) * (GX_COLOR)xdiff * (GX_COLOR)ydiff) >> 16; |
201 |
|
|
|
202 |
|
2788080 |
blue = (BLUEVAL(neighbor_pixels[0][0]) * (256 - (GX_COLOR)xdiff) * (256 - (GX_COLOR)ydiff) + \ |
203 |
|
2788080 |
BLUEVAL(neighbor_pixels[0][1]) * (GX_COLOR)xdiff * (256 - (GX_COLOR)ydiff) + \ |
204 |
|
2788080 |
BLUEVAL(neighbor_pixels[1][0]) * (GX_COLOR)ydiff * (256 - (GX_COLOR)xdiff) + \ |
205 |
|
2788080 |
BLUEVAL(neighbor_pixels[1][1]) * (GX_COLOR)xdiff * (GX_COLOR)ydiff) >> 16; |
206 |
|
|
|
207 |
|
2788080 |
red = BYTE_RANGE(red); |
208 |
|
2788080 |
green = BYTE_RANGE(green); |
209 |
|
2788080 |
blue = BYTE_RANGE(blue); |
210 |
|
|
|
211 |
|
2788080 |
*put++ = ASSEMBLECOLOR(red, green, blue); |
212 |
|
|
} |
213 |
|
|
} |
214 |
|
|
|
215 |
|
101 |
return GX_SUCCESS; |
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
/**************************************************************************/ |
219 |
|
|
/* */ |
220 |
|
|
/* FUNCTION RELEASE */ |
221 |
|
|
/* */ |
222 |
|
|
/* _gx_utility_1555xrgb_pixelmap_alpha_resize PORTABLE C */ |
223 |
|
|
/* 6.1.7 */ |
224 |
|
|
/* AUTHOR */ |
225 |
|
|
/* */ |
226 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
227 |
|
|
/* */ |
228 |
|
|
/* DESCRIPTION */ |
229 |
|
|
/* */ |
230 |
|
|
/* Internal helper function that resize an 1555xrgb format pixelmap */ |
231 |
|
|
/* with alpha. */ |
232 |
|
|
/* */ |
233 |
|
|
/* INPUT */ |
234 |
|
|
/* */ |
235 |
|
|
/* src The source pixelmap */ |
236 |
|
|
/* destination The resized pixelmap to be */ |
237 |
|
|
/* returned */ |
238 |
|
|
/* width New width */ |
239 |
|
|
/* height New height */ |
240 |
|
|
/* */ |
241 |
|
|
/* OUTPUT */ |
242 |
|
|
/* */ |
243 |
|
|
/* status Completion status */ |
244 |
|
|
/* */ |
245 |
|
|
/* CALLS */ |
246 |
|
|
/* */ |
247 |
|
|
/* _gx_system_memory_allocator */ |
248 |
|
|
/* */ |
249 |
|
|
/* CALLED BY */ |
250 |
|
|
/* */ |
251 |
|
|
/* GUIX Internal Code */ |
252 |
|
|
/* */ |
253 |
|
|
/* RELEASE HISTORY */ |
254 |
|
|
/* */ |
255 |
|
|
/* DATE NAME DESCRIPTION */ |
256 |
|
|
/* */ |
257 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
258 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
259 |
|
|
/* resulting in version 6.1 */ |
260 |
|
|
/* 06-02-2021 Kenneth Maxwell Modified comment(s), */ |
261 |
|
|
/* removed unused variable */ |
262 |
|
|
/* assignment, */ |
263 |
|
|
/* resulting in version 6.1.7 */ |
264 |
|
|
/* */ |
265 |
|
|
/**************************************************************************/ |
266 |
|
103 |
static UINT _gx_utility_1555xrgb_pixelmap_alpha_resize(GX_PIXELMAP *src, GX_PIXELMAP *destination, INT width, INT height) |
267 |
|
|
{ |
268 |
|
|
/* The pixelmap resize function is implemented from bilinear interpolation |
269 |
|
|
image scaling algorithm. */ |
270 |
|
|
|
271 |
|
|
USHORT *get; |
272 |
|
|
USHORT *put; |
273 |
|
|
GX_UBYTE *getalpha; |
274 |
|
|
GX_UBYTE *putalpha; |
275 |
|
|
INT xdiff; |
276 |
|
|
INT ydiff; |
277 |
|
|
INT xradio; |
278 |
|
|
INT yradio; |
279 |
|
|
INT x; |
280 |
|
|
INT y; |
281 |
|
|
INT xx; |
282 |
|
|
INT yy; |
283 |
|
|
USHORT neighbor_pixels[2][2]; |
284 |
|
|
GX_COLOR alpha[4]; |
285 |
|
|
GX_COLOR red; |
286 |
|
|
GX_COLOR green; |
287 |
|
|
GX_COLOR blue; |
288 |
|
|
|
289 |
|
|
/* Calculate scale ratio and enlarge it by 256 times to keep precision. */ |
290 |
|
103 |
xradio = ((src -> gx_pixelmap_width) << 8) / width; |
291 |
|
103 |
yradio = ((src -> gx_pixelmap_height) << 8) / height; |
292 |
|
|
|
293 |
|
|
/* Fill property values into destination pixelmap structure. */ |
294 |
|
103 |
destination -> gx_pixelmap_flags = src -> gx_pixelmap_flags; |
295 |
|
103 |
destination -> gx_pixelmap_format = src -> gx_pixelmap_format; |
296 |
|
|
|
297 |
|
103 |
destination -> gx_pixelmap_height = (GX_VALUE)height; |
298 |
|
103 |
destination -> gx_pixelmap_width = (GX_VALUE)width; |
299 |
|
|
|
300 |
|
|
/* Safe int math is not required here, calling function limits max width, height to 14 bits so |
301 |
|
|
overflow cannot occur. */ |
302 |
|
103 |
destination -> gx_pixelmap_data_size = (UINT)(height * width) * sizeof(USHORT); |
303 |
|
103 |
destination -> gx_pixelmap_aux_data_size = (UINT)(height * width) * sizeof(GX_UBYTE); |
304 |
|
|
|
305 |
|
|
/* Allocate memory to load pixelmap data. */ |
306 |
|
103 |
destination -> gx_pixelmap_data = (GX_UBYTE *)_gx_system_memory_allocator(destination -> gx_pixelmap_data_size); |
307 |
|
|
|
308 |
✓✓ |
103 |
if (destination -> gx_pixelmap_data == GX_NULL) |
309 |
|
|
{ |
310 |
|
1 |
return GX_SYSTEM_MEMORY_ERROR; |
311 |
|
|
} |
312 |
|
|
|
313 |
|
102 |
destination -> gx_pixelmap_aux_data = (GX_UBYTE *)_gx_system_memory_allocator(destination -> gx_pixelmap_aux_data_size); |
314 |
|
|
|
315 |
✓✓ |
102 |
if (destination -> gx_pixelmap_aux_data == GX_NULL) |
316 |
|
|
{ |
317 |
|
1 |
_gx_system_memory_free((void *)destination -> gx_pixelmap_data); |
318 |
|
1 |
return GX_SYSTEM_MEMORY_ERROR; |
319 |
|
|
} |
320 |
|
|
|
321 |
|
101 |
put = (USHORT *)destination -> gx_pixelmap_data; |
322 |
|
101 |
putalpha = (GX_UBYTE *)destination -> gx_pixelmap_aux_data; |
323 |
|
|
|
324 |
|
|
/* Loop through destination's pixel and fill each pixel with |
325 |
|
|
the interpolation of 4 nearest neighboring pixels.*/ |
326 |
✓✓ |
14434 |
for (y = 0; y < height; y++) |
327 |
|
|
{ |
328 |
✓✓ |
2487353 |
for (x = 0; x < width; x++) |
329 |
|
|
{ |
330 |
|
|
/* Find the original source pixel that the destination pixel conrespond to. */ |
331 |
|
2473020 |
xx = (xradio * x) >> 8; |
332 |
|
2473020 |
yy = (yradio * y) >> 8; |
333 |
|
|
|
334 |
|
|
/* The coordinates of the original source pixel are truncate value, |
335 |
|
|
calucate their distance between the mathematical coordinates. */ |
336 |
|
2473020 |
xdiff = (xradio * x) & 0xff; |
337 |
|
2473020 |
ydiff = (yradio * y) & 0xff; |
338 |
|
|
|
339 |
|
2473020 |
get = (USHORT *)src -> gx_pixelmap_data; |
340 |
|
2473020 |
get += yy * src -> gx_pixelmap_width; |
341 |
|
2473020 |
get += xx; |
342 |
|
|
|
343 |
|
2473020 |
getalpha = (GX_UBYTE *)src -> gx_pixelmap_aux_data; |
344 |
|
2473020 |
getalpha += yy * src -> gx_pixelmap_width; |
345 |
|
2473020 |
getalpha += xx; |
346 |
|
|
|
347 |
|
|
|
348 |
|
|
/* Calculate 4 nearest neighboring pixels around the mathematical point of original pixel. */ |
349 |
|
2473020 |
neighbor_pixels[0][0] = *get; |
350 |
|
2473020 |
alpha[0] = *getalpha; |
351 |
|
|
|
352 |
✓✓✓✓
|
2473020 |
if ((xx < src -> gx_pixelmap_width - 1) && (yy < src -> gx_pixelmap_height - 1)) |
353 |
|
|
{ |
354 |
|
2467921 |
neighbor_pixels[0][1] = *(get + 1); |
355 |
|
2467921 |
neighbor_pixels[1][0] = *(get + src -> gx_pixelmap_width); |
356 |
|
2467921 |
neighbor_pixels[1][1] = *(get + src -> gx_pixelmap_width + 1); |
357 |
|
|
|
358 |
|
2467921 |
alpha[1] = *(getalpha + 1); |
359 |
|
2467921 |
alpha[2] = *(getalpha + src -> gx_pixelmap_width); |
360 |
|
2467921 |
alpha[3] = *(getalpha + src -> gx_pixelmap_width + 1); |
361 |
|
|
} |
362 |
|
|
else |
363 |
|
|
{ |
364 |
|
|
|
365 |
✓✓ |
5099 |
if ((xx == src -> gx_pixelmap_width - 1) && |
366 |
✓✓ |
1411 |
(yy == src -> gx_pixelmap_height - 1)) |
367 |
|
|
{ |
368 |
|
|
/* Handle right bottom corder pixel. */ |
369 |
|
2 |
neighbor_pixels[0][1] = neighbor_pixels[0][0]; |
370 |
|
2 |
neighbor_pixels[1][0] = neighbor_pixels[0][0]; |
371 |
|
2 |
neighbor_pixels[1][1] = neighbor_pixels[0][0]; |
372 |
|
|
|
373 |
|
2 |
alpha[1] = alpha[0]; |
374 |
|
2 |
alpha[2] = alpha[0]; |
375 |
|
2 |
alpha[3] = alpha[0]; |
376 |
|
|
} |
377 |
✓✓ |
5097 |
else if (xx == src -> gx_pixelmap_width - 1) |
378 |
|
|
{ |
379 |
|
|
/* Handle pixels in right edge. */ |
380 |
|
1409 |
neighbor_pixels[0][1] = neighbor_pixels[0][0]; |
381 |
|
1409 |
neighbor_pixels[1][0] = *(get + src -> gx_pixelmap_width); |
382 |
|
1409 |
neighbor_pixels[1][1] = neighbor_pixels[1][0]; |
383 |
|
|
|
384 |
|
1409 |
alpha[1] = alpha[0]; |
385 |
|
1409 |
alpha[2] = *(getalpha + src -> gx_pixelmap_width); |
386 |
|
1409 |
alpha[3] = alpha[2]; |
387 |
|
|
} |
388 |
|
|
else |
389 |
|
|
{ |
390 |
|
|
/* Handle pixels in bottom edge. */ |
391 |
|
3688 |
neighbor_pixels[0][1] = *(get + 1); |
392 |
|
3688 |
neighbor_pixels[1][0] = neighbor_pixels[0][0]; |
393 |
|
3688 |
neighbor_pixels[1][1] = neighbor_pixels[0][1]; |
394 |
|
|
|
395 |
|
3688 |
alpha[1] = *(getalpha + 1); |
396 |
|
3688 |
alpha[2] = alpha[0]; |
397 |
|
3688 |
alpha[3] = alpha[1]; |
398 |
|
|
} |
399 |
|
|
} |
400 |
|
|
|
401 |
|
|
/* Calulate pixel values by interpolating 4 neighboring pixels. */ |
402 |
|
2473020 |
red = (REDVAL(neighbor_pixels[0][0]) * (alpha[0]) * (256 - (GX_COLOR)xdiff) * (256 - (GX_COLOR)ydiff) + \ |
403 |
|
2473020 |
REDVAL(neighbor_pixels[0][1]) * (alpha[1]) * (GX_COLOR)xdiff * (256 - (GX_COLOR)ydiff) + \ |
404 |
|
2473020 |
REDVAL(neighbor_pixels[1][0]) * (alpha[2]) * (GX_COLOR)ydiff * (256 - (GX_COLOR)xdiff) + \ |
405 |
|
2473020 |
REDVAL(neighbor_pixels[1][1]) * (alpha[3]) * (GX_COLOR)xdiff * (GX_COLOR)ydiff) >> 16; |
406 |
|
|
|
407 |
|
2473020 |
green = (GREENVAL(neighbor_pixels[0][0]) * (alpha[0]) * (256 - (GX_COLOR)xdiff) * (256 - (GX_COLOR)ydiff) + \ |
408 |
|
2473020 |
GREENVAL(neighbor_pixels[0][1]) * (alpha[1]) * (GX_COLOR)xdiff * (256 - (GX_COLOR)ydiff) + \ |
409 |
|
2473020 |
GREENVAL(neighbor_pixels[1][0]) * (alpha[2]) * (GX_COLOR)ydiff * (256 - (GX_COLOR)xdiff) + \ |
410 |
|
2473020 |
GREENVAL(neighbor_pixels[1][1]) * (alpha[3]) * (GX_COLOR)xdiff * (GX_COLOR)ydiff) >> 16; |
411 |
|
|
|
412 |
|
2473020 |
blue = (BLUEVAL(neighbor_pixels[0][0]) * (alpha[0]) * (256 - (GX_COLOR)xdiff) * (256 - (GX_COLOR)ydiff) + \ |
413 |
|
2473020 |
BLUEVAL(neighbor_pixels[0][1]) * (alpha[1]) * (GX_COLOR)xdiff * (256 - (GX_COLOR)ydiff) + \ |
414 |
|
2473020 |
BLUEVAL(neighbor_pixels[1][0]) * (alpha[2]) * (GX_COLOR)ydiff * (256 - (GX_COLOR)xdiff) + \ |
415 |
|
2473020 |
BLUEVAL(neighbor_pixels[1][1]) * (alpha[3]) * (GX_COLOR)xdiff * (GX_COLOR)ydiff) >> 16; |
416 |
|
|
|
417 |
|
2473020 |
alpha[0] = ((alpha[0]) * (256 - (GX_COLOR)xdiff) * (256 - (GX_COLOR)ydiff) + \ |
418 |
|
2473020 |
(alpha[1]) * (GX_COLOR)xdiff * (256 - (GX_COLOR)ydiff) + \ |
419 |
|
2473020 |
(alpha[2]) * (GX_COLOR)ydiff * (256 - (GX_COLOR)xdiff) + \ |
420 |
|
2473020 |
(alpha[3]) * (GX_COLOR)xdiff * (GX_COLOR)ydiff) >> 16; |
421 |
|
|
|
422 |
✓✓ |
2473020 |
if (alpha[0]) |
423 |
|
|
{ |
424 |
|
1060788 |
red /= alpha[0]; |
425 |
|
1060788 |
green /= alpha[0]; |
426 |
|
1060788 |
blue /= alpha[0]; |
427 |
|
|
} |
428 |
|
|
|
429 |
|
2473020 |
alpha[0] = BYTE_RANGE(alpha[0]); |
430 |
|
2473020 |
red = BYTE_RANGE(red); |
431 |
|
2473020 |
green = BYTE_RANGE(green); |
432 |
|
2473020 |
blue = BYTE_RANGE(blue); |
433 |
|
|
|
434 |
|
2473020 |
*put++ = ASSEMBLECOLOR(red, green, blue); |
435 |
|
2473020 |
*putalpha++ = (GX_UBYTE)alpha[0]; |
436 |
|
|
} |
437 |
|
|
} |
438 |
|
|
|
439 |
|
101 |
return GX_SUCCESS; |
440 |
|
|
} |
441 |
|
|
|
442 |
|
|
/**************************************************************************/ |
443 |
|
|
/* */ |
444 |
|
|
/* FUNCTION RELEASE */ |
445 |
|
|
/* */ |
446 |
|
|
/* _gx_utility_1555xrgb_pixelmap_resize PORTABLE C */ |
447 |
|
|
/* 6.1 */ |
448 |
|
|
/* AUTHOR */ |
449 |
|
|
/* */ |
450 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
451 |
|
|
/* */ |
452 |
|
|
/* DESCRIPTION */ |
453 |
|
|
/* */ |
454 |
|
|
/* This function resize an 1555xrgb format pixelmap with or without */ |
455 |
|
|
/* alpha channel. */ |
456 |
|
|
/* */ |
457 |
|
|
/* INPUT */ |
458 |
|
|
/* */ |
459 |
|
|
/* src The source pixelmap */ |
460 |
|
|
/* destination The resized pixelmap to be */ |
461 |
|
|
/* returned */ |
462 |
|
|
/* width New width */ |
463 |
|
|
/* height New height */ |
464 |
|
|
/* */ |
465 |
|
|
/* OUTPUT */ |
466 |
|
|
/* */ |
467 |
|
|
/* status Completion status */ |
468 |
|
|
/* */ |
469 |
|
|
/* CALLS */ |
470 |
|
|
/* */ |
471 |
|
|
/* _gx_utility_1555xrgb_pixelmap_alpha_resize */ |
472 |
|
|
/* Resize 1555xrgb format */ |
473 |
|
|
/* pixelmap with alpha */ |
474 |
|
|
/* _gx_utility_1555xrgb_pixelmap_raw_resize */ |
475 |
|
|
/* Resize 1555xrgb format */ |
476 |
|
|
/* pixelmap without alpha */ |
477 |
|
|
/* */ |
478 |
|
|
/* CALLED BY */ |
479 |
|
|
/* */ |
480 |
|
|
/* GUIX Internal Code */ |
481 |
|
|
/* */ |
482 |
|
|
/* RELEASE HISTORY */ |
483 |
|
|
/* */ |
484 |
|
|
/* DATE NAME DESCRIPTION */ |
485 |
|
|
/* */ |
486 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
487 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
488 |
|
|
/* resulting in version 6.1 */ |
489 |
|
|
/* */ |
490 |
|
|
/**************************************************************************/ |
491 |
|
206 |
UINT _gx_utility_1555xrgb_pixelmap_resize(GX_PIXELMAP *src, GX_PIXELMAP *destination, INT width, INT height) |
492 |
|
|
{ |
493 |
|
|
UINT status; |
494 |
|
|
|
495 |
✓✓ |
206 |
if (src -> gx_pixelmap_flags & GX_PIXELMAP_ALPHA) |
496 |
|
|
{ |
497 |
|
|
/* alpha, no compression */ |
498 |
|
|
|
499 |
|
103 |
status = _gx_utility_1555xrgb_pixelmap_alpha_resize(src, destination, width, height); |
500 |
|
|
} |
501 |
|
|
else |
502 |
|
|
{ |
503 |
|
|
/* no alpha, no compression */ |
504 |
|
|
|
505 |
|
103 |
status = _gx_utility_1555xrgb_pixelmap_raw_resize(src, destination, width, height); |
506 |
|
|
} |
507 |
|
|
|
508 |
|
206 |
return status; |
509 |
|
|
} |