internal static List<MipMap> LoadWithCodecs(Stream stream, int decodeWidth, int decodeHeight, double scale, bool isDDS)
{
if (isDDS && !ImageEngine.WindowsWICCodecsAvailable)
return null;
bool alternateDecodeDimensions = decodeHeight != 0 || decodeWidth != 0 || scale != 0;
int alternateWidth = decodeWidth;
int alternateHeight = decodeHeight;
List<MipMap> mipmaps = new List<MipMap>();
if (isDDS)
{
// KFreon: Attempt to load any mipmaps
stream.Seek(0, SeekOrigin.Begin);
var decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnDemand);
// Setup alternateDimensions if required
if (scale != 0)
{
alternateHeight = (int)(decoder.Frames[0].Height * scale);
alternateWidth = (int)(decoder.Frames[0].Width * scale);
}
foreach (var mipmap in decoder.Frames)
{
// KFreon: Skip mipmaps that are too big if asked to load a smaller image
if (alternateDecodeDimensions)
{
if (mipmap.Width > alternateWidth || mipmap.Height > alternateHeight)
continue;
}
mipmaps.Add(new MipMap(mipmap.GetPixelsAsBGRA32(), mipmap.PixelWidth, mipmap.PixelHeight));
}
if (mipmaps.Count == 0)
{
// KFreon: Image has no mips, so resize largest
var frame = decoder.Frames[0];
var mip = new MipMap(frame.GetPixelsAsBGRA32(), frame.PixelWidth, frame.PixelHeight);
mip = ImageEngine.Resize(mip, scale);
mipmaps.Add(mip);
}
}
else
{
// KFreon: No Mipmaps
BitmapImage bmp = AttemptUsingWindowsCodecs(stream, alternateWidth, alternateHeight);
if (bmp == null)
return null;
bmp.Freeze();
mipmaps.Add(new MipMap(bmp.GetPixelsAsBGRA32(), bmp.PixelWidth, bmp.PixelHeight));
}
return mipmaps;
}