37 #include <wx/bitmap.h> 38 #include <wx/mstream.h> 89 auto new_image = std::make_unique<wxImage>();
91 if( !new_image->LoadFile( aInStream ) )
106 wxImage* new_image =
new wxImage();
108 if( !new_image->LoadFile( aFullFilename ) )
126 wxMemoryOutputStream stream;
127 m_image->SaveFile( stream, wxBITMAP_TYPE_PNG );
130 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
131 char* begin = (
char*) buffer->GetBufferStart();
133 for(
int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
139 if( fprintf( aFile,
"\n" ) == EOF )
143 if( fprintf( aFile,
"%2.2X ", *begin & 0xFF ) == EOF )
156 wxMemoryOutputStream stream;
157 m_image->SaveFile( stream, wxBITMAP_TYPE_PNG );
160 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
161 char* begin = (
char*) buffer->GetBufferStart();
164 for(
int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
169 aPngStrings.Add( line );
177 if( !line.IsEmpty() )
178 aPngStrings.Add( line );
185 wxMemoryOutputStream stream;
192 aErrorMsg = wxT(
"Unexpected end of data");
198 if( strncasecmp( line,
"EndData", 4 ) == 0 )
203 wxMemoryInputStream istream( stream );
204 m_image->LoadFile( istream, wxBITMAP_TYPE_PNG );
212 int len = strlen( line );
214 for( ; len > 0; len -= 3, line += 3 )
218 if( sscanf( line,
"%X", &value ) == 1 )
219 stream.PutC( (
char) value );
235 rect.
Inflate( size.x / 2, size.y / 2 );
250 if( ( size.x == 0 ) || ( size.y == 0 ) )
258 int logicalOriginX, logicalOriginY;
260 aDC->GetLogicalOrigin( &logicalOriginX, &logicalOriginY );
262 bool useTransform = aDC->CanUseTransformMatrix();
263 wxAffineMatrix2D init_matrix = aDC->GetTransformMatrix();
267 wxAffineMatrix2D matrix = aDC->GetTransformMatrix();
268 matrix.Translate( pos.x, pos.y );
270 aDC->SetTransformMatrix( matrix );
285 wxBitmap result(
m_bitmap->ConvertToImage().ConvertToGreyscale() );
286 aDC->DrawBitmap( result, pos.x, pos.y,
true );
290 aDC->DrawBitmap( *
m_bitmap, pos.x, pos.y,
true );
294 aDC->SetTransformMatrix( init_matrix );
298 aDC->SetLogicalOrigin( logicalOriginX, logicalOriginY );
343 int aDefaultPensize )
350 aPlotter->
SetColor( aDefaultColor );
double GetScalingFactor() const
This scaling factor depends on m_pixelSizeIu and m_scale.
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
BITMAP_BASE(const wxPoint &pos=wxPoint(0, 0))
char * Line() const
Return a pointer to the last line that was read in.
bool SaveData(FILE *aFile) const
Write the bitmap data to aFile.
virtual void SetColor(COLOR4D color)=0
void Mirror(bool aVertically)
Mirror image vertically (i.e.
const EDA_RECT GetBoundingBox() const
Return the orthogonal, bounding box of this object for display purposes.
This class handle bitmap images in KiCad.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Base plotter engine class.
virtual void PlotImage(const wxImage &aImage, const wxPoint &aPos, double aScaleFactor)
Only PostScript plotters can plot bitmaps.
void ImportData(BITMAP_BASE *aItem)
Copy aItem image to this object and update m_bitmap.
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
void PlotImage(PLOTTER *aPlotter, const wxPoint &aPos, KIGFX::COLOR4D aDefaultColor, int aDefaultPensize)
Plot bitmap on plotter.
Handle the component boundary box.
bool LoadData(LINE_READER &aLine, wxString &aErrorMsg)
Load an image data saved by SaveData.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
void DrawBitmap(wxDC *aDC, const wxPoint &aPos)
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores in memory an image file.
bool GetGRForceBlackPenState(void)
Function GetGRForceBlackPenState.
void Rotate(bool aRotateCCW)
Rotate image CW or CCW.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
A color representation with 4 components: red, green, blue, alpha.