Skip to content

Commit

Permalink
+added automatic rescale to powers-of-2
Browse files Browse the repository at this point in the history
  • Loading branch information
bahstrike committed Sep 22, 2021
1 parent e3ac395 commit f80e441
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Matt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,35 @@ unsafe Material GenerateOutputMat()
if (bmp == null)
return null;


// powers-of-2 automatic rescale
int newWidth = (int)Math.Pow(2.0, Math.Ceiling(Math.Log((double)bmp.Width) / Math.Log(2.0)));
int newHeight = (int)Math.Pow(2.0, Math.Ceiling(Math.Log((double)bmp.Height) / Math.Log(2.0)));

if (newWidth != bmp.Width || newHeight != bmp.Height)
{
Bitmap newBmp = new Bitmap(newWidth, newHeight, PixelFormat.Format32bppArgb);
newBmp.SetResolution(bmp.HorizontalResolution, bmp.VerticalResolution);

using (Graphics gfx = Graphics.FromImage(newBmp))
{
gfx.CompositingMode = CompositingMode.SourceCopy;
gfx.InterpolationMode = InterpolationMode.NearestNeighbor;
gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;

using (ImageAttributes wrapMode = new ImageAttributes())
{
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
gfx.DrawImage(bmp, new Rectangle(0, 0, newWidth, newHeight), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, wrapMode);
}
}

bmp.Dispose();
bmp = newBmp;
}



Format fmt = CurrentFormat;
Colormap cmp = GetCurrentColormap();
int clrIndex = CurrentColorIndex;
Expand Down

0 comments on commit f80e441

Please sign in to comment.