Example #1
0
        public void ThumbnailTest053s()
        {
            string file = Path.Combine(Util.ArtifactsDataPath, "test053C_01_01.th44");

            using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (DjvuReader reader = new DjvuReader(stream))
                {
                    TH44Chunk th    = new TH44Chunk(reader, null, null, "TH44", stream.Length);
                    var       thumb = th.Thumbnail;
                    Assert.NotNull(thumb);
                    Assert.Equal(128, thumb.Height);
                    Assert.Equal(91, thumb.Width);

                    th.Thumbnail = null;
                    var thumb2 = th.Thumbnail;
                    Assert.NotNull(thumb2);
                    Assert.Equal(128, thumb2.Height);
                    Assert.Equal(91, thumb2.Width);

                    Assert.NotSame(thumb, thumb2);

                    var map = new InterWavePixelMapDecoder();
                    th.Thumbnail = map;

                    var thumb3 = th.Thumbnail;
                    Assert.NotNull(thumb3);
                    Assert.Same(map, thumb3);
                }
        }
Example #2
0
        /// <summary>
        /// Builds the list of pages
        /// </summary>
        private void BuildPageList()
        {
            Queue <DirmComponent> pageHeaders = new Queue <DirmComponent>(Directory.Components.Where(x => x.IsPage));
            Queue <TH44Chunk>     thumbnail   = new Queue <TH44Chunk>(FormChunk.GetChildrenItems <TH44Chunk>());

            DjviChunk[] sharedItems = FormChunk.GetChildrenItems <DjviChunk>();

            List <DjvuPage> pages = new List <DjvuPage>();

            int pageCount = 1;

            foreach (IFFChunk child in FormChunk.Children)
            {
                if (child is FormChunk)
                {
                    FormChunk form = (FormChunk)child;

                    if (form.Children.Any(x => x.ChunkType == ChunkTypes.Form_Djvu))
                    {
                        DirmComponent currentHeader    = pageHeaders.Count() > 0 ? pageHeaders.Dequeue() : null;
                        TH44Chunk     currentThumbnail = thumbnail.Count() > 0 ? thumbnail.Dequeue() : null;
                        DjvuPage      newPage          = new DjvuPage(pageCount++, this, currentHeader, currentThumbnail, sharedItems, form);

                        pages.Add(newPage);
                    }
                }
            }

            Pages = pages.ToArray();
        }
Example #3
0
 public DjvuPage(int pageNumber, DjvuDocument document, DirmComponent header, TH44Chunk thumbnail, DjviChunk[] includedItems, FormChunk form)
 {
     PageNumber    = pageNumber;
     Document      = document;
     Header        = header;
     Thumbnail     = thumbnail;
     IncludedItems = includedItems;
     PageForm      = form;
 }
Example #4
0
        public void TH44ChunkTest()
        {
            Mock <IDjvuReader> readerMock = new Mock <IDjvuReader>();

            readerMock.Setup(x => x.Position).Returns(1024);

            TH44Chunk unk = new TH44Chunk(readerMock.Object, null, null, null, 0);

            Assert.Equal <ChunkType>(ChunkType.TH44, unk.ChunkType);
            Assert.Equal(ChunkType.TH44.ToString(), unk.Name);
            Assert.Equal <long>(1024, unk.DataOffset);
        }
Example #5
0
        public void ThumbnailTest053()
        {
            string file = Path.Combine(Util.ArtifactsDataPath, "test053C_01_01.th44");

            using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (DjvuReader reader = new DjvuReader(stream))
                {
                    TH44Chunk th    = new TH44Chunk(reader, null, null, "TH44", stream.Length);
                    var       thumb = th.Thumbnail;
                    Assert.NotNull(thumb);
                    Assert.Equal(128, thumb.Height);
                    Assert.Equal(91, thumb.Width);
                }
        }
Example #6
0
        public void TH44Chunk_Theory(string fileName, string filePath)
        {
            using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (DjvuReader reader = new DjvuReader(stream))
                {
                    TH44Chunk th = new TH44Chunk(reader, null, null, "TH44", stream.Length);
                    Assert.Equal <ChunkType>(ChunkType.TH44, th.ChunkType);
                    Assert.Equal(stream.Length, th.Length);

                    var image = th.Image;
                    Assert.NotNull(image);
                    Assert.IsType <PixelMap>(image);
                    Assert.True(image.Width >= 64 && image.Width < 512);
                }
        }
Example #7
0
        private void DumpTH44ChunkList(int docIndex, IReadOnlyList <IDjvuNode> th44List, int i)
        {
            string docFile         = Util.GetTestFilePath(docIndex);
            string fileName        = Path.GetFileNameWithoutExtension(docFile);
            string outFileTemplate = Path.Combine(Util.ArtifactsDataPath, fileName);

            for (int k = 0; k < th44List.Count; k++)
            {
                TH44Chunk th   = (TH44Chunk)th44List[k];
                string    file = outFileTemplate + "_" + (i + 1).ToString("00") + "_" + (k + 1).ToString("00") + ".th44";
                using (FileStream outFile = new FileStream(file, FileMode.Create, FileAccess.ReadWrite))
                {
                    outFile.Write(th.ChunkData, 0, th.ChunkData.Length);
                }
            }
        }
Example #8
0
        public void ReadDataTest()
        {
            Mock <IDjvuReader> readerMock = new Mock <IDjvuReader>();

            readerMock.SetupProperty <long>(x => x.Position);
            IDjvuReader reader = readerMock.Object;

            reader.Position = 1024;

            TH44Chunk unk = new TH44Chunk(reader, null, null, null, 1024);

            Assert.Equal <ChunkType>(ChunkType.TH44, unk.ChunkType);
            Assert.Equal(ChunkType.TH44.ToString(), unk.Name);
            Assert.Equal <long>(1024, unk.DataOffset);

            unk.ReadData(reader);
            Assert.Equal <long>(2048, reader.Position);
        }
Example #9
0
        public static IDjvuNode CreateEncodedDjvuNode(IDjvuWriter writer, IDjvuElement parent, ChunkType chunkType, long length)
        {
            IDjvuNode result = null;

            switch (chunkType)
            {
            case ChunkType.Djvm:
                result = new DjvmChunk(writer, parent, length);
                break;

            case ChunkType.Djvu:
                result = new DjvuChunk(writer, parent, length);
                break;

            case ChunkType.Djvi:
                result = new DjviChunk(writer, parent, length);
                break;

            case ChunkType.Thum:
                result = new ThumChunk(writer, parent, length);
                break;

            case ChunkType.Dirm:
                result = new DirmChunk(writer, parent, length);
                break;

            case ChunkType.Navm:
                result = new NavmChunk(writer, parent, length);
                break;

            case ChunkType.Anta:
                result = new AntaChunk(writer, parent, length);
                break;

            case ChunkType.Antz:
                result = new AntzChunk(writer, parent, length);
                break;

            case ChunkType.Txta:
                result = new TxtaChunk(writer, parent, length);
                break;

            case ChunkType.Txtz:
                result = new TxtzChunk(writer, parent, length);
                break;

            case ChunkType.Djbz:
                result = new DjbzChunk(writer, parent, length);
                break;

            case ChunkType.Sjbz:
                result = new SjbzChunk(writer, parent, length);
                break;

            case ChunkType.FG44:
                result = new FG44Chunk(writer, parent, length);
                break;

            case ChunkType.BG44:
                result = new BG44Chunk(writer, parent, length);
                break;

            case ChunkType.TH44:
                result = new TH44Chunk(writer, parent, length);
                break;

            case ChunkType.BM44:
                result = new BM44Chunk(writer, parent, length);
                break;

            case ChunkType.BM44Form:
                result = new BM44Form(writer, parent, length);
                break;

            case ChunkType.PM44:
                result = new PM44Chunk(writer, parent, length);
                break;

            case ChunkType.PM44Form:
                result = new PM44Form(writer, parent, length);
                break;

            case ChunkType.Wmrm:
                result = new WmrmChunk(writer, parent, length);
                break;

            case ChunkType.FGbz:
                result = new FGbzChunk(writer, parent, length);
                break;

            case ChunkType.Info:
                result = new InfoChunk(writer, parent, length);
                break;

            case ChunkType.Incl:
                result = new InclChunk(writer, parent, length);
                break;

            case ChunkType.BGjp:
                result = new BGjpChunk(writer, parent, length);
                break;

            case ChunkType.FGjp:
                result = new FGjpChunk(writer, parent, length);
                break;

            case ChunkType.Smmr:
                result = new SmmrChunk(writer, parent, length);
                break;

            default:
                throw new DjvuInvalidOperationException($"Chunk type is not supported in encoding. ChunkType: {chunkType}");
            }

            return(result);
        }
Example #10
0
        /// <summary>
        /// Builds the appropriate chunk for the ID
        /// </summary>
        /// <returns></returns>
        public static IDjvuNode CreateDecodedDjvuNode(IDjvuReader reader, IDjvuDocument rootDocument,
                                                      IDjvuElement parent, ChunkType chunkType,
                                                      string chunkID = "", long length = 0)
        {
            IDjvuNode result = null;

            switch (chunkType)
            {
            case ChunkType.Djvm:
                result = new DjvmChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Djvu:
                result = new DjvuChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Djvi:
                result = new DjviChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Thum:
                result = new ThumChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Dirm:
                result = new DirmChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Navm:
                result = new NavmChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Anta:
                result = new AntaChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Antz:
                result = new AntzChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Txta:
                result = new TxtaChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Txtz:
                result = new TxtzChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Djbz:
                result = new DjbzChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Sjbz:
                result = new SjbzChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.FG44:
                result = new FG44Chunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.BG44:
                result = new BG44Chunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.TH44:
                result = new TH44Chunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.BM44:
                result = new BM44Chunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.BM44Form:
                result = new BM44Form(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.PM44:
                result = new PM44Chunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.PM44Form:
                result = new PM44Form(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Wmrm:
                result = new WmrmChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.FGbz:
                result = new FGbzChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Info:
                result = new InfoChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Incl:
                result = new InclChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.BGjp:
                result = new BGjpChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.FGjp:
                result = new FGjpChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Smmr:
                result = new SmmrChunk(reader, parent, rootDocument, chunkID, length);
                break;

            case ChunkType.Cida:
                result = new CidaChunk(reader, parent, rootDocument, chunkID, length);
                break;

            default:
                result = new UnknownChunk(reader, parent, rootDocument, chunkID, length);
                break;
            }

            return(result);
        }