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

Clamp DDS dwMipMapCount to <1, dwMipMapCount> #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions BCnEnc.Net/Decoder/BcDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ private ColorRgba32[][] DecodeInternal(KtxFile file, bool allMipMaps, Cancellati
/// <returns>An array of decoded Rgba32 images.</returns>
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
Expand Down Expand Up @@ -1414,7 +1414,7 @@ private ColorRgbFloat[][] DecodeInternalHdr(KtxFile file, bool allMipMaps, Cance
/// <returns>An array of decoded Rgba32 images.</returns>
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
Expand Down
2 changes: 1 addition & 1 deletion BCnEnc.Net/Shared/ImageFiles/DdsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down