KiCad PCB EDA Suite
Loading...
Searching...
No Matches
bitmap_tracing.h File Reference
#include <geometry/shape_poly_set.h>
#include <wx/image.h>

Go to the source code of this file.

Functions

wxImage ConvertImageToBilevel (const wxImage &aImage, double aThreshold, bool aInvert)
 Reduce an image to pure black and white.
 
wxImage MakeBilevelPreview (const wxImage &aImage, double aThreshold, bool aInvert, const wxSize &aRoom)
 Produce the black and white view of an image, shrunk to fit a preview area.
 
SHAPE_POLY_SET TraceBilevelImage (const wxImage &aBilevelImage, double aScaleX, double aScaleY, REPORTER &aReporter)
 Trace the black regions of a black and white image into filled polygons.
 

Function Documentation

◆ ConvertImageToBilevel()

wxImage ConvertImageToBilevel ( const wxImage & aImage,
double aThreshold,
bool aInvert )

Reduce an image to pure black and white.

A pixel becomes black when it is darker than the threshold and opaque enough. Masked areas become white.

Parameters
aImageis the source image.
aThresholdis the brightness cut, from 0 to 1.
aInvertinverts the greyscale before the cut is applied.
Returns
a new image holding only black and white pixels.

Definition at line 86 of file bitmap_tracing.cpp.

References source.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), DRAWING_TOOL::ConvertImageToOutlines(), SCH_EDIT_TOOL::ConvertImageToOutlines(), BITMAP_IMPORT_PLUGIN::Import(), and MakeBilevelPreview().

◆ MakeBilevelPreview()

wxImage MakeBilevelPreview ( const wxImage & aImage,
double aThreshold,
bool aInvert,
const wxSize & aRoom )

Produce the black and white view of an image, shrunk to fit a preview area.

The aspect ratio is kept, and an image already smaller than the area is left alone.

Parameters
aImageis the source image.
aThresholdis the brightness cut, from 0 to 1.
aInvertinverts the greyscale before the cut is applied.
aRoomis the area the result has to fit inside.
Returns
the black and white image, scaled down if it did not fit.

Definition at line 134 of file bitmap_tracing.cpp.

References ConvertImageToBilevel(), and KiROUND().

Referenced by DIALOG_IMPORT_GFX::updatePreview(), and DIALOG_IMPORT_GRAPHICS::updatePreview().

◆ TraceBilevelImage()

SHAPE_POLY_SET TraceBilevelImage ( const wxImage & aBilevelImage,
double aScaleX,
double aScaleY,
REPORTER & aReporter )

Trace the black regions of a black and white image into filled polygons.

Holes are fractured into their outlines, so every returned outline is a simple polygon that can be drawn filled.

Parameters
aBilevelImageis an image produced by ConvertImageToBilevel.
aScaleXconverts pixels to caller units on X.
aScaleYconverts pixels to caller units on Y. A negative value flips the Y axis.
aReporterreceives errors.
Returns
the traced polygons, empty if nothing was traced.

Definition at line 153 of file bitmap_tracing.cpp.

References _, SHAPE_POLY_SET::Append(), BezierToPolyline(), SHAPE_POLY_SET::BooleanSubtract(), SHAPE_POLY_SET::Fracture(), KiROUND(), SHAPE_POLY_SET::NewOutline(), SHAPE_POLY_SET::NormalizeAreaOutlines(), SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), path, SHAPE_POLY_SET::RemoveAllContours(), REPORTER::Report(), result, RPT_SEVERITY_ERROR, RPT_SEVERITY_WARNING, and SHAPE_POLY_SET::Simplify().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), DRAWING_TOOL::ConvertImageToOutlines(), SCH_EDIT_TOOL::ConvertImageToOutlines(), and BITMAP_IMPORT_PLUGIN::Import().