Skip to main content

Python implementation of carry-less range coder

Project description

Both static and dynamic encoding can be used.

Install

$ pip install CarryLessRangeCoder

Examples

from collections import Counter
import carryless_rangecoder as rc
from io import BytesIO

data = list(map(ord, 'qawsedrftgyhujikolp;'))
count = [1] * 256
for i, c in Counter(data).items():
    count[i] += c
count_cum = [0] * 256
for i in range(1, 256):
    count_cum[i] = count[i] + count_cum[i - 1]

out = BytesIO()
# Encode
with rc.Encoder(out) as enc:  # or enc.finish()
    for index in data:
        enc.encode(count, count_cum, index)
# Decode
decoded = []
with rc.Decode(out) as dec:  # or dec.start()
    for _ in range(len(data)):
        decoded.append(dec.decode(count, count_cum))

assert decoded == data

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

CarryLessRangeCoder-1.0.2.tar.gz (3.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page