public override void CloneDataFromRead( PngChunk other ) { PngChunkOFFS otherx = ( PngChunkOFFS ) other; this.posX = otherx.posX; this.posY = otherx.posY; this.units = otherx.units; }
public override void CloneDataFromRead(PngChunk other) { PngChunkICCP otherx = (PngChunkICCP)other; profileName = otherx.profileName; compressedProfile = new byte[otherx.compressedProfile.Length]; System.Array.Copy(otherx.compressedProfile, compressedProfile, compressedProfile.Length); }
public override void CloneDataFromRead( PngChunk other ) { PngChunkPHYS otherx = ( PngChunkPHYS ) other; this.PixelsxUnitX = otherx.PixelsxUnitX; this.PixelsxUnitY = otherx.PixelsxUnitY; this.Units = otherx.Units; }
public override void CloneDataFromRead(PngChunk other) { PngChunkSPLT otherx = (PngChunkSPLT)other; PalName = otherx.PalName; SampleDepth = otherx.SampleDepth; Palette = new int[otherx.Palette.Length]; System.Array.Copy(otherx.Palette, 0, Palette, 0, Palette.Length); }
public override void CloneDataFromRead( PngChunk other ) { PngChunkBKGD otherx = ( PngChunkBKGD ) other; gray = otherx.gray; red = otherx.red; green = otherx.red; blue = otherx.red; paletteIndex = otherx.paletteIndex; }
public override void CloneDataFromRead(PngChunk other) { PngChunkSBIT otherx = (PngChunkSBIT)other; Graysb = otherx.Graysb; Redsb = otherx.Redsb; Greensb = otherx.Greensb; Bluesb = otherx.Bluesb; Alphasb = otherx.Alphasb; }
public override void CloneDataFromRead( PngChunk other ) { PngChunkITXT otherx = ( PngChunkITXT ) other; key = otherx.key; val = otherx.val; compressed = otherx.compressed; langTag = otherx.langTag; translatedTag = otherx.translatedTag; }
public override void CloneDataFromRead( PngChunk other ) { PngChunkTIME x = ( PngChunkTIME ) other; year = x.year; mon = x.mon; day = x.day; hour = x.hour; min = x.min; sec = x.sec; }
public bool Matches(PngChunk c) { if (!c.Id.Equals(id)) return false; if (c is PngChunkTextVar && !((PngChunkTextVar)c).GetKey().Equals(innerid)) return false; if (c is PngChunkSPLT && !((PngChunkSPLT)c).PalName.Equals(innerid)) return false; return true; }
public override void CloneDataFromRead(PngChunk other) { PngChunkIHDR otherx = (PngChunkIHDR)other; Cols = otherx.Cols; Rows = otherx.Rows; Bitspc = otherx.Bitspc; Colormodel = otherx.Colormodel; Compmeth = otherx.Compmeth; Filmeth = otherx.Filmeth; Interlaced = otherx.Interlaced; }
public override void CloneDataFromRead(PngChunk other) { PngChunkCHRM otherx = (PngChunkCHRM)other; whitex = otherx.whitex; whitey = otherx.whitex; redx = otherx.redx; redy = otherx.redy; greenx = otherx.greenx; greeny = otherx.greeny; bluex = otherx.bluex; bluey = otherx.bluey; }
public override void CloneDataFromRead(PngChunk other) { PngChunkTRNS otherx = (PngChunkTRNS)other; gray = otherx.gray; red = otherx.red; green = otherx.green; blue = otherx.blue; if (otherx.paletteAlpha != null) { paletteAlpha = new int[otherx.paletteAlpha.Length]; System.Array.Copy(otherx.paletteAlpha, 0, paletteAlpha, 0, paletteAlpha.Length); } }
/// <summary> /// Ad-hoc criteria for 'equivalent' chunks. /// </summary> /// <remarks> /// Two chunks are equivalent if they have the same Id AND either: /// 1. they are Single /// 2. both are textual and have the same key /// 3. both are SPLT and have the same palette name /// Bear in mind that this is an ad-hoc, non-standard, nor required (nor wrong) /// criterion. Use it only if you find it useful. Notice that PNG allows to have /// repeated textual keys with same keys. /// </remarks> /// <param name="c1">Chunk1</param> /// <param name="c2">Chunk1</param> /// <returns>true if equivalent</returns> public static bool Equivalent(PngChunk c1, PngChunk c2) { if (c1 == c2) return true; if (c1 == null || c2 == null || !c1.Id.Equals(c2.Id)) return false; // same id if (c1.GetType() != c2.GetType()) return false; // should not happen if (!c2.AllowsMultiple()) return true; if (c1 is PngChunkTextVar) { return ((PngChunkTextVar)c1).GetKey().Equals(((PngChunkTextVar)c2).GetKey()); } if (c1 is PngChunkSPLT) { return ((PngChunkSPLT)c1).PalName.Equals(((PngChunkSPLT)c2).PalName); } // unknown chunks that allow multiple? consider they don't match return false; }
public static bool Equivalent( PngChunk c1, PngChunk c2 ) { if ( c1 == c2 ) return true; if ( c1 == null || c2 == null || !c1.Id.Equals ( c2.Id ) ) return false; if ( c1.GetType () != c2.GetType () ) return false; if ( !c2.AllowsMultiple () ) return true; if ( c1 is PngChunkTextVar ) { return ( ( PngChunkTextVar ) c1 ).GetKey ().Equals ( ( ( PngChunkTextVar ) c2 ).GetKey () ); } if ( c1 is PngChunkSPLT ) { return ( ( PngChunkSPLT ) c1 ).PalName.Equals ( ( ( PngChunkSPLT ) c2 ).PalName ); } return false; }
public static void testRead(String file) { // register with factory chunk PngChunk.FactoryRegister(PngChunkSERI.ID, typeof(PngChunkSERI)); // read all file PngReader pngr = FileHelper.CreatePngReader(file); pngr.ReadSkippingAllRows(); pngr.End(); // we assume there can be at most one chunk of this type... PngChunk chunk = pngr.GetChunksList().GetById1(PngChunkSERI.ID); // This would work even if not registered, but then PngChunk would be of type PngChunkUNKNOWN Console.Out.WriteLine(chunk); // the following would fail if we had not register the chunk PngChunkSERI chunkprop = (PngChunkSERI)chunk; string name = chunkprop.GetObj().name; int age = chunkprop.GetObj().age; Console.Out.WriteLine("Done. Name: " + name + " age=" + age); }
static void Main(string[] args) { if (args.Length != 2) { MessageBox.Show("Invalid number of parameters. Usage: ImageOcclusionEditor.exe <background-image-path> <occlusion-image-path>"); return; } string backgroundImg = args[0]; string occlusionImg = args[1]; if (!File.Exists(backgroundImg)) { MessageBox.Show(String.Format("Background file {0} doesn't exist", backgroundImg)); return; } if (!File.Exists(occlusionImg)) { MessageBox.Show(String.Format("Occlusion file {0} doesn't exist", occlusionImg)); return; } if (!ValidateImage(backgroundImg)) { MessageBox.Show(String.Format("Background file {0} isn't a known Image Format", backgroundImg)); return; } if (!ValidateImage(occlusionImg)) { MessageBox.Show(String.Format("Occlusion file {0} isn't a known Image Format", occlusionImg)); return; } PngChunk.FactoryRegister(PngChunkSVGI.ID, typeof(PngChunkSVGI)); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(backgroundImg, occlusionImg)); }
private byte[] ReadChunkType(PngChunk chunk) { byte[] typeBuffer = new byte[4]; int numBytes = _stream.Read(typeBuffer, 0, 4); if (numBytes >= 1 && numBytes <= 3) { throw new Exception("Image stream is not valid!"); } char[] chars = new char[4]; chars[0] = (char)typeBuffer[0]; chars[1] = (char)typeBuffer[1]; chars[2] = (char)typeBuffer[2]; chars[3] = (char)typeBuffer[3]; chunk.Type = new string(chars); return(typeBuffer); }
private void readChunkCrc(PngChunk chunk, byte[] typeBuffer) { byte[] crcBuffer = new byte[4]; int count = this.pngStream.Read(crcBuffer, 0, 4); if (count >= 1 && count <= 3) { throw new FormatException("Image stream is not valid!"); } #if !PNG_FAST Array.Reverse(crcBuffer); chunk.Crc = BitConverter.ToUInt32(crcBuffer, 0); Crc32 crc = new Crc32(); crc.Update(typeBuffer); crc.Update(chunk.Data); if (crc.Value != chunk.Crc) { throw new FormatException("CRC Error. PNG Image chunk is corrupt!"); } #endif }
/// <summary> /// copy chunks from reader - copy_mask : see ChunksToWrite.COPY_XXX /// If we are after idat, only considers those chunks after IDAT in PngReader /// TODO: this should be more customizable /// </summary> /// private void CopyChunks(PngReader reader, int copy_mask, bool onlyAfterIdat) { bool idatDone = CurrentChunkGroup >= ChunksList.CHUNK_GROUP_4_IDAT; if (onlyAfterIdat && reader.CurrentChunkGroup < ChunksList.CHUNK_GROUP_6_END) throw new PngjException("tried to copy last chunks but reader has not ended"); foreach (PngChunk chunk in reader.GetChunksList().GetChunks()) { int group = chunk.ChunkGroup; if (group < ChunksList.CHUNK_GROUP_4_IDAT && idatDone) continue; bool copy = false; if (chunk.Crit) { if (chunk.Id.Equals(ChunkHelper.PLTE, StringComparison.InvariantCultureIgnoreCase)) { if (ImgInfo.Indexed && ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_PALETTE)) copy = true; if (!ImgInfo.Greyscale && ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_ALL)) copy = true; } } else { // ancillary bool text = chunk is PngChunkTextVar; bool safe = chunk.Safe; // notice that these if are not exclusive if (ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_ALL)) copy = true; if (safe && ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_ALL_SAFE)) copy = true; if (chunk.Id.Equals(ChunkHelper.tRNS, StringComparison.InvariantCultureIgnoreCase) && ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_TRANSPARENCY)) copy = true; if (chunk.Id.Equals(ChunkHelper.pHYs, StringComparison.InvariantCultureIgnoreCase) && ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_PHYS)) copy = true; if (text && ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_TEXTUAL)) copy = true; if (ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_ALMOSTALL) && !(ChunkHelper.IsUnknown(chunk) || text || chunk.Id.Equals(ChunkHelper.hIST, StringComparison.InvariantCultureIgnoreCase) || chunk.Id.Equals(ChunkHelper.tIME, StringComparison.InvariantCultureIgnoreCase))) copy = true; if (chunk is PngChunkSkipped) copy = false; } if (copy) chunksList.Queue(PngChunk.CloneChunk(chunk, ImgInfo)); } }
private List <PngChunk> ReadChunks(byte[] array) { List <PngChunk> chunks = new List <PngChunk>(); for (int i = 8; i < array.Length;) { byte[] chunkSizeBytes = { array[i + 3], array[i + 2], array[i + 1], array[i] }; int chunkSize = BitConverter.ToInt32(chunkSizeBytes, 0); byte[] chunkNameBytes = { array[i + 4], array[i + 5], array[i + 6], array[i + 7] }; String chunkName = System.Text.Encoding.UTF8.GetString(chunkNameBytes, 0, chunkNameBytes.Length); if (chunkName.Equals(PngChunkType.IEND.ToString())) { return(chunks); } PngChunk chunk = new PngChunk(); chunk.PngChunkType = DeterminePngChunkType(chunkName); chunk.ChunkBody = array.Skip(8 + i).Take(chunkSize).ToArray(); chunks.Add(chunk); i += chunkSize + 8 + 4; } return(chunks); }
public static ResourceDictionary LoadFromPng(string FileName) { // read all file PngReader pngr = FileHelper.CreatePngReader(FileName); pngr.ReadSkippingAllRows(); pngr.End(); // we assume there can be at most one chunk of this type... PngChunk chunk = pngr.GetChunksList().GetById1(PngChunkSKIN.ID); // This would work even if not registered, but then PngChunk would be of type PngChunkUNKNOWN if (chunk != null) { // the following would fail if we had not register the chunk PngChunkSKIN chunkprop = (PngChunkSKIN)chunk; ParserContext pc = new ParserContext(); pc.XamlTypeMapper = XamlTypeMapper.DefaultMapper; // pc.XmlSpace //MimeObjectFactory s; var rd1 = (ResourceDictionary)XamlReader.Parse(chunkprop.Content); // Application.Current.Resources.MergedDictionaries.Add(rd1); // var rd2 = (ResourceDictionary)XamlReader.Parse(chunkprop.Content); //// Application.Current.Resources.MergedDictionaries.Add(rd2); // if (rd1 == rd2) { // } return(rd1); } else { return(null); } }
private void ReadChunkCrc(PngChunk chunk, byte[] typeBuffer) { // byte[] crcBuffer = new byte[4]; _stream.Position += 4; // if (numBytes >= 1 && numBytes <= 3) // { // throw new Exception("Image stream is not valid!"); // } // Array.Reverse(crcBuffer); // chunk.Crc = BitConverter.ToUInt32(crcBuffer, 0); // Crc32 crc = new Crc32(); // crc.Update(typeBuffer); // crc.Update(chunk.Data); // if (crc.Value != chunk.Crc) // { // throw new Exception("CRC Error. PNG Image chunk is corrupt!"); // } }
public override void CloneDataFromRead(PngChunk other) { PngChunkSERI otherx = (PngChunkSERI)other; this.obj = otherx.obj; // shallow clone, we could implement other copying }
public override void CloneDataFromRead(PngChunk other) { // THIS SHOULD NOT BE CALLED IF ALREADY CLONED WITH COPY CONSTRUCTOR PngChunkUNKNOWN c = (PngChunkUNKNOWN)other; data = c.data; // not deep copy }
public override void CloneDataFromRead(PngChunk other) { PngChunkSTER pngChunkSTER = (PngChunkSTER)other; Mode = pngChunkSTER.Mode; }
public byte[] Decode(Stream stream) { this.pngStream = stream; this.pngStream.Seek(8, SeekOrigin.Current); bool isEndChunckReached = false; PngChunk currentChunk = null; byte[] palette = null; byte[] paletteAlpha = null; int readScanlineRow = 0; using (MemoryStream dataStream = new MemoryStream()) { while ((currentChunk = this.readChunk()) != null) { if (isEndChunckReached) { throw new FormatException("Image does not end with end chunk."); } if (currentChunk.Type == PngChunkTypesHeader) { this.readHeaderChunk(currentChunk.Data); if (this.ColorType != 0 && this.ColorType != 2 && this.ColorType != 3 && this.ColorType != 4 && this.ColorType != 6) { throw new FormatException("Color type is not supported or not valid."); } if (this.ColorType == 0) { if (this.BitDepth != 1 && this.BitDepth != 2 && this.BitDepth != 4 && this.BitDepth != 8) { throw new FormatException("Bit depth is not supported or not valid."); } } if (this.ColorType == 2) { if (this.BitDepth != 8) { throw new FormatException("Bit depth is not supported or not valid."); } } if (this.ColorType == 3) { if (this.BitDepth != 1 && this.BitDepth != 2 && this.BitDepth != 4 && this.BitDepth != 8) { throw new FormatException("Bit depth is not supported or not valid."); } } if (this.ColorType == 4) { if (this.BitDepth != 8) { throw new FormatException("Bit depth is not supported or not valid."); } } if (this.ColorType == 6) { if (this.BitDepth != 8) { throw new FormatException("Bit depth is not supported or not valid."); } } if (this.FilterMethod != 0) { throw new FormatException("The png specification only defines 0 as filter method."); } if (this.InterlaceMethod != 0) { throw new FormatException("Interlacing is not supported."); } } else if (currentChunk.Type == PngChunkTypesData) { dataStream.Write(currentChunk.Data, 0, currentChunk.Data.Length); //这里的数据可以是多块 } else if (currentChunk.Type == PngChunkTypesPalette) { palette = currentChunk.Data; } else if (currentChunk.Type == PngChunkTypesPaletteAlpha) { paletteAlpha = currentChunk.Data; } else if (currentChunk.Type == PngChunkTypesEnd) { isEndChunckReached = true; } else if (currentChunk.Type == PngChunkTypesPhysical) { } else if (currentChunk.Type == PngChunkTypesText) { } } byte[] pixels = new byte[this.Width * this.Height * 4]; this.readScanlines(dataStream, pixels, ref readScanlineRow, palette, paletteAlpha); return(pixels); } }
private void ReadChunkData(PngChunk chunk) { chunk.Data = new byte[chunk.Length]; _stream.Read(chunk.Data, 0, chunk.Length); }
private void readChunkData(PngChunk chunk) { chunk.Data = new byte[chunk.Length]; this.pngStream.Read(chunk.Data, 0, chunk.Length); }
public override void CloneDataFromRead(PngChunk other) { }
public bool Matches(PngChunk c) { return(ChunkHelper.Equivalent(c, chunk)); }
public void WriteImage(Image.Image image, String path) { PngChunk ihdr = GenerateIhdrChunk(image); PngChunk idat = GenerateIdatChunk(image); byte[] file = new byte[57 + idat.ChunkBody.Length]; file[0] = 137; file[1] = 80; file[2] = 78; file[3] = 71; file[4] = 13; file[5] = 10; file[6] = 26; file[7] = 10; file[8] = 0; file[9] = 0; file[10] = 0; file[11] = 13; file[12] = 73; file[13] = 72; file[14] = 68; file[15] = 82; for (int i = 0; i < ihdr.ChunkBody.Length; i++) { file[16 + i] = ihdr.ChunkBody[i]; } file[29] = 141; file[30] = 111; file[31] = 38; file[32] = 229; byte[] idatSizeBytes = BitConverter.GetBytes(idat.ChunkBody.Length); file[33] = idatSizeBytes[3]; file[34] = idatSizeBytes[2]; file[35] = idatSizeBytes[1]; file[36] = idatSizeBytes[0]; file[37] = 73; file[38] = 68; file[39] = 65; file[40] = 84; for (int i = 0; i < idat.ChunkBody.Length; i++) { file[41 + i] = idat.ChunkBody[i]; } int iterator = 41 + idat.ChunkBody.Length; file[iterator] = 45; file[iterator + 1] = 27; file[iterator + 2] = 23; file[iterator + 3] = 249; file[iterator + 4] = 0; file[iterator + 5] = 0; file[iterator + 6] = 0; file[iterator + 7] = 0; file[iterator + 8] = 73; file[iterator + 9] = 69; file[iterator + 10] = 78; file[iterator + 11] = 68; file[iterator + 12] = 174; file[iterator + 13] = 66; file[iterator + 14] = 96; file[iterator + 15] = 130; File.WriteAllBytes(path, file); }
public void AppendReadChunk( PngChunk chunk, int chunkGroup ) { chunk.ChunkGroup = chunkGroup; chunks.Add ( chunk ); }
public override void CloneDataFromRead( PngChunk other ) { PngChunkSRGB otherx = ( PngChunkSRGB ) other; Intent = otherx.Intent; }
public static bool IsText(PngChunk c) { return c is PngChunkTextVar; }
/// <summary> /// Decodes the image from the specified stream and sets /// the data to image. /// </summary> /// <param name="image">The image, where the data should be set to. /// Cannot be null (Nothing in Visual Basic).</param> /// <param name="stream">The stream, where the image should be /// decoded from. Cannot be null (Nothing in Visual Basic).</param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="image"/> is null (Nothing in Visual Basic).</para> /// <para>- or -</para> /// <para><paramref name="stream"/> is null (Nothing in Visual Basic).</para> /// </exception> public Image Decode(Stream stream) { _stream = stream; _stream.Seek(8, SeekOrigin.Current); bool isEndChunckReached = false; PngChunk currentChunk = null; byte[] palette = null; byte[] paletteAlpha = null; using (MemoryStream dataStream = new MemoryStream()) { while ((currentChunk = ReadChunk()) != null) { if (isEndChunckReached) { throw new Exception("Image does not end with end chunk."); } if (currentChunk.Type == PngChunkTypes.Header) { ReadHeaderChunk(currentChunk.Data); ValidateHeader(); } else if (currentChunk.Type == PngChunkTypes.Physical) { ReadPhysicalChunk(currentChunk.Data); } else if (currentChunk.Type == PngChunkTypes.Data) { dataStream.Write(currentChunk.Data, 0, currentChunk.Data.Length); } else if (currentChunk.Type == PngChunkTypes.Palette) { palette = currentChunk.Data; } else if (currentChunk.Type == PngChunkTypes.PaletteAlpha) { paletteAlpha = currentChunk.Data; } else if (currentChunk.Type == PngChunkTypes.Text) { ReadTextChunk(currentChunk.Data); } else if (currentChunk.Type == PngChunkTypes.End) { isEndChunckReached = true; } } byte[] pixels = new byte[_header.Width * _header.Height * 4]; PngColorTypeInformation colorTypeInformation = _colorTypes[_header.ColorType]; if (colorTypeInformation != null) { ColorReader colorReader = colorTypeInformation.CreateColorReader(palette, paletteAlpha); ReadScanlines(dataStream, pixels, colorReader, colorTypeInformation); } Image i = new Image(_header.Width, _header.Height); int indx = 0; byte r, g, b, a; for (uint y = 0; y < i.Height; y++) { for (uint x = 0; x < i.Width; x++) { r = pixels[indx]; indx++; g = pixels[indx]; indx++; b = pixels[indx]; indx++; a = pixels[indx]; indx++; i.SetPixel(x, y, new Pixel(r, g, b, a)); } } pixels = null; System.GC.Collect(); return(i); } }
public override void CloneDataFromRead(PngChunk other) { PngChunkSRGB otherx = (PngChunkSRGB)other; Intent = otherx.Intent; }
public override void CloneDataFromRead(PngChunk other) { PngChunkSKIN otherx = (PngChunkSKIN)other; this.Content = otherx.Content; }
/// <summary>Queues the chunk at the writer</summary> /// <param name="chunk">Chunk, ready for write</param> public void QueueChunk(PngChunk chunk) => QueueChunk(chunk, true);
public List<PngChunk> GetEquivalent( PngChunk chunk ) { return ChunkHelper.FilterList ( chunks, new ChunkPredicateEquiv ( chunk ) ); }
public override void CloneDataFromRead(PngChunk other) { PngChunkZTXT otherx = (PngChunkZTXT)other; key = otherx.key; val = otherx.val; }
public override void CloneDataFromRead(PngChunk other) { gamma = ((PngChunkGAMA)other).gamma; }
public override void CloneDataFromRead(PngChunk other) { PngChunkSTER otherx = (PngChunkSTER)other; this.Mode = otherx.Mode; }
public ChunkPredicateEquiv(PngChunk chunk) { this.chunk = chunk; }
public bool Matches(PngChunk c) { return(c.Id.Equals(id)); }
public sealed override void CloneDataFromRead(PngChunk other) { throw new PngjException("Non supported for a skipped chunk"); }
public override void CloneDataFromRead(PngChunk other) { }
static PngSkin() { PngChunk.FactoryRegister(PngChunkSKIN.ID, typeof(PngChunkSKIN)); }
private static bool shouldWrite( PngChunk c, int currentGroup ) { if ( currentGroup == CHUNK_GROUP_2_PLTE ) return c.Id.Equals ( ChunkHelper.PLTE ); if ( currentGroup % 2 == 0 ) throw new PngjOutputException ( "bad chunk group?" ); int minChunkGroup, maxChunkGroup; if ( c.mustGoBeforePLTE () ) minChunkGroup = maxChunkGroup = ChunksList.CHUNK_GROUP_1_AFTERIDHR; else if ( c.mustGoBeforeIDAT () ) { maxChunkGroup = ChunksList.CHUNK_GROUP_3_AFTERPLTE; minChunkGroup = c.mustGoAfterPLTE () ? ChunksList.CHUNK_GROUP_3_AFTERPLTE : ChunksList.CHUNK_GROUP_1_AFTERIDHR; } else { maxChunkGroup = ChunksList.CHUNK_GROUP_5_AFTERIDAT; minChunkGroup = ChunksList.CHUNK_GROUP_1_AFTERIDHR; } int preferred = maxChunkGroup; if ( c.Priority ) preferred = minChunkGroup; if ( ChunkHelper.IsUnknown ( c ) && c.ChunkGroup > 0 ) preferred = c.ChunkGroup; if ( currentGroup == preferred ) return true; if ( currentGroup > preferred && currentGroup <= maxChunkGroup ) return true; return false; }
public override void CloneDataFromRead(PngChunk other) { PngChunkSRGB pngChunkSRGB = (PngChunkSRGB)other; Intent = pngChunkSRGB.Intent; }
public bool Queue( PngChunk chunk ) { queuedChunks.Add ( chunk ); return true; }
public override void CloneDataFromRead(PngChunk other) { PngChunkHIST otherx = (PngChunkHIST)other; hist = new int[otherx.hist.Length]; System.Array.Copy((Array)(otherx.hist), 0, (Array)(this.hist), 0, otherx.hist.Length); }
public bool RemoveChunk( PngChunk c ) { return queuedChunks.Remove ( c ); }
/// <summary> /// We consider a chunk as "unknown" if our chunk factory (even when it has been augmented by client code) doesn't recognize it /// </summary> /// <param name="chunk"></param> /// <returns></returns> public static bool IsUnknown(PngChunk chunk) { return chunk is PngChunkUNKNOWN; }
/// <summary> /// Creates predicate based of reference chunk /// </summary> /// <param name="chunk"></param> public ChunkPredicateEquiv(PngChunk chunk) { this.chunk = chunk; }
public override void CloneDataFromRead(PngChunk other) { gamma = ((PngChunkGAMA)other).gamma; }
/// <summary> /// Check for match /// </summary> /// <param name="c"></param> /// <returns></returns> public bool Matches(PngChunk c) { return ChunkHelper.Equivalent(c, chunk); }
public sealed override void CloneDataFromRead(PngChunk other) => throw new System.Exception("Non supported for a skipped chunk");
public void CopyChunks(PngReader reader, int copy_mask, bool onlyAfterIdat) { bool flag = CurrentChunkGroup >= 4; if (onlyAfterIdat && reader.CurrentChunkGroup < 6) { throw new PngjException("tried to copy last chunks but reader has not ended"); } foreach (PngChunk chunk in reader.GetChunksList().GetChunks()) { if (chunk.ChunkGroup >= 4 || !flag) { bool flag2 = false; if (chunk.Crit) { if (chunk.Id.Equals("PLTE")) { if (ImgInfo.Indexed && ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_PALETTE)) { flag2 = true; } if (!ImgInfo.Greyscale && ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_ALL)) { flag2 = true; } } } else { bool flag3 = chunk is PngChunkTextVar; bool safe = chunk.Safe; if (ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_ALL)) { flag2 = true; } if (safe && ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_ALL_SAFE)) { flag2 = true; } if (chunk.Id.Equals("tRNS") && ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_TRANSPARENCY)) { flag2 = true; } if (chunk.Id.Equals("pHYs") && ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_PHYS)) { flag2 = true; } if (flag3 && ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_TEXTUAL)) { flag2 = true; } if (ChunkHelper.maskMatch(copy_mask, ChunkCopyBehaviour.COPY_ALMOSTALL) && !(ChunkHelper.IsUnknown(chunk) | flag3) && !chunk.Id.Equals("hIST") && !chunk.Id.Equals("tIME")) { flag2 = true; } if (chunk is PngChunkSkipped) { flag2 = false; } } if (flag2) { chunksList.Queue(PngChunk.CloneChunk(chunk, ImgInfo)); } } } }