KiCad PCB EDA Suite
BITMAP_BASE Class Reference

This class handle bitmap images in KiCad. More...

#include <bitmap_base.h>

Public Member Functions

 BITMAP_BASE (const VECTOR2I &pos=VECTOR2I(0, 0))
 
 BITMAP_BASE (const BITMAP_BASE &aSchBitmap)
 
 ~BITMAP_BASE ()
 
double GetPixelSizeIu () const
 
void SetPixelSizeIu (double aPixSize)
 
wxImage * GetImageData ()
 
const wxImage * GetImageData () const
 
const wxImage * GetOriginalImageData () const
 
void SetImage (wxImage *aImage)
 
double GetScale () const
 
void SetScale (double aScale)
 
KIID GetImageID () const
 
void ImportData (BITMAP_BASE *aItem)
 Copy aItem image to this object and update m_bitmap. More...
 
double GetScalingFactor () const
 This scaling factor depends on m_pixelSizeIu and m_scale. More...
 
VECTOR2I GetSize () const
 
VECTOR2I GetSizePixels () const
 
int GetPPI () const
 
const BOX2I GetBoundingBox () const
 Return the orthogonal, bounding box of this object for display purposes. More...
 
void DrawBitmap (wxDC *aDC, const VECTOR2I &aPos)
 
bool ReadImageFile (const wxString &aFullFilename)
 Reads and stores in memory an image file. More...
 
bool ReadImageFile (wxInputStream &aInStream)
 Reads and stores in memory an image file. More...
 
bool SaveData (FILE *aFile) const
 Write the bitmap data to aFile. More...
 
void SaveData (wxArrayString &aPngStrings) const
 Write the bitmap data to an array string. More...
 
bool LoadData (LINE_READER &aLine, wxString &aErrorMsg)
 Load an image data saved by SaveData. More...
 
void Mirror (bool aVertically)
 Mirror image vertically (i.e. More...
 
void Rotate (bool aRotateCCW)
 Rotate image CW or CCW. More...
 
void ConvertToGreyscale ()
 
bool IsMirrored () const
 
EDA_ANGLE Rotation () const
 
void PlotImage (PLOTTER *aPlotter, const VECTOR2I &aPos, const KIGFX::COLOR4D &aDefaultColor, int aDefaultPensize) const
 Plot bitmap on plotter. More...
 

Private Member Functions

void rebuildBitmap (bool aResetID=true)
 
void updatePPI ()
 

Private Attributes

double m_scale
 
wxImage * m_image
 
wxImage * m_originalImage
 
wxBitmap * m_bitmap
 
double m_pixelSizeIu
 
int m_ppi
 
KIID m_imageId
 
bool m_isMirrored
 
EDA_ANGLE m_rotation
 

Detailed Description

This class handle bitmap images in KiCad.

It is not intended to be used alone, but inside another class so all methods are protected or private. It is used in SCH_BITMAP class, DS_DRAW_ITEM_BITMAP, and possibly others in the future.

Warning
Not all plotters are able to plot a bitmap. Mainly GERBER plotters cannot.

Definition at line 51 of file bitmap_base.h.

Constructor & Destructor Documentation

◆ BITMAP_BASE() [1/2]

BITMAP_BASE::BITMAP_BASE ( const VECTOR2I pos = VECTOR2I( 0, 0 ))

Definition at line 35 of file bitmap_base.cpp.

36{
37 m_scale = 1.0; // 1.0 = original bitmap size
38 m_bitmap = nullptr;
39 m_image = nullptr;
40 m_originalImage = nullptr;
41 m_ppi = 300; // the bitmap definition. the default is 300PPI
42 m_pixelSizeIu = 254000.0 / m_ppi; // a pixel size value OK for bitmaps using 300 PPI
43 // for Eeschema which uses currently 254000PPI
44 m_isMirrored = false;
46}
wxImage * m_originalImage
Definition: bitmap_base.h:244
wxBitmap * m_bitmap
Definition: bitmap_base.h:245
wxImage * m_image
Definition: bitmap_base.h:243
double m_scale
Definition: bitmap_base.h:241
double m_pixelSizeIu
Definition: bitmap_base.h:246
bool m_isMirrored
Definition: bitmap_base.h:252
EDA_ANGLE m_rotation
Definition: bitmap_base.h:253
static constexpr EDA_ANGLE & ANGLE_0
Definition: eda_angle.h:429

References ANGLE_0, m_bitmap, m_image, m_isMirrored, m_originalImage, m_pixelSizeIu, m_ppi, m_rotation, and m_scale.

◆ BITMAP_BASE() [2/2]

BITMAP_BASE::BITMAP_BASE ( const BITMAP_BASE aSchBitmap)

Definition at line 49 of file bitmap_base.cpp.

50{
51 m_scale = aSchBitmap.m_scale;
52 m_ppi = aSchBitmap.m_ppi;
53 m_pixelSizeIu = aSchBitmap.m_pixelSizeIu;
54 m_isMirrored = aSchBitmap.m_isMirrored;
55 m_rotation = aSchBitmap.m_rotation;
56
57 m_image = nullptr;
58 m_bitmap = nullptr;
59 m_originalImage = nullptr;
60
61 if( aSchBitmap.m_image )
62 {
63 m_image = new wxImage( *aSchBitmap.m_image );
64 m_bitmap = new wxBitmap( *m_image );
65 m_originalImage = new wxImage( *aSchBitmap.m_originalImage );
66 m_imageId = aSchBitmap.m_imageId;
67 }
68}
KIID m_imageId
Definition: bitmap_base.h:251

References m_bitmap, m_image, m_imageId, m_isMirrored, m_originalImage, m_pixelSizeIu, m_ppi, m_rotation, and m_scale.

◆ ~BITMAP_BASE()

BITMAP_BASE::~BITMAP_BASE ( )
inline

Definition at line 58 of file bitmap_base.h.

59 {
60 delete m_bitmap;
61 delete m_image;
62 delete m_originalImage;
63 }

References m_bitmap, m_image, and m_originalImage.

Member Function Documentation

◆ ConvertToGreyscale()

void BITMAP_BASE::ConvertToGreyscale ( )

Definition at line 421 of file bitmap_base.cpp.

422{
423 if( m_image )
424 {
425 *m_image = m_image->ConvertToGreyscale();
426 *m_originalImage = m_originalImage->ConvertToGreyscale();
428 }
429}
void rebuildBitmap(bool aResetID=true)
Definition: bitmap_base.cpp:82

References m_image, m_originalImage, and rebuildBitmap().

Referenced by PANEL_IMAGE_EDITOR::OnGreyScaleConvert().

◆ DrawBitmap()

void BITMAP_BASE::DrawBitmap ( wxDC *  aDC,
const VECTOR2I aPos 
)

Definition at line 281 of file bitmap_base.cpp.

282{
283 if( m_bitmap == nullptr )
284 return;
285
286 VECTOR2I pos = aPos;
287 VECTOR2I size = GetSize();
288
289 // This fixes a bug in OSX that should be fixed in the 3.0.3 version or later.
290 if( ( size.x == 0 ) || ( size.y == 0 ) )
291 return;
292
293 // To draw the bitmap, pos is the upper left corner position
294 pos.x -= size.x / 2;
295 pos.y -= size.y / 2;
296
297 double scale;
298 int logicalOriginX, logicalOriginY;
299 aDC->GetUserScale( &scale, &scale );
300 aDC->GetLogicalOrigin( &logicalOriginX, &logicalOriginY );
301
302 // We already have issues to draw a bitmap on the wxDC, depending on wxWidgets version.
303 // Now we have an issue on wxWidgets 3.1.6 to fix the clip area
304 // and the bitmap position when using TransformMatrix
305 // So for version == 3.1.6 do not use it
306 // Be carefull before changing the code.
307 bool useTransform = aDC->CanUseTransformMatrix();
308
309 #if wxCHECK_VERSION( 3, 1, 6 ) && !wxCHECK_VERSION( 3, 1, 7 )
310 useTransform = false;
311 #endif
312
313 wxAffineMatrix2D init_matrix = aDC->GetTransformMatrix();
314
315 // Note: clipping bitmap area was made to fix a minor issue in old versions of
316 // Kicad/wxWidgets (5.1 / wx 3.0)
317 // However SetClippingRegion creates a lot of issues (different ways to fix the
318 // position and size of the area, depending on wxWidget version)because it changes with
319 // each versions of wxWigets, so it is now disabled
320 // However the code is still here, just in case
321 // #define USE_CLIP_AREA
322
323 wxPoint clipAreaPos;
324
325 if( useTransform )
326 {
327 wxAffineMatrix2D matrix = aDC->GetTransformMatrix();
328 matrix.Translate( pos.x, pos.y );
329 matrix.Scale( GetScalingFactor(), GetScalingFactor() );
330 aDC->SetTransformMatrix( matrix );
331 // Needed on wx <= 3.1.5, and this is strange...
332 // Nevertheless, this code has problem (the bitmap is not seen)
333 // with wx version > 3.1.5
334 clipAreaPos.x = pos.x;
335 clipAreaPos.y = pos.y;
336
337 pos.x = pos.y = 0;
338 }
339 else
340 {
341 aDC->SetUserScale( scale * GetScalingFactor(), scale * GetScalingFactor() );
342 aDC->SetLogicalOrigin( logicalOriginX / GetScalingFactor(),
343 logicalOriginY / GetScalingFactor() );
344
345 pos.x = KiROUND( pos.x / GetScalingFactor() );
346 pos.y = KiROUND( pos.y / GetScalingFactor() );
347 size.x = KiROUND( size.x / GetScalingFactor() );
348 size.y = KiROUND( size.y / GetScalingFactor() );
349 clipAreaPos.x = pos.x;
350 clipAreaPos.y = pos.y;
351 }
352
353 #ifdef USE_CLIP_AREA
354 aDC->DestroyClippingRegion();
355 aDC->SetClippingRegion( clipAreaPos, wxSize( size.x, size.y ) );
356 #endif
357
359 {
360 wxBitmap result( m_bitmap->ConvertToImage().ConvertToGreyscale() );
361 aDC->DrawBitmap( result, pos.x, pos.y, true );
362 }
363 else
364 {
365 aDC->DrawBitmap( *m_bitmap, pos.x, pos.y, true );
366 }
367
368 if( useTransform )
369 aDC->SetTransformMatrix( init_matrix );
370 else
371 {
372 aDC->SetUserScale( scale, scale );
373 aDC->SetLogicalOrigin( logicalOriginX, logicalOriginY );
374 }
375
376 #ifdef USE_CLIP_AREA
377 aDC->DestroyClippingRegion();
378 #endif
379}
double GetScalingFactor() const
This scaling factor depends on m_pixelSizeIu and m_scale.
Definition: bitmap_base.h:99
VECTOR2I GetSize() const
bool GetGRForceBlackPenState(void)
Definition: gr_basic.cpp:165
const int scale
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85

References GetGRForceBlackPenState(), GetScalingFactor(), GetSize(), KiROUND(), m_bitmap, scale, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PANEL_IMAGE_EDITOR::OnRedrawPanel(), SCH_BITMAP::Print(), and DS_DRAW_ITEM_BITMAP::PrintWsItem().

◆ GetBoundingBox()

const BOX2I BITMAP_BASE::GetBoundingBox ( ) const

Return the orthogonal, bounding box of this object for display purposes.

This box should be an enclosing perimeter for visible components of this object, and the units should be in the pcb or schematic coordinate system. It is OK to overestimate the size by a few counts.

Definition at line 270 of file bitmap_base.cpp.

271{
272 BOX2I bbox;
273 VECTOR2I size = GetSize();
274
275 bbox.Inflate( size.x / 2, size.y / 2 );
276
277 return bbox;
278}
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:506

References GetSize(), BOX2< Vec >::Inflate(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BOOST_AUTO_TEST_CASE(), and SCH_BITMAP::GetBoundingBox().

◆ GetImageData() [1/2]

wxImage * BITMAP_BASE::GetImageData ( )
inline

◆ GetImageData() [2/2]

const wxImage * BITMAP_BASE::GetImageData ( ) const
inline

Definition at line 72 of file bitmap_base.h.

72{ return m_image; }

References m_image.

◆ GetImageID()

KIID BITMAP_BASE::GetImageID ( ) const
inline

Definition at line 81 of file bitmap_base.h.

81{ return m_imageId; }

References m_imageId.

Referenced by KIGFX::GL_BITMAP_CACHE::cacheBitmap(), and KIGFX::GL_BITMAP_CACHE::RequestBitmap().

◆ GetOriginalImageData()

const wxImage * BITMAP_BASE::GetOriginalImageData ( ) const
inline

◆ GetPixelSizeIu()

double BITMAP_BASE::GetPixelSizeIu ( ) const
inline

Definition at line 68 of file bitmap_base.h.

68{ return m_pixelSizeIu; }

References m_pixelSizeIu.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetPPI()

◆ GetScale()

◆ GetScalingFactor()

double BITMAP_BASE::GetScalingFactor ( ) const
inline

This scaling factor depends on m_pixelSizeIu and m_scale.

m_pixelSizeIu gives the scaling factor between a pixel size and the internal units. m_scale is an user dependent value, and gives the "zoom" value.

  • m_scale = 1.0 = original size of bitmap.
  • m_scale < 1.0 = the bitmap is drawn smaller than its original size.
  • m_scale > 1.0 = the bitmap is drawn bigger than its original size.
Returns
The scaling factor from pixel size to actual draw size.

Definition at line 99 of file bitmap_base.h.

100 {
101 return m_pixelSizeIu * m_scale;
102 }

References m_pixelSizeIu, and m_scale.

Referenced by DrawBitmap(), GetSize(), PANEL_IMAGE_EDITOR::OnRedrawPanel(), and PlotImage().

◆ GetSize()

VECTOR2I BITMAP_BASE::GetSize ( ) const
Returns
the actual size (in user units, not in pixels) of the image

Definition at line 382 of file bitmap_base.cpp.

383{
384 VECTOR2I size;
385
386 if( m_bitmap )
387 {
388 size.x = m_bitmap->GetWidth();
389 size.y = m_bitmap->GetHeight();
390
391 size.x = KiROUND( size.x * GetScalingFactor() );
392 size.y = KiROUND( size.y * GetScalingFactor() );
393 }
394
395 return size;
396}

References GetScalingFactor(), KiROUND(), m_bitmap, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BOOST_AUTO_TEST_CASE(), DrawBitmap(), GetBoundingBox(), DS_DRAW_ITEM_BITMAP::GetBoundingBox(), PCB_BITMAP::GetBoundingBox(), SCH_BITMAP::GetSize(), and PCB_BITMAP::GetSize().

◆ GetSizePixels()

VECTOR2I BITMAP_BASE::GetSizePixels ( ) const
inline
Returns
the size in pixels of the image

Definition at line 112 of file bitmap_base.h.

113 {
114 if( m_image )
115 return VECTOR2I( m_image->GetWidth(), m_image->GetHeight() );
116 else
117 return VECTOR2I( 0, 0 );
118 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590

References m_image.

Referenced by BOOST_AUTO_TEST_CASE(), PANEL_IMAGE_EDITOR::CheckValues(), KIGFX::CAIRO_GAL_BASE::DrawBitmap(), and KIGFX::OPENGL_GAL::DrawBitmap().

◆ ImportData()

void BITMAP_BASE::ImportData ( BITMAP_BASE aItem)

Copy aItem image to this object and update m_bitmap.

Definition at line 109 of file bitmap_base.cpp.

110{
111 *m_image = *aItem->m_image;
112 *m_bitmap = *aItem->m_bitmap;
114 m_imageId = aItem->m_imageId;
115 m_scale = aItem->m_scale;
116 m_ppi = aItem->m_ppi;
118 m_isMirrored = aItem->m_isMirrored;
119 m_rotation = aItem->m_rotation;
120}

References m_bitmap, m_image, m_imageId, m_isMirrored, m_originalImage, m_pixelSizeIu, m_ppi, m_rotation, and m_scale.

Referenced by PANEL_IMAGE_EDITOR::TransferToImage().

◆ IsMirrored()

bool BITMAP_BASE::IsMirrored ( ) const
inline

Definition at line 213 of file bitmap_base.h.

213{ return m_isMirrored; }

References m_isMirrored.

Referenced by KIGFX::OPENGL_GAL::DrawBitmap().

◆ LoadData()

bool BITMAP_BASE::LoadData ( LINE_READER aLine,
wxString &  aErrorMsg 
)

Load an image data saved by SaveData.

The file format must be png format in hexadecimal.

Parameters
aLinethe LINE_READER used to read the data file.
aErrorMsgDescription of the error if an error occurs while loading the png bitmap data.
Returns
true if the bitmap loaded successfully.

Definition at line 223 of file bitmap_base.cpp.

224{
225 wxMemoryOutputStream stream;
226 char* line;
227
228 while( true )
229 {
230 if( !aLine.ReadLine() )
231 {
232 aErrorMsg = wxT("Unexpected end of data");
233 return false;
234 }
235
236 line = aLine.Line();
237
238 if( strncasecmp( line, "EndData", 4 ) == 0 )
239 {
240 // all the PNG date is read.
241 // We expect here m_image and m_bitmap are void
242 m_image = new wxImage();
243 wxMemoryInputStream istream( stream );
244 m_image->LoadFile( istream, wxBITMAP_TYPE_PNG );
245 m_bitmap = new wxBitmap( *m_image );
246 m_originalImage = new wxImage( *m_image );
247 break;
248 }
249
250 // Read PNG data, stored in hexadecimal,
251 // each byte = 2 hexadecimal digits and a space between 2 bytes
252 // and put it in memory stream buffer
253 int len = strlen( line );
254
255 for( ; len > 0; len -= 3, line += 3 )
256 {
257 int value = 0;
258
259 if( sscanf( line, "%X", &value ) == 1 )
260 stream.PutC( (char) value );
261 else
262 break;
263 }
264 }
265
266 return true;
267}
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117

References LINE_READER::Line(), m_bitmap, m_image, m_originalImage, and LINE_READER::ReadLine().

Referenced by DRAWING_SHEET_PARSER::readPngdata().

◆ Mirror()

void BITMAP_BASE::Mirror ( bool  aVertically)

Mirror image vertically (i.e.

relative to its horizontal X axis ) or horizontally (i.e relative to its vertical Y axis).

Parameters
aVerticallyfalse to mirror horizontally or true to mirror vertically.

Definition at line 399 of file bitmap_base.cpp.

400{
401 if( m_image )
402 {
403 *m_image = m_image->Mirror( not aVertically );
405 rebuildBitmap( false );
406 }
407}

References m_image, m_isMirrored, and rebuildBitmap().

Referenced by PCB_BITMAP::Flip(), SCH_BITMAP::MirrorHorizontally(), and SCH_BITMAP::MirrorVertically().

◆ PlotImage()

void BITMAP_BASE::PlotImage ( PLOTTER aPlotter,
const VECTOR2I aPos,
const KIGFX::COLOR4D aDefaultColor,
int  aDefaultPensize 
) const

Plot bitmap on plotter.

If the plotter does not support bitmaps, plot a

Parameters
aPlotterthe plotter to use.
aPosthe position of the center of the bitmap.
aDefaultColorthe color used to plot the rectangle when bitmap is not supported.
aDefaultPensizethe pen size used to plot the rectangle when bitmap is not supported.

Definition at line 432 of file bitmap_base.cpp.

435{
436 if( m_image == nullptr )
437 return;
438
439 // These 2 lines are useful only for plotters that cannot plot a bitmap
440 // and plot a rectangle instead of.
441 aPlotter->SetColor( aDefaultColor );
442 aPlotter->SetCurrentLineWidth( aDefaultPensize );
443 aPlotter->PlotImage( *m_image, aPos, GetScalingFactor() );
444}
virtual void PlotImage(const wxImage &aImage, const VECTOR2I &aPos, double aScaleFactor)
Only PostScript plotters can plot bitmaps.
Definition: plotter.cpp:254
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
virtual void SetColor(const COLOR4D &color)=0

References GetScalingFactor(), m_image, PLOTTER::PlotImage(), PLOTTER::SetColor(), and PLOTTER::SetCurrentLineWidth().

Referenced by SCH_BITMAP::Plot(), and PlotDrawingSheet().

◆ ReadImageFile() [1/2]

bool BITMAP_BASE::ReadImageFile ( const wxString &  aFullFilename)

Reads and stores in memory an image file.

Initialize the bitmap format used to draw this item. Supported images formats are format supported by wxImage if all handlers are loaded. By default, .png, .jpeg are always loaded.

Parameters
aFullFilenameThe full filename of the image file to read.
Returns
true if success reading else false.

Definition at line 141 of file bitmap_base.cpp.

142{
143 wxImage* new_image = new wxImage();
144
145 if( !new_image->LoadFile( aFullFilename ) )
146 {
147 delete new_image;
148 return false;
149 }
150
151 delete m_image;
152 m_image = new_image;
153 delete m_originalImage;
154 m_originalImage = new wxImage( *m_image );
156 updatePPI();
157
158 return true;
159}
void updatePPI()
Definition: bitmap_base.cpp:94

References m_image, m_originalImage, rebuildBitmap(), and updatePPI().

Referenced by SCH_BITMAP::ReadImageFile(), PCB_BITMAP::ReadImageFile(), and TEST_BITMAP_BASE_FIXTURE::TEST_BITMAP_BASE_FIXTURE().

◆ ReadImageFile() [2/2]

bool BITMAP_BASE::ReadImageFile ( wxInputStream &  aInStream)

Reads and stores in memory an image file.

Initialize the bitmap format used to draw this item.

Supported images formats are format supported by wxImage if all handlers are loaded. By default, .png, .jpeg are always loaded.

Parameters
aInStreaman input stream containing the file data.
Returns
true if success reading else false.

Definition at line 123 of file bitmap_base.cpp.

124{
125 std::unique_ptr<wxImage> new_image = std::make_unique<wxImage>();
126
127 if( !new_image->LoadFile( aInStream ) )
128 return false;
129
130 delete m_image;
131 m_image = new_image.release();
132 delete m_originalImage;
133 m_originalImage = new wxImage( *m_image );
135 updatePPI();
136
137 return true;
138}

References m_image, m_originalImage, rebuildBitmap(), and updatePPI().

◆ rebuildBitmap()

void BITMAP_BASE::rebuildBitmap ( bool  aResetID = true)
private

Definition at line 82 of file bitmap_base.cpp.

83{
84 if( m_bitmap )
85 delete m_bitmap;
86
87 m_bitmap = new wxBitmap( *m_image );
88
89 if( aResetID )
90 m_imageId = KIID();
91}
Definition: kiid.h:48

References m_bitmap, m_image, and m_imageId.

Referenced by ConvertToGreyscale(), Mirror(), ReadImageFile(), Rotate(), and SetImage().

◆ Rotate()

void BITMAP_BASE::Rotate ( bool  aRotateCCW)

Rotate image CW or CCW.

Parameters
aRotateCCWtrue to rotate CCW or false to rotate CW.

Definition at line 410 of file bitmap_base.cpp.

411{
412 if( m_image )
413 {
414 *m_image = m_image->Rotate90( aRotateCCW );
415 m_rotation += ( aRotateCCW ? -ANGLE_90 : ANGLE_90 );
416 rebuildBitmap( false );
417 }
418}
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:431

References ANGLE_90, m_image, m_rotation, and rebuildBitmap().

Referenced by SCH_BITMAP::Rotate(), and PCB_BITMAP::Rotate().

◆ Rotation()

EDA_ANGLE BITMAP_BASE::Rotation ( ) const
inline

Definition at line 214 of file bitmap_base.h.

214{ return m_rotation; }

References m_rotation.

Referenced by KIGFX::OPENGL_GAL::DrawBitmap().

◆ SaveData() [1/2]

bool BITMAP_BASE::SaveData ( FILE *  aFile) const

Write the bitmap data to aFile.

The file format is png, in hexadecimal form. If the hexadecimal data is converted to binary it gives exactly a .png image data.

Parameters
aFileThe FILE to write to.
Returns
true if success writing else false.

Definition at line 162 of file bitmap_base.cpp.

163{
164 if( m_image )
165 {
166 wxMemoryOutputStream stream;
167 m_image->SaveFile( stream, wxBITMAP_TYPE_PNG );
168
169 // Write binary data in hexadecimal form (ASCII)
170 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
171 char* begin = (char*) buffer->GetBufferStart();
172
173 for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
174 {
175 if( ii >= 32 )
176 {
177 ii = 0;
178
179 if( fprintf( aFile, "\n" ) == EOF )
180 return false;
181 }
182
183 if( fprintf( aFile, "%2.2X ", *begin & 0xFF ) == EOF )
184 return false;
185 }
186 }
187
188 return true;
189}

References m_image.

Referenced by DS_DATA_MODEL_IO::format().

◆ SaveData() [2/2]

void BITMAP_BASE::SaveData ( wxArrayString &  aPngStrings) const

Write the bitmap data to an array string.

The format is png, in Hexadecimal form. If the hexadecimal data is converted to binary it gives exactly a .png image data.

Parameters
aPngStringsThe wxArrayString to write to.

Definition at line 192 of file bitmap_base.cpp.

193{
194 if( m_image )
195 {
196 wxMemoryOutputStream stream;
197 m_image->SaveFile( stream, wxBITMAP_TYPE_PNG );
198
199 // Write binary data in hexadecimal form (ASCII)
200 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
201 char* begin = (char*) buffer->GetBufferStart();
202 wxString line;
203
204 for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
205 {
206 if( ii >= 32 )
207 {
208 ii = 0;
209 aPngStrings.Add( line );
210 line.Empty();
211 }
212
213 line << wxString::Format( wxT( "%2.2X " ), *begin & 0xFF );
214 }
215
216 // Add last line:
217 if( !line.IsEmpty() )
218 aPngStrings.Add( line );
219 }
220}
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References Format(), and m_image.

◆ SetImage()

void BITMAP_BASE::SetImage ( wxImage *  aImage)

Definition at line 71 of file bitmap_base.cpp.

72{
73 delete m_image;
74 m_image = aImage;
75 delete m_originalImage;
76 m_originalImage = new wxImage( *aImage );
78 updatePPI();
79}

References m_image, m_originalImage, rebuildBitmap(), and updatePPI().

Referenced by SCH_BITMAP::SetImage(), and PCB_BITMAP::SetImage().

◆ SetPixelSizeIu()

◆ SetScale()

◆ updatePPI()

void BITMAP_BASE::updatePPI ( )
private

Definition at line 94 of file bitmap_base.cpp.

95{
96 // Todo: eventually we need to support dpi / scaling in both dimensions
97 int dpiX = m_originalImage->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
98
99 if( dpiX > 1 )
100 {
101 if( m_originalImage->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT ) == wxIMAGE_RESOLUTION_CM )
102 m_ppi = KiROUND( dpiX * 2.54 );
103 else
104 m_ppi = dpiX;
105 }
106}

References KiROUND(), m_originalImage, and m_ppi.

Referenced by ReadImageFile(), and SetImage().

Member Data Documentation

◆ m_bitmap

wxBitmap* BITMAP_BASE::m_bitmap
private

◆ m_image

◆ m_imageId

KIID BITMAP_BASE::m_imageId
private

Definition at line 251 of file bitmap_base.h.

Referenced by BITMAP_BASE(), GetImageID(), ImportData(), and rebuildBitmap().

◆ m_isMirrored

bool BITMAP_BASE::m_isMirrored
private

Definition at line 252 of file bitmap_base.h.

Referenced by BITMAP_BASE(), ImportData(), IsMirrored(), and Mirror().

◆ m_originalImage

wxImage* BITMAP_BASE::m_originalImage
private

◆ m_pixelSizeIu

double BITMAP_BASE::m_pixelSizeIu
private

◆ m_ppi

int BITMAP_BASE::m_ppi
private

Definition at line 250 of file bitmap_base.h.

Referenced by BITMAP_BASE(), GetPPI(), ImportData(), and updatePPI().

◆ m_rotation

EDA_ANGLE BITMAP_BASE::m_rotation
private

Definition at line 253 of file bitmap_base.h.

Referenced by BITMAP_BASE(), ImportData(), Rotate(), and Rotation().

◆ m_scale

double BITMAP_BASE::m_scale
private

Definition at line 241 of file bitmap_base.h.

Referenced by BITMAP_BASE(), GetScale(), GetScalingFactor(), ImportData(), and SetScale().


The documentation for this class was generated from the following files: