| 224 | } |
| 225 | |
| 226 | std::vector<std::unique_ptr<ImageTable::RequiredImage>> ImageTable::LoadImageArchiveImages( |
| 227 | IReadObjectContext* context, const std::string& path, const std::vector<int32_t>& range) |
| 228 | { |
| 229 | std::vector<std::unique_ptr<RequiredImage>> result; |
| 230 | auto gxRaw = context->GetData(path); |
| 231 | std::optional<Gx> gxData = GfxLoadGx(gxRaw); |
| 232 | if (gxData.has_value()) |
| 233 | { |
| 234 | // Fix entry data offsets |
| 235 | for (uint32_t i = 0; i < gxData->header.numEntries; i++) |
| 236 | { |
| 237 | if (gxData->elements[i].offset == nullptr) |
| 238 | { |
| 239 | gxData->elements[i].offset = gxData->data.get(); |
| 240 | } |
| 241 | else |
| 242 | { |
| 243 | gxData->elements[i].offset += reinterpret_cast<uintptr_t>(gxData->data.get()); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | if (!range.empty()) |
| 248 | { |
| 249 | size_t placeHoldersAdded = 0; |
| 250 | for (auto i : range) |
| 251 | { |
| 252 | if (i >= 0 && (i < static_cast<int32_t>(gxData->header.numEntries))) |
| 253 | { |
| 254 | result.push_back(std::make_unique<RequiredImage>(gxData->elements[i])); |
| 255 | } |
| 256 | else |
| 257 | { |
| 258 | result.push_back(std::make_unique<RequiredImage>()); |
| 259 | placeHoldersAdded++; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | // Log place holder information |
| 264 | if (placeHoldersAdded > 0) |
| 265 | { |
| 266 | std::string msg = "Adding " + std::to_string(placeHoldersAdded) + " placeholders"; |
| 267 | context->LogWarning(ObjectError::invalidProperty, msg.c_str()); |
| 268 | } |
| 269 | } |
| 270 | else |
| 271 | { |
| 272 | for (int i = 0; i < static_cast<int32_t>(gxData->header.numEntries); i++) |
| 273 | result.push_back(std::make_unique<RequiredImage>(gxData->elements[i])); |
| 274 | } |
| 275 | } |
| 276 | else |
| 277 | { |
| 278 | auto msg = String::stdFormat("Unable to load Gx '%s'", path.c_str()); |
| 279 | context->LogWarning(ObjectError::badImageTable, msg.c_str()); |
| 280 | for (size_t i = 0; i < range.size(); i++) |
| 281 | { |
| 282 | result.push_back(std::make_unique<RequiredImage>()); |
| 283 | } |