Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@deviceflow/rxing-wasm

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@deviceflow/rxing-wasm

wasm bindings for rxing to provide commong barcode operations (decode/encode)

  • 0.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
Maintainers
0
Weekly downloads
 
Created
Source

rxing-wasm

WASM bindings for common rxing functions. The NPM link is https://www.npmjs.com/package/@deviceflow/rxing-wasm and the rust source is https://github.com/deviceflow/rxing-wasm.

This fork is identical to the upstream package, except wasm-pack is invoked with the --web flag.

Decode Multi Breaking Change with v0.3.0

Version 0.3.0 now returns BarcodeResult objects in a native javascript array. This fully deprecates the old method which returned a custom object with internal state.

Data

The convert_js_image_to_luma function is used to convert canvas image data to the luma 8 format that rxing expects. An example might look like to below.

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 data = imageData.data;
    let luma8Data = convert_js_image_to_luma(data);
    let parsedBarcode = decode_barcode(luma8Data, width, height);
    
    return parsedBarcode;
}

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.

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.

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.

Remove a hint using remove_hint(hint: DecodeHintTypes). The function returns true if the hint was present and removed, and false otherwise. The hint value is the same as in the add_hint function.

DecodeHintTypes Values

The following values are available for the DecodeHintTypes enum.

  • Other: Unspecified, application-specific hint. This can be any string, only some decoders care about this value.
  • PureBarcode: Image is a pure monochrome image of a barcode. Should be a string with either "true" or "false".
  • PossibleFormats: A comma separated list (no spaces between elements), with the names of barcode formats to search for. For example, looking for a QrCode and a Datamatrix, one would pass in the string "qrcode,datamatrix".
  • TryHarder: Spend more time to try to find a barcode; optimize for accuracy, not speed. String with either "true" or "false".
  • CharacterSet: Specifies what character encoding to use when decoding, where applicable. This should be a string mapping to a character encoding.
  • AllowedLengths: Allowed lengths of encoded data -- reject anything else. A comma separated list of integers.
  • AssumeCode39CheckDigit: Assume Code 39 codes employ a check digit. A string with either "true" or "false".
  • AssumeGs1: Assume the barcode is being processed as a GS1 barcode, and modify behavior as needed. For example this affects FNC1 handling for Code 128 (aka GS1-128). A string with either "true" or "false".
  • ReturnCodabarStartEnd: If true, return the start and end digits in a Codabar barcode instead of stripping them. They are alpha, whereas the rest are numeric. By default, they are stripped, but this causes them to not be. A string with either "true" or "false".
  • NeedResultPointCallback: The caller needs to be notified via callback when a possible ResultPoint is found. Currently unsupported. In future will map to a (x: number, y: number) = {} function.
  • AllowedEanExtensions: Allowed extension lengths for EAN or UPC barcodes. Other formats will ignore this. A comma separated list of the allowed extension lengths, for example "2", "5" or "2,5". If it is optional to have an extension, do not set this hint. If this is set, and a UPC or EAN barcode is found but an extension is not, then no result will be returned at all.
  • AlsoInverted: If true, also tries to decode as inverted image. All configured decoders are simply called a second time with an inverted image. A string with either "true" or "false".

Result Metadata

Result metadata is now available through the get_result_metadata_name method of the BarcodeResult class. The returned result is a javascript Map object representing availble decoded metadata. The possible keys are:

  • OTHER
  • Orientation
  • Byte_Segments
  • Error_Correction_Level
  • Issue_Number
  • Suggested_Price
  • Possible_Country
  • UPC/EAN_Extension
  • PDF417_Extra_MetaData
  • Structured_Append_Sequence
  • Structured_Append_Parity
  • Symbology_Identifier
  • Is_Mirrored
  • Content_Type

It is important to note that not all values will be set for all results.

Functions

pub fn convert_js_image_to_luma(data: &[u8]) -> Vec<u8>;
pub fn encode_barcode(
    data: &str,
    width: u32,
    height: u32,
    bc_type: BarcodeFormat,
) -> Result<String, String>;
pub fn decode_barcode(
    data: Vec<u8>,
    width: u32,
    height: u32,
    try_harder: Option<bool>,
) -> Result<BarcodeResult, String>;
pub fn decode_barcode_with_hints(
    data: Vec<u8>,
    width: u32,
    height: u32,
    hints: &mut decode_hints::DecodeHintDictionary,
) -> Result<BarcodeResult, String>;
pub fn decode_multi(
    data: Vec<u8>,
    width: u32,
    height: u32,
    hints: &mut decode_hints::DecodeHintDictionary,
    filter_image: Option<bool>,
) -> Result<Vec<BarcodeResult>, String>;
pub fn encode_barcode_with_hints(
    data: &str,
    width: u32,
    height: u32,
    bc_type: BarcodeFormat,
    hints: &mut EncodeHintDictionary,
) -> Result<String, String>;

Beta Features

encode_barcode_with_hints is currently in alpha. The output and behaviour is unexpected and poorly documented. Use at your own risk, feature may change, unstable interface.

Keywords

FAQs

Package last updated on 20 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc