SkillAgentSearch skills...

Gerb2img

Library and utility for converting Gerber RS-274X and Excellon files into TIFF/BMP images. Supports both DLL and EXE versions, various processing options (DPI, scaling, inversion). Compatible with C++, Python, Delphi, and others.

Install / Use

/learn @DimaFantasy/Gerb2img
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Gerb2Img

Gerb2Img is a library and utility for converting Gerber RS-274X and Excellon (drill) files into raster images in TIFF or BMP formats. This project is based on the original gerb2tiff-1.2 code developed by Adam Seychell (2001). The original project was an executable file (.exe) and only supported the TIFF format. The gerb2tiff-1.2 project is no longer maintained or developed.

The project has been reworked into a DLL library and EXE utility, making it convenient for use in any C++, Delphi, Python, and other language projects. Compiler warnings have also been eliminated, some bugs fixed, BMP format support added (for DLL), and compatibility improved.

Main Features

  • Converting Gerber files to monochrome images:
    • DLL supports TIFF and BMP formats (depending on the output file extension).
    • EXE only supports TIFF format.
  • Support for Excellon files (drill format) in the DLL implementation.
  • Support for various parameters: DPI, scaling, polarity inversion, adding borders.
  • Export of functions for use in other applications through the DLL interface:
    • processGerber: The main function for processing Gerber files.
    • processExcellon: Function for processing Excellon files (drilling).

Exported DLL Functions

processGerber

int __stdcall processGerber(
    double imageDPI,              // Image resolution in DPI
    bool optGrowUnitsMillimeters, // Flag: growth units in millimeters
    bool optBoarderUnitsMillimeters, // Flag: border units in millimeters
    double optBoarder,           // Border size (in DPI or mm depending on flag)
    bool optInvertPolarity,      // Invert polarity
    double optGrowSize,          // Growth size (in DPI or mm depending on flag)
    double optScaleX,            // Scale factor on X axis
    double optScaleY,            // Scale factor on Y axis
    const char *outputFilename,  // Output file name
    const char *inputFilename,   // Input Gerber file name
    int *offsetX,                // [OUT] Origin X-offset in pixels
    int *offsetY                 // [OUT] Origin Y-offset in pixels
);

processExcellon

int __stdcall processExcellon(
    double imageDPI,              // Image resolution in DPI
    bool unitsMillimeters,        // Units: true - millimeters, false - pixels
    double optBoarder,            // Border size (in mm or pixels)
    bool optInvertPolarity,       // Invert polarity
    double optGrowSize,           // Hole growth size (in mm or pixels)
    double optScaleX,             // Scale factor on X axis
    double optScaleY,             // Scale factor on Y axis
    bool uniformDrills,           // Use uniform diameter for all holes
    bool uniformDrillsMillimeters,// For uniformDrillDiameter: true - millimeters, false - inches
    double uniformDrillDiameter,  // Diameter value for all holes (if uniformDrills=true) (mm/in)
    const char *outputFilename,   // Output file name
    const char *inputFilename,    // Input Excellon file name
    int *drillCount,              // [OUT] Pointer to variable for returning the number of drilled holes
    int *offsetX,                 // [OUT] Origin X-offset in pixels
    int *offsetY                  // [OUT] Origin Y-offset in pixels
);

Note:

  • The optGrowSize parameter in Excellon allows compensation for technological peculiarities in production: positive values increase hole diameter, negative values decrease it.
  • The offsetX and offsetY parameters provide information about the origin (0,0) position relative to the image:
    • Positive X offset: origin is to the right of the image's left edge
    • Negative X offset: origin is outside the left edge of the image
    • Positive Y offset: origin is above the top edge of the image
    • Negative Y offset: origin is below the top edge of the image

Usage Examples

Python (via ctypes)

import ctypes

# Loading the library
gerb2img = ctypes.WinDLL("gerb2img.dll")

# Defining the processGerber function
processGerber = gerb2img.processGerber
processGerber.argtypes = [
    ctypes.c_double, ctypes.c_bool, ctypes.c_bool, ctypes.c_double,
    ctypes.c_bool, ctypes.c_double, ctypes.c_double,
    ctypes.c_double, ctypes.c_char_p, ctypes.c_char_p,
    ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int)
]
processGerber.restype = ctypes.c_int

# Variables for receiving origin offset values
offsetX = ctypes.c_int(0)
offsetY = ctypes.c_int(0)

# Calling the function for Gerber
result = processGerber(
    2400.0, False, False, 0.0, False, 0.0, 1.0, 1.0,
    b"output.bmp", b"example.gbr", 
    ctypes.byref(offsetX), ctypes.byref(offsetY)
)

if result == 0:
    print("Gerber conversion successful!")
    print(f"Origin offset: X={offsetX.value}, Y={offsetY.value} pixels")
else:
    print("Gerber conversion error!")

# Defining the processExcellon function
processExcellon = gerb2img.processExcellon
processExcellon.argtypes = [
    ctypes.c_double, ctypes.c_bool, ctypes.c_double,
    ctypes.c_bool, ctypes.c_double, ctypes.c_double,
    ctypes.c_double, ctypes.c_bool, ctypes.c_bool,
    ctypes.c_double, ctypes.c_char_p, ctypes.c_char_p,
    ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int),
    ctypes.POINTER(ctypes.c_int)
]
processExcellon.restype = ctypes.c_int

# Calling the function for Excellon
drill_count = ctypes.c_int(0)
offsetX_drill = ctypes.c_int(0)
offsetY_drill = ctypes.c_int(0)

result = processExcellon(
    2400.0, False, 0.0, False, 0.0, 1.0, 1.0,
    False, False, 0.0,
    b"drill_output.bmp", b"example.drl",
    ctypes.byref(drill_count), ctypes.byref(offsetX_drill),
    ctypes.byref(offsetY_drill)
)

if result == 0:
    print(f"Excellon conversion successful! Number of drills: {drill_count.value}")
    print(f"Origin offset: X={offsetX_drill.value}, Y={offsetY_drill.value} pixels")
else:
    print("Excellon conversion error!")

Delphi

library Gerb2ImgDemo;

uses
  Windows, SysUtils;

type
  TProcessGerber = function(
    imageDPI: Double; 
    optGrowUnitsMillimeters: Boolean;
    optBoarderUnitsMillimeters: Boolean;
    optBoarder: Double;
    optInvertPolarity: Boolean;
    optGrowSize: Double;
    optScaleX: Double;
    optScaleY: Double;
    outputFilename: PAnsiChar;
    inputFilename: PAnsiChar;
    offsetX: PInteger;
    offsetY: PInteger
  ): Integer; stdcall;

  TProcessExcellon = function(
    imageDPI: Double;
    unitsMillimeters: Boolean;
    optBoarder: Double;
    optInvertPolarity: Boolean;
    optGrowSize: Double;
    optScaleX: Double;
    optScaleY: Double;
    uniformDrills: Boolean;
    uniformDrillsMillimeters: Boolean;
    uniformDrillDiameter: Double;
    outputFilename: PAnsiChar;
    inputFilename: PAnsiChar;
    drillCount: PInteger;
    offsetX: PInteger;
    offsetY: PInteger
  ): Integer; stdcall;

var
  Gerb2ImgLib: THandle;
  ProcessGerber: TProcessGerber;
  ProcessExcellon: TProcessExcellon;

begin
  Gerb2ImgLib := LoadLibrary('gerb2img.dll');
  if Gerb2ImgLib = 0 then
    raise Exception.Create('Failed to load gerb2img.dll');

  @ProcessGerber := GetProcAddress(Gerb2ImgLib, 'processGerber');
  if not Assigned(ProcessGerber) then
    raise Exception.Create('Failed to find processGerber function');

  @ProcessExcellon := GetProcAddress(Gerb2ImgLib, 'processExcellon');
  if not Assigned(ProcessExcellon) then
    raise Exception.Create('Failed to find processExcellon function');

  try
    var offsetX, offsetY: Integer;
    if ProcessGerber(2400.0, False, False, 0.0, False, 0.0, 1.0, 1.0,
      'output.bmp', 'example.gbr', @offsetX, @offsetY) = 0 then
    begin
      Writeln('Gerber conversion successful!');
      Writeln('Origin offset: X=', offsetX, ', Y=', offsetY, ' pixels');
    end
    else
      Writeln('Gerber conversion error!');

    var drillCount, offsetX_drill, offsetY_drill: Integer;
    if ProcessExcellon(2400.0, False, 0.0, False, 0.0, 1.0, 1.0,
      False, False, 0.0, 'drill_output.bmp', 'example.drl', 
      @drillCount, @offsetX_drill, @offsetY_drill) = 0 then
    begin
      Writeln('Excellon conversion successful! Drill count: ', drillCount);
      Writeln('Origin offset: X=', offsetX_drill, ', Y=', offsetY_drill, ' pixels');
    end
    else
      Writeln('Excellon conversion error!');
  finally
    FreeLibrary(Gerb2ImgLib);
  end;
end.

Demo

The project includes demonstration examples for using the library:

  • Delphi: Example of using DLL for processing Gerber files.
  • Python: Example of usage via ctypes.

Building

Requirements

  • Compiler with C++11 or higher support.
  • Libraries:

🔧 Building Instructions for Windows (MinGW)

1. Install the libtiff dependency (other dependencies are already included in the project):

  • For 64-bit MinGW environment:

    pacman -S mingw-w64-x86_64-libtiff
    
  • For 32-bit MinGW environment:

    pacman -S mingw-w64-i686-libtiff
    

2. Compile the project:

  • Run mingw64.exe (for 64-bit) or mingw32.exe (for 32-bit).
  • Navigate to the project folder:
    cd gerb2img
    
  • Execute the build:
    make
    

💡 Main commands:

  • make — Build release DLL and EXE for the current architecture (x32 or x64).
  • make debug — Build debug DLL and EXE.
  • make clean — Remove all generated files.

🔧 Individual targets:

  • make dll — Only release DLL.
  • make exe — Only release EXE.
  • make dll_debug — Only debug DLL.
  • make exe_debug — Only debug EXE.

License

This project is distributed under the GNU General Public License v3.

Acknowledgements

  • Adam Seychell for the original gerb2tiff-1.2 project.
  • The Open Source community for provided libraries and tools.

Project Future

The project will be actively developed. Plans include:

  • Adding BMP format support for EXE.
  • Improving pe
View on GitHub
GitHub Stars4
CategoryCustomer
Updated2mo ago
Forks0

Languages

C++

Security Score

70/100

Audited on Jan 28, 2026

No findings