public override void Encode(IntField image, Stream output) { // Predictive transform image.ArgbTo4c(); image.PredictionEnTransformXor(Seer); // Convert to three fields' runlengths var fields = CodecUtil.FieldcodeRunlengthsEn(image, new RunLength01MaxSmartCodec(FieldcodeSymbols), this); // Write size DeltaTracker pos = new DeltaTracker(); output.WriteUInt32Optim((uint)image.Width); output.WriteUInt32Optim((uint)image.Height); SetCounter("bytes|size", pos.Next(output.Position)); // Write probs ulong[] probs = CodecUtil.GetFreqsForAllSections(fields, FieldcodeSymbols + 1); probs[0] = 6; CodecUtil.SaveFreqsCrappy(output, probs); SetCounter("bytes|probs", pos.Next(output.Position)); // Write fields ArithmeticSectionsCodec ac = new ArithmeticSectionsCodec(probs, 6, output); for (int i = 0; i < fields.Count; i++) { ac.WriteSection(fields[i]); SetCounter("bytes|fields|" + (i + 1), pos.Next(output.Position)); } ac.Encode(); SetCounter("bytes|arith-err", pos.Next(output.Position)); }
public override void Encode(IntField image, Stream output) { // Predictive transform image.ArgbTo4c(); image.PredictionEnTransformXor(Seer); // Convert to three fields' runlengths var fields = CodecUtil.FieldcodeRunlengthsEn2(image, RLE, this); SetCounter("rle|longer", (RLE as RunLength01LongShortCodec).Counter_Longers); SetCounter("rle|muchlonger", (RLE as RunLength01LongShortCodec).Counter_MuchLongers); // Write size DeltaTracker pos = new DeltaTracker(); output.WriteUInt32Optim((uint)image.Width); output.WriteUInt32Optim((uint)image.Height); SetCounter("bytes|size", pos.Next(output.Position)); // Write probs ulong[] probs = CodecUtil.CountValues(fields, RLE.MaxSymbol); CodecUtil.SaveFreqs(output, probs, TimwiCecCompressor.runLProbsProbs, ""); SetCounter("bytes|probs", pos.Next(output.Position)); // Write fields ArithmeticWriter aw = new ArithmeticWriter(output, probs); output.WriteUInt32Optim((uint)fields.Length); foreach (var sym in fields) { aw.WriteSymbol(sym); } aw.Flush(); SetCounter("bytes|fields", pos.Next(output.Position)); }