33#include <wx/mstream.h>
36#include <wx/wfstream.h>
102 if(
m_originalImage->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT ) == wxIMAGE_RESOLUTION_CM )
130 size_t dataSize = aInStream.GetLength();
135 std::unique_ptr<wxImage> new_image = std::make_unique<wxImage>();
138 wxMemoryInputStream mem_stream(
m_imageData.GetData(), dataSize );
139 if( !new_image->LoadFile( mem_stream ) )
151 std::unique_ptr<wxImage> new_image = std::make_unique<wxImage>();
156 if( !new_image->LoadFile( mem_stream ) )
165 wxFileInputStream file_stream(aFullFilename);
168 if (!file_stream.IsOk())
177 if( !aImage.IsOk() || aImage.GetWidth() == 0 || aImage.GetHeight() == 0 )
181 m_image =
new wxImage( aImage );
199 wxBitmapType type =
m_imageType == wxBITMAP_TYPE_JPEG ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG;
201 if( !
m_image->SaveFile( aOutStream, type ) )
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_ANY );
247 int len = strlen( line );
249 for( ; len > 0; len -= 3, line += 3 )
253 if( sscanf( line,
"%X", &value ) == 1 )
254 stream.PutC( (
char) value );
285 if( ( size.
x == 0 ) || ( size.
y == 0 ) )
293 int logicalOriginX, logicalOriginY;
295 aDC->GetLogicalOrigin( &logicalOriginX, &logicalOriginY );
302 bool useTransform = aDC->CanUseTransformMatrix();
304 wxAffineMatrix2D init_matrix = aDC->GetTransformMatrix();
318 wxAffineMatrix2D matrix = aDC->GetTransformMatrix();
319 matrix.Translate( pos.
x, pos.
y );
321 aDC->SetTransformMatrix( matrix );
325 clipAreaPos.x = pos.
x;
326 clipAreaPos.y = pos.
y;
340 clipAreaPos.x = pos.
x;
341 clipAreaPos.y = pos.
y;
345 aDC->DestroyClippingRegion();
346 aDC->SetClippingRegion( clipAreaPos, wxSize( size.
x, size.
y ) );
349 if( aBackgroundColor != COLOR4D::UNSPECIFIED &&
m_bitmap->HasAlpha() )
357 wxImage
image( w, h );
358 wxColour bgColor = aBackgroundColor.
ToColour();
360 image.SetRGB( wxRect( 0, 0, w, h ), bgColor.Red(), bgColor.Green(), bgColor.Blue() );
361 image.Paste(
m_bitmap->ConvertToImage(), 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE );
366 aDC->DrawBitmap( wxBitmap(
image ), pos.
x, pos.
y,
true );
370 wxBitmap result(
m_bitmap->ConvertToImage().ConvertToGreyscale() );
371 aDC->DrawBitmap( result, pos.
x, pos.
y,
true );
375 aDC->DrawBitmap( *
m_bitmap, pos.
x, pos.
y,
true );
379 aDC->SetTransformMatrix( init_matrix );
383 aDC->SetLogicalOrigin( logicalOriginX, logicalOriginY );
387 aDC->DestroyClippingRegion();
417 int resX =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
418 int resY =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY );
419 int unit =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT );
421 *
m_image =
m_image->Mirror( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT );
423 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONUNIT , unit);
424 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONX, resX);
425 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONY, resY);
427 if( aFlipDirection == FLIP_DIRECTION::TOP_BOTTOM )
446 int resX =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
447 int resY =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY );
448 int unit =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT );
452 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONUNIT , unit);
453 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONX, resX);
454 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONY, resY);
477 int aDefaultPensize )
const
484 aPlotter->
SetColor( aDefaultColor );
494 wxMemoryOutputStream stream;
495 wxBitmapType type =
m_imageType == wxBITMAP_TYPE_JPEG ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG;
497 if( !
m_image->SaveFile( stream, type ) )
501 stream.CopyTo(
m_imageData.GetData(), stream.GetLength() );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
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.
void Mirror(FLIP_DIRECTION aFlipDirection)
Mirror image vertically (i.e.
const BOX2I GetBoundingBox() const
Return the orthogonal, bounding box of this object for display purposes.
void ImportData(BITMAP_BASE &aItem)
Copy aItem image to this object and update m_bitmap.
bool SaveImageData(wxOutputStream &aOutStream) const
Write the bitmap data to aOutStream.
wxImage * m_originalImage
void rebuildBitmap(bool aResetID=true)
void ConvertToGreyscale()
bool SetImage(const wxImage &aImage)
Set the image from an existing wxImage.
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.
void DrawBitmap(wxDC *aDC, const VECTOR2I &aPos, const KIGFX::COLOR4D &aBackgroundColor=KIGFX::COLOR4D::UNSPECIFIED) const
BITMAP_BASE(const VECTOR2I &pos=VECTOR2I(0, 0))
constexpr 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)