コード例 #1
0
        static public void testReadall()
        {
            long t0 = Environment.TickCount;

            for (int n = 0; n < 2000; n++)
            {
                String           f   = "C:/temp/z/zlibcs" + n + ".bin";
                Stream           bos = new FileStream(f, FileMode.Open);
                AZlibInputStream ist = ZlibStreamFactory.createZlibInputStream(bos, false);
                if (n == 0)
                {
                    Console.WriteLine("Using: " + ist);
                }
                byte[] res         = readAll(ist);
                long   expectedlen = n < 50 ? n : n * n - 7;
                if (res.Length != expectedlen)
                {
                    throw new Exception("error 0: " + f + " expected:" + expectedlen + " len=" + res.Length);
                }
                for (int i = 0; i < expectedlen; i++)
                {
                    if ((res[i] & 0xff) != ((i * 7) & 0xff))
                    {
                        throw new Exception("error 1: " + f);
                    }
                }
                //Console.WriteLine(f + " :" + expectedlen);
            }
            long t1 = Environment.TickCount;

            Console.WriteLine("read 3000 files in " + (t1 - t0));
        }
コード例 #2
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;
            }

            var clen    = 0;
            var found   = false;
            var chunkid = new byte[4]; // it's important to reallocate in each

            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;
                    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);
                }
                var chunkids = ChunkHelper.ToString(chunkid);
                if (chunkids.Equals(ChunkHelper.PLTE, System.StringComparison.Ordinal))
                {
                    CurrentChunkGroup = ChunksList.CHUNK_GROUP_2_PLTE;
                }

                ReadChunk(chunkid, clen, false);
                if (chunkids.Equals(ChunkHelper.PLTE, System.StringComparison.Ordinal))
                {
                    CurrentChunkGroup = ChunksList.CHUNK_GROUP_3_AFTERPLTE;
                }
            }

            var idatLen = found ? clen : -1;

            if (idatLen < 0)
            {
                throw new PngjInputException("first idat chunk not found!");
            }

            iIdatCstream = new PngIDatChunkInputStream(inputStream, idatLen, offset);
            idatIstream  = new ZlibInputStream(iIdatCstream, true);
        }
コード例 #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>
        ///
        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, 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, 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();
            }
        }
コード例 #4
0
ファイル: PngReader.cs プロジェクト: 1144822034/sc2.2mobile
        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();
            }
        }