diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..1658e98 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,43 @@ +--- +Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay' +WarningsAsErrors: '' +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +FormatStyle: none +CheckOptions: + - key: llvm-else-after-return.WarnOnConditionVariables + value: '0' + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-replace-auto-ptr.IncludeStyle + value: llvm + - key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons + value: '0' + - key: google-readability-namespace-comments.ShortNamespaceLines + value: '10' + - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField + value: '0' + - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: '1' + - key: cert-dcl16-c.NewSuffixes + value: 'L;LL;LU;LLU' + - key: google-readability-braces-around-statements.ShortStatementLines + value: '1' + - key: modernize-pass-by-value.IncludeStyle + value: llvm + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' + - key: modernize-loop-convert.MaxCopySize + value: '16' + - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors + value: '1' + - key: modernize-use-nullptr.NullMacros + value: 'NULL' + - key: llvm-qualified-auto.AddConstToQualified + value: '0' + - key: modernize-loop-convert.NamingStyle + value: CamelCase + - key: llvm-else-after-return.WarnOnUnfixable + value: '0' + - key: google-readability-function-size.StatementThreshold + value: '800' diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index 65397fa..734d582 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -57,7 +57,7 @@ QDataStream& operator<<( QDataStream& out, const CalypFileInfoVector& array ) QDataStream& operator>>( QDataStream& in, CalypFileInfoVector& array ) { CalypFileInfo d; - int array_size; + int array_size{ 0 }; in >> array_size; for( int i = 0; i < array_size; i++ ) { @@ -984,7 +984,6 @@ void VideoSubWindow::seekAbsoluteEvent( unsigned int new_frame_num ) void VideoSubWindow::seekRelativeEvent( bool bIsFoward ) { - bool bRefresh = false; if( m_pCurrStream ) { if( bIsFoward ) @@ -993,7 +992,7 @@ void VideoSubWindow::seekRelativeEvent( bool bIsFoward ) } else { - bRefresh = m_pCurrStream->seekInputRelative( bIsFoward ); + m_pCurrStream->seekInputRelative( bIsFoward ); #ifdef CALYP_MANAGED_RESOURCES m_pcResourceManager->wakeResourceWorker( m_uiResourceId ); #endif diff --git a/app/VideoSubWindow.h b/app/VideoSubWindow.h index 5f93f3b..e65a3bf 100644 --- a/app/VideoSubWindow.h +++ b/app/VideoSubWindow.h @@ -222,9 +222,9 @@ private: QSize getScrollSize(); protected: - void keyPressEvent( QKeyEvent* event ); - void resizeEvent( QResizeEvent* event ); - void closeEvent( QCloseEvent* event ); + void keyPressEvent( QKeyEvent* event ) override; + void resizeEvent( QResizeEvent* event ) override; + void closeEvent( QCloseEvent* event ) override; public Q_SLOTS: void updateWindowOnTimeout(); @@ -235,7 +235,7 @@ public Q_SLOTS: void updatePixelValueStatusBar( const QPoint& pos ); }; -Q_DECLARE_METATYPE( CalypFileInfo ) -Q_DECLARE_METATYPE( CalypFileInfoVector ) +Q_DECLARE_METATYPE( CalypFileInfo ) // NOLINT +Q_DECLARE_METATYPE( CalypFileInfoVector ) // NOLINT #endif // __VIDEOSUBWINDOW_H__ diff --git a/lib/CalypFrame.cpp b/lib/CalypFrame.cpp index be21d09..ec9c2c8 100644 --- a/lib/CalypFrame.cpp +++ b/lib/CalypFrame.cpp @@ -41,6 +41,9 @@ #include #endif +constexpr auto kMinBitsPerPixel = 8; +constexpr auto kMaxBitsPerPixel = 16; + std::vector CalypFrame::supportedColorSpacesListNames() { return std::vector{ @@ -74,7 +77,7 @@ std::vector CalypFrame::supportedPixelFormatListNames( int colorSpace int CalypFrame::numberOfFormats() { - return g_CalypPixFmtDescriptorsMap.size(); + return static_cast( g_CalypPixFmtDescriptorsMap.size() ); } int CalypFrame::findPixelFormat( const ClpString& name ) @@ -95,40 +98,39 @@ int CalypFrame::pelformatColorSpace( const int idx ) class CalypFrame::CalypFramePrivate { public: - bool m_bInit; + bool m_bInit{ false }; //! Struct with the pixel format description. - const CalypPixelFormatDescriptor* m_pcPelFormat; + const CalypPixelFormatDescriptor* m_pcPelFormat{ nullptr }; ClpString m_cPelFmtName; - unsigned int m_uiWidth; //!< Width of the frame - unsigned int m_uiHeight; //!< Height of the frame - int m_iPixelFormat; //!< Pixel format number (it follows the list of supported pixel formats) - unsigned int m_uiBitsPel; //!< Bits per pixel/channel - unsigned int m_uiHalfPelValue; //!< Bits per pixel/channel - bool m_bHasNegativeValues; //!< Half of the scale correspond to negative values + unsigned int m_uiWidth{ 0 }; //!< Width of the frame + unsigned int m_uiHeight{ 0 }; //!< Height of the frame + int m_iPixelFormat{ 0 }; //!< Pixel format number (it follows the list of supported pixel formats) + unsigned int m_uiBitsPel{ 0 }; //!< Bits per pixel/channel + unsigned int m_uiHalfPelValue{ 0 }; //!< Bits per pixel/channel + bool m_bHasNegativeValues{ false }; //!< Half of the scale correspond to negative values - ClpPel*** m_pppcInputPel; + ClpPel*** m_pppcInputPel{ nullptr }; - bool m_bHasRGBPel; //!< Flag indicating that the ARGB buffer was computed + bool m_bHasRGBPel{ false }; //!< Flag indicating that the ARGB buffer was computed std::vector m_pcARGB32; //!< Buffer with the ARGB pixels used in Qt libs /** Histogram control variables **/ - bool m_bHasHistogram; - bool m_bHistogramRunning; + bool m_bHasHistogram{ false }; + bool m_bHistogramRunning{ false }; /** The histogram data.*/ std::vector m_puiHistogram; /** If the image is RGB and calcLuma is true, we have 1 more channel */ - unsigned int m_uiHistoChannels; + unsigned int m_uiHistoChannels{ 0 }; /** Numbers of histogram segments depending of image bytes depth*/ - unsigned int m_uiHistoSegments; + unsigned int m_uiHistoSegments{ 0 }; - CalypFramePrivate() - { - m_bInit = false; - m_bHasRGBPel = false; - m_pppcInputPel = nullptr; - } + CalypFramePrivate() = default; + CalypFramePrivate( const CalypFramePrivate& ) = delete; + CalypFramePrivate( CalypFramePrivate&& ) = delete; + CalypFramePrivate& operator=( const CalypFramePrivate& ) = delete; + CalypFramePrivate& operator=( CalypFramePrivate&& ) = delete; void init( unsigned int width, unsigned int height, int pel_format, unsigned bitsPixel ) { @@ -140,11 +142,11 @@ public: m_uiWidth = width; m_uiHeight = height; m_iPixelFormat = pel_format; - m_uiBitsPel = bitsPixel < 8 ? 8 : bitsPixel; + m_uiBitsPel = bitsPixel < kMinBitsPerPixel ? kMinBitsPerPixel : bitsPixel; m_uiHalfPelValue = 1 << ( m_uiBitsPel - 1 ); m_bHasNegativeValues = has_negative_values; - if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > 16 ) + if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > kMaxBitsPerPixel ) { throw CalypFailure( "CalypFrame", "Cannot create a CalypFrame of this type" ); } @@ -809,7 +811,7 @@ void CalypFrame::fillRGBBuffer() const if( d->m_pcPelFormat->colorSpace == CLP_COLOR_GRAY ) { ClpPel* pY = d->m_pppcInputPel[CLP_LUMA][0]; - unsigned char finalPel; + unsigned char finalPel{ 0 }; for( unsigned int i = 0; i < d->m_uiHeight * d->m_uiWidth; i++ ) { finalPel = ( *pY++ ) >> shiftBits; @@ -844,32 +846,28 @@ void CalypFrame::fillRGBBuffer() const ClpPel* pLineU = d->m_pppcInputPel[CLP_CHROMA_U][0]; ClpPel* pLineV = d->m_pppcInputPel[CLP_CHROMA_V][0]; unsigned int uiChromaStride = CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth ); - ClpPel* pY; - ClpPel* pU; - ClpPel* pV; + int iY, iU, iV, iR, iG, iB; uint32_t* pARGBLine = pARGB; uint32_t* pARGBAux; - unsigned int y, x; - int i, j; - for( y = 0; y < CHROMASHIFT( d->m_uiHeight, d->m_pcPelFormat->log2ChromaHeight ); y++ ) + for( int y = 0; y < CHROMASHIFT( d->m_uiHeight, d->m_pcPelFormat->log2ChromaHeight ); y++ ) { - for( i = 0; i < 1 << d->m_pcPelFormat->log2ChromaHeight; i++ ) + for( int i = 0; i < 1 << d->m_pcPelFormat->log2ChromaHeight; i++ ) { - pY = pLineY; - pU = pLineU; - pV = pLineV; + ClpPel* pY = pLineY; + ClpPel* pU = pLineU; + ClpPel* pV = pLineV; pARGBAux = pARGBLine; - for( x = 0; x < CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth ); x++ ) + for( int x = 0; x < CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth ); x++ ) { - iU = *pU++; + int iU = *pU++; iU >>= shiftBits; - iV = *pV++; + int iV = *pV++; iV >>= shiftBits; - for( j = 0; j < ( 1 << d->m_pcPelFormat->log2ChromaWidth ); j++ ) + for( int j = 0; j < ( 1 << d->m_pcPelFormat->log2ChromaWidth ); j++ ) { - iY = *pY++; + int iY = *pY++; iY >>= shiftBits; YUV2RGB( iY, iU, iV, iR, iG, iB ); *pARGBAux++ = PEL_RGB( iR, iG, iB ); diff --git a/lib/CalypStream.cpp b/lib/CalypStream.cpp index 22e45f6..17a562a 100644 --- a/lib/CalypStream.cpp +++ b/lib/CalypStream.cpp @@ -46,6 +46,9 @@ #include +constexpr auto kDefaultBitsPerPixel = 8; +constexpr auto kDefaultFrameRate = 30; + std::vector CalypStream::supportedReadFormats() { INI_REGIST_CALYP_SUPPORTED_FMT; @@ -102,109 +105,6 @@ std::vector CalypStream::stdResolutionSizes() return stdResList; } -class CalypStreamBufferPrivate -{ -private: - std::vector m_framePool; - std::deque m_frameBuffer; - std::int64_t m_iSize; - std::int64_t m_iReadIndex; - std::int64_t m_iWriteIndex; - -public: - CalypStreamBufferPrivate( std::size_t size, unsigned int width, unsigned int height, int pelFormat, unsigned int bitsPixel, bool hasNegative ) - { - m_framePool.reserve( size ); - for( std::size_t i = 0; i < size; i++ ) - { - m_framePool.push_back( CalypFrame{ width, height, pelFormat, bitsPixel, hasNegative } ); - } - m_iSize = std::ssize( m_framePool ); - m_iReadIndex = -1; - m_iWriteIndex = 0; - } - - ~CalypStreamBufferPrivate() = default; - - void increase( std::size_t newSize ) - { - m_framePool.reserve( newSize ); - for( std::size_t i = m_iSize; i < newSize; i++ ) - { - m_framePool.push_back( CalypFrame{ m_framePool[0].getWidth(), - m_framePool[0].getHeight(), - m_framePool[0].getPelFormat(), - m_framePool[0].getBitsPel(), - m_framePool[0].getHasNegativeValues() } ); - } - m_iSize = std::ssize( m_framePool ); - } - - void setIndex( std::int64_t i ) - { - m_iWriteIndex = m_iReadIndex = i; - m_iWriteIndex = nextIndex( m_iWriteIndex ); - } - void reset() - { - m_iReadIndex = -1; - m_iWriteIndex = 0; - } - void startRead() - { - assert( m_iWriteIndex >= 0 ); - m_iReadIndex = 0; - } - CalypFrame& frame( int i ) { return m_framePool.at( i ); } - - CalypFrame& currentRead() - { - assert( m_iReadIndex < m_iWriteIndex && ( m_iReadIndex % m_iSize ) < m_iSize ); - return m_framePool.at( m_iReadIndex % m_iSize ); - } - - const CalypFrame& ref() { return m_framePool.at( m_iWriteIndex % m_iSize ); } - - CalypFrame& readOneFrame() - { - assert( m_iReadIndex < m_iWriteIndex && ( m_iReadIndex % m_iSize ) < m_iSize ); - CalypFrame& frameToRead = m_framePool.at( m_iReadIndex % m_iSize ); - m_iReadIndex = nextIndex( m_iReadIndex ); - return frameToRead; - } - CalypFrame& writeOneFrame() - { - assert( m_iWriteIndex > m_iReadIndex && ( m_iReadIndex % m_iSize ) != ( m_iWriteIndex % m_iSize ) ); - CalypFrame& frameToWrite = m_framePool.at( m_iWriteIndex % m_iSize ); - m_iWriteIndex = nextIndex( m_iWriteIndex ); - return frameToWrite; - } - - bool hasWritingSlot() - { - if( ( m_iReadIndex % m_iSize ) != ( m_iWriteIndex % m_iSize ) ) - return true; - return false; - } - - std::shared_ptr retrieveFrame() - { - assert( m_iReadIndex < m_iWriteIndex && ( m_iReadIndex % m_iSize ) < m_iSize ); - auto ptr = std::make_shared( std::move( m_framePool[m_iReadIndex % m_iSize] ) ); - m_framePool[m_iReadIndex % m_iSize] = CalypFrame{ ptr->getWidth(), - ptr->getHeight(), - ptr->getPelFormat(), - ptr->getBitsPel(), - ptr->getHasNegativeValues() }; - m_iReadIndex = nextIndex( m_iReadIndex ); - return ptr; - } - -private: - //inline int nextIndex( std::int64_t curr ) { return curr + 1 >= m_iSize ? 0 : curr + 1; } - inline int nextIndex( std::int64_t curr ) { return curr + 1; } -}; - struct CalypStreamFrameBuffer : std::enable_shared_from_this { std::mutex buffer_mutex; @@ -221,6 +121,11 @@ struct CalypStreamFrameBuffer : std::enable_shared_from_thisiCurrFrameNum = 0; } - int currFrameNum = d->iCurrFrameNum; + auto currFrameNum = d->iCurrFrameNum; d->iCurrFrameNum = -1; seekInput( currFrameNum ); return true; @@ -605,16 +514,16 @@ void CalypStream::getFormat( unsigned int& rWidth, unsigned int& rHeight, int& r rInputFormat = d->handler->m_iPixelFormat; rBitsPerPel = d->handler->m_uiBitsPerPixel; rEndianness = d->handler->m_iEndianness; - rFrameRate = d->handler->m_dFrameRate; + rFrameRate = static_cast( std::max( 0.0, d->handler->m_dFrameRate ) ); } else { rWidth = 0; rHeight = 0; rInputFormat = CLP_YUV420P; - rBitsPerPel = 8; + rBitsPerPel = kDefaultBitsPerPixel; rEndianness = 0; - rFrameRate = 30; + rFrameRate = kDefaultFrameRate; } }