32#include <wx/mstream.h>
109 std::unique_ptr<wxImage> new_image = std::make_unique<wxImage>();
111 if( !new_image->LoadFile( aInStream ) )
126 wxImage* new_image =
new wxImage();
128 if( !new_image->LoadFile( aFullFilename ) )
141 int dpiX =
m_originalImage->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
145 if(
m_originalImage->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT ) == wxIMAGE_RESOLUTION_CM )
159 wxMemoryOutputStream stream;
160 m_image->SaveFile( stream, wxBITMAP_TYPE_PNG );
163 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
164 char* begin = (
char*) buffer->GetBufferStart();
166 for(
int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
172 if( fprintf( aFile,
"\n" ) == EOF )
176 if( fprintf( aFile,
"%2.2X ", *begin & 0xFF ) == EOF )
189 wxMemoryOutputStream stream;
190 m_image->SaveFile( stream, wxBITMAP_TYPE_PNG );
193 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
194 char* begin = (
char*) buffer->GetBufferStart();
197 for(
int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
202 aPngStrings.Add( line );
210 if( !line.IsEmpty() )
211 aPngStrings.Add( line );
218 wxMemoryOutputStream stream;
225 aErrorMsg = wxT(
"Unexpected end of data");
231 if( strncasecmp( line,
"EndData", 4 ) == 0 )
236 wxMemoryInputStream istream( stream );
237 m_image->LoadFile( istream, wxBITMAP_TYPE_PNG );
246 int len = strlen( line );
248 for( ; len > 0; len -= 3, line += 3 )
252 if( sscanf( line,
"%X", &value ) == 1 )
253 stream.PutC( (
char) value );
283 if( ( size.
x == 0 ) || ( size.
y == 0 ) )
291 int logicalOriginX, logicalOriginY;
293 aDC->GetLogicalOrigin( &logicalOriginX, &logicalOriginY );
300 bool useTransform = aDC->CanUseTransformMatrix();
302 #if wxCHECK_VERSION( 3, 1, 6 ) && !wxCHECK_VERSION( 3, 1, 7 )
303 useTransform =
false;
306 wxAffineMatrix2D init_matrix = aDC->GetTransformMatrix();
320 wxAffineMatrix2D matrix = aDC->GetTransformMatrix();
321 matrix.Translate( pos.
x, pos.
y );
323 aDC->SetTransformMatrix( matrix );
327 clipAreaPos.x = pos.
x;
328 clipAreaPos.y = pos.
y;
342 clipAreaPos.x = pos.
x;
343 clipAreaPos.y = pos.
y;
347 aDC->DestroyClippingRegion();
348 aDC->SetClippingRegion( clipAreaPos, wxSize( size.
x, size.
y ) );
353 wxBitmap result(
m_bitmap->ConvertToImage().ConvertToGreyscale() );
354 aDC->DrawBitmap( result, pos.
x, pos.
y,
true );
358 aDC->DrawBitmap( *
m_bitmap, pos.
x, pos.
y,
true );
362 aDC->SetTransformMatrix( init_matrix );
366 aDC->SetLogicalOrigin( logicalOriginX, logicalOriginY );
370 aDC->DestroyClippingRegion();
427 int aDefaultPensize )
const
434 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)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".