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 |
|
|
/** Image Reader Management (Image Reader) */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define GX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
|
27 |
|
|
#include "gx_api.h" |
28 |
|
|
#include "gx_image_reader.h" |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
/**************************************************************************/ |
32 |
|
|
/* */ |
33 |
|
|
/* FUNCTION RELEASE */ |
34 |
|
|
/* */ |
35 |
|
|
/* _gx_image_reader_nearest_palette_color_get PORTABLE C */ |
36 |
|
|
/* 6.1 */ |
37 |
|
|
/* AUTHOR */ |
38 |
|
|
/* */ |
39 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
40 |
|
|
/* */ |
41 |
|
|
/* DESCRIPTION */ |
42 |
|
|
/* */ |
43 |
|
|
/* This function retrieves the nearest palette color. */ |
44 |
|
|
/* */ |
45 |
|
|
/* INPUT */ |
46 |
|
|
/* */ |
47 |
|
|
/* image_reader Image reader control block. */ |
48 |
|
|
/* want_color Wanted color value. */ |
49 |
|
|
/* index Retrieved color index. */ |
50 |
|
|
/* */ |
51 |
|
|
/* OUTPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* Completion Status */ |
54 |
|
|
/* */ |
55 |
|
|
/* CALLS */ |
56 |
|
|
/* */ |
57 |
|
|
/* None */ |
58 |
|
|
/* */ |
59 |
|
|
/* CALLED BY */ |
60 |
|
|
/* */ |
61 |
|
|
/* GUIX Internal Code */ |
62 |
|
|
/* */ |
63 |
|
|
/**************************************************************************/ |
64 |
|
|
#if defined(GX_SOFTWARE_DECODER_SUPPORT) |
65 |
|
3675284 |
UINT _gx_image_reader_nearest_palette_color_get(GX_IMAGE_READER *image_reader, GX_PIXEL *want_color, INT *index) |
66 |
|
|
{ |
67 |
|
3675284 |
ULONG nearest_dist = 0x7fffffff; |
68 |
|
|
ULONG dist; |
69 |
|
|
GX_UBYTE red_dist; |
70 |
|
|
GX_UBYTE green_dist; |
71 |
|
|
GX_UBYTE blue_dist; |
72 |
|
|
UINT pal_index; |
73 |
|
3675284 |
INT nearest_index = 0; |
74 |
|
3675284 |
GX_COLOR *palette = image_reader -> gx_image_reader_palette; |
75 |
|
3675284 |
UINT palsize = image_reader -> gx_image_reader_palette_size; |
76 |
|
|
GX_PIXEL pal_color; |
77 |
|
|
|
78 |
✓✓ |
3675284 |
if (palette) |
79 |
|
|
{ |
80 |
✓✓ |
935239962 |
for (pal_index = 0; pal_index < palsize; pal_index++) |
81 |
|
|
{ |
82 |
|
931600896 |
pal_color.gx_pixel_red = (GX_UBYTE)(palette[pal_index] >> 16); |
83 |
|
931600896 |
pal_color.gx_pixel_green = (GX_UBYTE)(palette[pal_index] >> 8); |
84 |
|
931600896 |
pal_color.gx_pixel_blue = (GX_UBYTE)palette[pal_index]; |
85 |
|
|
|
86 |
✓✓ |
931600896 |
red_dist = (GX_UBYTE)GX_ABS(want_color -> gx_pixel_red - pal_color.gx_pixel_red); |
87 |
✓✓ |
931600896 |
green_dist = (GX_UBYTE)GX_ABS(want_color -> gx_pixel_green - pal_color.gx_pixel_green); |
88 |
✓✓ |
931600896 |
blue_dist = (GX_UBYTE)GX_ABS(want_color -> gx_pixel_blue - pal_color.gx_pixel_blue); |
89 |
|
|
|
90 |
|
931600896 |
dist = (ULONG)((red_dist * red_dist) + (green_dist * green_dist) + (blue_dist * blue_dist)); |
91 |
|
|
|
92 |
✓✓ |
931600896 |
if (dist < nearest_dist) |
93 |
|
|
{ |
94 |
|
33454356 |
nearest_dist = dist; |
95 |
|
33454356 |
nearest_index = (INT)pal_index; |
96 |
|
|
} |
97 |
|
|
} |
98 |
|
|
|
99 |
|
3639066 |
want_color -> gx_pixel_red = (GX_UBYTE)(palette[nearest_index] >> 16); |
100 |
|
3639066 |
want_color -> gx_pixel_green = (GX_UBYTE)(palette[nearest_index] >> 8); |
101 |
|
3639066 |
want_color -> gx_pixel_blue = (GX_UBYTE)palette[nearest_index]; |
102 |
|
|
|
103 |
|
3639066 |
*index = nearest_index; |
104 |
|
|
} |
105 |
|
|
else |
106 |
|
|
{ |
107 |
|
36218 |
want_color -> gx_pixel_red = 0; |
108 |
|
36218 |
want_color -> gx_pixel_green = 0; |
109 |
|
36218 |
want_color -> gx_pixel_blue = 0; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
3675284 |
return GX_SUCCESS; |
113 |
|
|
} |
114 |
|
|
#endif |
115 |
|
|
|