From 6083d58499631c094e61138d28b9ff4a52d2e2b7 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 3 May 2013 23:59:08 +0200 Subject: [PATCH] Only resize bmp if necessary --- Vocaluxe/Lib/Draw/COpenGL.cs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 625558ae..4cfb9866 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -708,30 +708,33 @@ namespace Vocaluxe.Lib.Draw int h = Math.Min(bmp.Height, maxSize); texture.W2 = MathHelper.NextPowerOfTwo(w); texture.H2 = MathHelper.NextPowerOfTwo(h); + + Bitmap bmp2 = null; try { - using (Bitmap bmp2 = new Bitmap(texture.W2, texture.H2)) + if (bmp.Width != w || bmp.Height != h) { + //Create a new Bitmap with the new sizes + bmp2 = new Bitmap(w, h); + //Scale the texture using (Graphics g = Graphics.FromImage(bmp2)) { g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.SmoothingMode = SmoothingMode.HighQuality; g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); } - - BitmapData bmpData = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - - GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, texture.W2, texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); - - GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, bmpData.Width, bmpData.Height, PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0); - - bmp2.UnlockBits(bmpData); + bmp = bmp2; } + + BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, texture.W2, texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); + GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, bmpData.Width, bmpData.Height, PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0); + bmp.UnlockBits(bmpData); } - catch + finally { - CLog.LogError(w + " " + h + " " + texture.W2 + " " + texture.H2); - throw; + if (bmp2 != null) + bmp2.Dispose(); } GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureParameterName.ClampToEdge);