CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-google-zxing--core

Core barcode encoding/decoding library supporting 17 formats including QR Code, Data Matrix, Aztec, PDF 417, and various 1D barcodes

Pending
Overview
Eval results
Files

aztec.mddocs/reference/

Aztec Support

Complete Aztec Code 2D barcode encoding and decoding support. Aztec codes are square 2D matrix symbology with variable capacity (up to 3,832 numeric characters) and built-in error correction. A distinctive feature is the central bull's-eye finder pattern, and no quiet zone is required, making Aztec ideal for mobile tickets, transportation passes, and space-constrained applications.

Capabilities

AztecReader

Reader implementation for detecting and decoding Aztec barcodes from binary bitmap images. Supports both compact and full-range Aztec codes with automatic layer detection.

/**
 * Reader implementation for Aztec Code 2D barcodes.
 * Locates and decodes Aztec codes using the central bull's-eye finder pattern.
 * Supports both compact (up to 4 layers) and full-range (up to 32 layers) variants.
 */
public class AztecReader implements Reader {
    /**
     * Creates a new Aztec reader.
     */
    public AztecReader();

    /**
     * Locates and decodes an Aztec code in an image.
     *
     * @param image Binary bitmap representation of the image
     * @return Result containing decoded text and metadata
     * @throws NotFoundException If an Aztec code cannot be found in the image
     * @throws FormatException If an Aztec code cannot be decoded
     */
    @Override
    public Result decode(BinaryBitmap image) throws NotFoundException, FormatException;

    /**
     * Locates and decodes an Aztec code in an image with configuration hints.
     *
     * @param image Binary bitmap representation of the image
     * @param hints Map of DecodeHintType to configuration values
     *              - CHARACTER_SET (String): Expected character encoding
     *              - TRY_HARDER (Boolean): Spend more time for better accuracy
     * @return Result containing decoded text and metadata
     * @throws NotFoundException If an Aztec code cannot be found in the image
     * @throws FormatException If an Aztec code cannot be decoded
     */
    @Override
    public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
        throws NotFoundException, FormatException;

    /**
     * Resets any internal state. Should be called between decoding attempts.
     */
    @Override
    public void reset();
}

Usage Example:

import com.google.zxing.*;
import com.google.zxing.common.*;
import com.google.zxing.aztec.*;
import java.util.*;

// Create luminance source from image pixels
int[] pixels = ...; // RGB int array
LuminanceSource source = new RGBLuminanceSource(width, height, pixels);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

// Decode Aztec code
Reader reader = new AztecReader();
Result result = reader.decode(bitmap);

// Access decoded data
String text = result.getText();
byte[] rawBytes = result.getRawBytes();
ResultPoint[] corners = result.getResultPoints();

// Access metadata
Map<ResultMetadataType, Object> metadata = result.getResultMetadata();
Integer errorsCorrected = (Integer) metadata.get(ResultMetadataType.ERRORS_CORRECTED);

AztecWriter

Writer implementation for encoding Aztec barcodes. Generates a BitMatrix representation with automatic or manual layer selection and configurable error correction.

/**
 * Writer implementation for Aztec Code 2D barcodes.
 * Encodes text into Aztec BitMatrix with automatic layer selection
 * or manual layer specification.
 */
public final class AztecWriter implements Writer {
    /**
     * Creates a new Aztec writer.
     */
    public AztecWriter();

    /**
     * Encodes contents into an Aztec BitMatrix with default settings.
     * Uses automatic layer selection and 33% error correction.
     *
     * @param contents String content to encode
     * @param format Must be BarcodeFormat.AZTEC
     * @param width Preferred width in pixels
     * @param height Preferred height in pixels
     * @return BitMatrix representation of the Aztec code
     * @throws WriterException If encoding fails
     * @throws IllegalArgumentException If format is not AZTEC
     */
    @Override
    public BitMatrix encode(String contents, BarcodeFormat format, int width, int height)
        throws WriterException;

    /**
     * Encodes contents into an Aztec BitMatrix with configuration hints.
     *
     * @param contents String content to encode
     * @param format Must be BarcodeFormat.AZTEC
     * @param width Preferred width in pixels
     * @param height Preferred height in pixels
     * @param hints Map of EncodeHintType to configuration values
     *              - ERROR_CORRECTION (Integer): Error correction percentage (default: 33)
     *              - AZTEC_LAYERS (Integer): Specific layer count (negative for compact)
     *                  Compact: -1 to -4 (1-4 layers)
     *                  Full-range: 1 to 32 (1-32 layers)
     *                  0 or omitted: Automatic selection
     *              - CHARACTER_SET (String): Character encoding (e.g., "UTF-8")
     * @return BitMatrix representation of the Aztec code
     * @throws WriterException If encoding fails
     * @throws IllegalArgumentException If parameters are invalid
     */
    @Override
    public BitMatrix encode(String contents, BarcodeFormat format, int width, int height,
                          Map<EncodeHintType,?> hints) throws WriterException;
}

Usage Example:

import com.google.zxing.*;
import com.google.zxing.common.*;
import com.google.zxing.aztec.*;
import java.util.*;

// Encode with default settings (automatic layer selection, 33% EC)
Writer writer = new AztecWriter();
BitMatrix matrix = writer.encode(
    "https://example.com",
    BarcodeFormat.AZTEC,
    200,
    200
);

// Encode with high error correction (50%)
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.ERROR_CORRECTION, 50);
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");

BitMatrix matrix2 = writer.encode(
    "Important ticket data",
    BarcodeFormat.AZTEC,
    300,
    300,
    hints
);

// Force compact mode with 2 layers
hints.clear();
hints.put(EncodeHintType.AZTEC_LAYERS, -2); // Negative for compact

BitMatrix compact = writer.encode(
    "Small data",
    BarcodeFormat.AZTEC,
    150,
    150,
    hints
);

// Force full-range mode with 10 layers
hints.clear();
hints.put(EncodeHintType.AZTEC_LAYERS, 10); // Positive for full-range

BitMatrix fullRange = writer.encode(
    "Larger data content here...",
    BarcodeFormat.AZTEC,
    400,
    400,
    hints
);

// Convert BitMatrix to image pixels
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
        pixels[y * width + x] = matrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF;
    }
}

Aztec Code Structure

Symbol Variants

Compact Aztec:

  • Layers: 1 to 4
  • Size: 15x15 to 27x27 modules
  • Capacity: Up to 110 numeric characters
  • Central finder: 9x9 modules
  • Use for: Small data, mobile tickets, coupons

Full-Range Aztec:

  • Layers: 1 to 32
  • Size: 19x19 to 151x151 modules
  • Capacity: Up to 3,832 numeric characters
  • Central finder: 11x11 modules
  • Use for: Large data, documents, complex tickets

No Quiet Zone Required

Unlike most 2D barcodes, Aztec codes do not require a quiet zone (white border), making them ideal for:

  • Densely packed labels
  • Mobile device screens
  • Space-constrained applications
  • Adjacent placement to other graphics

Data Capacity

Compact Aztec (Layers 1-4)

LayersSizeNumericAlphanumericBinaryEC %
115x15139623%
219x1940271923%
323x2370483325%
427x27110755325%

Full-Range Aztec (Selected Layers)

LayersSizeNumericAlphanumericBinaryEC %
119x192014923%
535x3523015711123%
1055x5573250135523%
1575x751532104874323%
2095x9524921704120823%
25115x11534222341165925%
32151x15138322622185725%

Error Correction

Aztec uses Reed-Solomon error correction with configurable levels:

Default: 33%

  • Good balance for most applications
  • Can recover from moderate damage

Low: 23%

  • Minimum overhead for clean environments
  • Maximum data capacity

High: 50%+

  • Maximum reliability for damaged codes
  • Reduced data capacity
  • Use for outdoor, printed, or small codes
// Low error correction (23%) - maximum capacity
hints.put(EncodeHintType.ERROR_CORRECTION, 23);

// Default error correction (33%)
hints.put(EncodeHintType.ERROR_CORRECTION, 33);

// High error correction (50%)
hints.put(EncodeHintType.ERROR_CORRECTION, 50);

Layer Selection

Automatic (Recommended)

Let the encoder select the optimal layer count:

// Omit AZTEC_LAYERS or set to 0
BitMatrix matrix = writer.encode("Data", BarcodeFormat.AZTEC, 200, 200);

Manual Compact Mode

Force compact mode with specific layers (-1 to -4):

Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.AZTEC_LAYERS, -1); // Compact, 1 layer (15x15)
hints.put(EncodeHintType.AZTEC_LAYERS, -2); // Compact, 2 layers (19x19)
hints.put(EncodeHintType.AZTEC_LAYERS, -3); // Compact, 3 layers (23x23)
hints.put(EncodeHintType.AZTEC_LAYERS, -4); // Compact, 4 layers (27x27)

Manual Full-Range Mode

Force full-range mode with specific layers (1 to 32):

hints.put(EncodeHintType.AZTEC_LAYERS, 1);  // Full-range, 1 layer (19x19)
hints.put(EncodeHintType.AZTEC_LAYERS, 10); // Full-range, 10 layers (55x55)
hints.put(EncodeHintType.AZTEC_LAYERS, 32); // Full-range, 32 layers (151x151)

Best Practices

Symbol Size Selection:

  • Use automatic layer selection for optimal results
  • Use compact mode for small data (< 100 characters)
  • Use full-range mode for larger data
  • Specify layers only when size constraints are critical

Error Correction:

  • Use 23% for clean printing, good quality
  • Use 33% (default) for most applications
  • Use 50% for outdoor use, small prints, or damage-prone applications

No Quiet Zone Advantage:

  • Place Aztec codes edge-to-edge on labels
  • Use on crowded mobile screens
  • Overlay on graphics or backgrounds
  • No wasted space for borders

Application Guidelines:

  • Mobile Tickets: Compact mode, 33% EC, UTF-8 encoding
  • Boarding Passes: Compact mode, high EC (50%)
  • Transportation Passes: Compact mode, 33% EC
  • Documents: Full-range mode, low EC (23%)
  • Outdoor Signage: Full-range mode, high EC (50%)

Quality Considerations:

  • Print at least 4-6 pixels per module for reliable scanning
  • Use high contrast (black on white recommended)
  • Test with actual scanners before production
  • Aztec is more forgiving of poor quality than QR codes due to bull's-eye finder

See Also

  • Core Reading and Writing - Basic reading and writing operations
  • Configuration Hints - AZTEC_LAYERS and ERROR_CORRECTION hints
  • Barcode Formats - Comparison with other 2D formats
  • QR Code Support - Similar 2D format with quiet zone requirement
  • Result Handling - Working with Result objects

Advanced Encoding APIs

Encoder

Advanced Aztec Code encoder providing direct access to encoding operations without using the Writer interface. Useful for custom encoding workflows and accessing intermediate encoding results.

/**
 * Aztec Code encoder with static methods for direct encoding.
 * Provides fine-grained control over encoding parameters.
 */
public final class Encoder {
    /**
     * Default error correction percentage (33%).
     */
    public static final int DEFAULT_EC_PERCENT = 33;

    /**
     * Default layer selection (0 = automatic).
     */
    public static final int DEFAULT_AZTEC_LAYERS = 0;

    /**
     * Encodes string content as Aztec using default settings.
     * Uses ISO-8859-1 encoding, 33% error correction, automatic layers.
     *
     * @param data Input string (must be ISO-8859-1 encodable)
     * @return AztecCode object containing encoded matrix and metadata
     */
    public static AztecCode encode(String data);

    /**
     * Encodes string content with custom error correction and layers.
     *
     * @param data Input string (must be ISO-8859-1 encodable)
     * @param minECCPercent Error correction percentage (23-90, recommended: 23% + 3 words minimum)
     * @param userSpecifiedLayers Layer specification:
     *                           0 = automatic (recommended)
     *                           -1 to -4 = compact mode with specified layers
     *                           1 to 32 = full-range mode with specified layers
     * @return AztecCode object containing encoded matrix and metadata
     */
    public static AztecCode encode(String data, int minECCPercent, int userSpecifiedLayers);

    /**
     * Encodes string content with custom charset (adds ECI indicator).
     *
     * @param data Input string
     * @param minECCPercent Error correction percentage
     * @param userSpecifiedLayers Layer specification (0 for automatic)
     * @param charset Character set for encoding (null for ISO-8859-1)
     * @return AztecCode object containing encoded matrix and metadata
     */
    public static AztecCode encode(String data, int minECCPercent, int userSpecifiedLayers, Charset charset);

    /**
     * Encodes binary data as Aztec using default settings.
     *
     * @param data Binary data bytes
     * @return AztecCode object containing encoded matrix and metadata
     */
    public static AztecCode encode(byte[] data);

    /**
     * Encodes binary data with custom error correction and layers.
     *
     * @param data Binary data bytes
     * @param minECCPercent Error correction percentage
     * @param userSpecifiedLayers Layer specification (0 for automatic)
     * @return AztecCode object containing encoded matrix and metadata
     */
    public static AztecCode encode(byte[] data, int minECCPercent, int userSpecifiedLayers);

    /**
     * Encodes binary data with custom charset ECI marker.
     *
     * @param data Binary data bytes
     * @param minECCPercent Error correction percentage
     * @param userSpecifiedLayers Layer specification (0 for automatic)
     * @param charset Character set to mark with ECI (null for default)
     * @return AztecCode object containing encoded matrix and metadata
     */
    public static AztecCode encode(byte[] data, int minECCPercent, int userSpecifiedLayers, Charset charset);
}

Usage Example:

import com.google.zxing.aztec.encoder.*;
import java.nio.charset.StandardCharsets;

// Simple encoding with defaults
AztecCode aztec = Encoder.encode("Hello, World!");

// Access encoded structure
BitMatrix matrix = aztec.getMatrix();
int layers = aztec.getLayers();
boolean compact = aztec.isCompact();
int size = aztec.getSize();

System.out.println("Aztec " + (compact ? "Compact" : "Full-range"));
System.out.println("Layers: " + layers);
System.out.println("Size: " + size + "x" + size);

// Custom error correction (50%)
AztecCode highEC = Encoder.encode("Important data", 50, 0);

// Force compact mode with 2 layers
AztecCode compactAztec = Encoder.encode("Ticket#12345", 33, -2);

// Force full-range mode with 10 layers
AztecCode fullRange = Encoder.encode("Large data...", 23, 10);

// UTF-8 encoding with ECI
AztecCode utf8Aztec = Encoder.encode(
    "Hello 世界",
    33,
    0,
    StandardCharsets.UTF_8
);

// Binary data encoding
byte[] binaryData = new byte[]{0x01, 0x02, 0x03, 0x04};
AztecCode binaryAztec = Encoder.encode(binaryData, 33, 0);

AztecCode

Represents an encoded Aztec Code with access to the matrix and encoding parameters. Used as the output of the Encoder class, providing programmatic access to the encoded structure.

/**
 * Represents an encoded Aztec Code structure with matrix and metadata.
 * Provides access to encoding parameters and the encoded bit matrix.
 */
public final class AztecCode {
    /**
     * Checks if the code is compact mode.
     *
     * @return true if compact (1-4 layers), false if full-range (1-32 layers)
     */
    public boolean isCompact();

    /**
     * Sets compact mode flag.
     *
     * @param compact true for compact mode, false for full-range
     */
    public void setCompact(boolean compact);

    /**
     * Gets the symbol size in pixels (width and height).
     *
     * @return Size in pixels
     */
    public int getSize();

    /**
     * Sets the symbol size.
     *
     * @param size Size in pixels
     */
    public void setSize(int size);

    /**
     * Gets the number of layers (rings around center).
     *
     * @return Number of layers (1-4 for compact, 1-32 for full-range)
     */
    public int getLayers();

    /**
     * Sets the number of layers.
     *
     * @param layers Number of layers
     */
    public void setLayers(int layers);

    /**
     * Gets the number of data codewords.
     *
     * @return Number of data codewords (excluding error correction)
     */
    public int getCodeWords();

    /**
     * Sets the number of data codewords.
     *
     * @param codeWords Number of data codewords
     */
    public void setCodeWords(int codeWords);

    /**
     * Gets the encoded symbol matrix.
     *
     * @return BitMatrix containing the complete Aztec Code
     */
    public BitMatrix getMatrix();

    /**
     * Sets the encoded symbol matrix.
     *
     * @param matrix BitMatrix to set
     */
    public void setMatrix(BitMatrix matrix);
}

Usage Example:

import com.google.zxing.aztec.encoder.*;
import com.google.zxing.common.*;

// Encode and inspect structure
AztecCode aztec = Encoder.encode("Sample data", 33, 0);

// Check encoding parameters
if (aztec.isCompact()) {
    System.out.println("Compact Aztec with " + aztec.getLayers() + " layers");
    System.out.println("Size: " + aztec.getSize() + "x" + aztec.getSize() + " modules");
} else {
    System.out.println("Full-range Aztec with " + aztec.getLayers() + " layers");
    System.out.println("Size: " + aztec.getSize() + "x" + aztec.getSize() + " modules");
}

System.out.println("Data codewords: " + aztec.getCodeWords());

// Access matrix
BitMatrix matrix = aztec.getMatrix();
int width = matrix.getWidth();
int height = matrix.getHeight();

// Convert to image
for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
        boolean isBlack = matrix.get(x, y);
        // Render pixel
    }
}

Install with Tessl CLI

npx tessl i tessl/maven-com-google-zxing--core@3.5.1

docs

index.md

tile.json