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 = 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); }
internal static PngChunk Factory(ChunkRaw chunk, ImageInfo info) { PngChunk pngChunk = FactoryFromId(ChunkHelper.ToString(chunk.IdBytes), info); pngChunk.Length = chunk.Length; pngChunk.ParseFromRaw(chunk); return(pngChunk); }
internal static AbstractPngChunk Factory(ChunkRaw chunk, ImageInfo info) { var c = FactoryFromId(ChunkHelper.ToString(chunk.IdBytes), info); c.Length = chunk.Len; c.ParseFromRaw(chunk); return(c); }
public override void ParseFromRaw(ChunkRaw c) { if (c is null) { throw new System.ArgumentNullException(nameof(c)); } var nullsFound = 0; var nullsIdx = new int[3]; for (var 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]); var i = nullsIdx[0] + 1; compressed = c.Data[i] != 0; 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) { var 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); } }
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; } }
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; } }
internal void WriteChunk(Stream os) { if (IdBytes.Length != 4) { throw new PngjOutputException("bad chunkid [" + ChunkHelper.ToString(IdBytes) + "]"); } crcval = ComputeCrc(); PngHelperInternal.WriteInt4(os, Length); PngHelperInternal.WriteBytes(os, IdBytes); if (Length > 0) { PngHelperInternal.WriteBytes(os, Data, 0, Length); } PngHelperInternal.WriteInt4(os, crcval); }
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); } }
public override void ParseFromRaw(ChunkRaw c) { int num = 0; int[] array = new int[3]; for (int i = 0; i < c.Data.Length; i++) { if (c.Data[i] == 0) { array[num] = i; num++; if (num == 1) { i += 2; } if (num == 3) { break; } } } if (num != 3) { throw new PngjException("Bad formed PngChunkITXT chunk"); } key = ChunkHelper.ToString(c.Data, 0, array[0]); int num2 = array[0] + 1; compressed = ((c.Data[num2] != 0) ? true : false); num2++; if (compressed && c.Data[num2] != 0) { throw new PngjException("Bad formed PngChunkITXT chunk - bad compression method "); } langTag = ChunkHelper.ToString(c.Data, num2, array[1] - num2); translatedTag = ChunkHelper.ToStringUTF8(c.Data, array[1] + 1, array[2] - array[1] - 1); num2 = array[2] + 1; if (compressed) { byte[] x = ChunkHelper.compressBytes(c.Data, num2, c.Data.Length - num2, compress: false); val = ChunkHelper.ToStringUTF8(x); } else { val = ChunkHelper.ToStringUTF8(c.Data, num2, c.Data.Length - num2); } }
internal void WriteChunk(Stream os) { if (IdBytes.Length != 4) { throw new PngjOutputException("bad chunkid [" + ChunkHelper.ToString(IdBytes) + "]"); } crcval = ComputeCrc(); PngHelperInternal.WriteInt4(os, Len); PngHelperInternal.WriteBytes(os, IdBytes); if (Len > 0) { PngHelperInternal.WriteBytes(os, Data, 0, Len); } //Console.WriteLine("writing chunk " + this.ToString() + "crc=" + crcval); PngHelperInternal.WriteInt4(os, crcval); }
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); }
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); }
internal ChunkRaw(int length, byte[] idbytes, bool alloc) : this(length, ChunkHelper.ToString(idbytes), alloc) { }
/// <summary> /// Just id and length /// </summary> /// <returns></returns> public override String ToString() { return("chunkid=" + ChunkHelper.ToString(IdBytes) + " len=" + Len); }
public string GetProfileAsString() { return(ChunkHelper.ToString(GetProfile())); }
/// <summary> /// Just id and length /// </summary> /// <returns></returns> public override string ToString() { return("chunkid=" + ChunkHelper.ToString(IdBytes) + " len=" + Len.ToString(CultureInfo.InvariantCulture)); }