KiCad PCB EDA Suite
IMAGE_SIZE Class Reference

#include <bitmap2cmp_gui.h>

Public Member Functions

 IMAGE_SIZE ()
 
void SetUnit (EDA_UNITS aUnit)
 
void SetOriginalDPI (int aDPI)
 
void SetOriginalSizePixels (int aPixels)
 
double GetOutputSize ()
 
void SetOutputSize (double aSize, EDA_UNITS aUnit)
 
int GetOriginalSizePixels ()
 
void SetOutputSizeFromInitialImageSize ()
 
int GetOutputDPI ()
 

Private Attributes

EDA_UNITS m_unit
 
double m_outputSize
 
int m_originalDPI
 
int m_originalSizePixels
 

Detailed Description

Definition at line 33 of file bitmap2cmp_gui.h.

Constructor & Destructor Documentation

◆ IMAGE_SIZE()

IMAGE_SIZE::IMAGE_SIZE ( )

Definition at line 44 of file bitmap2cmp_gui.cpp.

45 {
46  m_outputSize = 0.0;
50 }
EDA_UNITS m_unit
int m_originalSizePixels
#define DEFAULT_DPI
double m_outputSize

References DEFAULT_DPI, m_originalDPI, m_originalSizePixels, m_outputSize, m_unit, and MILLIMETRES.

Member Function Documentation

◆ GetOriginalSizePixels()

int IMAGE_SIZE::GetOriginalSizePixels ( )
inline

Definition at line 64 of file bitmap2cmp_gui.h.

65  {
66  return m_originalSizePixels;
67  }
int m_originalSizePixels

References m_originalSizePixels.

Referenced by GetOutputDPI(), and SetOutputSizeFromInitialImageSize().

◆ GetOutputDPI()

int IMAGE_SIZE::GetOutputDPI ( )
Returns
the pixels per inch value to build the output image. It is used by potrace to build the polygonal image

Definition at line 75 of file bitmap2cmp_gui.cpp.

76 {
77  int outputDPI;
78 
80  {
81  outputDPI = GetOriginalSizePixels() / ( m_outputSize / 25.4 );
82  }
83  else if( m_unit == EDA_UNITS::INCHES )
84  {
85  outputDPI = GetOriginalSizePixels() / m_outputSize;
86  }
87  else
88  {
89  outputDPI = KiROUND( m_outputSize );
90  }
91 
92  // Zero is not a DPI, and may cause divide-by-zero errors...
93  outputDPI = std::max( 1, outputDPI );
94 
95  return outputDPI;
96 }
EDA_UNITS m_unit
int GetOriginalSizePixels()
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:68
double m_outputSize

References GetOriginalSizePixels(), INCHES, KiROUND(), m_outputSize, m_unit, and MILLIMETRES.

Referenced by BM2CMP_FRAME::ExportToBuffer().

◆ GetOutputSize()

double IMAGE_SIZE::GetOutputSize ( )
inline

◆ SetOriginalDPI()

void IMAGE_SIZE::SetOriginalDPI ( int  aDPI)
inline

Definition at line 43 of file bitmap2cmp_gui.h.

44  {
45  m_originalDPI = aDPI;
46  }

References m_originalDPI.

Referenced by BM2CMP_FRAME::OpenProjectFiles().

◆ SetOriginalSizePixels()

void IMAGE_SIZE::SetOriginalSizePixels ( int  aPixels)
inline

Definition at line 48 of file bitmap2cmp_gui.h.

49  {
50  m_originalSizePixels = aPixels;
51  }
int m_originalSizePixels

References m_originalSizePixels.

Referenced by BM2CMP_FRAME::OpenProjectFiles().

◆ SetOutputSize()

void IMAGE_SIZE::SetOutputSize ( double  aSize,
EDA_UNITS  aUnit 
)
inline

Definition at line 58 of file bitmap2cmp_gui.h.

59  {
60  m_unit = aUnit;
61  m_outputSize = aSize;
62  }
EDA_UNITS m_unit
double m_outputSize

References m_outputSize, and m_unit.

Referenced by BM2CMP_FRAME::BM2CMP_FRAME(), BM2CMP_FRAME::OnSizeChangeX(), and BM2CMP_FRAME::OnSizeChangeY().

◆ SetOutputSizeFromInitialImageSize()

void IMAGE_SIZE::SetOutputSizeFromInitialImageSize ( )

Definition at line 53 of file bitmap2cmp_gui.cpp.

54 {
55  // Safety-check to guarantee no divide-by-zero
56  m_originalDPI = std::max( 1, m_originalDPI );
57 
58  // Set the m_outputSize value from the m_originalSizePixels and the selected unit
60  {
62  }
63  else if( m_unit == EDA_UNITS::INCHES )
64  {
66  }
67  else
68  {
70  }
71 
72 }
EDA_UNITS m_unit
int GetOriginalSizePixels()
double m_outputSize

References GetOriginalSizePixels(), INCHES, m_originalDPI, m_outputSize, m_unit, and MILLIMETRES.

Referenced by BM2CMP_FRAME::OpenProjectFiles().

◆ SetUnit()

void IMAGE_SIZE::SetUnit ( EDA_UNITS  aUnit)

Definition at line 99 of file bitmap2cmp_gui.cpp.

100 {
101  // Set the unit used for m_outputSize, and convert the old m_outputSize value
102  // to the value in new unit
103  if( aUnit == m_unit )
104  return;
105 
106  // Convert m_outputSize to mm:
107  double size_mm;
108 
110  {
111  size_mm = m_outputSize;
112  }
113  else if( m_unit == EDA_UNITS::INCHES )
114  {
115  size_mm = m_outputSize * 25.4;
116  }
117  else
118  {
119  // m_outputSize is the DPI, not an image size
120  // the image size is m_originalSizePixels / m_outputSize (in inches)
121  if( m_outputSize )
122  size_mm = m_originalSizePixels / m_outputSize * 25.4;
123  else
124  size_mm = 0;
125  }
126 
127  // Convert m_outputSize to new value:
128  if( aUnit == EDA_UNITS::MILLIMETRES )
129  {
130  m_outputSize = size_mm;
131  }
132  else if( aUnit == EDA_UNITS::INCHES )
133  {
134  m_outputSize = size_mm / 25.4;
135  }
136  else
137  {
138  if( size_mm )
139  m_outputSize = m_originalSizePixels / size_mm * 25.4;
140  else
141  m_outputSize = 0;
142  }
143 
144  m_unit = aUnit;
145 }
EDA_UNITS m_unit
int m_originalSizePixels
double m_outputSize

References INCHES, m_originalSizePixels, m_outputSize, m_unit, and MILLIMETRES.

Referenced by BM2CMP_FRAME::BM2CMP_FRAME(), and BM2CMP_FRAME::OnSizeUnitChange().

Member Data Documentation

◆ m_originalDPI

int IMAGE_SIZE::m_originalDPI
private

Definition at line 81 of file bitmap2cmp_gui.h.

Referenced by IMAGE_SIZE(), SetOriginalDPI(), and SetOutputSizeFromInitialImageSize().

◆ m_originalSizePixels

int IMAGE_SIZE::m_originalSizePixels
private

Definition at line 82 of file bitmap2cmp_gui.h.

Referenced by GetOriginalSizePixels(), IMAGE_SIZE(), SetOriginalSizePixels(), and SetUnit().

◆ m_outputSize

double IMAGE_SIZE::m_outputSize
private

◆ m_unit

EDA_UNITS IMAGE_SIZE::m_unit
private

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