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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <wx/bitmap.h>
24#include <wx/image.h>
25
26#include <core/mirror.h>
27#include <kiid.h>
28#include <math/box2.h>
29#include <gal/color4d.h>
30
31class LINE_READER;
32class PLOTTER;
33
34
45{
46public:
47 BITMAP_BASE( const VECTOR2I& pos = VECTOR2I( 0, 0 ) );
48
49 BITMAP_BASE( const BITMAP_BASE& aSchBitmap );
50
52 {
53 delete m_bitmap;
54 delete m_image;
55 delete m_originalImage;
56 }
57
58 /*
59 * Accessors:
60 */
61 double GetPixelSizeIu() const { return m_pixelSizeIu; }
62 void SetPixelSizeIu( double aPixSize ) { m_pixelSizeIu = aPixSize; }
63
64 wxImage* GetImageData() { return m_image; }
65 const wxImage* GetImageData() const { return m_image; }
66
67 const wxImage* GetOriginalImageData() const { return m_originalImage; }
68
69 double GetScale() const { return m_scale; }
70 void SetScale( double aScale ) { m_scale = aScale; }
71
72 KIID GetImageID() const { return m_imageId; }
73
77 void ImportData( BITMAP_BASE& aItem );
78
90 double GetScalingFactor() const
91 {
92 return m_pixelSizeIu * m_scale;
93 }
94
98 VECTOR2I GetSize() const;
99
104 {
105 if( m_image )
106 return VECTOR2I( m_image->GetWidth(), m_image->GetHeight() );
107 else
108 return VECTOR2I( 0, 0 );
109 }
110
114 int GetPPI() const
115 {
116 return m_ppi;
117 }
118
127 int GetLegacyPPI() const;
128
136 const BOX2I GetBoundingBox() const;
137
138 void DrawBitmap( wxDC* aDC, const VECTOR2I& aPos,
139 const KIGFX::COLOR4D& aBackgroundColor = KIGFX::COLOR4D::UNSPECIFIED ) const;
140
151 bool ReadImageFile( const wxString& aFullFilename );
152
164 bool ReadImageFile( wxInputStream& aInStream );
165
177 bool ReadImageFile( wxMemoryBuffer& aBuf );
178
182 bool SetImage( const wxImage& aImage );
183
192 bool SaveImageData( wxOutputStream& aOutStream ) const;
193
204 bool LoadLegacyData( LINE_READER& aLine, wxString& aErrorMsg );
205
211 void Mirror( FLIP_DIRECTION aFlipDirection );
212
218 void Rotate( bool aRotateCCW );
219
220 void ConvertToGreyscale();
221
222 bool IsMirroredX() const { return m_isMirroredX; }
223 bool IsMirroredY() const { return m_isMirroredY; }
224 EDA_ANGLE Rotation() const { return m_rotation; }
225
236 void PlotImage( PLOTTER* aPlotter, const VECTOR2I& aPos,
237 const KIGFX::COLOR4D& aDefaultColor, int aDefaultPensize ) const;
238
242 wxBitmapType GetImageType() const { return m_imageType; }
243
247 void SetImageType( wxBitmapType aType ) { m_imageType = aType; }
248
249private:
254
262 void rebuildBitmap( bool aResetID = true );
263
268 void ensureBitmapUpToDate() const;
269
270 void updatePPI();
271
275 static void mirrorImageInPlace( wxImage& aImage, FLIP_DIRECTION aFlipDirection );
276
277 double m_scale;
279 mutable wxMemoryBuffer m_imageData;
280 wxBitmapType m_imageType;
281
282 wxImage* m_image;
284 mutable wxBitmap* m_bitmap;
285 mutable bool m_bitmapDirty;
289 int m_ppi;
291 bool m_isMirroredX; // Used for OpenGL rendering only
292 bool m_isMirroredY; // Used for OpenGL rendering only
293 EDA_ANGLE m_rotation; // Used for OpenGL rendering only
294};
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
This class handle bitmap images in KiCad.
Definition bitmap_base.h:45
void ensureBitmapUpToDate() const
Ensure the cached wxBitmap is up-to-date with the current wxImage.
wxMemoryBuffer m_imageData
Cached encoded image data (PNG/JPEG).
void Rotate(bool aRotateCCW)
Rotate image CW or CCW.
bool LoadLegacyData(LINE_READER &aLine, wxString &aErrorMsg)
Load an image data saved by #SaveData.
void updateImageDataBuffer()
Resets the image data buffer using the current image data.
double GetScalingFactor() const
This scaling factor depends on m_pixelSizeIu and m_scale.
Definition bitmap_base.h:90
void SetImageType(wxBitmapType aType)
Set the bitmap type (png, jpeg, etc.)
const wxImage * GetOriginalImageData() const
Definition bitmap_base.h:67
void PlotImage(PLOTTER *aPlotter, const VECTOR2I &aPos, const KIGFX::COLOR4D &aDefaultColor, int aDefaultPensize) const
Plot bitmap on plotter.
VECTOR2I GetSizePixels() const
EDA_ANGLE Rotation() const
void Mirror(FLIP_DIRECTION aFlipDirection)
Mirror image vertically (i.e.
const BOX2I GetBoundingBox() const
Return the orthogonal, bounding box of this object for display purposes.
double GetPixelSizeIu() const
Definition bitmap_base.h:61
double GetScale() const
Definition bitmap_base.h:69
wxBitmapType GetImageType() const
Return the bitmap type (png, jpeg, etc.)
bool m_isMirroredY
bool m_isMirroredX
void ImportData(BITMAP_BASE &aItem)
Copy aItem image to this object and update m_bitmap.
bool m_bitmapDirty
True when m_bitmap needs rebuilding from m_image.
bool SaveImageData(wxOutputStream &aOutStream) const
Write the bitmap data to aOutStream.
bool IsMirroredX() const
wxImage * m_originalImage
Raw image data, not transformed by rotate/mirror.
void rebuildBitmap(bool aResetID=true)
Rebuild the internal bitmap used to draw/plot image.
static void mirrorImageInPlace(wxImage &aImage, FLIP_DIRECTION aFlipDirection)
Mirror the wxImage pixel data in-place without allocating a new image.
wxBitmapType m_imageType
The image type (png, jpeg, etc.).
bool IsMirroredY() const
void SetPixelSizeIu(double aPixSize)
Definition bitmap_base.h:62
wxBitmap * m_bitmap
The bitmap used to draw/plot image.
void ConvertToGreyscale()
bool SetImage(const wxImage &aImage)
Set the image from an existing wxImage.
const wxImage * GetImageData() const
Definition bitmap_base.h:65
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores in memory an image file.
KIID GetImageID() const
Definition bitmap_base.h:72
wxImage * m_image
The raw, uncompressed image data.
double m_scale
The scaling factor of the bitmap with m_pixelSizeIu, controls the actual draw size.
double m_pixelSizeIu
The scaling factor of the bitmap to convert the bitmap size (in pixels) to internal KiCad units.
int m_ppi
The bitmap definition. The default is 300PPI.
int GetPPI() const
void DrawBitmap(wxDC *aDC, const VECTOR2I &aPos, const KIGFX::COLOR4D &aBackgroundColor=KIGFX::COLOR4D::UNSPECIFIED) const
int GetLegacyPPI() const
Recompute the PPI the way it was computed before the pixels/cm truncation fix.
wxImage * GetImageData()
Definition bitmap_base.h:64
BITMAP_BASE(const VECTOR2I &pos=VECTOR2I(0, 0))
VECTOR2I GetSize() const
EDA_ANGLE m_rotation
void SetScale(double aScale)
Definition bitmap_base.h:70
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
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:44
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition richio.h:62
Base plotter engine class.
Definition plotter.h:133
FLIP_DIRECTION
Definition mirror.h:23
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683