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 |
|
|
/** Binres Loader Management (Binres Loader) */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
|
21 |
|
|
#define GX_SOURCE_CODE |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#include "gx_api.h" |
27 |
|
|
#include "gx_binres_loader.h" |
28 |
|
|
#include "gx_utility.h" |
29 |
|
|
|
30 |
|
|
/**************************************************************************/ |
31 |
|
|
/* */ |
32 |
|
|
/* FUNCTION RELEASE */ |
33 |
|
|
/* */ |
34 |
|
|
/* _gx_binres_standalone_resource_seek PORTABLE C */ |
35 |
|
|
/* 6.3.0 */ |
36 |
|
|
/* AUTHOR */ |
37 |
|
|
/* */ |
38 |
|
|
/* Ting Zhu, Microsoft Corporation */ |
39 |
|
|
/* */ |
40 |
|
|
/* DESCRIPTION */ |
41 |
|
|
/* */ |
42 |
|
|
/* This function locates the resource data in the binary data memory. */ |
43 |
|
|
/* */ |
44 |
|
|
/* INPUT */ |
45 |
|
|
/* */ |
46 |
|
|
/* info Binary resource control block */ |
47 |
|
|
/* res_index The index of the resource to */ |
48 |
|
|
/* be located */ |
49 |
|
|
/* */ |
50 |
|
|
/* OUTPUT */ |
51 |
|
|
/* */ |
52 |
|
|
/* Status Completion status */ |
53 |
|
|
/* */ |
54 |
|
|
/* CALLS */ |
55 |
|
|
/* */ |
56 |
|
|
/* None */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLED BY */ |
59 |
|
|
/* */ |
60 |
|
|
/* GUIX Internal Code */ |
61 |
|
|
/* */ |
62 |
|
|
/* RELEASE HISTORY */ |
63 |
|
|
/* */ |
64 |
|
|
/* DATE NAME DESCRIPTION */ |
65 |
|
|
/* */ |
66 |
|
|
/* 10-31-2023 Ting Zhu Initial Version 6.3.0 */ |
67 |
|
|
/* */ |
68 |
|
|
/**************************************************************************/ |
69 |
|
26 |
UINT _gx_binres_standalone_resource_seek(GX_BINRES_DATA_INFO *info, UINT res_index) |
70 |
|
|
{ |
71 |
|
|
USHORT type; |
72 |
|
|
ULONG count; |
73 |
|
|
|
74 |
|
26 |
GX_BINRES_READ_USHORT(type, info -> gx_binres_root_address + info -> gx_binres_read_offset); |
75 |
|
26 |
info -> gx_binres_read_offset += sizeof(USHORT); |
76 |
|
|
|
77 |
✓✓ |
26 |
if (type != GX_RESOURCE_TYPE_BINRES_STANDALONE) |
78 |
|
|
{ |
79 |
|
7 |
return GX_INVALID_FORMAT; |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
/* Skip 2 bytes version. */ |
83 |
|
19 |
info -> gx_binres_read_offset += sizeof(USHORT); |
84 |
|
|
|
85 |
|
19 |
GX_BINRES_READ_ULONG(count, info -> gx_binres_root_address + info -> gx_binres_read_offset); |
86 |
|
19 |
info -> gx_binres_read_offset += sizeof(ULONG); |
87 |
|
|
|
88 |
✗✓ |
19 |
if ((USHORT)res_index >= count) |
89 |
|
|
{ |
90 |
|
|
return GX_NOT_FOUND; |
91 |
|
|
} |
92 |
|
|
|
93 |
✓✓ |
19 |
if (count > 1) |
94 |
|
|
{ |
95 |
|
11 |
GX_BINRES_READ_ULONG(info -> gx_binres_read_offset, info -> gx_binres_root_address + info -> gx_binres_read_offset + sizeof(ULONG) * res_index); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
19 |
return GX_SUCCESS; |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
/**************************************************************************/ |
102 |
|
|
/* */ |
103 |
|
|
/* FUNCTION RELEASE */ |
104 |
|
|
/* */ |
105 |
|
|
/* _gx_binres_pixelmap_load PORTABLE C */ |
106 |
|
|
/* 6.3.0 */ |
107 |
|
|
/* AUTHOR */ |
108 |
|
|
/* */ |
109 |
|
|
/* Ting Zhu, Microsoft Corporation */ |
110 |
|
|
/* */ |
111 |
|
|
/* DESCRIPTION */ |
112 |
|
|
/* */ |
113 |
|
|
/* This service loads a pixelmap from a resource data memory. */ |
114 |
|
|
/* */ |
115 |
|
|
/* INPUT */ |
116 |
|
|
/* */ |
117 |
|
|
/* root_address Pointer to the binary data */ |
118 |
|
|
/* memory */ |
119 |
|
|
/* map_index Resource index of the pixelmap*/ |
120 |
|
|
/* to be loaded */ |
121 |
|
|
/* pixelmap Pointer to the returned */ |
122 |
|
|
/* pixelmap */ |
123 |
|
|
/* */ |
124 |
|
|
/* OUTPUT */ |
125 |
|
|
/* */ |
126 |
|
|
/* Status Completion status */ |
127 |
|
|
/* */ |
128 |
|
|
/* CALLS */ |
129 |
|
|
/* */ |
130 |
|
|
/* _gx_binres_standalone_resource_seek Locate the resource data */ |
131 |
|
|
/* _gx_binres_one_pixelmap_load Load one pixelmap */ |
132 |
|
|
/* */ |
133 |
|
|
/* CALLED BY */ |
134 |
|
|
/* */ |
135 |
|
|
/* Application Code */ |
136 |
|
|
/* */ |
137 |
|
|
/* RELEASE HISTORY */ |
138 |
|
|
/* */ |
139 |
|
|
/* DATE NAME DESCRIPTION */ |
140 |
|
|
/* */ |
141 |
|
|
/* 10-31-2023 Ting Zhu Initial Version 6.3.0 */ |
142 |
|
|
/* */ |
143 |
|
|
/**************************************************************************/ |
144 |
|
18 |
UINT _gx_binres_pixelmap_load(GX_UBYTE *root_address, UINT map_index, GX_PIXELMAP *pixelmap) |
145 |
|
|
{ |
146 |
|
18 |
UINT status = GX_SUCCESS; |
147 |
|
|
GX_BINRES_DATA_INFO info; |
148 |
|
|
|
149 |
|
|
/* file format |
150 |
|
|
+--------+ |
151 |
|
|
| | <-- represents one bytes |
152 |
|
|
+--------+ |
153 |
|
|
|
154 |
|
|
|+========+ |
155 |
|
|
| | <-- represents a variable number of bytes |
156 |
|
|
|+========+ |
157 |
|
|
|
158 |
|
|
|+--------+--------+--------+--------+ |
159 |
|
|
| magic number | resource count | |
160 |
|
|
|+--------+--------+--------+--------+ |
161 |
|
|
|+--------+--------+--------+--------+ |
162 |
|
|
| resource offset | |
163 |
|
|
|+--------+--------+--------+--------+ |
164 |
|
|
|+--------+--------+--------+--------+ |
165 |
|
|
| ... | |
166 |
|
|
|+--------+--------+--------+--------+ |
167 |
|
|
|+===================================+ |
168 |
|
|
| resource data | |
169 |
|
|
|+===================================+ |
170 |
|
|
*/ |
171 |
|
|
|
172 |
|
18 |
memset(&info, 0, sizeof(GX_BINRES_DATA_INFO)); |
173 |
|
|
|
174 |
|
18 |
info.gx_binres_root_address = (GX_UBYTE *)root_address; |
175 |
|
18 |
info.gx_binres_buffer = (GX_UBYTE *)pixelmap; |
176 |
|
18 |
info.gx_binres_buffer_size = sizeof(GX_PIXELMAP); |
177 |
|
|
|
178 |
|
18 |
status = _gx_binres_standalone_resource_seek(&info, map_index); |
179 |
|
|
|
180 |
✓✓ |
18 |
if (status == GX_SUCCESS) |
181 |
|
|
{ |
182 |
|
16 |
status = _gx_binres_one_pixelmap_load(&info, GX_NULL, GX_NULL); |
183 |
|
|
} |
184 |
|
|
|
185 |
|
18 |
return status; |
186 |
|
|
} |
187 |
|
|
|