Hjg.Pngcs.PngReader.ReadFirstChunks C# (CSharp) Method

ReadFirstChunks() private method

Reads chunks before first IDAT. Position before: after IDHR (crc included) Position after: just after the first IDAT chunk id Returns length of first IDAT chunk , -1 if not found
private ReadFirstChunks ( ) : void
return void
        private void ReadFirstChunks()
        {
            if (!FirstChunksNotYetRead())
                return;
            int clen = 0;
            bool found = false;
            byte[] chunkid = new byte[4]; // it's important to reallocate in each
            this.CurrentChunkGroup = ChunksList.CHUNK_GROUP_1_AFTERIDHR;
            while (!found) {
                clen = PngHelperInternal.ReadInt4(inputStream);
                offset += 4;
                if (clen < 0)
                    break;
                PngHelperInternal.ReadBytes(inputStream, chunkid, 0, 4);
                offset += 4;
                if (PngCsUtils.arraysEqual4(chunkid, Hjg.Pngcs.Chunks.ChunkHelper.b_IDAT)) {
                    found = true;
                    this.CurrentChunkGroup = ChunksList.CHUNK_GROUP_4_IDAT;
                    // add dummy idat chunk to list
                    chunksList.AppendReadChunk(new PngChunkIDAT(ImgInfo, clen, offset - 8), CurrentChunkGroup);
                    break;
                } else if (PngCsUtils.arraysEqual4(chunkid, Hjg.Pngcs.Chunks.ChunkHelper.b_IEND)) {
                    throw new PngjInputException("END chunk found before image data (IDAT) at offset=" + offset);
                }
                String chunkids = ChunkHelper.ToString(chunkid);
                if (chunkids.Equals(ChunkHelper.PLTE))
                    this.CurrentChunkGroup = ChunksList.CHUNK_GROUP_2_PLTE;
                ReadChunk(chunkid, clen, false);
                if (chunkids.Equals(ChunkHelper.PLTE))
                    this.CurrentChunkGroup = ChunksList.CHUNK_GROUP_3_AFTERPLTE;
            }
            int idatLen = found ? clen : -1;
            if (idatLen < 0)
                throw new PngjInputException("first idat chunk not found!");
            iIdatCstream = new PngIDatChunkInputStream(inputStream, idatLen, offset);
            idatIstream = ZlibStreamFactory.createZlibInputStream(iIdatCstream, true);
            if (!crcEnabled)
                iIdatCstream.DisableCrcCheck();
        }