PTWM
ptwm

ptwm.codecs

Plane-level entropy coders.

ptwm.codecs

Plane-level entropy coders.

pymodule

ptwm.codecs

python/ptwm/codecs/__init__.py:1
module ptwm.codecs

Plane-level entropy coders.

Exposes the four entropy coders (IDENTITY, Huffman, rANS, ZSTD) behind the uniform :class:`Codec` protocol, so callers can write ``get_codec(name).encode(plane.data)`` without caring which coder backs the name. Each codec operates on a single byte buffer — no preprocessing, no header framing. Call :func:`ptwm.preprocessing.split` first to obtain planes, feed each into a codec, and collect the blobs. The inverse runs the coder's :meth:`Codec.decode` on each blob and passes the recovered bytes to :func:`ptwm.preprocessing.combine`.
pyclass

ptwm.codecs.Codec

python/ptwm/codecs/__init__.py:26
class Codec(Protocol):

Plane-level entropy coder.

pymethod

ptwm.codecs.Codec.decode

python/ptwm/codecs/__init__.py:36
def decode(self, blob: bytes | memoryview, original_len: int) -> bytes

Decode ``blob`` back to the original bytes.

``original_len`` is the uncompressed length (in bytes) of the data passed to :meth:`encode`. Some codecs self-describe the original length (e.g. ZSTD) and verify against it; others need it to pre- allocate the output (Huffman, rANS).
pymethod

ptwm.codecs.Codec.encode

python/ptwm/codecs/__init__.py:32
def encode(self, data: bytes | memoryview) -> bytes

Encode ``data`` into a codec-specific blob.

pyattribute

ptwm.codecs.Codec.name

python/ptwm/codecs/__init__.py:30
name: str
pyclass

ptwm.codecs.CodecId

python/ptwm/codecs/__init__.py:169
class CodecId(IntEnum):

Numeric codec identifiers — wire identifiers, never reassign.

These values are baked into every ``.ptwm`` container's plane and prelude records; renumbering them breaks the wire format. Mirrors ``crates/ptwm-core/src/codec.rs::CodecId``.
pyattribute

ptwm.codecs.CodecId.ArithmeticO0

python/ptwm/codecs/__init__.py:186
ArithmeticO0 = 18
pyattribute

ptwm.codecs.CodecId.ArithmeticO0Adaptive

python/ptwm/codecs/__init__.py:187
ArithmeticO0Adaptive = 19
pyattribute

ptwm.codecs.CodecId.ArithmeticO1

python/ptwm/codecs/__init__.py:188
ArithmeticO1 = 20
pyattribute

ptwm.codecs.CodecId.ContextMixingLite

python/ptwm/codecs/__init__.py:189
ContextMixingLite = 21
pyattribute

ptwm.codecs.CodecId.Fpc

python/ptwm/codecs/__init__.py:182
Fpc = 6
pyattribute

ptwm.codecs.CodecId.HuffLlm5Bit

python/ptwm/codecs/__init__.py:190
HuffLlm5Bit = 22
pyattribute

ptwm.codecs.CodecId.Huffman

python/ptwm/codecs/__init__.py:178
Huffman = 1
pyattribute

ptwm.codecs.CodecId.Identity

python/ptwm/codecs/__init__.py:177
Identity = 0
pyattribute

ptwm.codecs.CodecId.NeuralPredictor

python/ptwm/codecs/__init__.py:192
NeuralPredictor = 24
pyattribute

ptwm.codecs.CodecId.Order1Arithmetic

python/ptwm/codecs/__init__.py:191
Order1Arithmetic = 23
pyattribute

ptwm.codecs.CodecId.Order1ScaleAC

python/ptwm/codecs/__init__.py:185
Order1ScaleAC = 17
pyattribute

ptwm.codecs.CodecId.PerGroupCodebook

python/ptwm/codecs/__init__.py:184
PerGroupCodebook = 16
pyattribute

ptwm.codecs.CodecId.Rans

python/ptwm/codecs/__init__.py:179
Rans = 3
pyattribute

ptwm.codecs.CodecId.Tans

python/ptwm/codecs/__init__.py:183
Tans = 7
pyattribute

ptwm.codecs.CodecId.Zstd

python/ptwm/codecs/__init__.py:180
Zstd = 4
pyattribute

ptwm.codecs.CodecId.ZstdDict

python/ptwm/codecs/__init__.py:181
ZstdDict = 5
pyfunction

ptwm.codecs.decode_planes

python/ptwm/codecs/__init__.py:153
def decode_planes(blobs: Sequence[bytes | memoryview], original_lens: Sequence[int], codec: Codec | str) -> list[bytes]

Decode each blob with ``codec``, using the matching ``original_lens[i]``.

pyfunction

ptwm.codecs.encode_planes

python/ptwm/codecs/__init__.py:144
def encode_planes(planes: Sequence[Plane | bytes | memoryview], codec: Codec | str) -> list[bytes]

Encode each plane with ``codec``. Returns one blob per plane.

pyfunction

ptwm.codecs.get_codec

python/ptwm/codecs/__init__.py:129
def get_codec(name: str) -> Codec

Look up a codec by short name.

Known names: ``"identity"``, ``"huffman"``, ``"rans"``, ``"zstd"``. ``"zstd"`` returns the default level-3 variant; construct :class:`ZstdCodec` directly for other levels.
pyclass

ptwm.codecs.HuffmanCodec

python/ptwm/codecs/__init__.py:62
class HuffmanCodec:

Canonical-Huffman entropy coder (4-stream interleaved).

pymethod

ptwm.codecs.HuffmanCodec.__init__

python/ptwm/codecs/__init__.py:1
def __init__(self, name: str = 'huffman') -> None
pymethod

ptwm.codecs.HuffmanCodec.decode

python/ptwm/codecs/__init__.py:72
def decode(self, blob: bytes | memoryview, original_len: int) -> bytes

Decode a Huffman blob produced by :meth:`encode`.

pymethod

ptwm.codecs.HuffmanCodec.encode

python/ptwm/codecs/__init__.py:68
def encode(self, data: bytes | memoryview) -> bytes

Huffman-encode ``data``; falls back to tagged-raw if not beneficial.

pyattribute

ptwm.codecs.HuffmanCodec.name

python/ptwm/codecs/__init__.py:66
name: str = 'huffman'
pyclass

ptwm.codecs.IdentityCodec

python/ptwm/codecs/__init__.py:47
class IdentityCodec:

Passthrough codec: ``encode`` and ``decode`` return their input.

pymethod

ptwm.codecs.IdentityCodec.__init__

python/ptwm/codecs/__init__.py:1
def __init__(self, name: str = 'identity') -> None
pymethod

ptwm.codecs.IdentityCodec.decode

python/ptwm/codecs/__init__.py:57
def decode(self, blob: bytes | memoryview, original_len: int) -> bytes

Return ``blob`` unchanged after a length check.

pymethod

ptwm.codecs.IdentityCodec.encode

python/ptwm/codecs/__init__.py:53
def encode(self, data: bytes | memoryview) -> bytes

Return ``data`` unchanged.

pyattribute

ptwm.codecs.IdentityCodec.name

python/ptwm/codecs/__init__.py:51
name: str = 'identity'
pyclass

ptwm.codecs.RansCodec

python/ptwm/codecs/__init__.py:77
class RansCodec:

Range-asymmetric-numeral-systems entropy coder.

pymethod

ptwm.codecs.RansCodec.__init__

python/ptwm/codecs/__init__.py:1
def __init__(self, name: str = 'rans') -> None
pymethod

ptwm.codecs.RansCodec.decode

python/ptwm/codecs/__init__.py:87
def decode(self, blob: bytes | memoryview, original_len: int) -> bytes

Decode an rANS blob produced by :meth:`encode`.

pymethod

ptwm.codecs.RansCodec.encode

python/ptwm/codecs/__init__.py:83
def encode(self, data: bytes | memoryview) -> bytes

rANS-encode ``data``; falls back to tagged-raw if not beneficial.

pyattribute

ptwm.codecs.RansCodec.name

python/ptwm/codecs/__init__.py:81
name: str = 'rans'
pyclass

ptwm.codecs.ZstdCodec

python/ptwm/codecs/__init__.py:92
class ZstdCodec:

ZSTD entropy coder. ``level`` is the standard 1-22 compression level.

pymethod

ptwm.codecs.ZstdCodec.__init__

python/ptwm/codecs/__init__.py:1
def __init__(self, level: int = 3) -> None
pymethod

ptwm.codecs.ZstdCodec.decode

python/ptwm/codecs/__init__.py:107
def decode(self, blob: bytes | memoryview, original_len: int) -> bytes

Decode a ZSTD blob and verify its length matches ``original_len``.

pymethod

ptwm.codecs.ZstdCodec.encode

python/ptwm/codecs/__init__.py:103
def encode(self, data: bytes | memoryview) -> bytes

ZSTD-encode ``data`` at ``self.level``.

pyattribute

ptwm.codecs.ZstdCodec.level

python/ptwm/codecs/__init__.py:96
level: int = 3
pyattribute

ptwm.codecs.ZstdCodec.name

python/ptwm/codecs/__init__.py:99
name: str

Short codec name suffixed by level (e.g. ``zstd-3``).