GithubHelp home page GithubHelp logo

jbigkit-py's Introduction

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.

jbigkit-py's People

Contributors

hypersine avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.