Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: Remove numpy requirement, use buffer protocol instead #615

Merged
merged 4 commits into from
Sep 14, 2023

Commits on Sep 14, 2023

  1. Python: Remove numpy requirement, use buffer protocol instead

    Partly taken from zxing-cpp#283 (comment)
    
    This removes the requirement of `read_barcode` / `write_barcode` to have
    Numpy installed and uses [buffer protocol](https://pybind11.readthedocs.io/en/stable/advanced/pycpp/numpy.html#buffer-protocol)
    instead.
    
    Numpy arrays can already be converted to a buffer, for PIL images we
    get the `__array_interface__` and use its values to create a memory view
    with the right shape.
    
    The `write_barcode` function now returns a buffer instead of a Numpy
    array. This buffer also supports `__array_interface__` for easy
    conversion to PIL images or Numpy arrays.
    
    * For PIL: `img = Image.fromarray(result, "L")`
    * For Numpy: `img = np.array(result)`
    
    fixes zxing-cpp#283
    
    Co-authored-by: axxel <awagger@gmail.com>
    EchterAgo and axxel committed Sep 14, 2023
    Configuration menu
    Copy the full SHA
    dbc6850 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f36d278 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d9b3e5d View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    266e475 View commit details
    Browse the repository at this point in the history