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 ) )
162 std::unique_ptr<wxImage> new_image = std::make_unique<wxImage>();
167 if( !new_image->LoadFile( mem_stream ) )
187 wxFileInputStream file_stream(aFullFilename);
190 if (!file_stream.IsOk())
202 wxBitmapType type =
m_imageType == wxBITMAP_TYPE_JPEG ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG;
204 if( !
m_image->SaveFile( aOutStream, type ) )
221 wxMemoryOutputStream stream;
228 aErrorMsg = wxT(
"Unexpected end of data");
234 if( strncasecmp( line,
"EndData", 4 ) == 0 )
239 wxMemoryInputStream istream( stream );
240 m_image->LoadFile( istream, wxBITMAP_TYPE_ANY );
250 int len = strlen( line );
252 for( ; len > 0; len -= 3, line += 3 )
256 if( sscanf( line,
"%X", &value ) == 1 )
257 stream.PutC( (
char) value );
288 if( ( size.
x == 0 ) || ( size.
y == 0 ) )
296 int logicalOriginX, logicalOriginY;
298 aDC->GetLogicalOrigin( &logicalOriginX, &logicalOriginY );
305 bool useTransform = aDC->CanUseTransformMatrix();
307 wxAffineMatrix2D init_matrix = aDC->GetTransformMatrix();
321 wxAffineMatrix2D matrix = aDC->GetTransformMatrix();
322 matrix.Translate( pos.
x, pos.
y );
324 aDC->SetTransformMatrix( matrix );
328 clipAreaPos.x = pos.
x;
329 clipAreaPos.y = pos.
y;
343 clipAreaPos.x = pos.
x;
344 clipAreaPos.y = pos.
y;
348 aDC->DestroyClippingRegion();
349 aDC->SetClippingRegion( clipAreaPos, wxSize( size.
x, size.
y ) );
352 if( aBackgroundColor != COLOR4D::UNSPECIFIED &&
m_bitmap->HasAlpha() )
360 wxImage
image( w, h );
361 wxColour bgColor = aBackgroundColor.
ToColour();
363 image.SetRGB( wxRect( 0, 0, w, h ), bgColor.Red(), bgColor.Green(), bgColor.Blue() );
364 image.Paste(
m_bitmap->ConvertToImage(), 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE );
369 aDC->DrawBitmap( wxBitmap(
image ), pos.
x, pos.
y,
true );
373 wxBitmap result(
m_bitmap->ConvertToImage().ConvertToGreyscale() );
374 aDC->DrawBitmap( result, pos.
x, pos.
y,
true );
378 aDC->DrawBitmap( *
m_bitmap, pos.
x, pos.
y,
true );
382 aDC->SetTransformMatrix( init_matrix );
386 aDC->SetLogicalOrigin( logicalOriginX, logicalOriginY );
390 aDC->DestroyClippingRegion();
420 int resX =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
421 int resY =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY );
422 int unit =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT );
424 *
m_image =
m_image->Mirror( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT );
426 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONUNIT , unit);
427 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONX, resX);
428 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONY, resY);
430 if( aFlipDirection == FLIP_DIRECTION::TOP_BOTTOM )
449 int resX =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
450 int resY =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY );
451 int unit =
m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT );
455 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONUNIT , unit);
456 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONX, resX);
457 m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONY, resY);
480 int aDefaultPensize )
const
487 aPlotter->
SetColor( aDefaultColor );
497 wxMemoryOutputStream stream;
498 wxBitmapType type =
m_imageType == wxBITMAP_TYPE_JPEG ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG;
500 if( !
m_image->SaveFile( stream, type ) )
504 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()
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)