qr: rsc.io/qr/coding Index | Files

package coding

import "rsc.io/qr/coding"

Package coding implements low-level QR coding details.


Package Files



const MaxVersion = 40
const MinVersion = 1


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

Field is the field for QR error correction.

type Alpha Uses

type Alpha string

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

func (Alpha) Bits Uses

func (s Alpha) Bits(v Version) int

func (Alpha) Check Uses

func (s Alpha) Check() error

func (Alpha) Encode Uses

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

func (Alpha) String Uses

func (s Alpha) String() string

type Bits Uses

type Bits struct {
    // contains filtered or unexported fields

func (*Bits) AddCheckBytes Uses

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

func (*Bits) Append Uses

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

func (*Bits) Bits Uses

func (b *Bits) Bits() int

func (*Bits) Bytes Uses

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

func (*Bits) Pad Uses

func (b *Bits) Pad(n int)

func (*Bits) Reset Uses

func (b *Bits) Reset()

func (*Bits) Write Uses

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

type Code Uses

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 Uses

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

type Encoding Uses

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 Uses

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 Uses

func (l Level) String() string

type Mask Uses

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 Uses

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

type Num Uses

type Num string

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

func (Num) Bits Uses

func (s Num) Bits(v Version) int

func (Num) Check Uses

func (s Num) Check() error

func (Num) Encode Uses

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

func (Num) String Uses

func (s Num) String() string

type Pixel Uses

type Pixel uint32

A Pixel describes a single pixel in a QR code.

const (
    Black Pixel = 1 << iota

func OffsetPixel Uses

func OffsetPixel(o uint) Pixel

func (Pixel) Offset Uses

func (p Pixel) Offset() uint

func (Pixel) Role Uses

func (p Pixel) Role() PixelRole

func (Pixel) String Uses

func (p Pixel) String() string

type PixelRole Uses

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 Uses

func (r PixelRole) Pixel() Pixel

func (PixelRole) String Uses

func (r PixelRole) String() string

type Plan Uses

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 Uses

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 Uses

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

type String Uses

type String string

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

func (String) Bits Uses

func (s String) Bits(v Version) int

func (String) Check Uses

func (s String) Check() error

func (String) Encode Uses

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

func (String) String Uses

func (s String) String() string

type Version Uses

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 Uses

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 Uses

func (v Version) String() string

Package coding imports 4 packages (graph) and is imported by 9 packages. Updated 2018-07-12. Refresh now. Tools for package owners.