mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-22 05:10:29 +03:00
Refactor TransformationHelper into ImageScaleHelper, removing code that was no longer used
This commit is contained in:
parent
4a4da70baf
commit
68d228d019
@ -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" />
|
||||
|
29
NAPS2.Core/Scan/Images/ImageScaleHelper.cs
Normal file
29
NAPS2.Core/Scan/Images/ImageScaleHelper.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user