public void ProgressiveDecodeBackground_Theory(string file, long length) { using (FileStream fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)) using (IDjvuReader reader = new DjvuReader(fs)) { BG44Chunk unk = new BG44Chunk(reader, null, null, "BG44", length); unk.Initialize(); var map = new InterWavePixelMapDecoder(); var result = unk.ProgressiveDecodeBackground(map); Assert.Same(result, map); #if !_APPVEYOR string dumpsDir = Path.Combine(Util.ArtifactsDataPath, "dumps"); if (!System.IO.Directory.Exists(dumpsDir)) { System.IO.Directory.CreateDirectory(dumpsDir); } using (System.Drawing.Bitmap image = map.GetPixelMap().ToImage()) { string fileName = Path.GetFileNameWithoutExtension(file); string outFile = Path.Combine(dumpsDir, fileName + "_bg44.png"); using (FileStream stream = new FileStream(outFile, FileMode.Create)) image.Save(stream, System.Drawing.Imaging.ImageFormat.Png); } #endif } }
public void BG44ChunkTest() { Mock <IDjvuReader> readerMock = new Mock <IDjvuReader>(); readerMock.Setup(x => x.Position).Returns(1024); BG44Chunk unk = new BG44Chunk(readerMock.Object, null, null, null, 0); Assert.Equal <ChunkType>(ChunkType.BG44, unk.ChunkType); Assert.Equal(ChunkType.BG44.ToString(), unk.Name); Assert.Equal <long>(1024, unk.DataOffset); }
public void ImageTest035() { string file = Path.Combine(Util.ArtifactsDataPath, "test035C_P01_0.bg44"); using (FileStream fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)) using (IDjvuReader reader = new DjvuReader(fs)) { BG44Chunk unk = new BG44Chunk(reader, null, null, "BG44", fs.Length); unk.Initialize(); var map = new InterWavePixelMapDecoder(); IInterWavePixelMap result = unk.BackgroundImage; var pixMap = result.GetPixelMap(); unk.BackgroundImage = map; Assert.NotSame(result, unk.BackgroundImage); Assert.Same(map, unk.BackgroundImage); } }
public void ReadDataTest() { Mock <IDjvuReader> readerMock = new Mock <IDjvuReader>(); readerMock.SetupProperty <long>(x => x.Position); IDjvuReader reader = readerMock.Object; reader.Position = 1024; BG44Chunk unk = new BG44Chunk(readerMock.Object, null, null, null, 1024); Assert.Equal <ChunkType>(ChunkType.BG44, unk.ChunkType); Assert.Equal(ChunkType.BG44.ToString(), unk.Name); Assert.Equal <long>(1024, unk.DataOffset); unk.ReadData(reader); Assert.Equal <long>(2048, reader.Position); }
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); }
/// <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); }