zx-codec 1.0.0__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyzx.py ADDED
@@ -0,0 +1,9 @@
1
+ """Legacy import for ZX Codec when no package named pyzx takes precedence."""
2
+ import sys
3
+
4
+ import zxcodec
5
+
6
+ for name, module in tuple(sys.modules.items()):
7
+ if name.startswith("zxcodec."):
8
+ sys.modules.setdefault("pyzx" + name[len("zxcodec"):], module)
9
+ sys.modules[__name__] = zxcodec
@@ -0,0 +1,271 @@
1
+ Metadata-Version: 2.4
2
+ Name: zx-codec
3
+ Version: 1.0.0
4
+ Summary: High-speed lossless image, multichannel HDR, camera RAW, and all-intra video readers and writers for NumPy and PyTorch
5
+ Author: ZX-Codec Contributors
6
+ Keywords: image-codec, video-codec, lossless, hdr, openexr, pytorch, numpy, multimodal, ai-training
7
+ Project-URL: Homepage, https://github.com/7owel/ZX-Codec
8
+ Project-URL: Releases, https://github.com/7owel/ZX-Codec/releases
9
+ Project-URL: Documentation, https://github.com/7owel/ZX-Codec/blob/main/docs/BENCHMARKS.md
10
+ Project-URL: Issues, https://github.com/7owel/ZX-Codec/issues
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: MacOS :: MacOS X
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Multimedia :: Graphics
24
+ Classifier: Topic :: Multimedia :: Video
25
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
26
+ Requires-Python: >=3.10
27
+ Requires-Dist: numpy>=1.24
28
+ License-File: THIRD_PARTY_NOTICES.txt
29
+ Description-Content-Type: text/markdown
30
+
31
+ # ZX Codec for Python
32
+
33
+ Install the `zx-codec` distribution and import `zxcodec`. It requires Python 3.10 or newer and NumPy 1.24 or newer. The Windows x64 wheel selects baseline or accelerated kernels at runtime according to processor and operating-system support. The Linux x86-64 and ARM64 release wheels target glibc 2.28 or newer.
34
+
35
+ ```console
36
+ python -m pip install zx-codec
37
+ ```
38
+
39
+ To install a prebuilt release wheel offline:
40
+
41
+ ```console
42
+ python -m pip install --no-index --find-links . zx-codec
43
+ ```
44
+
45
+ Legacy code can import `pyzx` when that name is available. In an environment with the quantum-computing `pyzx` package in the same installation directory, `import pyzx` loads the quantum package and `import zxcodec` loads ZX Codec. In environments with multiple installation directories, Python follows its usual import path order. If an older ZX Codec wheel using the `pyzx` distribution name is installed, use `import zxcodec` to select the new implementation.
46
+
47
+ Build a native wheel from the complete ZX source checkout using CMake 3.25 or newer, Ninja and a C++20 compiler. Use `--config-settings build-dir=/absolute/path/to/build` to reuse a Release Ninja build of the same checkout with `ZX_BUILD_PYTHON=ON`.
48
+
49
+ ```console
50
+ python -m pip wheel --no-deps ./bindings/python
51
+ ```
52
+
53
+ The release version comes from the source tree's `VERSION` file. Set
54
+ `ZX_PYTHON_VERSION=1.0.0` before configuring a fresh build, or pass
55
+ `-DZX_PYTHON_VERSION=1.0.0` to CMake, to select a different wheel version.
56
+
57
+ ```python
58
+ import zxcodec as pyzx
59
+
60
+ encoded = pyzx.encode_zxi(rgba16, icc=profile, preset="fast", threads=4)
61
+ full = pyzx.decode_zxi(encoded, threads=4)
62
+
63
+ with pyzx.RasterReader("pyramid.zxil") as image:
64
+ first, stats = image.read_tile(511, 519, 1024, 1024, return_stats=True)
65
+ crops = image.read_tiles([(32, 64, 512, 512), (384, 640, 512, 512)])
66
+ thumbnail = image.thumbnail(max_size=256)
67
+ icc = image.read_icc()
68
+
69
+ planes = pyzx.read_hdr("workboard.zxf", channels=["Depth", "Flow.X"], threads=4)
70
+ sensor = pyzx.read_raw("camera.zxrw", threads=4)
71
+ rgb = pyzx.read_raw_preview("camera.zxrw", half=True, threads=4)
72
+ frame = pyzx.read_frame("production.zxv1", 13, threads=4)
73
+ ```
74
+
75
+ Raster rectangles are layer-local at the requested pyramid level. Layer and frame indices start at zero. Use `layer=None` to choose the stored preview when present. HDR returns named, bit-preserving `float16`, `float32` or `uint32` planes. RAW reads return the native sensor values or a separate oriented RGB8 development. Video returns a tuple of native planes in the file's pixel-format order, with 10/12-bit samples in little-endian `uint16`. Returned arrays remain valid after the reader closes. ZVL2 is a lossy edit profile. Its arrays reflect the stored stream.
76
+
77
+ Pass a path or a C-contiguous byte buffer to `RasterReader`, `read_roi`, or
78
+ `HDRReader`. The reader holds a borrowed buffer until it closes. Keep mutable
79
+ sources unchanged during that lifetime. `encode_zxi` returns a read-only
80
+ `memoryview` over the native result. Set `as_bytes=True` for a detached Python
81
+ `bytes` copy. The in-memory ZXI, tiled ZXIL and ZXF read paths use no temporary
82
+ files. Decoders can allocate destination arrays or fill caller-owned arrays.
83
+
84
+ With a tiled `RasterReader`, `open_read_bytes` reports the native input reads
85
+ during opening. `return_stats=True` reports reads for each crop call or the
86
+ sum for a batch, including reference tile reads when required. These are bytes
87
+ read from the source abstraction and do not measure physical disk traffic.
88
+
89
+ ### Reading from object storage
90
+
91
+ `read_roi`, `read_hdr` and `read_video_frame` also accept HTTP(S) URLs, fsspec
92
+ URLs and open, seekable binary streams. The matching readers and raster/HDR
93
+ batch APIs accept the same sources and can reuse an open reader across requests.
94
+
95
+ ```python
96
+ pixels = pyzx.read_roi(signed_zxi_url, 32, 64, 128, 96)
97
+ frame = pyzx.read_video_frame(signed_video_url, 13, threads=8)
98
+
99
+ with pyzx.open_range("s3://bucket/workboard.zxf", storage_options={"anon": True}) as source:
100
+ depth = pyzx.read_hdr(source, channels="Depth", roi=(32, 64, 128, 96))["Depth"]
101
+ ```
102
+
103
+ For an HTTP(S) object, the reader uses a one-byte probe to obtain the object
104
+ size, then requests the ranges required by the selected image region,
105
+ channels, or video frame. It validates `206 Partial Content` and the response
106
+ bounds, rejects `200 OK` without reading its body and uses a strong ETag when
107
+ available to keep reads on the same version. Use a signed URL or pass
108
+ `headers=` to `open_range()` for an authenticated HTTP source. When opened
109
+ explicitly, the range source exposes `.size`, `.read_at(offset, length)` and
110
+ HTTP `.stats`. Readable objects must stay open and stable until their ZX
111
+ reader closes. The caller owns supplied streams and range sources. A supplied
112
+ seekable stream retains its original position between calls. A custom
113
+ `read_at(offset, length)` source can supply its size as an attribute or via
114
+ `open_range(source, size=...)`.
115
+
116
+ For `s3://` and other fsspec protocols, install fsspec and the appropriate
117
+ backend, such as s3fs. ZX opens these URLs with the backend's read cache
118
+ disabled. An already open stream uses the caller's cache settings. A ranged
119
+ video reader reports frame count, dimensions, bit depth, time base and pixel
120
+ format. Path-based `VideoReader.info` also reports the full local metadata.
121
+
122
+ For frequent selective reads of a ZXF2 image, build its channel companion
123
+ once at ingest. Save the returned source SHA-256 in the dataset manifest.
124
+ The reader uses it to check the association without fetching the original.
125
+
126
+ ```python
127
+ meta = pyzx.build_zxf_companion("workboard.zxf", "workboard.range.bin",
128
+ channels=["Z", "N.X", "N.Y", "N.Z"])
129
+ with pyzx.open_zxf_companion(companion_url, source_digest=meta["source_digest"]) as selected:
130
+ depth = selected.read("Z", threads=4)["Z"]
131
+ transferred = selected.stats["payload_bytes"]
132
+ ```
133
+
134
+ A cold HTTP read of a contiguous group of whole lanes takes four successful
135
+ range requests, including the one-byte probe. A partial-height ROI fetches
136
+ only its intersecting stripes in each lane. Selected packet checksums are
137
+ verified before decoding. Use `read_hdr(original, channels=...)` for an
138
+ unindexed channel or an object without a companion. Older version-1
139
+ companions support the same read API and omit checksum and source-digest
140
+ metadata. Supplying `source_digest` requires a version-2 companion.
141
+
142
+ ### Batch destinations
143
+
144
+ For local ZXV1 files, `VideoReader.read_frames(indices, out=..., workers=...)`
145
+ decodes arbitrary indices in order, including repeated frames. For multiple
146
+ cameras, keep the readers and a reusable pool of 1–32 workers open:
147
+
148
+ ```python
149
+ import torch
150
+ from zxcodec import VideoBatch, VideoReader
151
+
152
+ with VideoReader("left.zxv1") as left, VideoReader("right.zxv1") as right:
153
+ with VideoBatch(workers=4) as batch:
154
+ cameras = (left, right)
155
+ rows = [(13, 12), (2, 2), (7, 6)]
156
+ shape, dtype = batch.output_shape(cameras, len(rows) * len(cameras))
157
+ host = torch.empty(shape, dtype=getattr(torch, dtype.name), pin_memory=True)
158
+ batch.read_synchronized(cameras, rows, out=host)
159
+ device = host.to("cuda", non_blocking=True)
160
+ torch.cuda.synchronize() # Reuse host only after the copy finishes.
161
+ ```
162
+
163
+ Each row supplies a common index or one index per camera. Results follow row
164
+ order, then camera order. Readers must use the same geometry and pixel format.
165
+ Equal-sized native planes yield `(frames, channels, height, width)`. Subsampled
166
+ formats or `packed=True` yield `uint8` rows of length `reader.frame_bytes`.
167
+ `reader.plane_shapes` gives the geometry of each plane.
168
+
169
+ The decoder fills a contiguous CPU tensor or writable, aligned C-contiguous NumPy
170
+ array directly. Without `out`, it allocates a NumPy result. `torch.from_dlpack`
171
+ shares this storage on CPU. The separate CUDA upload copies the decoded bytes.
172
+ Corrupt packets can leave partial output. For remote video, use `read_frame`.
173
+ In multi-worker PyTorch `DataLoader` pipelines, open each `VideoReader` inside
174
+ the worker process that reads it.
175
+
176
+ ```python
177
+ import numpy as np
178
+ import zxcodec as pyzx
179
+
180
+ rects = [(32, 64, 128, 96), (384, 640, 128, 96)]
181
+ with pyzx.RasterReader("pyramid.zxil") as image:
182
+ pixels = np.empty((2, 96, 128, 3), dtype=np.uint8)
183
+ assert image.read_tiles(rects, out=pixels) is pixels
184
+
185
+ depth = np.empty((2, 1, 96, 128), dtype=np.float32)
186
+ assert pyzx.read_hdr_batch(["frame-01.zxf", "frame-02.zxf"], channels="Depth",
187
+ roi=rects[0], out=depth) is depth
188
+ ```
189
+
190
+ `read_raster_batch` and `read_hdr_batch` read one item per source in order.
191
+ Pass `roi=` to repeat a rectangle, `rois=` for one rectangle per source or
192
+ omit both to read full frames. `HDRReader.read_batch(rois)` reuses an open
193
+ source for multiple rectangles. Each dense batch requires matching region
194
+ dimensions, channels and dtypes. `RasterReader.read_tiles(rects)` keeps its
195
+ list result unless `out=` or an explicit `layout=` requests a dense batch.
196
+
197
+ Raster batches write interleaved `(B,H,W,C)` (`layout="BHWC"`). A homogeneous
198
+ HDR selection writes planar `(B,C,H,W)` (`layout="BCHW"`) in the selected
199
+ channel order. Either layout spelling works for one channel or one pixel,
200
+ where the byte order is identical. Other layout requests raise `ValueError`.
201
+ Pass `{name: array}` for mixed HDR, with a separate `(B,H,W)` array in each
202
+ channel's stored type. The same name must keep its dtype across sources. The
203
+ named path issues separate channel reads into those arrays.
204
+
205
+ Each `out` array must be writable, aligned, C-contiguous and have the exact
206
+ shape and dtype. It is returned by identity. The decoder writes its output
207
+ into each batch slot and uses its usual tile or stripe workspace. If data
208
+ decoding fails, slots may already contain decoded pixels. NumPy arrays can be
209
+ borrowed by `torch.from_dlpack` on CPU without copying their sample data.
210
+
211
+ ```python
212
+ import torch
213
+
214
+ tensor = torch.from_dlpack(depth)
215
+ assert tensor.data_ptr() == depth.ctypes.data
216
+ ```
217
+
218
+ For repeated RAW reads, pass a writable array of the same shape and dtype as `out=`. A `RawReader` also keeps the file mapping open between reads.
219
+
220
+ `verify(path)` runs the native whole-stream validation. An invalid stream raises `ZXError` when the affected data is read or validated. Missing raster paths also pass through normal Python file I/O errors. These are reader APIs.
221
+
222
+ ZXI, ZXIL, ZXF and ZX-RAW accept `threads=1..64`. Use `threads=0` to
223
+ select the available physical CPU concurrency. The thread budget bounds the
224
+ work for each request. Video reads accept `threads=1..32`, with `0` selecting
225
+ one worker. ZX-Photo reads accept `threads=0..4`.
226
+ Use a context manager or `close()` to release an open reader.
227
+
228
+ ## Writing arrays
229
+
230
+ Pass aligned, C-contiguous native-endian NumPy arrays. The writers borrow the
231
+ input buffers for the call. Keep them stable until the call returns. Use
232
+ `numpy.ascontiguousarray` explicitly if a cropped or transposed view needs
233
+ packing. Convert foreign-endian types explicitly before writing.
234
+
235
+ pyzx.write_hdr("scene.zxf", {"Beauty.R": half_plane, "Z": depth_f32, "ID": id_u32})
236
+ pyzx.write_zxi("frame.zxi", rgba16, alpha="straight", icc=profile)
237
+ pyzx.write_zxil("layers.zxil", {"Background": rgb8, "Foreground": rgba16})
238
+ pyzx.write_video("clip.zxv1", timed_frames, width=w, height=h, pix_fmt="yuv422p10le",
239
+ time_base=(1, 30), color_range="tv")
240
+
241
+ Each HDR entry is a separate two-dimensional float16, float32 or uint32 array.
242
+ The Python entry stores a zero-origin data/display window, pLinear=0 and no
243
+ ancillary EXR attributes. It writes ZXF2 for both homogeneous and mixed input.
244
+ ZXIL accepts full-canvas, ordered RGB/RGBA layers with uint8, uint16 or float16
245
+ samples. Layers use normal blend, full opacity and visible state.
246
+ Video input uses a contiguous array per frame in native planar order. Items may
247
+ be (array, PTS, duration), or bare frames with consecutive unit durations.
248
+ Encoded files use native atomic output staging. The writers invoke no helper
249
+ process and create no intermediate image or video interchange file.
250
+
251
+ ## PyTorch training adapters
252
+
253
+ Install PyTorch in the training environment. The optional `zxcodec.torch_io` module imports it when samples are used. NumPy-only decoding keeps its existing dependencies.
254
+
255
+ Given local camera files and the tabular rows of a LeRobot episode, the three lines below send matching images, states and actions to a CUDA training step. `cameras` maps names such as `front` and `wrist` to local ZXV1 files with planar GBR or BT.709 YUV 4:4:4 (full or limited range) and straight or absent alpha. `train_step` is your training function.
256
+
257
+ ```python
258
+ from zxcodec.torch_io import MultiCameraVideoDataset, PinnedVideoPrefetcher
259
+ with MultiCameraVideoDataset.from_lerobot(cameras, rows, episode_index=0, workers=4) as data, PinnedVideoPrefetcher(data, batch_size=8) as batches:
260
+ for batch in batches: train_step(batch)
261
+ ```
262
+
263
+ Use `frame_indices=` for independent camera frame numbers and `frame_offsets=` for the start of each episode in a shared camera file. Pass a PyTorch batch sampler to `PinnedVideoPrefetcher(data, batches=sampler)` to choose random rows. For CPU training pass the dataset to `torch.utils.data.DataLoader`.
264
+
265
+ The source examples in `bindings/python/examples/` are runnable with `--help`:
266
+
267
+ | Example | Input | Training data |
268
+ | --- | --- | --- |
269
+ | `robot_multicamera.py` | LeRobot episode rows and matching ZX camera streams | RGB camera tensors, state and action |
270
+ | `cloud_depth.py` | HTTP(S) v2 companion URL and its original ZXF2 digest | A named depth plane in its stored precision |
271
+ | `large_image_tiles.py` | A tiled ZXIL pyramid | Random crops from selected stored levels |
@@ -0,0 +1,21 @@
1
+ pyzx.py,sha256=WmysHspEj7N-MaLrmW7k-LIA8P8dbp2Qjm0DcFvUKZs,293
2
+ zx_codec-1.0.0.dist-info/METADATA,sha256=02_Aq_JxOCQeXNrLJo4LBC0jgtPazoy6po60--vE-R8,15403
3
+ zx_codec-1.0.0.dist-info/WHEEL,sha256=QsCblD0lcDstXqkWa4K1zuXjbQ4zrSApjdllkLaGXYo,86
4
+ zx_codec-1.0.0.dist-info/licenses/THIRD_PARTY_NOTICES.txt,sha256=PU8kTDJ8wFXSRvDOVlh4zOUzQ17Sh6htrqTgzPhSs3s,47900
5
+ zxcodec/__init__.py,sha256=a5pRlB0Qdydcaa8FSUGZmImfLCxpemEcsa7j90WfIAY,36152
6
+ zxcodec/_buffers.py,sha256=jppPvXD_IzlKsnmcLL-muCNfGMsgvDlXuMsoopwP1Ww,1193
7
+ zxcodec/_coalesce.py,sha256=VS20E6Nk691tEMWP-pfPjNz_3axKiOk9dC5GnCn6cCE,4670
8
+ zxcodec/_companion.py,sha256=Kh4oQrsvITGNNpftZNXqSrf8e6eDib-1zvCoKoUYG_0,20988
9
+ zxcodec/_hdr.py,sha256=8ymn_adcmzeTBmCpOZEELhcJzlf9dKg98blt2uvJ_Og,10242
10
+ zxcodec/_native.py,sha256=qqTMRaVNqTlzyQXhmJhglBGh0T6j8y9ibrvfLi2eFQk,7245
11
+ zxcodec/_range.py,sha256=LGukjtfNrNoAzncJ2wFVo4TY7KJxa-G475EFTRZ0f1E,17790
12
+ zxcodec/_raster_ai.py,sha256=twk7N35W-uQrp9MuPfJI8lM0kKGbN5tv8JbIdYxgOVo,1795
13
+ zxcodec/_torch_image.py,sha256=h-7xYWL-00aWoQ5KVjN1GhRdMp5uzvFtB_CFd5NOKlI,8829
14
+ zxcodec/_torch_range.py,sha256=Sza4K2Lw5gP-sUtvuN2Sflc3XNMI6pRa70VcgKeb4gw,3477
15
+ zxcodec/_torch_video.py,sha256=C2AvAGlJJDpGfirAozo2mczlZkxVT7p00uq4T0ljs6Y,22588
16
+ zxcodec/_version.py,sha256=J-j-u0itpEFT6irdmWmixQqYMadNl1X91TxUmoiLHMI,22
17
+ zxcodec/_video_batch.py,sha256=k7rXK3-4ouo41TuFoBVSp02v4fCdE31xrIYju9XvvIc,6505
18
+ zxcodec/_writers.py,sha256=Tg9YGnHSMzkjHZ51tWSINvpQVfoa3fW7mq7p5GLOhkg,9124
19
+ zxcodec/pyzx_core.dll,sha256=vFPzkWBMXdHwbU3VcCFbW9qtJUyiZ87sGHbDIjKtE8g,6199808
20
+ zxcodec/torch_io.py,sha256=bqSgW51XIqAlc8m2V94To7PQxQirL46LVIi82LBjzhw,474
21
+ zx_codec-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: zx-codec
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64