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
Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
        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
        }
Exemplo n.º 3
0
 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 ) : "";
 }
Exemplo n.º 4
0
 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);
     }
 }
Exemplo n.º 5
0
 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 );
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
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 );
 }
Exemplo n.º 8
0
 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 );
 }
Exemplo n.º 9
0
 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));
 }
Exemplo n.º 10
0
 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;
 }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 13
0
 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 18
0
        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);
            }
        }
Exemplo n.º 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) : "";
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 27
0
 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 );
     }
 }
Exemplo n.º 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 );
 }
Exemplo n.º 29
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);
     }
 }
Exemplo n.º 30
0
 public override ChunkRaw CreateRawChunk()
 {
     ChunkRaw p = createEmptyChunk(data.Length, false);
     p.Data = this.data;
     return p;
 }
Exemplo n.º 31
0
 /// <summary>
 /// Deserialization. Given a Raw chunk, just rad, fills this chunk content
 /// </summary>
 public abstract void ParseFromRaw(ChunkRaw c);
Exemplo n.º 32
0
 public override void ParseFromRaw( ChunkRaw c )
 {
     Content = Encoding.UTF8.GetString(c.Data);
 }
Exemplo n.º 33
0
 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 ) );
     }
 }
Exemplo n.º 34
0
 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;
     }
 }
Exemplo n.º 35
0
        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;
        }
Exemplo n.º 36
0
 public override void ParseFromRaw(ChunkRaw c) { // does nothing
 }
Exemplo n.º 37
0
 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 );
     }
 }
Exemplo n.º 38
0
 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);
     }
 }
Exemplo n.º 39
0
 public override void ParseFromRaw(ChunkRaw c)
 {
     // this is not used
 }
Exemplo n.º 40
0
 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);
        }
Exemplo n.º 42
0
 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
 }
Exemplo n.º 44
0
 public override void ParseFromRaw(ChunkRaw c)
 { // does nothing
 }
Exemplo n.º 45
0
 public override void ParseFromRaw(ChunkRaw chunk)
 {
     if (chunk.Length != 1)
         throw new PngjException("bad chunk length " + chunk);
     Mode = chunk.Data[0];
 }
Exemplo n.º 46
0
 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);
 }
Exemplo n.º 47
0
        public ChunkRaw createEmptyChunk(int len, bool alloc)
        {
            ChunkRaw c = new ChunkRaw(len, ChunkHelper.ToBytes(Id), alloc);

            return(c);
        }
Exemplo n.º 48
0
 public override void ParseFromRaw( ChunkRaw c )
 {
     if ( c.Length != 1 )
         throw new PngjException ( "bad chunk length " + c );
     Intent = PngHelperInternal.ReadInt1fromByte ( c.Data, 0 );
 }
Exemplo n.º 49
0
        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;
            }
        }
Exemplo n.º 50
0
 public override void ParseFromRaw(ChunkRaw c)
 {
     XmlSerializer serializerObj = new XmlSerializer(typeof(DummyClass));
     obj = (DummyClass)serializerObj.Deserialize(new MemoryStream(c.Data));
 }
Exemplo n.º 51
0
 public sealed override void ParseFromRaw(ChunkRaw c)
 {
     throw new PngjException("Non supported for a skipped chunk");
 }
Exemplo n.º 52
0
 public override void ParseFromRaw(ChunkRaw c)
 {
     data = c.Data;
 }
Exemplo n.º 53
0
 public override void ParseFromRaw(ChunkRaw c)
 {
     data = c.Data;
 }
Exemplo n.º 54
0
 public override void ParseFromRaw( ChunkRaw c )
 {
 }