Skip to content

Make OpenCV a core dependency, encode RGBA PNG, bump to 0.4.0 - #15

Merged
MilkClouds merged 1 commit into
mainfrom
opencv-core-rgba-png
Oct 4, 2026
Merged

MilkClouds merged 1 commit into
mainfrom
opencv-core-rgba-png

Conversation

@MilkClouds

Copy link
Copy Markdown
Collaborator

Summary

  • OpenCV is a core dependency. The images extra is gone (no alias); opencv-python-headless>=4.12 is in dependencies. cv2 is still imported lazily on first image-codec use; _opencv.py drops the "install tensorcodec[images]" message and keeps only the 4.12 version check.
  • NumPy floor is now 2. Every opencv-python-headless 4.12+ wheel requires numpy>=2 on Python 3.9+, so numpy>=1.26 could no longer be satisfied. tensorcodec now declares numpy>=2, and the glibc 2.17 release check pins cp310 to NumPy 2.0.2 (the oldest NumPy 2 with cp310 manylinux2014 wheels) instead of 1.26.4. tensorcodec-av alone keeps numpy>=1.26.
  • RGBA PNG encoding. PngEncoder accepts 4-channel CHW uint8 and converts RGBA→BGRA for OpenCV, so alpha is kept. JpegEncoder still allows only 1 or 3 channels; with 4 it raises ValueError: JpegEncoder needs a nonempty CHW uint8 array with 1/3 channels.
  • Encode/decode symmetry. No decoder change was needed. decode_image(..., mode="RGBA") (or "UNCHANGED") returns 4×H×W RGBA with straight alpha last, which is exactly what PngEncoder takes. The default mode="RGB" drops alpha without premultiplying.
  • Version 0.4.0 in pyproject.toml (project and tensorcodec-av pin), av/Cargo.toml, av/Cargo.lock, src/tensorcodec/__init__.py, plus docs/releasing.md and docs/system_ffmpeg.md. Not tagged or published. The repo has no changelog.
  • Docs (README, docs/images.md, docs/package_size.md) and CI (build-python.yml installs plain tensorcodec; build-av.yml no longer installs OpenCV separately next to the wheels) are updated to match.

Tests

  • New test_png_rgba_round_trip: a random RGBA image with fully transparent pixels. It is read back exactly by Pillow, and by decode_image in RGBA/UNCHANGED mode. Default RGB mode returns the first three channels unchanged.
  • test_jpeg_rejects_alpha. Input-error cases now use 2 and 5 channels for PngEncoder.
  • Locally (Python 3.12, OpenCV 5.0, NumPy 2.5, FFmpeg 7.1.1 fixtures): ruff check and format pass, and the image and version tests pass. The full suite (without --compare) passes when run against the published tensorcodec-av 0.3.0 wheel. To do that, __version__ was temporarily set back to 0.3.0, because tensorcodec-av 0.4.0 does not exist yet and this PR does not touch av/ sources.

Notes

  • Breaking for users who are on NumPy 1.x, or who use a different cv2 variant (opencv-python, contrib). The pip metadata now pulls in the headless wheel, and the docs warn against mixing variants.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YAijSnAE4aAjuS1EcCTwqS

- Drop the `images` extra; opencv-python-headless>=4.12 is now required.
  Its wheels require NumPy 2, so the NumPy floor and the glibc 2.17 minimum-NumPy
  check move to 2.0.2. cv2 stays lazily imported.
- PngEncoder accepts 4-channel CHW (RGBA), symmetric with decode_image(mode="RGBA").
  JpegEncoder still rejects 4 channels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YAijSnAE4aAjuS1EcCTwqS
@MilkClouds
MilkClouds merged commit 7db2ea5 into main Oct 4, 2026
8 checks passed
@MilkClouds
MilkClouds deleted the opencv-core-rgba-png branch October 4, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant