22 Commits
Author SHA1 Message Date
jfmcarreira 17e2a6084a Fix resouce worker stop 2021-12-19 15:25:01 +00:00
jfmcarreira 77617ce53a Replace atomic_flag with plain atomic 2021-12-19 01:15:39 +00:00
jfmcarreira 6789ada346 Remove spin lock from the resource handler and avoid threads on a single frame stream 2021-12-19 00:55:42 +00:00
jfmcarreira f4c69fd894 Fix module tests 2021-12-18 23:53:10 +00:00
jfmcarreira c24ddcdc59 Cast to avoid recursion std::string 2021-12-18 23:44:54 +00:00
jfmcarreira 496bb54450 Fix scroll bug 2021-12-18 23:44:22 +00:00
jfmcarreira a048d2e0df Clean constructor of SubWindowAbstract 2021-12-18 23:42:40 +00:00
jfmcarreira 9d28051f38 Use std::span to give access to RGB buffer 2021-12-18 22:24:46 +00:00
jfmcarreira 8717338bf9 Modernise CalypModules factory 2021-12-18 22:24:03 +00:00
jfmcarreira 84865a039f Version bump 2.2.0 2021-12-05 00:41:03 +00:00
jfmcarreira 96b7576a1d Fix optional opencv dependency 2021-12-03 23:08:40 +00:00
jfmcarreira b61fd9d0e0 Remove type_safe library 2021-12-03 22:36:11 +00:00
jfmcarreira 5b4cdddde4 Disable DEBUG_ASSERT 2021-11-28 23:27:33 +00:00
jfmcarreira c43cb2bd0a Version bump 2.1.0 2021-11-28 20:36:33 +00:00
jfmcarreira e6970fb953 Fix windows build 2021-11-28 20:34:41 +00:00
jfmcarreira aac02a9959 Fix missing include 2021-11-28 18:23:05 +00:00
jfmcarreira 500e0e85ba Add macro to protect against the Qt version 2021-11-28 01:46:37 +00:00
jfmcarreira d4886a7fee Fix fetch content to build main product 2021-11-27 23:28:27 +00:00
jfmcarreira f3919ac8e8 Change cmake fetch content 2021-11-27 22:51:58 +00:00
jfmcarreira 562fd915fe Add build checks 2021-11-27 01:04:51 +00:00
jfmcarreira f3df40cdf7 Code cleanup 2021-11-27 00:52:32 +00:00
jfmcarreira 1bb2773abc Add support to filter components to display 2021-11-27 00:45:56 +00:00
46 changed files with 488 additions and 336 deletions

No files matched your search

+3 -1
View File
@@ -1,5 +1,5 @@
--- ---
Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-bounds-constant-array-index' Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-bounds-constant-array-index, -readability-magic-numbers,-cppcoreguidelines-avoid-magic-numbers'
WarningsAsErrors: '' WarningsAsErrors: ''
HeaderFilterRegex: '' HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false AnalyzeTemporaryDtors: false
@@ -41,3 +41,5 @@ CheckOptions:
value: '0' value: '0'
- key: google-readability-function-size.StatementThreshold - key: google-readability-function-size.StatementThreshold
value: '800' value: '800'
- key: readability-magic-numbers.IgnorePowersOf2IntegerValues
value: '1'
+7 -5
View File
@@ -26,14 +26,16 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Configure CMake - name: Build with default options
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Build - name: Build without threads
# Build your program with the given configuration run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON -DCALYP_MANAGED_RESOURCES=OFF -DCALYP_THREADED_MODULES=OFF; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Build without dependencies
run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON -DUSE_OPENCV=OFF -DUSE_FFMPEG=OFF; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
check-tests: check-tests:
runs-on: ubuntu-latest runs-on: ubuntu-latest
+2 -2
View File
@@ -1,6 +1,6 @@
# Created by https://www.gitignore.io/api/c++,clion,linux # Created by https://www.gitignore.io/api/c++,clion,linux
# Edit at https://www.gitignore.io/?templates=c++,clion,linux # Edit at https://www.gitignore.io/?templates=c++,clion,linux
deps/**
### C++ ### ### C++ ###
# Prerequisites # Prerequisites
*.d *.d
@@ -146,4 +146,4 @@ doc/
compile_commands.json compile_commands.json
# Build dirs # Build dirs
build* build*
+5 -5
View File
@@ -20,10 +20,10 @@ repos:
entry: cmake -B build entry: cmake -B build
pass_filenames: false pass_filenames: false
language: system language: system
- id: cmake-build #- id: cmake-build
name: Cmake Build #name: Cmake Build
entry: cmake --build build #entry: cmake --build build
pass_filenames: false #pass_filenames: false
language: system #language: system
+14 -31
View File
@@ -18,8 +18,8 @@ SET(PROJECT_LIBRARY
) )
SET(CALYP_VERSION_MAJOR "2") SET(CALYP_VERSION_MAJOR "2")
SET(CALYP_VERSION_MINOR "0") SET(CALYP_VERSION_MINOR "2")
SET(CALYP_VERSION_PATCH "1") SET(CALYP_VERSION_PATCH "0")
SET(CALYP_VERSION SET(CALYP_VERSION
"${CALYP_VERSION_MAJOR}.${CALYP_VERSION_MINOR}.${CALYP_VERSION_PATCH}" "${CALYP_VERSION_MAJOR}.${CALYP_VERSION_MINOR}.${CALYP_VERSION_PATCH}"
CACHE INTERNAL "" FORCE CACHE INTERNAL "" FORCE
@@ -104,7 +104,8 @@ SET(UPDATE_CHANNEL
# #################################################################################################################################################### # ####################################################################################################################################################
INCLUDE(FetchContent) INCLUDE(FetchContent)
# #################################################################################################################################################### SET(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/deps")
# Doxygen # Doxygen
IF(BUILD_DOC) IF(BUILD_DOC)
FIND_PACKAGE(Doxygen) FIND_PACKAGE(Doxygen)
@@ -117,7 +118,6 @@ SET_PACKAGE_PROPERTIES(
TYPE OPTIONAL TYPE OPTIONAL
) )
# ####################################################################################################################################################
# Catch2 and Google Tests # Catch2 and Google Tests
IF(BUILD_TESTS) IF(BUILD_TESTS)
FETCHCONTENT_DECLARE(googletest URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip) FETCHCONTENT_DECLARE(googletest URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip)
@@ -126,7 +126,12 @@ IF(BUILD_TESTS)
ON ON
CACHE BOOL "" FORCE CACHE BOOL "" FORCE
) )
FETCHCONTENT_MAKEAVAILABLE(googletest) FETCHCONTENT_DECLARE(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.1
)
SET_PACKAGE_PROPERTIES( SET_PACKAGE_PROPERTIES(
googletest PROPERTIES googletest PROPERTIES
URL "https://github.com/google/googletest" URL "https://github.com/google/googletest"
@@ -134,19 +139,15 @@ IF(BUILD_TESTS)
TYPE OPTIONAL TYPE OPTIONAL
) )
FETCHCONTENT_DECLARE(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.1
)
FETCHCONTENT_MAKEAVAILABLE(Catch2)
SET_PACKAGE_PROPERTIES( SET_PACKAGE_PROPERTIES(
Catch2 PROPERTIES Catch2 PROPERTIES
URL "https://github.com/catchorg/Catch2" URL "https://github.com/catchorg/Catch2"
DESCRIPTION "Catch2 unit tests" DESCRIPTION "Catch2 unit tests"
TYPE OPTIONAL TYPE OPTIONAL
) )
INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/_deps/catch2-src/contrib/Catch.cmake) FETCHCONTENT_MAKEAVAILABLE(googletest Catch2)
INCLUDE(${CMAKE_BINARY_DIR}/deps/catch2-src/contrib/Catch.cmake)
INCLUDE(CTest) INCLUDE(CTest)
ENABLE_TESTING() ENABLE_TESTING()
@@ -156,23 +157,6 @@ IF(BUILD_TESTS)
) )
ENDIF() ENDIF()
# ####################################################################################################################################################
# Type safe
FETCHCONTENT_DECLARE(
type_safe
GIT_REPOSITORY https://github.com/foonathan/type_safe
GIT_TAG v0.2.2
)
FETCHCONTENT_MAKEAVAILABLE(type_safe)
SET_PACKAGE_PROPERTIES(
type_safe PROPERTIES
URL "https://github.com/foonathan/type_safe"
DESCRIPTION "Zero overhead abstractions that use the C++ type system to prevent bugs."
TYPE REQUIRED
)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/_deps/type_safe-src/include/ ${CMAKE_CURRENT_BINARY_DIR}/_deps/type_safe-src/external/debug_assert/)
# ####################################################################################################################################################
# OpenCV # OpenCV
OPTION(USE_OPENCV "Add OpenCV support" ON) OPTION(USE_OPENCV "Add OpenCV support" ON)
IF(USE_OPENCV) IF(USE_OPENCV)
@@ -199,7 +183,6 @@ SET_PACKAGE_PROPERTIES(
TYPE OPTIONAL TYPE OPTIONAL
) )
# ####################################################################################################################################################
# FFmpeg # FFmpeg
OPTION(USE_FFMPEG "Add FFMPEG support" ON) OPTION(USE_FFMPEG "Add FFMPEG support" ON)
IF(USE_FFMPEG) IF(USE_FFMPEG)
@@ -266,7 +249,7 @@ IF(USE_WERROR)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
ENDIF() ENDIF()
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0") SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -DCLP_DEBUG")
IF(BUILD_WITH_SANITIZERS) IF(BUILD_WITH_SANITIZERS)
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fsanitize=leak -fsanitize=undefined") SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fsanitize=leak -fsanitize=undefined")
ENDIF() ENDIF()
+1 -1
View File
@@ -131,7 +131,7 @@ bool CalypAppModuleIf::apply( bool isPlaying, bool disableThreads )
} }
} }
if( !( isPlaying && m_pcModule->m_uiModuleRequirements.is_set( ClpModuleFeature::SkipWhilePlaying ) ) ) if( !( isPlaying && m_pcModule->has( ClpModuleFeature::SkipWhilePlaying ) ) )
{ {
m_frameList.clear(); m_frameList.clear();
for( unsigned int i = 0; i < m_pcModule->m_uiNumberOfFrames; i++ ) for( unsigned int i = 0; i < m_pcModule->m_uiNumberOfFrames; i++ )
+1 -2
View File
@@ -81,12 +81,11 @@ public:
auto getSubWindowList() const -> const std::vector<VideoSubWindow*>& { return m_pcSubWindow; } auto getSubWindowList() const -> const std::vector<VideoSubWindow*>& { return m_pcSubWindow; }
CalypModuleIf* getModule() { return m_pcModule.get(); } CalypModuleIf* getModule() { return m_pcModule.get(); }
auto getModuleRequirements() const -> ClpModuleFeatures { return m_pcModule->m_uiModuleRequirements; } auto hasFeature( ClpModuleFeature feature ) const -> bool { return m_pcModule->has( feature ); }
std::string moduleInfo() const { return m_pcModule->moduleInfo(); } std::string moduleInfo() const { return m_pcModule->moduleInfo(); }
void update( bool isPlaying ); void update( bool isPlaying );
bool apply( bool isPlaying = false, bool disableThreads = false ); bool apply( bool isPlaying = false, bool disableThreads = false );
bool process(); bool process();
// void setPlaying( bool isPlaying );
bool isRunning() const; bool isRunning() const;
void show(); void show();
void disable(); void disable();
+1 -1
View File
@@ -69,7 +69,7 @@ void ModuleSubWindow::updateVideoWindowInfo()
} }
} }
} }
if( module_ptr->getModuleRequirements().is_set( ClpModuleFeature::HasInfo ) ) if( module_ptr->hasFeature( ClpModuleFeature::HasInfo ) )
{ {
QStringList list = QString::fromStdString( module_ptr->moduleInfo() ).split( '\n' ); QStringList list = QString::fromStdString( module_ptr->moduleInfo() ).split( '\n' );
windowInfoList.append( list ); windowInfoList.append( list );
+8 -9
View File
@@ -100,12 +100,11 @@ void ModulesHandle::buildMenu()
m_pcModulesMenu->clear(); m_pcModulesMenu->clear();
m_pcModulesSubMenuList.clear(); m_pcModulesSubMenuList.clear();
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); const auto& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin(); for( auto& [name, create_fct] : moduleFactoryMap )
for( ; it != moduleFactoryMap.end(); ++it )
{ {
auto pcCurrModuleIf = it->second(); auto pcCurrModuleIf = create_fct();
QString ModuleIfinternalName = QString::fromLocal8Bit( it->first ); QString moduleIfInternalName = QString::fromStdString( name );
QMenu* currSubMenu{ nullptr }; QMenu* currSubMenu{ nullptr };
if( pcCurrModuleIf->m_iModuleAPI <= CLP_MODULE_API_2 ) if( pcCurrModuleIf->m_iModuleAPI <= CLP_MODULE_API_2 )
@@ -134,7 +133,7 @@ void ModulesHandle::buildMenu()
moduleTooltip += QString( " | Requires %1 frames" ).arg( pcCurrModuleIf->m_uiNumberOfFrames ); moduleTooltip += QString( " | Requires %1 frames" ).arg( pcCurrModuleIf->m_uiNumberOfFrames );
currAction->setStatusTip( moduleTooltip ); currAction->setStatusTip( moduleTooltip );
currAction->setData( ModuleIfinternalName ); currAction->setData( moduleIfInternalName );
currAction->setCheckable( false ); currAction->setCheckable( false );
connect( currAction, &QAction::triggered, this, &ModulesHandle::activateModule ); connect( currAction, &QAction::triggered, this, &ModulesHandle::activateModule );
m_arrayModulesActions.append( currAction ); m_arrayModulesActions.append( currAction );
@@ -283,7 +282,7 @@ void ModulesHandle::activateModule()
{ {
int minNumFrames = numberOfFrames; int minNumFrames = numberOfFrames;
int maxNumFrames = numberOfFrames; int maxNumFrames = numberOfFrames;
if( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements.is_set( ClpModuleFeature::VariableNumOfFrames ) ) if( pcCurrAppModuleIf->m_pcModule->has( ClpModuleFeature::VariableNumOfFrames ) )
{ {
minNumFrames = numberOfFrames; minNumFrames = numberOfFrames;
maxNumFrames = 255; maxNumFrames = 255;
@@ -356,7 +355,7 @@ void ModulesHandle::activateModule()
pcCurrAppModuleIf->m_pcSubWindow[i] = videoSubWindowList.at( i ); pcCurrAppModuleIf->m_pcSubWindow[i] = videoSubWindowList.at( i );
} }
if( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements.is_set( ClpModuleFeature::Options ) ) if( pcCurrAppModuleIf->m_pcModule->has( ClpModuleFeature::Options ) )
{ {
ModulesHandleOptDialog moduleOptDialog( m_pcParent, pcCurrAppModuleIf.get() ); ModulesHandleOptDialog moduleOptDialog( m_pcParent, pcCurrAppModuleIf.get() );
if( moduleOptDialog.runConfiguration() == QDialog::Rejected ) if( moduleOptDialog.runConfiguration() == QDialog::Rejected )
@@ -373,7 +372,7 @@ void ModulesHandle::activateModule()
if( pcCurrAppModuleIf->m_pcModule->m_iModuleType == ClpModuleType::FrameProcessing ) if( pcCurrAppModuleIf->m_pcModule->m_iModuleType == ClpModuleType::FrameProcessing )
{ {
if( bShowModulesNewWindow || pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements.is_set( ClpModuleFeature::NewWindow ) ) if( bShowModulesNewWindow || pcCurrAppModuleIf->m_pcModule->has( ClpModuleFeature::NewWindow ) )
{ {
auto pcModuleSubWindow = new ModuleSubWindow( pcCurrAppModuleIf.get() ); auto pcModuleSubWindow = new ModuleSubWindow( pcCurrAppModuleIf.get() );
pcModuleSubWindow->resetWindowName(); pcModuleSubWindow->resetWindowName();
+10 -8
View File
@@ -36,8 +36,8 @@
#include <optional> #include <optional>
ResourceWorker::ResourceWorker( std::shared_ptr<CalypStream> stream ) ResourceWorker::ResourceWorker( std::shared_ptr<CalypStream> stream )
: m_pcStream{ stream }
{ {
m_pcStream = stream;
} }
void ResourceWorker::stop() void ResourceWorker::stop()
@@ -57,25 +57,23 @@ void ResourceWorker::wake()
void ResourceWorker::run() void ResourceWorker::run()
{ {
m_bStop = false; m_bStop = false;
// Loop forever // Loop forever
while( !m_bStop ) while( !m_bStop )
{ {
//auto start = std::chrono::steady_clock::now(); // auto start = std::chrono::steady_clock::now();
m_pcStream->readNextFrameFillRGBBuffer(); m_pcStream->readNextFrameFillRGBBuffer();
// auto end = std::chrono::steady_clock::now(); // auto end = std::chrono::steady_clock::now();
// std::cout << "Elapsed time reading and processing a frame: " // std::cout << "Elapsed time reading and processing a frame: "
// << std::chrono::duration_cast<std::chrono::milliseconds>( end - start ).count() // << std::chrono::duration_cast<std::chrono::milliseconds>( end - start ).count()
// << " ms" << std::endl; // << " ms" << std::endl;
// if( !m_pcStream->hasWritingSlot() )
// {
// m_Mutex.lock();
// m_ResourceIdle.wait( &m_Mutex );
// m_Mutex.unlock();
// }
while( !m_bStop && !m_pcStream->hasWritingSlot() ) while( !m_bStop && !m_pcStream->hasWritingSlot() )
{ {
// Wait here // Wait here
m_Mutex.lock();
m_ResourceIdle.wait( &m_Mutex );
m_Mutex.unlock();
} }
} }
} }
@@ -150,6 +148,10 @@ void ResourceHandle::startResourceWorker( std::size_t id )
assert( false ); assert( false );
return; return;
} }
if( m_apcStreamResourcesList[id]->getFrameNum() < 2 )
{
return; // No work to be done!
}
m_apcStreamResourcesWorkersList[id]->setObjectName( m_apcStreamResourcesWorkersList[id]->setObjectName(
"RW-" + "RW-" +
QFileInfo( QString::fromStdString( m_apcStreamResourcesList[id]->getFileName() ) ).completeBaseName() ); QFileInfo( QString::fromStdString( m_apcStreamResourcesList[id]->getFileName() ) ).completeBaseName() );
+2 -1
View File
@@ -29,6 +29,7 @@
#include <QThread> #include <QThread>
#include <QVector> #include <QVector>
#include <QWaitCondition> #include <QWaitCondition>
#include <atomic>
#include "CommonDefs.h" #include "CommonDefs.h"
#include "lib/CalypStream.h" #include "lib/CalypStream.h"
@@ -39,7 +40,7 @@ private:
QMutex m_Mutex; QMutex m_Mutex;
QWaitCondition m_ResourceIdle; QWaitCondition m_ResourceIdle;
std::shared_ptr<CalypStream> m_pcStream; std::shared_ptr<CalypStream> m_pcStream;
bool m_bStop{ false }; std::atomic<bool> m_bStop{ false };
public: public:
ResourceWorker( std::shared_ptr<CalypStream> stream ); ResourceWorker( std::shared_ptr<CalypStream> stream );
+1 -6
View File
@@ -35,7 +35,7 @@
#include "MdiSubWindow.h" #include "MdiSubWindow.h"
SubWindowAbstract::SubWindowAbstract( QWidget* parent, unsigned int category ) SubWindowAbstract::SubWindowAbstract( QWidget* parent, unsigned int category )
: QWidget( parent ), m_cSubWindow( NULL ) : QWidget{ parent }, m_uiCategory{ category }, m_cWindowName{ " " }
{ {
setParent( parent ); setParent( parent );
setVisible( false ); setVisible( false );
@@ -46,11 +46,6 @@ SubWindowAbstract::SubWindowAbstract( QWidget* parent, unsigned int category )
setWindowIcon( QIcon( ":/logos/calyp-icon.png" ) ); setWindowIcon( QIcon( ":/logos/calyp-icon.png" ) );
// setWidgetResizable( true );
m_pcLayout = NULL;
m_uiCategory = category;
m_cWindowName = QString( " " );
connect( this, SIGNAL( destroyed() ), this, SLOT( onDestroyed() ) ); connect( this, SIGNAL( destroyed() ), this, SLOT( onDestroyed() ) );
} }
+3 -3
View File
@@ -56,11 +56,11 @@ class SubWindowAbstract : public QWidget
Q_OBJECT Q_OBJECT
private: private:
QHBoxLayout* m_pcLayout; QHBoxLayout* m_pcLayout{ nullptr };
unsigned int m_uiCategory; unsigned int m_uiCategory;
QString m_cWindowName; QString m_cWindowName;
MdiSubWindow* m_cSubWindow; MdiSubWindow* m_cSubWindow{ nullptr };
public: public:
enum SubWindowCategory enum SubWindowCategory
@@ -90,7 +90,7 @@ public:
*/ */
virtual void zoomToFit() = 0; virtual void zoomToFit() = 0;
/** /**
* Scale the image (zoomed in or out) to speficied absolute zoom value (1.0 = * Scale the image (zoomed in or out) to specified absolute zoom value (1.0 =
* original size). * original size).
*/ */
virtual void zoomToFactor( double factor, QPoint center = QPoint() ) = 0; virtual void zoomToFactor( double factor, QPoint center = QPoint() ) = 0;
+95
View File
@@ -42,6 +42,7 @@
#include "SubWindowSelectorDialog.h" #include "SubWindowSelectorDialog.h"
#include "VideoStreamSubWindow.h" #include "VideoStreamSubWindow.h"
#include "VideoSubWindow.h" #include "VideoSubWindow.h"
#include "lib/CalypFrame.h"
VideoHandle::VideoHandle( QWidget* parent, SubWindowHandle* windowManager ) VideoHandle::VideoHandle( QWidget* parent, SubWindowHandle* windowManager )
: m_pcParent( parent ), m_pcMainWindowManager( windowManager ) : m_pcParent( parent ), m_pcMainWindowManager( windowManager )
@@ -123,6 +124,24 @@ void VideoHandle::createActions()
connect( m_pcFrameSlider, SIGNAL( valueChanged( int ) ), this, SLOT( seekSliderEvent( int ) ) ); connect( m_pcFrameSlider, SIGNAL( valueChanged( int ) ), this, SLOT( seekSliderEvent( int ) ) );
// ------------ Image ------------ // ------------ Image ------------
m_mapperComponent = new QSignalMapper( this );
m_actionGroupComponent = new QActionGroup( this );
m_actionGroupComponent->setExclusive( true );
m_mapperComponent->setMapping( m_actionGroupComponent->addAction( "All" ), -1 );
m_mapperComponent->setMapping( m_actionGroupComponent->addAction( "Red" ), 0 );
m_mapperComponent->setMapping( m_actionGroupComponent->addAction( "Green" ), 1 );
m_mapperComponent->setMapping( m_actionGroupComponent->addAction( "Blue" ), 2 );
m_mapperComponent->setMapping( m_actionGroupComponent->addAction( "Alpha" ), 3 );
for( int i = 0; i < m_actionGroupComponent->actions().size(); i++ )
{
m_actionGroupComponent->actions().at( i )->setCheckable( true );
m_actionGroupComponent->actions().at( i )->setVisible( false );
connect( m_actionGroupComponent->actions().at( i ), SIGNAL( triggered() ), m_mapperComponent, SLOT( map() ) );
}
m_actionGroupComponent->actions().at( 0 )->setChecked( true );
m_actionGroupComponent->actions().at( 0 )->setVisible( true );
connect( m_mapperComponent, SIGNAL( mapped( int ) ), this, SLOT( setComponent( int ) ) );
m_actionGroupTools = new QActionGroup( this ); m_actionGroupTools = new QActionGroup( this );
m_actionGroupTools->setExclusive( true ); m_actionGroupTools->setExclusive( true );
@@ -158,9 +177,11 @@ void VideoHandle::createActions()
m_mapperGrid = new QSignalMapper( this ); m_mapperGrid = new QSignalMapper( this );
m_actionGroupGrid = new QActionGroup( this ); m_actionGroupGrid = new QActionGroup( this );
m_actionGroupGrid->setExclusive( true ); m_actionGroupGrid->setExclusive( true );
m_mapperGrid->setMapping( m_actionGroupGrid->addAction( "4x4" ), 4 );
m_mapperGrid->setMapping( m_actionGroupGrid->addAction( "8x8" ), 8 ); m_mapperGrid->setMapping( m_actionGroupGrid->addAction( "8x8" ), 8 );
m_mapperGrid->setMapping( m_actionGroupGrid->addAction( "16x16" ), 16 ); m_mapperGrid->setMapping( m_actionGroupGrid->addAction( "16x16" ), 16 );
m_mapperGrid->setMapping( m_actionGroupGrid->addAction( "64x64" ), 64 ); m_mapperGrid->setMapping( m_actionGroupGrid->addAction( "64x64" ), 64 );
m_mapperGrid->setMapping( m_actionGroupGrid->addAction( "128x128" ), 128 );
for( int i = 0; i < m_actionGroupGrid->actions().size(); i++ ) for( int i = 0; i < m_actionGroupGrid->actions().size(); i++ )
{ {
@@ -194,6 +215,8 @@ QMenu* VideoHandle::createVideoMenu()
QMenu* VideoHandle::createImageMenu() QMenu* VideoHandle::createImageMenu()
{ {
m_pcMenuImage = new QMenu( "Image", m_pcParent ); m_pcMenuImage = new QMenu( "Image", m_pcParent );
m_menuComponent = m_pcMenuImage->addMenu( "Component" );
m_menuComponent->addActions( m_actionGroupComponent->actions() );
m_pcMenuImage->addAction( m_arrayActions[NAVIGATION_TOOL_ACT] ); m_pcMenuImage->addAction( m_arrayActions[NAVIGATION_TOOL_ACT] );
m_pcMenuImage->addAction( m_arrayActions[SELECTION_TOOL_ACT] ); m_pcMenuImage->addAction( m_arrayActions[SELECTION_TOOL_ACT] );
m_pcMenuImage->addAction( m_arrayActions[BLOCK_SELECTION_TOOL_ACT] ); m_pcMenuImage->addAction( m_arrayActions[BLOCK_SELECTION_TOOL_ACT] );
@@ -268,6 +291,62 @@ QWidget* VideoHandle::createStatusBarMessage()
return pcStatusBarWidget; return pcStatusBarWidget;
} }
void VideoHandle::updateComponentMenu()
{
VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow<VideoSubWindow>();
if( pcSubWindow == nullptr )
{
m_menuComponent->setEnabled( false );
return;
}
const auto* frame = pcSubWindow->getCurrFrame();
if( frame == nullptr )
{
m_menuComponent->setEnabled( false );
return;
}
m_menuComponent->setEnabled( true );
for( int i = 1; i < m_actionGroupComponent->actions().size(); i++ )
{
m_actionGroupComponent->actions()[i]->setChecked( false );
m_actionGroupComponent->actions()[i]->setVisible( false );
}
switch( frame->getColorSpace() )
{
case CLP_COLOR_GRAY:
m_actionGroupComponent->actions().at( 1 )->setText( QStringLiteral( "Gray" ) );
m_actionGroupComponent->actions().at( 1 )->setVisible( true );
break;
case CLP_COLOR_YUV:
m_actionGroupComponent->actions().at( 1 )->setText( QStringLiteral( "Luminance" ) );
m_actionGroupComponent->actions().at( 1 )->setVisible( true );
m_actionGroupComponent->actions().at( 2 )->setText( QStringLiteral( "Chrominance U (Cb)" ) );
m_actionGroupComponent->actions().at( 2 )->setVisible( true );
m_actionGroupComponent->actions().at( 3 )->setText( QStringLiteral( "Chrominance V (Cr)" ) );
m_actionGroupComponent->actions().at( 3 )->setVisible( true );
break;
case CLP_COLOR_RGBA:
m_actionGroupComponent->actions().at( 4 )->setText( QStringLiteral( "Alpha" ) );
m_actionGroupComponent->actions().at( 4 )->setVisible( true );
[[fallthrough]];
case CLP_COLOR_RGB:
m_actionGroupComponent->actions().at( 1 )->setText( QStringLiteral( "Red" ) );
m_actionGroupComponent->actions().at( 1 )->setVisible( true );
m_actionGroupComponent->actions().at( 2 )->setText( QStringLiteral( "Green" ) );
m_actionGroupComponent->actions().at( 2 )->setVisible( true );
m_actionGroupComponent->actions().at( 3 )->setText( QStringLiteral( "Blue" ) );
m_actionGroupComponent->actions().at( 3 )->setVisible( true );
break;
default:
Q_ASSERT( false );
}
auto component = pcSubWindow->getViewArea()->getFilteredChannel();
int idx = component.has_value() ? *component : 0;
m_actionGroupComponent->actions().at( idx )->setChecked( true );
}
void VideoHandle::updateMenus() void VideoHandle::updateMenus()
{ {
VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow<VideoSubWindow>(); VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow<VideoSubWindow>();
@@ -296,6 +375,8 @@ void VideoHandle::updateMenus()
m_arrayActions[SELECTION_TOOL_ACT]->setEnabled( hasSubWindow ); m_arrayActions[SELECTION_TOOL_ACT]->setEnabled( hasSubWindow );
m_arrayActions[BLOCK_SELECTION_TOOL_ACT]->setEnabled( hasSubWindow ); m_arrayActions[BLOCK_SELECTION_TOOL_ACT]->setEnabled( hasSubWindow );
m_arrayActions[SHOW_GRID_ACT]->setEnabled( hasSubWindow ); m_arrayActions[SHOW_GRID_ACT]->setEnabled( hasSubWindow );
updateComponentMenu();
} }
void VideoHandle::readSettings() void VideoHandle::readSettings()
@@ -860,6 +941,20 @@ void VideoHandle::videoSelectionButtonEvent()
} }
} }
void VideoHandle::setComponent( int component )
{
if( m_pcCurrentVideoSubWindow == nullptr )
return;
if( component < 0 )
{
m_pcCurrentVideoSubWindow->getViewArea()->clearFilteredChannel();
}
else
{
m_pcCurrentVideoSubWindow->getViewArea()->setFilteredChannel( static_cast<std::size_t>( component ) );
}
}
void VideoHandle::setTool( int tool ) void VideoHandle::setTool( int tool )
{ {
m_uiViewTool = tool; m_uiViewTool = tool;
+7
View File
@@ -97,6 +97,11 @@ private:
QSlider* m_pcFrameSlider; QSlider* m_pcFrameSlider;
FrameNumberWidget* m_pcFrameNumInfo; FrameNumberWidget* m_pcFrameNumInfo;
// Filter component actions
QMenu* m_menuComponent;
QActionGroup* m_actionGroupComponent;
QSignalMapper* m_mapperComponent;
// Tools Actions // Tools Actions
QActionGroup* m_actionGroupTools; QActionGroup* m_actionGroupTools;
QSignalMapper* m_mapperTools; QSignalMapper* m_mapperTools;
@@ -131,6 +136,7 @@ private:
void calculateRealFrameRate(); void calculateRealFrameRate();
unsigned long getMaxFrameNumber(); unsigned long getMaxFrameNumber();
void setTimerStatus(); void setTimerStatus();
void updateComponentMenu();
Q_SIGNALS: Q_SIGNALS:
void changed(); void changed();
@@ -150,6 +156,7 @@ private Q_SLOTS:
void seekEvent( int direction ); void seekEvent( int direction );
void seekVideo(); void seekVideo();
void videoSelectionButtonEvent(); void videoSelectionButtonEvent();
void setComponent( int component );
void setTool( int tool ); void setTool( int tool );
void toggleGrid( bool checked ); void toggleGrid( bool checked );
void setGridSize( int size ); void setGridSize( int size );
+1 -1
View File
@@ -121,7 +121,7 @@ void VideoStreamSubWindow::updateVideoWindowInfo()
} }
} }
} }
if( m_pcDisplayModule->getModuleRequirements() & ClpModuleFeature::HasInfo ) if( m_pcDisplayModule->hasFeature( ClpModuleFeature::HasInfo ) )
{ {
QStringList list = QString::fromStdString( m_pcDisplayModule->moduleInfo() ).split( '\n' ); QStringList list = QString::fromStdString( m_pcDisplayModule->moduleInfo() ).split( '\n' );
windowInfoList.append( list ); windowInfoList.append( list );
+15 -22
View File
@@ -156,7 +156,7 @@ void VideoSubWindow::keyPressEvent( QKeyEvent* event )
{ {
if( m_pcDisplayModule ) if( m_pcDisplayModule )
{ {
if( m_pcDisplayModule->getModuleRequirements().is_set( ClpModuleFeature::KeysShortcuts ) ) if( m_pcDisplayModule->hasFeature( ClpModuleFeature::KeysShortcuts ) )
{ {
bool bRet = false; bool bRet = false;
switch( event->key() ) switch( event->key() )
@@ -396,7 +396,7 @@ QSize VideoSubWindow::getScrollSize()
return QSize( m_pcScrollArea->viewport()->size().width() - 5, m_pcScrollArea->viewport()->size().height() - 5 ); return QSize( m_pcScrollArea->viewport()->size().width() - 5, m_pcScrollArea->viewport()->size().height() - 5 );
} }
void VideoSubWindow::adjustScrollBarToRatio( const double& horRatio, const double& verRatio ) void VideoSubWindow::adjustScrollBarToRatio( const double horRatio, const double verRatio )
{ {
QScrollBar* scrollBarH = m_pcScrollArea->horizontalScrollBar(); QScrollBar* scrollBarH = m_pcScrollArea->horizontalScrollBar();
QScrollBar* scrollBarV = m_pcScrollArea->verticalScrollBar(); QScrollBar* scrollBarV = m_pcScrollArea->verticalScrollBar();
@@ -455,19 +455,19 @@ void VideoSubWindow::adjustScrollBarByScale( double scale, QPoint center )
void VideoSubWindow::updateScrollValues() void VideoSubWindow::updateScrollValues()
{ {
double xPos = m_pcScrollArea->horizontalScrollBar()->value(); auto xPos = m_pcScrollArea->horizontalScrollBar()->value();
double yPos = m_pcScrollArea->verticalScrollBar()->value(); auto yPos = m_pcScrollArea->verticalScrollBar()->value();
m_cCurrScroll.setX( xPos != 0 ); m_cCurrScroll.setX( xPos );
m_cCurrScroll.setY( yPos != 0 ); m_cCurrScroll.setY( yPos );
m_dHorScroll = m_dVerScroll = 0; m_dHorScroll = m_dVerScroll = 0;
if( xPos != 0 ) if( xPos != 0 )
m_dHorScroll = xPos / double( m_pcScrollArea->horizontalScrollBar()->maximum() ); m_dHorScroll = static_cast<double>( xPos ) / static_cast<double>( m_pcScrollArea->horizontalScrollBar()->maximum() );
if( yPos != 0 ) if( yPos != 0 )
m_dVerScroll = yPos / double( m_pcScrollArea->verticalScrollBar()->maximum() ); m_dVerScroll = static_cast<double>( yPos ) / static_cast<double>( m_pcScrollArea->verticalScrollBar()->maximum() );
} }
void VideoSubWindow::normalSize() void VideoSubWindow::normalSize()
@@ -476,8 +476,7 @@ void VideoSubWindow::normalSize()
double curFactor = getScaleFactor(); double curFactor = getScaleFactor();
if( factor != curFactor ) if( factor != curFactor )
{ {
double usedScale; double usedScale = m_cViewArea->scaleZoomFactor( factor / curFactor, QPoint(), QSize() );
usedScale = m_cViewArea->scaleZoomFactor( factor / curFactor, QPoint(), QSize() );
adjustScrollBarByScale( usedScale, QPoint() ); adjustScrollBarByScale( usedScale, QPoint() );
} }
} }
@@ -500,12 +499,11 @@ void VideoSubWindow::zoomToFactor( double factor, QPoint center )
void VideoSubWindow::scaleView( double scale, QPoint center ) void VideoSubWindow::scaleView( double scale, QPoint center )
{ {
Q_ASSERT( !m_cViewArea->image().isNull() ); if( scale == 1.0 )
if( scale != 1.0 ) return;
{
double usedScale = m_cViewArea->scaleZoomFactor( scale, center, getScrollSize() ); double usedScale = m_cViewArea->scaleZoomFactor( scale, center, getScrollSize() );
adjustScrollBarByScale( usedScale, center ); adjustScrollBarByScale( usedScale, center );
}
} }
void VideoSubWindow::scaleView( const QSize& size, QPoint center ) void VideoSubWindow::scaleView( const QSize& size, QPoint center )
@@ -521,12 +519,7 @@ void VideoSubWindow::scaleView( const QSize& size, QPoint center )
// Calc the zoom factor // Calc the zoom factor
double wfactor = (double)newSize.width() / imgViewSize.width(); double wfactor = (double)newSize.width() / imgViewSize.width();
double hfactor = (double)newSize.height() / imgViewSize.height(); double hfactor = (double)newSize.height() / imgViewSize.height();
double factor{ wfactor }; auto factor = std::min( wfactor, hfactor );
if( wfactor < hfactor )
factor = wfactor;
else
factor = hfactor;
double curFactor = getScaleFactor(); double curFactor = getScaleFactor();
if( factor != curFactor ) if( factor != curFactor )
+3 -3
View File
@@ -135,7 +135,7 @@ public:
void setFillWindow( bool bFlag ); void setFillWindow( bool bFlag );
void adjustScrollBarToRatio( const double& horRatio, const double& verRatio ); void adjustScrollBarToRatio( const double horRatio, const double verRatio );
private: private:
bool hasRunningModule(); bool hasRunningModule();
@@ -177,8 +177,8 @@ protected:
private: private:
QScrollArea* m_pcScrollArea; QScrollArea* m_pcScrollArea;
QPoint m_cCurrScroll; QPoint m_cCurrScroll;
double m_dHorScroll; double m_dHorScroll{ 0 };
double m_dVerScroll; double m_dVerScroll{ 0 };
ViewArea* m_cViewArea; ViewArea* m_cViewArea;
QRect m_cSelectedArea; QRect m_cSelectedArea;
VideoSubWindow* m_pcReferenceSubWindow; VideoSubWindow* m_pcReferenceSubWindow;
+98 -54
View File
@@ -25,6 +25,7 @@
#include "ViewArea.h" #include "ViewArea.h"
#include <qcolor.h>
#include <qnamespace.h> #include <qnamespace.h>
#include <QColor> #include <QColor>
@@ -42,9 +43,17 @@
#include "GridManager.h" #include "GridManager.h"
static const QColor selectionColor = Qt::cyan; #if QT_VERSION >= QT_VERSION_CHECK( 5, 14, 0 )
static const QColor imageMaskColor = Qt::green; constexpr auto kSelectionColor = QColorConstants::Cyan;
static const QColor eraserColor = Qt::red; constexpr auto kImageMaskColor = QColorConstants::Green;
constexpr auto kEraserColor = QColorConstants::Red;
#else
static const QColor kSelectionColor = Qt::cyan;
static const QColor kImageMaskColor = Qt::green;
static const QColor kEraserColor = Qt::red;
#endif
constexpr double kMaxZoom = 100.0;
constexpr double kMinZoom = 0.01;
ViewArea::ViewArea( QWidget* parent ) ViewArea::ViewArea( QWidget* parent )
: QWidget( parent ) : QWidget( parent )
@@ -53,15 +62,6 @@ ViewArea::ViewArea( QWidget* parent )
m_grid = GridManager(); m_grid = GridManager();
m_mask = QBitmap(); m_mask = QBitmap();
m_selectedArea = QRect(); m_selectedArea = QRect();
m_dZoomFactor = 1;
m_xOffset = 0;
m_yOffset = 0;
m_mode = NormalMode;
m_eTool = NavigationTool;
m_bGridVisible = false;
m_snapToGrid = false;
m_blockTrackEnable = false;
m_visibleZoomRect = true;
m_zoomWinTimer.setSingleShot( true ); m_zoomWinTimer.setSingleShot( true );
m_zoomWinTimer.setInterval( 2000 ); m_zoomWinTimer.setInterval( 2000 );
@@ -72,8 +72,17 @@ void ViewArea::setImage( std::shared_ptr<CalypFrame> frame )
{ {
m_nextFrame = frame; m_nextFrame = frame;
m_uiPixelHalfScale = 1 << ( m_nextFrame->getBitsPel() - 1 ); m_uiPixelHalfScale = 1 << ( m_nextFrame->getBitsPel() - 1 );
m_nextFrame->fillRGBBuffer(); if( m_filterSingleChannel.has_value() )
m_image = QImage( m_nextFrame->getRGBBuffer(), {
m_nextFrame->fillRGBBuffer( m_filterSingleChannel );
}
else
{
m_nextFrame->fillRGBBuffer();
}
auto rgb_buffer = *m_nextFrame->getRGBBuffer();
m_image = QImage( rgb_buffer.data(),
m_nextFrame->getWidth(), m_nextFrame->getWidth(),
m_nextFrame->getHeight(), m_nextFrame->getHeight(),
QImage::Format_ARGB32 ); QImage::Format_ARGB32 );
@@ -86,14 +95,49 @@ void ViewArea::setImage( std::shared_ptr<CalypFrame> frame )
initZoomWinRect(); initZoomWinRect();
} }
void ViewArea::clear() // void ViewArea::clear()
// {
// m_image = QImage();
// m_mask = QBitmap();
// m_mode = NormalMode;
// updateSize();
// update();
// updateGeometry();
// }
auto ViewArea::getFilteredChannel() -> std::optional<std::size_t>
{ {
m_image = QImage(); return m_filterSingleChannel;
m_mask = QBitmap(); }
m_mode = NormalMode;
updateSize(); void ViewArea::setFilteredChannel( std::size_t channel )
{
m_filterSingleChannel = channel;
if( m_nextFrame != nullptr )
{
m_nextFrame->fillRGBBuffer( m_filterSingleChannel );
auto rgb_buffer = *m_nextFrame->getRGBBuffer();
m_image = QImage( rgb_buffer.data(),
m_nextFrame->getWidth(),
m_nextFrame->getHeight(),
QImage::Format_ARGB32 );
}
update();
}
void ViewArea::clearFilteredChannel()
{
m_filterSingleChannel = {};
if( m_nextFrame != nullptr )
{
m_nextFrame->fillRGBBuffer( m_filterSingleChannel );
auto rgb_buffer = *m_nextFrame->getRGBBuffer();
m_image = QImage( rgb_buffer.data(),
m_nextFrame->getWidth(),
m_nextFrame->getHeight(),
QImage::Format_ARGB32 );
}
update(); update();
updateGeometry();
} }
void ViewArea::setTool( unsigned int view ) void ViewArea::setTool( unsigned int view )
@@ -161,14 +205,14 @@ void ViewArea::setZoomFactor( double f )
double ViewArea::scaleZoomFactor( double scale, QPoint center, QSize minimumSize ) double ViewArea::scaleZoomFactor( double scale, QPoint center, QSize minimumSize )
{ {
double maxZoom = 100.0; Q_ASSERT( !m_image.isNull() );
double minZoom = 0.01; //( 1.0 / m_image.width() );
double new_scale = 1.0; double new_scale = 1.0;
if( ( m_dZoomFactor == minZoom ) && ( scale < 1 ) ) if( ( m_dZoomFactor == kMinZoom ) && ( scale < 1 ) )
return new_scale; return new_scale;
if( ( m_dZoomFactor == maxZoom ) && ( scale > 1 ) ) if( ( m_dZoomFactor == kMaxZoom ) && ( scale > 1 ) )
return new_scale; return new_scale;
double newZoomFactor = m_dZoomFactor * scale * 100.0; double newZoomFactor = m_dZoomFactor * scale * 100.0;
@@ -209,16 +253,16 @@ double ViewArea::scaleZoomFactor( double scale, QPoint center, QSize minimumSize
new_scale = scale; new_scale = scale;
if( newZoomFactor < minZoom ) if( newZoomFactor < kMinZoom )
{ {
newZoomFactor = minZoom; newZoomFactor = kMinZoom;
new_scale = newZoomFactor / m_dZoomFactor; new_scale = newZoomFactor / m_dZoomFactor;
} }
else else
{ {
if( newZoomFactor > maxZoom ) if( newZoomFactor > kMaxZoom )
{ {
newZoomFactor = maxZoom; newZoomFactor = kMaxZoom;
new_scale = newZoomFactor / m_dZoomFactor; new_scale = newZoomFactor / m_dZoomFactor;
} }
} }
@@ -474,12 +518,12 @@ void ViewArea::paintEvent( QPaintEvent* event )
// Draw a border around the image. // Draw a border around the image.
/* if( m_xOffset || m_yOffset ) /* if( m_xOffset || m_yOffset )
{ {
painter.setPen( Qt::black ); painter.setPen( Qt::black );
painter.drawRect( m_xOffset - 1, m_yOffset - 1, m_image.width() * painter.drawRect( m_xOffset - 1, m_yOffset - 1, m_image.width() *
m_dZoomFactor + 1, m_image.height() * m_dZoomFactor + 1, m_image.height() *
m_dZoomFactor + 1 ); m_dZoomFactor + 1 );
}*/ }*/
int frFormat = m_currFrame->getColorSpace(); int frFormat = m_currFrame->getColorSpace();
@@ -567,16 +611,16 @@ void ViewArea::paintEvent( QPaintEvent* event )
QRect vr = windowToView( winRect ); QRect vr = windowToView( winRect );
QRect cVisibleImg = vr & cImg; QRect cVisibleImg = vr & cImg;
//cVisibleImg.moveTopLeft(vr.topLeft()); // cVisibleImg.moveTopLeft(vr.topLeft());
QRect cVisibleWinRect; QRect cVisibleWinRect;
cVisibleWinRect.setLeft( floor( (double)cVisibleImg.x() / dRatio ) ); cVisibleWinRect.setLeft( floor( (double)cVisibleImg.x() / dRatio ) );
cVisibleWinRect.setTop( floor( (double)cVisibleImg.y() / dRatio ) ); cVisibleWinRect.setTop( floor( (double)cVisibleImg.y() / dRatio ) );
cVisibleWinRect.setRight( round( (double)cVisibleImg.right() / dRatio ) ); cVisibleWinRect.setRight( round( (double)cVisibleImg.right() / dRatio ) );
cVisibleWinRect.setBottom( round( (double)cVisibleImg.bottom() / dRatio ) ); cVisibleWinRect.setBottom( round( (double)cVisibleImg.bottom() / dRatio ) );
//painter.fillRect( cImgWinRect, QBrush( QColor( 128, 128, 128, 128 ) ) ); // painter.fillRect( cImgWinRect, QBrush( QColor( 128, 128, 128, 128 ) ) );
painter.setPen( QColor( 50, 50, 50, 128 ) ); painter.setPen( QColor( 50, 50, 50, 128 ) );
//painter.drawRect( cImgWinRect ); // painter.drawRect( cImgWinRect );
painter.setOpacity( 0.7 ); painter.setOpacity( 0.7 );
painter.drawImage( cImgWinRect, m_image ); painter.drawImage( cImgWinRect, m_image );
painter.setOpacity( 1 ); painter.setOpacity( 1 );
@@ -599,7 +643,7 @@ void ViewArea::paintEvent( QPaintEvent* event )
painter.setPen( QColor( 255, 255, 255, 128 ) ); painter.setPen( QColor( 255, 255, 255, 128 ) );
painter.drawRect( cVisibleWinRect ); painter.drawRect( cVisibleWinRect );
//qDebug() << "Debug VisibleZoomRect: " << winRect << vr << cImgWinRect << cVisibleWinRect << cVisibleImg << dRatio; // qDebug() << "Debug VisibleZoomRect: " << winRect << vr << cImgWinRect << cVisibleWinRect << cVisibleImg << dRatio;
} }
QRect sr = viewToWindow( m_selectedArea ); QRect sr = viewToWindow( m_selectedArea );
@@ -610,7 +654,7 @@ void ViewArea::paintEvent( QPaintEvent* event )
if( m_newShape || m_blockTrackEnable ) if( m_newShape || m_blockTrackEnable )
{ {
// Set the tool color // Set the tool color
QColor selectColor = selectionColor; QColor selectColor = kSelectionColor;
selectColor.setAlpha( 120 ); selectColor.setAlpha( 120 );
@@ -664,7 +708,7 @@ void ViewArea::paintEvent( QPaintEvent* event )
if( m_maskColor.isValid() ) if( m_maskColor.isValid() )
color = m_maskColor; color = m_maskColor;
else else
color = imageMaskColor; color = kImageMaskColor;
color.setAlpha( 120 ); color.setAlpha( 120 );
painter.setPen( color ); painter.setPen( color );
@@ -684,16 +728,16 @@ void ViewArea::paintEvent( QPaintEvent* event )
if( m_maskColor.isValid() ) if( m_maskColor.isValid() )
color = m_maskColor; color = m_maskColor;
else else
color = imageMaskColor; color = kImageMaskColor;
break; break;
} }
case EraserTool: { case EraserTool: {
color = eraserColor; color = kEraserColor;
break; break;
} }
default: default:
color = selectionColor; // ?Problems! color = kSelectionColor; // ?Problems!
} }
color.setAlpha( 120 ); color.setAlpha( 120 );
@@ -898,18 +942,18 @@ void ViewArea::mouseMoveEvent( QMouseEvent* event )
} }
} }
/* else // if tool() == BlockSelectionTool || MaskTool || EraserTool /* else // if tool() == BlockSelectionTool || MaskTool || EraserTool
{ {
m_blockTrackEnable = false; m_blockTrackEnable = false;
// If cursor is inside the selected area, we most redraw // If cursor is inside the selected area, we most redraw
// the selection rect because it may be smaller. // the selection rect because it may be smaller.
if( m_selectedArea.contains( actualPos ) ) if( m_selectedArea.contains( actualPos ) )
{ {
m_selectedArea = m_grid.rectContains( m_lastPos ); m_selectedArea = m_grid.rectContains( m_lastPos );
} }
m_selectedArea = m_selectedArea.united( m_grid.rectContains( actualPos ) ); m_selectedArea = m_selectedArea.united( m_grid.rectContains( actualPos ) );
} }
*/ */
if( tool() == SelectionTool ) if( tool() == SelectionTool )
{ {
// intercept the selected area with the image area to limit the // intercept the selected area with the image area to limit the
+22 -23
View File
@@ -56,17 +56,15 @@ public:
ViewArea( QWidget* parent = 0 ); ViewArea( QWidget* parent = 0 );
QImage& image() { return m_image; };
void setImage( std::shared_ptr<CalypFrame> frame ); void setImage( std::shared_ptr<CalypFrame> frame );
auto getFilteredChannel() -> std::optional<std::size_t>;
void setFilteredChannel( std::size_t channel );
void clearFilteredChannel();
void setMode( int mode ); void setMode( int mode );
void setMaskColor( const QColor& color = QColor() ); void setMaskColor( const QColor& color = QColor() );
/**
* Clears any contents.
*/
void clear();
/** /**
* Select tool from the menu * Select tool from the menu
*/ */
@@ -108,12 +106,12 @@ public Q_SLOTS:
// void setSelectedArea( QRect &rect ); // void setSelectedArea( QRect &rect );
protected: protected:
void paintEvent( QPaintEvent* event ); void paintEvent( QPaintEvent* event ) override;
void resizeEvent( QResizeEvent* event ); void resizeEvent( QResizeEvent* event ) override;
void mousePressEvent( QMouseEvent* event ); void mousePressEvent( QMouseEvent* event ) override;
void mouseMoveEvent( QMouseEvent* event ); void mouseMoveEvent( QMouseEvent* event ) override;
void mouseReleaseEvent( QMouseEvent* event ); void mouseReleaseEvent( QMouseEvent* event ) override;
void wheelEvent( QWheelEvent* event ); void wheelEvent( QWheelEvent* event ) override;
void updateSize(); void updateSize();
void updateOffset(); void updateOffset();
@@ -149,34 +147,35 @@ private:
QRect viewToWindow( const QRect& rc ) const; QRect viewToWindow( const QRect& rc ) const;
std::shared_ptr<CalypFrame> m_currFrame; std::shared_ptr<CalypFrame> m_currFrame;
QImage m_image;
std::shared_ptr<CalypFrame> m_nextFrame; std::shared_ptr<CalypFrame> m_nextFrame;
std::optional<std::size_t> m_filterSingleChannel;
ClpPel m_uiPixelHalfScale; ClpPel m_uiPixelHalfScale;
Tool m_eTool; Tool m_eTool{ NavigationTool };
bool m_bGridVisible; bool m_bGridVisible{ false };
QTimer m_zoomWinTimer; QTimer m_zoomWinTimer;
double m_dZoomWinRatio; double m_dZoomWinRatio;
double m_dZoomFactor; double m_dZoomFactor{ 1.0 };
QImage m_image; // QPixmap m_pixmap;
//QPixmap m_pixmap;
QBitmap m_mask; QBitmap m_mask;
QRect m_selectedArea; QRect m_selectedArea;
QPoint m_lastPos; QPoint m_lastPos;
QPoint m_lastWindowPos; QPoint m_lastWindowPos;
GridManager m_grid; GridManager m_grid;
ViewMode m_mode; ViewMode m_mode{ NormalMode };
QColor m_maskColor; QColor m_maskColor;
int m_xOffset; int m_xOffset{ 0 };
int m_yOffset; int m_yOffset{ 0 };
bool m_blockTrackEnable; bool m_blockTrackEnable{ false };
bool m_newShape; bool m_newShape;
bool m_snapToGrid; bool m_snapToGrid{ false };
bool m_cursorInGrid; bool m_cursorInGrid;
bool m_visibleZoomRect; bool m_visibleZoomRect{ true };
}; };
#endif // __VIEWAREA_H__ #endif // __VIEWAREA_H__
+1 -3
View File
@@ -22,7 +22,7 @@ SET(Calyp_Lib_Stream_SRCS
SET(Calyp_Lib_OptionParser_SRCS CalypOptions.h CalypOptions.cpp) SET(Calyp_Lib_OptionParser_SRCS CalypOptions.h CalypOptions.cpp)
SET(Calyp_Lib_Modules_SRCS CalypOptions.h CalypOptions.cpp) SET(Calyp_Lib_Modules_SRCS CalypModuleIf.h CalypModuleIf.cpp)
SET(Calyp_Lib_SRCS CalypLib.h CalypDefs.h ${Calyp_Lib_Frame_SRCS} ${Calyp_Lib_Stream_SRCS} ${Calyp_Lib_OptionParser_SRCS} ${Calyp_Lib_Modules_SRCS}) SET(Calyp_Lib_SRCS CalypLib.h CalypDefs.h ${Calyp_Lib_Frame_SRCS} ${Calyp_Lib_Stream_SRCS} ${Calyp_Lib_OptionParser_SRCS} ${Calyp_Lib_Modules_SRCS})
@@ -44,8 +44,6 @@ IF(USE_OPENCV)
LIST(APPEND Calyp_Lib_SRCS StreamHandlerOpenCV.h) LIST(APPEND Calyp_Lib_SRCS StreamHandlerOpenCV.h)
LIST(APPEND Calyp_Lib_SRCS StreamHandlerOpenCV.cpp) LIST(APPEND Calyp_Lib_SRCS StreamHandlerOpenCV.cpp)
LIST(APPEND Calyp_Lib_SRCS CalypOpenCVModuleIf.cpp)
LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${OpenCV_LIBRARIES}) LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${OpenCV_LIBRARIES})
LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${OpenCV_INCLUDE_DIRS}) LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${OpenCV_INCLUDE_DIRS})
+1 -1
View File
@@ -20,7 +20,7 @@
/** /**
* \file CalypDefs.h * \file CalypDefs.h
* \ingroup CalypLibGrp * \ingroup CalypLibGrp
* \brief Define basic types, new types and enumerations * \brief Define basic types, new types and enumerations (private use only)
*/ */
#ifndef __CALYPDEFS_H__ #ifndef __CALYPDEFS_H__
+49 -21
View File
@@ -24,6 +24,7 @@
#include "CalypFrame.h" #include "CalypFrame.h"
#include <algorithm>
#include <array> #include <array>
#include <cassert> #include <cassert>
#include <cmath> #include <cmath>
@@ -96,7 +97,7 @@ auto CalypFrame::findPixelFormat( const std::string_view name ) -> std::optional
return {}; return {};
} }
auto CalypFrame::pelformatColorSpace( ClpPixelFormats idx ) -> int auto CalypFrame::pelFormatColorSpace( ClpPixelFormats idx ) -> int
{ {
return g_CalypPixFmtDescriptorsMap.at( idx ).colorSpace; return g_CalypPixFmtDescriptorsMap.at( idx ).colorSpace;
} }
@@ -535,13 +536,13 @@ ClpPel*** CalypFrame::getPelBufferYUV()
return d->m_pppcInputPel; return d->m_pppcInputPel;
} }
auto CalypFrame::getRGBBuffer() const -> const unsigned char* auto CalypFrame::getRGBBuffer() const -> std::optional<std::span<const std::uint8_t>>
{ {
if( d->m_bHasRGBPel ) if( !d->m_bHasRGBPel )
{ {
return d->m_pcARGB32.data(); return std::nullopt;
} }
return NULL; return std::span{ d->m_pcARGB32 };
} }
ClpPel CalypFrame::operator()( unsigned int ch, unsigned int xPos, unsigned int yPos, bool absolute ) const ClpPel CalypFrame::operator()( unsigned int ch, unsigned int xPos, unsigned int yPos, bool absolute ) const
@@ -782,18 +783,20 @@ inline constexpr auto convert_to_pel_argb( const T r, const T g, const T b ) ->
template <typename T> template <typename T>
inline constexpr void convert_yuv_to_rgb( const T iY, const T iU, const T iV, T& iR, T& iG, T& iB ) inline constexpr void convert_yuv_to_rgb( const T iY, const T iU, const T iV, T& iR, T& iG, T& iB )
{ {
auto clamp_pel_value = []( auto X ) {if( X < 0 ) auto clamp_pel_value = []( auto X ) {
return 0; if( X < 0 )
if( X > 255 ) return 0;
return 255; if( X > 255 )
return X; }; return 255;
return X;
};
iR = iY + ( ( 1436 * ( iV - 128 ) ) >> 10 ); iR = iY + ( ( 1436 * ( iV - 128 ) ) >> 10 );
iG = iY - ( ( 352 * ( iU - 128 ) + 731 * ( iV - 128 ) ) >> 10 ); iG = iY - ( ( 352 * ( iU - 128 ) + 731 * ( iV - 128 ) ) >> 10 );
iB = iY + ( ( 1812 * ( iU - 128 ) ) >> 10 ); iB = iY + ( ( 1812 * ( iU - 128 ) ) >> 10 );
clamp_pel_value( iR ); iR = clamp_pel_value( iR );
clamp_pel_value( iG ); iG = clamp_pel_value( iG );
clamp_pel_value( iB ); iB = clamp_pel_value( iB );
} }
void fillRGBBufferYUV420p( ClpPel*** pppInputPel, uint32_t* pARGB, unsigned uiWidth, unsigned uiHeight, int shiftBits ) void fillRGBBufferYUV420p( ClpPel*** pppInputPel, uint32_t* pARGB, unsigned uiWidth, unsigned uiHeight, int shiftBits )
@@ -828,25 +831,42 @@ void fillRGBBufferYUV420p( ClpPel*** pppInputPel, uint32_t* pARGB, unsigned uiWi
} }
} }
void CalypFrame::fillRGBBuffer() const void CalypFrame::fillRGBBuffer( std::optional<std::size_t> channel ) const
{ {
if( d->m_bHasRGBPel ) auto shiftBits = static_cast<int>( d->m_uiBitsPel ) - 8;
return;
int shiftBits = d->m_uiBitsPel - 8;
d->m_bHasRGBPel = true; d->m_bHasRGBPel = true;
// 4 bytes for A, R, G and B // 4 bytes for A, R, G and B
uint32_t* pARGB = (uint32_t*)d->m_pcARGB32.data(); uint32_t* pARGB = (uint32_t*)d->m_pcARGB32.data();
if( d->m_pcPelFormat->colorSpace == CLP_COLOR_GRAY ) if( d->m_pcPelFormat->colorSpace == CLP_COLOR_GRAY || ( channel.has_value() && *channel == 0 ) )
{ {
ClpPel* pY = d->m_pppcInputPel[CLP_LUMA][0]; ClpPel* pY = d->m_pppcInputPel[0][0];
unsigned char finalPel{ 0 };
for( unsigned int i = 0; i < d->m_uiHeight * d->m_uiWidth; i++ ) for( unsigned int i = 0; i < d->m_uiHeight * d->m_uiWidth; i++ )
{ {
finalPel = ( *pY++ ) >> shiftBits; unsigned char finalPel = ( *pY++ ) >> shiftBits;
*pARGB++ = convert_to_pel_argb( finalPel, finalPel, finalPel ); *pARGB++ = convert_to_pel_argb( finalPel, finalPel, finalPel );
} }
} }
else if( channel.has_value() && *channel > 0 )
{
ClpPel* pLine = d->m_pppcInputPel[*channel][0];
for( unsigned y = 0; y < CHROMASHIFT( d->m_uiHeight, d->m_pcPelFormat->log2ChromaHeight ); y++ )
{
for( int i = 0; i < 1 << d->m_pcPelFormat->log2ChromaHeight; i++ )
{
ClpPel* pPel = pLine;
for( unsigned x = 0; x < CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth ); x++ )
{
unsigned char finalPel = ( *pPel++ ) >> shiftBits;
for( int j = 0; j < ( 1 << d->m_pcPelFormat->log2ChromaWidth ); j++ )
{
*pARGB++ = convert_to_pel_argb( finalPel, finalPel, finalPel );
}
}
}
pLine += CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth );
}
}
else if( d->m_pcPelFormat->colorSpace == CLP_COLOR_RGB ) else if( d->m_pcPelFormat->colorSpace == CLP_COLOR_RGB )
{ {
ClpPel* pR = d->m_pppcInputPel[CLP_COLOR_R][0]; ClpPel* pR = d->m_pppcInputPel[CLP_COLOR_R][0];
@@ -910,6 +930,14 @@ void CalypFrame::fillRGBBuffer() const
} }
} }
void CalypFrame::fillRGBBuffer() const
{
if( d->m_bHasRGBPel )
return;
fillRGBBuffer( {} );
}
/** /**
* Histogram * Histogram
*/ */
+4 -3
View File
@@ -26,7 +26,7 @@
#ifndef __CALYPFRAME_H__ #ifndef __CALYPFRAME_H__
#define __CALYPFRAME_H__ #define __CALYPFRAME_H__
#include <cstdint> #include <array>
#include <map> #include <map>
#include <memory> #include <memory>
#include <optional> #include <optional>
@@ -222,7 +222,7 @@ public:
static constexpr auto numberOfFormats() -> std::size_t; static constexpr auto numberOfFormats() -> std::size_t;
static auto findPixelFormat( const std::string& name ) -> std::optional<ClpPixelFormats>; static auto findPixelFormat( const std::string& name ) -> std::optional<ClpPixelFormats>;
static auto findPixelFormat( const std::string_view name ) -> std::optional<ClpPixelFormats>; static auto findPixelFormat( const std::string_view name ) -> std::optional<ClpPixelFormats>;
static auto pelformatColorSpace( ClpPixelFormats idx ) -> int; static auto pelFormatColorSpace( ClpPixelFormats idx ) -> int;
static auto supportedPixelFormatListNames() -> std::map<ClpPixelFormats, std::string_view>; static auto supportedPixelFormatListNames() -> std::map<ClpPixelFormats, std::string_view>;
static auto supportedPixelFormatListNames( int colorSpace ) -> std::map<ClpPixelFormats, std::string_view>; static auto supportedPixelFormatListNames( int colorSpace ) -> std::map<ClpPixelFormats, std::string_view>;
static auto pixelFormatName( ClpPixelFormats idx ) -> const std::string_view; static auto pixelFormatName( ClpPixelFormats idx ) -> const std::string_view;
@@ -416,7 +416,7 @@ public:
ClpPel*** getPelBufferYUV() const; ClpPel*** getPelBufferYUV() const;
ClpPel*** getPelBufferYUV(); ClpPel*** getPelBufferYUV();
auto getRGBBuffer() const -> const unsigned char*; auto getRGBBuffer() const -> std::optional<std::span<const std::uint8_t>>;
/** /**
* Get pixel value at coordinates * Get pixel value at coordinates
@@ -492,6 +492,7 @@ public:
void frameFromBuffer( const std::vector<ClpByte>&, int ); void frameFromBuffer( const std::vector<ClpByte>&, int );
void frameToBuffer( std::vector<ClpByte>&, int ) const; void frameToBuffer( std::vector<ClpByte>&, int ) const;
void fillRGBBuffer( std::optional<std::size_t> channel ) const;
void fillRGBBuffer() const; void fillRGBBuffer() const;
/** /**
@@ -22,16 +22,19 @@
* \brief Calyp modules interface for OpenCV * \brief Calyp modules interface for OpenCV
*/ */
#include "CalypFrame.h"
#include "CalypModuleIf.h" #include "CalypModuleIf.h"
// OpenCV #include "CalypFrame.h"
#include <opencv2/opencv.hpp>
#include "PixelFormats.h" #include "PixelFormats.h"
#include "config.h"
#ifdef USE_OPENCV
#include <opencv2/opencv.hpp>
#endif
bool CalypOpenCVModuleIf::create( std::vector<CalypFrame*> apcFrameList ) bool CalypOpenCVModuleIf::create( std::vector<CalypFrame*> apcFrameList )
{ {
#ifdef USE_OPENCV
_BASIC_MODULE_API_2_CHECK_ _BASIC_MODULE_API_2_CHECK_
bool bRet = false; bool bRet = false;
std::vector<Mat> acMatList( apcFrameList.size() ); std::vector<Mat> acMatList( apcFrameList.size() );
@@ -51,10 +54,14 @@ bool CalypOpenCVModuleIf::create( std::vector<CalypFrame*> apcFrameList )
return false; return false;
} }
return bRet; return bRet;
#else
return false;
#endif
} }
CalypFrame* CalypOpenCVModuleIf::process( std::vector<CalypFrame*> apcFrameList ) CalypFrame* CalypOpenCVModuleIf::process( std::vector<CalypFrame*> apcFrameList )
{ {
#ifdef USE_OPENCV
m_pcOutputFrame->reset(); m_pcOutputFrame->reset();
std::vector<Mat> acMatList( apcFrameList.size() ); std::vector<Mat> acMatList( apcFrameList.size() );
for( unsigned i = 0; i < apcFrameList.size(); i++ ) for( unsigned i = 0; i < apcFrameList.size(); i++ )
@@ -64,8 +71,35 @@ CalypFrame* CalypOpenCVModuleIf::process( std::vector<CalypFrame*> apcFrameList
Mat* cvOutput = process_using_opencv( acMatList ); Mat* cvOutput = process_using_opencv( acMatList );
m_pcOutputFrame->fromMat( *cvOutput ); m_pcOutputFrame->fromMat( *cvOutput );
return m_pcOutputFrame.get(); return m_pcOutputFrame.get();
#else
return nullptr;
#endif
} }
void CalypOpenCVModuleIf::destroy() void CalypOpenCVModuleIf::destroy()
{ {
} }
ClpModuleFeature operator|( ClpModuleFeature lhs, ClpModuleFeature rhs )
{
return static_cast<ClpModuleFeature>(
static_cast<std::underlying_type_t<ClpModuleFeature>>( lhs ) |
static_cast<std::underlying_type_t<ClpModuleFeature>>( rhs ) );
}
ClpModuleFeature operator&( ClpModuleFeature lhs, ClpModuleFeature rhs )
{
return static_cast<ClpModuleFeature>(
static_cast<std::underlying_type_t<ClpModuleFeature>>( lhs ) &
static_cast<std::underlying_type_t<ClpModuleFeature>>( rhs ) );
}
auto CalypModuleIf::getModuleLongName() -> const char*
{
return m_pchModuleLongName ? m_pchModuleLongName : m_pchModuleName;
}
auto CalypModuleIf::has( ClpModuleFeature feature ) -> bool
{
return ( m_uiModuleRequirements & feature ) != ClpModuleFeature::None;
}
+16 -18
View File
@@ -35,7 +35,6 @@
*/ */
#include <memory> #include <memory>
#include <type_safe/flag_set.hpp>
#include <vector> #include <vector>
#include "CalypFrame.h" #include "CalypFrame.h"
@@ -95,19 +94,18 @@ enum class ClpModuleType : std::uint8_t
* Features/Requirements of a module * Features/Requirements of a module
* @see m_uiModuleRequirements * @see m_uiModuleRequirements
*/ */
enum class ClpModuleFeature enum class ClpModuleFeature : std::uint64_t
{ {
None, None = 0,
SkipWhilePlaying, SkipWhilePlaying = 1,
Options, Options = 2,
NewWindow, NewWindow = 4,
KeysShortcuts, KeysShortcuts = 8,
VariableNumOfFrames, VariableNumOfFrames = 16,
HasInfo, HasInfo = 32,
_flag_set_size
}; };
using ClpModuleFeatures = type_safe::flag_set<ClpModuleFeature>; auto operator|( ClpModuleFeature lhs, ClpModuleFeature rhs ) -> ClpModuleFeature;
enum Module_Key_Supported enum Module_Key_Supported
{ {
@@ -117,6 +115,8 @@ enum Module_Key_Supported
MODULE_KEY_DOWN, MODULE_KEY_DOWN,
}; };
class CalypFrame;
/** /**
* \class CalypModuleIf * \class CalypModuleIf
* \ingroup CalypLib Calyp_Modules * \ingroup CalypLib Calyp_Modules
@@ -134,10 +134,8 @@ public:
virtual ~CalypModuleIf() = default; virtual ~CalypModuleIf() = default;
virtual void destroy(){}; virtual void destroy(){};
const char* getModuleLongName() auto getModuleLongName() -> const char*;
{ auto has( ClpModuleFeature feature ) -> bool;
return m_pchModuleLongName ? m_pchModuleLongName : m_pchModuleName;
}
/** /**
* Module API version 1 * Module API version 1
@@ -175,7 +173,7 @@ public:
//! Number of frames //! Number of frames
unsigned int m_uiNumberOfFrames{ 1 }; unsigned int m_uiNumberOfFrames{ 1 };
//! Features/Requirements //! Features/Requirements
ClpModuleFeatures m_uiModuleRequirements{ ClpModuleFeature::None }; ClpModuleFeature m_uiModuleRequirements{ ClpModuleFeature::None };
unsigned int m_iFrameBufferCount{ 0 }; unsigned int m_iFrameBufferCount{ 0 };
@@ -197,7 +195,7 @@ class CalypOpenCVModuleIf : public CalypModuleIf
using Mat = cv::Mat; using Mat = cv::Mat;
public: public:
CalypOpenCVModuleIf() { m_bConvertToGray = false; }; CalypOpenCVModuleIf() = default;
virtual ~CalypOpenCVModuleIf() {} virtual ~CalypOpenCVModuleIf() {}
// Common API // Common API
@@ -216,7 +214,7 @@ public:
protected: protected:
// const char* m_pchPythonFunctionName; // const char* m_pchPythonFunctionName;
std::unique_ptr<CalypFrame> m_pcOutputFrame; std::unique_ptr<CalypFrame> m_pcOutputFrame;
bool m_bConvertToGray; bool m_bConvertToGray{ false };
}; };
using CalypModulePtr = std::unique_ptr<CalypModuleIf>; using CalypModulePtr = std::unique_ptr<CalypModuleIf>;
+2 -1
View File
@@ -38,12 +38,13 @@
#include "CalypOptions.h" #include "CalypOptions.h"
#include <cstring> #include <functional>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include "config.h" #include "config.h"
#include "lib/CalypFrame.h"
#include "lib/CalypModuleIf.h" #include "lib/CalypModuleIf.h"
struct ParseFailure : public std::exception struct ParseFailure : public std::exception
+2 -2
View File
@@ -42,10 +42,10 @@
#include <list> #include <list>
#include <map> #include <map>
#include <memory>
#include <string>
#include <vector> #include <vector>
#include "CalypDefs.h"
/** /**
* \class CalypOptions * \class CalypOptions
* \ingroup CalypLibGrp * \ingroup CalypLibGrp
+2
View File
@@ -149,6 +149,7 @@ auto CalypPixel::operator==( const CalypPixel& other ) const -> bool
std::ostream& operator<<( std::ostream& os, const CalypPixel& p ) std::ostream& operator<<( std::ostream& os, const CalypPixel& p )
{ {
#ifdef CLP_DEBUG
if( p.colorSpace() == CLP_COLOR_RGB || p.colorSpace() == CLP_COLOR_YUV ) if( p.colorSpace() == CLP_COLOR_RGB || p.colorSpace() == CLP_COLOR_YUV )
{ {
os << "(" << p[0] << ", " << p[1] << ", " << p[2] << ")"; os << "(" << p[0] << ", " << p[1] << ", " << p[2] << ")";
@@ -157,6 +158,7 @@ std::ostream& operator<<( std::ostream& os, const CalypPixel& p )
{ {
os << "(" << p[0] << ", " << p[1] << ", " << p[2] << ", " << p[3] << ")"; os << "(" << p[0] << ", " << p[1] << ", " << p[2] << ", " << p[3] << ")";
} }
#endif
return os; return os;
} }
+1 -1
View File
@@ -84,7 +84,7 @@ bool StreamHandlerPortableMap::openHandler( std::string strFilename, bool bInput
} }
else else
{ {
int colorSpace = CalypFrame::pelformatColorSpace( m_iPixelFormat ); int colorSpace = CalypFrame::pelFormatColorSpace( m_iPixelFormat );
m_iMaxValue = ( 1 << m_uiBitsPerPixel ) - 1; m_iMaxValue = ( 1 << m_uiBitsPerPixel ) - 1;
if( m_uiBitsPerPixel == 1 ) if( m_uiBitsPerPixel == 1 )
{ {
+1 -1
View File
@@ -62,7 +62,7 @@ bool StreamHandlerRaw::openHandler( std::string strFilename, bool bInput )
return false; return false;
} }
calculateFrameNumber(); calculateFrameNumber();
std::string fileExtension = std::filesystem::path{ strFilename }.extension(); std::string fileExtension = std::filesystem::path{ strFilename }.extension().string();
fileExtension.erase( fileExtension.begin() ); fileExtension.erase( fileExtension.begin() );
m_strFormatName = clpUppercase( fileExtension ); m_strFormatName = clpUppercase( fileExtension );
m_strCodecName = "Raw Video"; m_strCodecName = "Raw Video";
+3
View File
@@ -2,6 +2,9 @@
# CMakeLists for Calyp lis tests using catch2 # CMakeLists for Calyp lis tests using catch2
# #
FETCHCONTENT_MAKEAVAILABLE(Catch2)
SET(Calyp_Lib_Catch2_Tests_SRCS SET(Calyp_Lib_Catch2_Tests_SRCS
CalypLibTests.cpp CalypLibTests.cpp
CalypStreamTests.cpp CalypStreamTests.cpp
+35 -33
View File
@@ -24,9 +24,6 @@
#include "CalypModulesFactory.h" #include "CalypModulesFactory.h"
#include <cstring>
#include <functional>
#include "config.h" #include "config.h"
#ifdef USE_DYNLOAD #ifdef USE_DYNLOAD
#include <dlfcn.h> #include <dlfcn.h>
@@ -37,45 +34,50 @@
// Generated by cmake // Generated by cmake
#include "ModulesListHeader.h" #include "ModulesListHeader.h"
CalypModulesFactory::CalypModulesFactory(){ REGISTER_ALL_MODULES } CalypModulesFactory::CalypModulesFactory()
{
REGISTER_ALL_MODULES
}
void CalypModulesFactory::Register( const std::string& moduleName, std::function<CalypModulePtr( void )> pfnCreate )
void CalypModulesFactory::Register( const char* moduleName, CreateModuleFn pfnCreate )
{ {
m_FactoryMap[moduleName] = pfnCreate; m_FactoryMap[moduleName] = pfnCreate;
} }
bool CalypModulesFactory::RegisterDl( const char* dlName ) void CalypModulesFactory::Register( const char* moduleName, std::function<CalypModulePtr( void )> pfnCreate )
{ {
#ifdef USE_DYNLOAD Register( std::string{ moduleName }, pfnCreate );
void* pHndl = dlopen( dlName, RTLD_NOW );
if( pHndl == NULL )
{
std::cerr << dlerror() << std::endl;
return false;
}
CreateModuleFn pfnCreate = (CreateModuleFn)dlsym( pHndl, "Maker" );
if( pfnCreate == NULL )
{
return false;
}
Register( dlName, pfnCreate );
return true;
#else
return false;
#endif
} }
CalypModulePtr CalypModulesFactory::CreateModule( const char* moduleName ) bool CalypModulesFactory::RegisterDl( const char* dlName )
{ {
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); // #ifdef USE_DYNLOAD
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin(); // void* pHndl = dlopen( dlName, RTLD_NOW );
for( ; it != moduleFactoryMap.end(); ++it ) // if( pHndl == NULL )
// {
// std::cerr << dlerror() << std::endl;
// return false;
// }
// CreateModuleFn pfnCreate = (CreateModuleFn)dlsym( pHndl, "Maker" );
// if( pfnCreate == NULL )
// {
// return false;
// }
// Register( dlName, pfnCreate );
// return true;
// #else
return false;
// #endif
}
CalypModulePtr CalypModulesFactory::CreateModule( const std::string& moduleName ) const
{
const auto& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
if( moduleFactoryMap.contains( moduleName ) )
{ {
if( !strcmp( it->first, moduleName ) ) auto createFct = moduleFactoryMap.at( moduleName );
{ return createFct();
return it->second();
}
} }
return nullptr; return nullptr;
} }
+6 -10
View File
@@ -25,37 +25,33 @@
#ifndef __CALYPMODULESFACTORY_H__ #ifndef __CALYPMODULESFACTORY_H__
#define __CALYPMODULESFACTORY_H__ #define __CALYPMODULESFACTORY_H__
#include <functional>
#include <map> #include <map>
// CalypLib // CalypLib
#include "lib/CalypModuleIf.h" #include "lib/CalypModuleIf.h"
#define REGISTER_MODULE( X ) Register( "X", &( X::Create ) );
typedef CalypModulePtr ( *CreateModuleFn )( void );
typedef std::map<const char*, CreateModuleFn> CalypModulesFactoryMap;
// Factory for creating instances of CalypModuleIf // Factory for creating instances of CalypModuleIf
class CalypModulesFactory class CalypModulesFactory
{ {
using CalypModulesFactoryMap = std::map<std::string, std::function<CalypModulePtr( void )>>;
private: private:
CalypModulesFactory(); CalypModulesFactory();
CalypModulesFactory& operator=( const CalypModulesFactory& ) { return *this; }
CalypModulesFactoryMap m_FactoryMap; CalypModulesFactoryMap m_FactoryMap;
public: public:
~CalypModulesFactory() = default;
static CalypModulesFactory* Get() static CalypModulesFactory* Get()
{ {
static CalypModulesFactory instance; static CalypModulesFactory instance;
return &instance; return &instance;
} }
void Register( const char* moduleName, CreateModuleFn pfnCreate ); void Register( const std::string& moduleName, std::function<CalypModulePtr( void )> pfnCreate );
void Register( const char* moduleName, std::function<CalypModulePtr( void )> pfnCreate );
bool RegisterDl( const char* dlName ); bool RegisterDl( const char* dlName );
CalypModulePtr CreateModule( const char* moduleName ); CalypModulePtr CreateModule( const std::string& moduleName ) const;
CalypModulesFactoryMap& getMap() { return m_FactoryMap; } CalypModulesFactoryMap& getMap() { return m_FactoryMap; }
}; };
+1
View File
@@ -26,6 +26,7 @@
#define __FILTERCOMPONENT_H__ #define __FILTERCOMPONENT_H__
// CalypLib // CalypLib
#include "lib/CalypFrame.h"
#include "lib/CalypModuleIf.h" #include "lib/CalypModuleIf.h"
class FilterComponentModule : public CalypModuleIf class FilterComponentModule : public CalypModuleIf
+2
View File
@@ -24,6 +24,8 @@
#include "FrameDifference.h" #include "FrameDifference.h"
#include "lib/CalypFrame.h"
FrameDifference::FrameDifference() FrameDifference::FrameDifference()
{ {
/* Module Definition */ /* Module Definition */
+2
View File
@@ -24,6 +24,8 @@
#include "FrameMask.h" #include "FrameMask.h"
#include "lib/CalypFrame.h"
FrameMask::FrameMask() FrameMask::FrameMask()
{ {
/* Module Definition */ /* Module Definition */
+1
View File
@@ -26,6 +26,7 @@
#define __INTERFRAMEVARIANCE_H__ #define __INTERFRAMEVARIANCE_H__
// CalypLib // CalypLib
#include "lib/CalypFrame.h"
#include "lib/CalypModuleIf.h" #include "lib/CalypModuleIf.h"
class InterFrameVariance : public CalypModuleIf class InterFrameVariance : public CalypModuleIf
+1 -3
View File
@@ -24,12 +24,10 @@
#include "ShapeDetection.h" #include "ShapeDetection.h"
#include <cstdlib> #include <cstdlib>
#include <opencv2/imgproc.hpp>
//#include <opencv2/video/video.hpp>
using cv::Mat; using cv::Mat;
using cv::Ptr; using cv::Ptr;
using namespace cv::saliency;
ShapeDetection::ShapeDetection() ShapeDetection::ShapeDetection()
: m_rng( 12345 ) : m_rng( 12345 )
-1
View File
@@ -30,7 +30,6 @@
// OpenCV // OpenCV
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
#include <opencv2/saliency.hpp>
class ShapeDetection : public CalypOpenCVModuleIf, class ShapeDetection : public CalypOpenCVModuleIf,
public CalypModuleInstace<ShapeDetection> public CalypModuleInstace<ShapeDetection>
+3
View File
@@ -3,6 +3,9 @@
# #
OPTION(BUILD_MODULES_TESTS "Build unit tests of modules" ON) OPTION(BUILD_MODULES_TESTS "Build unit tests of modules" ON)
IF(BUILD_MODULES_TESTS) IF(BUILD_MODULES_TESTS)
FETCHCONTENT_MAKEAVAILABLE(googletest Catch2)
INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS})
ADD_DEFINITIONS(-DCALYP_TEST_DATA_DIR=\"${CALYP_TEST_DATA_DIR}\") ADD_DEFINITIONS(-DCALYP_TEST_DATA_DIR=\"${CALYP_TEST_DATA_DIR}\")
+2 -12
View File
@@ -55,17 +55,7 @@ protected:
void SetUp() void SetUp()
{ {
std::string moduleName = CALYP_TEST_MODULE_NAME; std::string moduleName = CALYP_TEST_MODULE_NAME;
pcModule = CalypModulesFactory::Get()->CreateModule( moduleName );
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ )
{
if( strcmp( it->first, moduleName.c_str() ) == 0 )
{
pcModule = it->second();
break;
}
}
} }
// Called after each test // Called after each test
@@ -89,7 +79,7 @@ TEST_F( TestModuleCreate, FIND_MODULE )
TEST_F( TestModuleCreate, CREATE_OK ) TEST_F( TestModuleCreate, CREATE_OK )
{ {
bool moduleRequireOptions = false; bool moduleRequireOptions = false;
if( pcModule->m_uiModuleRequirements & ClpModuleFeature::Options ) if( pcModule->has( ClpModuleFeature::Options ) )
{ {
moduleRequireOptions = true; moduleRequireOptions = true;
} }
@@ -55,16 +55,7 @@ protected:
pcStream->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, ClpPixelFormats::YUV420p, 8, pcStream->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, ClpPixelFormats::YUV420p, 8,
CLP_BIG_ENDIAN, 1, CalypStream::Type::Input ); CLP_BIG_ENDIAN, 1, CalypStream::Type::Input );
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); pcModule = CalypModulesFactory::Get()->CreateModule( moduleName );
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ )
{
if( strcmp( it->first, moduleName.c_str() ) == 0 )
{
pcModule = it->second();
break;
}
}
} }
void TearDown() void TearDown()
+2 -11
View File
@@ -303,23 +303,14 @@ int CalypTools::Open( int argc, char* argv[] )
{ {
std::string moduleName = m_strModule; std::string moduleName = m_strModule;
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); m_pcCurrModuleIf = CalypModulesFactory::Get()->CreateModule( moduleName );
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ )
{
if( strcmp( it->first, moduleName.c_str() ) == 0 )
{
m_pcCurrModuleIf = it->second();
break;
}
}
if( !m_pcCurrModuleIf ) if( !m_pcCurrModuleIf )
{ {
log( CLP_LOG_ERROR, "Invalid module! " ); log( CLP_LOG_ERROR, "Invalid module! " );
return -1; return -1;
} }
if( m_pcCurrModuleIf->m_uiModuleRequirements & ClpModuleFeature::VariableNumOfFrames ) if( m_pcCurrModuleIf->has( ClpModuleFeature::VariableNumOfFrames ) )
{ {
m_pcCurrModuleIf->m_uiNumberOfFrames = m_apcInputStreams.size(); m_pcCurrModuleIf->m_uiNumberOfFrames = m_apcInputStreams.size();
} }
+12 -23
View File
@@ -118,20 +118,10 @@ int CalypToolsCmdParser::parseToolsArgs( int argc, char* argv[] )
void CalypToolsCmdParser::listModuleHelp() void CalypToolsCmdParser::listModuleHelp()
{ {
std::string moduleName = m_strModule; std::string moduleName = m_strModule;
auto pcCurrModuleIf = CalypModulesFactory::Get()->CreateModule( moduleName );
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ )
{
if( strcmp( it->first, moduleName.c_str() ) == 0 )
{
break;
}
}
auto pcCurrModuleIf = it->second();
if( pcCurrModuleIf ) if( pcCurrModuleIf )
{ {
printf( "Usage: calypTools --module=%s options:\n", it->first ); printf( "Usage: calypTools --module=%s options:\n", moduleName.c_str() );
pcCurrModuleIf->m_cModuleOptions.doHelp( std::cout ); pcCurrModuleIf->m_cModuleOptions.doHelp( std::cout );
} }
} }
@@ -143,27 +133,26 @@ void CalypToolsCmdParser::listModules()
if( m_cOptions.hasOpt( "module_list_full" ) ) if( m_cOptions.hasOpt( "module_list_full" ) )
bDetailed = true; bDetailed = true;
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); const auto& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
printf( "Calyp available modules: \n" ); std::cout << "Calyp available modules:" << std::endl;
printf( " [Internal Name] " ); std::cout << " [Internal Name] ";
if( bDetailed ) if( bDetailed )
{ {
printf( " [Full Name] " ); std::cout << " [Full Name] ";
printf( " [Type] " ); std::cout << " [Type] ";
printf( " [Description]" ); std::cout << " [Description]";
} }
printf( " \n" ); std::cout << std::endl;
for( unsigned int i = 0; it != moduleFactoryMap.end(); ++it, i++ ) for( const auto& [name, moduleFct] : moduleFactoryMap )
{ {
printf( " " ); printf( " " );
printf( "%-33s", it->first ); printf( "%-33s", name.c_str() );
if( bDetailed ) if( bDetailed )
{ {
std::string ModuleNameString; std::string ModuleNameString;
auto pcCurrModuleIf = it->second(); auto pcCurrModuleIf = moduleFct();
if( pcCurrModuleIf->m_pchModuleCategory ) if( pcCurrModuleIf->m_pchModuleCategory )
{ {
+1
View File
@@ -28,6 +28,7 @@
#include <vector> #include <vector>
#include "config.h" #include "config.h"
#include "lib/CalypDefs.h"
#include "lib/CalypOptions.h" #include "lib/CalypOptions.h"
class CalypToolsCmdParser class CalypToolsCmdParser