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-2023 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#include <gal/color4d.h>
33
34class LINE_READER;
35class PLOTTER;
36
37
48{
49public:
50 BITMAP_BASE( const VECTOR2I& pos = VECTOR2I( 0, 0 ) );
51
52 BITMAP_BASE( const BITMAP_BASE& aSchBitmap );
53
55 {
56 delete m_bitmap;
57 delete m_image;
58 delete m_originalImage;
59 }
60
61 /*
62 * Accessors:
63 */
64 double GetPixelSizeIu() const { return m_pixelSizeIu; }
65 void SetPixelSizeIu( double aPixSize ) { m_pixelSizeIu = aPixSize; }
66
67 wxImage* GetImageData() { return m_image; }
68 const wxImage* GetImageData() const { return m_image; }
69
70 const wxImage* GetOriginalImageData() const { return m_originalImage; }
71
72 double GetScale() const { return m_scale; }
73 void SetScale( double aScale ) { m_scale = aScale; }
74
75 KIID GetImageID() const { return m_imageId; }
76
80 void ImportData( BITMAP_BASE* aItem );
81
93 double GetScalingFactor() const
94 {
95 return m_pixelSizeIu * m_scale;
96 }
97
101 VECTOR2I GetSize() const;
102
107 {
108 if( m_image )
109 return VECTOR2I( m_image->GetWidth(), m_image->GetHeight() );
110 else
111 return VECTOR2I( 0, 0 );
112 }
113
117 int GetPPI() const
118 {
119 return m_ppi;
120 }
121
129 const BOX2I GetBoundingBox() const;
130
131 void DrawBitmap( wxDC* aDC, const VECTOR2I& aPos,
132 const KIGFX::COLOR4D& aBackgroundColor = KIGFX::COLOR4D::UNSPECIFIED );
133
144 bool ReadImageFile( const wxString& aFullFilename );
145
157 bool ReadImageFile( wxInputStream& aInStream );
158
170 bool ReadImageFile( wxMemoryBuffer& aBuf );
171
180 bool SaveImageData( wxOutputStream& aOutStream ) const;
181
192 bool LoadLegacyData( LINE_READER& aLine, wxString& aErrorMsg );
193
199 void Mirror( bool aVertically );
200
206 void Rotate( bool aRotateCCW );
207
208 void ConvertToGreyscale();
209
210 bool IsMirroredX() const { return m_isMirroredX; }
211 bool IsMirroredY() const { return m_isMirroredY; }
212 EDA_ANGLE Rotation() const { return m_rotation; }
213
224 void PlotImage( PLOTTER* aPlotter, const VECTOR2I& aPos,
225 const KIGFX::COLOR4D& aDefaultColor, int aDefaultPensize ) const;
226
230 wxBitmapType GetImageType() const { return m_imageType; }
231
235 void SetImageType( wxBitmapType aType ) { m_imageType = aType; }
236
240 const wxMemoryBuffer& GetImageDataBuffer() const { return m_imageData; }
241
246
247private:
248 /*
249 * Rebuild the internal bitmap used to draw/plot image.
250 *
251 * This must be called after a #m_image change.
252 *
253 * @param aResetID is used to reset the cache ID used for OpenGL rendering.
254 */
255 void rebuildBitmap( bool aResetID = true );
256
257 void updatePPI();
258
259 double m_scale; // The scaling factor of the bitmap
260 // With m_pixelSizeIu, controls the actual draw size
261 wxMemoryBuffer m_imageData; // The original image data, in its original format
262 wxBitmapType m_imageType; // the image type (png, jpeg, etc.)
263
264 wxImage* m_image; // the raw, uncompressed image data
265 wxImage* m_originalImage; // Raw image data, not transformed by rotate/mirror
266 wxBitmap* m_bitmap; // the bitmap used to draw/plot image
267 double m_pixelSizeIu; // The scaling factor of the bitmap
268 // to convert the bitmap size (in pixels)
269 // to internal KiCad units
270 // Usually does not change
271 int m_ppi; // the bitmap definition. the default is 300PPI
273 bool m_isMirroredX; // Used for OpenGL rendering only
274 bool m_isMirroredY; // Used for OpenGL rendering only
275 EDA_ANGLE m_rotation; // Used for OpenGL rendering only
276};
277
278
279#endif // BITMAP_BASE_H
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:48
wxMemoryBuffer m_imageData
Definition: bitmap_base.h:261
void Rotate(bool aRotateCCW)
Rotate image CW or CCW.
bool LoadLegacyData(LINE_READER &aLine, wxString &aErrorMsg)
Load an image data saved by #SaveData.
double GetScalingFactor() const
This scaling factor depends on m_pixelSizeIu and m_scale.
Definition: bitmap_base.h:93
void SetImageType(wxBitmapType aType)
Set the bitmap type (png, jpeg, etc.)
Definition: bitmap_base.h:235
const wxImage * GetOriginalImageData() const
Definition: bitmap_base.h:70
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:106
EDA_ANGLE Rotation() const
Definition: bitmap_base.h:212
void updatePPI()
Definition: bitmap_base.cpp:94
const BOX2I GetBoundingBox() const
Return the orthogonal, bounding box of this object for display purposes.
double GetPixelSizeIu() const
Definition: bitmap_base.h:64
double GetScale() const
Definition: bitmap_base.h:72
wxBitmapType GetImageType() const
Return the bitmap type (png, jpeg, etc.)
Definition: bitmap_base.h:230
bool m_isMirroredY
Definition: bitmap_base.h:274
bool m_isMirroredX
Definition: bitmap_base.h:273
void Mirror(bool aVertically)
Mirror image vertically (i.e.
const wxMemoryBuffer & GetImageDataBuffer() const
Definition: bitmap_base.h:240
KIID m_imageId
Definition: bitmap_base.h:272
bool SaveImageData(wxOutputStream &aOutStream) const
Write the bitmap data to aOutStream.
bool IsMirroredX() const
Definition: bitmap_base.h:210
wxImage * m_originalImage
Definition: bitmap_base.h:265
void rebuildBitmap(bool aResetID=true)
Definition: bitmap_base.cpp:81
void DrawBitmap(wxDC *aDC, const VECTOR2I &aPos, const KIGFX::COLOR4D &aBackgroundColor=KIGFX::COLOR4D::UNSPECIFIED)
wxBitmapType m_imageType
Definition: bitmap_base.h:262
bool IsMirroredY() const
Definition: bitmap_base.h:211
void SetPixelSizeIu(double aPixSize)
Definition: bitmap_base.h:65
wxBitmap * m_bitmap
Definition: bitmap_base.h:266
void ImportData(BITMAP_BASE *aItem)
Copy aItem image to this object and update m_bitmap.
void ConvertToGreyscale()
void UpdateImageDataBuffer()
Resets the image data buffer using the current image data.
const wxImage * GetImageData() const
Definition: bitmap_base.h:68
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores in memory an image file.
KIID GetImageID() const
Definition: bitmap_base.h:75
wxImage * m_image
Definition: bitmap_base.h:264
double m_scale
Definition: bitmap_base.h:259
double m_pixelSizeIu
Definition: bitmap_base.h:267
int GetPPI() const
Definition: bitmap_base.h:117
wxImage * GetImageData()
Definition: bitmap_base.h:67
VECTOR2I GetSize() const
EDA_ANGLE m_rotation
Definition: bitmap_base.h:275
void SetScale(double aScale)
Definition: bitmap_base.h:73
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:398
Definition: kiid.h:49
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:104
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588