Rxing

CIHex.pmHexDocsLicense: MIT

rxing decodes barcodes from image binaries using a source-built Rustler NIF powered by the Rust rxing crate.

Installation

def deps do
[
{:rxing, "~> 0.1.0"}
]
end

rxing compiles its native library from source when the dependency is compiled. Install Rust 1.91 or newer (rustc and cargo) before running mix compile.

Immediate Example (binary input)

image = File.read!("path/to/barcode.png")
{:ok, [%Rxing.Result{format: :qr_code} | _results]} =
Rxing.decode(image, formats: [:qr_code])

Public APIs

Rxing exposes three decoding entry points:

All APIs share the same option vocabulary and stable error vocabulary.

Decoding Binaries, One Result, and Files

image = File.read!("path/to/barcodes.png")
# Decode every result up to the configured bound.
{:ok, results} =
Rxing.decode(image, formats: [:qr_code, :data_matrix], max_results: 32)
# Decode only the first result.
{:ok, first} = Rxing.decode_one(image, formats: [:qr_code, :data_matrix])
%Rxing.Result{} = first
# Let Rxing read a regular file after applying the input-size pre-check.
{:ok, file_results} =
Rxing.decode_file("path/to/barcodes.png", formats: [:qr_code, :data_matrix])

results and file_results are lists of %Rxing.Result{} values in upstream detection order. When no barcode is recognized, decoding returns {:ok, []}.

Supported Barcode Formats

Rxing.formats/0 returns the guaranteed format set in stable order:

Supported Image Encodings

The binary API accepts these content-detectable formats from image 0.25:

Committed integration fixtures guarantee representative decoding coverage for PNG, JPEG, GIF, BMP, and WebP. Other enabled encodings use the same content-based classification and decoding pipeline.

AVIF and TGA are not accepted by the current binary-only pipeline: AVIF decoding requires the separate image/avif-native feature, while image::guess_format cannot identify TGA without a filename extension.

Options, Filtering, and Defaults

Public options:

Filtering examples:

Stable Errors

Decode operations return:

Result Payload, Raw Bytes, and Metadata

Every successful decode returns %Rxing.Result{} values:

Runtime and Concurrency Notes

Source Build Requirements and Platforms

Benchmarks

From a repository checkout with development dependencies installed, run:

mix run bench/rxing_bench.exs

The non-gating Benchee report includes throughput, median, p95, and p99 latency, BEAM memory, scheduler counts, run-queue snapshots, and heartbeat observations. It covers the guaranteed barcode formats, clean/rotated/inverted/damaged/multiple and no-code scenarios, an image-size sweep, and concurrency levels 1 through 32.

Treat the output as a baseline for comparisons made on the same host and toolchain. It deliberately contains no pass/fail latency thresholds or portable speed claims.

Non-goals (0.1.0)

License

MIT. See LICENSE.