35#include <potracelib.h>
36#include <wx/clipbrd.h>
39#include <wx/dcclient.h>
42#define DEFAULT_DPI 300
47 m_parentFrame( aParent ), m_negative( false ),
50 for( wxString unit : {
_(
"mm" ),
_(
"Inch" ),
_(
"DPI" ) } )
81 if( u_select < 0 || u_select > 2 )
106 if( last_layer < 0 || last_layer >
static_cast<int>(
MOD_LYR_FINAL ) )
200 int imageDPIx =
m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
201 int imageDPIy =
m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY );
203 if( imageDPIx > 1 && imageDPIy > 1 )
205 if(
m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT ) == wxIMAGE_RESOLUTION_CM )
207 imageDPIx =
KiROUND( imageDPIx * 2.54 );
208 imageDPIy =
KiROUND( imageDPIy * 2.54 );
229 wxCommandEvent
dummy;
282 text.Printf( wxS(
"%.1f" ), aSize );
284 text.Printf( wxS(
"%.2f" ), aSize );
302 m_SizeXValue->SetLabel( wxString::Format( wxT(
"%d" ), w ) );
303 m_SizeYValue->SetLabel( wxString::Format( wxT(
"%d" ), h ) );
304 m_BPPValue->SetLabel( wxString::Format( wxT(
"%d" ), nb ) );
314 case 1:
return EDA_UNITS::INCHES;
315 case 2:
return EDA_UNITS::UNSCALED;
317 default:
return EDA_UNITS::MILLIMETRES;
326 if(
m_UnitSizeX->GetValue().ToDouble( &new_size ) )
355 if(
m_UnitSizeY->GetValue().ToDouble( &new_size ) )
407 wxCommandEvent
dummy;
417 unsigned char threshold = aThreshold * 255;
418 unsigned char alpha_thresh = 0.7 * threshold;
420 for(
int y = 0; y < h; y++ )
422 for(
int x = 0; x < w; x++ )
424 unsigned char pixout;
429 if( pixin < threshold && alpha > alpha_thresh )
434 m_NB_Image.SetRGB( x, y, pixout, pixout, pixout );
448 for(
int y = 0; y < h; y++ )
450 for(
int x = 0; x < w; x++ )
503 if( wxTheClipboard->Open() )
507 wxTheClipboard->SetData(
new wxTextDataObject( buffer.c_str() ) );
508 wxTheClipboard->Flush();
509 wxTheClipboard->Close();
513 wxMessageBox(
_(
"Unable to export to the Clipboard") );
535 potrace_bitmap_t* potrace_bitmap = bm_new( w, h );
537 if( !potrace_bitmap )
540 msg.Printf(
_(
"Error allocating memory for potrace bitmap" ) );
546 for(
int y = 0; y < h; y++ )
548 for(
int x = 0; x < w; x++ )
550 unsigned char pix =
m_NB_Image.GetGreen( x, y );
551 BM_PUT( potrace_bitmap, x, y, pix ? 0 : 1 );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
void ExportPcbnewFormat()
Generate a footprint in S expr format.
void ExportDrawingSheetFormat()
Generate a file suitable to be copied into a drawing sheet (.kicad_wks) file.
void ExportEeschemaFormat()
Generate a schematic library which contains one component: the logo.
void ExportPostScriptFormat()
Generate a postscript file.
Class BITMAP2CMP_PANEL_BASE.
wxStaticText * m_BPPValue
wxScrolledWindow * m_GreyscalePicturePanel
wxButton * m_buttonExportFile
wxScrolledWindow * m_BNPicturePanel
wxButton * m_buttonExportClipboard
wxSlider * m_sliderThreshold
wxCheckBox * m_aspectRatioCheckbox
wxRadioBox * m_rbOutputFormat
wxCheckBox * m_checkNegative
wxStaticText * m_SizeXValue
wxStaticText * m_SizeYValue
wxStaticText * m_InputYValueDPI
wxStaticText * m_InputXValueDPI
wxScrolledWindow * m_InitialPicturePanel
void OnPaintGreyscale(wxPaintEvent &event) override
void SetOutputSize(const IMAGE_SIZE &aSizeX, const IMAGE_SIZE &aSizeY)
void OnSizeUnitChange(wxCommandEvent &event) override
void OnSizeChangeX(wxCommandEvent &event) override
void OnPaintInit(wxPaintEvent &event) override
void Binarize(double aThreshold)
void OnExportToClipboard(wxCommandEvent &event) override
void LoadSettings(BITMAP2CMP_SETTINGS *aCfg)
wxImage m_Greyscale_Image
wxString FormatOutputSize(double aSize)
void ToggleAspectRatioLock(wxCommandEvent &event) override
bool OpenProjectFiles(const std::vector< wxString > &aFilenames, int aCtl=0)
wxWindow * GetCurrentPage()
BITMAP2CMP_PANEL(BITMAP2CMP_FRAME *aParent)
void NegateGreyscaleImage()
void OnExportToFile(wxCommandEvent &event) override
void SaveSettings(BITMAP2CMP_SETTINGS *aCfg)
void OnThresholdChange(wxScrollEvent &event) override
void ExportToBuffer(std::string &aOutput, OUTPUT_FMT_ID aFormat)
generate a export data of the current bitmap.
BITMAP2CMP_FRAME * m_parentFrame
void OnFormatChange(wxCommandEvent &event) override
void OnLoadFile(wxCommandEvent &event) override
wxBitmap m_Greyscale_Bitmap
EDA_UNITS getUnitFromSelection()
void OnNegativeClicked(wxCommandEvent &event) override
void OnPaintBW(wxPaintEvent &event) override
void exportBitmap(OUTPUT_FMT_ID aFormat)
void OnSizeChangeY(wxCommandEvent &event) override
std::string & GetErrorMessages()
int ConvertBitmap(potrace_bitmap_t *aPotrace_bitmap, OUTPUT_FMT_ID aFormat, int aDpi_X, int aDpi_Y, BMP2CMP_MOD_LAYER aModLayer)
Run the conversion of the bitmap.
void SetUnit(EDA_UNITS aUnit)
void SetOriginalDPI(int aDPI)
void SetOutputSizeFromInitialImageSize()
void SetOutputSize(double aSize, EDA_UNITS aUnit)
void SetOriginalSizePixels(int aPixels)
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
std::vector< FAB_LAYER_COLOR > dummy