예제 #1
0
        public IEnumerable <int> AltDeinterleave(IEnumerable <int> selectedIndices)
        {
            lock (this)
            {
                // Duplicate the list
                int count  = Images.Count;
                int split  = (count + 1) / 2;
                var images = Images.ToList();

                // Rebuild the image list, even-indexed images first (odd-indexed images in reverse order)
                Images.Clear();
                for (int i = 0; i < split; ++i)
                {
                    Images.Add(images[i * 2]);
                }

                for (int i = count - split - 1; i >= 0; --i)
                {
                    Images.Add(images[i * 2 + 1]);
                }

                RecoveryImage.Refresh(Images);

                // Clear the selection (may be changed in the future to maintain it, but not necessary)
                return(Enumerable.Empty <int>());
            }
        }
예제 #2
0
        public IEnumerable <int> Deinterleave(IEnumerable <int> selection)
        {
            lock (this)
            {
                // Duplicate the list
                var count  = Images.Count;
                var split  = (count + 1) / 2;
                var images = Images.ToList();

                // Rebuild the image list, even-indexed images first
                Images.Clear();
                for (var i = 0; i < split; ++i)
                {
                    Images.Add(images[i * 2]);
                }

                for (var i = 0; i < (count - split); ++i)
                {
                    Images.Add(images[i * 2 + 1]);
                }

                RecoveryImage.Refresh(Images);

                // Clear the selection (may be changed in the future to maintain it, but not necessary)
                return(Enumerable.Empty <int>());
            }
        }
예제 #3
0
        public ScannedImage(Bitmap img, ScanBitDepth bitDepth, bool highQuality, int quality)
        {
            var tempFilePath = ScannedImageHelper.SaveSmallestBitmap(img, bitDepth, highQuality, quality, out var fileFormat);

            transformList = new List <Transform>();
            recoveryImage = RecoveryImage.CreateNew(fileFormat, bitDepth, highQuality, transformList);

            File.Move(tempFilePath, recoveryImage.FilePath);

            recoveryImage.Save();
        }
예제 #4
0
 public void Delete(IEnumerable <int> selection)
 {
     lock (this)
     {
         using (RecoveryImage.DeferSave())
         {
             foreach (ScannedImage img in Images.ElementsAt(selection))
             {
                 img.Dispose();
             }
             Images.RemoveAll(selection);
         }
     }
 }
예제 #5
0
        private ScannedImage(string pdfPath, bool copy)
        {
            transformList = new List <Transform>();
            recoveryImage = RecoveryImage.CreateNew(null, ScanBitDepth.C24Bit, false, transformList);

            if (copy)
            {
                File.Copy(pdfPath, recoveryImage.FilePath);
            }
            else
            {
                File.Move(pdfPath, recoveryImage.FilePath);
            }

            recoveryImage.Save();
        }
예제 #6
0
        public IEnumerable <int> Reverse(IEnumerable <int> selection)
        {
            var selectionList = selection.ToList();
            int pairCount     = selectionList.Count / 2;

            // Swap pairs in the selection, excluding the middle element (if the total count is odd)
            for (int i = 0; i < pairCount; i++)
            {
                int x    = selectionList[i];
                int y    = selectionList[selectionList.Count - i - 1];
                var temp = Images[x];
                Images[x] = Images[y];
                Images[y] = temp;
            }

            RecoveryImage.Refresh(Images);

            // Selection stays the same, so is easy to maintain
            return(selectionList);
        }
예제 #7
0
        public IEnumerable <int> AltInterleave(IEnumerable <int> selectedIndices)
        {
            // Partition the image list in two
            int count = Images.Count;
            int split = (count + 1) / 2;
            var p1    = Images.Take(split).ToList();
            var p2    = Images.Skip(split).ToList();

            // Rebuild the image list, taking alternating images from each the partitions (the latter in reverse order)
            Images.Clear();
            for (int i = 0; i < count; ++i)
            {
                Images.Add(i % 2 == 0 ? p1[i / 2] : p2[p2.Count - 1 - i / 2]);
            }

            RecoveryImage.Refresh(Images);

            // Clear the selection (may be changed in the future to maintain it, but not necessary)
            return(Enumerable.Empty <int>());
        }
예제 #8
0
        public IEnumerable <int> DividedScanBooklet(IEnumerable <int> selection)
        {
            lock (this)
            {
                var original = Images.ToList();
                var max      = original.Count;
                var middle   = max / 2;

                Images.Clear();
                for (int i = 0; i < original.Count; ++i)
                {
                    Images.Add(original[GetScanIndexForDividedBookletByLogicalPage(i, max, middle)]);
                }

                RecoveryImage.Refresh(Images);

                // Clear the selection (may be changed in the future to maintain it, but not necessary)
                return(Enumerable.Empty <int>());
            }
        }
예제 #9
0
        public IEnumerable <int> Interleave(IEnumerable <int> selection)
        {
            lock (this)
            {
                // Partition the image list in two
                var count = Images.Count;
                var split = (count + 1) / 2;
                var p1    = Images.Take(split).ToList();
                var p2    = Images.Skip(split).ToList();

                // Rebuild the image list, taking alternating images from each the partitions
                Images.Clear();
                for (var i = 0; i < count; ++i)
                {
                    Images.Add(i % 2 == 0 ? p1[i / 2] : p2[i / 2]);
                }

                RecoveryImage.Refresh(Images);

                // Clear the selection (may be changed in the future to maintain it, but not necessary)
                return(Enumerable.Empty <int>());
            }
        }
예제 #10
0
 public ScannedImage(RecoveryIndexImage recoveryIndexImage)
 {
     recoveryImage = RecoveryImage.LoadExisting(recoveryIndexImage);
     transformList = recoveryImage.IndexImage.TransformList;
 }
예제 #11
0
        protected override Task ScanInternal(ScannedImageSource.Concrete source)
        {
            if (ScanProfile.ProxyConfig == null)
            {
                throw new InvalidOperationException("ScanProfile.ProxyConfig must be specified to use ProxiedScanDriver.");
            }

            return(Task.Factory.StartNew(async() =>
            {
                try
                {
                    using (var client = clientContextFactory.Create(ScanProfile.ProxyConfig))
                    {
                        var noUi = ScanParams.NoUi;
                        var form = Invoker.Current.InvokeGet(() => noUi ? null : formFactory.Create <FScanProgress>());
                        var pageNumber = 1;
                        var sem = new Semaphore(0, int.MaxValue);

                        client.Callback.ImageCallback += (imageBytes, indexImage) =>
                        {
                            try
                            {
                                indexImage.FileName = RecoveryImage.GetNextFileName() + Path.GetExtension(indexImage.FileName);
                                var recoveryFilePath = Path.Combine(RecoveryImage.RecoveryFolder.FullName, indexImage.FileName);
                                File.WriteAllBytes(recoveryFilePath, imageBytes);
                                var image = new ScannedImage(indexImage);
                                using (var bitmap = new Bitmap(new MemoryStream(imageBytes)))
                                {
                                    scannedImageHelper.PostProcessStep2(image, bitmap, ScanProfile, ScanParams, pageNumber++, false);
                                }

                                source.Put(image);
                                if (form != null)
                                {
                                    form.PageNumber = pageNumber;
                                    Invoker.Current.SafeInvoke(() => form.RefreshStatus());
                                }
                            }
                            finally
                            {
                                sem.Release();
                            }
                        };

                        var scanTask = client.Service.Scan(ScanProfile, ScanParams).ContinueWith(t =>
                        {
                            for (var i = 0; i < t.Result; i++)
                            {
                                sem.WaitOne();
                            }
                        });

                        if (!noUi)
                        {
                            form.PageNumber = pageNumber;
                            form.AsyncTransfer = async() => await scanTask;
                            form.CancelToken.Register(client.Service.CancelScan);
                        }
                        CancelToken.Register(client.Service.CancelScan);

                        if (noUi)
                        {
                            await scanTask;
                        }
                        else if (ScanParams.Modal)
                        {
                            Invoker.Current.SafeInvoke(() => form.ShowDialog());
                        }
                        else
                        {
                            Invoker.Current.SafeInvoke(() => form.Show());
                            await scanTask;
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.ErrorException("Error scanning with proxy", e);
                }
            }, TaskCreationOptions.LongRunning).Unwrap());
        }