KiCad PCB EDA Suite
Loading...
Searching...
No Matches
bitmap_base.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 (C) 2018 jean-pierre.charras jp.charras at wanadoo.fr
5 * Copyright (C) 2013-2020 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef BITMAP_BASE_H
26#define BITMAP_BASE_H
27
28#include <wx/bitmap.h>
29#include <wx/image.h>
30#include <kiid.h>
31#include <math/box2.h>
32
33namespace KIGFX
34{
35class COLOR4D;
36}
37
38class LINE_READER;
39class PLOTTER;
40
41
52{
53public:
54 BITMAP_BASE( const VECTOR2I& pos = VECTOR2I( 0, 0 ) );
55
56 BITMAP_BASE( const BITMAP_BASE& aSchBitmap );
57
59 {
60 delete m_bitmap;
61 delete m_image;
62 delete m_originalImage;
63 }
64
65 /*
66 * Accessors:
67 */
68 double GetPixelSizeIu() const { return m_pixelSizeIu; }
69 void SetPixelSizeIu( double aPixSize ) { m_pixelSizeIu = aPixSize; }
70
71 wxImage* GetImageData() { return m_image; }
72 const wxImage* GetImageData() const { return m_image; }
73
74 const wxImage* GetOriginalImageData() const { return m_originalImage; }
75
76 void SetImage( wxImage* aImage );
77
78 double GetScale() const { return m_scale; }
79 void SetScale( double aScale ) { m_scale = aScale; }
80
81 KIID GetImageID() const { return m_imageId; }
82
86 void ImportData( BITMAP_BASE* aItem );
87
99 double GetScalingFactor() const
100 {
101 return m_pixelSizeIu * m_scale;
102 }
103
107 VECTOR2I GetSize() const;
108
113 {
114 if( m_image )
115 return VECTOR2I( m_image->GetWidth(), m_image->GetHeight() );
116 else
117 return VECTOR2I( 0, 0 );
118 }
119
123 int GetPPI() const
124 {
125 return m_ppi;
126 }
127
135 const BOX2I GetBoundingBox() const;
136
137 void DrawBitmap( wxDC* aDC, const VECTOR2I& aPos );
138
149 bool ReadImageFile( const wxString& aFullFilename );
150
162 bool ReadImageFile( wxInputStream& aInStream );
163
173 bool SaveData( FILE* aFile ) const;
174
183 void SaveData( wxArrayString& aPngStrings ) const;
184
195 bool LoadData( LINE_READER& aLine, wxString& aErrorMsg );
196
202 void Mirror( bool aVertically );
203
209 void Rotate( bool aRotateCCW );
210
211 void ConvertToGreyscale();
212
213 bool IsMirroredX() const { return m_isMirroredX; }
214 bool IsMirroredY() const { return m_isMirroredY; }
215 EDA_ANGLE Rotation() const { return m_rotation; }
216
227 void PlotImage( PLOTTER* aPlotter, const VECTOR2I& aPos,
228 const KIGFX::COLOR4D& aDefaultColor, int aDefaultPensize ) const;
229
230private:
231 /*
232 * Rebuild the internal bitmap used to draw/plot image.
233 *
234 * This must be called after a #m_image change.
235 *
236 * @param aResetID is used to reset the cache ID used for OpenGL rendering.
237 */
238 void rebuildBitmap( bool aResetID = true );
239
240 void updatePPI();
241
242 double m_scale; // The scaling factor of the bitmap
243 // With m_pixelSizeIu, controls the actual draw size
244 wxImage* m_image; // the raw image data (png format)
245 wxImage* m_originalImage; // Raw image data, not transformed by rotate/mirror
246 wxBitmap* m_bitmap; // the bitmap used to draw/plot image
247 double m_pixelSizeIu; // The scaling factor of the bitmap
248 // to convert the bitmap size (in pixels)
249 // to internal KiCad units
250 // Usually does not change
251 int m_ppi; // the bitmap definition. the default is 300PPI
253 bool m_isMirroredX; // Used for OpenGL rendering only
254 bool m_isMirroredY; // Used for OpenGL rendering only
255 EDA_ANGLE m_rotation; // Used for OpenGL rendering only
256};
257
258
259#endif // BITMAP_BASE_H
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:52
void Rotate(bool aRotateCCW)
Rotate image CW or CCW.
double GetScalingFactor() const
This scaling factor depends on m_pixelSizeIu and m_scale.
Definition: bitmap_base.h:99
bool SaveData(FILE *aFile) const
Write the bitmap data to aFile.
const wxImage * GetOriginalImageData() const
Definition: bitmap_base.h:74
void PlotImage(PLOTTER *aPlotter, const VECTOR2I &aPos, const KIGFX::COLOR4D &aDefaultColor, int aDefaultPensize) const
Plot bitmap on plotter.
VECTOR2I GetSizePixels() const
Definition: bitmap_base.h:112
EDA_ANGLE Rotation() const
Definition: bitmap_base.h:215
void updatePPI()
Definition: bitmap_base.cpp:96
const BOX2I GetBoundingBox() const
Return the orthogonal, bounding box of this object for display purposes.
double GetPixelSizeIu() const
Definition: bitmap_base.h:68
double GetScale() const
Definition: bitmap_base.h:78
bool m_isMirroredY
Definition: bitmap_base.h:254
bool m_isMirroredX
Definition: bitmap_base.h:253
void Mirror(bool aVertically)
Mirror image vertically (i.e.
KIID m_imageId
Definition: bitmap_base.h:252
bool IsMirroredX() const
Definition: bitmap_base.h:213
wxImage * m_originalImage
Definition: bitmap_base.h:245
void rebuildBitmap(bool aResetID=true)
Definition: bitmap_base.cpp:84
bool IsMirroredY() const
Definition: bitmap_base.h:214
void SetPixelSizeIu(double aPixSize)
Definition: bitmap_base.h:69
wxBitmap * m_bitmap
Definition: bitmap_base.h:246
void ImportData(BITMAP_BASE *aItem)
Copy aItem image to this object and update m_bitmap.
void ConvertToGreyscale()
void DrawBitmap(wxDC *aDC, const VECTOR2I &aPos)
void SetImage(wxImage *aImage)
Definition: bitmap_base.cpp:73
const wxImage * GetImageData() const
Definition: bitmap_base.h:72
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores in memory an image file.
KIID GetImageID() const
Definition: bitmap_base.h:81
wxImage * m_image
Definition: bitmap_base.h:244
double m_scale
Definition: bitmap_base.h:242
double m_pixelSizeIu
Definition: bitmap_base.h:247
int GetPPI() const
Definition: bitmap_base.h:123
bool LoadData(LINE_READER &aLine, wxString &aErrorMsg)
Load an image data saved by SaveData.
wxImage * GetImageData()
Definition: bitmap_base.h:71
VECTOR2I GetSize() const
EDA_ANGLE m_rotation
Definition: bitmap_base.h:255
void SetScale(double aScale)
Definition: bitmap_base.h:79
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
Definition: kiid.h:48
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:93
Base plotter engine class.
Definition: plotter.h:110
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:246
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588