Ich verwende derzeit die arithmetische Codierung, die funktioniert, aber ich dachte, ich könnte es besser machen. AI schlug rANS Duda mit der folgenden Implementierung vor. Es funktioniert jedoch nicht. Die Arbeit übersteigt mein mathematisches Verständnis. Kann jemand auf die Fehler hinweisen?
Code: Select all
//Common declarations:
static class Rans
{
public const uint L = 1u = Rans.L * model.total)
{
output.Add((byte)(x & 0xFF));
x >>= 8;
}
x = (x / freq) * model.total + (x % freq) + cum;
}
for (int i = 0; i < 4; i++)
{
output.Add((byte)(x & 0xFF));
x >>= 8;
}
return output.ToArray();
}
}
//Decoder:
static class RansDecoder
{
public static string Decode(byte[] data, int bitCount, uint count0, uint count1)
{
var model = new BitModel(count0, count1);
int idx = data.Length - 1;
uint x = 0;
while (idx >= 0 && x < Rans.L)
{
x = (x > Rans.SCALE_BITS) + (v - cum);
while (x < Rans.L && idx >= 0)
{
x = (x c == '0');
uint count1 = (uint)bits.Length - count0;
var e = RansEncoder.Encode(bits, count0, count1);
var d = RansDecoder.Decode(e, bits.Length, count0, count1);
Console.WriteLine(bits);
Console.WriteLine(d);
Mobile version