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;
207 const double angleCos =
std::abs( aOrientation.
Cos() );
208 const double angleSin =
std::abs( aOrientation.
Sin() );
210 const double w = size.
x * angleCos + size.
y * angleSin;
211 const double h = size.
x * angleSin + size.
y * angleCos;
257 const double ratio = aWidth / (double)
m_bitmapBase->GetSize().x;
267 const double ratio = aHeight / (double)
m_bitmapBase->GetSize().y;
295 const VECTOR2D newCenter = currentOrigin - newOffset;
319 MIRROR( newPos, aCentre, aFlipDirection );
385 m_opacity = std::clamp( aOpacity, 0.0, 1.0 );
427 wxMemoryOutputStream imageStream;
431 size_t size = imageStream.GetSize();
435 aOutputBytes.resize( size );
436 imageStream.CopyTo( aOutputBytes.data(), size );
444 if( aInputBytes.empty() )
447 wxMemoryBuffer imageBuffer;
448 imageBuffer.AppendData( aInputBytes.data(), aInputBytes.size() );
468 int aDefaultPensize )
const
477 aPlotter->
SetColor( aDefaultColor );
480 const double scaleFactor =
m_bitmapBase->GetScalingFactor();
490 wxImage turned =
image->Copy();
494 turned = turned.Rotate90(
false );
498 turned = turned.Rotate180();
502 turned = turned.Rotate90(
true );
504 else if( !angle.
IsZero() )
507 if( !turned.HasAlpha() )
510 const wxPoint centerPoint( turned.GetWidth() / 2, turned.GetHeight() / 2 );
511 turned = turned.Rotate( angle.
AsRadians(), centerPoint,
true );
514 wxCHECK_MSG( turned.IsOk(), , wxT(
"Failed to rotate image" ) );
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 SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
virtual void PlotImage(const wxImage &aImage, const VECTOR2I &aPos, double aScaleFactor, double aAlpha)
Plot a bitmap.
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.
bool Mirror(const SEG &aAxis)
Mirror the image about an arbitrary axis, keeping its layer.
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
const VECTOR2I ReflectPoint(const VECTOR2I &aP) const
Reflect a point using this segment as axis.
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.
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
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