예제 #1
0
        public bool Start(ICollection <ScannedImage> images)
        {
            ProgressTitle = MiscResources.AutoDeskewProgress;
            Status        = new OperationStatus
            {
                StatusText  = MiscResources.AutoDeskewing,
                MaxProgress = images.Count
            };
            cancel = false;

            thread = threadFactory.StartThread(() =>
            {
                var memoryLimitingSem = new Semaphore(4, 4);
                Pipeline.For(images).StepParallel(img =>
                {
                    if (cancel)
                    {
                        return(null);
                    }
                    memoryLimitingSem.WaitOne();
                    Bitmap bitmap = scannedImageRenderer.Render(img);
                    try
                    {
                        if (cancel)
                        {
                            return(null);
                        }
                        var transform = RotationTransform.Auto(bitmap);
                        if (cancel)
                        {
                            return(null);
                        }
                        bitmap = transform.Perform(bitmap);
                        img.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap));

                        // The final pipeline step is pretty fast, so updating progress here is more accurate
                        lock (this)
                        {
                            Status.CurrentProgress += 1;
                        }
                        InvokeStatusChanged();

                        return(Tuple.Create(img, transform));
                    }
                    finally
                    {
                        bitmap.Dispose();
                        memoryLimitingSem.Release();
                    }
                }).Step((img, transform) =>
                {
                    img.AddTransform(transform);
                    return(img);
                }).Run();
                Status.Success = !cancel;
                InvokeFinished();
            });

            return(true);
        }
예제 #2
0
 public async Task <Bitmap> RenderThumbnail(ScannedImage.Snapshot snapshot, int size)
 {
     using (var bitmap = await scannedImageRenderer.Render(snapshot, snapshot.TransformList.Count == 0 ? 0 : size *OVERSAMPLE))
     {
         return(RenderThumbnail(bitmap, size));
     }
 }
예제 #3
0
        public bool Start(ICollection <ScannedImage> images)
        {
            ProgressTitle = MiscResources.AutoDeskewProgress;
            Status        = new OperationStatus
            {
                StatusText  = MiscResources.AutoDeskewing,
                MaxProgress = images.Count
            };

            RunAsync(() =>
            {
                var memoryLimitingSem = new Semaphore(4, 4);
                Pipeline.For(images).StepParallel(img =>
                {
                    if (CancelToken.IsCancellationRequested)
                    {
                        return(null);
                    }
                    memoryLimitingSem.WaitOne();
                    var bitmap = scannedImageRenderer.Render(img).Result;
                    try
                    {
                        if (CancelToken.IsCancellationRequested)
                        {
                            return(null);
                        }
                        var transform = RotationTransform.Auto(bitmap);
                        if (CancelToken.IsCancellationRequested)
                        {
                            return(null);
                        }
                        bitmap        = transform.Perform(bitmap);
                        var thumbnail = thumbnailRenderer.RenderThumbnail(bitmap);
                        lock (img)
                        {
                            img.AddTransform(transform);
                            img.SetThumbnail(thumbnail);
                        }

                        // The final pipeline step is pretty fast, so updating progress here is more accurate
                        lock (this)
                        {
                            Status.CurrentProgress += 1;
                        }
                        InvokeStatusChanged();

                        return(Tuple.Create(img, transform));
                    }
                    finally
                    {
                        bitmap.Dispose();
                        memoryLimitingSem.Release();
                    }
                }).Run();
                return(!CancelToken.IsCancellationRequested);
            });

            return(true);
        }
예제 #4
0
        public bool Start(ICollection <ScannedImage> images)
        {
            ProgressTitle = MiscResources.AutoDeskewProgress;
            Status        = new OperationStatus
            {
                StatusText  = MiscResources.AutoDeskewing,
                MaxProgress = images.Count
            };
            cancel = false;

            thread = threadFactory.StartThread(() =>
            {
                Pipeline.For(images).StepParallel(img =>
                {
                    if (cancel)
                    {
                        return(null);
                    }
                    Bitmap bitmap = scannedImageRenderer.Render(img);
                    try
                    {
                        if (cancel)
                        {
                            return(null);
                        }
                        var transform = RotationTransform.Auto(bitmap);
                        if (cancel)
                        {
                            return(null);
                        }
                        bitmap = transform.Perform(bitmap);
                        img.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap));
                        return(Tuple.Create(img, transform));
                    }
                    finally
                    {
                        bitmap.Dispose();
                    }
                }).Step((img, transform) =>
                {
                    img.AddTransform(transform);
                    Status.CurrentProgress++;
                    InvokeStatusChanged();
                    return(img);
                }).Run();
                Status.Success = !cancel;
                InvokeFinished();
            });

            return(true);
        }
예제 #5
0
 public Bitmap RenderThumbnail(ScannedImage scannedImage)
 {
     return(RenderThumbnail(scannedImageRenderer.Render(scannedImage), userConfigManager.Config.ThumbnailSize));
 }