Ejemplo n.º 1
0
        public static T CloneChunk <T>(T chunk, ImageInfo info) where T : PngChunk
        {
            PngChunk pngChunk = FactoryFromId(chunk.Id, info);

            if ((object)pngChunk.GetType() != chunk.GetType())
            {
                throw new PngjException("bad class cloning chunk: " + pngChunk.GetType()?.ToString() + " " + chunk.GetType()?.ToString());
            }
            pngChunk.CloneDataFromRead(chunk);
            return((T)pngChunk);
        }
Ejemplo n.º 2
0
        /* @SuppressWarnings("unchecked")*/
        public static T CloneChunk <T>(T chunk, ImageInfo info) where T : PngChunk
        {
            PngChunk cn = FactoryFromId(chunk.Id, info);

            if ((Object)cn.GetType() != (Object)chunk.GetType())
            {
                throw new PngjException("bad class cloning chunk: " + cn.GetType() + " "
                                        + chunk.GetType());
            }
            cn.CloneDataFromRead(chunk);
            return((T)cn);
        }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 /// <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);
 }