/**
         * this should be called only for ancillary chunks and PLTE (groups 1 - 3 - 5)
         **/
        static bool ShouldWrite(PngChunk chunk, int currentGroup)
        {
            if (currentGroup == CHUNK_GROUP_2_PLTE)
            {
                return(chunk.Id.Equals(ChunkHelper.PLTE));
            }
            if (currentGroup % 2 == 0)
            {
                throw new System.IO.IOException("bad chunk group?");
            }
            int minChunkGroup, maxChunkGroup;

            if (chunk.MustGoBeforePLTE())
            {
                minChunkGroup = maxChunkGroup = ChunksList.CHUNK_GROUP_1_AFTERIDHR;
            }
            else if (chunk.MustGoBeforeIDAT())
            {
                maxChunkGroup = ChunksList.CHUNK_GROUP_3_AFTERPLTE;
                minChunkGroup = chunk.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 (chunk.Priority)
            {
                preferred = minChunkGroup;
            }
            if (ChunkHelper.IsUnknown(chunk) && chunk.ChunkGroup > 0)
            {
                preferred = chunk.ChunkGroup;
            }

            if (currentGroup == preferred)
            {
                return(true);
            }
            if (currentGroup > preferred && currentGroup <= maxChunkGroup)
            {
                return(true);
            }
            return(false);
        }
Пример #2
0
        /**
         * this should be called only for ancillary chunks and PLTE (groups 1 - 3 - 5)
         **/
        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 = CHUNK_GROUP_1_AFTERIDHR;
            }
            else if (c.MustGoBeforeIDAT())
            {
                maxChunkGroup = CHUNK_GROUP_3_AFTERPLTE;
                minChunkGroup = c.MustGoAfterPLTE() ? CHUNK_GROUP_3_AFTERPLTE
                        : CHUNK_GROUP_1_AFTERIDHR;
            }
            else
            {
                maxChunkGroup = CHUNK_GROUP_5_AFTERIDAT;
                minChunkGroup = CHUNK_GROUP_1_AFTERIDHR;
            }

            int preferred = maxChunkGroup;

            if (c.Priority)
            {
                preferred = minChunkGroup;
            }
            if (currentGroup == preferred)
            {
                return(true);
            }
            if (currentGroup > preferred && currentGroup <= maxChunkGroup)
            {
                return(true);
            }
            return(false);
        }