コード例 #1
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            byte[] data   = c.Data;
            int    length = data.Length;
            int    i;

            for (i = 0; i < length; i++)
            {
                if (data[i] == 0)
                {
                    break;
                }
            }
            key = PngHelperInternal.charsetLatin1.GetString(data, 0, i);
            i++;
            val = i < length?PngHelperInternal.charsetLatin1.GetString(data, i, length - i) : "";
        }
コード例 #2
0
ファイル: ChunkReader.cs プロジェクト: Computdroid/pngcs
        int crcn           = 0; // how many bytes have been read from crc


        public ChunkReader
        (
            int clen,
            string id,
            long offsetInPng,
            EChunkReaderMode mode
        )
        {
            if (mode < 0 || id.Length != 4 || clen < 0)
            {
                throw new Pngcs.PngjExceptionInternal($"Bad chunk paramenters: { mode }");
            }

            this.mode = mode;
            chunkRaw  = new ChunkRaw(clen, id, mode == EChunkReaderMode.BUFFER);
            chunkRaw.setOffset(offsetInPng);
            this.crcCheck = mode == EChunkReaderMode.SKIP ? false : true;// can be changed with setter
        }
コード例 #3
0
 public override void ParseFromRaw(ChunkRaw chunk)
 {
     if (chunk.Length != 9)
     {
         throw new PngjException("bad chunk length " + chunk?.ToString());
     }
     posX = PngHelperInternal.ReadInt4fromBytes(chunk.Data, 0);
     if (posX < 0)
     {
         posX += 4294967296L;
     }
     posY = PngHelperInternal.ReadInt4fromBytes(chunk.Data, 4);
     if (posY < 0)
     {
         posY += 4294967296L;
     }
     units = PngHelperInternal.ReadInt1fromByte(chunk.Data, 8);
 }
コード例 #4
0
        public override ChunkRaw CreateRawChunk()
        {
            if (key.Length == 0)
            {
                throw new System.Exception("Text chunk key must be non empty");
            }
            var ba = new System.IO.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);
        }
コード例 #5
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);
 }
コード例 #6
0
        public override ChunkRaw CreateRawChunk()
        {
            if (key.Length == 0)
            {
                throw new System.Exception("Text chunk key must be non empty");
            }

            byte[] b1 = PngHelperInternal.charsetLatin1.GetBytes(key);
            byte[] b2 = PngHelperInternal.charsetLatin1.GetBytes(val);

            ChunkRaw chunk = CreateEmptyChunk(b1.Length + b2.Length + 1, true);

            byte[] data = chunk.Data;

            System.Array.Copy(b1, 0, data, 0, b1.Length);
            data[b1.Length] = 0;
            System.Array.Copy(b2, 0, data, b1.Length + 1, b2.Length);

            return(chunk);
        }
コード例 #7
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            if (c is null)
            {
                throw new System.ArgumentNullException(nameof(c));
            }

            if (c.Len != 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));
        }
コード例 #8
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            if (c is null)
            {
                throw new System.ArgumentNullException(nameof(c));
            }

            if (ImgInfo.Greyscale)
            {
                gray = Hjg.Pngcs.PngHelperInternal.ReadInt2fromBytes(c.Data, 0);
            }
            else if (ImgInfo.Indexed)
            {
                paletteIndex = 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);
            }
        }
コード例 #9
0
        public override ChunkRaw CreateRawChunk()
        {
            ChunkRaw chunkRaw = null;

            if (ImgInfo.Greyscale)
            {
                chunkRaw = createEmptyChunk(2, alloc: true);
                PngHelperInternal.WriteInt2tobytes(gray, chunkRaw.Data, 0);
            }
            else if (ImgInfo.Indexed)
            {
                chunkRaw         = createEmptyChunk(1, alloc: true);
                chunkRaw.Data[0] = (byte)paletteIndex;
            }
            else
            {
                chunkRaw = createEmptyChunk(6, alloc: true);
                PngHelperInternal.WriteInt2tobytes(red, chunkRaw.Data, 0);
                PngHelperInternal.WriteInt2tobytes(green, chunkRaw.Data, 0);
                PngHelperInternal.WriteInt2tobytes(blue, chunkRaw.Data, 0);
            }
            return(chunkRaw);
        }
コード例 #10
0
 public override void ParseFromRaw(ChunkRaw c)
 {
     if (c.Length != GetLen())
     {
         throw new PngjException("bad chunk length " + c?.ToString());
     }
     if (ImgInfo.Greyscale)
     {
         Graysb = PngHelperInternal.ReadInt1fromByte(c.Data, 0);
         if (ImgInfo.Alpha)
         {
             Alphasb = PngHelperInternal.ReadInt1fromByte(c.Data, 1);
         }
         return;
     }
     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);
     }
 }
コード例 #11
0
ファイル: PngSkin.cs プロジェクト: johnkramerr/Sc2tvChatPub
 public override void ParseFromRaw(ChunkRaw c)
 {
     Content = Encoding.UTF8.GetString(c.Data);
 }
コード例 #12
0
ファイル: PngChunkIDAT.cs プロジェクト: Chapmania/Juniper
 public override void ParseFromRaw(ChunkRaw c)
 { // does nothing
 }
コード例 #13
0
ファイル: PngChunkIEND.cs プロジェクト: Chapmania/Juniper
 public override void ParseFromRaw(ChunkRaw c)
 {
     // this is not used
 }
コード例 #14
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            XmlSerializer serializerObj = new XmlSerializer(typeof(DummyClass));

            obj = (DummyClass)serializerObj.Deserialize(new MemoryStream(c.Data));
        }
コード例 #15
0
 public sealed override void ParseFromRaw(ChunkRaw c)
 {
     throw new PngjException("Non supported for a skipped chunk");
 }
コード例 #16
0
ファイル: PngChunkIEND.cs プロジェクト: Chapmania/Juniper
        public override ChunkRaw CreateRawChunk()
        {
            var c = new ChunkRaw(0, ChunkHelper.b_IEND, false);

            return(c);
        }
コード例 #17
0
 public override void ParseFromRaw(ChunkRaw chunk) => data = chunk.Data;
コード例 #18
0
 public sealed override void ParseFromRaw(ChunkRaw c) => throw new System.Exception("Non supported for a skipped chunk");
コード例 #19
0
 public override void ParseFromRaw(ChunkRaw c)
 {
 }