示例#1
0
        public int ReadRowRaw(int nrow)
        {
            if (nrow == 0 && FirstChunksNotYetRead())
            {
                ReadFirstChunks();
            }
            if (nrow == 0 && interlaced)
            {
                Array.Clear(rowb, 0, rowb.Length);
            }
            int num = ImgInfo.BytesPerRow;

            if (interlaced)
            {
                if (nrow < 0 || nrow > deinterlacer.getRows() || (nrow != 0 && nrow != deinterlacer.getCurrRowSubimg() + 1))
                {
                    throw new PngjInputException("invalid row in interlaced mode: " + nrow.ToString());
                }
                deinterlacer.setRow(nrow);
                num = (ImgInfo.BitspPixel * deinterlacer.getPixelsToRead() + 7) / 8;
                if (num < 1)
                {
                    throw new PngjExceptionInternal("wtf??");
                }
            }
            else if (nrow < 0 || nrow >= ImgInfo.Rows || nrow != rowNum + 1)
            {
                throw new PngjInputException("invalid row: " + nrow.ToString());
            }
            rowNum = nrow;
            byte[] array = rowb;
            rowb     = rowbprev;
            rowbprev = array;
            PngHelperInternal.ReadBytes(idatIstream, rowbfilter, 0, num + 1);
            offset = iIdatCstream.GetOffset();
            if (offset < 0)
            {
                throw new PngjExceptionInternal("bad offset ??" + offset.ToString());
            }
            if (MaxTotalBytesRead > 0 && offset >= MaxTotalBytesRead)
            {
                throw new PngjInputException("Reading IDAT: Maximum total bytes to read exceeeded: " + MaxTotalBytesRead.ToString() + " offset:" + offset.ToString());
            }
            rowb[0] = 0;
            UnfilterRow(num);
            rowb[0] = rowbfilter[0];
            if ((rowNum == ImgInfo.Rows - 1 && !interlaced) || (interlaced && deinterlacer.isAtLastRow()))
            {
                ReadLastAndClose();
            }
            return(num);
        }
示例#2
0
 public void ReadSkippingAllRows()
 {
     if (FirstChunksNotYetRead())
     {
         ReadFirstChunks();
     }
     iIdatCstream.DisableCrcCheck();
     try
     {
         int num;
         do
         {
             num = iIdatCstream.Read(rowbfilter, 0, rowbfilter.Length);
         }while (num >= 0);
     }
     catch (IOException cause)
     {
         throw new PngjInputException("error in raw read of IDAT", cause);
     }
     offset = iIdatCstream.GetOffset();
     if (offset < 0)
     {
         throw new PngjExceptionInternal("bad offset ??" + offset.ToString());
     }
     if (MaxTotalBytesRead > 0 && offset >= MaxTotalBytesRead)
     {
         throw new PngjInputException("Reading IDAT: Maximum total bytes to read exceeeded: " + MaxTotalBytesRead.ToString() + " offset:" + offset.ToString());
     }
     ReadLastAndClose();
 }
示例#3
0
        public PngChunk ReadChunk(byte[] chunkid, int clen, bool skipforced)
        {
            if (clen < 0)
            {
                throw new PngjInputException("invalid chunk lenght: " + clen.ToString());
            }
            if (skipChunkIdsSet == null && CurrentChunkGroup > 0)
            {
                skipChunkIdsSet = new Dictionary <string, int>();
                if (SkipChunkIds != null)
                {
                    string[] skipChunkIds = SkipChunkIds;
                    foreach (string key in skipChunkIds)
                    {
                        skipChunkIdsSet.Add(key, 1);
                    }
                }
            }
            string   text     = ChunkHelper.ToString(chunkid);
            PngChunk pngChunk = null;
            bool     flag     = ChunkHelper.IsCritical(text);
            bool     flag2    = skipforced;

            if (MaxTotalBytesRead > 0 && clen + offset > MaxTotalBytesRead)
            {
                throw new PngjInputException("Maximum total bytes to read exceeeded: " + MaxTotalBytesRead.ToString() + " offset:" + offset.ToString() + " clen=" + clen.ToString());
            }
            if (CurrentChunkGroup > 0 && !ChunkHelper.IsCritical(text))
            {
                flag2 = (flag2 || (SkipChunkMaxSize > 0 && clen >= SkipChunkMaxSize) || skipChunkIdsSet.ContainsKey(text) || (MaxBytesMetadata > 0 && clen > MaxBytesMetadata - bytesChunksLoaded) || !ChunkHelper.ShouldLoad(text, ChunkLoadBehaviour));
            }
            if (flag2)
            {
                PngHelperInternal.SkipBytes(inputStream, clen);
                PngHelperInternal.ReadInt4(inputStream);
                pngChunk = new PngChunkSkipped(text, ImgInfo, clen);
            }
            else
            {
                ChunkRaw chunkRaw = new ChunkRaw(clen, chunkid, alloc: true);
                chunkRaw.ReadChunkData(inputStream, crcEnabled | flag);
                pngChunk = PngChunk.Factory(chunkRaw, ImgInfo);
                if (!pngChunk.Crit)
                {
                    bytesChunksLoaded += chunkRaw.Length;
                }
            }
            pngChunk.Offset = offset - 8;
            chunksList.AppendReadChunk(pngChunk, CurrentChunkGroup);
            offset += (long)clen + 4L;
            return(pngChunk);
        }