diff --git a/lib/CalypFrame.cpp b/lib/CalypFrame.cpp index 910c7bc..947cf19 100644 --- a/lib/CalypFrame.cpp +++ b/lib/CalypFrame.cpp @@ -119,6 +119,15 @@ public: /** Numbers of histogram segments depending of image bytes depth*/ unsigned int m_uiHistoSegments; + CalypFramePrivate() + { + m_bInit = false; + m_bHasRGBPel = false; + m_pppcInputPel = nullptr; + m_pcARGB32 = nullptr; + m_puiHistogram = nullptr; + } + void init( unsigned int width, unsigned int height, int pel_format, unsigned bitsPixel ) { init( width, height, pel_format, bitsPixel, false ); @@ -126,10 +135,6 @@ public: void init( unsigned int width, unsigned int height, int pel_format, unsigned bitsPixel, bool has_negative_values ) { - m_bInit = false; - m_bHasRGBPel = false; - m_pppcInputPel = NULL; - m_pcARGB32 = NULL; m_uiWidth = width; m_uiHeight = height; m_iPixelFormat = pel_format; @@ -258,6 +263,11 @@ public: * \brief Constructors */ +CalypFrame::CalypFrame() + : d( new CalypFramePrivate ) +{ +} + CalypFrame::CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel ) : d( new CalypFramePrivate ) { @@ -270,6 +280,28 @@ CalypFrame::CalypFrame( unsigned int width, unsigned int height, int pelFormat, d->init( width, height, pelFormat, bitsPixel, has_negative_values ); } +CalypFrame::CalypFrame( CalypFrame&& other ) noexcept + : d( other.d ) +{ + other.d = nullptr; // we'll talk more about this line below +} + +CalypFrame& CalypFrame::operator=( CalypFrame&& other ) noexcept +{ + // Self-assignment detection + if( &other == this ) + return *this; + + // Release any resource we're holding + delete d; + + // Transfer ownership of a.m_ptr to m_ptr + d = other.d; + other.d = nullptr; + + return *this; +} + CalypFrame::CalypFrame( const CalypFrame& other ) : d( new CalypFramePrivate ) { @@ -287,6 +319,23 @@ CalypFrame::CalypFrame( const CalypFrame* other ) } } +CalypFrame& CalypFrame::operator=( const CalypFrame& other ) +{ + // Self-assignment detection + if( &other == this ) + return *this; + + // Release any resource we're holding + delete d; + + // Copy the resource + d = new CalypFramePrivate; + d->init( other.getWidth(), other.getHeight(), other.getPelFormat(), other.getBitsPel(), other.getHasNegativeValues() ); + copyFrom( &other ); + + return *this; +} + CalypFrame::CalypFrame( const CalypFrame& other, unsigned int x, unsigned int y, unsigned int width, unsigned int height ) : d( new CalypFramePrivate ) { diff --git a/lib/CalypFrame.h b/lib/CalypFrame.h index f77cf86..6ddce11 100644 --- a/lib/CalypFrame.h +++ b/lib/CalypFrame.h @@ -102,6 +102,11 @@ public: static int findPixelFormat( const ClpString& name ); static int pelformatColorSpace( const int idx ); + /** + * Default constructor. Frame is not valid + */ + CalypFrame(); + /** * Creates a new frame using the following configuration * @@ -124,6 +129,20 @@ public: */ CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel, bool has_negative_values ); + /** + * Move contructor + * + * @param other existing frame to copy from + */ + CalypFrame( CalypFrame&& other ) noexcept; + + /** + * Move assignement contructor + * + * @param other existing frame to copy from + */ + CalypFrame& operator=( CalypFrame&& other ) noexcept; + /** * Copy contructor * @@ -132,6 +151,13 @@ public: CalypFrame( const CalypFrame& other ); CalypFrame( const CalypFrame* other ); + /** + * Copy-assignement contructor + * + * @param other existing frame to copy from + */ + CalypFrame& operator=( const CalypFrame& other ); + /** * Creates and new frame with the configuration of an existing one and copy * its contents. This function only copies a specific region from the existing