Refactor TransformationHelper into ImageScaleHelper, removing code that was no longer used

This commit is contained in:
Ben Olden-Cooligan 2015-08-03 06:25:44 -04:00
parent 4a4da70baf
commit 68d228d019
5 changed files with 32 additions and 77 deletions

View File

@ -193,7 +193,7 @@
<Compile Include="Scan\Images\ScannedImageHelper.cs" />
<Compile Include="Scan\Images\ScannedImageList.cs" />
<Compile Include="Scan\Images\ThumbnailHelper.cs" />
<Compile Include="Scan\Images\TransformationHelper.cs" />
<Compile Include="Scan\Images\ImageScaleHelper.cs" />
<Compile Include="Scan\IScanDriver.cs" />
<Compile Include="Scan\IScanPerformer.cs" />
<Compile Include="Scan\IScanReceiver.cs" />

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
namespace NAPS2.Scan.Images
{
internal static class ImageScaleHelper
{
public static Bitmap ScaleImage(Image original, double scaleFactor)
{
double realWidth = original.Width / scaleFactor;
double realHeight = original.Height / scaleFactor;
double horizontalRes = original.HorizontalResolution / scaleFactor;
double verticalRes = original.VerticalResolution / scaleFactor;
var result = new Bitmap((int)realWidth, (int)realHeight);
using (Graphics g = Graphics.FromImage(result))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(original, 0, 0, (int)realWidth, (int)realHeight);
result.SetResolution((float)horizontalRes, (float)verticalRes);
return result;
}
}
}
}

View File

@ -1,74 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
namespace NAPS2.Scan.Images
{
internal static class TransformationHelper
{
public static RotateFlipType CombineRotation(RotateFlipType currentTransform, RotateFlipType nextTransform)
{
if ((int)currentTransform >= 4)
{
throw new ArgumentException("The currentTransform argument must not include a flip.");
}
if ((int)nextTransform >= 4)
{
throw new ArgumentException("The nextTransform argument must not include a flip.");
}
return FromRotation(GetRotation(currentTransform) + GetRotation(nextTransform));
}
public static int GetRotation(RotateFlipType rotateFlipType)
{
switch (rotateFlipType)
{
case RotateFlipType.RotateNoneFlipNone:
return 0;
case RotateFlipType.Rotate90FlipNone:
return 1;
case RotateFlipType.Rotate180FlipNone:
return 2;
case RotateFlipType.Rotate270FlipNone:
return 3;
}
throw new ArgumentException();
}
public static RotateFlipType FromRotation(int rotation)
{
switch (rotation % 4)
{
case 0:
return RotateFlipType.RotateNoneFlipNone;
case 1:
return RotateFlipType.Rotate90FlipNone;
case 2:
return RotateFlipType.Rotate180FlipNone;
case 3:
return RotateFlipType.Rotate270FlipNone;
}
throw new ArgumentException();
}
public static Bitmap ScaleImage(Image original, double scaleFactor)
{
double realWidth = original.Width / scaleFactor;
double realHeight = original.Height / scaleFactor;
double horizontalRes = original.HorizontalResolution / scaleFactor;
double verticalRes = original.VerticalResolution / scaleFactor;
var result = new Bitmap((int)realWidth, (int)realHeight);
using (Graphics g = Graphics.FromImage(result))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(original, 0, 0, (int)realWidth, (int)realHeight);
result.SetResolution((float)horizontalRes, (float)verticalRes);
return result;
}
}
}
}

View File

@ -103,7 +103,7 @@ namespace NAPS2.Scan.Twain
scaleFactor = ScanSettings.AfterScanScale.ToIntScaleFactor();
}
using (var result = TransformationHelper.ScaleImage(output, scaleFactor))
using (var result = ImageScaleHelper.ScaleImage(output, scaleFactor))
{
var bitDepth = output.PixelFormat == PixelFormat.Format1bppIndexed
? ScanBitDepth.BlackWhite

View File

@ -117,7 +117,7 @@ namespace NAPS2.Scan.Wia
scaleFactor = ScanSettings.AfterScanScale.ToIntScaleFactor();
}
using (var result = TransformationHelper.ScaleImage(output, scaleFactor))
using (var result = ImageScaleHelper.ScaleImage(output, scaleFactor))
{
ScanBitDepth bitDepth = ScanSettings.UseNativeUI ? ScanBitDepth.C24Bit : ScanSettings.BitDepth;
return scannedImageFactory.Create(result, bitDepth, ScanSettings.MaxQuality);