Wraps the raw chunk data
Short lived object, to be created while serialing/deserializing Do not reuse it for different chunks See http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html
コード例 #1
0
ファイル: PngChunkGAMA.cs プロジェクト: NoobsArePeople2/pngcs
 public override void ParseFromRaw(ChunkRaw chunk)
 {
     if (chunk.Length != 4)
         throw new PngjException("bad chunk " + chunk);
     int g = Hjg.Pngcs.PngHelperInternal.ReadInt4fromBytes(chunk.Data, 0);
     gamma = ((double)g) / 100000.0d;
 }
コード例 #2
0
ファイル: ChunkReader.cs プロジェクト: facemao3/pngcs
        private int crcn = 0; // how many bytes have been read from crc

        #endregion Fields

        #region Constructors

        public ChunkReader(int clen, String id, long offsetInPng, ChunkReaderMode mode)
        {
            if (mode == null || id.Length != 4 || clen < 0)
                throw new PngjExceptionInternal("Bad chunk paramenters: " + mode);
            this.mode = mode;
            chunkRaw = new ChunkRaw(clen, id, mode == ChunkReaderMode.BUFFER);
            chunkRaw.setOffset(offsetInPng);
            this.crcCheck = mode == ChunkReaderMode.SKIP ? false : true; // can be changed with setter
        }
コード例 #3
0
ファイル: PngChunkTEXT.cs プロジェクト: Daramkun/Misty
 public override void ParseFromRaw( ChunkRaw c )
 {
     int i;
     for ( i = 0; i < c.Data.Length; i++ )
         if ( c.Data [ i ] == 0 )
             break;
     key = Hjg.Pngcs.PngHelperInternal.charsetLatin1.GetString ( c.Data, 0, i );
     i++;
     val = i < c.Data.Length ? Hjg.Pngcs.PngHelperInternal.charsetLatin1.GetString ( c.Data, i, c.Data.Length - i ) : "";
 }
コード例 #4
0
ファイル: PngChunkHIST.cs プロジェクト: gitter-badger/blimey
 public override void ParseFromRaw(ChunkRaw c)
 {
     if (!ImgInfo.Indexed)
         throw new PngjException("only indexed images accept a HIST chunk");
     int nentries = c.Data.Length / 2;
     hist = new int[nentries];
     for (int i = 0; i < hist.Length; i++) {
         hist[i] = PngHelperInternal.ReadInt2fromBytes(c.Data, i * 2);
     }
 }
コード例 #5
0
ファイル: PngChunkTIME.cs プロジェクト: Daramkun/Misty
 public override void ParseFromRaw( ChunkRaw chunk )
 {
     if ( chunk.Length != 7 )
         throw new PngjException ( "bad chunk " + chunk );
     year = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes ( chunk.Data, 0 );
     mon = Hjg.Pngcs.PngHelperInternal.ReadInt1fromByte ( chunk.Data, 2 );
     day = Hjg.Pngcs.PngHelperInternal.ReadInt1fromByte ( chunk.Data, 3 );
     hour = Hjg.Pngcs.PngHelperInternal.ReadInt1fromByte ( chunk.Data, 4 );
     min = Hjg.Pngcs.PngHelperInternal.ReadInt1fromByte ( chunk.Data, 5 );
     sec = Hjg.Pngcs.PngHelperInternal.ReadInt1fromByte ( chunk.Data, 6 );
 }
コード例 #6
0
ファイル: PngChunkICCP.cs プロジェクト: gitter-badger/blimey
 public override void ParseFromRaw(ChunkRaw chunk)
 {
     int pos0 = Hjg.Pngcs.Chunks.ChunkHelper.PosNullByte(chunk.Data);
     profileName = Hjg.Pngcs.PngHelperInternal.charsetLatin1.GetString(chunk.Data, 0, pos0);
     int comp = (chunk.Data[pos0 + 1] & 0xff);
     if (comp != 0)
         throw new Exception("bad compression for ChunkTypeICCP");
     int compdatasize = chunk.Data.Length - (pos0 + 2);
     compressedProfile = new byte[compdatasize];
     System.Array.Copy((Array)(chunk.Data), pos0 + 2, (Array)(compressedProfile), 0, compdatasize);
 }
コード例 #7
0
ファイル: PngChunkPHYS.cs プロジェクト: Daramkun/Misty
 public override void ParseFromRaw( ChunkRaw chunk )
 {
     if ( chunk.Length != 9 )
         throw new PngjException ( "bad chunk length " + chunk );
     PixelsxUnitX = Hjg.Pngcs.PngHelperInternal.ReadInt4fromBytes ( chunk.Data, 0 );
     if ( PixelsxUnitX < 0 )
         PixelsxUnitX += 0x100000000L;
     PixelsxUnitY = Hjg.Pngcs.PngHelperInternal.ReadInt4fromBytes ( chunk.Data, 4 );
     if ( PixelsxUnitY < 0 )
         PixelsxUnitY += 0x100000000L;
     Units = Hjg.Pngcs.PngHelperInternal.ReadInt1fromByte ( chunk.Data, 8 );
 }
コード例 #8
0
ファイル: PngChunkOFFS.cs プロジェクト: Daramkun/Misty
 public override void ParseFromRaw( ChunkRaw chunk )
 {
     if ( chunk.Length != 9 )
         throw new PngjException ( "bad chunk length " + chunk );
     posX = PngHelperInternal.ReadInt4fromBytes ( chunk.Data, 0 );
     if ( posX < 0 )
         posX += 0x100000000L;
     posY = PngHelperInternal.ReadInt4fromBytes ( chunk.Data, 4 );
     if ( posY < 0 )
         posY += 0x100000000L;
     units = PngHelperInternal.ReadInt1fromByte ( chunk.Data, 8 );
 }
コード例 #9
0
ファイル: PngChunkCHRM.cs プロジェクト: gitter-badger/blimey
 public override void ParseFromRaw(ChunkRaw c)
 {
     if (c.Length != 32)
         throw new PngjException("bad chunk " + c);
     whitex = PngHelperInternal.IntToDouble100000(PngHelperInternal.ReadInt4fromBytes(c.Data, 0));
     whitey = PngHelperInternal.IntToDouble100000(PngHelperInternal.ReadInt4fromBytes(c.Data, 4));
     redx = PngHelperInternal.IntToDouble100000(PngHelperInternal.ReadInt4fromBytes(c.Data, 8));
     redy = PngHelperInternal.IntToDouble100000(PngHelperInternal.ReadInt4fromBytes(c.Data, 12));
     greenx = PngHelperInternal.IntToDouble100000(PngHelperInternal.ReadInt4fromBytes(c.Data, 16));
     greeny = PngHelperInternal.IntToDouble100000(PngHelperInternal.ReadInt4fromBytes(c.Data, 20));
     bluex = PngHelperInternal.IntToDouble100000(PngHelperInternal.ReadInt4fromBytes(c.Data, 24));
     bluey = PngHelperInternal.IntToDouble100000(PngHelperInternal.ReadInt4fromBytes(c.Data, 28));
 }
コード例 #10
0
ファイル: PngChunkIHDR.cs プロジェクト: Daramkun/Misty
 public override ChunkRaw CreateRawChunk()
 {
     ChunkRaw c = new ChunkRaw ( 13, ChunkHelper.b_IHDR, true );
     int offset = 0;
     Hjg.Pngcs.PngHelperInternal.WriteInt4tobytes ( Cols, c.Data, offset );
     offset += 4;
     Hjg.Pngcs.PngHelperInternal.WriteInt4tobytes ( Rows, c.Data, offset );
     offset += 4;
     c.Data [ offset++ ] = ( byte ) Bitspc;
     c.Data [ offset++ ] = ( byte ) Colormodel;
     c.Data [ offset++ ] = ( byte ) Compmeth;
     c.Data [ offset++ ] = ( byte ) Filmeth;
     c.Data [ offset++ ] = ( byte ) Interlaced;
     return c;
 }
コード例 #11
0
ファイル: PngChunkIHDR.cs プロジェクト: git-thinh/limada
        public override void ParseFromRaw(ChunkRaw c)
        {
            if (c.Length != 13)
            {
                throw new PngjException("Bad IDHR len " + c.Length);
            }
            MemoryStream st = c.GetAsByteStream();

            Cols = Hjg.Pngcs.PngHelperInternal.ReadInt4(st);
            Rows = Hjg.Pngcs.PngHelperInternal.ReadInt4(st);
            // bit depth: number of bits per channel
            Bitspc     = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
            Colormodel = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
            Compmeth   = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
            Filmeth    = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
            Interlaced = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
        }
コード例 #12
0
        public override ChunkRaw CreateRawChunk()
        {
            int len = 3 * nentries;

            int[]    array    = new int[3];
            ChunkRaw chunkRaw = createEmptyChunk(len, alloc: true);
            int      i        = 0;
            int      num      = 0;

            for (; i < nentries; i++)
            {
                GetEntryRgb(i, array);
                chunkRaw.Data[num++] = (byte)array[0];
                chunkRaw.Data[num++] = (byte)array[1];
                chunkRaw.Data[num++] = (byte)array[2];
            }
            return(chunkRaw);
        }
コード例 #13
0
ファイル: PngChunkZTXT.cs プロジェクト: NoobsArePeople2/pngcs
 public override void ParseFromRaw(ChunkRaw c)
 {
     int nullsep = -1;
     for (int i = 0; i < c.Data.Length; i++) { // look for first zero
         if (c.Data[i] != 0)
             continue;
         nullsep = i;
         break;
     }
     if (nullsep < 0 || nullsep > c.Data.Length - 2)
         throw new PngjException("bad zTXt chunk: no separator found");
     key = ChunkHelper.ToString(c.Data, 0, nullsep);
     int compmet = (int)c.Data[nullsep + 1];
     if (compmet != 0)
         throw new PngjException("bad zTXt chunk: unknown compression method");
     byte[] uncomp = ChunkHelper.compressBytes(c.Data, nullsep + 2, c.Data.Length - nullsep - 2, false); // uncompress
     val = ChunkHelper.ToString(uncomp);
 }
コード例 #14
0
 public override void ParseFromRaw(ChunkRaw chunk)
 {
     if (chunk.Length != 9)
     {
         throw new PngjException("bad chunk length " + chunk);
     }
     PixelsxUnitX = Hjg.Pngcs.PngHelperInternal.ReadInt4fromBytes(chunk.Data, 0);
     if (PixelsxUnitX < 0)
     {
         PixelsxUnitX += 0x100000000L;
     }
     PixelsxUnitY = Hjg.Pngcs.PngHelperInternal.ReadInt4fromBytes(chunk.Data, 4);
     if (PixelsxUnitY < 0)
     {
         PixelsxUnitY += 0x100000000L;
     }
     Units = Hjg.Pngcs.PngHelperInternal.ReadInt1fromByte(chunk.Data, 8);
 }
コード例 #15
0
 public override void ParseFromRaw(ChunkRaw chunk)
 {
     if (chunk.Len != 9)
     {
         throw new PngjException("bad chunk length " + chunk);
     }
     posX = PngHelperInternal.ReadInt4fromBytes(chunk.Data, 0);
     if (posX < 0)
     {
         posX += 0x100000000L;
     }
     posY = PngHelperInternal.ReadInt4fromBytes(chunk.Data, 4);
     if (posY < 0)
     {
         posY += 0x100000000L;
     }
     units = PngHelperInternal.ReadInt1fromByte(chunk.Data, 8);
 }
コード例 #16
0
        public override ChunkRaw CreateRawChunk()
        {
            if (key.Length == 0)
            {
                throw new PngjException("Text chunk key must be non empty");
            }
            MemoryStream memoryStream = new MemoryStream();

            ChunkHelper.WriteBytesToStream(memoryStream, ChunkHelper.ToBytes(key));
            memoryStream.WriteByte(0);
            memoryStream.WriteByte(0);
            byte[] bytes = ChunkHelper.compressBytes(ChunkHelper.ToBytes(val), compress: true);
            ChunkHelper.WriteBytesToStream(memoryStream, bytes);
            byte[]   array    = memoryStream.ToArray();
            ChunkRaw chunkRaw = createEmptyChunk(array.Length, alloc: false);

            chunkRaw.Data = array;
            return(chunkRaw);
        }
コード例 #17
0
        public override ChunkRaw CreateRawChunk()
        {
            if (key.Length == 0)
            {
                throw new PngjException("Text chunk key must be non empty");
            }
            MemoryStream ba = new MemoryStream();

            ChunkHelper.WriteBytesToStream(ba, ChunkHelper.ToBytes(key));
            ba.WriteByte(0); // separator
            ba.WriteByte(0); // compression method: 0
            byte[] textbytes = ChunkHelper.compressBytes(ChunkHelper.ToBytes(val), true);
            ChunkHelper.WriteBytesToStream(ba, textbytes);
            byte[]   b     = ba.ToArray();
            ChunkRaw chunk = createEmptyChunk(b.Length, false);

            chunk.Data = b;
            return(chunk);
        }
コード例 #18
0
ファイル: PngChunkHIST.cs プロジェクト: Chapmania/Juniper
        public override void ParseFromRaw(ChunkRaw c)
        {
            if (c is null)
            {
                throw new ArgumentNullException(nameof(c));
            }

            if (!ImgInfo.Indexed)
            {
                throw new PngjException("only indexed images accept a HIST chunk");
            }

            var nentries = c.Data.Length / 2;

            hist = new int[nentries];
            for (var i = 0; i < hist.Length; i++)
            {
                hist[i] = PngHelperInternal.ReadInt2fromBytes(c.Data, i * 2);
            }
        }
コード例 #19
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            if (c is null)
            {
                throw new ArgumentNullException(nameof(c));
            }

            int i;

            for (i = 0; i < c.Data.Length; i++)
            {
                if (c.Data[i] == 0)
                {
                    break;
                }
            }

            Key = PngHelperInternal.charsetLatin1.GetString(c.Data, 0, i);
            i++;
            Val = i < c.Data.Length ? PngHelperInternal.charsetLatin1.GetString(c.Data, i, c.Data.Length - i) : "";
        }
コード例 #20
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            if (c is null)
            {
                throw new ArgumentNullException(nameof(c));
            }

            var pos0 = Hjg.Pngcs.Chunks.ChunkHelper.PosNullByte(c.Data);

            profileName = Hjg.Pngcs.PngHelperInternal.charsetLatin1.GetString(c.Data, 0, pos0);
            var comp = (c.Data[pos0 + 1] & 0xff);

            if (comp != 0)
            {
                throw new Exception("bad compression for ChunkTypeICCP");
            }

            var compdatasize = c.Data.Length - (pos0 + 2);

            compressedProfile = new byte[compdatasize];
            Array.Copy(c.Data, pos0 + 2, compressedProfile, 0, compdatasize);
        }
コード例 #21
0
 public override void ParseFromRaw(ChunkRaw c)
 {
     if (ImgInfo.Greyscale)
     {
         gray = PngHelperInternal.ReadInt2fromBytes(c.Data, 0);
     }
     else if (ImgInfo.Indexed)
     {
         int num = c.Data.Length;
         paletteAlpha = new int[num];
         for (int i = 0; i < num; i++)
         {
             paletteAlpha[i] = (c.Data[i] & 0xFF);
         }
     }
     else
     {
         red   = PngHelperInternal.ReadInt2fromBytes(c.Data, 0);
         green = PngHelperInternal.ReadInt2fromBytes(c.Data, 2);
         blue  = PngHelperInternal.ReadInt2fromBytes(c.Data, 4);
     }
 }
コード例 #22
0
 public override void ParseFromRaw(ChunkRaw c)
 {
     if (ImgInfo.Greyscale)
     {
         gray = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes(c.Data, 0);
     }
     else if (ImgInfo.Indexed)
     {
         int nentries = c.Data.Length;
         paletteAlpha = new int[nentries];
         for (int n = 0; n < nentries; n++)
         {
             paletteAlpha[n] = (int)(c.Data[n] & 0xff);
         }
     }
     else
     {
         red   = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes(c.Data, 0);
         green = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes(c.Data, 2);
         blue  = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes(c.Data, 4);
     }
 }
コード例 #23
0
ファイル: PngChunkIHDR.cs プロジェクト: Chapmania/Juniper
        public override void ParseFromRaw(ChunkRaw c)
        {
            if (c is null)
            {
                throw new System.ArgumentNullException(nameof(c));
            }

            if (c.Len != 13)
            {
                throw new PngjException("Bad IDHR len " + c.Len.ToString(CultureInfo.CurrentCulture));
            }

            using var st = c.GetAsByteStream();
            Cols         = Hjg.Pngcs.PngHelperInternal.ReadInt4(st);
            Rows         = Hjg.Pngcs.PngHelperInternal.ReadInt4(st);
            // bit depth: number of bits per channel
            Bitspc     = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
            Colormodel = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
            Compmeth   = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
            Filmeth    = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
            Interlaced = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
        }
コード例 #24
0
        public override ChunkRaw CreateRawChunk()
        {
            ChunkRaw c = null;

            if (ImgInfo.Greyscale)
            {
                c = createEmptyChunk(2, true);
                Hjg.Pngcs.PngHelperInternal.WriteInt2tobytes(gray, c.Data, 0);
            }
            else if (ImgInfo.Indexed)
            {
                c         = createEmptyChunk(1, true);
                c.Data[0] = (byte)paletteIndex;
            }
            else
            {
                c = createEmptyChunk(6, true);
                PngHelperInternal.WriteInt2tobytes(red, c.Data, 0);
                Hjg.Pngcs.PngHelperInternal.WriteInt2tobytes(green, c.Data, 0);
                Hjg.Pngcs.PngHelperInternal.WriteInt2tobytes(blue, c.Data, 0);
            }
            return(c);
        }
コード例 #25
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            if (c is null)
            {
                throw new ArgumentNullException(nameof(c));
            }

            var nullsep = -1;

            for (var i = 0; i < c.Data.Length; i++)
            { // look for first zero
                if (c.Data[i] != 0)
                {
                    continue;
                }

                nullsep = i;
                break;
            }

            if (nullsep < 0 || nullsep > c.Data.Length - 2)
            {
                throw new PngjException("bad zTXt chunk: no separator found");
            }

            Key = ChunkHelper.ToString(c.Data, 0, nullsep);
            var compmet = (int)c.Data[nullsep + 1];

            if (compmet != 0)
            {
                throw new PngjException("bad zTXt chunk: unknown compression method");
            }

            var uncomp = ChunkHelper.CompressBytes(c.Data, nullsep + 2, c.Data.Length - nullsep - 2, false); // uncompress

            Val = ChunkHelper.ToString(uncomp);
        }
コード例 #26
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            int num = -1;

            for (int i = 0; i < c.Data.Length; i++)
            {
                if (c.Data[i] == 0)
                {
                    num = i;
                    break;
                }
            }
            if (num < 0 || num > c.Data.Length - 2)
            {
                throw new PngjException("bad zTXt chunk: no separator found");
            }
            key = ChunkHelper.ToString(c.Data, 0, num);
            if (c.Data[num + 1] != 0)
            {
                throw new PngjException("bad zTXt chunk: unknown compression method");
            }
            byte[] x = ChunkHelper.compressBytes(c.Data, num + 2, c.Data.Length - num - 2, compress: false);
            val = ChunkHelper.ToString(x);
        }
コード例 #27
0
ファイル: PngChunkITXT.cs プロジェクト: Daramkun/Misty
 public override void ParseFromRaw( ChunkRaw c )
 {
     int nullsFound = 0;
     int [] nullsIdx = new int [ 3 ];
     for ( int k = 0; k < c.Data.Length; k++ )
     {
         if ( c.Data [ k ] != 0 )
             continue;
         nullsIdx [ nullsFound ] = k;
         nullsFound++;
         if ( nullsFound == 1 )
             k += 2;
         if ( nullsFound == 3 )
             break;
     }
     if ( nullsFound != 3 )
         throw new PngjException ( "Bad formed PngChunkITXT chunk" );
     key = ChunkHelper.ToString ( c.Data, 0, nullsIdx [ 0 ] );
     int i = nullsIdx [ 0 ] + 1;
     compressed = c.Data [ i ] == 0 ? false : true;
     i++;
     if ( compressed && c.Data [ i ] != 0 )
         throw new PngjException ( "Bad formed PngChunkITXT chunk - bad compression method " );
     langTag = ChunkHelper.ToString ( c.Data, i, nullsIdx [ 1 ] - i );
     translatedTag = ChunkHelper.ToStringUTF8 ( c.Data, nullsIdx [ 1 ] + 1, nullsIdx [ 2 ] - nullsIdx [ 1 ] - 1 );
     i = nullsIdx [ 2 ] + 1;
     if ( compressed )
     {
         byte [] bytes = ChunkHelper.compressBytes ( c.Data, i, c.Data.Length - i, false );
         val = ChunkHelper.ToStringUTF8 ( bytes );
     }
     else
     {
         val = ChunkHelper.ToStringUTF8 ( c.Data, i, c.Data.Length - i );
     }
 }
コード例 #28
0
 protected override void FlushBuffer( byte [] b, int len )
 {
     ChunkRaw c = new ChunkRaw ( len, Hjg.Pngcs.Chunks.ChunkHelper.b_IDAT, false );
     c.Data = b;
     c.WriteChunk ( outputStream );
 }
コード例 #29
0
ファイル: PngChunkTRNS.cs プロジェクト: NoobsArePeople2/pngcs
 public override void ParseFromRaw(ChunkRaw c)
 {
     if (ImgInfo.Greyscale) {
         gray = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes(c.Data, 0);
     } else if (ImgInfo.Indexed) {
         int nentries = c.Data.Length;
         paletteAlpha = new int[nentries];
         for (int n = 0; n < nentries; n++) {
             paletteAlpha[n] = (int)(c.Data[n] & 0xff);
         }
     } else {
         red = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes(c.Data, 0);
         green = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes(c.Data, 2);
         blue = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes(c.Data, 4);
     }
 }
コード例 #30
0
ファイル: PngChunkUNKNOWN.cs プロジェクト: git-thinh/limada
 public override ChunkRaw CreateRawChunk()
 {
     ChunkRaw p = createEmptyChunk(data.Length, false);
     p.Data = this.data;
     return p;
 }
コード例 #31
0
ファイル: PngChunk.cs プロジェクト: ondrejmyska/pngcs
 /// <summary>
 /// Deserialization. Given a Raw chunk, just rad, fills this chunk content
 /// </summary>
 public abstract void ParseFromRaw(ChunkRaw c);
コード例 #32
0
ファイル: PngSkin.cs プロジェクト: johnkramerr/Sc2tvChatPub
 public override void ParseFromRaw( ChunkRaw c )
 {
     Content = Encoding.UTF8.GetString(c.Data);
 }
コード例 #33
0
ファイル: PngChunkPLTE.cs プロジェクト: Daramkun/Misty
 public override void ParseFromRaw( ChunkRaw chunk )
 {
     SetNentries ( chunk.Length / 3 );
     for ( int n = 0, i = 0; n < nentries; n++ )
     {
         SetEntry ( n, ( int ) ( chunk.Data [ i++ ] & 0xff ), ( int ) ( chunk.Data [ i++ ] & 0xff ),
                 ( int ) ( chunk.Data [ i++ ] & 0xff ) );
     }
 }
コード例 #34
0
ファイル: PngChunkSPLT.cs プロジェクト: gitter-badger/blimey
 public override void ParseFromRaw(ChunkRaw c)
 {
     int t = -1;
     for (int i = 0; i < c.Data.Length; i++) { // look for first zero
         if (c.Data[i] == 0) {
             t = i;
             break;
         }
     }
     if (t <= 0 || t > c.Data.Length - 2)
         throw new PngjException("bad sPLT chunk: no separator found");
     PalName = ChunkHelper.ToString(c.Data, 0, t);
     SampleDepth = PngHelperInternal.ReadInt1fromByte(c.Data, t + 1);
     t += 2;
     int nentries = (c.Data.Length - t) / (SampleDepth == 8 ? 6 : 10);
     Palette = new int[nentries * 5];
     int r, g, b, a, f, ne;
     ne = 0;
     for (int i = 0; i < nentries; i++) {
         if (SampleDepth == 8) {
             r = PngHelperInternal.ReadInt1fromByte(c.Data, t++);
             g = PngHelperInternal.ReadInt1fromByte(c.Data, t++);
             b = PngHelperInternal.ReadInt1fromByte(c.Data, t++);
             a = PngHelperInternal.ReadInt1fromByte(c.Data, t++);
         } else {
             r = PngHelperInternal.ReadInt2fromBytes(c.Data, t);
             t += 2;
             g = PngHelperInternal.ReadInt2fromBytes(c.Data, t);
             t += 2;
             b = PngHelperInternal.ReadInt2fromBytes(c.Data, t);
             t += 2;
             a = PngHelperInternal.ReadInt2fromBytes(c.Data, t);
             t += 2;
         }
         f = PngHelperInternal.ReadInt2fromBytes(c.Data, t);
         t += 2;
         Palette[ne++] = r;
         Palette[ne++] = g;
         Palette[ne++] = b;
         Palette[ne++] = a;
         Palette[ne++] = f;
     }
 }
コード例 #35
0
ファイル: PngReader.cs プロジェクト: Daramkun/Misty
        private PngChunk ReadChunk( byte [] chunkid, int clen, bool skipforced )
        {
            if ( clen < 0 ) throw new PngjInputException ( "invalid chunk lenght: " + clen );
            if ( skipChunkIdsSet == null && CurrentChunkGroup > ChunksList.CHUNK_GROUP_0_IDHR )
            {
                skipChunkIdsSet = new Dictionary<string, int> ();
                if ( SkipChunkIds != null )
                    foreach ( string id in SkipChunkIds ) skipChunkIdsSet.Add ( id, 1 );
            }

            String chunkidstr = ChunkHelper.ToString ( chunkid );
            PngChunk pngChunk = null;
            bool critical = ChunkHelper.IsCritical ( chunkidstr );
            bool skip = skipforced;
            if ( MaxTotalBytesRead > 0 && clen + offset > MaxTotalBytesRead )
                throw new PngjInputException ( "Maximum total bytes to read exceeeded: " + MaxTotalBytesRead + " offset:"
                        + offset + " clen=" + clen );
            if ( CurrentChunkGroup > ChunksList.CHUNK_GROUP_0_IDHR && !ChunkHelper.IsCritical ( chunkidstr ) )
                skip = skip || ( SkipChunkMaxSize > 0 && clen >= SkipChunkMaxSize ) || skipChunkIdsSet.ContainsKey ( chunkidstr )
                        || ( MaxBytesMetadata > 0 && clen > MaxBytesMetadata - bytesChunksLoaded )
                        || !ChunkHelper.ShouldLoad ( chunkidstr, ChunkLoadBehaviour );

            if ( skip )
            {
                PngHelperInternal.SkipBytes ( inputStream, clen );
                PngHelperInternal.ReadInt4 ( inputStream );
                pngChunk = new PngChunkSkipped ( chunkidstr, ImgInfo, clen );
            }
            else
            {
                ChunkRaw chunk = new ChunkRaw ( clen, chunkid, true );
                chunk.ReadChunkData ( inputStream, crcEnabled || critical );
                pngChunk = PngChunk.Factory ( chunk, ImgInfo );
                if ( !pngChunk.Crit )
                {
                    bytesChunksLoaded += chunk.Length;
                }

            }
            pngChunk.Offset = offset - 8L;
            chunksList.AppendReadChunk ( pngChunk, CurrentChunkGroup );
            offset += clen + 4L;
            return pngChunk;
        }
コード例 #36
0
ファイル: PngChunkIDAT.cs プロジェクト: LonghronShen/pngcs
 public override void ParseFromRaw(ChunkRaw c) { // does nothing
 }
コード例 #37
0
ファイル: PngChunkBKGD.cs プロジェクト: Daramkun/Misty
 public override void ParseFromRaw( ChunkRaw c )
 {
     if ( ImgInfo.Greyscale )
     {
         gray = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes ( c.Data, 0 );
     }
     else if ( ImgInfo.Indexed )
     {
         paletteIndex = ( int ) ( c.Data [ 0 ] & 0xff );
     }
     else
     {
         red = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes ( c.Data, 0 );
         green = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes ( c.Data, 2 );
         blue = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes ( c.Data, 4 );
     }
 }
コード例 #38
0
ファイル: PngChunkSBIT.cs プロジェクト: gitter-badger/blimey
 public override void ParseFromRaw(ChunkRaw c)
 {
     if (c.Length != GetLen())
         throw new PngjException("bad chunk length " + c);
     if (ImgInfo.Greyscale) {
         Graysb = PngHelperInternal.ReadInt1fromByte(c.Data, 0);
         if (ImgInfo.Alpha)
             Alphasb = PngHelperInternal.ReadInt1fromByte(c.Data, 1);
     } else {
         Redsb = PngHelperInternal.ReadInt1fromByte(c.Data, 0);
         Greensb = PngHelperInternal.ReadInt1fromByte(c.Data, 1);
         Bluesb = PngHelperInternal.ReadInt1fromByte(c.Data, 2);
         if (ImgInfo.Alpha)
             Alphasb = PngHelperInternal.ReadInt1fromByte(c.Data, 3);
     }
 }
コード例 #39
0
ファイル: PngChunkIEND.cs プロジェクト: gitter-badger/blimey
 public override void ParseFromRaw(ChunkRaw c)
 {
     // this is not used
 }
コード例 #40
0
ファイル: PngChunkIEND.cs プロジェクト: gitter-badger/blimey
 public override ChunkRaw CreateRawChunk()
 {
     ChunkRaw c = new ChunkRaw(0, ChunkHelper.b_IEND, false);
     return c;
 }
        public override ChunkRaw CreateRawChunk()
        {
            ChunkRaw c = new ChunkRaw(0, ChunkHelper.b_IEND, false);

            return(c);
        }
コード例 #42
0
ファイル: PngChunkSkipped.cs プロジェクト: LonghronShen/pngcs
 public sealed override void ParseFromRaw(ChunkRaw c) {
     throw new PngjException("Non supported for a skipped chunk");
 }
 public override void ParseFromRaw(ChunkRaw c)
 {
     // this is not used
 }
コード例 #44
0
 public override void ParseFromRaw(ChunkRaw c)
 { // does nothing
 }
コード例 #45
0
ファイル: PngChunkSTER.cs プロジェクト: NoobsArePeople2/pngcs
 public override void ParseFromRaw(ChunkRaw chunk)
 {
     if (chunk.Length != 1)
         throw new PngjException("bad chunk length " + chunk);
     Mode = chunk.Data[0];
 }
コード例 #46
0
ファイル: PngChunkIHDR.cs プロジェクト: gitter-badger/blimey
 public override void ParseFromRaw(ChunkRaw c)
 {
     if (c.Length != 13)
         throw new PngjException("Bad IDHR len " + c.Length);
     MemoryStream st = c.GetAsByteStream();
     Cols = Hjg.Pngcs.PngHelperInternal.ReadInt4(st);
     Rows = Hjg.Pngcs.PngHelperInternal.ReadInt4(st);
     // bit depth: number of bits per channel
     Bitspc = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
     Colormodel = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
     Compmeth = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
     Filmeth = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
     Interlaced = Hjg.Pngcs.PngHelperInternal.ReadByte(st);
 }
コード例 #47
0
ファイル: PngChunk.cs プロジェクト: ondrejmyska/pngcs
        public ChunkRaw createEmptyChunk(int len, bool alloc)
        {
            ChunkRaw c = new ChunkRaw(len, ChunkHelper.ToBytes(Id), alloc);

            return(c);
        }
コード例 #48
0
ファイル: PngChunkSRGB.cs プロジェクト: Daramkun/Misty
 public override void ParseFromRaw( ChunkRaw c )
 {
     if ( c.Length != 1 )
         throw new PngjException ( "bad chunk length " + c );
     Intent = PngHelperInternal.ReadInt1fromByte ( c.Data, 0 );
 }
コード例 #49
0
ファイル: PngChunkSPLT.cs プロジェクト: Chapmania/Juniper
        public override void ParseFromRaw(ChunkRaw c)
        {
            if (c is null)
            {
                throw new System.ArgumentNullException(nameof(c));
            }

            var t = -1;

            for (var i = 0; i < c.Data.Length; i++)
            { // look for first zero
                if (c.Data[i] == 0)
                {
                    t = i;
                    break;
                }
            }

            if (t <= 0 || t > c.Data.Length - 2)
            {
                throw new PngjException("bad sPLT chunk: no separator found");
            }

            PalName     = ChunkHelper.ToString(c.Data, 0, t);
            SampleDepth = PngHelperInternal.ReadInt1fromByte(c.Data, t + 1);
            t          += 2;
            var nentries = (c.Data.Length - t) / (SampleDepth == 8 ? 6 : 10);

            Palette = new int[nentries * 5];
            int r;
            int g;
            int b;
            int a;
            int f;
            int ne;

            ne = 0;
            for (var i = 0; i < nentries; i++)
            {
                if (SampleDepth == 8)
                {
                    r = PngHelperInternal.ReadInt1fromByte(c.Data, t++);
                    g = PngHelperInternal.ReadInt1fromByte(c.Data, t++);
                    b = PngHelperInternal.ReadInt1fromByte(c.Data, t++);
                    a = PngHelperInternal.ReadInt1fromByte(c.Data, t++);
                }
                else
                {
                    r  = PngHelperInternal.ReadInt2fromBytes(c.Data, t);
                    t += 2;
                    g  = PngHelperInternal.ReadInt2fromBytes(c.Data, t);
                    t += 2;
                    b  = PngHelperInternal.ReadInt2fromBytes(c.Data, t);
                    t += 2;
                    a  = PngHelperInternal.ReadInt2fromBytes(c.Data, t);
                    t += 2;
                }

                f             = PngHelperInternal.ReadInt2fromBytes(c.Data, t);
                t            += 2;
                Palette[ne++] = r;
                Palette[ne++] = g;
                Palette[ne++] = b;
                Palette[ne++] = a;
                Palette[ne++] = f;
            }
        }
コード例 #50
0
 public override void ParseFromRaw(ChunkRaw c)
 {
     XmlSerializer serializerObj = new XmlSerializer(typeof(DummyClass));
     obj = (DummyClass)serializerObj.Deserialize(new MemoryStream(c.Data));
 }
コード例 #51
0
ファイル: PngChunkSkipped.cs プロジェクト: git-thinh/limada
 public sealed override void ParseFromRaw(ChunkRaw c)
 {
     throw new PngjException("Non supported for a skipped chunk");
 }
コード例 #52
0
ファイル: PngChunkUNKNOWN.cs プロジェクト: git-thinh/limada
 public override void ParseFromRaw(ChunkRaw c)
 {
     data = c.Data;
 }
コード例 #53
0
 public override void ParseFromRaw(ChunkRaw c)
 {
     data = c.Data;
 }
コード例 #54
0
ファイル: PngChunkIEND.cs プロジェクト: Daramkun/Misty
 public override void ParseFromRaw( ChunkRaw c )
 {
 }