Exemplo n.º 1
0
        /// <inheritdoc />
        public byte[] Decode(IReadOnlyList <byte> input, DictionaryToken streamDictionary, int filterIndex)
        {
            var parameters = DecodeParameterResolver.GetFilterParameters(streamDictionary, filterIndex);

            var predictor = parameters.GetIntOrDefault(NameToken.Predictor, -1);

            var earlyChange = parameters.GetIntOrDefault(NameToken.EarlyChange, 1);

            if (predictor > 1)
            {
                var decompressed = Decode(input, earlyChange == 1);

                var colors           = Math.Min(parameters.GetIntOrDefault(NameToken.Colors, DefaultColors), 32);
                var bitsPerComponent = parameters.GetIntOrDefault(NameToken.BitsPerComponent, DefaultBitsPerComponent);
                var columns          = parameters.GetIntOrDefault(NameToken.Columns, DefaultColumns);

                var result = PngPredictor.Decode(decompressed, predictor, colors, bitsPerComponent, columns);

                return(result);
            }

            var data = Decode(input, earlyChange == 1);

            return(data);
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public byte[] Decode(IReadOnlyList <byte> input, DictionaryToken streamDictionary, int filterIndex)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var parameters = DecodeParameterResolver.GetFilterParameters(streamDictionary, filterIndex);

            var predictor = parameters.GetIntOrDefault(NameToken.Predictor, -1);

            var bytes = input.ToArray();

            try
            {
                var decompressed = Decompress(bytes);

                if (predictor == -1)
                {
                    return(decompressed);
                }

                var colors           = Math.Min(parameters.GetIntOrDefault(NameToken.Colors, DefaultColors), 32);
                var bitsPerComponent = parameters.GetIntOrDefault(NameToken.BitsPerComponent, DefaultBitsPerComponent);
                var columns          = parameters.GetIntOrDefault(NameToken.Columns, DefaultColumns);

                var result = PngPredictor.Decode(decompressed, predictor, colors, bitsPerComponent, columns);

                return(result);
            }
            catch
            {
                // ignored.
            }

            return(bytes);
        }