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) : ""; }
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 }
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); }
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); }
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); }
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); }
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)); }
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); } }
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); }
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); } }
public override void ParseFromRaw(ChunkRaw c) { Content = Encoding.UTF8.GetString(c.Data); }
public override void ParseFromRaw(ChunkRaw c) { // does nothing }
public override void ParseFromRaw(ChunkRaw c) { // this is not used }
public override void ParseFromRaw(ChunkRaw c) { XmlSerializer serializerObj = new XmlSerializer(typeof(DummyClass)); obj = (DummyClass)serializerObj.Deserialize(new MemoryStream(c.Data)); }
public sealed override void ParseFromRaw(ChunkRaw c) { throw new PngjException("Non supported for a skipped chunk"); }
public override ChunkRaw CreateRawChunk() { var c = new ChunkRaw(0, ChunkHelper.b_IEND, false); return(c); }
public override void ParseFromRaw(ChunkRaw chunk) => data = chunk.Data;
public sealed override void ParseFromRaw(ChunkRaw c) => throw new System.Exception("Non supported for a skipped chunk");
public override void ParseFromRaw(ChunkRaw c) { }