mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-21 04:37:47 +03:00
cbcfd2de82
This should be okay in general and allows us to inject an IPdfRenderer for rendering PDF-based images.
64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
using NAPS2.Images.Gdi;
|
|
|
|
namespace NAPS2.Images;
|
|
|
|
public class DeskewOperation : OperationBase
|
|
{
|
|
private readonly ImageContext _imageContext;
|
|
|
|
public DeskewOperation(ImageContext imageContext)
|
|
{
|
|
_imageContext = imageContext;
|
|
|
|
AllowCancel = true;
|
|
AllowBackground = true;
|
|
}
|
|
|
|
public bool Start(ICollection<UiImage> images, DeskewParams deskewParams)
|
|
{
|
|
ProgressTitle = MiscResources.AutoDeskewProgress;
|
|
Status = new OperationStatus
|
|
{
|
|
StatusText = MiscResources.AutoDeskewing,
|
|
MaxProgress = images.Count
|
|
};
|
|
|
|
RunAsync(async () =>
|
|
{
|
|
return await Pipeline.For(images, CancelToken).RunParallel(async img =>
|
|
{
|
|
using var processedImage = img.GetClonedImage();
|
|
var image = _imageContext.Render(processedImage);
|
|
try
|
|
{
|
|
CancelToken.ThrowIfCancellationRequested();
|
|
var transform = Deskewer.GetDeskewTransform(image);
|
|
CancelToken.ThrowIfCancellationRequested();
|
|
image = _imageContext.PerformTransform(image, transform);
|
|
var thumbnail = deskewParams.ThumbnailSize.HasValue
|
|
? _imageContext.PerformTransform(image, new ThumbnailTransform(deskewParams.ThumbnailSize.Value))
|
|
: null;
|
|
lock (img)
|
|
{
|
|
img.AddTransform(transform);
|
|
if (thumbnail != null)
|
|
{
|
|
img.SetThumbnail(thumbnail);
|
|
}
|
|
}
|
|
lock (this)
|
|
{
|
|
Status.CurrentProgress += 1;
|
|
}
|
|
InvokeStatusChanged();
|
|
}
|
|
finally
|
|
{
|
|
image.Dispose();
|
|
}
|
|
});
|
|
});
|
|
|
|
return true;
|
|
}
|
|
} |