| 481 | } |
| 482 | |
| 483 | bool SaveImagesFromTextureSet(ntc::IContext* context, ntc::ITextureSet* textureSet) |
| 484 | { |
| 485 | const ntc::TextureSetDesc& textureSetDesc = textureSet->GetDesc(); |
| 486 | fs::path const outputPath = g_options.saveImagesPath; |
| 487 | bool mipsDirCreated = false; |
| 488 | |
| 489 | int numTextures = textureSet->GetTextureCount(); |
| 490 | |
| 491 | std::mutex mutex; |
| 492 | bool anyErrors = false; |
| 493 | |
| 494 | const int mips = g_options.saveMips ? textureSetDesc.mips : 1; |
| 495 | |
| 496 | for (int textureIndex = 0; textureIndex < numTextures; ++textureIndex) |
| 497 | { |
| 498 | ntc::ITextureMetadata* texture = textureSet->GetTexture(textureIndex); |
| 499 | assert(texture); |
| 500 | |
| 501 | ntc::BlockCompressedFormat bcFormat = texture->GetBlockCompressedFormat(); |
| 502 | if (bcFormat != ntc::BlockCompressedFormat::None) |
| 503 | continue; |
| 504 | |
| 505 | if (!mipsDirCreated && g_options.saveMips && textureSetDesc.mips > 1) |
| 506 | { |
| 507 | fs::path mipsPath = outputPath / "mips"; |
| 508 | if (!fs::is_directory(mipsPath) && !fs::create_directories(mipsPath)) |
| 509 | { |
| 510 | fprintf(stderr, "Failed to create directory '%s'.\n", mipsPath.generic_string().c_str()); |
| 511 | return false; |
| 512 | } |
| 513 | mipsDirCreated = true; |
| 514 | } |
| 515 | |
| 516 | const char* textureName = texture->GetName(); |
| 517 | int firstChannel = 0; |
| 518 | int numChannels = 0; |
| 519 | texture->GetChannels(firstChannel, numChannels); |
| 520 | ntc::ChannelFormat channelFormat = texture->GetChannelFormat(); |
| 521 | ntc::ColorSpace rgbColorSpace = texture->GetRgbColorSpace(); |
| 522 | ntc::ColorSpace const alphaColorSpace = texture->GetAlphaColorSpace(); |
| 523 | |
| 524 | ImageContainer container = g_options.imageFormat; |
| 525 | |
| 526 | // Select the container from texture's channel format if it wasn't provided explicitly |
| 527 | if (container == ImageContainer::Auto) |
| 528 | { |
| 529 | if (channelFormat == ntc::ChannelFormat::FLOAT16 || channelFormat == ntc::ChannelFormat::FLOAT32) |
| 530 | container = ImageContainer::EXR; |
| 531 | else if (channelFormat == ntc::ChannelFormat::UNORM16) |
| 532 | container = ImageContainer::PNG16; |
| 533 | else |
| 534 | container = ImageContainer::PNG; |
| 535 | } |
| 536 | |
| 537 | // Pick the channel format suitable for our container |
| 538 | channelFormat = GetContainerChannelFormat(container); |
| 539 | |
| 540 | // EXR uses linear data, request that from NTC |
no test coverage detected