Skip to main content

A Python binding library to jbigkit.

Project description

jbigkit-py

jbigkit-py is a Python binding library to jbigkit, making you able to encode/decode image to/from JBIG format.

jbigkit-py is designed for Python3.6+. It has not been tested on Python2 yet.

Install

From pip:

$ pip install jbigkit-py

Or from source:

# make sure you have c++ compiler installed before
# make sure you have setuptools, pybind11 installed in pip before

$ git clone --recurse-submodules https://github.com/HyperSine/jbigkit-py.git
$ cd jbigkit-py
$ pip install .

To perform tests after installation:

# make sure you have pytest, Pillow installed in pip before

$ python -m pytest .

Tutorial

A decode example:

#!/usr/bin/env python3
import jbigkit

with open('path to a .jbg file', 'rb') as f:
    jbg_data = f.read()

decoder = jbigkit.JbgDecoder()
status, processed_len = decoder.decode_in(jbg_data)

# status should be JbgErrno.EOK if a valid .jbg file was given
assert status == jbigkit.JbgErrno.EOK

# make sure all processed
assert processed_len == len(jbg_data)

w, h = decoder.get_width(), decoder.get_height()
print('the .jbg file has image size {:d}x{:d}'.format(w, h))
print('the .jbg file has {:d} planes.'.format(decoder.get_planes_num()))

# to get the i-th plane
ith_plane = decoder.get_plane(i)    # type: memoryview

# pass the i-th plane to Pillow library for further processing
import PIL.Image
img = PIL.Image.frombytes('1', (w, h), bytes(ith_plane), 'raw', '1;I')

For encode, see tests/test_JbgEncoder.py

API Reference

APIs Descriptions
JbgEncoder.__init__(x, y, *planes) Equivalent to call jbg_enc_init.
Planes data is pass via *planes variadic arguments. Each one for a plane, and must be Bytes-like object.
JbgEncoder.set_lrlmax(mwidth, mheight) Equivalent to call jbg_enc_lrlmax.
JbgEncoder.set_layers(d) Equivalent to call jbg_enc_layers.
JbgEncoder.set_lrange(dl, dh) Equivalent to call jbg_enc_lrange.
JbgEncoder.set_options(order, options, l0, mx, my) Equivalent to call jbg_enc_options.
JbgEncoder.encode_out() Equivalent to call jbg_enc_out, but returns a bytes object which is the encode result.
JbgDecoder.__init__ Equivalent to call jbg_dec_init.
JbgDecoder.set_maxsize(xmax, ymax) Equivalent to call jbg_dec_maxsize.
JbgDecoder.decode_in(buf) Equivalent to call jbg_dec_in. buf must be Bytes-like object.
JbgDecoder.get_width() Equivalent to call jbg_dec_getwidth.
JbgDecoder.get_height() Equivalent to call jbg_dec_getheight.
JbgDecoder.get_plane(plane) Equivalent to call jbg_dec_getimage and jbg_dec_getsize.
It returns a readonly memoryview object which is the data of user-specified plane.
JbgDecoder.get_planes_num() Equivalent to call jbg_dec_getplanes.
JbgDecoder.merge_planes(use_graycode) Equivalent to call jbg_dec_merge_planes.
JbgErrno.to_string() Equivalent to call jbg_strerror.

Version Convention

As this project is based on the C library jbigkit, this project uses the following scheme for versioning:

<version of C library jbigkit>.<a integer for jbigkit-py version>

For example, a release with version 2.1.1 means it is based on jbitkit-2.1 and is the 1st release of jbigkit-py.

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

jbigkit-py-2.1.4.tar.gz (44.7 kB view details)

Uploaded Source

File details

Details for the file jbigkit-py-2.1.4.tar.gz.

File metadata

  • Download URL: jbigkit-py-2.1.4.tar.gz
  • Upload date:
  • Size: 44.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.0 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15

File hashes

Hashes for jbigkit-py-2.1.4.tar.gz
Algorithm Hash digest
SHA256 625727ca44257524a80dbd7e961d1e7e4e0a6133a55a320f77c266137a7beda8
MD5 a6ea9d7008bd5c5cac30f12f4034aee3
BLAKE2b-256 671728665b749a337f14fe92418715eb1cfdbaa6e7506dea5e7e2e32597a2454

See more details on using hashes here.

Supported by

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