API reference -- top-level package¶
All public symbols are importable from the root gerberdiff package; see
the Python API guide for usage examples.
Parsing¶
Parse a Gerber RS-274X file string into a ParsedImage.
All diagnostics (errors, warnings, info) are collected on
image.diagnostics. This function never raises for parse-level
problems; only genuine Python-level exceptions (e.g. MemoryError) propagate.
Parse an Excellon drill file into a ParsedImage.
Tool definitions become CircleAperture entries in image.apertures.
Drill hits become DrawOp(aperture_state=Flash) entries.
All coordinates are normalised to inches.
Both decimal-format (KiCad modern) and integer-format (Altium, older KiCad,
most CAM systems) coordinate encodings are supported. The zero-suppression
convention and digit counts are read from the METRIC/INCH header
line. If no format header is present, METRIC,TZ with 3.3 digit counts
is assumed and a DiagnosticSeverity.Warning is emitted.
Geometry diff¶
Geometry-diff two directories of Gerber/Excellon layer files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
before_dir
|
Path
|
Directories containing the before and after layer files. |
required |
after_dir
|
Path
|
Directories containing the before and after layer files. |
required |
layers
|
Sequence[str] | None
|
If given, only layers whose names appear in this sequence are diffed. |
None
|
move_tol_mm
|
float
|
Minimum centroid displacement (mm) for a matched pair to be reported
as |
DEFAULT_MOVE_TOL_MM
|
gate_radius_mm
|
float
|
Maximum centroid distance (mm) at which two ops can be considered the same object. |
DEFAULT_GATE_RADIUS_MM
|
area_tol
|
float
|
Relative area delta within which two matched ops still count as the
same dimensions (distinguishes |
DEFAULT_AREA_TOL
|
dust_area_mm2
|
float
|
Boolean-difference components smaller than this (mm^2) are dropped as numeric noise. |
DEFAULT_DUST_AREA_MM2
|
on_diagnostic
|
Callable[[Path, Diagnostic], None] | None
|
Called with |
None
|
Raises:
| Type | Description |
|---|---|
GerberParseError
|
When a file contains a fatal ( |
OSError
|
When a layer file cannot be read. |
Raster diff¶
Render both images to a shared viewport and compute the pixel diff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_a
|
ParsedImage
|
Parsed Gerber/Excellon images to compare. |
required |
image_b
|
ParsedImage
|
Parsed Gerber/Excellon images to compare. |
required |
width
|
int
|
Canvas dimensions in pixels. |
required |
height
|
int
|
Canvas dimensions in pixels. |
required |
alignment_offset
|
tuple[float, float] | None
|
Optional |
None
|
min_pixel_count
|
int
|
Minimum pixel count for a region to be reported (filters noise). |
4
|
merge_tolerance
|
float
|
Bounding-box padding (inches) used when deciding whether to merge two nearby regions into one. |
0.05
|
overlay_callback
|
Callable[[ndarray, ndarray, ndarray], None] | None
|
Optional callable invoked with |
None
|
Diff two directories of Gerber/Excellon layer files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
before_dir
|
Path
|
Directories containing the before and after layer files. |
required |
after_dir
|
Path
|
Directories containing the before and after layer files. |
required |
width
|
int
|
Canvas dimensions in pixels. |
2048
|
height
|
int
|
Canvas dimensions in pixels. |
2048
|
layers
|
Sequence[str] | None
|
If given, only layers whose names appear in this sequence are diffed. |
None
|
alignment_offset
|
tuple[float, float] | None
|
Optional |
None
|
min_pixel_count
|
int
|
Minimum pixel count for a region to be reported. |
4
|
merge_tolerance
|
float
|
Bounding-box padding (inches) used when merging nearby regions. |
0.05
|
overlay_callback
|
Callable[[str, ndarray, ndarray, ndarray], None] | None
|
Called with |
None
|
on_diagnostic
|
Callable[[Path, Diagnostic], None] | None
|
Called with |
None
|
Raises:
| Type | Description |
|---|---|
GerberParseError
|
When a file contains a fatal ( |
OSError
|
When a layer file cannot be read. |
Rendering¶
Render to a numpy array of shape (H, W, 4) with dtype uint8.
Channel order is BGRA (Cairo's native ARGB32 little-endian layout).
Render parsed_image into a new cairo.ImageSurface.
The surface uses FORMAT_ARGB32 (premultiplied alpha). Transparent
pixels represent the PCB substrate / background.
coordinate_offset shifts the board in world-space (inches) before
rendering. Used by compute_diff to align two boards with different
origins.
Fit bbox into a width x height canvas with a 10% margin.
Returns a default viewport (zoom=100, centred) when the bbox is invalid or has zero extent in either axis.