Back to / coding

Package coding

Latest Go to latest

The latest major version is .

Published: Jun 5, 2018 | License: BSD-3-Clause | Module:


Package coding implements low-level QR coding details.



const MaxVersion = 40
const MinVersion = 1


var Field = gf256.NewField(0x11d, 2)

Field is the field for QR error correction.

type Alpha

type Alpha string

Alpha is the encoding for alphanumeric data. The valid characters are 0-9A-Z$%*+-./: and space.

func (Alpha) Bits

func (s Alpha) Bits(v Version) int

func (Alpha) Check

func (s Alpha) Check() error

func (Alpha) Encode

func (s Alpha) Encode(b *Bits, v Version)

func (Alpha) String

func (s Alpha) String() string

type Bits

type Bits struct {
	// contains filtered or unexported fields

func (*Bits) AddCheckBytes

func (b *Bits) AddCheckBytes(v Version, l Level)

func (*Bits) Append

func (b *Bits) Append(p []byte)

func (*Bits) Bits

func (b *Bits) Bits() int

func (*Bits) Bytes

func (b *Bits) Bytes() []byte

func (*Bits) Pad

func (b *Bits) Pad(n int)

func (*Bits) Reset

func (b *Bits) Reset()

func (*Bits) Write

func (b *Bits) Write(v uint, nbit int)

type Code

type Code struct {
	Bitmap []byte // 1 is black, 0 is white
	Size   int    // number of pixels on a side
	Stride int    // number of bytes per row

A Code is a square pixel grid.

func (*Code) Black

func (c *Code) Black(x, y int) bool

type Encoding

type Encoding interface {
	Check() error
	Bits(v Version) int
	Encode(b *Bits, v Version)

Encoding implements a QR data encoding scheme. The implementations--Numeric, Alphanumeric, and String--specify the character set and the mapping from UTF-8 to code bits. The more restrictive the mode, the fewer code bits are needed.

type Level

type Level int

A Level represents a QR error correction level. From least to most tolerant of errors, they are L, M, Q, H.

const (
	L Level = iota

func (Level) String

func (l Level) String() string

type Mask

type Mask int

A Mask describes a mask that is applied to the QR code to avoid QR artifacts being interpreted as alignment and timing patterns (such as the squares in the corners). Valid masks are integers from 0 to 7.

func (Mask) Invert

func (m Mask) Invert(y, x int) bool

type Num

type Num string

Num is the encoding for numeric data. The only valid characters are the decimal digits 0 through 9.

func (Num) Bits

func (s Num) Bits(v Version) int

func (Num) Check

func (s Num) Check() error

func (Num) Encode

func (s Num) Encode(b *Bits, v Version)

func (Num) String

func (s Num) String() string

type Pixel

type Pixel uint32

A Pixel describes a single pixel in a QR code.

const (
	Black Pixel = 1 << iota

func OffsetPixel

func OffsetPixel(o uint) Pixel

func (Pixel) Offset

func (p Pixel) Offset() uint

func (Pixel) Role

func (p Pixel) Role() PixelRole

func (Pixel) String

func (p Pixel) String() string

type PixelRole

type PixelRole uint32

A PixelRole describes the role of a QR pixel.

const (
	Position  PixelRole // position squares (large)
	Alignment           // alignment squares (small)
	Timing              // timing strip between position squares
	Format              // format metadata
	PVersion            // version pattern
	Unused              // unused pixel
	Data                // data bit
	Check               // error correction check bit

func (PixelRole) Pixel

func (r PixelRole) Pixel() Pixel

func (PixelRole) String

func (r PixelRole) String() string

type Plan

type Plan struct {
	Version Version
	Level   Level
	Mask    Mask

	DataBytes  int // number of data bytes
	CheckBytes int // number of error correcting (checksum) bytes
	Blocks     int // number of data blocks

	Pixel [][]Pixel // pixel map

A Plan describes how to construct a QR code with a specific version, level, and mask.

func NewPlan

func NewPlan(version Version, level Level, mask Mask) (*Plan, error)

NewPlan returns a Plan for a QR code with the given version, level, and mask.

func (*Plan) Encode

func (p *Plan) Encode(text ...Encoding) (*Code, error)

type String

type String string

String is the encoding for 8-bit data. All bytes are valid.

func (String) Bits

func (s String) Bits(v Version) int

func (String) Check

func (s String) Check() error

func (String) Encode

func (s String) Encode(b *Bits, v Version)

func (String) String

func (s String) String() string

type Version

type Version int

A Version represents a QR version. The version specifies the size of the QR code: a QR code with version v has 4v+17 pixels on a side. Versions number from 1 to 40: the larger the version, the more information the code can store.

func (Version) DataBytes

func (v Version) DataBytes(l Level) int

DataBytes returns the number of data bytes that can be stored in a QR code with the given version and level.

func (Version) String

func (v Version) String() string

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier