Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Commit d68ca28

Browse files
JJL772craftablescience
authored andcommitted
cli: Recompute mip count when source VTF is resized
1 parent 9c2c27c commit d68ca28

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/cli/action_convert.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,19 @@ ActionConvert::init_from_file(const std::filesystem::path& src, VTFLib::CVTFFile
435435
// Convert immediately to the processing format, so we can match between src and dest
436436
srcFile->ConvertInPlace(newFormat);
437437

438-
// Use the mip count from the source file if the user hasn't specified it yet
439-
auto mipCount = m_opts->has(opts::mips) || m_opts->has(opts::nomips) ? m_mips : srcFile->GetMipmapCount();
440-
441438
// Determine buffer sizes
442439
const auto width = (m_width == -1) ? srcFile->GetWidth() : m_width;
443440
const auto height = (m_height == -1) ? srcFile->GetHeight() : m_height;
444441

442+
// If the width/height have been changed, we can't just pull the mip count from the source VTF
443+
const bool bNeedsNewMips = width != srcFile->GetWidth() || height != srcFile->GetHeight();
444+
const int nDefaultMips = CVTFFile::ComputeMipmapCount(width, height, 1);
445+
446+
// Use the mip count from the source file if the user hasn't specified it yet
447+
auto mipCount = m_opts->has(opts::mips) || m_opts->has(opts::nomips)
448+
? m_mips
449+
: (bNeedsNewMips ? nDefaultMips : srcFile->GetMipmapCount());
450+
445451
// Init image with the desired parameters and processing format
446452
file->Init(
447453
width, height, srcFile->GetFrameCount(), srcFile->GetFaceCount(), srcFile->GetDepth(), newFormat,

0 commit comments

Comments
 (0)