internal int WriteChunks(IO.Stream os, int currentGroup)
        {
            List <int> written = new List <int>();

            for (int i = 0; i < queuedChunks.Count; i++)
            {
                PngChunk chunk = queuedChunks[i];

                if (!ShouldWrite(chunk, currentGroup))
                {
                    continue;
                }

                if (ChunkHelper.IsCritical(chunk.Id) && !chunk.Id.Equals(ChunkHelper.PLTE))
                {
                    throw new System.IO.IOException($"bad chunk queued: {chunk}");
                }
                if (alreadyWrittenKeys.ContainsKey(chunk.Id) && !chunk.AllowsMultiple())
                {
                    throw new System.IO.IOException($"duplicated chunk does not allow multiple: {chunk}");
                }

                chunk.Write(os);
                chunks.Add(chunk);
                alreadyWrittenKeys[chunk.Id] = alreadyWrittenKeys.ContainsKey(chunk.Id) ? alreadyWrittenKeys[chunk.Id] + 1 : 1;
                written.Add(i);
                chunk.ChunkGroup = currentGroup;
            }
            for (int k = written.Count - 1; k != -1; k--)
            {
                queuedChunks.RemoveAt(written[k]);
            }
            return(written.Count);
        }
Exemple #2
0
        internal int writeChunks(Stream os, int currentGroup)
        {
            List <int> written = new List <int>();

            for (int i = 0; i < queuedChunks.Count; i++)
            {
                PngChunk c = queuedChunks[i];
                if (!shouldWrite(c, currentGroup))
                {
                    continue;
                }
                if (ChunkHelper.IsCritical(c.Id) && !c.Id.Equals(ChunkHelper.PLTE))
                {
                    throw new PngjOutputException("bad chunk queued: " + c);
                }
                if (alreadyWrittenKeys.ContainsKey(c.Id) && !c.AllowsMultiple())
                {
                    throw new PngjOutputException("duplicated chunk does not allow multiple: " + c);
                }
                c.write(os);
                chunks.Add(c);
                alreadyWrittenKeys[c.Id] = alreadyWrittenKeys.ContainsKey(c.Id) ? alreadyWrittenKeys[c.Id] + 1 : 1;
                written.Add(i);
                c.ChunkGroup = currentGroup;
            }
            for (int k = written.Count - 1; k >= 0; k--)
            {
                queuedChunks.RemoveAt(written[k]);
            }
            return(written.Count);
        }
Exemple #3
0
 /// <summary>
 /// Constructs an empty chunk
 /// </summary>
 /// <param name="id"></param>
 /// <param name="imgInfo"></param>
 protected PngChunk(string id, ImageInfo imgInfo)
 {
     Id         = id;
     ImgInfo    = imgInfo;
     Crit       = ChunkHelper.IsCritical(id);
     Pub        = ChunkHelper.IsPublic(id);
     Safe       = ChunkHelper.IsSafeToCopy(id);
     Priority   = false;
     ChunkGroup = -1;
     Length     = -1;
     Offset     = 0;
 }