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); } }
public void CloseCodecTest() { string file = Path.Combine(Util.ArtifactsDataPath, "test002C_P01_0.bg44"); using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (DjvuReader reader = new DjvuReader(stream)) { var map = new InterWavePixelMapDecoder(); map.Decode(reader); Assert.NotNull(map._YMap); Assert.NotNull(map._YDecoder); Assert.NotNull(map._CbMap); Assert.NotNull(map._CbDecoder); Assert.NotNull(map._CrMap); Assert.NotNull(map._CrDecoder); map.CloseCodec(); Assert.NotNull(map._YMap); Assert.Null(map._YDecoder); Assert.NotNull(map._CbMap); Assert.Null(map._CbDecoder); Assert.NotNull(map._CrMap); Assert.Null(map._CrDecoder); } }
public void ForegroundImageTest() { string file = Path.Combine(Util.ArtifactsDataPath, "test037C_P01.fg44"); using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) using (DjvuReader reader = new DjvuReader(stream)) { FG44Chunk unk = new FG44Chunk(reader, null, null, "FG44", stream.Length); var img = unk.ForegroundImage; Assert.NotNull(img); Assert.NotEqual(0, img.Width); Assert.NotEqual(0, img.Height); var map = new InterWavePixelMapDecoder(); Assert.Equal(0, map.Width); Assert.Equal(0, map.Height); unk.ForegroundImage = map; Assert.NotSame(img, map); img = unk.ForegroundImage; Assert.Same(img, map); Assert.Equal(0, img.Width); Assert.Equal(0, img.Height); } }
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 ForegroundImageTest002() { string filePath = Path.Combine(Util.ArtifactsDataPath, "test037C_P01.fg44"); using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (DjvuReader reader = new DjvuReader(stream)) { FG44Chunk th = new FG44Chunk(reader, null, null, "FG44", stream.Length); Assert.Equal <ChunkType>(ChunkType.FG44, th.ChunkType); Assert.Equal(stream.Length, th.Length); var image = th.ForegroundImage; Assert.NotNull(image); Assert.IsType <InterWavePixelMapDecoder>(image); Assert.True(image.Width >= 0 && image.Height > 0); var map = new InterWavePixelMapDecoder(); th.ForegroundImage = map; var image2 = th.ForegroundImage; Assert.NotNull(image2); Assert.NotSame(image, image2); Assert.Same(map, image2); Assert.True(image2.Width == 0 && image2.Height == 0); } }
/// <summary> /// Decodes the background image for this chunk /// </summary> /// <returns></returns> internal IInterWavePixelMap DecodeImage() { using (IDjvuReader reader = Reader.CloneReaderToMemory(DataOffset, Length)) { IInterWavePixelMap pixelMap = new InterWavePixelMapDecoder(); pixelMap.Decode(reader); return(pixelMap); } }
public void DecodeTest004() { byte[] buffer = new byte[] { 0x01, 0x48, 0x01, 0x05, 0x03, 0x3B, 0x04, 0x3F, 0x8A, 0xFF, 0xFF, 0xE9, 0xFB, 0x80, 0x3E, 0xA2 }; using (MemoryStream stream = new MemoryStream(buffer)) using (DjvuReader reader = new DjvuReader(stream)) { var map = new InterWavePixelMapDecoder(); Assert.Throws <DjvuFormatException>(() => map.Decode(reader)); } }
/// <summary> /// Decodes the background image for this chunk /// </summary> /// <returns></returns> internal IInterWavePixelMap DecodeBackgroundImage() { using (IDjvuReader reader = Reader.CloneReaderToMemory(DataOffset, Length)) { IInterWavePixelMap background = new InterWavePixelMapDecoder(); background.Decode(reader); return(background); } }
/// <summary> /// Decodes the thumbnail image for this chunk /// </summary> /// <returns></returns> internal IInterWavePixelMap DecodeThumbnailImage() { using (IDjvuReader reader = Reader.CloneReaderToMemory(DataOffset, Length)) { IInterWavePixelMap thumbnail = new InterWavePixelMapDecoder(); thumbnail.Decode(reader); return(thumbnail); } }
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 ProgressiveDecodeBackgroundTest() { string file = Path.Combine(Util.ArtifactsDataPath, "test001C_P01.fg44"); using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) using (DjvuReader reader = new DjvuReader(stream)) { BM44Chunk unk = new BM44Chunk(reader, null, null, null, reader.Length); Assert.Equal <ChunkType>(ChunkType.BM44, unk.ChunkType); Assert.Equal(ChunkType.BM44.ToString(), unk.Name); Assert.Equal <long>(0, unk.DataOffset); Assert.Equal <long>(reader.Length, unk.Length); var map = new InterWavePixelMapDecoder(); IInterWavePixelMap result = unk.ProgressiveDecodeBackground(map); Assert.NotNull(map); } }
public void DuplicateTest001() { string file = Path.Combine(Util.ArtifactsDataPath, "test002C_P01_0.bg44"); using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (DjvuReader reader = new DjvuReader(stream)) { var map = new InterWavePixelMapDecoder(); map.Decode(reader); Assert.NotNull(map._YMap); Assert.NotNull(map._YDecoder); Assert.NotNull(map._CbMap); Assert.NotNull(map._CbDecoder); Assert.NotNull(map._CrMap); Assert.NotNull(map._CrDecoder); var dyMap = map._YMap.Duplicate(); Assert.NotNull(dyMap); Assert.Equal(map._YMap.Width, dyMap.Width); Assert.Equal(map._YMap.Height, dyMap.Height); Assert.Equal(map._YMap.Blocks.Length, dyMap.Blocks.Length); } }