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 49 of file bitmap2cmp_gui.cpp.

50{
51 m_outputSize = 0.0;
55}
#define DEFAULT_DPI
double m_outputSize
EDA_UNITS m_unit
int m_originalSizePixels

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 {
67 }

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 80 of file bitmap2cmp_gui.cpp.

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

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 }

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 }

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 58 of file bitmap2cmp_gui.cpp.

59{
60 // Safety-check to guarantee no divide-by-zero
61 m_originalDPI = std::max( 1, m_originalDPI );
62
63 // Set the m_outputSize value from the m_originalSizePixels and the selected unit
65 {
67 }
68 else if( m_unit == EDA_UNITS::INCHES )
69 {
71 }
72 else
73 {
75 }
76
77}

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 104 of file bitmap2cmp_gui.cpp.

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

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: