KiCad PCB EDA Suite
Loading...
Searching...
No Matches
bitmap_import_plugin.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef BITMAP_IMPORT_PLUGIN_H
21#define BITMAP_IMPORT_PLUGIN_H
22
24
25#include <vector>
26#include <wx/image.h>
27
28
36{
37public:
39 static constexpr double DEFAULT_THRESHOLD = 0.5;
40
42 static constexpr int DEFAULT_DPI = 300;
43
44 const wxString GetName() const override { return "Bitmap image"; }
45
46 const std::vector<std::string> GetFileExtensions() const override
47 {
48 static std::vector<std::string> exts = { "png", "jpg", "jpeg", "bmp", "gif" };
49 return exts;
50 }
51
52 const wxString& GetMessages() const override { return m_messages; }
53
54 void ReportMsg( const wxString& aMessage ) override;
55
56 bool Load( const wxString& aFileName ) override;
57 bool LoadFromMemory( const wxMemoryBuffer& aMemBuffer ) override;
58 bool Import() override;
59
60 double GetImageWidth() const override;
61 double GetImageHeight() const override;
62 BOX2D GetImageBBox() const override;
63
65 const wxImage& GetImage() const { return m_image; }
66
68 void SetThreshold( double aThreshold ) { m_threshold = aThreshold; }
69
71 void SetInvert( bool aInvert ) { m_invert = aInvert; }
72
73private:
74 double pixelSizeXmm() const;
75 double pixelSizeYmm() const;
76
77 wxImage m_image;
79 bool m_invert = false;
80 wxString m_messages;
81};
82
83#endif // BITMAP_IMPORT_PLUGIN_H
BOX2< VECTOR2D > BOX2D
Definition box2.h:915
Import a raster image by tracing its dark areas into filled polygons.
bool Load(const wxString &aFileName) override
Load file for import.
const wxString GetName() const override
Return the plugin name.
double GetImageWidth() const override
Return image width from original imported file.
void ReportMsg(const wxString &aMessage) override
void SetInvert(bool aInvert)
Invert the image before the threshold is applied.
bool LoadFromMemory(const wxMemoryBuffer &aMemBuffer) override
Set memory buffer with content for import.
bool Import() override
Actually imports the file.
BOX2D GetImageBBox() const override
Return image bounding box from original imported file.
const wxImage & GetImage() const
The loaded image, so a caller showing a preview does not have to read the file again.
static constexpr int DEFAULT_DPI
Resolution assumed for images that do not carry one.
void SetThreshold(double aThreshold)
Brightness cut deciding which pixels are traced, from 0 to 1.
double GetImageHeight() const override
Return image height from original imported file.
static constexpr double DEFAULT_THRESHOLD
Used when the caller offers the user no threshold setting.
const std::vector< std::string > GetFileExtensions() const override
Return a vector of the file extensions handled by this plugin.
const wxString & GetMessages() const override
Collect warning and error messages after loading/importing.
Interface for vector graphics import plugins.