Esempio n. 1
0
 public override void ParseFromRaw(ChunkRaw chunk)
 {
     byte[] data = chunk.Data;
     if (chunk.Len != GetLen())
     {
         throw new System.Exception($"bad chunk length {chunk}");
     }
     if (ImgInfo.Greyscale)
     {
         Graysb = PngHelperInternal.ReadInt1fromByte(data, 0);
         if (ImgInfo.Alpha)
         {
             Alphasb = PngHelperInternal.ReadInt1fromByte(data, 1);
         }
     }
     else
     {
         Redsb   = PngHelperInternal.ReadInt1fromByte(data, 0);
         Greensb = PngHelperInternal.ReadInt1fromByte(data, 1);
         Bluesb  = PngHelperInternal.ReadInt1fromByte(data, 2);
         if (ImgInfo.Alpha)
         {
             Alphasb = PngHelperInternal.ReadInt1fromByte(data, 3);
         }
     }
 }
Esempio n. 2
0
 public override void ParseFromRaw(ChunkRaw c)
 {
     if (c.Len != 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);
         }
     }
 }
Esempio n. 3
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            if (c is null)
            {
                throw new System.ArgumentNullException(nameof(c));
            }

            if (c.Len != 9)
            {
                throw new PngjException("bad chunk length " + c);
            }

            posX = PngHelperInternal.ReadInt4fromBytes(c.Data, 0);
            if (posX < 0)
            {
                posX += 0x100000000L;
            }

            posY = PngHelperInternal.ReadInt4fromBytes(c.Data, 4);
            if (posY < 0)
            {
                posY += 0x100000000L;
            }

            units = PngHelperInternal.ReadInt1fromByte(c.Data, 8);
        }
Esempio n. 4
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            if (c is null)
            {
                throw new ArgumentNullException(nameof(c));
            }

            if (c.Len != 7)
            {
                throw new PngjException("bad chunk " + c);
            }

            var year = PngHelperInternal.ReadInt2fromBytes(c.Data, 0);
            var mon  = PngHelperInternal.ReadInt1fromByte(c.Data, 2);
            var day  = PngHelperInternal.ReadInt1fromByte(c.Data, 3);
            var hour = PngHelperInternal.ReadInt1fromByte(c.Data, 4);
            var min  = PngHelperInternal.ReadInt1fromByte(c.Data, 5);
            var sec  = PngHelperInternal.ReadInt1fromByte(c.Data, 6);

            try
            {
                timestamp = new DateTime(year, mon, day, hour, min, sec);
            }
            catch
            {
                timestamp = DateTime.MinValue;
            }
        }
Esempio n. 5
0
 public override void ParseFromRaw(ChunkRaw c)
 {
     if (c.Length != 1)
     {
         throw new PngjException("bad chunk length " + c?.ToString());
     }
     Intent = PngHelperInternal.ReadInt1fromByte(c.Data, 0);
 }
 public override void ParseFromRaw(ChunkRaw c)
 {
     if (c.Len != 1)
     {
         throw new System.Exception($"bad chunk length {c}");
     }
     Intent = PngHelperInternal.ReadInt1fromByte(c.Data, 0);
 }
Esempio n. 7
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 sPLT chunk: no separator found");
            }
            PalName     = ChunkHelper.ToString(c.Data, 0, num);
            SampleDepth = PngHelperInternal.ReadInt1fromByte(c.Data, num + 1);
            num        += 2;
            int num2 = (c.Data.Length - num) / ((SampleDepth == 8) ? 6 : 10);

            Palette = new int[num2 * 5];
            int num3 = 0;

            for (int j = 0; j < num2; j++)
            {
                int num4;
                int num5;
                int num6;
                int num7;
                if (SampleDepth == 8)
                {
                    num4 = PngHelperInternal.ReadInt1fromByte(c.Data, num++);
                    num5 = PngHelperInternal.ReadInt1fromByte(c.Data, num++);
                    num6 = PngHelperInternal.ReadInt1fromByte(c.Data, num++);
                    num7 = PngHelperInternal.ReadInt1fromByte(c.Data, num++);
                }
                else
                {
                    num4 = PngHelperInternal.ReadInt2fromBytes(c.Data, num);
                    num += 2;
                    num5 = PngHelperInternal.ReadInt2fromBytes(c.Data, num);
                    num += 2;
                    num6 = PngHelperInternal.ReadInt2fromBytes(c.Data, num);
                    num += 2;
                    num7 = PngHelperInternal.ReadInt2fromBytes(c.Data, num);
                    num += 2;
                }
                int num8 = PngHelperInternal.ReadInt2fromBytes(c.Data, num);
                num            += 2;
                Palette[num3++] = num4;
                Palette[num3++] = num5;
                Palette[num3++] = num6;
                Palette[num3++] = num7;
                Palette[num3++] = num8;
            }
        }
Esempio n. 8
0
        public override void ParseFromRaw(ChunkRaw chunk)
        {
            byte[] data   = chunk.Data;
            int    length = data.Length;
            int    t      = -1;

            for (int i = 0; i < length; i++)           // look for first zero
            {
                if (data[i] == 0)
                {
                    t = i;
                    break;
                }
            }
            if (t <= 0 || t > length - 2)
            {
                throw new System.Exception("bad sPLT chunk: no separator found");
            }
            PalName     = ChunkHelper.ToString(data, 0, t);
            SampleDepth = PngHelperInternal.ReadInt1fromByte(data, t + 1);
            t          += 2;
            int nentries = (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(data, t++);
                    g = PngHelperInternal.ReadInt1fromByte(data, t++);
                    b = PngHelperInternal.ReadInt1fromByte(data, t++);
                    a = PngHelperInternal.ReadInt1fromByte(data, t++);
                }
                else
                {
                    r  = PngHelperInternal.ReadInt2fromBytes(data, t);
                    t += 2;
                    g  = PngHelperInternal.ReadInt2fromBytes(data, t);
                    t += 2;
                    b  = PngHelperInternal.ReadInt2fromBytes(data, t);
                    t += 2;
                    a  = PngHelperInternal.ReadInt2fromBytes(data, t);
                    t += 2;
                }
                f             = PngHelperInternal.ReadInt2fromBytes(data, t);
                t            += 2;
                Palette[ne++] = r;
                Palette[ne++] = g;
                Palette[ne++] = b;
                Palette[ne++] = a;
                Palette[ne++] = f;
            }
        }
Esempio n. 9
0
 public override void ParseFromRaw(ChunkRaw chunk)
 {
     if (chunk.Length != 7)
     {
         throw new PngjException("bad chunk " + chunk?.ToString());
     }
     year = PngHelperInternal.ReadInt2fromBytes(chunk.Data, 0);
     mon  = PngHelperInternal.ReadInt1fromByte(chunk.Data, 2);
     day  = PngHelperInternal.ReadInt1fromByte(chunk.Data, 3);
     hour = PngHelperInternal.ReadInt1fromByte(chunk.Data, 4);
     min  = PngHelperInternal.ReadInt1fromByte(chunk.Data, 5);
     sec  = PngHelperInternal.ReadInt1fromByte(chunk.Data, 6);
 }
 public override void ParseFromRaw(ChunkRaw chunk)
 {
     if (chunk.Len != 7)
     {
         throw new System.Exception($"bad chunk {chunk}");
     }
     byte[] data = chunk.Data;
     year = PngHelperInternal.ReadInt2fromBytes(data, 0);
     mon  = PngHelperInternal.ReadInt1fromByte(data, 2);
     day  = PngHelperInternal.ReadInt1fromByte(data, 3);
     hour = PngHelperInternal.ReadInt1fromByte(data, 4);
     min  = PngHelperInternal.ReadInt1fromByte(data, 5);
     sec  = PngHelperInternal.ReadInt1fromByte(data, 6);
 }
Esempio n. 11
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            if (c is null)
            {
                throw new System.ArgumentNullException(nameof(c));
            }

            if (c.Len != 1)
            {
                throw new PngjException("bad chunk length " + c);
            }

            Intent = PngHelperInternal.ReadInt1fromByte(c.Data, 0);
        }
Esempio n. 12
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);
 }
Esempio n. 13
0
 public override void ParseFromRaw(ChunkRaw chunk)
 {
     if (chunk.Length != 9)
     {
         throw new PngjException("bad chunk length " + chunk?.ToString());
     }
     PixelsxUnitX = PngHelperInternal.ReadInt4fromBytes(chunk.Data, 0);
     if (PixelsxUnitX < 0)
     {
         PixelsxUnitX += 4294967296L;
     }
     PixelsxUnitY = PngHelperInternal.ReadInt4fromBytes(chunk.Data, 4);
     if (PixelsxUnitY < 0)
     {
         PixelsxUnitY += 4294967296L;
     }
     Units = PngHelperInternal.ReadInt1fromByte(chunk.Data, 8);
 }
Esempio n. 14
0
 public override void ParseFromRaw(ChunkRaw chunk)
 {
     byte[] data = chunk.Data;
     if (chunk.Len != 9)
     {
         throw new System.Exception($"bad chunk length {chunk}");
     }
     posX = PngHelperInternal.ReadInt4fromBytes(data, 0);
     if (posX < 0)
     {
         posX += 0x100000000L;
     }
     posY = PngHelperInternal.ReadInt4fromBytes(data, 4);
     if (posY < 0)
     {
         posY += 0x100000000L;
     }
     units = PngHelperInternal.ReadInt1fromByte(data, 8);
 }
Esempio n. 15
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;
            }
        }