nickbabcock / Pfim

.NET Standard targa (.tga) and direct draw surface (.dds) image decoder
https://nickbabcock.github.io/Pfim/
MIT License
109 stars 18 forks source link

Pfim.CompressedDds.InMemoryDecode #104

Closed cmkushnir closed 2 years ago

cmkushnir commented 2 years ago

Found that using a MemoryStream to decode a DXT5 dds with 0 mipmaps results in dds.Data[] of all 0's due to: for (int imageIndex = 0; imageIndex < Header.MipMapCount && pixelsLeft > 0; imageIndex++) in Pfim.CompressedDds.InMemoryDecode.

Work around: In Pfim.CompressedDds.DataDecode comment out:

if (stream is MemoryStream s && s.TryGetBuffer(out var arr)) {
    return InMemoryDecode(arr.Array, (int)s.Position);
}

Not sure if Pfim.CompressedDds.Decompress, which also calls InMemoryDecode, still works.

nickbabcock commented 2 years ago

I'm deeply grateful for the bug report. This has been fixed and I'll release a patch right now.