From 1093ca17ef1a39d3741969677ff80ee5ba695a14 Mon Sep 17 00:00:00 2001 From: Richard Geldreich Date: Wed, 1 Jul 2026 13:20:19 -0400 Subject: [PATCH] modifications for v2.5 --- encoder/3rdparty/tinydds.h | 54 ++++++++++++++++++------- encoder_lib/encoder_lib.vcxproj | 23 +++++++++-- encoder_lib/encoder_lib.vcxproj.filters | 45 +++++++++++++++++++++ 3 files changed, 103 insertions(+), 19 deletions(-) diff --git a/encoder/3rdparty/tinydds.h b/encoder/3rdparty/tinydds.h index 6b4712a..829c56b 100644 --- a/encoder/3rdparty/tinydds.h +++ b/encoder/3rdparty/tinydds.h @@ -1368,27 +1368,51 @@ bool TinyDDS_ReadHeader(TinyDDS_ContextHandle handle) { return false; } - // correct for dodgy mipmap levels counts + // rg: The original tinydds mipmap-count "correction" below is WRONG and is + // disabled. For COMPRESSED formats it stopped counting at the 4x4 block size + // (w <= 4 || h <= 4) and truncated mipMapCount there, which drops the perfectly + // valid sub-block mip levels (e.g. 2x2 and 1x1) -- those levels are legal and are + // simply stored padded to a single 4x4 block. ANY DDS file, block-compressed or + // uncompressed, can carry a full mip chain down to 1x1. + // + // Original (incorrect) code: + // + // if(ctx->header.mipMapCount > 1) { + // uint32_t w = ctx->header.width; + // uint32_t h = ctx->header.height; + // + // for(uint32_t i = 0; i < ctx->header.mipMapCount;++i) { + // if (TinyDDS_IsCompressed(ctx->format)) { + // if (w <= 4 || h <= 4) { + // ctx->header.mipMapCount = i + 1; + // break; + // } + // } else if (w <= 1 || h <= 1) { + // ctx->header.mipMapCount = i + 1; + // break; + // } + // + // w = w / 2; + // h = h / 2; + // } + // } + // + // Replacement: count the true maximum number of mip levels for these dimensions + // (halving each axis down to 1x1, for every format) and clamp the header's count + // to it ONLY if the file claims MORE levels than are dimensionally possible. if(ctx->header.mipMapCount > 1) { uint32_t w = ctx->header.width; uint32_t h = ctx->header.height; - for(uint32_t i = 0; i < ctx->header.mipMapCount;++i) { - if (TinyDDS_IsCompressed(ctx->format)) { - if (w <= 4 || h <= 4) { - ctx->header.mipMapCount = i + 1; - break; - } - } else if (w <= 1 || h <= 1) { - ctx->header.mipMapCount = i + 1; - break; - } - - - w = w / 2; - h = h / 2; + uint32_t maxMipMapCount = 1; + while ((w > 1) || (h > 1)) { + w = (w > 1) ? (w >> 1) : 1; + h = (h > 1) ? (h >> 1) : 1; + maxMipMapCount++; } + if (ctx->header.mipMapCount > maxMipMapCount) + ctx->header.mipMapCount = maxMipMapCount; } if (TinyDDS_IsCompressed(ctx->format)) { diff --git a/encoder_lib/encoder_lib.vcxproj b/encoder_lib/encoder_lib.vcxproj index 9d4c1b9..19a67ec 100644 --- a/encoder_lib/encoder_lib.vcxproj +++ b/encoder_lib/encoder_lib.vcxproj @@ -32,12 +32,16 @@ + + + + @@ -49,6 +53,8 @@ + + @@ -62,9 +68,13 @@ + + + + @@ -82,6 +92,8 @@ + + @@ -99,6 +111,7 @@ + @@ -111,6 +124,8 @@ + + 17.0 @@ -228,7 +243,7 @@ false - _DEBUG;_LIB;%(PreprocessorDefinitions);BASISU_SUPPORT_SSE=1;BASISU_SUPPORT_OPENCL=1; + _DEBUG;_LIB;%(PreprocessorDefinitions);BASISU_SUPPORT_SSE=1;BASISU_SUPPORT_OPENCL=1;_HAS_EXCEPTIONS=0 true NotUsing pch.h @@ -246,7 +261,7 @@ false - _DEBUG;_LIB;%(PreprocessorDefinitions);BASISU_SUPPORT_SSE=0;BASISU_SUPPORT_OPENCL=1; + _DEBUG;_LIB;%(PreprocessorDefinitions);BASISU_SUPPORT_SSE=0;BASISU_SUPPORT_OPENCL=1;_HAS_EXCEPTIONS=0 true NotUsing pch.h @@ -266,7 +281,7 @@ true true false - NDEBUG;_LIB;%(PreprocessorDefinitions);BASISU_SUPPORT_SSE=1;BASISU_SUPPORT_OPENCL=1; + NDEBUG;_LIB;%(PreprocessorDefinitions);BASISU_SUPPORT_SSE=1;BASISU_SUPPORT_OPENCL=1;_HAS_EXCEPTIONS=0 true NotUsing pch.h @@ -294,7 +309,7 @@ true true false - NDEBUG;_LIB;%(PreprocessorDefinitions);BASISU_SUPPORT_SSE=0;BASISU_SUPPORT_OPENCL=1; + NDEBUG;_LIB;%(PreprocessorDefinitions);BASISU_SUPPORT_SSE=0;BASISU_SUPPORT_OPENCL=1;_HAS_EXCEPTIONS=0 true NotUsing pch.h diff --git a/encoder_lib/encoder_lib.vcxproj.filters b/encoder_lib/encoder_lib.vcxproj.filters index 8d0ad48..fc2a011 100644 --- a/encoder_lib/encoder_lib.vcxproj.filters +++ b/encoder_lib/encoder_lib.vcxproj.filters @@ -45,6 +45,12 @@ Source Files\encoder + + Source Files\encoder + + + Source Files\encoder + Source Files\encoder @@ -78,6 +84,12 @@ Source Files\encoder + + Source Files\encoder + + + Source Files\encoder + Source Files\encoder @@ -102,9 +114,15 @@ Source Files\encoder + + Source Files\encoder + Source Files\encoder + + Source Files\encoder + @@ -158,6 +176,12 @@ Source Files\encoder + + Source Files\encoder + + + Source Files\encoder + Source Files\encoder @@ -206,6 +230,12 @@ Source Files\encoder + + Source Files\encoder + + + Source Files\encoder + Source Files\encoder @@ -236,9 +266,18 @@ Source Files\encoder + + Source Files\encoder + Source Files\transcoder + + Source Files\encoder + + + Source Files\transcoder + @@ -271,5 +310,11 @@ Source Files\transcoder + + Source Files\transcoder + + + Source Files\transcoder + \ No newline at end of file