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

ReadRowRaw() private method

private ReadRowRaw ( int nrow ) : int
nrow int
return int
        private int ReadRowRaw(int nrow)
        {
            //
            if (nrow == 0 && FirstChunksNotYetRead())
                ReadFirstChunks();
            if (nrow == 0 && interlaced)
                Array.Clear(rowb, 0, rowb.Length); // new subimage: reset filters: this is enough, see the swap that happens lines
            // below
            int bytesRead = ImgInfo.BytesPerRow; // NOT including the filter byte
            if (interlaced) {
                if (nrow < 0 || nrow > deinterlacer.getRows() || (nrow != 0 && nrow != deinterlacer.getCurrRowSubimg() + 1))
                    throw new PngjInputException("invalid row in interlaced mode: " + nrow);
                deinterlacer.setRow(nrow);
                bytesRead = (ImgInfo.BitspPixel * deinterlacer.getPixelsToRead() + 7) / 8;
                if (bytesRead < 1)
                    throw new PngjExceptionInternal("wtf??");
            } else { // check for non interlaced
                if (nrow < 0 || nrow >= ImgInfo.Rows || nrow != rowNum + 1)
                    throw new PngjInputException("invalid row: " + nrow);
            }
            rowNum = nrow;
            // swap buffers
            byte[] tmp = rowb;
            rowb = rowbprev;
            rowbprev = tmp;
            // loads in rowbfilter "raw" bytes, with filter
            PngHelperInternal.ReadBytes(idatIstream, rowbfilter, 0, bytesRead + 1);
            offset = iIdatCstream.GetOffset();
            if (offset < 0)
                throw new PngjExceptionInternal("bad offset ??" + offset);
            if (MaxTotalBytesRead > 0 && offset >= MaxTotalBytesRead)
                throw new PngjInputException("Reading IDAT: Maximum total bytes to read exceeeded: " + MaxTotalBytesRead
                        + " offset:" + offset);
            rowb[0] = 0;
            UnfilterRow(bytesRead);
            rowb[0] = rowbfilter[0];
            if ((rowNum == ImgInfo.Rows - 1 && !interlaced) || (interlaced && deinterlacer.isAtLastRow()))
                ReadLastAndClose();
            return bytesRead;
        }