High-performance C++ Gerber file parsing and rendering library with separation architecture design between parsing and rendering
- Separation of parsing and rendering: Core parser is completely decoupled from rendering engine for easy extension and customization
- Blend2D rendering engine: Provides a high-performance 2D rendering backend with headless image export
- High performance: Optimized parsing algorithms and memory management
- Cross-platform: Blend2D-based, supports Linux natively. Need Windows/macOS? Contact us for paid cross-platform support.
| 🚀 | This project saves you weeks of Gerber parsing development. |
| 💰 | Your donation directly funds feature development and maintenance. |
⭐ Star this project · 🐛 Submit Issues · 📖 Improve docs · 🔄 Share with others
src/
├── parser/ # Gerber file parser
│ └── src/
│ ├── gerber_parser/ # Parser core implementation
│ ├── engine/ # Parser engine interface
│ └── parser/ # Various Gerber code parsers
└── engines/ # Rendering engines
├── engine_common.h # Shared engine constants
└── blend2d_engine.cpp/h # Blend2D rendering engine
- Supports complete Gerber file format (RS-274X)
- Parses various aperture types: circular, rectangular, polygonal, elliptical, macro-defined
- Supports G codes, D codes, M codes, and other Gerber commands
- Provides bounding box calculation and coordinate transformation
- Error handling and logging
- Blend2D engine: Headless rendering, PNG export via built-in codec
- Extensible rendering interface, easy to add new rendering backends
- CMake 3.20+
- C++17 compatible compiler (GCC 7+, Clang 5+, MSVC 2019+)
- vcpkg (set the
VCPKG_ROOTenvironment variable) - Blend2D (via vcpkg manifest, see vcpkg.json)
All dependencies are installed automatically by the vcpkg manifest — no manual submodule initialization required.
# Prerequisite: install vcpkg and set the VCPKG_ROOT environment variable
git clone https://github.com/hsiang-lee/gerber-parser.git
cd gerber-parser
cmake --preset default # vcpkg manifest auto-installs blend2d/gtest/gflags
cmake --build --preset defaultThe project provides one example program:
# Convert Gerber file to PNG image
./build/example/gerber2image/gerber2image --gerber_file="path/to/gerber/file" --um_pixel=5The output PNG is written next to the input file as <input file>.png.
#include <blend2d.h>
#include "gerber_parser/gerber_parser.h"
#include "engines/blend2d_engine.h"
// Parse Gerber file
auto parser = std::make_shared<GerberParser>("path/to/gerber/file");
auto gerber = parser->GetGerber();
// Get bounding box information
const auto& bbox = gerber->GetBBox();
std::cout << "Width: " << bbox.Width() << " Height: " << bbox.Height() << std::endl;
// Render using Blend2D and export to PNG
BLImage image(800, 600, BL_FORMAT_PRGB32);
Blend2DEngine engine(image, bbox, 0.05);
engine.DrawBackground();
const int ret = engine.RenderGerber(gerber);
if (ret != 0) return ret;
image.writeToFile("output.png");- Inherit from the
Enginebase class - Implement the
RenderGerbermethod - Add new engine files in the
src/engines/directory - No CMakeLists.txt changes needed (CMake GLOB automatically collects
engines/*.cpp, and thegerber_enginetarget already linksblend2d::blend2d)
- Add new parsers in the
src/parser/gerber_parser/directory - Implement the corresponding parsing logic
- Update the parser factory class
The project includes a complete test suite:
# Configure and build (tests enabled by default preset)
cmake --preset default && cmake --build --preset default
# Run tests
ctest --preset default # or: ctest --test-dir buildTest inputs live in tests/test_data/gerber/gerber_files/, and the golden references are 19 Blend2D-rendered PNGs under tests/test_data/gerber/results/. Comparisons use a tolerance-based image diff (not strict per-pixel equality).
We welcome all forms of contributions! Please refer to the following steps:
- Fork this project
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Create a Pull Request
- Follow the .clang-format configuration in the project
- Use meaningful variable and function names
- Add appropriate comments and documentation
- Ensure all tests pass
This project is licensed under the MIT License - see the LICENSE file for details.
Thanks to the following open source projects for their support:
- Blend2D - High-performance 2D rendering library (Zlib license)
- Google Test - C++ testing framework
- gflags - Command line argument parsing
- Project homepage: https://github.com/hsiang-lee/gerber-parser.git
- Issues: https://github.com/hsiang-lee/gerber-parser/issues
- Email: leehsiang@hotmail.com
Gerber Parser - Making PCB file processing easier!


