예제 #1
0
        public void DjvuImageTest001()
        {
            DjvuImage image = new DjvuImage();

            Assert.Null(image.Page);
            Assert.Null(image.Document);
        }
예제 #2
0
        public void CreateBlankImageTest()
        {
            Mock <IDjvuPage>     pageMock     = new Mock <IDjvuPage>();
            Mock <IDjvuDocument> documentMock = new Mock <IDjvuDocument>();

            pageMock.Setup(x => x.Document).Returns(documentMock.Object);
            pageMock.Setup(x => x.Width).Returns(100);
            pageMock.Setup(x => x.Height).Returns(200);
            IDjvuPage page = pageMock.Object;

            DjvuImage image = new DjvuImage(page);

            Assert.Same(pageMock.Object, image.Page);
            Assert.Same(documentMock.Object, image.Document);

            using (Bitmap bitmap = image.CreateBlankImage(Brushes.White))
            {
                Assert.Equal <int>(page.Width, bitmap.Width);
                Assert.Equal <int>(page.Height, bitmap.Height);
                Color c = bitmap.GetPixel(0, 0);
                Assert.Equal <byte>(0xff, c.A);
                Assert.Equal <byte>(0xff, c.B);
                Assert.Equal <byte>(0xff, c.G);
                Assert.Equal <byte>(0xff, c.R);
            }
        }
예제 #3
0
        public void BuildPageImageTest000()
        {
            string file = Path.Combine(Util.ArtifactsPath, "test077C.djvu");

            using (DjvuDocument doc = new DjvuDocument(file))
            {
                var       page      = (DjvuPage)doc.Pages[0];
                DjvuImage djvuImage = page.Image as DjvuImage;
                using (var image = djvuImage.BuildPageImage())
                {
                    page.IsInverted = true;
                    using (Bitmap imageInv = djvuImage.BuildPageImage())
                    {
                        Assert.NotNull(image);
                        Assert.NotNull(imageInv);
                        Assert.NotSame(image, imageInv);
                        Color pix    = image.GetPixel(0, 0);
                        Color pixInv = imageInv.GetPixel(0, 0);
                        Assert.Equal(pix.R, 255 - pixInv.R);
                        Assert.Equal(pix.G, 255 - pixInv.G);
                        Assert.Equal(pix.B, 255 - pixInv.B);
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Gets the foreground image for the page.
        /// </summary>
        /// <param name="resizeToPage"></param>
        /// <returns></returns>
        public static Bitmap GetForegroundImage(this DjvuImage image, int subsample, bool resizeImage = false)
        {
            Verify.SubsampleRange(subsample);

            lock (image.LoadingLock)
            {
                Bitmap result = null;

                JB2Image           jb2image   = null;
                IInterWavePixelMap iwPixelMap = image.Page.ForegroundIWPixelMap;

                if (iwPixelMap != null)
                {
                    result = image.Page.ForegroundIWPixelMap.GetPixelMap().ToImage();
                }
                else if ((jb2image = image.Page.ForegroundJB2Image) != null)
                {
                    if (image.Page.ForegroundPalette == null)
                    {
                        result = jb2image.GetBitmap(1, GBitmap.BorderSize).ToImage();
                    }
                    else
                    {
                        result = jb2image.GetPixelMap(image.Page.ForegroundPalette, 1, 16).ToImage();
                    }
                }
                else if (iwPixelMap == null && jb2image == null)
                {
                    result = CreateBlankImage(Brushes.Black, image.Page.Width / subsample, image.Page.Height / subsample);
                }

                return(resizeImage ? ResizeImage(result, image.Page.Width / subsample, image.Page.Height / subsample) : result);
            }
        }
예제 #5
0
        public void GetMaskImage075()
        {
            int pageCount = 0;

            using (DjvuDocument document = Util.GetTestDocument(75, out pageCount))
            {
                Util.VerifyDjvuDocument(pageCount, document);

                DjvuPage page = document.FirstPage as DjvuPage;
                Assert.NotNull(page);
                var testImagePath = Path.Combine(Util.RepoRoot, "artifacts", "data", "test075C.mask.png");

                DjvuImage djvuImage = page.Image as DjvuImage;
                using (Bitmap image = djvuImage.GetMaskImage(1))
                    using (Bitmap testImage = new Bitmap(testImagePath))
                    {
                        Assert.NotNull(image);
                        Assert.IsType <Bitmap>(image);

                        Assert.NotNull(testImage);

                        bool result = Util.CompareImagesForBinarySimilarity(testImage, image, 0.3, true, "Testing Djvu mask: test075C.png, ");

                        Assert.True(result);
                    }
            }
        }
예제 #6
0
        public void BuildForegroundImage_Theory(int docNumber)
        {
            int pageCount = 0;

            using (DjvuDocument document = Util.GetTestDocument(docNumber, out pageCount))
            {
                Util.VerifyDjvuDocument(pageCount, document);
                IDjvuPage page          = document.FirstPage;
                var       testImagePath = Path.Combine(Util.RepoRoot, "artifacts", "data", $"test{docNumber:00#}CFgnd.png");

                DjvuImage djvuImage = page.Image as DjvuImage;
                using (Bitmap image = djvuImage.GetForegroundImage(1, true))
                    using (Bitmap testImage = new Bitmap(testImagePath))
                    {
                        Assert.NotNull(image);
                        Assert.IsType <Bitmap>(image);

                        if (image.Width != testImage.Width || image.Height != testImage.Height)
                        {
                            Assert.True(false, $"Unexpected image size differences. Width image: {image.Width} | testImage: {testImage.Width}, Height: image: {image.Height} | testImage {testImage.Height}");
                        }

                        bool result = Util.CompareImagesForBinarySimilarity(testImage, image, 0.025, true, $"Testing Djvu foreground: \ttest{docNumber:00#}C.png, ");

#if DUMP_IMAGES
                        DumpImage(docNumber, image, "Fgnd");
#endif

                        Assert.True(result);
                    }
            }
        }
예제 #7
0
        public void BuildMaskImage_Theory(int docNumber, double tolerance)
        {
            int pageCount = 0;

            using (DjvuDocument document = Util.GetTestDocument(docNumber, out pageCount))
            {
                Util.VerifyDjvuDocument(pageCount, document);
                IDjvuPage page          = document.FirstPage;
                var       testImagePath = Path.Combine(Util.RepoRoot, "artifacts", "data", $"test{docNumber:00#}Cmask.png");

                DjvuImage djvuImage = page.Image as DjvuImage;
                using (Bitmap image = djvuImage.GetMaskImage(1, true))
                    using (Bitmap testImage = new Bitmap(testImagePath))
                    {
                        Assert.NotNull(image);
                        Assert.IsType <Bitmap>(image);

                        using Bitmap invertedImage = DjvuImage.InvertImage(image);

                        bool result = Util.CompareImagesForBinarySimilarity(testImage, invertedImage, tolerance, true, $"Testing Djvu mask: \t\ttest{docNumber:00#}C.png, ");

#if DUMP_IMAGES
                        DumpIage(docNumber, image, "Mask");
#endif
                        Assert.True(result);
                    }
            }
        }
예제 #8
0
        public void Image003()
        {
            int pageCount = 0;

            using (DjvuDocument document = Util.GetTestDocument(3, out pageCount))
            {
                Util.VerifyDjvuDocument(pageCount, document);

                IDjvuPage page          = document.FirstPage;
                var       testImagePath = Path.Combine(Util.ArtifactsDataPath, "test003C.png");

                DjvuImage djvuImage = page.Image as DjvuImage;
                using (var image = djvuImage.Image)
                    using (Bitmap testImage = new Bitmap(testImagePath))
                    {
                        Assert.NotNull(image);
                        Assert.IsType <Bitmap>(image);
                        Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);

                        BitmapData data     = image.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                        BitmapData testData = testImage.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

                        bool result = Util.CompareImages(data, testData);

                        image.UnlockBits(data);
                        testImage.UnlockBits(testData);
                        //image.Save(Path.Combine(Util.RepoRoot, "artifacts", "data", "dumps", "test003CImage003n.png"));

                        //Assert.True(result);
                    }
            }
        }
예제 #9
0
        public void BuildImage_Theory(int docNumber)
        {
            int pageCount = 0;

            using (DjvuDocument document = Util.GetTestDocument(docNumber, out pageCount))
            {
                Util.VerifyDjvuDocument(pageCount, document);
                IDjvuPage page          = document.FirstPage;
                var       testImagePath = Path.Combine(Util.RepoRoot, "artifacts", "data", $"test{docNumber:00#}C.png");

                DjvuImage djvuImage = page.Image as DjvuImage;
                using (Bitmap image = djvuImage.BuildImage())
                    using (Bitmap testImage = new Bitmap(testImagePath))
                    {
                        Assert.NotNull(image);
                        Assert.IsType <Bitmap>(image);

                        bool result = Util.CompareImagesForBinarySimilarity(testImage, image, docNumber == 75 ? 0.1485 : 0.0585, true, $"Testing Djvu image: \t\ttest{docNumber:00#}C.png, ");

#if DUMP_IMAGES
                        DumpImage(docNumber, image, "Img");
#endif
                        Assert.True(result, $"Test failed: ");
                    }
            }
        }
예제 #10
0
        public void InvertColorTest002()
        {
            const int color  = 0x00000000;
            int       result = DjvuImage.InvertColor(color);

            Assert.Equal(0x00ffffff, result);
        }
예제 #11
0
        public void InvertColorTest003()
        {
            int color  = 0x00f0f0f0;
            int result = DjvuImage.InvertColor(color);

            Assert.Equal(0x000f0f0f, result);
        }
        public static void Run()
        {
            Console.WriteLine("Running example ConvertRangeOfDjVuPagesToSeparateImages");
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_DjVu();

            // Load a DjVu image
            using (DjvuImage image = (DjvuImage)Image.Load(dataDir + "Sample.djvu"))
            {
                // Create an instance of BmpOptions and Set BitsPerPixel for resultant images
                BmpOptions exportOptions = new BmpOptions();
                exportOptions.BitsPerPixel = 32;

                // Create an instance of IntRange and initialize it with range of pages to be exported
                IntRange range   = new IntRange(0, 2);
                int      counter = 0;
                foreach (var i in range.Range)
                {
                    // Save each page in separate file, as BMP do not support layering
                    exportOptions.MultiPageOptions = new DjvuMultiPageOptions(range.GetArrayOneItemFromIndex(counter));
                    image.Save(dataDir + string.Format("{0}_out.bmp", counter++), exportOptions);
                }
            }

            Console.WriteLine("Finished example ConvertRangeOfDjVuPagesToSeparateImages");
        }
예제 #13
0
 public void ResizeImage003()
 {
     using (System.Drawing.Bitmap bitmap = new Bitmap(128, 128))
     {
         Assert.Throws <DjvuArgumentException>(() => DjvuImage.ResizeImage(bitmap, -128, 128));
     }
 }
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_DjVu();

            Console.WriteLine("Running example CommonMultipageImageExample");

            using (DjvuImage image = (DjvuImage)Image.Load(Path.Combine(dataDir, "Sample.djvu")))
            {
                if (image is IMultipageImage)
                {
                    var pages = ((IMultipageImage)image).Pages;
                    Console.WriteLine("Pages count in document is " + pages.Length);
                }

                int startPage = 3;
                int countPage = 1;

                PngOptions pngOptions = new PngOptions();
                pngOptions.MultiPageOptions = new MultiPageOptions(new IntRange(startPage, countPage));
                image.Save(Path.Combine(dataDir, "multipageExportSingle_out.png"), pngOptions);


                startPage = 0;
                countPage = 2;
                TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.TiffDeflateRgb);
                tiffOptions.MultiPageOptions = new MultiPageOptions(new IntRange(startPage, countPage));
                image.Save(Path.Combine(dataDir, "multipageExportMultiple_out.tiff"), tiffOptions);
            }

            Console.WriteLine("Finished example CommonMultipageImageExample");
        }
예제 #15
0
        public void DjvuImageTest003()
        {
            Mock <IDjvuPage>     pageMock     = new Mock <IDjvuPage>();
            Mock <IDjvuDocument> documentMock = new Mock <IDjvuDocument>();

            pageMock.Setup(x => x.Document).Returns(documentMock.Object);

            DjvuImage image = new DjvuImage(pageMock.Object);

            Assert.Same(pageMock.Object, image.Page);
            Assert.Same(documentMock.Object, image.Document);
        }
예제 #16
0
        /// <summary>
        /// Extracts a thumbnail image for the page
        /// </summary>
        /// <returns></returns>
        public static Bitmap ExtractThumbnailImage(this DjvuImage image)
        {
            if (image.Page.Thumbnail != null)
            {
                return(image.Page.Thumbnail.Image.ToImage());
            }

            Bitmap result      = BuildImage(image);
            var    scaleAmount = (double)128 / result.Width;

            return(DjvuImage.ResizeImage(result, (int)(result.Width * scaleAmount), (int)(result.Height * scaleAmount)));
        }
예제 #17
0
 public void CreateBlankImageTest1()
 {
     using (Bitmap bitmap = DjvuImage.CreateBlankImage(Brushes.White, 100, 200))
     {
         Assert.Equal <int>(100, bitmap.Width);
         Assert.Equal <int>(200, bitmap.Height);
         Color c = bitmap.GetPixel(0, 0);
         Assert.Equal <byte>(0xff, c.A);
         Assert.Equal <byte>(0xff, c.B);
         Assert.Equal <byte>(0xff, c.G);
         Assert.Equal <byte>(0xff, c.R);
     }
 }
예제 #18
0
        /// <summary>
        /// Gets the background image for the page
        /// </summary>
        /// <returns></returns>
        public static Bitmap GetBackgroundImage(this DjvuImage image, int subsample, bool resizeImage = false)
        {
            Verify.SubsampleRange(subsample);

            int width  = image.Page.Width;
            int height = image.Page.Height;

            BG44Chunk[] backgrounds = image.Page.PageForm?.GetChildrenItems <BG44Chunk>();

            if ((backgrounds == null || backgrounds.Length == 0) && width > 0 && height > 0)
            {
                return(CreateBlankImage(Brushes.White, width, height));
            }

            // Get the composite background image
            Wavelet.IInterWavePixelMap backgroundMap = null;

            lock (image.LoadingLock)
            {
                foreach (BG44Chunk background in backgrounds)
                {
                    if (backgroundMap == null)
                    {
                        // Get the initial image
                        backgroundMap = background.BackgroundImage;
                    }
                    else
                    {
                        if (!image.IsBackgroundDecoded)
                        {
                            background.ProgressiveDecodeBackground(backgroundMap);
                        }
                    }
                }

                image.IsBackgroundDecoded = true;
            }

            Bitmap result = backgroundMap.GetPixelMap().ToImage();

            if (resizeImage)
            {
                int newWidth  = width / subsample;
                int newHeight = height / subsample;
                return(ResizeImage(result, newWidth, newHeight));
            }
            else
            {
                return(result);
            }
        }
예제 #19
0
        /// <summary>
        /// Gets mask image for the page.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="subsample"></param>
        /// <param name="resizeImage"></param>
        /// <returns></returns>
        public static Bitmap GetMaskImage(this DjvuImage image, int subsample, bool resizeImage = false)
        {
            Verify.SubsampleRange(subsample);

            if (image.Page.ForegroundJB2Image == null)
            {
                return(new Bitmap(image.Page.Width / subsample, image.Page.Height / subsample, PixelFormat.Format8bppIndexed));
            }

            lock (image.LoadingLock)
            {
                Bitmap result = image.Page.ForegroundJB2Image.GetBitmap(subsample, GBitmap.BorderSize).ToImage();
                return(resizeImage ? ResizeImage(result, image.Page.Width / subsample, image.Page.Height / subsample) : result);
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_DjVu();

            // Load a DjVu image
            using (DjvuImage image = (DjvuImage)Image.Load(dataDir + "Sample.djvu"))
            {
                // Create an instance of TiffOptions & use preset options for Black n While with Deflate compression
                TiffOptions exportOptions = new TiffOptions(TiffExpectedFormat.TiffDeflateBw);
                // Initialize the DjvuMultiPageOptions
                exportOptions.MultiPageOptions = new DjvuMultiPageOptions();
                // Call Save method while passing instance of TiffOptions
                image.Save(dataDir + "ConvertDjVuToTIFFFormat_out.tiff", exportOptions);
            }
        }
예제 #21
0
        public void ResizeImage0011()
        {
            int pageCount = 0;

            using (DjvuDocument document = Util.GetTestDocument(4, out pageCount))
            {
                Util.VerifyDjvuDocument(pageCount, document);
                IDjvuPage page      = document.ActivePage;
                DjvuImage djvuImage = page.Image as DjvuImage;
                using (Bitmap image = djvuImage.ResizeImage(64, 64))
                {
                    Assert.NotNull(image);
                    Assert.Equal(64, image.Width);
                    Assert.Equal(64, image.Height);
                }
            }
        }
예제 #22
0
        public void ExtractThumbnailImage058()
        {
            int pageCount = 0;

            using (DjvuDocument document = Util.GetTestDocument(58, out pageCount))
            {
                Util.VerifyDjvuDocument(pageCount, document);

                var page = document.FirstPage;

                DjvuImage djvuImage = page.Image as DjvuImage;
                using (var image = djvuImage.ExtractThumbnailImage())
                {
                    Assert.NotNull(image);
                    Assert.IsType <Bitmap>(image);
                }
            }
        }
예제 #23
0
        public void BuildPageImage002i()
        {
            int pageCount = 0;

            using (DjvuDocument document = Util.GetTestDocument(2, out pageCount))
            {
                Util.VerifyDjvuDocument(pageCount, document);
                var page = document.FirstPage;
                page.IsInverted = true;
                DjvuImage djvuImage = page.Image as DjvuImage;
                using (var image = djvuImage.BuildImage())
                {
                    Assert.NotNull(image);
                    Assert.IsType <Bitmap>(image);
                    //image.Save(Path.Combine(Util.RepoRoot, "artifacts", "data", "dumps", "test002CBuildPageImagen.png"));
                }
            }
        }
예제 #24
0
        public void BuildImage002i()
        {
            int pageCount = 0;

            using (DjvuDocument document = Util.GetTestDocument(2, out pageCount))
            {
                Util.VerifyDjvuDocument(pageCount, document);

                var page = document.FirstPage;
                page.IsInverted = true;
                DjvuImage djvuImage = page.Image as DjvuImage;
                using (var image = djvuImage.BuildImage())
                {
                    Assert.NotNull(image);
                    Assert.IsType <Bitmap>(image);
                }
            }
        }
예제 #25
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_DjVu();

            // Load a DjVu image
            using (DjvuImage image = (DjvuImage)Image.Load(dataDir + "Sample.djvu"))
            {
                // Create an instance of TiffOptions with preset options
                TiffOptions exportOptions = new TiffOptions(TiffExpectedFormat.TiffDeflateBw);
                // Create an instance of IntRange and initialize it with range of pages to be exported
                IntRange range = new IntRange(0, 2); //Export first 2 pages
                // Initialize an instance of DjvuMultiPageOptions while passing instance of IntRange
                exportOptions.MultiPageOptions = new DjvuMultiPageOptions(range);
                // Call Save method while passing instance of TiffOptions
                image.Save(dataDir + "ConvertRangeOfDjVuPages_out.djvu", exportOptions);
            }
        }
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            Console.WriteLine("Running example OptimizationStrategyInDJVU");

            using (DjvuImage image = (DjvuImage)Image.Load(Path.Combine(dataDir, "test.djvu"), new LoadOptions {
                BufferSizeHint = 50
            }))
            {
                int pageNumber = 2;
                for (int pageNum = 0; pageNum < pageNumber; pageNum++)
                {
                    image.Pages[pageNum].Save(Path.Combine(dataDir, "page" + pageNum + ".png"), new PngOptions());
                }
            }

            Console.WriteLine("Finished example OptimizationStrategyInDJVU");
        }
예제 #27
0
 public void GetForegroundImage000()
 {
     using (var page = new DjvuPage())
     {
         page.Height = 128;
         page.Width  = 128;
         DjvuImage djvuImage = page.Image as DjvuImage;
         using (Bitmap bitmap = djvuImage.GetForegroundImage(1))
         {
             Assert.NotNull(bitmap);
             Assert.NotEqual(0, page.Width);
             Assert.Equal(page.Width, bitmap.Width);
             Assert.Equal(page.Height, bitmap.Height);
             Color pixel = bitmap.GetPixel(0, 0);
             Assert.Equal(0, pixel.R);
             Assert.Equal(0, pixel.G);
             Assert.Equal(0, pixel.B);
         }
     }
 }
예제 #28
0
        public void GetTextImage000()
        {
            var page = new DjvuPage();

            page.Height = 128;
            page.Width  = 128;
            DjvuImage djvuImage = page.Image as DjvuImage;

            using (var bitmap = djvuImage.GetTextImage(1))
            {
                Assert.NotNull(bitmap);
                Assert.NotEqual(0, page.Width);
                Assert.Equal(page.Width, bitmap.Width);
                Assert.Equal(page.Height, bitmap.Height);
                var pixel = bitmap.GetPixel(0, 0);
                Assert.Equal(0, pixel.R);
                Assert.Equal(0, pixel.G);
                Assert.Equal(0, pixel.B);
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_DjVu();

            // Load a DjVu image
            using (DjvuImage image = (DjvuImage)Image.Load(dataDir + "Sample.djvu"))
            {
                // Create an instance of PdfOptions
                PdfOptions exportOptions = new PdfOptions();
                // Initialize the metadata for Pdf document
                exportOptions.PdfDocumentInfo = new Aspose.Imaging.FileFormats.Pdf.PdfDocumentInfo();
                // Create an instance of IntRange and initialize it with the range of DjVu pages to be exported
                IntRange range = new IntRange(0, 5); //Export first 5 pages
                // Initialize an instance of DjvuMultiPageOptions with range of DjVu pages to be exported
                exportOptions.MultiPageOptions = new DjvuMultiPageOptions(range);
                // Save the result in PDF format
                image.Save(dataDir + "ConvertDjVuToPDFFormat_out.pdf", exportOptions);
            }
        }
예제 #30
0
        public void ResizeImage001()
        {
            int wh = 128;

            using (System.Drawing.Bitmap bitmap = new Bitmap(wh, wh))
            {
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
                {
                    using (SolidBrush brush = new SolidBrush(Color.FromArgb(0xed, 0xed, 0xed)))
                        g.FillRectangle(brush, 0, 0, bitmap.Width, bitmap.Height);
                }

                Bitmap newImage = DjvuImage.ResizeImage(bitmap, 2 * bitmap.Width, 2 * bitmap.Height);
                Assert.Equal(2 * wh, newImage.Width);
                Assert.Equal(2 * wh, newImage.Height);
                Color c = newImage.GetPixel(newImage.Width / 2, newImage.Height / 2);
                Assert.Equal(0xed, c.R);
                Assert.Equal(0xed, c.G);
                Assert.Equal(0xed, c.B);
            }
        }