| 457 | } |
| 458 | |
| 459 | sp<ImageSet> PCKLoader::loadShadow(Data &data, UString PckFilename, UString TabFilename, |
| 460 | unsigned shadedIdx) |
| 461 | { |
| 462 | auto imageSet = mksp<ImageSet>(); |
| 463 | auto tabFile = data.fs.open(TabFilename); |
| 464 | if (!tabFile) |
| 465 | { |
| 466 | LogWarning("Failed to open tab \"%s\"", TabFilename); |
| 467 | return nullptr; |
| 468 | } |
| 469 | auto pckFile = data.fs.open(PckFilename); |
| 470 | if (!pckFile) |
| 471 | { |
| 472 | LogWarning("Failed to open tab \"%s\"", TabFilename); |
| 473 | return nullptr; |
| 474 | } |
| 475 | imageSet->maxSize = {0, 0}; |
| 476 | |
| 477 | uint32_t offset = 0; |
| 478 | unsigned idx = 0; |
| 479 | while (tabFile.read(reinterpret_cast<char *>(&offset), sizeof(offset))) |
| 480 | { |
| 481 | // shadow TAB files store the offset directly |
| 482 | pckFile.seekg(offset, std::ios::beg); |
| 483 | if (!pckFile) |
| 484 | { |
| 485 | LogError("Failed to seek to offset %u", offset); |
| 486 | return nullptr; |
| 487 | } |
| 488 | auto img = loadShadowImage(pckFile, shadedIdx); |
| 489 | if (!img) |
| 490 | { |
| 491 | LogError("Failed to load image"); |
| 492 | return nullptr; |
| 493 | } |
| 494 | imageSet->images.push_back(img); |
| 495 | img->owningSet = imageSet; |
| 496 | img->calculateBounds(); |
| 497 | img->indexInSet = idx++; |
| 498 | if (img->size.x > imageSet->maxSize.x) |
| 499 | imageSet->maxSize.x = img->size.x; |
| 500 | if (img->size.y > imageSet->maxSize.y) |
| 501 | imageSet->maxSize.y = img->size.y; |
| 502 | } |
| 503 | |
| 504 | LogInfo("Loaded %u images", static_cast<unsigned>(imageSet->images.size())); |
| 505 | |
| 506 | return imageSet; |
| 507 | } |
| 508 | |
| 509 | }; // namespace OpenApoc |
nothing calls this directly
no test coverage detected