Skip to main content

Python bindungs for libjpeg-turbo using pybind11

Project description

turbojpeg-python

Python bindings for libjpeg-turbo using pybind11. It's using Version 3 of the TurboJPEG C API.

It implements the three functions transform, compress and decompress. For more details see the function docstrings or the TurboJPEG C API docs https://rawcdn.githack.com/libjpeg-turbo/libjpeg-turbo/main/doc/html/group___turbo_j_p_e_g.html

Install

  • pip install turbojpeg

Example

Rotate JPEG file losslessly by 90 degrees.

import turbojpeg

with open("image.jpg", "rb") as fr:
    img_data = fr.read()

# lossless rotation. fails if lossless rotation is not possible
# for example when the image dimensions are not multiples of 16
img_data_rot = turbojpeg.transform(img_data, op=turbojpeg.OP.ROT90)

with open("image-rotated.jpg", "xb") as fw:
    fw.write(img_data_rot)

Save random image as JPEG with arithmetic coding.

import numpy as np
import turbojpeg
arr = np.random.randint(0, 256, (256, 256, 3), dtype=np.uint8)  # random color image
quality = 90
result = turbojpeg.compress(arr, quality, turbojpeg.SAMP.Y420, arithmetic=True)
with open("arithmetic.jpg", "xb") as fw:
    fw.write(result)

Build

The Python setup.py expects the libjpeg-turbo binaries in libjpeg-turbo-build. You can either build it yourself or download precompiled binaries. For more details see https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md.

GitHub actions CI builds wheels for Windows 32 and 64-bit, manylinux 64-bit, musllinux 64-bit and MacOS 64-bit. 32-bit Linux builds fail due some weird NASM error. Not all wheels are tested, since some of the test dependencies are not available for all platforms.

Run tests

python -m unittest discover -s tests

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

turbojpeg-0.0.2-cp311-cp311-win_amd64.whl (440.5 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

turbojpeg-0.0.2-cp311-cp311-win32.whl (378.2 kB view hashes)

Uploaded CPython 3.11 Windows x86

turbojpeg-0.0.2-cp311-cp311-musllinux_1_1_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

turbojpeg-0.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (565.2 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

turbojpeg-0.0.2-cp311-cp311-macosx_10_9_x86_64.whl (538.7 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

turbojpeg-0.0.2-cp310-cp310-win_amd64.whl (439.4 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

turbojpeg-0.0.2-cp310-cp310-win32.whl (377.3 kB view hashes)

Uploaded CPython 3.10 Windows x86

turbojpeg-0.0.2-cp310-cp310-musllinux_1_1_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

turbojpeg-0.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (563.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

turbojpeg-0.0.2-cp310-cp310-macosx_10_9_x86_64.whl (537.3 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

turbojpeg-0.0.2-cp39-cp39-win_amd64.whl (439.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

turbojpeg-0.0.2-cp39-cp39-win32.whl (377.7 kB view hashes)

Uploaded CPython 3.9 Windows x86

turbojpeg-0.0.2-cp39-cp39-musllinux_1_1_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

turbojpeg-0.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (564.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

turbojpeg-0.0.2-cp39-cp39-macosx_10_9_x86_64.whl (537.5 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

turbojpeg-0.0.2-cp38-cp38-win_amd64.whl (439.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

turbojpeg-0.0.2-cp38-cp38-win32.whl (377.4 kB view hashes)

Uploaded CPython 3.8 Windows x86

turbojpeg-0.0.2-cp38-cp38-musllinux_1_1_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

turbojpeg-0.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (563.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

turbojpeg-0.0.2-cp38-cp38-macosx_10_9_x86_64.whl (536.9 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

turbojpeg-0.0.2-cp37-cp37m-win_amd64.whl (440.4 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

turbojpeg-0.0.2-cp37-cp37m-win32.whl (379.2 kB view hashes)

Uploaded CPython 3.7m Windows x86

turbojpeg-0.0.2-cp37-cp37m-musllinux_1_1_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

turbojpeg-0.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (560.7 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

turbojpeg-0.0.2-cp37-cp37m-macosx_10_9_x86_64.whl (533.4 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

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