Skip to content

Commit 6b98ce5

Browse files
vtfpp: change default compression quality so dxt1-5, ati1n, ati2n are max quality by default
1 parent bde5b7a commit 6b98ce5

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

include/vtfpp/ImageConversion.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ concept PixelType =
324324

325325
namespace ImageConversion {
326326

327-
constexpr float DEFAULT_COMPRESSED_QUALITY = 0.105f;
327+
// Negative means use default quality
328+
// BC7, BC6H: 0.1
329+
// Everything else: 1.0
330+
constexpr float DEFAULT_COMPRESSED_QUALITY = -1.f;
328331

329332
/// Converts an image from one format to another.
330333
[[nodiscard]] std::vector<std::byte> convertImageDataToFormat(std::span<const std::byte> imageData, ImageFormat oldFormat, ImageFormat newFormat, uint16_t width, uint16_t height, float quality = DEFAULT_COMPRESSED_QUALITY);

src/vtfpp/ImageConversion.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,14 @@ namespace {
317317
destTexture.pData = reinterpret_cast<CMP_BYTE*>(destData.data());
318318

319319
CMP_CompressOptions options{};
320-
options.dwSize = sizeof(options);
321-
options.fquality = std::clamp(quality, 0.f, 1.f);
320+
options.dwSize = sizeof(options);
321+
if (quality >= 0.f) {
322+
options.fquality = std::min(quality, 1.f);
323+
} else if (oldFormat == ImageFormat::BC7 || newFormat == ImageFormat::BC7 || oldFormat == ImageFormat::BC6H || newFormat == ImageFormat::BC6H) {
324+
options.fquality = 0.1f;
325+
} else {
326+
options.fquality = 1.f;
327+
}
322328
options.bDXT1UseAlpha = oldFormat == ImageFormat::DXT1_ONE_BIT_ALPHA || newFormat == ImageFormat::DXT1_ONE_BIT_ALPHA;
323329
if (options.bDXT1UseAlpha) {
324330
options.nAlphaThreshold = 128;

0 commit comments

Comments
 (0)