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); }
public static void TestData(int[] data, int symMax, int symDataMax, int rlStages, params int[] symRle) { //int[] trip; //RunLengthCodec enc = new RunLengthCodec(symMax, symDataMax, rlStages, symRle); //RunLengthCodec dec = new RunLengthCodec(symMax, symDataMax, rlStages, symRle); //trip = dec.Decode(enc.Encode(data)); //Assert.IsTrue(data.SequenceEqual(trip)); //ulong[] probs = CodecUtil.CountValues(data); //ArithmeticCodec enca = new ArithmeticCodec(probs); //ArithmeticCodec deca = new ArithmeticCodec(probs); //trip = deca.Decode(enca.Encode(data)); //Assert.IsTrue(data.SequenceEqual(trip)); if (symDataMax == 1) { //RunLength01Codec encz = new RunLength01Codec(); //RunLength01Codec decz = new RunLength01Codec(); //trip = decz.Decode(encz.Encode(data)); //Assert.IsTrue(data.SequenceEqual(trip)); //RunLength01MaxCodec enczm = new RunLength01MaxCodec(15); //RunLength01MaxCodec deczm = new RunLength01MaxCodec(15); //trip = deczm.Decode(enczm.Encode(data)); //Assert.IsTrue(data.SequenceEqual(trip)); //RunLength01MaxSmartCodec enczs = new RunLength01MaxSmartCodec(15); //RunLength01MaxSmartCodec deczs = new RunLength01MaxSmartCodec(15); //trip = deczs.Decode(enczs.Encode(data)); //Assert.IsTrue(data.SequenceEqual(trip)); } { ulong[] input = data.Select(val => (ulong)val).ToArray(); MemoryStream ms = new MemoryStream(); CodecUtil.SaveFreqs(ms, input, TimwiCecCompressor.runLProbsProbs, ""); ms.Position = 0; ulong[] freqs = CodecUtil.LoadFreqs(ms, TimwiCecCompressor.runLProbsProbs, data.Length); Assert.IsTrue(input.SequenceEqual(freqs)); } }