コード例 #1
0
ファイル: TestZlib.cs プロジェクト: NoobsArePeople2/pngcs
 /*
 val= 3066839698
 val= 0
 val= 3799812176 t=14446
  */
 public static void testCRC32()
 {
     CRC32 crc1 = new CRC32();
     crc1.Update(new byte[] { 1, 2 });
     if (crc1.GetValue() != 3066839698) throw new Exception("Bad CRC32!");
     Console.WriteLine("Testing CRC32");
     Console.WriteLine("val= " + crc1.GetValue());
     crc1.Reset();
     Console.WriteLine("val= " + crc1.GetValue());
     if (crc1.GetValue() != 0) throw new Exception("Bad CRC32!!");
     Random r = new Random();
     byte[] all = new byte[2000 * 4];
     long t0 = Environment.TickCount;
     for (int n = 0; n < 2000; n++) {
         byte[] b = createBytes7(n < 50 ? n : n * n - 7);
         CRC32 crc = new CRC32();
         int offset = 0;
         while (offset < b.Length) {
             int len = r.Next(b.Length - offset) + 1;
             crc.Update(b, offset, len);
             offset += len;
         }
         long x = crc.GetValue();
         all[n * 4] = (byte)((x >> 24) & 0xff);
         all[n * 4 + 1] = (byte)((x >> 16) & 0xff);
         all[n * 4 + 2] = (byte)((x >> 8) & 0xff);
         all[n * 4 + 3] = (byte)((x) & 0xff);
     }
     long t1 = Environment.TickCount;
     Adler32 a = new Adler32();
     a.Update(all);
     long v = a.GetValue();
     Console.WriteLine("val= " + v + " t=" + (t1 - t0));
     if (v != 3799812176) throw new Exception("Bad cRC32");// tested with Java CRC32
 }
コード例 #2
0
 public PngIDatChunkInputStream( Stream iStream, int lenFirstChunk, long offset_0 )
 {
     this.idLastChunk = new byte [ 4 ];
     this.toReadThisChunk = 0;
     this.ended = false;
     this.foundChunksInfo = new List<IdatChunkInfo> ();
     this.offset = offset_0;
     checkCrc = true;
     inputStream = iStream;
     crcEngine = new CRC32 ();
     this.lenLastChunk = lenFirstChunk;
     toReadThisChunk = lenFirstChunk;
     System.Array.Copy ( ( Array ) ( Hjg.Pngcs.Chunks.ChunkHelper.b_IDAT ), 0, ( Array ) ( idLastChunk ), 0, 4 );
     crcEngine.Update ( idLastChunk, 0, 4 );
     foundChunksInfo.Add ( new PngIDatChunkInputStream.IdatChunkInfo ( lenLastChunk, offset_0 - 8 ) );
     if ( this.lenLastChunk == 0 )
         EndChunkGoForNext ();
 }
コード例 #3
0
 /// <summary>
 /// Constructor must be called just after reading length and id of first IDAT
 /// chunk
 /// </summary>
 ///
 public PngIDatChunkInputStream(Stream iStream, int lenFirstChunk, long offset_0)
 {
     this.idLastChunk     = new byte[4];
     this.toReadThisChunk = 0;
     this.ended           = false;
     this.foundChunksInfo = new List <IdatChunkInfo>();
     this.offset          = offset_0;
     checkCrc             = true;
     inputStream          = iStream;
     crcEngine            = new CRC32();
     this.lenLastChunk    = lenFirstChunk;
     toReadThisChunk      = lenFirstChunk;
     // we know it's a IDAT
     System.Array.Copy((Hjg.Pngcs.Chunks.ChunkHelper.b_IDAT), 0, (idLastChunk), 0, 4);
     crcEngine.Update(idLastChunk, 0, 4);
     foundChunksInfo.Add(new PngIDatChunkInputStream.IdatChunkInfo(lenLastChunk, offset_0 - 8));
     // PngHelper.logdebug("IDAT Initial fragment: len=" + lenLastChunk);
     if (this.lenLastChunk == 0)
     {
         EndChunkGoForNext(); // rare, but...
     }
 }
コード例 #4
0
ファイル: PngHelperInternal.cs プロジェクト: Daramkun/Misty
 public static CRC32 GetCRC()
 {
     if ( crc32Engine == null ) crc32Engine = new CRC32 ();
     return crc32Engine;
 }