Skip to content

Commit 5172c82

Browse files
committed
Use better variable names.
1 parent 3fcd108 commit 5172c82

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

ReClass.NET/UI/DpiUtil.cs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -83,73 +83,74 @@ public static int ScaleIntY(int i)
8383
return (int)Math.Round(i * scaleY);
8484
}
8585

86-
public static Image ScaleImage(Image img)
86+
public static Image ScaleImage(Image sourceImage)
8787
{
88-
if (img == null)
88+
if (sourceImage == null)
8989
{
9090
return null;
9191
}
9292

93-
int w = img.Width;
94-
int h = img.Height;
95-
int sw = ScaleIntX(w);
96-
int sh = ScaleIntY(h);
93+
var width = sourceImage.Width;
94+
var height = sourceImage.Height;
95+
var scaledWidth = ScaleIntX(width);
96+
var scaledHeight = ScaleIntY(height);
9797

98-
if (w == sw && h == sh)
98+
if (width == scaledWidth && height == scaledHeight)
9999
{
100-
return img;
100+
return sourceImage;
101101
}
102102

103-
return ScaleImage(img, sw, sh);
103+
return ScaleImage(sourceImage, scaledWidth, scaledHeight);
104104
}
105105

106-
private static Image ScaleImage(Image img, int w, int h)
106+
private static Image ScaleImage(Image sourceImage, int width, int height)
107107
{
108-
Contract.Requires(img != null);
109-
Contract.Requires(w >= 0);
110-
Contract.Requires(h >= 0);
108+
Contract.Requires(sourceImage != null);
109+
Contract.Requires(width >= 0);
110+
Contract.Requires(height >= 0);
111111

112-
var bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
113-
using var g = Graphics.FromImage(bmp);
112+
var scaledImage = new Bitmap(width, height, PixelFormat.Format32bppArgb);
113+
114+
using var g = Graphics.FromImage(scaledImage);
114115
g.Clear(Color.Transparent);
115116

116117
g.SmoothingMode = SmoothingMode.HighQuality;
117118
g.CompositingQuality = CompositingQuality.HighQuality;
118119

119-
var wSrc = img.Width;
120-
var hSrc = img.Height;
120+
var sourceWidth = sourceImage.Width;
121+
var sourceHeight = sourceImage.Height;
121122

122-
var im = InterpolationMode.HighQualityBicubic;
123-
if (wSrc > 0 && hSrc > 0)
123+
var interpolationMode = InterpolationMode.HighQualityBicubic;
124+
if (sourceWidth > 0 && sourceHeight > 0)
124125
{
125-
if ((w % wSrc) == 0 && (h % hSrc) == 0)
126+
if ((width % sourceWidth) == 0 && (height % sourceHeight) == 0)
126127
{
127-
im = InterpolationMode.NearestNeighbor;
128+
interpolationMode = InterpolationMode.NearestNeighbor;
128129
}
129130
}
130131

131-
g.InterpolationMode = im;
132+
g.InterpolationMode = interpolationMode;
132133

133-
var rSource = new RectangleF(0.0f, 0.0f, wSrc, hSrc);
134-
var rDest = new RectangleF(0.0f, 0.0f, w, h);
135-
AdjustScaleRects(ref rSource, ref rDest);
134+
var srcRect = new RectangleF(0.0f, 0.0f, sourceWidth, sourceHeight);
135+
var destRect = new RectangleF(0.0f, 0.0f, width, height);
136+
AdjustScaleRects(ref srcRect, ref destRect);
136137

137-
g.DrawImage(img, rDest, rSource, GraphicsUnit.Pixel);
138+
g.DrawImage(sourceImage, destRect, srcRect, GraphicsUnit.Pixel);
138139

139-
return bmp;
140+
return scaledImage;
140141
}
141142

142-
private static void AdjustScaleRects(ref RectangleF rSource, ref RectangleF rDest)
143+
private static void AdjustScaleRects(ref RectangleF srcRect, ref RectangleF destRect)
143144
{
144-
if (rDest.Width > rSource.Width)
145-
rSource.X = rSource.X - 0.5f;
146-
if (rDest.Height > rSource.Height)
147-
rSource.Y = rSource.Y - 0.5f;
148-
149-
if (rDest.Width < rSource.Width)
150-
rSource.X = rSource.X + 0.5f;
151-
if (rDest.Height < rSource.Height)
152-
rSource.Y = rSource.Y + 0.5f;
145+
if (destRect.Width > srcRect.Width)
146+
srcRect.X -= 0.5f;
147+
if (destRect.Height > srcRect.Height)
148+
srcRect.Y -= 0.5f;
149+
150+
if (destRect.Width < srcRect.Width)
151+
srcRect.X += 0.5f;
152+
if (destRect.Height < srcRect.Height)
153+
srcRect.Y += 0.5f;
153154
}
154155
}
155156
}

0 commit comments

Comments
 (0)