27#include <wx/mstream.h>
39 if( !leftImage || !rightImage )
40 return leftImage == rightImage;
42 wxMemoryOutputStream leftStream;
43 wxMemoryOutputStream rightStream;
48 size_t leftSize = leftStream.GetSize();
49 size_t rightSize = rightStream.GetSize();
51 if( leftSize != rightSize )
57 std::string leftData( leftSize,
'\0' );
58 std::string rightData( rightSize,
'\0' );
60 leftStream.CopyTo( leftData.data(), leftSize );
61 rightStream.CopyTo( rightData.data(), rightSize );
63 return leftData == rightData;
107 if( &aOther !=
this )
156 double similarity = 1.0;
205 const double w = size.
x * angleCos + size.
y * angleSin;
206 const double h = size.
x * angleSin + size.
y * angleCos;
252 const double ratio = aWidth / (double)
m_bitmapBase->GetSize().x;
262 const double ratio = aHeight / (double)
m_bitmapBase->GetSize().y;
290 const VECTOR2D newCenter = currentOrigin - newOffset;
314 MIRROR( newPos, aCentre, aFlipDirection );
355 m_opacity = std::clamp( aOpacity, 0.0, 1.0 );
397 wxMemoryOutputStream imageStream;
401 size_t size = imageStream.GetSize();
405 aOutputBytes.resize( size );
406 imageStream.CopyTo( aOutputBytes.data(), size );
414 if( aInputBytes.empty() )
417 wxMemoryBuffer imageBuffer;
418 imageBuffer.AppendData( aInputBytes.data(), aInputBytes.size() );
438 int aDefaultPensize )
const
447 aPlotter->
SetColor( aDefaultColor );
450 const double scaleFactor =
m_bitmapBase->GetScalingFactor();
454 if( angle.
IsZero() && !faded )
461 wxImage turned =
image->Copy();
465 turned = turned.Rotate90(
false );
469 turned = turned.Rotate180();
473 turned = turned.Rotate90(
true );
475 else if( !angle.
IsZero() )
478 if( !turned.HasAlpha() )
481 const wxPoint centerPoint( turned.GetWidth() / 2, turned.GetHeight() / 2 );
482 turned = turned.Rotate( angle.
AsRadians(), centerPoint,
true );
485 wxCHECK_MSG( turned.IsOk(), , wxT(
"Failed to rotate image" ) );
490 if( !turned.HasAlpha() )
493 unsigned char* alpha = turned.GetAlpha();
494 const int pixels = turned.GetWidth() * turned.GetHeight();
497 for(
int ii = 0; ii < pixels; ++ii )
501 aPlotter->
PlotImage( turned, aPos, scaleFactor );
constexpr bool IsBOX2Safe(const BOX2< Vec > &aInput)
Check if a BOX2 is safe for use with BOX2D (probably BOX2D or BOX2L)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
This class handle bitmap images in KiCad.
bool SaveImageData(wxOutputStream &aOutStream) const
Write the bitmap data to aOutStream.
static constexpr BOX2< VECTOR2I > ByCenter(const VECTOR2I &aCenter, const SizeVec &aSize)
bool IsHorizontal() const
A color representation with 4 components: red, green, blue, alpha.
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
BITMAP_BASE & MutableImage() const
Only use this if you really need to modify the underlying image.
const EDA_IU_SCALE & m_iuScale
EDA_ANGLE GetOrientation() const
void SwapData(REFERENCE_IMAGE &aItem)
bool Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
VECTOR2I m_pos
XY coordinates of center of the bitmap.
void Rotate(const VECTOR2I &aCenter, const EDA_ANGLE &aAngle)
Rotate the image about aCenter.
void SetTransformOriginOffset(const VECTOR2I &aCenter)
bool ReadImageFile(const wxString &aFullFilename)
Read and store an image file.
VECTOR2I GetTransformOriginOffset() const
Get the center of scaling, etc, relative to the image center (GetPosition()).
VECTOR2I GetPosition() const
void PlotImage(PLOTTER *aPlotter, const VECTOR2I &aPos, const KIGFX::COLOR4D &aDefaultColor, int aDefaultPensize) const
Plot the image on a plotter, turned to its stored orientation.
EDA_ORIENTATION m_orientation
Rotation of the image content relative to the raster, in [0, 360).
bool SetImage(const wxImage &aImage)
Set the image from an existing wxImage.
std::unique_ptr< BITMAP_BASE > m_bitmapBase
REFERENCE_IMAGE & operator=(const REFERENCE_IMAGE &aOther)
void SetHeight(int aHeight)
VECTOR2I m_transformOriginOffset
Center of scaling, etc, relative to the image center.
bool UnpackFromBytes(const std::string &aInputBytes)
void SetOrientation(const EDA_ANGLE &aAngle)
Set the rotation of the image content relative to the stored raster.
void SetOpacity(double aOpacity)
void SetPosition(const VECTOR2I &aPos)
void SetWidth(int aWidth)
void updatePixelSizeInIU()
const BITMAP_BASE & GetImage() const
Get the underlying image.
double Similarity(const REFERENCE_IMAGE &aOther) const
double GetImageScale() const
void SetImageScale(double aScale)
Set the image "zoom" value.
REFERENCE_IMAGE(const EDA_IU_SCALE &aIuScale)
VECTOR2I boundingSize() const
BOX2I GetBoundingBox() const
void scaleBy(double ratio)
void PackToBytes(std::string &aOutputBytes) const
double m_opacity
The opacity of the image, in the range [0, 1].
bool operator==(const REFERENCE_IMAGE &aOther) const
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE ANGLE_270
static constexpr EDA_ANGLE ANGLE_180
a few functions useful in geometry calculations.
bool IsVec2SafeXY(const VECTOR2< T > &aVec)
Check if both coordinates of a vector are within the limits of the integer type.
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
static bool compareImages(const BITMAP_BASE &aLeft, const BITMAP_BASE &aRight)
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D