gozxing

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2021 License: Apache-2.0, MIT Imports: 8 Imported by: 140

README

gozxing A Barcode Scanning/Encoding Library for Go

Build Status codecov

ZXing is an open-source, multi-format 1D/2D barcode image processing library for Java. This project is a port of ZXing core library to pure Go.

Porting Status (supported formats)

2D barcodes
Format Scanning Encoding
QR Code
Data Matrix
Aztec
PDF 417
MaxiCode
1D product barcodes
Format Scanning Encoding
UPC-A
UPC-E
EAN-8
EAN-13
1D industrial barcode
Format Scanning Encoding
Code 39
Code 93
Code 128
Codabar
ITF
RSS-14 -
RSS-Expanded
Special reader/writer
Reader/Writer Porting status
MultiFormatReader
MultiFormatWriter
ByQuadrantReader
GenericMultipleBarcodeReader
QRCodeMultiReader
MultiFormatUPCEANReader
MultiFormatOneDReader

Usage Examples

Scanning QR code
package main

import (
	"fmt"
	"image"
	_ "image/jpeg"
	"os"

	"github.com/makiuchi-d/gozxing"
	"github.com/makiuchi-d/gozxing/qrcode"
)

func main() {
	// open and decode image file
	file, _ := os.Open("qrcode.jpg")
	img, _, _ := image.Decode(file)

	// prepare BinaryBitmap
	bmp, _ := gozxing.NewBinaryBitmapFromImage(img)

	// decode image
	qrReader := qrcode.NewQRCodeReader()
	result, _ := qrReader.Decode(bmp, nil)

	fmt.Println(result)
}
Generating CODE128 barcode
package main

import (
	"image/png"
	"os"

	"github.com/makiuchi-d/gozxing"
	"github.com/makiuchi-d/gozxing/oned"
)

func main() {
	// Generate a barcode image (*BitMatrix)
	enc := oned.NewCode128Writer()
	img, _ := enc.Encode("Hello, Gophers!", gozxing.BarcodeFormat_CODE_128, 250, 50, nil)

	file, _ := os.Create("barcode.png")
	defer file.Close()

	// *BitMatrix implements the image.Image interface,
	// so it is able to be passed to png.Encode directly.
	_ = png.Encode(file, img)
}

Documentation

Index

Constants

View Source
const (
	/** Aztec 2D barcode format. */
	BarcodeFormat_AZTEC = BarcodeFormat(iota)

	/** CODABAR 1D format. */
	BarcodeFormat_CODABAR

	/** Code 39 1D format. */
	BarcodeFormat_CODE_39

	/** Code 93 1D format. */
	BarcodeFormat_CODE_93

	/** Code 128 1D format. */
	BarcodeFormat_CODE_128

	/** Data Matrix 2D barcode format. */
	BarcodeFormat_DATA_MATRIX

	/** EAN-8 1D format. */
	BarcodeFormat_EAN_8

	/** EAN-13 1D format. */
	BarcodeFormat_EAN_13

	/** ITF (Interleaved Two of Five) 1D format. */
	BarcodeFormat_ITF

	/** MaxiCode 2D barcode format. */
	BarcodeFormat_MAXICODE

	/** PDF417 format. */
	BarcodeFormat_PDF_417

	/** QR Code 2D barcode format. */
	BarcodeFormat_QR_CODE

	/** RSS 14 */
	BarcodeFormat_RSS_14

	/** RSS EXPANDED */
	BarcodeFormat_RSS_EXPANDED

	/** UPC-A 1D format. */
	BarcodeFormat_UPC_A

	/** UPC-E 1D format. */
	BarcodeFormat_UPC_E

	/** UPC/EAN extension format. Not a stand-alone format. */
	BarcodeFormat_UPC_EAN_EXTENSION
)
View Source
const (
	/**
	 * Specifies what degree of error correction to use, for example in QR Codes.
	 * Type depends on the encoder. For example for QR codes it's type
	 * {@link com.google.zxing.qrcode.decoder.ErrorCorrectionLevel ErrorCorrectionLevel}.
	 * For Aztec it is of type {@link Integer}, representing the minimal percentage of error correction words.
	 * For PDF417 it is of type {@link Integer}, valid values being 0 to 8.
	 * In all cases, it can also be a {@link String} representation of the desired value as well.
	 * Note: an Aztec symbol should have a minimum of 25% EC words.
	 */
	EncodeHintType_ERROR_CORRECTION = iota

	/**
	 * Specifies what character encoding to use where applicable (type {@link String})
	 */
	EncodeHintType_CHARACTER_SET

	/**
	 * Specifies the matrix shape for Data Matrix (type {@link com.google.zxing.datamatrix.encoder.SymbolShapeHint})
	 */
	EncodeHintType_DATA_MATRIX_SHAPE

	/**
	 * Specifies a minimum barcode size (type {@link Dimension}). Only applicable to Data Matrix now.
	 *
	 * @deprecated use width/height params in
	 * {@link com.google.zxing.datamatrix.DataMatrixWriter#encode(String, BarcodeFormat, int, int)}
	 */
	EncodeHintType_MIN_SIZE

	/**
	 * Specifies a maximum barcode size (type {@link Dimension}). Only applicable to Data Matrix now.
	 *
	 * @deprecated without replacement
	 */
	EncodeHintType_MAX_SIZE

	/**
	 * Specifies margin, in pixels, to use when generating the barcode. The meaning can vary
	 * by format; for example it controls margin before and after the barcode horizontally for
	 * most 1D formats. (Type {@link Integer}, or {@link String} representation of the integer value).
	 */
	EncodeHintType_MARGIN

	/**
	 * Specifies whether to use compact mode for PDF417 (type {@link Boolean}, or "true" or "false"
	 * {@link String} value).
	 */
	EncodeHintType_PDF417_COMPACT

	/**
	 * Specifies what compaction mode to use for PDF417 (type
	 * {@link com.google.zxing.pdf417.encoder.Compaction Compaction} or {@link String} value of one of its
	 * enum values).
	 */
	EncodeHintType_PDF417_COMPACTION

	/**
	 * Specifies the minimum and maximum number of rows and columns for PDF417 (type
	 * {@link com.google.zxing.pdf417.encoder.Dimensions Dimensions}).
	 */
	EncodeHintType_PDF417_DIMENSIONS

	/**
	 * Specifies the required number of layers for an Aztec code.
	 * A negative number (-1, -2, -3, -4) specifies a compact Aztec code.
	 * 0 indicates to use the minimum number of layers (the default).
	 * A positive number (1, 2, .. 32) specifies a normal (non-compact) Aztec code.
	 * (Type {@link Integer}, or {@link String} representation of the integer value).
	 */
	EncodeHintType_AZTEC_LAYERS

	/**
	 * Specifies the exact version of QR code to be encoded.
	 * (Type {@link Integer}, or {@link String} representation of the integer value).
	 */
	EncodeHintType_QR_VERSION

	/**
	 * Specifies the QR code mask pattern to be used. Allowed values are
	 * 0..QRCode.NUM_MASK_PATTERNS-1. By default the code will automatically select
	 * the optimal mask pattern.
	 * (Type {@link Integer}, or {@link String} representation of the integer value).
	 */
	EncodeHintType_QR_MASK_PATTERN

	/**
	 * Specifies whether the data should be encoded to the GS1 standard (type {@link Boolean}, or "true" or "false"
	 * {@link String } value).
	 */
	EncodeHintType_GS1_FORMAT

	/**
	 * Forces which encoding will be used. Currently only used for Code-128 code sets (Type {@link String}). Valid values are "A", "B", "C".
	 */
	EncodeHintType_FORCE_CODE_SET
)
View Source
const (
	LUMINANCE_BITS    = 5
	LUMINANCE_SHIFT   = 8 - LUMINANCE_BITS
	LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS
)
View Source
const (
	BLOCK_SIZE_POWER  = 3
	BLOCK_SIZE        = 1 << BLOCK_SIZE_POWER // ...0100...00
	BLOCK_SIZE_MASK   = BLOCK_SIZE - 1        // ...0011...11
	MINIMUM_DIMENSION = BLOCK_SIZE * 5
	MIN_DYNAMIC_RANGE = 24
)
View Source
const (
	/**
	 * Unspecified, application-specific metadata. Maps to an unspecified {@link Object}.
	 */
	ResultMetadataType_OTHER = ResultMetadataType(iota)

	/**
	 * Denotes the likely approximate orientation of the barcode in the image. This value
	 * is given as degrees rotated clockwise from the normal, upright orientation.
	 * For example a 1D barcode which was found by reading top-to-bottom would be
	 * said to have orientation "90". This key maps to an {@link Integer} whose
	 * value is in the range [0,360).
	 */
	ResultMetadataType_ORIENTATION

	/**
	 * <p>2D barcode formats typically encode text, but allow for a sort of 'byte mode'
	 * which is sometimes used to encode binary data. While {@link Result} makes available
	 * the complete raw bytes in the barcode for these formats, it does not offer the bytes
	 * from the byte segments alone.</p>
	 *
	 * <p>This maps to a {@link java.util.List} of byte arrays corresponding to the
	 * raw bytes in the byte segments in the barcode, in order.</p>
	 */
	ResultMetadataType_BYTE_SEGMENTS

	/**
	 * Error correction level used, if applicable. The value type depends on the
	 * format, but is typically a String.
	 */
	ResultMetadataType_ERROR_CORRECTION_LEVEL

	/**
	 * For some periodicals, indicates the issue number as an {@link Integer}.
	 */
	ResultMetadataType_ISSUE_NUMBER

	/**
	 * For some products, indicates the suggested retail price in the barcode as a
	 * formatted {@link String}.
	 */
	ResultMetadataType_SUGGESTED_PRICE

	/**
	 * For some products, the possible country of manufacture as a {@link String} denoting the
	 * ISO country code. Some map to multiple possible countries, like "US/CA".
	 */
	ResultMetadataType_POSSIBLE_COUNTRY

	/**
	 * For some products, the extension text
	 */
	ResultMetadataType_UPC_EAN_EXTENSION

	/**
	 * PDF417-specific metadata
	 */
	ResultMetadataType_PDF417_EXTRA_METADATA

	/**
	 * If the code format supports structured append and the current scanned code is part of one then the
	 * sequence number is given with it.
	 */
	ResultMetadataType_STRUCTURED_APPEND_SEQUENCE

	/**
	 * If the code format supports structured append and the current scanned code is part of one then the
	 * parity is given with it.
	 */
	ResultMetadataType_STRUCTURED_APPEND_PARITY

	/**
	 * Barcode Symbology Identifier.
	 *  Note: According to the GS1 specification the identifier may have to replace a leading FNC1/GS character when prepending to the barcode content.
	 */
	ResultMetadataType_SYMBOLOGY_IDENTIFIER
)

Variables

This section is empty.

Functions

func LuminanceSourceString

func LuminanceSourceString(this LuminanceSource) string

func ResultPoint_Distance

func ResultPoint_Distance(pattern1, pattern2 ResultPoint) float64

Types

type BarcodeFormat

type BarcodeFormat int

func (BarcodeFormat) String

func (f BarcodeFormat) String() string

type BarcodeFormats

type BarcodeFormats []BarcodeFormat

func (BarcodeFormats) Contains

func (barcodes BarcodeFormats) Contains(c BarcodeFormat) bool

type Binarizer

type Binarizer interface {
	GetLuminanceSource() LuminanceSource

	/**
	 * Converts one row of luminance data to 1 bit data. May actually do the conversion, or return
	 * cached data. Callers should assume this method is expensive and call it as seldom as possible.
	 * This method is intended for decoding 1D barcodes and may choose to apply sharpening.
	 * For callers which only examine one row of pixels at a time, the same BitArray should be reused
	 * and passed in with each call for performance. However it is legal to keep more than one row
	 * at a time if needed.
	 *
	 * @param y The row to fetch, which must be in [0, bitmap height)
	 * @param row An optional preallocated array. If null or too small, it will be ignored.
	 *            If used, the Binarizer will call BitArray.clear(). Always use the returned object.
	 * @return The array of bits for this row (true means black).
	 * @throws NotFoundException if row can't be binarized
	 */
	GetBlackRow(y int, row *BitArray) (*BitArray, error)

	/**
	 * Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive
	 * and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or
	 * may not apply sharpening. Therefore, a row from this matrix may not be identical to one
	 * fetched using getBlackRow(), so don't mix and match between them.
	 *
	 * @return The 2D array of bits for the image (true means black).
	 * @throws NotFoundException if image can't be binarized to make a matrix
	 */
	GetBlackMatrix() (*BitMatrix, error)

	/**
	 * Creates a new object with the same type as this Binarizer implementation, but with pristine
	 * state. This is needed because Binarizer implementations may be stateful, e.g. keeping a cache
	 * of 1 bit data. See Effective Java for why we can't use Java's clone() method.
	 *
	 * @param source The LuminanceSource this Binarizer will operate on.
	 * @return A new concrete Binarizer implementation object.
	 */
	CreateBinarizer(source LuminanceSource) Binarizer

	GetWidth() int
	GetHeight() int
}

func NewGlobalHistgramBinarizer

func NewGlobalHistgramBinarizer(source LuminanceSource) Binarizer

func NewHybridBinarizer

func NewHybridBinarizer(source LuminanceSource) Binarizer

type BinaryBitmap

type BinaryBitmap struct {
	// contains filtered or unexported fields
}

func NewBinaryBitmap

func NewBinaryBitmap(binarizer Binarizer) (*BinaryBitmap, error)

func NewBinaryBitmapFromImage

func NewBinaryBitmapFromImage(img image.Image) (*BinaryBitmap, error)

func (*BinaryBitmap) Crop

func (this *BinaryBitmap) Crop(left, top, width, height int) (*BinaryBitmap, error)

func (*BinaryBitmap) GetBlackMatrix

func (this *BinaryBitmap) GetBlackMatrix() (*BitMatrix, error)

func (*BinaryBitmap) GetBlackRow

func (this *BinaryBitmap) GetBlackRow(y int, row *BitArray) (*BitArray, error)

func (*BinaryBitmap) GetHeight

func (this *BinaryBitmap) GetHeight() int

func (*BinaryBitmap) GetWidth

func (this *BinaryBitmap) GetWidth() int

func (*BinaryBitmap) IsCropSupported

func (this *BinaryBitmap) IsCropSupported() bool

func (*BinaryBitmap) IsRotateSupported

func (this *BinaryBitmap) IsRotateSupported() bool

func (*BinaryBitmap) RotateCounterClockwise

func (this *BinaryBitmap) RotateCounterClockwise() (*BinaryBitmap, error)

func (*BinaryBitmap) RotateCounterClockwise45

func (this *BinaryBitmap) RotateCounterClockwise45() (*BinaryBitmap, error)

func (*BinaryBitmap) String

func (this *BinaryBitmap) String() string

type BitArray

type BitArray struct {
	// contains filtered or unexported fields
}

func NewBitArray

func NewBitArray(size int) *BitArray

func NewEmptyBitArray

func NewEmptyBitArray() *BitArray

func (*BitArray) AppendBit

func (b *BitArray) AppendBit(bit bool)

func (*BitArray) AppendBitArray

func (b *BitArray) AppendBitArray(other *BitArray)

func (*BitArray) AppendBits

func (b *BitArray) AppendBits(value int, numBits int) error

func (*BitArray) Clear

func (b *BitArray) Clear()

func (*BitArray) Flip

func (b *BitArray) Flip(i int)

func (*BitArray) Get

func (b *BitArray) Get(i int) bool

func (*BitArray) GetBitArray

func (b *BitArray) GetBitArray() []uint32

func (*BitArray) GetNextSet

func (b *BitArray) GetNextSet(from int) int

func (*BitArray) GetNextUnset

func (b *BitArray) GetNextUnset(from int) int

func (*BitArray) GetSize

func (b *BitArray) GetSize() int

func (*BitArray) GetSizeInBytes

func (b *BitArray) GetSizeInBytes() int

func (*BitArray) IsRange

func (b *BitArray) IsRange(start, end int, value bool) (bool, error)

func (*BitArray) Reverse

func (b *BitArray) Reverse()

func (*BitArray) Set

func (b *BitArray) Set(i int)

func (*BitArray) SetBulk

func (b *BitArray) SetBulk(i int, newBits uint32)

func (*BitArray) SetRange

func (b *BitArray) SetRange(start, end int) error

func (*BitArray) String

func (b *BitArray) String() string

func (*BitArray) ToBytes

func (b *BitArray) ToBytes(bitOffset int, array []byte, offset, numBytes int)

func (*BitArray) Xor

func (b *BitArray) Xor(other *BitArray) error

type BitMatrix

type BitMatrix struct {
	// contains filtered or unexported fields
}

func NewBitMatrix

func NewBitMatrix(width, height int) (*BitMatrix, error)

func NewSquareBitMatrix

func NewSquareBitMatrix(dimension int) (*BitMatrix, error)

func ParseBoolMapToBitMatrix

func ParseBoolMapToBitMatrix(image [][]bool) (*BitMatrix, error)

func ParseStringToBitMatrix

func ParseStringToBitMatrix(stringRepresentation, setString, unsetString string) (*BitMatrix, error)

func (*BitMatrix) At

func (img *BitMatrix) At(x, y int) color.Color

func (*BitMatrix) Bounds

func (img *BitMatrix) Bounds() image.Rectangle

func (*BitMatrix) Clear

func (b *BitMatrix) Clear()

func (*BitMatrix) ColorModel

func (img *BitMatrix) ColorModel() color.Model

func (*BitMatrix) Flip

func (b *BitMatrix) Flip(x, y int)

func (*BitMatrix) FlipAll

func (b *BitMatrix) FlipAll()

func (*BitMatrix) Get

func (b *BitMatrix) Get(x, y int) bool

func (*BitMatrix) GetBottomRightOnBit

func (b *BitMatrix) GetBottomRightOnBit() []int

func (*BitMatrix) GetEnclosingRectangle

func (b *BitMatrix) GetEnclosingRectangle() []int

func (*BitMatrix) GetHeight

func (b *BitMatrix) GetHeight() int

func (*BitMatrix) GetRow

func (b *BitMatrix) GetRow(y int, row *BitArray) *BitArray

func (*BitMatrix) GetRowSize

func (b *BitMatrix) GetRowSize() int

func (*BitMatrix) GetTopLeftOnBit

func (b *BitMatrix) GetTopLeftOnBit() []int

func (*BitMatrix) GetWidth

func (b *BitMatrix) GetWidth() int

func (*BitMatrix) Rotate180

func (b *BitMatrix) Rotate180()

func (*BitMatrix) Rotate90

func (b *BitMatrix) Rotate90()

func (*BitMatrix) Set

func (b *BitMatrix) Set(x, y int)

func (*BitMatrix) SetRegion

func (b *BitMatrix) SetRegion(left, top, width, height int) error

func (*BitMatrix) SetRow

func (b *BitMatrix) SetRow(y int, row *BitArray)

func (*BitMatrix) String

func (b *BitMatrix) String() string

func (*BitMatrix) ToString

func (b *BitMatrix) ToString(setString, unsetString string) string

func (*BitMatrix) ToStringWithLineSeparator

func (b *BitMatrix) ToStringWithLineSeparator(setString, unsetString, lineSeparator string) string

func (*BitMatrix) Unset

func (b *BitMatrix) Unset(x, y int)

func (*BitMatrix) Xor

func (b *BitMatrix) Xor(mask *BitMatrix) error

type ChecksumException

type ChecksumException interface {
	ReaderException
	// contains filtered or unexported methods
}

func NewChecksumException

func NewChecksumException(args ...interface{}) ChecksumException

func WrapChecksumException

func WrapChecksumException(e error) ChecksumException

type DecodeHintType

type DecodeHintType int
const (
	/**
	 * Unspecified, application-specific hint. Maps to an unspecified {@link Object}.
	 */
	DecodeHintType_OTHER DecodeHintType = iota

	/**
	 * Image is a pure monochrome image of a barcode. Doesn't matter what it maps to;
	 * use {@link Boolean#TRUE}.
	 */
	DecodeHintType_PURE_BARCODE

	/**
	 * Image is known to be of one of a few possible formats.
	 * Maps to a {@link List} of {@link BarcodeFormat}s.
	 */
	DecodeHintType_POSSIBLE_FORMATS

	/**
	 * Spend more time to try to find a barcode; optimize for accuracy, not speed.
	 * Doesn't matter what it maps to; use {@link Boolean#TRUE}.
	 */
	DecodeHintType_TRY_HARDER

	/**
	 * Specifies what character encoding to use when decoding, where applicable (type String)
	 */
	DecodeHintType_CHARACTER_SET

	/**
	 * Allowed lengths of encoded data -- reject anything else. Maps to an {@code int[]}.
	 */
	DecodeHintType_ALLOWED_LENGTHS

	/**
	 * Assume Code 39 codes employ a check digit. Doesn't matter what it maps to;
	 * use {@link Boolean#TRUE}.
	 */
	DecodeHintType_ASSUME_CODE_39_CHECK_DIGIT

	/**
	 * 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). Doesn't matter what it maps to;
	 * use {@link Boolean#TRUE}.
	 */
	DecodeHintType_ASSUME_GS1

	/**
	 * 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. Doesn't matter what it maps to; use {@link Boolean#TRUE}.
	 */
	DecodeHintType_RETURN_CODABAR_START_END

	/**
	 * The caller needs to be notified via callback when a possible {@link ResultPoint}
	 * is found. Maps to a {@link ResultPointCallback}.
	 */
	DecodeHintType_NEED_RESULT_POINT_CALLBACK

	/**
	 * Allowed extension lengths for EAN or UPC barcodes. Other formats will ignore this.
	 * Maps to an {@code int[]} 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.
	 */
	DecodeHintType_ALLOWED_EAN_EXTENSIONS

	/**
	 * If true, also tries to decode as inverted image. All configured decoders are simply called a
	 * second time with an inverted image. Doesn't matter what it maps to; use {@link Boolean#TRUE}.
	 */
	DecodeHintType_ALSO_INVERTED
)

func (DecodeHintType) String

func (t DecodeHintType) String() string

type Dimension

type Dimension struct {
	// contains filtered or unexported fields
}

func NewDimension

func NewDimension(width, height int) (*Dimension, error)

func (*Dimension) Equals

func (this *Dimension) Equals(other *Dimension) bool

func (*Dimension) GetHeight

func (this *Dimension) GetHeight() int

func (*Dimension) GetWidth

func (this *Dimension) GetWidth() int

func (*Dimension) HashCode

func (this *Dimension) HashCode() int

func (*Dimension) String

func (this *Dimension) String() string

type EncodeHintType

type EncodeHintType int

func (EncodeHintType) String

func (this EncodeHintType) String() string

type FormatException

type FormatException interface {
	ReaderException
	// contains filtered or unexported methods
}

func NewFormatException

func NewFormatException(args ...interface{}) FormatException

func WrapFormatException

func WrapFormatException(e error) FormatException

type GlobalHistogramBinarizer

type GlobalHistogramBinarizer struct {
	// contains filtered or unexported fields
}

func (*GlobalHistogramBinarizer) CreateBinarizer

func (this *GlobalHistogramBinarizer) CreateBinarizer(source LuminanceSource) Binarizer

func (*GlobalHistogramBinarizer) GetBlackMatrix

func (this *GlobalHistogramBinarizer) GetBlackMatrix() (*BitMatrix, error)

func (*GlobalHistogramBinarizer) GetBlackRow

func (this *GlobalHistogramBinarizer) GetBlackRow(y int, row *BitArray) (*BitArray, error)

func (*GlobalHistogramBinarizer) GetHeight

func (this *GlobalHistogramBinarizer) GetHeight() int

func (*GlobalHistogramBinarizer) GetLuminanceSource

func (this *GlobalHistogramBinarizer) GetLuminanceSource() LuminanceSource

func (*GlobalHistogramBinarizer) GetWidth

func (this *GlobalHistogramBinarizer) GetWidth() int

type GoImageLuminanceSource

type GoImageLuminanceSource struct {
	*RGBLuminanceSource
}

func (*GoImageLuminanceSource) Crop

func (this *GoImageLuminanceSource) Crop(left, top, width, height int) (LuminanceSource, error)

func (*GoImageLuminanceSource) Invert

func (this *GoImageLuminanceSource) Invert() LuminanceSource

func (*GoImageLuminanceSource) IsRotateSupported

func (this *GoImageLuminanceSource) IsRotateSupported() bool

func (*GoImageLuminanceSource) RotateCounterClockwise

func (this *GoImageLuminanceSource) RotateCounterClockwise() (LuminanceSource, error)

func (*GoImageLuminanceSource) RotateCounterClockwise45

func (this *GoImageLuminanceSource) RotateCounterClockwise45() (LuminanceSource, error)

type HybridBinarizer

type HybridBinarizer struct {
	*GlobalHistogramBinarizer
	// contains filtered or unexported fields
}

func (*HybridBinarizer) CreateBinarizer

func (this *HybridBinarizer) CreateBinarizer(source LuminanceSource) Binarizer

func (*HybridBinarizer) GetBlackMatrix

func (this *HybridBinarizer) GetBlackMatrix() (*BitMatrix, error)

type InvertedLuminanceSource

type InvertedLuminanceSource struct {
	LuminanceSource
}

func (*InvertedLuminanceSource) Crop

func (this *InvertedLuminanceSource) Crop(left, top, width, height int) (LuminanceSource, error)

func (*InvertedLuminanceSource) GetMatrix

func (this *InvertedLuminanceSource) GetMatrix() []byte

func (*InvertedLuminanceSource) GetRow

func (this *InvertedLuminanceSource) GetRow(y int, row []byte) ([]byte, error)

func (*InvertedLuminanceSource) Invert

func (*InvertedLuminanceSource) RotateCounterClockwise

func (this *InvertedLuminanceSource) RotateCounterClockwise() (LuminanceSource, error)

func (*InvertedLuminanceSource) RotateCounterClockwise45

func (this *InvertedLuminanceSource) RotateCounterClockwise45() (LuminanceSource, error)

func (*InvertedLuminanceSource) String

func (this *InvertedLuminanceSource) String() string

type LuminanceSource

type LuminanceSource interface {
	/**
	 * Fetches one row of luminance data from the underlying platform's bitmap. Values range from
	 * 0 (black) to 255 (white). Because Java does not have an unsigned byte type, callers will have
	 * to bitwise and with 0xff for each value. It is preferable for implementations of this method
	 * to only fetch this row rather than the whole image, since no 2D Readers may be installed and
	 * getMatrix() may never be called.
	 *
	 * @param y The row to fetch, which must be in [0,getHeight())
	 * @param row An optional preallocated array. If null or too small, it will be ignored.
	 *            Always use the returned object, and ignore the .length of the array.
	 * @return An array containing the luminance data.
	 */
	GetRow(y int, row []byte) ([]byte, error)

	/**
	 * Fetches luminance data for the underlying bitmap. Values should be fetched using:
	 * {@code int luminance = array[y * width + x] & 0xff}
	 *
	 * @return A row-major 2D array of luminance values. Do not use result.length as it may be
	 *         larger than width * height bytes on some platforms. Do not modify the contents
	 *         of the result.
	 */
	GetMatrix() []byte

	/**
	 * @return The width of the bitmap.
	 */
	GetWidth() int

	/**
	 * @return The height of the bitmap.
	 */
	GetHeight() int

	/**
	 * @return Whether this subclass supports cropping.
	 */
	IsCropSupported() bool

	/**
	 * Returns a new object with cropped image data. Implementations may keep a reference to the
	 * original data rather than a copy. Only callable if isCropSupported() is true.
	 *
	 * @param left The left coordinate, which must be in [0,getWidth())
	 * @param top The top coordinate, which must be in [0,getHeight())
	 * @param width The width of the rectangle to crop.
	 * @param height The height of the rectangle to crop.
	 * @return A cropped version of this object.
	 */
	Crop(left, top, width, height int) (LuminanceSource, error)

	/**
	 * @return Whether this subclass supports counter-clockwise rotation.
	 */
	IsRotateSupported() bool

	/**
	 * @return a wrapper of this {@code LuminanceSource} which inverts the luminances it returns -- black becomes
	 *  white and vice versa, and each value becomes (255-value).
	 */
	Invert() LuminanceSource

	/**
	 * Returns a new object with rotated image data by 90 degrees counterclockwise.
	 * Only callable if {@link #isRotateSupported()} is true.
	 *
	 * @return A rotated version of this object.
	 */
	RotateCounterClockwise() (LuminanceSource, error)

	/**
	 * Returns a new object with rotated image data by 45 degrees counterclockwise.
	 * Only callable if {@link #isRotateSupported()} is true.
	 *
	 * @return A rotated version of this object.
	 */
	RotateCounterClockwise45() (LuminanceSource, error)

	String() string
}

func LuminanceSourceInvert

func LuminanceSourceInvert(this LuminanceSource) LuminanceSource

func NewInvertedLuminanceSource

func NewInvertedLuminanceSource(delegate LuminanceSource) LuminanceSource

func NewLuminanceSourceFromImage

func NewLuminanceSourceFromImage(img image.Image) LuminanceSource

func NewPlanarYUVLuminanceSource

func NewPlanarYUVLuminanceSource(yuvData []byte,
	dataWidth, dataHeight, left, top, width, height int,
	reverseHorizontal bool) (LuminanceSource, error)

func NewRGBLuminanceSource

func NewRGBLuminanceSource(width, height int, pixels []int) LuminanceSource

type LuminanceSourceBase

type LuminanceSourceBase struct {
	Width  int
	Height int
}

func (*LuminanceSourceBase) Crop

func (this *LuminanceSourceBase) Crop(left, top, width, height int) (LuminanceSource, error)

func (*LuminanceSourceBase) GetHeight

func (this *LuminanceSourceBase) GetHeight() int

func (*LuminanceSourceBase) GetWidth

func (this *LuminanceSourceBase) GetWidth() int

func (*LuminanceSourceBase) IsCropSupported

func (this *LuminanceSourceBase) IsCropSupported() bool

func (*LuminanceSourceBase) IsRotateSupported

func (this *LuminanceSourceBase) IsRotateSupported() bool

func (*LuminanceSourceBase) RotateCounterClockwise

func (this *LuminanceSourceBase) RotateCounterClockwise() (LuminanceSource, error)

func (*LuminanceSourceBase) RotateCounterClockwise45

func (this *LuminanceSourceBase) RotateCounterClockwise45() (LuminanceSource, error)

type NotFoundException

type NotFoundException interface {
	ReaderException
	// contains filtered or unexported methods
}

func NewNotFoundException

func NewNotFoundException(args ...interface{}) NotFoundException

func WrapNotFoundException

func WrapNotFoundException(e error) NotFoundException

type PlanarYUVLuminanceSource

type PlanarYUVLuminanceSource struct {
	LuminanceSourceBase
	// contains filtered or unexported fields
}

func (*PlanarYUVLuminanceSource) Crop

func (this *PlanarYUVLuminanceSource) Crop(left, top, width, height int) (LuminanceSource, error)

func (*PlanarYUVLuminanceSource) GetMatrix

func (this *PlanarYUVLuminanceSource) GetMatrix() []byte

func (*PlanarYUVLuminanceSource) GetRow

func (this *PlanarYUVLuminanceSource) GetRow(y int, row []byte) ([]byte, error)

func (*PlanarYUVLuminanceSource) GetThumbnailHeight

func (this *PlanarYUVLuminanceSource) GetThumbnailHeight() int

GetThumbnailHeight return height of image from {@link #renderThumbnail()}

func (*PlanarYUVLuminanceSource) GetThumbnailWidth

func (this *PlanarYUVLuminanceSource) GetThumbnailWidth() int

GetThumbnailWidth return width of image from {@link #renderThumbnail()}

func (*PlanarYUVLuminanceSource) Invert

func (*PlanarYUVLuminanceSource) IsCropSupported

func (this *PlanarYUVLuminanceSource) IsCropSupported() bool

func (*PlanarYUVLuminanceSource) RenderThumbnail

func (this *PlanarYUVLuminanceSource) RenderThumbnail() []uint

func (*PlanarYUVLuminanceSource) String

func (this *PlanarYUVLuminanceSource) String() string

type RGBLuminanceSource

type RGBLuminanceSource struct {
	LuminanceSourceBase
	// contains filtered or unexported fields
}

func (*RGBLuminanceSource) Crop

func (this *RGBLuminanceSource) Crop(left, top, width, height int) (LuminanceSource, error)

func (*RGBLuminanceSource) GetMatrix

func (this *RGBLuminanceSource) GetMatrix() []byte

func (*RGBLuminanceSource) GetRow

func (this *RGBLuminanceSource) GetRow(y int, row []byte) ([]byte, error)

func (*RGBLuminanceSource) Invert

func (this *RGBLuminanceSource) Invert() LuminanceSource

func (*RGBLuminanceSource) IsCropSupported

func (this *RGBLuminanceSource) IsCropSupported() bool

func (*RGBLuminanceSource) String

func (this *RGBLuminanceSource) String() string

type Reader

type Reader interface {
	/**
	 * Locates and decodes a barcode in some format within an image.
	 *
	 * @param image image of barcode to decode
	 * @return String which the barcode encodes
	 * @throws NotFoundException if no potential barcode is found
	 * @throws ChecksumException if a potential barcode is found but does not pass its checksum
	 * @throws FormatException if a potential barcode is found but format is invalid
	 */
	DecodeWithoutHints(image *BinaryBitmap) (*Result, error)

	/**
	 * Locates and decodes a barcode in some format within an image. This method also accepts
	 * hints, each possibly associated to some data, which may help the implementation decode.
	 *
	 * @param image image of barcode to decode
	 * @param hints passed as a {@link Map} from {@link DecodeHintType}
	 * to arbitrary data. The
	 * meaning of the data depends upon the hint type. The implementation may or may not do
	 * anything with these hints.
	 * @return String which the barcode encodes
	 * @throws NotFoundException if no potential barcode is found
	 * @throws ChecksumException if a potential barcode is found but does not pass its checksum
	 * @throws FormatException if a potential barcode is found but format is invalid
	 */
	Decode(image *BinaryBitmap, hints map[DecodeHintType]interface{}) (*Result, error)

	/**
	 * Resets any internal state the implementation has after a decode, to prepare it
	 * for reuse.
	 */
	Reset()
}

type ReaderException

type ReaderException interface {
	error
	// contains filtered or unexported methods
}

func WrapReaderException

func WrapReaderException(e error) ReaderException

type Result

type Result struct {
	// contains filtered or unexported fields
}

func NewResult

func NewResult(text string, rawBytes []byte, resultPoints []ResultPoint, format BarcodeFormat) *Result

func NewResultWithNumBits

func NewResultWithNumBits(text string, rawBytes []byte, numBits int, resultPoints []ResultPoint, format BarcodeFormat, timestamp int64) *Result

func NewResultWithTimestamp

func NewResultWithTimestamp(text string, rawBytes []byte, resultPoints []ResultPoint, format BarcodeFormat, timestamp int64) *Result

func (*Result) AddResultPoints

func (this *Result) AddResultPoints(newPoints []ResultPoint)

func (*Result) GetBarcodeFormat

func (this *Result) GetBarcodeFormat() BarcodeFormat

func (*Result) GetNumBits

func (this *Result) GetNumBits() int

func (*Result) GetRawBytes

func (this *Result) GetRawBytes() []byte

func (*Result) GetResultMetadata

func (this *Result) GetResultMetadata() map[ResultMetadataType]interface{}

func (*Result) GetResultPoints

func (this *Result) GetResultPoints() []ResultPoint

func (*Result) GetText

func (this *Result) GetText() string

func (*Result) GetTimestamp

func (this *Result) GetTimestamp() int64

func (*Result) PutAllMetadata

func (this *Result) PutAllMetadata(metadata map[ResultMetadataType]interface{})

func (*Result) PutMetadata

func (this *Result) PutMetadata(mdtype ResultMetadataType, value interface{})

func (*Result) String

func (this *Result) String() string

type ResultMetadataType

type ResultMetadataType int

func (ResultMetadataType) String

func (t ResultMetadataType) String() string

type ResultPoint

type ResultPoint interface {
	GetX() float64
	GetY() float64
}

func NewResultPoint

func NewResultPoint(x, y float64) ResultPoint

func ResultPoint_OrderBestPatterns

func ResultPoint_OrderBestPatterns(pattern0, pattern1, pattern2 ResultPoint) (pointA, pointB, pointC ResultPoint)

Orders an array of three ResultPoints in an order [A,B,C] such that AB is less than AC and BC is less than AC, and the angle between BC and BA is less than 180 degrees. @param patterns array of three {@code ResultPoint} to order

type ResultPointBase

type ResultPointBase struct {
	// contains filtered or unexported fields
}

func (ResultPointBase) GetX

func (rp ResultPointBase) GetX() float64

func (ResultPointBase) GetY

func (rp ResultPointBase) GetY() float64

type ResultPointCallback

type ResultPointCallback func(ResultPoint)

type Writer

type Writer interface {
	/**
	 * Encode a barcode using the default settings.
	 *
	 * @param contents The contents to encode in the barcode
	 * @param format The barcode format to generate
	 * @param width The preferred width in pixels
	 * @param height The preferred height in pixels
	 * @return {@link BitMatrix} representing encoded barcode image
	 * @throws WriterException if contents cannot be encoded legally in a format
	 */
	EncodeWithoutHint(contents string, format BarcodeFormat, width, height int) (*BitMatrix, error)

	/**
	 * @param contents The contents to encode in the barcode
	 * @param format The barcode format to generate
	 * @param width The preferred width in pixels
	 * @param height The preferred height in pixels
	 * @param hints Additional parameters to supply to the encoder
	 * @return {@link BitMatrix} representing encoded barcode image
	 * @throws WriterException if contents cannot be encoded legally in a format
	 */
	Encode(contents string, format BarcodeFormat, width, height int, hints map[EncodeHintType]interface{}) (*BitMatrix, error)
}

type WriterException

type WriterException interface {
	error
	// contains filtered or unexported methods
}

func NewWriterException

func NewWriterException(args ...interface{}) WriterException

func WrapWriterException

func WrapWriterException(err error) WriterException

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL