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); } }
/// <summary> /// Reads the compressed data from the djvu file /// </summary> /// <param name="reader"></param> /// <param name="count"></param> /// <param name="compressedSectionLength"></param> private void ReadCompressedData(DjvuReader reader, int count, int compressedSectionLength) { DjvuReader decompressor = reader.GetBZZEncodedReader(compressedSectionLength); // Read the component sizes for (int x = 0; x < count; x++) { _components[x].Size = decompressor.ReadInt24MSB(); } // Read the component flag information for (int x = 0; x < count; x++) { _components[x].DecodeFlags(decompressor.ReadSByte()); } // Read the component strings for (int x = 0; x < count; x++) { _components[x].ID = decompressor.ReadNullTerminatedString(); if (_components[x].HasName == true) { _components[x].Name = decompressor.ReadNullTerminatedString(); } if (_components[x].HasTitle == true) { _components[x].Title = decompressor.ReadNullTerminatedString(); } } _isInitialized = true; }
protected override void ReadChunkData(DjvuReader reader) { _dataLocation = reader.Position; // Skip the shape data which is delayed read reader.Position += Length; }
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); } }
private Image DecodeImageData() { using (DjvuReader reader = Reader.CloneReader(_dataLocation)) { return(reader.GetJPEGImage(Length)); } }
public void SearchForTextStringTest() { string file = Path.Combine(Util.ArtifactsDataPath, "test077C_P01.txtz"); using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) using (DjvuReader reader = new DjvuReader(stream)) { TxtzChunk unk = new TxtzChunk(reader, null, null, null, stream.Length); string test = "landscapes"; Assert.True(unk.TextLength > 0); Assert.NotNull(unk.Text); Assert.Equal(unk.TextLength, unk.Text.Length); Assert.Equal(1, unk.Version); Assert.True(unk.Text.Contains(test), "Text not found on page"); int contains = 0; int preContains = 0; int postContains = 0; VerifyZoneContainsText(unk.Zone, test, ref contains, ref preContains, ref postContains); Assert.True(contains > 0, "Text not found in zones"); //Assert.True(postContains > 0, "Text not found in PostText"); //Assert.True(preContains > 0, "Text not found in PreText"); } }
/// <summary> /// Decodes the children of this chunk /// </summary> /// <param name="reader"></param> private void ReadChildren(DjvuReader reader) { List <IFFChunk> children = new List <IFFChunk>(); // Read in all the chunks while (reader.Position < Offset + Length + 8) { if (reader.Position % 2 == 1) { reader.Position++; } // Read the chunk ID string id = reader.ReadUTF8String(4); ChunkTypes type = IFFChunk.GetChunkType(id); // Reset the stream position reader.Position -= 4; var chunk = IFFChunk.BuildIFFChunk(reader, Document, this, type); if (chunk != null) { children.Add(chunk); } } Children = children.ToArray(); }
public TextZone(DjvuReader reader, TextZone parent, TextZone sibling, TextChunk chunkParent) { _parent = parent; _chunkParent = chunkParent; DecodeZoneData(reader, sibling, chunkParent); }
public void InclChunk_Theory(string file, DjvuJsonDocument doc) { byte[] buffer = null; using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) { buffer = new byte[fs.Length]; int result = fs.Read(buffer, 0, buffer.Length); Assert.Equal <long>(fs.Length, result); } Mock <IDjvuDocument> docMock = new Mock <IDjvuDocument>(); Mock <IDjvuElement> parentMock = new Mock <IDjvuElement>(); IDjvuElement parent = parentMock.Object; IDjvuDocument document = docMock.Object; using (MemoryStream ms = new MemoryStream(buffer, false)) using (IDjvuReader reader = new DjvuReader(ms)) { InclChunk chunk = new InclChunk(reader, parent, document, "INCL", buffer.Length); Assert.False(chunk.IsInitialized); // Support multiple INCL chunks in single DjvuChunk var testChunk = doc.Data.Pages[0].Children .Where(x => x.ID == "INCL" && x.Name == chunk.IncludeID) .FirstOrDefault <DjvuJsonDocument.Chunk>(); Assert.NotNull(testChunk); Assert.Equal(testChunk.Name, chunk.IncludeID); } }
protected override void ReadChunkData(DjvuReader reader) { if (Length > 0) { ReadChildren(reader); } }
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); } }
protected override void ReadChunkData(DjvuReader reader) { _dataLocation = reader.Position; // Skip the data since it is delayed read reader.Position += Length; }
public void ColorPalette001() { string filePath = Path.Combine(Util.ArtifactsDataPath, "test003C_P01.fgbz"); using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (DjvuReader reader = new DjvuReader(stream)) { FGbzChunk th = new FGbzChunk(reader, null, null, "FGBZ", stream.Length); Assert.Equal <ChunkType>(ChunkType.FGbz, th.ChunkType); Assert.Equal(stream.Length, th.Length); var palette = th.Palette; Assert.NotNull(palette); Assert.IsType <ColorPalette>(palette); Assert.False(th.HasShapeTableData); reader.Position = 0; var colPal = new ColorPalette(reader, th); th.Palette = colPal; var palette2 = th.Palette; Assert.NotNull(palette2); Assert.IsType <ColorPalette>(palette2); Assert.NotSame(palette, palette2); Assert.Same(palette2, colPal); } }
public void Palette_Theory(string file, DjvuJsonDocument doc) { byte[] buffer = null; using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) { buffer = new byte[fs.Length]; int result = fs.Read(buffer, 0, buffer.Length); Assert.Equal <long>(fs.Length, result); } Mock <IDjvuDocument> docMock = new Mock <IDjvuDocument>(); Mock <IDjvuElement> parentMock = new Mock <IDjvuElement>(); IDjvuElement parent = parentMock.Object; IDjvuDocument document = docMock.Object; using (MemoryStream ms = new MemoryStream(buffer, false)) using (IDjvuReader reader = new DjvuReader(ms)) { FGbzChunk chunk = new FGbzChunk(reader, parent, document, "FGBZ", buffer.Length); Assert.False(chunk.IsInitialized); var testChunk = doc.Data.Pages[0].Children .Where(x => x.ID == "FGbz") .FirstOrDefault <DjvuJsonDocument.Chunk>(); Assert.Equal <int>((int)testChunk?.Version.Value, chunk.Version); Assert.Equal <int>((int)testChunk.Colors.Value, (int)chunk.Palette?.PaletteColors?.Length); } }
public void ChunkDataTest003() { Mock <DjvuNode> nodeMock = new Mock <DjvuNode>() { CallBase = true }; byte[] data = new byte[4096]; for (int i = 0; i < data.Length; i++) { data[i] = (byte)(i % 256); } using (MemoryStream stream = new MemoryStream(data)) using (DjvuReader reader = new DjvuReader(stream)) { DjvuNode node = nodeMock.Object; node.Reader = reader; node.Length = 0; byte[] chunkData = node.ChunkData; Assert.NotNull(chunkData); Assert.Equal(0, chunkData.Length); node.ChunkData = data; chunkData = node.ChunkData; Assert.Equal(data.Length, chunkData.Length); for (int i = 0; i < data.Length; i++) { Assert.Equal(data[i], chunkData[i]); } } }
/// <summary> /// Decodes the data for the zone /// </summary> /// <param name="reader"></param> private void DecodeZoneData(DjvuReader reader, TextZone sibling, TextChunk chunkParent) { _zoneType = (ZoneTypes)reader.ReadByte(); _x = reader.ReadUInt16BigEndian() - 0x8000; _y = reader.ReadUInt16BigEndian() - 0x8000; _width = reader.ReadUInt16BigEndian() - 0x8000; _height = reader.ReadUInt16BigEndian() - 0x8000; _textOffset = reader.ReadUInt16BigEndian() - 0x8000; _textLength = reader.ReadInt24BigEndian(); ResolveOffsets(_parent, sibling); _rectangle = new Rectangle(_x, _y, _width, _height); int childrenZones = reader.ReadInt24BigEndian(); List <TextZone> children = new List <TextZone>(); TextZone childrenSibling = null; for (int x = 0; x < childrenZones; x++) { TextZone newZone = new TextZone(reader, this, childrenSibling, chunkParent); childrenSibling = newZone; children.Add(newZone); } _children = children.ToArray(); }
public void NavmChunk_Theory(string file) { Mock <IDjvuDocument> docMock = new Mock <IDjvuDocument>(); List <IDjvuPage> pages = new List <IDjvuPage>(); docMock.Setup(x => x.Pages).Returns(pages); for (int i = 0; i < 300; i++) { Mock <IDjvuPage> pageMock = new Mock <IDjvuPage>(); pageMock.Setup(x => x.PageNumber).Returns(i + 1); pages.Add(pageMock.Object); } Mock <DjvuFormElement> parentMock = new Mock <DjvuFormElement> { CallBase = true }; using (FileStream stream = new FileStream(file, FileMode.Open)) using (DjvuReader reader = new DjvuReader(stream)) { NavmChunk unk = new NavmChunk(reader, parentMock.Object, docMock.Object, "NAVM", stream.Length); Assert.Equal <ChunkType>(ChunkType.Navm, unk.ChunkType); Assert.Equal(stream.Length, unk.Length); var bookmarks = unk.Bookmarks; Assert.NotNull(bookmarks); foreach (var b in bookmarks) { Assert.NotNull(b.Children); } } }
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); } }
protected override void ReadChunkData(DjvuReader reader) { _dataLocation = reader.Position; // Skip the data since it will be delay read reader.Position += Length; }
protected override void ReadChunkData(DjvuReader reader) { _dataLocation = reader.Position; // Skip past the navigation data which will be delayed read reader.Position += Length; }
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 } }
protected override void ReadChunkData(DjvuReader reader) { _dataLocation = reader.Position; // Skip past the bytes which will be delayed read reader.Position += Length; }
private JB2Image ReadCompressedImage() { using (DjvuReader reader = Reader.CloneReader(_dataLocation, Length)) { JB2Image image = new JB2Image(); JB2.JB2Dictionary includedDictionary = null; if (Parent is FormChunk) { InclChunk[] includes = ((FormChunk)Parent).IncludedItems; if (includes != null && includes.Count() > 0) { string includeID = includes.FirstOrDefault().IncludeID; var includeItem = Document.GetChunkByID <DjbzChunk>(includeID); if (includeItem != null) { includedDictionary = includeItem.ShapeDictionary; } } } image.Decode(reader, includedDictionary); return(image); } }
public void InvalidBookmarkFormat() { string file = Path.Combine(Util.ArtifactsDataPath, "test053C.navm"); Mock <IDjvuDocument> docMock = new Mock <IDjvuDocument>(); List <IDjvuPage> pages = new List <IDjvuPage>(); docMock.Setup(x => x.Pages).Returns(pages); for (int i = 0; i < 300; i++) { Mock <IDjvuPage> pageMock = new Mock <IDjvuPage>(); pageMock.Setup(x => x.PageNumber).Returns(i + 1); pages.Add(pageMock.Object); } Mock <DjvuFormElement> parentMock = new Mock <DjvuFormElement> { CallBase = true }; using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) using (DjvuReader reader = new DjvuReader(stream)) { NavmChunk unk = new NavmChunk(reader, parentMock.Object, docMock.Object, "NAVM", stream.Length); Assert.Equal <ChunkType>(ChunkType.Navm, unk.ChunkType); Assert.Equal(stream.Length, unk.Length); Assert.Throws <DjvuFormatException>(() => unk.Bookmarks); } }
/// <summary> /// Decodes the data for the palette /// </summary> /// <returns></returns> private ColorPalette DecodePaletteData() { using (DjvuReader reader = Reader.CloneReader(_dataLocation, Length)) { // Read in the palette data return(new ColorPalette(reader)); } }
public Bookmark(DjvuReader reader, DjvuDocument document, Bookmark parent) { _document = document; _parent = parent; DecodeBookmarkData(reader); LoadReferencedPage(); }
/// <summary> /// Reads in the chunk data /// </summary> /// <param name="reader"></param> protected override void ReadChunkData(DjvuReader reader) { // Save the current position for delayed decoding _dataLocation = reader.Position; // Advance the reader reader.Position += Length; }
public void ReadHeaderWithError_Theory(string fileFormat, byte[] headerBuffer) { using (MemoryStream ms = new MemoryStream(headerBuffer)) using (DjvuReader reader = new DjvuReader(ms)) { Assert.Throws <DjvuFormatException>(() => ImageConverter.Read(reader)); } }
public void ColorPaletteTest002() { using (MemoryStream ms = new MemoryStream()) using (DjvuReader reader = new DjvuReader(ms)) { Assert.Throws <DjvuArgumentNullException>("parent", () => new ColorPalette(reader, null)); } }
protected override void ReadChunkData(DjvuReader reader) { // Save the data location for reading later _dataLocation = reader.Position; //Skip the thumbnail bytes which are delayed read reader.Position += Length; }
/// <summary> /// Reads in the chunk data /// </summary> /// <param name="reader"></param> private void ReadChunkHeader(DjvuReader reader) { ChunkID = reader.ReadUTF8String(4); if (IsSubFormChunk == false) { Length = reader.ReadInt32MSB(); } }
/// <summary> /// Progressively decodes the background image /// </summary> /// <param name="backgroundMap"></param> public IWPixelMap ProgressiveDecodeBackground(IWPixelMap backgroundMap) { using (DjvuReader reader = Reader.CloneReader(_dataLocation, Length)) { backgroundMap.Decode(reader); } return(backgroundMap); }
public void DjvuPageTest001() { using (MemoryStream stream = new MemoryStream()) using (DjvuReader reader = new DjvuReader(stream)) { ThumChunk form = new ThumChunk(reader, null, null, "THUM", 0); Assert.Throws <DjvuFormatException>(() => new DjvuPage(1, null, null, null, null, form)); } }
protected override void ReadChunkData(DjvuReader reader) { // Skip the data bytes which are delayed read reader.Position += Length; // CIDa is a known unknown chunk if (ChunkID != "CIDa") { //Console.WriteLine("Creating unknown chunk for: {0}", ChunkID); } }
public AnnotationChunk(DjvuReader reader, IFFChunk parent, DjvuDocument document) : base(reader, parent, document) { }
public ColorPalette(DjvuReader reader) { ReadPaletteData(reader); }
protected override void ReadChunkData(DjvuReader reader) { // Nothing }
public ThumChunk(DjvuReader reader, IFFChunk parent, DjvuDocument document) : base(reader, parent, document) { }
public FormChunk(DjvuReader reader, IFFChunk parent, DjvuDocument document) : base(reader, parent, document) { // Nothing }
/// <summary> /// Loads the bookmark data /// </summary> /// <param name="reader"></param> private void DecodeBookmarkData(DjvuReader reader) { int childrenCount = reader.ReadByte(); int textSize = reader.ReadInt24MSB(); Name = reader.ReadUTF8String(textSize); int urlSize = reader.ReadInt24MSB(); URL = reader.ReadUTF8String(urlSize); // Read in all the children bookmarks List<Bookmark> children = new List<Bookmark>(); for (int x = 0; x < childrenCount; x++) { children.Add(new Bookmark(reader, Document, this)); } _children = children.ToArray(); }
protected override void ReadChunkData(DjvuReader reader) { _includeID = reader.ReadUTF8String(Length); }
protected override void ReadChunkData(DjvuReader reader) { Width = reader.ReadInt16MSB(); Height = reader.ReadInt16MSB(); MinorVersion = reader.ReadSByte(); MajorVersion = reader.ReadSByte(); DPI = reader.ReadInt16(); // LSB Gamma = (float)reader.ReadByte() / 10; sbyte flag = reader.ReadSByte(); // B[3..0] PageRotation = (PageRotations)(flag & 0x07); }
/// <summary> /// Reads the compressed data from the djvu file /// </summary> /// <param name="reader"></param> /// <param name="count"></param> /// <param name="compressedSectionLength"></param> private void ReadCompressedData(DjvuReader reader, int count, int compressedSectionLength) { DjvuReader decompressor = reader.GetBZZEncodedReader(compressedSectionLength); // Read the component sizes for (int x = 0; x < count; x++) { _components[x].Size = decompressor.ReadInt24MSB(); } // Read the component flag information for (int x = 0; x < count; x++) { _components[x].DecodeFlags(decompressor.ReadSByte()); } // Read the component strings for (int x = 0; x < count; x++) { _components[x].ID = decompressor.ReadNullTerminatedString(); if (_components[x].HasName == true) _components[x].Name = decompressor.ReadNullTerminatedString(); if (_components[x].HasTitle == true) _components[x].Title = decompressor.ReadNullTerminatedString(); } _isInitialized = true; }
/// <summary> /// Reads the data for the components /// </summary> /// <param name="reader"></param> /// <param name="count"></param> private void ReadComponentData(DjvuReader reader, int count) { List<DirmComponent> components = new List<DirmComponent>(); // Read the offsets for the components for (int x = 0; x < count; x++) { int offset = reader.ReadInt32MSB(); components.Add(new DirmComponent(offset)); } _dataLocation = reader.Position; _isInitialized = false; _compressedSectionLength = (int)(Length - (reader.Position - Offset - 12)); // Skip the bytes since this section is delayed read reader.Position += _compressedSectionLength; _components = components.ToArray(); }
protected override void ReadChunkData(DjvuReader reader) { sbyte flagByte = reader.ReadSByte(); // B[7] IsBundled = (flagByte >> 7) == 1; // B[6..0] Version = flagByte & 127; int count = reader.ReadInt16MSB(); ReadComponentData(reader, count); }
protected override void ReadChunkData(DjvuReader reader) { // Need to figure out the decoding for the MMR format throw new NotImplementedException(); }
/// <summary> /// Decodes the data for the zone /// </summary> /// <param name="reader"></param> private void DecodeZoneData(DjvuReader reader, TextZone sibling, TextChunk chunkParent) { _zoneType = (ZoneTypes)reader.ReadByte(); _x = reader.ReadUInt16MSB() - 0x8000; _y = reader.ReadUInt16MSB() - 0x8000; _width = reader.ReadUInt16MSB() - 0x8000; _height = reader.ReadUInt16MSB() - 0x8000; _textOffset = reader.ReadUInt16MSB() - 0x8000; _textLength = reader.ReadInt24MSB(); ResolveOffsets(_parent, sibling); _rectangle = new Rectangle(_x, _y, _width, _height); int childrenZones = reader.ReadInt24MSB(); List<TextZone> children = new List<TextZone>(); TextZone childrenSibling = null; for (int x = 0; x < childrenZones; x++) { TextZone newZone = new TextZone(reader, this, childrenSibling, chunkParent); childrenSibling = newZone; children.Add(newZone); } _children = children.ToArray(); }
/// <summary> /// Decodes the palette data /// </summary> /// <param name="reader"></param> private void ReadPaletteData(DjvuReader reader) { sbyte header = reader.ReadSByte(); bool isShapeTable = (header >> 7) == 1; _version = header & 127; int paletteSize = reader.ReadInt16MSB(); // Read in the palette colors List<Pixel> paletteColors = new List<Pixel>(); for (int x = 0; x < paletteSize; x++) { sbyte b = reader.ReadSByte(); sbyte g = reader.ReadSByte(); sbyte r = reader.ReadSByte(); paletteColors.Add(new Pixel(b, g, r)); } _paletteColors = paletteColors.ToArray(); if (isShapeTable == true) { int totalBlits = reader.ReadInt24MSB(); DjvuReader compressed = reader.GetBZZEncodedReader(); // Read in the blit colors List<int> blitColors = new List<int>(); for (int x = 0; x < totalBlits; x++) { int index = compressed.ReadInt16MSB(); blitColors.Add(index); } _blitColors = blitColors.ToArray(); } }
/// <summary> /// Decodes the children of this chunk /// </summary> /// <param name="reader"></param> private void ReadChildren(DjvuReader reader) { List<IFFChunk> children = new List<IFFChunk>(); // Read in all the chunks while (reader.Position < Offset + Length + 8) { if (reader.Position % 2 == 1) { reader.Position++; } // Read the chunk ID string id = reader.ReadUTF8String(4); ChunkTypes type = IFFChunk.GetChunkType(id); // Reset the stream position reader.Position -= 4; var chunk = IFFChunk.BuildIFFChunk(reader, Document, this, type); if (chunk != null) { children.Add(chunk); } } Children = children.ToArray(); }