KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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
 
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.
 
double GetScalingFactor () const
 This scaling factor depends on m_pixelSizeIu and m_scale.
 
VECTOR2I GetSize () const
 
VECTOR2I GetSizePixels () const
 
int GetPPI () const
 
const BOX2I GetBoundingBox () const
 Return the orthogonal, bounding box of this object for display purposes.
 
void DrawBitmap (wxDC *aDC, const VECTOR2I &aPos, const KIGFX::COLOR4D &aBackgroundColor=KIGFX::COLOR4D::UNSPECIFIED)
 
bool ReadImageFile (const wxString &aFullFilename)
 Reads and stores in memory an image file.
 
bool ReadImageFile (wxInputStream &aInStream)
 Reads and stores in memory an image file.
 
bool ReadImageFile (wxMemoryBuffer &aBuf)
 Reads and stores in memory an image file.
 
bool SaveImageData (wxOutputStream &aOutStream) const
 Write the bitmap data to aOutStream.
 
bool LoadLegacyData (LINE_READER &aLine, wxString &aErrorMsg)
 Load an image data saved by #SaveData.
 
void Mirror (bool aVertically)
 Mirror image vertically (i.e.
 
void Rotate (bool aRotateCCW)
 Rotate image CW or CCW.
 
void ConvertToGreyscale ()
 
bool IsMirroredX () const
 
bool IsMirroredY () const
 
EDA_ANGLE Rotation () const
 
void PlotImage (PLOTTER *aPlotter, const VECTOR2I &aPos, const KIGFX::COLOR4D &aDefaultColor, int aDefaultPensize) const
 Plot bitmap on plotter.
 
wxBitmapType GetImageType () const
 Return the bitmap type (png, jpeg, etc.)
 
void SetImageType (wxBitmapType aType)
 Set the bitmap type (png, jpeg, etc.)
 
const wxMemoryBuffer & GetImageDataBuffer () const
 
void UpdateImageDataBuffer ()
 Resets the image data buffer using the current image data.
 

Private Member Functions

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

Private Attributes

double m_scale
 
wxMemoryBuffer m_imageData
 
wxBitmapType m_imageType
 
wxImage * m_image
 
wxImage * m_originalImage
 
wxBitmap * m_bitmap
 
double m_pixelSizeIu
 
int m_ppi
 
KIID m_imageId
 
bool m_isMirroredX
 
bool m_isMirroredY
 
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 47 of file bitmap_base.h.

Constructor & Destructor Documentation

◆ BITMAP_BASE() [1/2]

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

◆ BITMAP_BASE() [2/2]

BITMAP_BASE::BITMAP_BASE ( const BITMAP_BASE aSchBitmap)

◆ ~BITMAP_BASE()

BITMAP_BASE::~BITMAP_BASE ( )
inline

Definition at line 54 of file bitmap_base.h.

References m_bitmap, m_image, and m_originalImage.

Member Function Documentation

◆ ConvertToGreyscale()

void BITMAP_BASE::ConvertToGreyscale ( )

◆ DrawBitmap()

◆ 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 266 of file bitmap_base.cpp.

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]

◆ GetImageData() [2/2]

const wxImage * BITMAP_BASE::GetImageData ( ) const
inline

Definition at line 68 of file bitmap_base.h.

References m_image.

◆ GetImageDataBuffer()

const wxMemoryBuffer & BITMAP_BASE::GetImageDataBuffer ( ) const
inline
Returns
the image data buffer.

Definition at line 240 of file bitmap_base.h.

References m_imageData.

Referenced by PCB_IO_KICAD_SEXPR::format(), DS_DATA_MODEL_IO::format(), and SCH_IO_KICAD_SEXPR::saveBitmap().

◆ GetImageID()

◆ GetImageType()

wxBitmapType BITMAP_BASE::GetImageType ( ) const
inline

Return the bitmap type (png, jpeg, etc.)

Definition at line 230 of file bitmap_base.h.

References m_imageType.

◆ GetOriginalImageData()

const wxImage * BITMAP_BASE::GetOriginalImageData ( ) const
inline

◆ GetPixelSizeIu()

double BITMAP_BASE::GetPixelSizeIu ( ) const
inline

Definition at line 64 of file bitmap_base.h.

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 93 of file bitmap_base.h.

References m_pixelSizeIu, and m_scale.

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

◆ GetSize()

◆ GetSizePixels()

VECTOR2I BITMAP_BASE::GetSizePixels ( ) const
inline

◆ 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.

References m_bitmap, m_image, m_imageData, m_imageId, m_imageType, m_isMirroredX, m_isMirroredY, m_originalImage, m_pixelSizeIu, m_ppi, m_rotation, and m_scale.

Referenced by PANEL_IMAGE_EDITOR::TransferToImage().

◆ IsMirroredX()

bool BITMAP_BASE::IsMirroredX ( ) const
inline

Definition at line 210 of file bitmap_base.h.

References m_isMirroredX.

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

◆ IsMirroredY()

bool BITMAP_BASE::IsMirroredY ( ) const
inline

Definition at line 211 of file bitmap_base.h.

References m_isMirroredY.

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

◆ LoadLegacyData()

bool BITMAP_BASE::LoadLegacyData ( 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 218 of file bitmap_base.cpp.

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

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 411 of file bitmap_base.cpp.

References m_image, m_isMirroredX, m_isMirroredY, rebuildBitmap(), and UpdateImageDataBuffer().

Referenced by PCB_REFERENCE_IMAGE::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 477 of file bitmap_base.cpp.

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

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

◆ ReadImageFile() [1/3]

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 184 of file bitmap_base.cpp.

References ReadImageFile().

Referenced by DRAWING_SHEET_PARSER::parseBitmap(), SCH_BITMAP::ReadImageFile(), ReadImageFile(), PCB_REFERENCE_IMAGE::ReadImageFile(), and TEST_BITMAP_BASE_FIXTURE::TEST_BITMAP_BASE_FIXTURE().

◆ ReadImageFile() [2/3]

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 126 of file bitmap_base.cpp.

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

◆ ReadImageFile() [3/3]

bool BITMAP_BASE::ReadImageFile ( wxMemoryBuffer &  aBuf)

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
aBufa memory buffer containing the file data.
Returns
true if success reading else false.

Definition at line 156 of file bitmap_base.cpp.

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

◆ rebuildBitmap()

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

Definition at line 81 of file bitmap_base.cpp.

References m_bitmap, m_image, and m_imageId.

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

◆ 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 440 of file bitmap_base.cpp.

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

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

◆ Rotation()

EDA_ANGLE BITMAP_BASE::Rotation ( ) const
inline

Definition at line 212 of file bitmap_base.h.

References m_rotation.

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

◆ SaveImageData()

bool BITMAP_BASE::SaveImageData ( wxOutputStream &  aOutStream) const

Write the bitmap data to aOutStream.

This writes binary data, not hexadecimal strings

Parameters
aOutStreamThe output stream to write to.
Returns
true if success writing else false.

Definition at line 196 of file bitmap_base.cpp.

References m_image, m_imageData, and m_imageType.

◆ SetImageType()

void BITMAP_BASE::SetImageType ( wxBitmapType  aType)
inline

Set the bitmap type (png, jpeg, etc.)

Definition at line 235 of file bitmap_base.h.

References m_imageType.

◆ SetPixelSizeIu()

◆ SetScale()

◆ UpdateImageDataBuffer()

void BITMAP_BASE::UpdateImageDataBuffer ( )

Resets the image data buffer using the current image data.

Definition at line 492 of file bitmap_base.cpp.

References m_image, m_imageData, and m_imageType.

Referenced by ConvertToGreyscale(), LoadLegacyData(), Mirror(), and Rotate().

◆ updatePPI()

void BITMAP_BASE::updatePPI ( )
private

Definition at line 94 of file bitmap_base.cpp.

References KiROUND(), m_originalImage, and m_ppi.

Referenced by ReadImageFile().

Member Data Documentation

◆ m_bitmap

wxBitmap* BITMAP_BASE::m_bitmap
private

◆ m_image

◆ m_imageData

wxMemoryBuffer BITMAP_BASE::m_imageData
private

◆ m_imageId

KIID BITMAP_BASE::m_imageId
private

Definition at line 272 of file bitmap_base.h.

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

◆ m_imageType

wxBitmapType BITMAP_BASE::m_imageType
private

◆ m_isMirroredX

bool BITMAP_BASE::m_isMirroredX
private

Definition at line 273 of file bitmap_base.h.

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

◆ m_isMirroredY

bool BITMAP_BASE::m_isMirroredY
private

Definition at line 274 of file bitmap_base.h.

Referenced by BITMAP_BASE(), ImportData(), IsMirroredY(), 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 271 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 275 of file bitmap_base.h.

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

◆ m_scale

double BITMAP_BASE::m_scale
private

Definition at line 259 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: