/// <summary> /// Position before: just after chunk id. positon after: after crc Data should /// be already allocated. Checks CRC Return number of byte read. /// </summary> internal int ReadChunkData(System.IO.Stream stream, bool checkCrc) { PngHelperInternal.ReadBytes(stream, Data, 0, Len); crcval = PngHelperInternal.ReadInt4(stream); if (checkCrc) { int crc = ComputeCrc(); if (crc != crcval) { throw new System.Exception($"crc invalid for chunk {this} calc={crc} read={crcval}"); } } return(Len + 4); }
internal int ReadChunkData(Stream stream, bool checkCrc) { PngHelperInternal.ReadBytes(stream, Data, 0, Length); crcval = PngHelperInternal.ReadInt4(stream); if (checkCrc) { int num = ComputeCrc(); if (num != crcval) { throw new PngjBadCrcException("crc invalid for chunk " + ToString() + " calc=" + num.ToString() + " read=" + crcval.ToString()); } } return(Length + 4); }
public override void ParseFromRaw(ChunkRaw chunk) { if (chunk.Len != 13) { throw new System.Exception($"Bad IDHR len {chunk.Len}"); } IO.MemoryStream stream = chunk.GetAsByteStream(); Cols = PngHelperInternal.ReadInt4(stream); Rows = PngHelperInternal.ReadInt4(stream); // bit depth: number of bits per channel Bitspc = PngHelperInternal.ReadByte(stream); Colormodel = PngHelperInternal.ReadByte(stream); Compmeth = PngHelperInternal.ReadByte(stream); Filmeth = PngHelperInternal.ReadByte(stream); Interlaced = PngHelperInternal.ReadByte(stream); }
/// <summary> /// Position before: just after chunk id. positon after: after crc Data should /// be already allocated. Checks CRC Return number of byte read. /// </summary> /// internal int ReadChunkData(Stream stream, bool checkCrc) { PngHelperInternal.ReadBytes(stream, Data, 0, Len); crcval = PngHelperInternal.ReadInt4(stream); if (checkCrc) { var crc = ComputeCrc(); if (crc != crcval) { throw new PngjBadCrcException("crc invalid for chunk " + ToString() + " calc=" + crc.ToString(CultureInfo.CurrentCulture) + " read=" + crcval.ToString(CultureInfo.CurrentCulture)); } } return(Len + 4); }
public override void ParseFromRaw(ChunkRaw c) { if (c.Length != 13) { throw new PngjException("Bad IDHR len " + c.Length.ToString()); } MemoryStream asByteStream = c.GetAsByteStream(); Cols = PngHelperInternal.ReadInt4(asByteStream); Rows = PngHelperInternal.ReadInt4(asByteStream); Bitspc = PngHelperInternal.ReadByte(asByteStream); Colormodel = PngHelperInternal.ReadByte(asByteStream); Compmeth = PngHelperInternal.ReadByte(asByteStream); Filmeth = PngHelperInternal.ReadByte(asByteStream); Interlaced = PngHelperInternal.ReadByte(asByteStream); }
public override void Close() => base.Close(); // nothing void EndChunkGoForNext() { // Called after readging the last byte of chunk // Checks CRC, and read ID from next CHUNK // Those values are left in idLastChunk / lenLastChunk // Skips empty IDATS do { int crc = PngHelperInternal.ReadInt4(inputStream); offset += 4; if (checkCrc) { int crccalc = (int)crcEngine.GetValue(); if (lenLastChunk > 0 && crc != crccalc) { throw new System.Exception($"error reading idat; offset: {offset}"); } crcEngine.Reset(); } lenLastChunk = PngHelperInternal.ReadInt4(inputStream); if (lenLastChunk < 0) { throw new System.IO.IOException($"invalid len for chunk: {lenLastChunk}"); } toReadThisChunk = lenLastChunk; PngHelperInternal.ReadBytes(inputStream, idLastChunk, 0, 4); offset += 8; ended = !PngCsUtils.UnSafeEquals(idLastChunk, Chunks.ChunkHelper.b_IDAT); if (!ended) { foundChunksInfo.Add(new PngIDatChunkInputStream.IdatChunkInfo(lenLastChunk, offset - 8)); if (checkCrc) { crcEngine.Update(idLastChunk, 0, 4); } } // PngHelper.logdebug("IDAT ended. next len= " + lenLastChunk + " idat?" + // (!ended)); }while(lenLastChunk == 0 && !ended); // rarely condition is true (empty IDAT ??) }