public static unsafe void WriteBits(this IBitStream stream, byte *value, int byteCount, int bitLength, bool high = true) { if (bitLength < 1) { throw new ArgumentException(); } int remain = bitLength % 8; int count = (int)((bitLength - remain) / 8); if (high) { if (count > 0) { stream.Write(value, 0, count); } if (remain > 0) { stream.WriteBits(value[count], remain, true); } } else { if (remain > 0) { stream.WriteBits(value[byteCount - 1 - count], remain, false); } if (count > 0) { stream.Write(value, byteCount - count, count); } } }
//public static IEnumerator<T> DecodeHuffmanCoding<T>(this IBitStream stream) //{ //} public static void WriteBits(this IBitStream stream, byte[] value, int length, bool high = true) { if (length < 1 || length > value.Length * 8) { throw new ArgumentException(); } int remain = length % 8; int count = (int)((length - remain) / 8); if (high) { if (count > 0) { stream.Write(value, 0, count); } if (remain > 0) { stream.WriteBits(value[count], remain, true); } } else { if (remain > 0) { stream.WriteBits(value[value.Length - 1 - count], remain, false); } if (count > 0) { stream.Write(value, value.Length - count, count); } } }
public void Encode(IBitStream Buffer, int u) { if (u < 0) { throw new ArgumentOutOfRangeException (String.Format ("Invalid range for UnaryCoding, u: {0}", u)); } Buffer.Write (false, u); Buffer.Write (true); //Buffer.Write (true, u); //Buffer.Write (false); }
public void Encode(IBitStream Buffer, long u) { if (u < 1) { throw new ArgumentOutOfRangeException (String.Format ("Invalid range for elias gamma coding, u: {0}", u)); } var log2 = BitAccess.Log2 (u); --log2; unary.Encode (Buffer, log2); if (log2 <= 32) { Buffer.Write ((int)u, log2); } else { Buffer.Write ((int)u, 32); Buffer.Write (u >> 32, log2 - 32); } }
public void Serialize(double newValue, IBitStream bitStream) { int aux = (int)Math.Truncate(newValue * Math.Pow(10, _variable.DecimalPlaces)); int value = Math.Max(Math.Min(aux, (int)(_variable.MaxValue * Math.Pow(10, _variable.DecimalPlaces))), _variable.MinValue) - _variable.MinValue; bitStream.Write(value, 0, _bitLength); }
public void Encode(IBitStream Buffer, int u) { if (u < 1) { throw new ArgumentOutOfRangeException (String.Format ("Invalid range for elias delta coding, u: {0}", u)); } var log2 = BitAccess.Log2 (u); gammacoder.Encode (Buffer, log2); Buffer.Write (u, log2-1); }
public void Encode(IBitStream Buffer, int u) { if (u < 0) { throw new ArgumentOutOfRangeException (String.Format ("Invalid range for BlockCoding, u: {0}", u)); } int skip = u >> this.Power; this.SkipCoder.Encode (Buffer, skip); u &= (1 << this.Power) - 1; Buffer.Write(u, this.Power); }
public static unsafe void Write(this IBitStream stream, byte *buffer, int offset, int count) { var array = new byte[count]; for (int i = 0, j = offset; i < count; i++, j++) { array[i] = buffer[offset]; } stream.Write(array, 0, count); }
public void Encode(IBitStream stream, long u) { long check; long min = 0; int galloping = 1; while (true) { check = (1L << galloping) - 1L; if (u > check) { stream.Write (true); min = check + 1L; ++galloping; } else { stream.Write (false); if (min == 0L) { this.SecondCoding.Encode (stream, u, 2); } else { this.SecondCoding.Encode (stream, u - min, min); } break; } } }
public void Encode(IBitStream stream, long u) { long min = 0; long check; int galloping = 1; while (true) { check = (1L << galloping) - 1L; if (u > check) { stream.Write (true); min = check + 1L; ++galloping; } else { stream.Write (false); if (galloping == 1) { stream.Write (u == 1L); return; } else { u -= min; min = 0L; galloping = 1; } } } }
public void Encode(IBitStream stream, int u) { int min = 0; int galloping = 1; int check; while (true) { check = (1 << galloping) - 1; if (u > check) { stream.Write (true); min = check + 1; ++galloping; } else { stream.Write (false); if (galloping == 1) { stream.Write(u == 1); return; } else { u -= min; min = 0; galloping = 1; } } } }
public static unsafe void WriteBits(this IBitStream stream, params bool[] value) { var remain = value.Length % 8; var count = (value.Length - remain) / 8; var bytes = new byte[count + 1]; int idx; byte b; byte *bp = &b; for (int i = 0; i < count; i++) { b = 0; idx = i * 8; BitOperations.SetBit(bp, 7, value[idx + 0]); BitOperations.SetBit(bp, 6, value[idx + 1]); BitOperations.SetBit(bp, 5, value[idx + 2]); BitOperations.SetBit(bp, 4, value[idx + 3]); BitOperations.SetBit(bp, 3, value[idx + 4]); BitOperations.SetBit(bp, 2, value[idx + 5]); BitOperations.SetBit(bp, 1, value[idx + 6]); BitOperations.SetBit(bp, 0, value[idx + 7]); bytes[i] = b; } idx = count * 8; b = 0; for (int i = 0; i < remain; i++) { BitOperations.SetBit(bp, 7 - i, value[idx + i]); } bytes[count] = b; if (count > 0) { stream.Write(bytes, 0, count); } if (remain > 0) { stream.WriteBits(bytes[count], remain, true); } }
public bool End(bool initialState, uint syncVarDirtyBits) { var flag1 = false; if (_writeStream != null) { var flag2 = false; var array = _appendWriter.ToArray(); var position = (uint)_appendWriter.Position; if (_lastData != null && (int)_lastDataLength == (int)position) { flag2 = true; for (var index = 0; (long)index < (long)_lastDataLength; ++index) { if (_lastData[index] != array[index]) { flag2 = false; break; } } } var num = !flag2 ? syncVarDirtyBits : 0U; if (!initialState) { _writeStream.Serialize(ref num); } if (initialState || num != 0U) { _writeStream.Write(array, (int)_writeStream.Position, (int)position); _lastData = array; _lastDataLength = position; flag1 = position > 0U; } _writeStream = null; _appendWriter = null; } return(flag1 || initialState); }
public void Encode(IBitStream Buffer, int u) { if (u < 0) { var message = String.Format ("Negative numbers are not valid for BinaryCoding, u: {0}", u); throw new ArgumentOutOfRangeException (message); } int mask = 1 << this.NumBits; if (u >= mask) { var message = String.Format ("Number too large for {0} bits BinaryCoding, {1} >= {2}", this.NumBits, u, mask); throw new ArgumentOutOfRangeException (message); } --mask; u &= mask; Buffer.Write(u, this.NumBits); }
public void Serialize(double newValue, IBitStream bitStream) { bitStream.Write(newValue == 0 ? false : true); }
public void Serialize(double newValue, IBitStream bitStream) { int value = Math.Max(Math.Min((int)newValue, _variable.MaxValue), _variable.MinValue) - _variable.MinValue; bitStream.Write(value, 0, _bitLength); }
public void ArrayAdd(IBitStream Buffer, int val) { Buffer.Write (val, this.NumBits); }
public void Encode(IBitStream stream, int u, int N) { int min = 0; int max = N - 1; int mid; do { mid = (min >> 1) + (max >> 1); if (1 == (min & 1 & max)) { mid++; } if (u <= mid) { stream.Write (false); max = mid; } else { stream.Write (true); min = mid + 1; } } while (min < max); }