32#include <wx/mstream.h>
35#include <wx/wfstream.h>
101 if(
m_originalImage->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT ) == wxIMAGE_RESOLUTION_CM )
129 size_t dataSize = aInStream.GetLength();
134 std::unique_ptr<wxImage> new_image = std::make_unique<wxImage>();
137 wxMemoryInputStream mem_stream(
m_imageData.GetData(), dataSize );
138 if( !new_image->LoadFile( mem_stream ) )
161 std::unique_ptr<wxImage> new_image = std::make_unique<wxImage>();
166 if( !new_image->LoadFile( mem_stream ) )
186 wxFileInputStream file_stream(aFullFilename);
189 if (!file_stream.IsOk())
201 wxBitmapType type =
m_imageType == wxBITMAP_TYPE_JPEG ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG;
203 if( !
m_image->SaveFile( aOutStream, type ) )
220 wxMemoryOutputStream stream;
227 aErrorMsg = wxT(
"Unexpected end of data");
233 if( strncasecmp( line,
"EndData", 4 ) == 0 )
238 wxMemoryInputStream istream( stream );
239 m_image->LoadFile( istream, wxBITMAP_TYPE_ANY );
249 int len = strlen( line );
251 for( ; len > 0; len -= 3, line += 3 )
255 if( sscanf( line,
"%X", &value ) == 1 )
256 stream.PutC( (
char) value );
287 if( ( size.
x == 0 ) || ( size.
y == 0 ) )
295 int logicalOriginX, logicalOriginY;
297 aDC->GetLogicalOrigin( &logicalOriginX, &logicalOriginY );
304 bool useTransform = aDC->CanUseTransformMatrix();
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 ) );
351 if( aBackgroundColor != COLOR4D::UNSPECIFIED &&
m_bitmap->HasAlpha() )
359 wxImage
image( w, h );
360 wxColour bgColor = aBackgroundColor.
ToColour();
362 image.SetRGB( wxRect( 0, 0, w, h ), bgColor.Red(), bgColor.Green(), bgColor.Blue() );
363 image.Paste(
m_bitmap->ConvertToImage(), 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE );
368 aDC->DrawBitmap( wxBitmap(
image ), pos.
x, pos.
y,
true );
372 wxBitmap result(
m_bitmap->ConvertToImage().ConvertToGreyscale() );
373 aDC->DrawBitmap( result, pos.
x, pos.
y,
true );
377 aDC->DrawBitmap( *
m_bitmap, pos.
x, pos.
y,
true );
381 aDC->SetTransformMatrix( init_matrix );
385 aDC->SetLogicalOrigin( logicalOriginX, logicalOriginY );
389 aDC->DestroyClippingRegion();
419 int resX =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
420 int resY =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY );
421 int unit =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT );
425 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONUNIT , unit);
426 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONX, resX);
427 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONY, resY);
448 int resX =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
449 int resY =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY );
450 int unit =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT );
454 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONUNIT , unit);
455 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONX, resX);
456 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONY, resY);
479 int aDefaultPensize )
const
486 aPlotter->
SetColor( aDefaultColor );
496 wxMemoryOutputStream stream;
497 wxBitmapType type =
m_imageType == wxBITMAP_TYPE_JPEG ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG;
499 if( !
m_image->SaveFile( stream, type ) )
503 stream.CopyTo(
m_imageData.GetData(), stream.GetLength() );
This class handle bitmap images in KiCad.
wxMemoryBuffer m_imageData
void Rotate(bool aRotateCCW)
Rotate image CW or CCW.
bool LoadLegacyData(LINE_READER &aLine, wxString &aErrorMsg)
Load an image data saved by #SaveData.
double GetScalingFactor() const
This scaling factor depends on m_pixelSizeIu and m_scale.
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.
bool SaveImageData(wxOutputStream &aOutStream) const
Write the bitmap data to aOutStream.
wxImage * m_originalImage
void rebuildBitmap(bool aResetID=true)
void DrawBitmap(wxDC *aDC, const VECTOR2I &aPos, const KIGFX::COLOR4D &aBackgroundColor=KIGFX::COLOR4D::UNSPECIFIED)
void ImportData(BITMAP_BASE *aItem)
Copy aItem image to this object and update m_bitmap.
void ConvertToGreyscale()
void UpdateImageDataBuffer()
Resets the image data buffer using the current image data.
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores in memory an image file.
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.
wxColour ToColour() const
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_0
static constexpr EDA_ANGLE ANGLE_90
bool GetGRForceBlackPenState(void)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".