32#include <wx/mstream.h>
103 if(
m_originalImage->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT ) == wxIMAGE_RESOLUTION_CM )
128 std::unique_ptr<wxImage> new_image = std::make_unique<wxImage>();
130 if( !new_image->LoadFile( aInStream ) )
146 wxImage* new_image =
new wxImage();
148 if( !new_image->LoadFile( aFullFilename ) )
169 wxMemoryOutputStream stream;
170 m_image->SaveFile( stream, wxBITMAP_TYPE_PNG );
173 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
174 char* begin = (
char*) buffer->GetBufferStart();
176 for(
int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
182 if( fprintf( aFile,
"\n" ) == EOF )
186 if( fprintf( aFile,
"%2.2X ", *begin & 0xFF ) == EOF )
199 wxMemoryOutputStream stream;
200 m_image->SaveFile( stream, wxBITMAP_TYPE_PNG );
203 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
204 char* begin = (
char*) buffer->GetBufferStart();
207 for(
int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
212 aPngStrings.Add( line );
216 line << wxString::Format( wxT(
"%2.2X " ), *begin & 0xFF );
220 if( !line.IsEmpty() )
221 aPngStrings.Add( line );
228 wxMemoryOutputStream stream;
235 aErrorMsg = wxT(
"Unexpected end of data");
241 if( strncasecmp( line,
"EndData", 4 ) == 0 )
246 wxMemoryInputStream istream( stream );
247 m_image->LoadFile( istream, wxBITMAP_TYPE_PNG );
256 int len = strlen( line );
258 for( ; len > 0; len -= 3, line += 3 )
262 if( sscanf( line,
"%X", &value ) == 1 )
263 stream.PutC( (
char) value );
293 if( ( size.
x == 0 ) || ( size.
y == 0 ) )
301 int logicalOriginX, logicalOriginY;
303 aDC->GetLogicalOrigin( &logicalOriginX, &logicalOriginY );
310 bool useTransform = aDC->CanUseTransformMatrix();
312 #if wxCHECK_VERSION( 3, 1, 6 ) && !wxCHECK_VERSION( 3, 1, 7 )
313 useTransform =
false;
316 wxAffineMatrix2D init_matrix = aDC->GetTransformMatrix();
330 wxAffineMatrix2D matrix = aDC->GetTransformMatrix();
331 matrix.Translate( pos.
x, pos.
y );
333 aDC->SetTransformMatrix( matrix );
337 clipAreaPos.x = pos.
x;
338 clipAreaPos.y = pos.
y;
352 clipAreaPos.x = pos.
x;
353 clipAreaPos.y = pos.
y;
357 aDC->DestroyClippingRegion();
358 aDC->SetClippingRegion( clipAreaPos, wxSize( size.
x, size.
y ) );
363 wxBitmap result(
m_bitmap->ConvertToImage().ConvertToGreyscale() );
364 aDC->DrawBitmap( result, pos.
x, pos.
y,
true );
368 aDC->DrawBitmap( *
m_bitmap, pos.
x, pos.
y,
true );
372 aDC->SetTransformMatrix( init_matrix );
376 aDC->SetLogicalOrigin( logicalOriginX, logicalOriginY );
380 aDC->DestroyClippingRegion();
410 int resX =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
411 int resY =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY );
412 int unit =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT );
416 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONUNIT , unit);
417 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONX, resX);
418 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONY, resY);
438 int resX =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
439 int resY =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY );
440 int unit =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT );
444 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONUNIT , unit);
445 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONX, resX);
446 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONY, resY);
467 int aDefaultPensize )
const
474 aPlotter->
SetColor( aDefaultColor );
This class handle bitmap images in KiCad.
void Rotate(bool aRotateCCW)
Rotate image CW or CCW.
double GetScalingFactor() const
This scaling factor depends on m_pixelSizeIu and m_scale.
bool SaveData(FILE *aFile) const
Write the bitmap data to aFile.
void PlotImage(PLOTTER *aPlotter, const VECTOR2I &aPos, const KIGFX::COLOR4D &aDefaultColor, int aDefaultPensize) const
Plot bitmap on plotter.
const BOX2I GetBoundingBox() const
Return the orthogonal, bounding box of this object for display purposes.
void Mirror(bool aVertically)
Mirror image vertically (i.e.
wxImage * m_originalImage
void rebuildBitmap(bool aResetID=true)
void ImportData(BITMAP_BASE *aItem)
Copy aItem image to this object and update m_bitmap.
void ConvertToGreyscale()
void DrawBitmap(wxDC *aDC, const VECTOR2I &aPos)
void SetImage(wxImage *aImage)
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores in memory an image file.
bool LoadData(LINE_READER &aLine, wxString &aErrorMsg)
Load an image data saved by SaveData.
BITMAP_BASE(const VECTOR2I &pos=VECTOR2I(0, 0))
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
A color representation with 4 components: red, green, blue, alpha.
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
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.
Base plotter engine class.
virtual void PlotImage(const wxImage &aImage, const VECTOR2I &aPos, double aScaleFactor)
Only PostScript plotters can plot bitmaps.
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
virtual void SetColor(const COLOR4D &color)=0
static constexpr EDA_ANGLE & ANGLE_90
static constexpr EDA_ANGLE & ANGLE_0
bool GetGRForceBlackPenState(void)
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".