Documentation
¶
Overview ¶
Package zxinggo is a pure Go port of the ZXing barcode library.
Index ¶
- Variables
- func BitMatrixToImage(matrix interface{ ... }) *image.Gray
- func CrossProductZ(a, b, c ResultPoint) float64
- func Distance(a, b ResultPoint) float64
- func Encode(contents string, format Format, width, height int, opts *EncodeOptions) (*bitutil.BitMatrix, error)
- func RegisterReader(format Format, factory readerFactory)
- func RegisterWriter(format Format, factory writerFactory)
- type Binarizer
- type BinarizerFactory
- type BinaryBitmap
- func (b *BinaryBitmap) BlackMatrix() (*bitutil.BitMatrix, error)
- func (b *BinaryBitmap) BlackRow(y int, row *bitutil.BitArray) (*bitutil.BitArray, error)
- func (b *BinaryBitmap) Crop(left, top, width, height int) *BinaryBitmap
- func (b *BinaryBitmap) Height() int
- func (b *BinaryBitmap) RotateCounterClockwise() *BinaryBitmap
- func (b *BinaryBitmap) Width() int
- type DecodeOptions
- type EncodeOptions
- type Format
- type ImageLuminanceSource
- func (s *ImageLuminanceSource) Crop(left, top, cropWidth, cropHeight int) *ImageLuminanceSource
- func (s *ImageLuminanceSource) Height() int
- func (s *ImageLuminanceSource) Matrix() []byte
- func (s *ImageLuminanceSource) RotateCounterClockwise() *ImageLuminanceSource
- func (s *ImageLuminanceSource) Row(y int, row []byte) []byte
- func (s *ImageLuminanceSource) Width() int
- type LuminanceSource
- type MultiFormatReader
- type MultiFormatWriter
- type MultipleBarcodeReader
- type PDF417DimensionConfig
- type Reader
- type Result
- type ResultMetadataKey
- type ResultPoint
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when a barcode is not found in the image. ErrNotFound = errors.New("barcode not found") // ErrChecksum is returned when a barcode's checksum does not match. ErrChecksum = errors.New("checksum error") // ErrFormat is returned when a barcode cannot be decoded due to format issues. ErrFormat = errors.New("format error") // ErrWriter is returned when a barcode cannot be encoded. ErrWriter = errors.New("writer error") )
Functions ¶
func BitMatrixToImage ¶
BitMatrixToImage converts a BitMatrix to a grayscale image where black modules are black (0) and white modules are white (255).
func CrossProductZ ¶
func CrossProductZ(a, b, c ResultPoint) float64
CrossProductZ computes the z component of the cross product between vectors (bX-aX, bY-aY) and (cX-aX, cY-aY).
func Distance ¶
func Distance(a, b ResultPoint) float64
Distance returns the distance between two points.
func Encode ¶
func Encode(contents string, format Format, width, height int, opts *EncodeOptions) (*bitutil.BitMatrix, error)
Encode is a top-level convenience function that encodes the given contents into a barcode of the specified format.
func RegisterReader ¶
func RegisterReader(format Format, factory readerFactory)
RegisterReader registers a reader factory for the given format. This should be called from an init() function in format-specific packages.
func RegisterWriter ¶
func RegisterWriter(format Format, factory writerFactory)
RegisterWriter registers a writer factory for the given format.
Types ¶
type Binarizer ¶
type Binarizer interface {
// BlackRow returns a row of black/white values.
BlackRow(y int, row *bitutil.BitArray) (*bitutil.BitArray, error)
// BlackMatrix returns the 2D matrix of black/white values.
BlackMatrix() (*bitutil.BitMatrix, error)
// LuminanceSource returns the underlying LuminanceSource.
LuminanceSource() LuminanceSource
// Width returns the width of the image.
Width() int
// Height returns the height of the image.
Height() int
}
Binarizer converts luminance data to 1-bit black/white data.
func NewBinarizerFromSource ¶
func NewBinarizerFromSource(template Binarizer, source LuminanceSource) Binarizer
NewBinarizerFromSource creates a new binarizer of the same type with a new source. This is a factory method to support rotation.
type BinarizerFactory ¶
type BinarizerFactory interface {
CreateBinarizer(source LuminanceSource) Binarizer
}
BinarizerFactory is an interface for binarizers that can create new instances with a different LuminanceSource.
type BinaryBitmap ¶
type BinaryBitmap struct {
// contains filtered or unexported fields
}
BinaryBitmap represents a bitmap of binary (black/white) values.
func NewBinaryBitmap ¶
func NewBinaryBitmap(binarizer Binarizer) *BinaryBitmap
NewBinaryBitmap creates a new BinaryBitmap from the given Binarizer.
func (*BinaryBitmap) BlackMatrix ¶
func (b *BinaryBitmap) BlackMatrix() (*bitutil.BitMatrix, error)
BlackMatrix returns the 2D matrix of black/white values.
func (*BinaryBitmap) Crop ¶
func (b *BinaryBitmap) Crop(left, top, width, height int) *BinaryBitmap
Crop returns a new BinaryBitmap representing a rectangular sub-region. Returns nil if the source doesn't support cropping.
func (*BinaryBitmap) Height ¶
func (b *BinaryBitmap) Height() int
Height returns the height of the bitmap.
func (*BinaryBitmap) RotateCounterClockwise ¶
func (b *BinaryBitmap) RotateCounterClockwise() *BinaryBitmap
RotateCounterClockwise returns a new BinaryBitmap rotated 90 degrees CCW. The underlying LuminanceSource must be an *ImageLuminanceSource. Returns nil if rotation is not supported.
func (*BinaryBitmap) Width ¶
func (b *BinaryBitmap) Width() int
Width returns the width of the bitmap.
type DecodeOptions ¶
type DecodeOptions struct {
// PureBarcode hints that the image contains only the barcode with minimal
// border and no rotation.
PureBarcode bool
// TryHarder enables spending more time looking for barcodes.
TryHarder bool
// PossibleFormats limits which formats to look for.
PossibleFormats []Format
// CharacterSet specifies the character set to use when decoding.
CharacterSet string
// AllowedLengths restricts the set of valid barcode lengths for 1D formats.
AllowedLengths []int
// AssumeCode39CheckDigit assumes Code 39 includes a check digit.
AssumeCode39CheckDigit bool
// AssumeGS1 assumes data is GS1 formatted.
AssumeGS1 bool
// AllowedEANExtensions restricts the allowed EAN extension lengths.
AllowedEANExtensions []int
// AlsoInverted enables checking for barcodes on inverted images.
AlsoInverted bool
}
DecodeOptions configures barcode decoding behavior.
type EncodeOptions ¶
type EncodeOptions struct {
// ErrorCorrection specifies the error correction level.
ErrorCorrection string
// CharacterSet specifies the character set to use when encoding.
CharacterSet string
// Margin specifies the margin (quiet zone) in modules around the barcode.
Margin *int
// QRVersion forces a specific QR version (1-40).
QRVersion int
// QRMaskPattern forces a specific QR mask pattern (0-7).
QRMaskPattern int
// QRCompact enables compact QR mode.
QRCompact bool
// PDF417Compact enables compact PDF417 mode.
PDF417Compact bool
// PDF417Compaction specifies the PDF417 compaction mode.
PDF417Compaction int
// PDF417Dimensions specifies min/max rows/cols for PDF417.
PDF417Dimensions *PDF417DimensionConfig
// PDF417AutoECI enables automatic ECI selection in PDF417.
PDF417AutoECI bool
// GS1Format encodes in GS1 format.
GS1Format bool
// ForceCodeSet forces a specific code set (e.g., for Code 128).
ForceCodeSet string
// Code128Compact enables compact Code 128 encoding.
Code128Compact bool
}
EncodeOptions configures barcode encoding behavior.
type ImageLuminanceSource ¶
type ImageLuminanceSource struct {
// contains filtered or unexported fields
}
ImageLuminanceSource is a LuminanceSource implementation that wraps a Go image.Image, converting each pixel to greyscale luminance on the fly.
func NewGrayImageLuminanceSource ¶
func NewGrayImageLuminanceSource(img *image.Gray) *ImageLuminanceSource
NewGrayImageLuminanceSource creates a LuminanceSource from a *image.Gray, using the pixel data directly without conversion.
func NewImageLuminanceSource ¶
func NewImageLuminanceSource(img image.Image) *ImageLuminanceSource
NewImageLuminanceSource creates a LuminanceSource from a Go image.Image. The image is converted to greyscale luminance values upon construction. Uses the same luminance formula as Java ZXing's BufferedImageLuminanceSource: (306*R + 601*G + 117*B + 0x200) >> 10, operating on 8-bit color components.
func (*ImageLuminanceSource) Crop ¶
func (s *ImageLuminanceSource) Crop(left, top, cropWidth, cropHeight int) *ImageLuminanceSource
Crop returns a new ImageLuminanceSource that represents a rectangular sub-region of this source.
func (*ImageLuminanceSource) Height ¶
func (s *ImageLuminanceSource) Height() int
Height returns the height of the image.
func (*ImageLuminanceSource) Matrix ¶
func (s *ImageLuminanceSource) Matrix() []byte
Matrix returns the entire luminance matrix.
func (*ImageLuminanceSource) RotateCounterClockwise ¶
func (s *ImageLuminanceSource) RotateCounterClockwise() *ImageLuminanceSource
RotateCounterClockwise returns a new ImageLuminanceSource rotated 90 degrees counterclockwise. This is used by 1D readers to try reading barcodes that may be oriented vertically.
func (*ImageLuminanceSource) Row ¶
func (s *ImageLuminanceSource) Row(y int, row []byte) []byte
Row returns a row of luminance data.
func (*ImageLuminanceSource) Width ¶
func (s *ImageLuminanceSource) Width() int
Width returns the width of the image.
type LuminanceSource ¶
type LuminanceSource interface {
// Row returns a row of luminance data. If row is non-nil and large enough,
// it should be reused.
Row(y int, row []byte) []byte
// Matrix returns the entire luminance matrix.
Matrix() []byte
// Width returns the width of the image.
Width() int
// Height returns the height of the image.
Height() int
}
LuminanceSource provides access to greyscale luminance values for an image.
type MultiFormatReader ¶
type MultiFormatReader struct {
// contains filtered or unexported fields
}
MultiFormatReader is a factory/dispatcher that selects appropriate Reader implementations based on format hints and tries them in sequence.
func NewMultiFormatReader ¶
func NewMultiFormatReader() *MultiFormatReader
NewMultiFormatReader creates a new multi-format reader. If opts specifies PossibleFormats, only those formats are tried. Otherwise all formats are tried.
func (*MultiFormatReader) Decode ¶
func (r *MultiFormatReader) Decode(image *BinaryBitmap, opts *DecodeOptions) (*Result, error)
Decode attempts to decode a barcode from the given image using all registered format readers.
func (*MultiFormatReader) DecodeWithFormat ¶
func (r *MultiFormatReader) DecodeWithFormat(image *BinaryBitmap, format Format, opts *DecodeOptions) (*Result, error)
DecodeWithFormat attempts to decode a barcode of the given format.
func (*MultiFormatReader) Reset ¶
func (r *MultiFormatReader) Reset()
Reset resets all internal readers.
type MultiFormatWriter ¶
type MultiFormatWriter struct{}
MultiFormatWriter is a factory/dispatcher that selects the appropriate Writer implementation based on the requested format.
func NewMultiFormatWriter ¶
func NewMultiFormatWriter() *MultiFormatWriter
NewMultiFormatWriter creates a new multi-format writer.
func (*MultiFormatWriter) Encode ¶
func (w *MultiFormatWriter) Encode(contents string, format Format, width, height int, opts *EncodeOptions) (*bitutil.BitMatrix, error)
Encode encodes the given contents into a barcode of the specified format.
type MultipleBarcodeReader ¶
type MultipleBarcodeReader interface {
// DecodeMultiple attempts to decode all barcodes in the image.
DecodeMultiple(image *BinaryBitmap, opts *DecodeOptions) ([]*Result, error)
}
MultipleBarcodeReader can decode multiple barcodes from a single image.
type PDF417DimensionConfig ¶
PDF417DimensionConfig specifies min/max rows/cols for PDF417.
type Reader ¶
type Reader interface {
// Decode attempts to decode a barcode from the image.
Decode(image *BinaryBitmap, opts *DecodeOptions) (*Result, error)
// Reset resets any internal state.
Reset()
}
Reader decodes barcodes from a BinaryBitmap.
type Result ¶
type Result struct {
Text string
RawBytes []byte
NumBits int
Points []ResultPoint
Format Format
Metadata map[ResultMetadataKey]interface{}
Timestamp time.Time
}
Result encapsulates the result of decoding a barcode.
func Decode ¶
func Decode(image *BinaryBitmap, opts *DecodeOptions) (*Result, error)
Decode is a top-level convenience function that decodes a barcode from the given BinaryBitmap.
func NewResult ¶
func NewResult(text string, rawBytes []byte, points []ResultPoint, format Format) *Result
NewResult creates a new Result with the given text, format, and points.
func (*Result) AddResultPoints ¶
func (r *Result) AddResultPoints(points []ResultPoint)
AddResultPoints appends additional result points.
func (*Result) PutMetadata ¶
func (r *Result) PutMetadata(key ResultMetadataKey, value interface{})
PutMetadata adds a metadata key/value pair.
type ResultMetadataKey ¶
type ResultMetadataKey int
ResultMetadataKey identifies a type of metadata about a barcode result.
const ( MetadataOther ResultMetadataKey = iota MetadataOrientation MetadataByteSegments MetadataErrorCorrectionLevel MetadataErrorsCorrected MetadataErasuresCorrected MetadataIssueNumber MetadataSuggestedPrice MetadataPossibleCountry MetadataUPCEANExtension MetadataPDF417ExtraMetadata MetadataStructuredAppendSequence MetadataStructuredAppendParity MetadataSymbologyIdentifier )
type ResultPoint ¶
type ResultPoint struct {
X, Y float64
}
ResultPoint represents a point of interest in an image.
func OrderBestPatterns ¶
func OrderBestPatterns(patterns [3]ResultPoint) [3]ResultPoint
OrderBestPatterns orders three points in an pointA-pointB-pointC order such that AB is less than AC and BC is less than AC.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package aztec provides Aztec barcode reading and writing.
|
Package aztec provides Aztec barcode reading and writing. |
|
decoder
Package decoder implements the Aztec barcode decoder.
|
Package decoder implements the Aztec barcode decoder. |
|
detector
Package detector implements Aztec barcode detection in binary images.
|
Package detector implements Aztec barcode detection in binary images. |
|
encoder
Package encoder implements Aztec barcode encoding.
|
Package encoder implements Aztec barcode encoding. |
|
Package binarizer provides implementations for converting luminance data to binary.
|
Package binarizer provides implementations for converting luminance data to binary. |
|
Package bitutil provides bit manipulation utilities for barcode processing.
|
Package bitutil provides bit manipulation utilities for barcode processing. |
|
Package charset provides character set ECI mappings and encoding detection.
|
Package charset provides character set ECI mappings and encoding detection. |
|
cmd
|
|
|
barcodescan
command
|
|
|
Package datamatrix provides Data Matrix (ECC-200) reading and writing.
|
Package datamatrix provides Data Matrix (ECC-200) reading and writing. |
|
decoder
Package decoder implements Data Matrix (ECC-200) barcode decoding.
|
Package decoder implements Data Matrix (ECC-200) barcode decoding. |
|
detector
Package detector implements Data Matrix barcode detection in binary images.
|
Package detector implements Data Matrix barcode detection in binary images. |
|
encoder
Package encoder implements Data Matrix (ECC-200) barcode encoding.
|
Package encoder implements Data Matrix (ECC-200) barcode encoding. |
|
Package internal provides shared result types used across barcode format packages.
|
Package internal provides shared result types used across barcode format packages. |
|
Package maxicode provides MaxiCode barcode reading.
|
Package maxicode provides MaxiCode barcode reading. |
|
decoder
Package decoder implements MaxiCode decoding: bit matrix parsing, Reed-Solomon error correction, and character set decoding.
|
Package decoder implements MaxiCode decoding: bit matrix parsing, Reed-Solomon error correction, and character set decoding. |
|
Package multi provides multiple barcode detection.
|
Package multi provides multiple barcode detection. |
|
qrcode
Package qrcode provides multi-QR code detection and structured append support.
|
Package qrcode provides multi-QR code detection and structured append support. |
|
Package oned implements one-dimensional barcode reading and writing.
|
Package oned implements one-dimensional barcode reading and writing. |
|
decoder
Package decoder implements the PDF417 barcode decoder.
|
Package decoder implements the PDF417 barcode decoder. |
|
detector
Package detector implements PDF417 barcode detection in binary images.
|
Package detector implements PDF417 barcode detection in binary images. |
|
Package qrcode provides QR code reading and writing.
|
Package qrcode provides QR code reading and writing. |
|
decoder
Package decoder implements QR code decoding.
|
Package decoder implements QR code decoding. |
|
detector
Package detector implements QR code detection in binary images.
|
Package detector implements QR code detection in binary images. |
|
encoder
Package encoder implements QR code encoding.
|
Package encoder implements QR code encoding. |
|
Package reedsolomon implements Reed-Solomon error correction coding.
|
Package reedsolomon implements Reed-Solomon error correction coding. |
|
Package transform provides geometric transformation utilities for barcode detection.
|
Package transform provides geometric transformation utilities for barcode detection. |