From eb87085d0902592f396b4ebcab2b3e4825c5bdef Mon Sep 17 00:00:00 2001 From: Crauzer Date: Mon, 16 Jan 2023 23:57:50 +0100 Subject: [PATCH] fix dds dwMipMapCount --- BCnEnc.Net/Decoder/BcDecoder.cs | 4 ++-- BCnEnc.Net/Shared/ImageFiles/DdsFile.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/BCnEnc.Net/Decoder/BcDecoder.cs b/BCnEnc.Net/Decoder/BcDecoder.cs index 6c37ad9..eb2578b 100644 --- a/BCnEnc.Net/Decoder/BcDecoder.cs +++ b/BCnEnc.Net/Decoder/BcDecoder.cs @@ -1160,7 +1160,7 @@ private ColorRgba32[][] DecodeInternal(KtxFile file, bool allMipMaps, Cancellati /// An array of decoded Rgba32 images. private ColorRgba32[][] DecodeInternal(DdsFile file, bool allMipMaps, CancellationToken token) { - var mipMaps = allMipMaps ? file.header.dwMipMapCount : 1; + var mipMaps = allMipMaps ? Math.Max(1, file.header.dwMipMapCount) : 1; var colors = new ColorRgba32[mipMaps][]; var context = new OperationContext @@ -1414,7 +1414,7 @@ private ColorRgbFloat[][] DecodeInternalHdr(KtxFile file, bool allMipMaps, Cance /// An array of decoded Rgba32 images. private ColorRgbFloat[][] DecodeInternalHdr(DdsFile file, bool allMipMaps, CancellationToken token) { - var mipMaps = allMipMaps ? file.header.dwMipMapCount : 1; + var mipMaps = allMipMaps ? Math.Max(1, file.header.dwMipMapCount) : 1; var colors = new ColorRgbFloat[mipMaps][]; var context = new OperationContext diff --git a/BCnEnc.Net/Shared/ImageFiles/DdsFile.cs b/BCnEnc.Net/Shared/ImageFiles/DdsFile.cs index a1b3172..7ee3e9d 100644 --- a/BCnEnc.Net/Shared/ImageFiles/DdsFile.cs +++ b/BCnEnc.Net/Shared/ImageFiles/DdsFile.cs @@ -54,7 +54,7 @@ public static DdsFile Load(Stream s) output = new DdsFile(header); } - var mipMapCount = (header.dwCaps & HeaderCaps.DdscapsMipmap) != 0 ? header.dwMipMapCount : 1; + var mipMapCount = Math.Max(1, header.dwMipMapCount); var faceCount = (header.dwCaps2 & HeaderCaps2.Ddscaps2Cubemap) != 0 ? 6u : 1u; var width = header.dwWidth; var height = header.dwHeight;