internal static void TestDDSMipSize(List <MipMap> newMips, ImageFormats.ImageEngineFormatDetails destFormatDetails, int width, int height, out double fixXScale, out double fixYScale, MipHandling mipChoice) { fixXScale = 0; fixYScale = 0; if (destFormatDetails.IsBlockCompressed && (!UsefulThings.General.IsPowerOfTwo(width) || !UsefulThings.General.IsPowerOfTwo(height))) { // If only keeping top mip, and that mip is divisible by 4, it's ok. if ((mipChoice == MipHandling.KeepTopOnly || mipChoice == MipHandling.KeepExisting) && DDSGeneral.CheckSize_DXT(width, height)) { return; } double newWidth = 0; double newHeight = 0; // Takes into account aspect ratio (a little bit) double aspect = width / height; if (aspect > 1) { newWidth = UsefulThings.General.RoundToNearestPowerOfTwo(width); var tempScale = newWidth / width; newHeight = UsefulThings.General.RoundToNearestPowerOfTwo((int)(height * tempScale)); } else { newHeight = UsefulThings.General.RoundToNearestPowerOfTwo(height); var tempScale = newHeight / height; newWidth = UsefulThings.General.RoundToNearestPowerOfTwo((int)(width * tempScale)); } // Little extra bit to allow integer cast from Double with the correct answer. Occasionally dimensions * scale would be 511.99999999998 instead of 512, so adding a little allows the integer cast to return correct value. fixXScale = 1d * newWidth / width + 0.001; fixYScale = 1d * newHeight / height + 0.001; newMips[0] = Resize(newMips[0], fixXScale, fixYScale); } }