diff --git a/Cargo.toml b/Cargo.toml index 82c274d..04e692f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rxing-wasm" -version = "0.3.0" +version = "0.3.1" edition = "2021" description = "wasm bindings for rxing to provide commong barcode operations (decode/encode)" repository = "https://github.com/rxing-core/rxing-wasm" @@ -18,6 +18,7 @@ decode_hints = [] [dependencies] wasm-bindgen = "0.2.92" js-sys = "0.3.69" +web-sys = {version = "0.3.69", features = ["CanvasRenderingContext2d", "HtmlCanvasElement", "ImageData"]} # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires diff --git a/README.md b/README.md index d7cbea6..c834353 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,37 @@ function decodeBarcode(canvas) { } ``` +The `convert_canvas_to_luma` function is used to convert a canvas to the luma 8 +format that rxing expects. An example might look like to below. + +```javascript +function decodeBarcode(canvas) { + let height = canvas.height; + let width = canvas.width; + let luma8Data = convert_canvas_to_luma(canvas); + let parsedBarcode = decode_barcode(luma8Data, width, height); + + return parsedBarcode; +} +``` + +The `convert_imagedata_to_luma` function is used to convert an ImageData object to the luma 8 +format that rxing expects. An example might look like to below. + +```javascript +function decodeBarcode(canvas) { + let context = canvas.getContext('2d'); + let height = canvas.height; + let width = canvas.width; + let imageData = context.getImageData(0, 0, width, height); + + let luma8Data = convert_imagedata_to_luma(imageData); + let parsedBarcode = decode_barcode(luma8Data, width, height); + + return parsedBarcode; +} +``` + ## Hints ### Using the `DecodeHintDictionary` class Add a hint with `set_hint(hint: DecodeHintTypes, value: string)`. The function returns `true` if the hint was added and `false` if it was not. The value of hint must be a `number` representing on of the enum values for `DecodeHintTypes`. The easiest way to use this is to simply pass in one of the values from `DecodeHintTypes`. diff --git a/examples/webpack+js/index.html b/examples/webpack+js/index.html index 75ac07b..516fcd9 100644 --- a/examples/webpack+js/index.html +++ b/examples/webpack+js/index.html @@ -106,4 +106,4 @@