Example #1
0
        public override IntField Decode(Stream input)
        {
            // Read size
            int w = (int)input.ReadUInt32Optim();
            int h = (int)input.ReadUInt32Optim();

            // Read probabilities
            ulong[] probs = CodecUtil.LoadFreqsCrappy(input, FieldcodeSymbols + 1);
            // Read fields
            ArithmeticSectionsCodec ac = new ArithmeticSectionsCodec(probs, 6);

            ac.Decode(input);
            var fields = new List <int[]>();

            for (int i = 1; i <= 3; i++)
            {
                fields.Add(ac.ReadSection());
            }

            // Undo fieldcode
            IntField transformed = CodecUtil.FieldcodeRunlengthsDe(fields, w, h, new RunLength01MaxSmartCodec(FieldcodeSymbols), this);

            // Undo predictive transform
            transformed.PredictionDeTransformXor(Seer);
            transformed.ArgbFromField(0, 3);
            return(transformed);
        }
Example #2
0
        public override IntField Decode(Stream input)
        {
            // Read size
            int w = (int)input.ReadUInt32Optim();
            int h = (int)input.ReadUInt32Optim();

            // Read probabilities
            ulong[] probs = CodecUtil.LoadFreqs(input, TimwiCecCompressor.runLProbsProbs, RLE.MaxSymbol + 1);
            // Read fields
            int len = (int)input.ReadUInt32Optim();
            ArithmeticCodingReader acr = new ArithmeticCodingReader(input, probs);

            int[] fields = new int[len];
            for (int p = 0; p < len; p++)
            {
                fields[p] = acr.ReadSymbol();
            }

            // Undo fieldcode
            IntField transformed = CodecUtil.FieldcodeRunlengthsDe2(fields, w, h, RLE, this);

            // Undo predictive transform
            transformed.PredictionDeTransformXor(Seer);
            transformed.ArgbFromField(0, 3);
            return(transformed);
        }