Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Recompute mip count when source VTF is resized #56

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/cli/action_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,19 @@ ActionConvert::init_from_file(const std::filesystem::path& src, VTFLib::CVTFFile
// Convert immediately to the processing format, so we can match between src and dest
srcFile->ConvertInPlace(newFormat);

// Use the mip count from the source file if the user hasn't specified it yet
auto mipCount = m_opts->has(opts::mips) || m_opts->has(opts::nomips) ? m_mips : srcFile->GetMipmapCount();

// Determine buffer sizes
const auto width = (m_width == -1) ? srcFile->GetWidth() : m_width;
const auto height = (m_height == -1) ? srcFile->GetHeight() : m_height;

// If the width/height have been changed, we can't just pull the mip count from the source VTF
const bool bNeedsNewMips = width != srcFile->GetWidth() || height != srcFile->GetHeight();
const int nDefaultMips = CVTFFile::ComputeMipmapCount(width, height, 1);

// Use the mip count from the source file if the user hasn't specified it yet
auto mipCount = m_opts->has(opts::mips) || m_opts->has(opts::nomips)
? m_mips
: (bNeedsNewMips ? nDefaultMips : srcFile->GetMipmapCount());

// Init image with the desired parameters and processing format
file->Init(
width, height, srcFile->GetFrameCount(), srcFile->GetFaceCount(), srcFile->GetDepth(), newFormat,
Expand Down
Loading