Projects

Codes

Codes is a family of machine-readable codes I designed. They're in the same category as QR codes, Aztec, and Data Matrix, but each has its own look. Stitch weaves short dashes into a grid. Rings arranges them in circles around a bullseye.

Honestly, I made it because I wanted to. I wanted to see if I could design a working barcode format from scratch, with a look that's all its own.

It also grew out of something I was working on, which was finding new ways to authenticate people. QR codes kept coming up, but anyone can make one, and any phone can read one. A custom format doesn't make a code secure by itself. A photo of a code still scans, and the real protection comes from what's inside it, like a token that expires in seconds. But no off-the-shelf generator can make a Stitch code, so faking one means learning the format first.

A Stitch code that reads “https://prestonkwei.com/projects/codes”

Two Formats

Both carry the same kinds of data, with the same error correction underneath. Only the geometry changes. These two encode the same link.

A Stitch code for https://prestonkwei.com/projects/codes
StitchA woven grid of short dashes inside an L-shaped finder. Horizontal is 0, vertical is 1.
A Rings code for https://prestonkwei.com/projects/codes
RingsRings of dashes around a bullseye, inside a dotted square frame. Along the ring is 0, pointing outward is 1. It reads at steeper angles.

Anatomy of a Code

Every format has the same four parts. Hover over one, or pick it below, to see what it does.

The parts of a Stitch code

Finder. The solid L along the left and bottom edges. A scanner looks for it first: it locates the code and fixes which way is up, whether the image is mirrored, and how much the photo is tilted.

What I Built

A format is only useful with everything around it, so the project is four pieces.

The Specification

One document defines every format: the grid, the finder, the header, and how bits are placed. Both formats share one payload layer and one error-correction layer, so a new format only has to define its geometry.

The Codec

A TypeScript package with no dependencies that encodes, draws, and scans both formats. It finds a code in a camera frame and decodes it in roughly 10 to 50 ms.

The App

Type text and get a code, with the anatomy view and SVG or PNG downloads. Scan from the camera or a photo, entirely in the browser. Print a test sheet with a size ladder and damage blots to check real-world reads.

The Image API

A Cloudflare Worker that returns any code as an SVG from a URL, so a site can drop one into an img tag. No key needed, rate limited per IP.

New Look, Proven Rules

The look is new. The rules underneath are the ones that make QR codes, Aztec, and Data Matrix fast and reliable to read, and the numbers on the right come from the test suite.

  1. A finder that is cheap to detect at any size and angleIt is the first thing a scanner looks for in a cluttered frame.
  2. A ruler that gives the exact cell pitchCounting its dots gives the grid size, so the reader never drifts.
  3. A rigid grid of two-state cellsEvery dash is one bit, so there is nothing to guess.
  4. Header information stored twiceWith its own error correction, so one smudge cannot hide it.
  5. Reed-Solomon error correction, spread across the symbolDamage in one spot costs a few bits from many bytes, which can be repaired.
  6. Even ink coverageA code never forms a false finder or a large blank area.
  7. Compact encodings for common textCommon URL prefixes and a six-bit alphabet keep codes small.
to find and decode a code in a camera frame
10–50 ms
tilt Stitch reads on one axis, 35° on two
45°
tilt Rings reads on one axis, 45° on two
60°
bytes in the largest Stitch code
882

Questions

What is a 2D barcode symbology?
A set of rules for turning data into a printed pattern a camera can read back. QR, Aztec, and Data Matrix are symbologies. Stitch and Rings are two more, with their own looks, built on the same ideas: a finder, a ruler, a header, and Reed-Solomon error correction.
Can you design your own QR-style code?
Yes, as long as it keeps the rules that make QR reliable: a finder that is cheap to detect at any angle, a timing pattern for the grid, header bits stored twice, and error correction spread across the symbol. Stitch and Rings keep those rules and change the look.
How does a damaged code still scan?
Reed-Solomon error correction adds extra bytes computed from the message, between 15% and 60% of the code depending on the level. The message and those bytes are spread across the whole symbol, so a scratch in one spot costs a few bits from many bytes, and the decoder can rebuild them.
Can a normal QR scanner read Stitch or Rings?
No. A phone’s camera app looks for QR’s three square finders, so it does not recognize these. They are read by the Codes scanner, which tells the two formats apart by their finders.

Built by Preston Kwei with TypeScript, Next.js, Cloudflare Workers, and SVG.