DisableCrcCheck() private method

Disables CRC checking. This can make reading faster
private DisableCrcCheck ( ) : void
return void
Ejemplo n.º 1
0
 public void ReadSkippingAllRows()
 {
     if (FirstChunksNotYetRead())
     {
         ReadFirstChunks();
     }
     // we read directly from the compressed stream, we dont decompress nor chec CRC
     iIdatCstream.DisableCrcCheck();
     try {
         int r;
         do
         {
             r = iIdatCstream.Read(rowbfilter, 0, rowbfilter.Length);
         } while (r >= 0);
     } catch (IOException e) {
         throw new PngjInputException("error in raw read of IDAT", e);
     }
     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);
     }
     ReadLastAndClose();
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 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
        /// </summary>
        ///
        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();
            }
        }
Ejemplo n.º 4
0
        public void ReadFirstChunks()
        {
            if (!FirstChunksNotYetRead())
            {
                return;
            }
            int  num  = 0;
            bool flag = false;

            byte[] array = new byte[4];
            CurrentChunkGroup = 1;
            while (!flag)
            {
                num     = PngHelperInternal.ReadInt4(inputStream);
                offset += 4L;
                if (num < 0)
                {
                    break;
                }
                PngHelperInternal.ReadBytes(inputStream, array, 0, 4);
                offset += 4L;
                if (PngCsUtils.arraysEqual4(array, ChunkHelper.b_IDAT))
                {
                    flag = true;
                    CurrentChunkGroup = 4;
                    chunksList.AppendReadChunk(new PngChunkIDAT(ImgInfo, num, offset - 8), CurrentChunkGroup);
                    break;
                }
                if (PngCsUtils.arraysEqual4(array, ChunkHelper.b_IEND))
                {
                    throw new PngjInputException("END chunk found before image data (IDAT) at offset=" + offset.ToString());
                }
                string text = ChunkHelper.ToString(array);
                if (text.Equals("PLTE"))
                {
                    CurrentChunkGroup = 2;
                }
                ReadChunk(array, num, skipforced: false);
                if (text.Equals("PLTE"))
                {
                    CurrentChunkGroup = 3;
                }
            }
            int num2 = flag ? num : (-1);

            if (num2 < 0)
            {
                throw new PngjInputException("first idat chunk not found!");
            }
            iIdatCstream = new PngIDatChunkInputStream(inputStream, num2, offset);
            idatIstream  = ZlibStreamFactory.createZlibInputStream(iIdatCstream, leaveOpen: true);
            if (!crcEnabled)
            {
                iIdatCstream.DisableCrcCheck();
            }
        }
Ejemplo n.º 5
0
 private void ReadFirstChunks()
 {
     if ( !FirstChunksNotYetRead () )
         return;
     int clen = 0;
     bool found = false;
     byte [] chunkid = new byte [ 4 ];
     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;
             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 ();
 }