36 #include <wx/bitmap.h> 37 #include <wx/mstream.h> 80 auto new_image = std::make_unique<wxImage>();
82 if( !new_image->LoadFile( aInStream ) )
97 wxImage* new_image =
new wxImage();
99 if( !new_image->LoadFile( aFullFilename ) )
117 wxMemoryOutputStream stream;
118 m_image->SaveFile( stream, wxBITMAP_TYPE_PNG );
121 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
122 char* begin = (
char*) buffer->GetBufferStart();
124 for(
int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
130 if( fprintf( aFile,
"\n" ) == EOF )
134 if( fprintf( aFile,
"%2.2X ", *begin & 0xFF ) == EOF )
147 wxMemoryOutputStream stream;
148 m_image->SaveFile( stream, wxBITMAP_TYPE_PNG );
151 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
152 char* begin = (
char*) buffer->GetBufferStart();
155 for(
int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
160 aPngStrings.Add( line );
168 if( !line.IsEmpty() )
169 aPngStrings.Add( line );
176 wxMemoryOutputStream stream;
183 aErrorMsg = wxT(
"Unexpected end of data");
189 if( strncasecmp( line,
"EndData", 4 ) == 0 )
194 wxMemoryInputStream istream( stream );
195 m_image->LoadFile( istream, wxBITMAP_TYPE_PNG );
203 int len = strlen( line );
205 for( ; len > 0; len -= 3, line += 3 )
209 if( sscanf( line,
"%X", &value ) == 1 )
210 stream.PutC( (
char) value );
226 rect.
Inflate( size.x / 2, size.y / 2 );
241 if( ( size.x == 0 ) || ( size.y == 0 ) )
249 int logicalOriginX, logicalOriginY;
251 aDC->GetLogicalOrigin( &logicalOriginX, &logicalOriginY );
253 bool useTransform = aDC->CanUseTransformMatrix();
254 wxAffineMatrix2D init_matrix = aDC->GetTransformMatrix();
260 wxAffineMatrix2D matrix = aDC->GetTransformMatrix();
261 matrix.Translate( pos.x, pos.y );
263 aDC->SetTransformMatrix( matrix );
264 clipAreaPos.x = pos.x;
265 clipAreaPos.y = pos.y;
278 clipAreaPos.x = pos.x;
279 clipAreaPos.y = pos.y;
282 aDC->DestroyClippingRegion();
283 aDC->SetClippingRegion( clipAreaPos, size );
287 wxBitmap result(
m_bitmap->ConvertToImage().ConvertToGreyscale() );
288 aDC->DrawBitmap( result, pos.x, pos.y,
true );
292 aDC->DrawBitmap( *
m_bitmap, pos.x, pos.y,
true );
296 aDC->SetTransformMatrix( init_matrix );
300 aDC->SetLogicalOrigin( logicalOriginX, logicalOriginY );
303 aDC->DestroyClippingRegion();
347 int aDefaultPensize )
const 354 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.
void PlotImage(PLOTTER *aPlotter, const wxPoint &aPos, const KIGFX::COLOR4D &aDefaultColor, int aDefaultPensize) const
Plot bitmap on plotter.
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.
virtual void SetColor(const COLOR4D &color)=0
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.
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)
void Rotate(bool aRotateCCW)
Rotate image CW or CCW.
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
A color representation with 4 components: red, green, blue, alpha.