37 Commits
Author SHA1 Message Date
jfmcarreira b7ad00a4c5 Minor refactor CalypStream header and format handler 2021-10-10 19:48:14 +01:00
jfmcarreira fbbd77bfbf Merge branch 'devel' 2021-10-10 18:05:23 +01:00
jfmcarreira be06ca656d Add new window classes for modules and streams 2021-10-10 15:13:42 +01:00
jfmcarreira 665cd0bb1c Add new window classes 2021-10-09 20:02:19 +01:00
jfmcarreira 1c0321a705 Fix histogram widget 2021-10-09 20:01:02 +01:00
jfmcarreira 5b9e16a708 Make CalypPixel work on stack 2021-10-09 18:31:21 +01:00
jfmcarreira 5b6d3e9031 Add iwyu 2021-10-03 19:19:21 +01:00
jfmcarreira 12c3b26580 appveyor: revert opencv dir change 2021-10-03 18:44:29 +01:00
jfmcarreira 574c712207 appveyor: Fix qt dll dir 2021-10-03 18:18:07 +01:00
jfmcarreira 4deef9e11c appveyor: fix Qt dir 2021-10-03 16:15:53 +01:00
jfmcarreira c7c8074cf8 appveyor: use visual studio 16 2019 generator 2021-10-03 16:02:06 +01:00
jfmcarreira a7ca36d252 appveyor: use latest cmake generator 2021-10-03 15:37:31 +01:00
jfmcarreira 8940ede351 appveyor: add executable name to the command 2021-10-03 15:34:05 +01:00
jfmcarreira b57e887d55 Fix last commit 2021-10-03 15:31:45 +01:00
jfmcarreira 3502b5df0d Fix script location in appveyor 2021-10-03 15:27:14 +01:00
jfmcarreira 15007d7784 Upgrade visual studio version in appveyor 2021-10-03 15:20:37 +01:00
jfmcarreira 9790ef3e31 Fix generator 2021-10-03 15:15:20 +01:00
jfmcarreira 5f0bdb30b5 Change CMake generator for appveyor 2021-10-03 14:48:15 +01:00
jfmcarreira 900c9c0418 Remove some files from the Calyp lib and clean up code 2021-10-03 14:30:15 +01:00
jfmcarreira 54f9f185e2 Add compile options and put Qt definitions in app CMakeLists 2021-10-03 14:13:02 +01:00
jfmcarreira dda88d8334 Fix c++20 compiler flag 2021-10-03 00:21:25 +01:00
jfmcarreira 73e5608624 Print the full log 2021-10-02 23:40:43 +01:00
jfmcarreira 317123c7b9 Remove flags not available on windows 2021-10-02 23:28:24 +01:00
jfmcarreira 0a40a8bdb6 Fix c++ flags for windows 2021-10-02 22:52:52 +01:00
jfmcarreira 5f66af794c Clean up code of HistogramWidget 2021-10-02 22:31:50 +01:00
jfmcarreira a6e1acd406 Update Cmake to fix config file 2021-10-02 22:29:51 +01:00
jfmcarreira 7818dbc9e3 Upate repo before install dependencies 2021-09-30 00:10:51 +01:00
jfmcarreira 448b64a8e3 Fix examples and tests 2021-09-30 00:06:57 +01:00
jfmcarreira 612f147639 Merge branch 'master' into devel 2021-09-29 23:37:30 +01:00
jfmcarreira 53bb100ad4 Fix bug removing a module 2021-09-29 23:36:53 +01:00
jfmcarreira d7b1d58b4b Merge branch 'master' into devel 2021-09-29 22:06:08 +01:00
jfmcarreira 58ce738026 Add devel build badge 2021-09-29 22:04:17 +01:00
jfmcarreira c8382ccaff Add github actions to devel 2021-09-28 01:21:39 +01:00
jfmcarreira 1a00bd328c Guard method position against Qt version 2021-09-28 01:13:55 +01:00
jfmcarreira 095d1863c2 Specify gcc-10 in the actions 2021-09-28 01:03:12 +01:00
jfmcarreira 3a56f532c1 Use GCC 10 in Github actions 2021-09-28 00:50:50 +01:00
jfmcarreira 2c89e47b8a Fix warnings to build with Werror flag 2021-09-28 00:38:33 +01:00
96 changed files with 2203 additions and 2094 deletions

No files matched your search

+6 -6
View File
@@ -1,4 +1,4 @@
image: Visual Studio 2017 image: Visual Studio 2019
configuration: Release configuration: Release
platform: platform:
- x64 - x64
@@ -16,7 +16,7 @@ init:
- ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
install: install:
- '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64' - '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64'
- choco install nsis - choco install nsis
- choco install opencv - choco install opencv
- 'C:\Tools\opencv\build\setup_vars_opencv4.cmd' - 'C:\Tools\opencv\build\setup_vars_opencv4.cmd'
@@ -32,10 +32,10 @@ build_script:
- mv C:\Projects\calyp C:\Projects\calyp-deployment\cmake-helper\ - mv C:\Projects\calyp C:\Projects\calyp-deployment\cmake-helper\
- mkdir C:\Projects\calyp-build - mkdir C:\Projects\calyp-build
- cd C:\Projects\calyp-build - cd C:\Projects\calyp-build
- cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DUSE_DYNLOAD=OFF -DOpenCV_DIR="C:/Tools/opencv/build" -DOpenCV_DLL_DIR="C:/Tools/opencv/build/x64/vc15/bin" -DOpenCV_INSTALL_MODULES="world" -DQT_DIR="C:\Qt\latest\msvc2017_64" -DQt5_DIR="C:\Qt\latest\msvc2017_64\lib\cmake\Qt5" -DUSE_QTDBUS=OFF -DAVFORMAT_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/avformat.lib -DAVFORMAT_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -DAVCODEC_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/avcodec.lib -DAVCODEC_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -DAVUTIL_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/avutil.lib -DAVUTIL_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -DSWSCALE_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/swscale.lib -DSWSCALE_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -DAVDEVICE_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/avdevice.lib -DAVDEVICE_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -DPOSTPROC_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/postproc.lib -DPOSTPROC_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -DFFMPEG_DIR=C:\Projects\ffmpeg_libraries -DSWRESAMPLE_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/swresample.lib -DSWRESAMPLE_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -G "Visual Studio 15 2017 Win64" C:\Projects\calyp-deployment\cmake-helper - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DUSE_DYNLOAD=OFF -DOpenCV_DIR="C:/Tools/opencv/build" -DOpenCV_DLL_DIR="C:/Tools/opencv/build/x64/vc15/bin" -DOpenCV_INSTALL_MODULES="world" -DQT_DIR="C:\Qt\latest\msvc2019_64" -DQt5_DIR="C:\Qt\latest\msvc2019_64\lib\cmake\Qt5" -DUSE_QTDBUS=OFF -DAVFORMAT_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/avformat.lib -DAVFORMAT_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -DAVCODEC_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/avcodec.lib -DAVCODEC_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -DAVUTIL_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/avutil.lib -DAVUTIL_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -DSWSCALE_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/swscale.lib -DSWSCALE_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -DAVDEVICE_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/avdevice.lib -DAVDEVICE_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -DPOSTPROC_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/postproc.lib -DPOSTPROC_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -DFFMPEG_DIR=C:\Projects\ffmpeg_libraries -DSWRESAMPLE_LIBRARIES=C:/Projects/ffmpeg_libraries/lib/swresample.lib -DSWRESAMPLE_INCLUDE_DIRS=C:/Projects/ffmpeg_libraries/include -G "Visual Studio 16 2019" -A x64 C:\Projects\calyp-deployment\cmake-helper
- cmake --build . --target ALL_BUILD -- /p:Configuration=Release > log_build - cmake --build . --target ALL_BUILD -- /p:Configuration=Release
- cmake --build . --target INSTALL -- /p:Configuration=Release > log_install - cmake --build . --target INSTALL -- /p:Configuration=Release
- cmake --build . --target PACKAGE -- /p:Configuration=Release > log_pkg - cmake --build . --target PACKAGE -- /p:Configuration=Release
after_build: after_build:
- IF "%APPVEYOR_REPO_BRANCH%" == "master" (CALL ..\calyp-deployment\scripts\deploy-to-github.bat) - IF "%APPVEYOR_REPO_BRANCH%" == "master" (CALL ..\calyp-deployment\scripts\deploy-to-github.bat)
+1 -1
View File
@@ -1,5 +1,5 @@
--- ---
Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay' 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'
WarningsAsErrors: '' WarningsAsErrors: ''
HeaderFilterRegex: '' HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false AnalyzeTemporaryDtors: false
+5 -3
View File
@@ -2,7 +2,9 @@ name: Build on Linux
on: on:
push: push:
branches: [ master ] branches:
- master
- devel
pull_request: pull_request:
branches: [ master ] branches: [ master ]
@@ -20,14 +22,14 @@ jobs:
steps: steps:
- name: Install dependencies - name: Install dependencies
run: sudo apt-get install cmake qtbase5-dev libavcodec-dev libavformat-dev libavutil-dev libopencv-dev libopencv-video-dev libopencv-contrib-dev run: sudo apt-get update && sudo apt-get install gcc-10 g++-10 cmake qtbase5-dev libavcodec-dev libavformat-dev libavutil-dev libopencv-dev libopencv-video-dev libopencv-contrib-dev
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Configure CMake - name: Configure CMake
# 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 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=OFF 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
- name: Build - name: Build
# Build your program with the given configuration # Build your program with the given configuration
+26 -26
View File
@@ -48,7 +48,6 @@ OPTION(BUILD_TOOLS "Build Command Line Application" ON)
OPTION(BUILD_EXAMPLES "Build Examples" OFF) OPTION(BUILD_EXAMPLES "Build Examples" OFF)
OPTION(BUILD_DOC "Build Documentation" OFF) OPTION(BUILD_DOC "Build Documentation" OFF)
OPTION(BUILD_TESTS "Build Google Tests" OFF) OPTION(BUILD_TESTS "Build Google Tests" OFF)
OPTION(BUILD_TESTS_CATCH2 "Build Catch2 Tests" OFF)
OPTION(BUILD_WITH_SANITIZERS "Build with sanitizers" OFF) OPTION(BUILD_WITH_SANITIZERS "Build with sanitizers" OFF)
OPTION(BUILD_WITH_THREAD_SANITIZER "Build with thread sanitizer" OFF) OPTION(BUILD_WITH_THREAD_SANITIZER "Build with thread sanitizer" OFF)
@@ -58,6 +57,7 @@ OPTION(USE_DYNLOAD "Use dynamic load of modules" ON)
OPTION(USE_SSE "Build with SSE support" ON) OPTION(USE_SSE "Build with SSE support" ON)
OPTION(USE_WERROR "Warnings as errors" OFF) OPTION(USE_WERROR "Warnings as errors" OFF)
OPTION(USE_STATIC "Use static libs" OFF) OPTION(USE_STATIC "Use static libs" OFF)
OPTION(USE_IWYU "Use include what you use tool" OFF)
# #################################################################################################################################################### # ####################################################################################################################################################
# Release configuration # Release configuration
@@ -123,21 +123,13 @@ IF(BUILD_TESTS)
CACHE BOOL "" FORCE CACHE BOOL "" FORCE
) )
FETCHCONTENT_MAKEAVAILABLE(googletest) FETCHCONTENT_MAKEAVAILABLE(googletest)
SET_PACKAGE_PROPERTIES( SET_PACKAGE_PROPERTIES(
googletest PROPERTIES googletest PROPERTIES
URL "https://github.com/google/googletest" URL "https://github.com/google/googletest"
DESCRIPTION "Google unit tests" DESCRIPTION "Google unit tests"
TYPE OPTIONAL TYPE OPTIONAL
) )
SET(CALYP_TEST_DATA_DIR
"CALYP_TEST_DATA_DIR"
CACHE PATH "Location of video information for testing"
)
ENDIF()
IF(BUILD_TESTS_CATCH2)
INCLUDE(FetchContent)
FETCHCONTENT_DECLARE( FETCHCONTENT_DECLARE(
Catch2 Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_REPOSITORY https://github.com/catchorg/Catch2.git
@@ -151,7 +143,13 @@ IF(BUILD_TESTS_CATCH2)
TYPE OPTIONAL TYPE OPTIONAL
) )
INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/_deps/catch2-src/contrib/Catch.cmake) INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/_deps/catch2-src/contrib/Catch.cmake)
INCLUDE(CTest)
ENABLE_TESTING() ENABLE_TESTING()
SET(CALYP_TEST_DATA_DIR
"CALYP_TEST_DATA_DIR"
CACHE PATH "Location of video information for testing"
)
ENDIF() ENDIF()
OPTION(USE_OPENCV "Add OpenCV support" ON) OPTION(USE_OPENCV "Add OpenCV support" ON)
@@ -220,7 +218,16 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
# #################################################################################################################################################### # ####################################################################################################################################################
SET(CMAKE_CXX_STANDARD 20) SET(CMAKE_CXX_STANDARD 20)
ADD_DEFINITIONS(-std=gnu++2a) SET(CMAKE_CXX_STANDARD_REQUIRED ON)
IF(MSVC)
ADD_COMPILE_OPTIONS(/std:c++20)
ELSE()
IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
ADD_DEFINITIONS(-std=gnu++2a)
ELSE()
ADD_DEFINITIONS(-std=c++20)
ENDIF()
ENDIF()
IF(NOT CMAKE_BUILD_TYPE) IF(NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "No build type selected, default to Release") MESSAGE(STATUS "No build type selected, default to Release")
@@ -229,23 +236,8 @@ ENDIF()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -funroll-loops") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -funroll-loops")
ADD_DEFINITIONS(
-DQT_NO_CAST_TO_ASCII
# -DQT_NO_CAST_FROM_ASCII
-DQT_NO_URL_CAST_FROM_STRING
-DQT_NO_CAST_FROM_BYTEARRAY
# -DQT_NO_SIGNALS_SLOTS_KEYWORDS -DQT_USE_QSTRINGBUILDER
)
# if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") endif() # if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") endif()
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
IF(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wlogical-op")
ENDIF()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
ENDIF()
IF(USE_WERROR) IF(USE_WERROR)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
ENDIF() ENDIF()
@@ -258,6 +250,11 @@ IF(BUILD_WITH_THREAD_SANITIZER)
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=thread") SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=thread")
ENDIF() ENDIF()
IF(USE_IWYU)
FIND_PROGRAM(iwyu_path NAMES include-what-you-use iwyu REQUIRED)
SET(CXX_INCLUDE_WHAT_YOU_USE ON)
ENDIF()
# #################################################################################################################################################### # ####################################################################################################################################################
# Configure targets # Configure targets
# #################################################################################################################################################### # ####################################################################################################################################################
@@ -269,7 +266,10 @@ ADD_FEATURE_INFO(SSE USE_SSE "SSE instructions support")
ADD_FEATURE_INFO(WErrors USE_WERROR "Warnings as errors") ADD_FEATURE_INFO(WErrors USE_WERROR "Warnings as errors")
ADD_SUBDIRECTORY(lib) ADD_SUBDIRECTORY(lib)
ADD_SUBDIRECTORY(modules)
IF(${BUILD_TOOLS} OR ${BUILD_APP})
ADD_SUBDIRECTORY(modules)
ENDIF()
IF(${BUILD_TOOLS}) IF(${BUILD_TOOLS})
ADD_SUBDIRECTORY(tools) ADD_SUBDIRECTORY(tools)
+3 -1
View File
@@ -3,7 +3,9 @@
## Build Status ## Build Status
![Build Action](https://github.com/pixlra/calyp/actions/workflows/build.yml/badge.svg?branch=master) [![Linux Status](https://travis-ci.org/pixlra/calyp.svg?branch=master)](https://travis-ci.org/pixlra/calyp.svg?branch=master) | Master | Development |
|--|--|
| ![master branch](https://github.com/pixlra/calyp/actions/workflows/build.yml/badge.svg?branch=master) | ![devel branch](https://github.com/pixlra/calyp/actions/workflows/build.yml/badge.svg?branch=master) |
[![Windows status](https://ci.appveyor.com/api/projects/status/ea2ktvtg7uqwrika/branch/master?svg=true)](https://ci.appveyor.com/project/jfmcarreira/calyp/branch/master) [![Windows status](https://ci.appveyor.com/api/projects/status/ea2ktvtg7uqwrika/branch/master?svg=true)](https://ci.appveyor.com/project/jfmcarreira/calyp/branch/master)
+16 -3
View File
@@ -3,8 +3,8 @@
# #
INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/external ${CMAKE_CURRENT_SOURCE_DIR}/dialog ${CMAKE_CURRENT_SOURCE_DIR}/docks ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/external ${CMAKE_CURRENT_SOURCE_DIR}/dialog
${CMAKE_CURRENT_SOURCE_DIR}/widgets ${CMAKE_CURRENT_SOURCE_DIR}/docks ${CMAKE_CURRENT_SOURCE_DIR}/widgets
) )
OPTION(USE_QTDBUS "Build with QtDBus" ON) OPTION(USE_QTDBUS "Build with QtDBus" ON)
@@ -36,6 +36,14 @@ IF(USE_QTDBUS)
ENDIF() ENDIF()
ENDIF() ENDIF()
ADD_DEFINITIONS(
-DQT_NO_CAST_TO_ASCII
# -DQT_NO_CAST_FROM_ASCII
-DQT_NO_URL_CAST_FROM_STRING
-DQT_NO_CAST_FROM_BYTEARRAY
# -DQT_NO_SIGNALS_SLOTS_KEYWORDS -DQT_USE_QSTRINGBUILDER
)
SET(Calyp_App_SRCS SET(Calyp_App_SRCS
# Main # Main
main.cpp main.cpp
@@ -48,12 +56,13 @@ SET(Calyp_App_SRCS
ResourceHandle.cpp ResourceHandle.cpp
VideoHandle.cpp VideoHandle.cpp
VideoSubWindow.cpp VideoSubWindow.cpp
VideoStreamSubWindow.cpp
ModuleSubWindow.cpp
ViewArea.cpp ViewArea.cpp
GridManager.cpp GridManager.cpp
# Module Quality # Module Quality
QualityHandle.cpp QualityHandle.cpp
PlotSubWindow.cpp PlotSubWindow.cpp
external/qcustomplot/qcustomplot.cpp
# Module Plugins # Module Plugins
ModulesHandle.cpp ModulesHandle.cpp
CalypAppModuleIf.cpp CalypAppModuleIf.cpp
@@ -127,6 +136,10 @@ QT5_ADD_RESOURCES(Calyp_App_RCC ${Calyp_App_RCC})
# Instruct CMake to run moc automatically when needed. # Instruct CMake to run moc automatically when needed.
SET(CMAKE_AUTOMOC ON) SET(CMAKE_AUTOMOC ON)
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-enum-enum-conversion")
ENDIF()
# Windows application icon # Windows application icon
IF(WIN32) IF(WIN32)
SET(WINDOWS_RES_FILE ${CMAKE_CURRENT_BINARY_DIR}/resources.obj) SET(WINDOWS_RES_FILE ${CMAKE_CURRENT_BINARY_DIR}/resources.obj)
+21 -15
View File
@@ -29,6 +29,7 @@
#include <QDockWidget> #include <QDockWidget>
#include "ModuleHandleDock.h" #include "ModuleHandleDock.h"
#include "ModuleSubWindow.h"
#include "VideoSubWindow.h" #include "VideoSubWindow.h"
#include "lib/CalypFrame.h" #include "lib/CalypFrame.h"
#include "lib/CalypStream.h" #include "lib/CalypStream.h"
@@ -55,16 +56,19 @@ CalypAppModuleIf::~CalypAppModuleIf()
auto* ptr = m_pcModuleDock; auto* ptr = m_pcModuleDock;
m_pcModuleDock = NULL; m_pcModuleDock = NULL;
ptr->close(); ptr->close();
delete ptr;
} }
if( m_pcDisplaySubWindow ) if( m_pcDisplaySubWindow )
{ {
auto* ptr = m_pcDisplaySubWindow; auto* ptr = m_pcDisplaySubWindow;
m_pcDisplaySubWindow = NULL; m_pcDisplaySubWindow = NULL;
ptr->closeSubWindow(); ptr->closeSubWindow();
delete ptr;
} }
if( m_pcDockWidget ) if( m_pcDockWidget )
{ {
m_pcDockWidget->close(); m_pcDockWidget->close();
delete m_pcDockWidget;
} }
if( m_pcModule ) if( m_pcModule )
{ {
@@ -77,7 +81,7 @@ void CalypAppModuleIf::update( bool isPlaying )
{ {
if( m_pcDisplaySubWindow ) if( m_pcDisplaySubWindow )
{ {
m_pcDisplaySubWindow->refreshFrame(); m_pcDisplaySubWindow->refreshSubWindow();
} }
else else
{ {
@@ -85,13 +89,13 @@ void CalypAppModuleIf::update( bool isPlaying )
} }
} }
void CalypAppModuleIf::setPlaying( bool isPlaying ) // void CalypAppModuleIf::setPlaying( bool isPlaying )
{ // {
if( m_pcDisplaySubWindow ) // if( m_pcDisplaySubWindow )
{ // {
m_pcDisplaySubWindow->setPlaying( isPlaying ); // m_pcDisplaySubWindow->setPlaying( isPlaying );
} // }
} // }
bool CalypAppModuleIf::isRunning() bool CalypAppModuleIf::isRunning()
{ {
@@ -154,7 +158,6 @@ bool CalypAppModuleIf::apply( bool isPlaying, bool disableThreads )
show(); show();
} }
} }
return moduleExecuted; return moduleExecuted;
} }
@@ -210,22 +213,25 @@ bool CalypAppModuleIf::process()
void CalypAppModuleIf::show() void CalypAppModuleIf::show()
{ {
if( m_canceling )
return;
switch( m_pcModule->m_iModuleType ) switch( m_pcModule->m_iModuleType )
{ {
case CLP_FRAME_PROCESSING_MODULE: { case CLP_FRAME_PROCESSING_MODULE: {
auto displayWindow = m_pcDisplaySubWindow; auto displayWindow = qobject_cast<VideoSubWindow*>( m_pcDisplaySubWindow );
if( displayWindow == nullptr ) if( displayWindow == nullptr )
displayWindow = m_pcSubWindow[0]; displayWindow = m_pcSubWindow[0];
#ifdef CALYP_THREADED_MODULES #ifdef CALYP_THREADED_MODULES
if( m_Mutex.try_lock() ) if( m_Mutex.try_lock() )
{ {
m_pcDisplaySubWindow->setFillWindow( false ); displayWindow->setFillWindow( false );
m_pcDisplaySubWindow->setCurrFrame( m_pcProcessedFrame ); displayWindow->setCurrFrame( m_pcProcessedFrame );
m_Mutex.unlock(); m_Mutex.unlock();
} }
#else
displayWindow->setFillWindow( false );
displayWindow->setCurrFrame( m_pcProcessedFrame );
#endif #endif
m_pcDisplaySubWindow->setFillWindow( false );
m_pcDisplaySubWindow->setCurrFrame( m_pcProcessedFrame );
break; break;
} }
case CLP_FRAME_MEASUREMENT_MODULE: case CLP_FRAME_MEASUREMENT_MODULE:
@@ -238,7 +244,7 @@ void CalypAppModuleIf::disable()
{ {
QApplication::setOverrideCursor( Qt::WaitCursor ); QApplication::setOverrideCursor( Qt::WaitCursor );
#ifdef CALYP_THREADED_MODULES #ifdef CALYP_THREADED_MODULES
QMutexLocker locker( &m_Mutex ); m_canceling = true;
m_Mutex.lock(); m_Mutex.lock();
m_Mutex.unlock(); m_Mutex.unlock();
#endif #endif
+5 -3
View File
@@ -52,6 +52,7 @@ class CalypFrame;
#define CLP_MODULE_MAX_NUM_FRAMES 5 #define CLP_MODULE_MAX_NUM_FRAMES 5
class VideoSubWindow; class VideoSubWindow;
class ModuleSubWindow;
class CalypAppModuleIf : std::enable_shared_from_this<CalypAppModuleIf>, class CalypAppModuleIf : std::enable_shared_from_this<CalypAppModuleIf>,
#ifdef CALYP_THREADED_MODULES #ifdef CALYP_THREADED_MODULES
@@ -84,11 +85,11 @@ public:
CalypModuleIf* getModule() { return m_pcModule.get(); } CalypModuleIf* getModule() { return m_pcModule.get(); }
unsigned int getModuleRequirements() { return m_pcModule->m_uiModuleRequirements; } unsigned int getModuleRequirements() { return m_pcModule->m_uiModuleRequirements; }
ClpString moduleInfo() { return m_pcModule->moduleInfo(); } std::string moduleInfo() { 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 ); // void setPlaying( bool isPlaying );
bool isRunning(); bool isRunning();
void show(); void show();
void disable(); void disable();
@@ -105,7 +106,7 @@ private:
std::vector<VideoSubWindow*> m_pcSubWindow; std::vector<VideoSubWindow*> m_pcSubWindow;
// The module owns the related widgets // The module owns the related widgets
VideoSubWindow* m_pcDisplaySubWindow{ nullptr }; ModuleSubWindow* m_pcDisplaySubWindow{ nullptr };
QDockWidget* m_pcDockWidget{ nullptr }; QDockWidget* m_pcDockWidget{ nullptr };
ModuleHandleDock* m_pcModuleDock{ nullptr }; ModuleHandleDock* m_pcModuleDock{ nullptr };
@@ -119,6 +120,7 @@ private:
#ifdef CALYP_THREADED_MODULES #ifdef CALYP_THREADED_MODULES
QMutex m_Mutex; QMutex m_Mutex;
std::atomic<bool> m_canceling{ false };
#endif #endif
}; };
+16 -18
View File
@@ -81,7 +81,7 @@ MainWindow::MainWindow()
setUnifiedTitleAndToolBarOnMac( true ); setUnifiedTitleAndToolBarOnMac( true );
setCentralWidget( m_pcWindowHandle ); setCentralWidget( m_pcWindowHandle );
setAcceptDrops( true ); setAcceptDrops( true );
setBackgroundRole( QPalette::Background ); setBackgroundRole( QPalette::Window );
connect( m_pcWindowHandle, &SubWindowHandle::windowActivated, this, &MainWindow::update ); connect( m_pcWindowHandle, &SubWindowHandle::windowActivated, this, &MainWindow::update );
connect( m_pcWindowHandle, &SubWindowHandle::changed, this, &MainWindow::update, Qt::QueuedConnection ); connect( m_pcWindowHandle, &SubWindowHandle::changed, this, &MainWindow::update, Qt::QueuedConnection );
@@ -95,9 +95,9 @@ bool MainWindow::parseArgs( int argc, char* argv[] )
bool bRet = false; bool bRet = false;
CalypOptions pcCmdParser; CalypOptions pcCmdParser;
std::vector<ClpString> m_apcInputs; std::vector<std::string> m_apcInputs;
ClpString strResolution( "" ); std::string strResolution( "" );
ClpString strPelFmt( "" ); std::string strPelFmt( "" );
pcCmdParser.addOptions() /**/ pcCmdParser.addOptions() /**/
( "input,i", m_apcInputs, "input file" ) /**/ ( "input,i", m_apcInputs, "input file" ) /**/
@@ -192,13 +192,13 @@ void MainWindow::loadFile( QString fileName, CalypFileInfo* pStreamInfo )
printMessage( "File " + fileName + " do not exist!", CLP_LOG_ERROR ); printMessage( "File " + fileName + " do not exist!", CLP_LOG_ERROR );
return; return;
} }
VideoSubWindow* videoSubWindow = MainWindow::findVideoStreamSubWindow( m_pcWindowHandle, fileName ); auto* videoSubWindow = MainWindow::findVideoStreamSubWindow( m_pcWindowHandle, fileName );
if( videoSubWindow ) if( videoSubWindow )
{ {
m_pcWindowHandle->setActiveSubWindow( videoSubWindow ); m_pcWindowHandle->setActiveSubWindow( videoSubWindow );
return; return;
} }
videoSubWindow = new VideoSubWindow( VideoSubWindow::VIDEO_STREAM_SUBWINDOW ); // createSubWindow(); videoSubWindow = new VideoStreamSubWindow(); // createSubWindow();
videoSubWindow->setResourceManaget( m_appResourceHandle.get() ); videoSubWindow->setResourceManaget( m_appResourceHandle.get() );
if( !pStreamInfo ) if( !pStreamInfo )
@@ -261,12 +261,12 @@ QStringList MainWindow::showFileDialog( bool bRead )
for( unsigned int i = 0; i < supportedFmts.size(); i++ ) for( unsigned int i = 0; i < supportedFmts.size(); i++ )
{ {
std::vector<ClpString> arrayExt = supportedFmts[i].getExts(); std::vector<std::string> arrayExt = supportedFmts[i].getExts();
if( arrayExt.size() > 0 ) if( arrayExt.size() > 0 )
{ {
QString currFmt( QString::fromStdString( supportedFmts[i].formatName ) ); QString currFmt( QString::fromStdString( supportedFmts[i].formatName ) );
currFmt.append( " (" ); currFmt.append( " (" );
for( std::vector<ClpString>::iterator e = arrayExt.begin(); e != arrayExt.end(); ++e ) for( std::vector<std::string>::iterator e = arrayExt.begin(); e != arrayExt.end(); ++e )
{ {
supported.append( " *." ); supported.append( " *." );
currFmt.append( "*." ); currFmt.append( "*." );
@@ -380,9 +380,8 @@ void MainWindow::saveStream()
void MainWindow::format() void MainWindow::format()
{ {
if( m_pcCurrentVideoSubWindow ) if( auto* pcVideoSubWindow = qobject_cast<VideoStreamSubWindow*>( m_pcCurrentVideoSubWindow ) )
{ {
VideoSubWindow* pcVideoSubWindow = m_pcCurrentVideoSubWindow;
try try
{ {
if( pcVideoSubWindow->loadFile( pcVideoSubWindow->getCurrentFileName(), true ) ) if( pcVideoSubWindow->loadFile( pcVideoSubWindow->getCurrentFileName(), true ) )
@@ -436,10 +435,10 @@ void MainWindow::reloadAll()
void MainWindow::loadAll() void MainWindow::loadAll()
{ {
if( m_pcCurrentVideoSubWindow ) if( auto* pcVideoSubWindow = qobject_cast<VideoStreamSubWindow*>( m_pcCurrentVideoSubWindow ) )
{ {
printMessage( "Loading file into memory...", CLP_LOG_INFO ); printMessage( "Loading file into memory...", CLP_LOG_INFO );
m_pcCurrentVideoSubWindow->loadAll(); pcVideoSubWindow->loadAll();
printMessage( "File loaded", CLP_LOG_INFO ); printMessage( "File loaded", CLP_LOG_INFO );
} }
} }
@@ -529,19 +528,18 @@ void MainWindow::dropEvent( QDropEvent* event )
// ----------------------- Sub Window Functions ----------------------- // ----------------------- Sub Window Functions -----------------------
VideoSubWindow* MainWindow::findVideoStreamSubWindow( const SubWindowHandle* windowManager, VideoStreamSubWindow* MainWindow::findVideoStreamSubWindow( const SubWindowHandle* windowManager,
const QString& fileName ) const QString& fileName )
{ {
QString canonicalFilePath = QFileInfo( fileName ).canonicalFilePath(); QString canonicalFilePath = QFileInfo( fileName ).canonicalFilePath();
VideoSubWindow* pcSubWindow;
QList<SubWindowAbstract*> subWindowList = windowManager->findSubWindow( SubWindowAbstract::VIDEO_STREAM_SUBWINDOW ); QList<SubWindowAbstract*> subWindowList = windowManager->findSubWindow( SubWindowAbstract::VIDEO_STREAM_SUBWINDOW );
for( int i = 0; i < subWindowList.size(); i++ ) for( int i = 0; i < subWindowList.size(); i++ )
{ {
pcSubWindow = qobject_cast<VideoSubWindow*>( subWindowList.at( i ) ); auto* pcSubWindow = qobject_cast<VideoStreamSubWindow*>( subWindowList.at( i ) );
if( pcSubWindow->getCurrentFileName() == canonicalFilePath ) if( pcSubWindow->getCurrentFileName() == canonicalFilePath )
return qobject_cast<VideoSubWindow*>( pcSubWindow ); return pcSubWindow;
} }
return 0; return nullptr;
} }
// ----------------------- Update Functions ----------------------- // ----------------------- Update Functions -----------------------
+4 -2
View File
@@ -41,6 +41,7 @@
#include <QVector> #include <QVector>
#include "CommonDefs.h" #include "CommonDefs.h"
#include "VideoStreamSubWindow.h"
#include "VideoSubWindow.h" #include "VideoSubWindow.h"
#include "config.h" #include "config.h"
#ifdef USE_QTDBUS #ifdef USE_QTDBUS
@@ -59,6 +60,7 @@ class QSignalMapper;
class CalypOptions; class CalypOptions;
class CalypStream; class CalypStream;
class SubWindowHandle; class SubWindowHandle;
class VideoStreamSubWindow;
class VideoHandle; class VideoHandle;
class QualityHandle; class QualityHandle;
class ModulesHandle; class ModulesHandle;
@@ -130,8 +132,8 @@ private:
QString m_cLastOpenPath; QString m_cLastOpenPath;
QStringList showFileDialog( bool bRead ); QStringList showFileDialog( bool bRead );
static VideoSubWindow* findVideoStreamSubWindow( const SubWindowHandle* windowManager, static VideoStreamSubWindow* findVideoStreamSubWindow( const SubWindowHandle* windowManager,
const QString& fileName ); const QString& fileName );
void updateMenus(); void updateMenus();
+1 -1
View File
@@ -32,7 +32,7 @@ MdiSubWindow::MdiSubWindow( QWidget* parent )
: QMdiSubWindow( parent ) : QMdiSubWindow( parent )
{ {
setAttribute( Qt::WA_DeleteOnClose ); setAttribute( Qt::WA_DeleteOnClose );
setBackgroundRole( QPalette::Background ); setBackgroundRole( QPalette::Window );
} }
QSize MdiSubWindow::sizeHint() const QSize MdiSubWindow::sizeHint() const
+114
View File
@@ -0,0 +1,114 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2021 by Joao Carreira (jfmcarreira@gmail.com)
* Luis Lucas (luisfrlucas@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file ModuleSubWindow.cpp
* \brief Video Sub windows handling
*/
#include "ModuleSubWindow.h"
#include <QSettings>
#include <QStaticText>
#include <cassert>
#include "ModulesHandle.h"
ModuleSubWindow::ModuleSubWindow( CalypAppModuleIf* module, QWidget* parent )
: VideoSubWindow( VideoSubWindow::MODULE_SUBWINDOW, parent )
{
m_pcDisplayModule = module;
}
ModuleSubWindow::~ModuleSubWindow()
{
}
void ModuleSubWindow::resetWindowName()
{
QString windowName{ "Module" };
if( auto module_ptr = m_pcDisplayModule )
{
windowName.append( " " ).append( module_ptr->getModule()->m_pchModuleLongName );
}
setWindowName( windowName );
}
void ModuleSubWindow::updateVideoWindowInfo()
{
m_cStreamInformation = "";
m_cStreamInformation = "Module";
if( auto module_ptr = m_pcDisplayModule )
{
const auto& arraySubWindows = module_ptr->getSubWindowList();
QStringList windowInfoList;
if( arraySubWindows.size() > 0 )
{
for( std::size_t i = 0; i < arraySubWindows.size(); i++ )
{
if( arraySubWindows[i]->getWindowName() != getWindowName() )
{
windowInfoList.append( QString( "Input %1 - " + arraySubWindows[i]->getWindowName() ).arg( i + 1 ) );
}
}
}
if( module_ptr->getModuleRequirements() & CLP_MODULES_HAS_INFO )
{
QStringList list = QString::fromStdString( module_ptr->moduleInfo() ).split( '\n' );
windowInfoList.append( list );
}
if( windowInfoList.size() > 0 )
{
m_pcVideoInfo->setInformationTopLeft( windowInfoList );
}
}
if( m_pcCurrFrameAsset )
{
QString m_cPelFmtName = QString::fromStdString( m_pcCurrFrameAsset->getPelFmtName() );
m_cStreamInformation += " | " + m_cPelFmtName;
}
if( m_cStreamInformation.isEmpty() )
{
m_cStreamInformation = " ";
}
}
bool ModuleSubWindow::isPlaying()
{
if( auto module_ptr = m_pcDisplayModule )
{
for( auto window : module_ptr->getSubWindowList() )
{
if( window->isPlaying() )
return true;
}
}
return false;
}
void ModuleSubWindow::refreshSubWindow()
{
if( auto module_ptr = m_pcDisplayModule )
{
setFillWindow( true );
updateVideoWindowInfo();
module_ptr->apply( isPlaying(), false );
}
}
+64
View File
@@ -0,0 +1,64 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2021 by Joao Carreira (jfmcarreira@gmail.com)
* Luis Lucas (luisfrlucas@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file ModuleSubWindow.h
* \brief Video Sub windows handling
*/
#ifndef __MODULESUBWINDOW_H__
#define __MODULESUBWINDOW_H__
#include <QDataStream>
#include <QFuture>
#include <QRect>
#include <QString>
#include <QVector>
#include "CalypAppModuleIf.h"
#include "CommonDefs.h"
#include "VideoSubWindow.h"
#include "config.h"
#include "lib/CalypStream.h"
class VideoInformation;
class ModuleSubWindow : public VideoSubWindow
{
Q_OBJECT
public:
ModuleSubWindow( CalypAppModuleIf* module, QWidget* parent = 0 );
~ModuleSubWindow();
void resetWindowName();
void updateVideoWindowInfo();
bool isPlaying();
void stop(){};
void advanceOneFrame(){};
auto getFrameNum() -> std::uint64_t { return 1; };
void refreshSubWindow();
void setCurrFrame( std::shared_ptr<CalypFrame> pcCurrFrame );
};
#endif // __MODULESUBWINDOW_H__
+26 -27
View File
@@ -27,6 +27,7 @@
#include <cstdio> #include <cstdio>
#include "MainWindow.h" #include "MainWindow.h"
#include "ModuleSubWindow.h"
#include "ModulesHandleOptDialog.h" #include "ModulesHandleOptDialog.h"
#include "SubWindowHandle.h" #include "SubWindowHandle.h"
#include "SubWindowSelectorDialog.h" #include "SubWindowSelectorDialog.h"
@@ -184,18 +185,17 @@ void ModulesHandle::updateMenus()
if( pcSubWindow ) if( pcSubWindow )
{ {
auto apcCurrentModule = pcSubWindow->getModuleArray(); m_arrayActions[DISABLE_ACT]->setEnabled( pcSubWindow->hasModules() );
m_arrayActions[DISABLE_ACT]->setEnabled( apcCurrentModule.size() > 0 );
if( pcSubWindow->getDisplayModule() ) if( pcSubWindow->getDisplayModule() )
{ {
m_arrayActions[APPLY_ALL_ACT]->setEnabled( true ); m_arrayActions[APPLY_ALL_ACT]->setEnabled( true );
m_arrayActions[SWAP_FRAMES_ACT]->setEnabled( true ); m_arrayActions[SWAP_FRAMES_ACT]->setEnabled( true );
} }
for( int i = 0; i < apcCurrentModule.size(); i++ ) // for( int i = 0; i < apcCurrentModule.size(); i++ )
{ // {
currModuleAction = apcCurrentModule.at( i )->m_pcModuleAction; // currModuleAction = apcCurrentModule.at( i )->m_pcModuleAction;
currModuleAction->setChecked( true ); // currModuleAction->setChecked( true );
} // }
} }
} }
@@ -219,16 +219,15 @@ void ModulesHandle::processOpt( int index )
CalypAppModuleIf* pcCurrentModule = pcSubWindow->getDisplayModule(); CalypAppModuleIf* pcCurrentModule = pcSubWindow->getDisplayModule();
if( pcCurrentModule ) if( pcCurrentModule )
{ {
CalypAppModuleIf* pcCurrModule = pcCurrentModule;
switch( index ) switch( index )
{ {
case INVALID_OPT: case INVALID_OPT:
break; break;
case SWAP_FRAMES_ACT: case SWAP_FRAMES_ACT:
swapModulesWindowsIf( pcCurrModule ); swapModulesWindowsIf( pcCurrentModule );
break; break;
case APPLY_ALL_ACT: case APPLY_ALL_ACT:
applyAllModuleIf( pcCurrModule ); applyAllModuleIf( pcCurrentModule );
break; break;
default: default:
Q_ASSERT( 0 ); Q_ASSERT( 0 );
@@ -276,6 +275,10 @@ void ModulesHandle::activateModule()
QString ModuleIfName = pcAction->data().toString(); QString ModuleIfName = pcAction->data().toString();
auto pcCurrModuleIf = CalypModulesFactory::Get()->CreateModule( ModuleIfName.toLocal8Bit().constData() ); auto pcCurrModuleIf = CalypModulesFactory::Get()->CreateModule( ModuleIfName.toLocal8Bit().constData() );
if( pcCurrModuleIf == nullptr )
{
return;
}
auto pcCurrAppModuleIf = std::make_shared<CalypAppModuleIf>( this, pcAction, std::move( pcCurrModuleIf ) ); auto pcCurrAppModuleIf = std::make_shared<CalypAppModuleIf>( this, pcAction, std::move( pcCurrModuleIf ) );
QList<VideoSubWindow*> videoSubWindowList; QList<VideoSubWindow*> videoSubWindowList;
@@ -372,14 +375,12 @@ void ModulesHandle::activateModule()
QString windowName; QString windowName;
VideoSubWindow* pcModuleSubWindow = NULL;
if( pcCurrAppModuleIf->m_pcModule->m_iModuleType == CLP_FRAME_PROCESSING_MODULE ) if( pcCurrAppModuleIf->m_pcModule->m_iModuleType == CLP_FRAME_PROCESSING_MODULE )
{ {
if( ( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements & CLP_MODULE_REQUIRES_NEW_WINDOW ) || bShowModulesNewWindow ) if( ( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements & CLP_MODULE_REQUIRES_NEW_WINDOW ) || bShowModulesNewWindow )
{ {
pcModuleSubWindow = new VideoSubWindow( VideoSubWindow::MODULE_SUBWINDOW, pcCurrAppModuleIf.get() ); auto pcModuleSubWindow = new ModuleSubWindow( pcCurrAppModuleIf.get() );
windowName.append( QStringLiteral( "Module " ) ); pcModuleSubWindow->resetWindowName();
windowName.append( pcCurrAppModuleIf->m_pcModule->m_pchModuleLongName );
pcCurrAppModuleIf->m_pcDisplaySubWindow = pcModuleSubWindow; pcCurrAppModuleIf->m_pcDisplaySubWindow = pcModuleSubWindow;
// connect( pcModuleSubWindow->getViewArea(), SIGNAL( selectionChanged( QRect ) ), m_appModuleVideo, // connect( pcModuleSubWindow->getViewArea(), SIGNAL( selectionChanged( QRect ) ), m_appModuleVideo,
// SLOT( updateSelectionArea( QRect ) ) ); // SLOT( updateSelectionArea( QRect ) ) );
@@ -441,12 +442,11 @@ void ModulesHandle::activateModule()
QCoreApplication::processEvents(); QCoreApplication::processEvents();
if( pcModuleSubWindow ) if( pcCurrAppModuleIf->m_pcDisplaySubWindow )
{ {
pcModuleSubWindow->setWindowName( windowName ); m_pcMainWindowManager->addSubWindow( pcCurrAppModuleIf->m_pcDisplaySubWindow );
m_pcMainWindowManager->addSubWindow( pcModuleSubWindow ); pcCurrAppModuleIf->m_pcDisplaySubWindow->show();
pcModuleSubWindow->show(); m_appModuleVideo->addSubWindow( pcCurrAppModuleIf->m_pcDisplaySubWindow );
m_appModuleVideo->addSubWindow( pcModuleSubWindow );
} }
else else
{ {
@@ -506,12 +506,12 @@ void ModulesHandle::applyAllModuleIf( CalypAppModuleIf* pcCurrModuleIf )
for( unsigned int i = 0; i < supportedFmts.size(); i++ ) for( unsigned int i = 0; i < supportedFmts.size(); i++ )
{ {
std::vector<ClpString> arrayExt = supportedFmts[i].getExts(); std::vector<std::string> arrayExt = supportedFmts[i].getExts();
if( arrayExt.size() > 0 ) if( arrayExt.size() > 0 )
{ {
QString currFmt( QString::fromStdString( supportedFmts[i].formatName ) ); QString currFmt( QString::fromStdString( supportedFmts[i].formatName ) );
currFmt.append( " (" ); currFmt.append( " (" );
for( std::vector<ClpString>::iterator e = arrayExt.begin(); e != arrayExt.end(); ++e ) for( std::vector<std::string>::iterator e = arrayExt.begin(); e != arrayExt.end(); ++e )
{ {
supported.append( " *." ); supported.append( " *." );
currFmt.append( "*." ); currFmt.append( "*." );
@@ -536,7 +536,7 @@ void ModulesHandle::applyAllModuleIf( CalypAppModuleIf* pcCurrModuleIf )
Height = pcCurrModuleIf->m_pcProcessedFrame->getHeight(); Height = pcCurrModuleIf->m_pcProcessedFrame->getHeight();
InputFormat = pcCurrModuleIf->m_pcProcessedFrame->getPelFormat(); InputFormat = pcCurrModuleIf->m_pcProcessedFrame->getPelFormat();
BitsPixel = pcCurrModuleIf->m_pcProcessedFrame->getBitsPel(); BitsPixel = pcCurrModuleIf->m_pcProcessedFrame->getBitsPel();
FrameRate = pcCurrModuleIf->m_pcSubWindow[0]->getInputStream()->getFrameRate(); FrameRate = 30;
pcCurrModuleIf->m_pcModuleStream = std::unique_ptr<CalypStream>(); pcCurrModuleIf->m_pcModuleStream = std::unique_ptr<CalypStream>();
if( !pcCurrModuleIf->m_pcModuleStream->open( fileName.toStdString(), Width, Height, InputFormat, BitsPixel, if( !pcCurrModuleIf->m_pcModuleStream->open( fileName.toStdString(), Width, Height, InputFormat, BitsPixel,
@@ -550,11 +550,11 @@ void ModulesHandle::applyAllModuleIf( CalypAppModuleIf* pcCurrModuleIf )
if( pcCurrModuleIf->m_pcModuleStream ) if( pcCurrModuleIf->m_pcModuleStream )
{ {
unsigned int numberOfWindows = pcCurrModuleIf->m_pcModule->m_uiNumberOfFrames; unsigned int numberOfWindows = pcCurrModuleIf->m_pcModule->m_uiNumberOfFrames;
ClpULong currFrames = 0; std::uint64_t currFrames = 0;
ClpULong numberOfFrames = -1; std::uint64_t numberOfFrames = -1;
for( unsigned int i = 0; i < numberOfWindows; i++ ) for( unsigned int i = 0; i < numberOfWindows; i++ )
{ {
currFrames = pcCurrModuleIf->m_pcSubWindow[i]->getInputStream()->getFrameNum(); currFrames = pcCurrModuleIf->m_pcSubWindow[i]->getFrameNum();
if( currFrames < numberOfFrames ) if( currFrames < numberOfFrames )
numberOfFrames = currFrames; numberOfFrames = currFrames;
pcCurrModuleIf->m_pcSubWindow[i]->stop(); pcCurrModuleIf->m_pcSubWindow[i]->stop();
@@ -567,8 +567,7 @@ void ModulesHandle::applyAllModuleIf( CalypAppModuleIf* pcCurrModuleIf )
pcCurrModuleIf->m_pcModuleStream->writeFrame( *pcCurrModuleIf->m_pcProcessedFrame ); pcCurrModuleIf->m_pcModuleStream->writeFrame( *pcCurrModuleIf->m_pcProcessedFrame );
for( unsigned int i = 0; i < numberOfWindows; i++ ) for( unsigned int i = 0; i < numberOfWindows; i++ )
{ {
pcCurrModuleIf->m_pcSubWindow[i]->play(); pcCurrModuleIf->m_pcSubWindow[i]->advanceOneFrame();
pcCurrModuleIf->m_pcSubWindow[i]->playEvent();
} }
} }
for( unsigned int i = 0; i < numberOfWindows; i++ ) for( unsigned int i = 0; i < numberOfWindows; i++ )
-1
View File
@@ -29,7 +29,6 @@
#include <QSize> #include <QSize>
#include "qcustomplot.h" #include "qcustomplot.h"
//#include "external/qcustomplot/qcustomplot.h"
void PlotSubWindow::definePlotColors() void PlotSubWindow::definePlotColors()
{ {
+7 -9
View File
@@ -32,7 +32,6 @@
#include "SubWindowHandle.h" #include "SubWindowHandle.h"
#include "SubWindowSelectorDialog.h" #include "SubWindowSelectorDialog.h"
#include "VideoSubWindow.h" #include "VideoSubWindow.h"
#include "lib/LibMemory.h"
QualityHandle::QualityHandle( QWidget* parent, SubWindowHandle* windowManager ) QualityHandle::QualityHandle( QWidget* parent, SubWindowHandle* windowManager )
: m_pcParet( parent ), m_pcMainWindowManager( windowManager ) : m_pcParet( parent ), m_pcMainWindowManager( windowManager )
@@ -157,8 +156,8 @@ void QualityHandle::update( VideoSubWindow* currSubWindow )
void QualityHandle::measureQuality( QVector<VideoSubWindow*> apcWindowList ) void QualityHandle::measureQuality( QVector<VideoSubWindow*> apcWindowList )
{ {
unsigned numberOfWindows = apcWindowList.size(); unsigned numberOfWindows = apcWindowList.size();
ClpULong currFrames = 0; std::uint64_t currFrames = 0;
ClpULong numberOfFrames = -1; std::uint64_t numberOfFrames = -1;
//! Check reference window //! Check reference window
for( unsigned i = 0; i < numberOfWindows; i++ ) for( unsigned i = 0; i < numberOfWindows; i++ )
@@ -170,10 +169,10 @@ void QualityHandle::measureQuality( QVector<VideoSubWindow*> apcWindowList )
} }
VideoSubWindow* pcReferenceWindow = apcWindowList.at( 0 )->getRefSubWindow(); VideoSubWindow* pcReferenceWindow = apcWindowList.at( 0 )->getRefSubWindow();
numberOfFrames = pcReferenceWindow->getInputStream()->getFrameNum(); numberOfFrames = pcReferenceWindow->getFrameNum();
for( unsigned i = 0; i < numberOfWindows; i++ ) for( unsigned i = 0; i < numberOfWindows; i++ )
{ {
currFrames = apcWindowList.at( i )->getInputStream()->getFrameNum(); currFrames = apcWindowList.at( i )->getFrameNum();
if( currFrames < numberOfFrames ) if( currFrames < numberOfFrames )
numberOfFrames = currFrames; numberOfFrames = currFrames;
apcWindowList.at( i )->stop(); apcWindowList.at( i )->stop();
@@ -184,7 +183,6 @@ void QualityHandle::measureQuality( QVector<VideoSubWindow*> apcWindowList )
QVector<double>* padQualityValues = new QVector<double>[numberOfWindows + 1]; QVector<double>* padQualityValues = new QVector<double>[numberOfWindows + 1];
double* padAverageQuality = new double[numberOfWindows + 1]; double* padAverageQuality = new double[numberOfWindows + 1];
double dCurrentQuality;
for( unsigned i = 0; i < numberOfWindows + 1; i++ ) for( unsigned i = 0; i < numberOfWindows + 1; i++ )
{ {
@@ -200,12 +198,12 @@ void QualityHandle::measureQuality( QVector<VideoSubWindow*> apcWindowList )
for( unsigned int i = 0; i < numberOfWindows; i++ ) for( unsigned int i = 0; i < numberOfWindows; i++ )
{ {
pcCurrFrame = apcWindowList.at( i )->getCurrFrame(); pcCurrFrame = apcWindowList.at( i )->getCurrFrame();
dCurrentQuality = pcCurrFrame->getQuality( m_iQualityMetricIdx, pcReferenceFrame, CLP_LUMA ); double dCurrentQuality = pcCurrFrame->getQuality( m_iQualityMetricIdx, pcReferenceFrame, CLP_LUMA );
padAverageQuality[i + 1] = ( padAverageQuality[i + 1] * double( f ) + dCurrentQuality ) / double( f + 1 ); padAverageQuality[i + 1] = ( padAverageQuality[i + 1] * double( f ) + dCurrentQuality ) / double( f + 1 );
padQualityValues[i + 1].append( dCurrentQuality ); padQualityValues[i + 1].append( dCurrentQuality );
apcWindowList.at( i )->seekRelativeEvent( true ); apcWindowList.at( i )->advanceOneFrame();
} }
pcReferenceWindow->seekRelativeEvent( true ); pcReferenceWindow->advanceOneFrame();
pcProgressBar->incrementProgress( 1 ); pcProgressBar->incrementProgress( 1 );
} }
for( unsigned int i = 0; i < numberOfWindows; i++ ) for( unsigned int i = 0; i < numberOfWindows; i++ )
+1 -1
View File
@@ -25,11 +25,11 @@
#ifndef __QUALITYMEASUREMENT_H__ #ifndef __QUALITYMEASUREMENT_H__
#define __QUALITYMEASUREMENT_H__ #define __QUALITYMEASUREMENT_H__
#include <QFuture>
#include <QtCore> #include <QtCore>
#include <QtWidgets> #include <QtWidgets>
#include "CommonDefs.h" #include "CommonDefs.h"
#include "QFuture"
#include "QualityMeasurementSidebar.h" #include "QualityMeasurementSidebar.h"
#include "config.h" #include "config.h"
+15 -3
View File
@@ -26,8 +26,10 @@
#include <QCloseEvent> #include <QCloseEvent>
#include <QFocusEvent> #include <QFocusEvent>
#include <QGuiApplication>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QIcon> #include <QIcon>
#include <QScreen>
#include <QScrollBar> #include <QScrollBar>
#include "MdiSubWindow.h" #include "MdiSubWindow.h"
@@ -40,7 +42,7 @@ SubWindowAbstract::SubWindowAbstract( QWidget* parent, unsigned int category )
// setFocusPolicy( Qt::WheelFocus ); // setFocusPolicy( Qt::WheelFocus );
setFocusPolicy( Qt::StrongFocus ); setFocusPolicy( Qt::StrongFocus );
setAttribute( Qt::WA_DeleteOnClose ); setAttribute( Qt::WA_DeleteOnClose );
setBackgroundRole( QPalette::Background ); setBackgroundRole( QPalette::Window );
setWindowIcon( QIcon( ":/logos/calyp-icon.png" ) ); setWindowIcon( QIcon( ":/logos/calyp-icon.png" ) );
@@ -87,10 +89,20 @@ bool SubWindowAbstract::mayClose()
QSize SubWindowAbstract::sizeHint() const QSize SubWindowAbstract::sizeHint() const
{ {
return QSize(); QSize maxSize;
QWidget* p = parentWidget();
if( p )
{
maxSize = p->size();
}
else
{
maxSize = QGuiApplication::screens()[0]->availableGeometry().size();
}
return sizeHint( maxSize );
} }
QSize SubWindowAbstract::sizeHint( const QSize& ) const QSize SubWindowAbstract::sizeHint( const QSize& maxSize ) const
{ {
return QSize(); return QSize();
} }
+1 -1
View File
@@ -107,7 +107,7 @@ public:
* Size related functions * Size related functions
*/ */
virtual QSize sizeHint() const; virtual QSize sizeHint() const;
virtual QSize sizeHint( const QSize& ) const; virtual QSize sizeHint( const QSize& maxSize ) const;
/** /**
* Window name * Window name
+1 -1
View File
@@ -49,7 +49,7 @@ public:
MdiArea( QWidget* parent = 0 ) MdiArea( QWidget* parent = 0 )
: QMdiArea( parent ), m_pixmapLogo( ":/logos/calyp-logo.png" ) : QMdiArea( parent ), m_pixmapLogo( ":/logos/calyp-logo.png" )
{ {
setBackgroundRole( QPalette::Background ); setBackgroundRole( QPalette::Window );
} }
void appendLogMessage( const QString& msg ) void appendLogMessage( const QString& msg )
+54 -54
View File
@@ -40,6 +40,7 @@
#include "SeekStreamDialog.h" #include "SeekStreamDialog.h"
#include "SubWindowHandle.h" #include "SubWindowHandle.h"
#include "SubWindowSelectorDialog.h" #include "SubWindowSelectorDialog.h"
#include "VideoStreamSubWindow.h"
#include "VideoSubWindow.h" #include "VideoSubWindow.h"
VideoHandle::VideoHandle( QWidget* parent, SubWindowHandle* windowManager ) VideoHandle::VideoHandle( QWidget* parent, SubWindowHandle* windowManager )
@@ -325,10 +326,16 @@ void VideoHandle::update()
{ {
if( m_pcCurrentVideoSubWindow ) if( m_pcCurrentVideoSubWindow )
{ {
const CalypStream* pcStream = m_pcCurrentVideoSubWindow->getInputStream(); bool isPlaying{ false };
const CalypFrame* pcFrame = m_pcCurrentVideoSubWindow->getCurrFrame(); const CalypStream* pcStream{ nullptr };
if( auto* videoStreamSubWindow = qobject_cast<VideoStreamSubWindow*>( m_pcCurrentVideoSubWindow ) )
{
pcStream = videoStreamSubWindow->getInputStream();
isPlaying = videoStreamSubWindow->isPlaying();
}
auto pcFrame = m_pcCurrentVideoSubWindow->getCurrFrameAsset();
m_pcVideoFormatLabel->setText( m_pcCurrentVideoSubWindow->getStreamInformation() ); m_pcVideoFormatLabel->setText( m_pcCurrentVideoSubWindow->getVideoInformation() );
QString resolution; QString resolution;
if( pcFrame ) if( pcFrame )
@@ -362,7 +369,7 @@ void VideoHandle::update()
} }
} }
m_pcResolutionLabel->setText( resolution ); m_pcResolutionLabel->setText( resolution );
m_pcFramePropertiesSideBar->setFrame( m_pcCurrentVideoSubWindow->getCurrFrameAsset(), m_pcCurrentVideoSubWindow->isPlaying() ); m_pcFramePropertiesSideBar->setFrame( pcFrame, isPlaying );
m_pcFrameNumInfo->setTotalFrameNum( total_frame_num ); m_pcFrameNumInfo->setTotalFrameNum( total_frame_num );
m_pcFrameNumInfo->setCurrFrameNum( frame_num ); m_pcFrameNumInfo->setCurrFrameNum( frame_num );
@@ -433,12 +440,11 @@ void VideoHandle::addSubWindow( VideoSubWindow* window )
void VideoHandle::closeSubWindow( SubWindowAbstract* subWindow ) void VideoHandle::closeSubWindow( SubWindowAbstract* subWindow )
{ {
VideoSubWindow* videoSubWindow = qobject_cast<VideoSubWindow*>( subWindow ); auto* videoStreamSubWindow = qobject_cast<VideoStreamSubWindow*>( subWindow );
if( m_acPlayingSubWindows.contains( videoSubWindow ) ) if( m_acPlayingSubWindows.contains( videoStreamSubWindow ) )
{ {
int pos = m_acPlayingSubWindows.indexOf( videoSubWindow ); int pos = m_acPlayingSubWindows.indexOf( videoStreamSubWindow );
// m_acPlayingSubWindows.at( pos )->stop();
m_acPlayingSubWindows.remove( pos ); m_acPlayingSubWindows.remove( pos );
if( m_acPlayingSubWindows.size() < 2 ) if( m_acPlayingSubWindows.size() < 2 )
{ {
@@ -541,18 +547,18 @@ unsigned long VideoHandle::getMaxFrameNumber()
unsigned long maxFrames = INT_MAX; unsigned long maxFrames = INT_MAX;
if( m_pcCurrentVideoSubWindow ) if( m_pcCurrentVideoSubWindow )
{ {
if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) if( m_acPlayingSubWindows.contains( qobject_cast<VideoStreamSubWindow*>( m_pcCurrentVideoSubWindow ) ) )
{ {
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ ) for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{ {
currFrames = m_acPlayingSubWindows.at( i )->getInputStream()->getFrameNum(); currFrames = m_acPlayingSubWindows.at( i )->getFrameNum();
if( currFrames < maxFrames ) if( currFrames < maxFrames )
maxFrames = currFrames; maxFrames = currFrames;
} }
} }
else else
{ {
maxFrames = m_pcCurrentVideoSubWindow->getInputStream()->getFrameNum(); maxFrames = m_pcCurrentVideoSubWindow->getFrameNum();
} }
} }
return maxFrames; return maxFrames;
@@ -565,9 +571,9 @@ void VideoHandle::setTimerStatus()
{ {
status |= m_acPlayingSubWindows.at( i )->isPlaying(); status |= m_acPlayingSubWindows.at( i )->isPlaying();
} }
if( m_pcCurrentVideoSubWindow ) if( auto* videoStreamSubWindow = qobject_cast<VideoStreamSubWindow*>( m_pcCurrentVideoSubWindow ) )
{ {
status |= m_pcCurrentVideoSubWindow->isPlaying(); status |= videoStreamSubWindow->isPlaying();
} }
if( status ) if( status )
{ {
@@ -596,13 +602,12 @@ void VideoHandle::configureFrameRateTimer()
void VideoHandle::play() void VideoHandle::play()
{ {
if( !m_pcCurrentVideoSubWindow ) auto* videoStreamSubWindow = qobject_cast<VideoStreamSubWindow*>( m_pcCurrentVideoSubWindow );
if( videoStreamSubWindow == nullptr )
return; return;
if( !m_pcCurrentVideoSubWindow->getInputStream() ) if( !videoStreamSubWindow->isPlaying() ) // Not playing
return;
if( !m_pcCurrentVideoSubWindow->isPlaying() ) // Not playing
{ {
if( m_acPlayingSubWindows.size() < 2 ) if( m_acPlayingSubWindows.size() < 2 )
{ {
@@ -611,9 +616,9 @@ void VideoHandle::play()
m_acPlayingSubWindows.at( i )->pause(); m_acPlayingSubWindows.at( i )->pause();
} }
m_acPlayingSubWindows.clear(); m_acPlayingSubWindows.clear();
m_acPlayingSubWindows.append( m_pcCurrentVideoSubWindow ); m_acPlayingSubWindows.append( videoStreamSubWindow );
} }
if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) if( m_acPlayingSubWindows.contains( videoStreamSubWindow ) )
{ {
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ ) for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{ {
@@ -624,7 +629,7 @@ void VideoHandle::play()
} }
else else
{ {
if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) if( m_acPlayingSubWindows.contains( videoStreamSubWindow ) )
{ {
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ ) for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{ {
@@ -633,12 +638,11 @@ void VideoHandle::play()
} }
else else
{ {
m_pcCurrentVideoSubWindow->pause(); videoStreamSubWindow->pause();
} }
} }
setTimerStatus(); setTimerStatus();
emit changed(); emit changed();
// update();
} }
void VideoHandle::stop() void VideoHandle::stop()
@@ -675,7 +679,7 @@ void VideoHandle::calculateRealFrameRate()
void VideoHandle::playEvent() void VideoHandle::playEvent()
{ {
auto start = std::chrono::steady_clock::now(); // auto start = std::chrono::steady_clock::now();
// This value should only be true if it is really needed to refresh the UI after this play event // This value should only be true if it is really needed to refresh the UI after this play event
// Lets assume the current window is not playing. Nothing changes in the UI expect the playing windows // Lets assume the current window is not playing. Nothing changes in the UI expect the playing windows
@@ -711,9 +715,7 @@ void VideoHandle::playEvent()
} }
catch( const char* msg ) catch( const char* msg )
{ {
QString warningMsg = "Error while playing " + QString warningMsg = "Error while playing " + m_pcCurrentVideoSubWindow->getWindowName() + " with the following error: \n" + msg;
QFileInfo( m_pcCurrentVideoSubWindow->getCurrentFileName() ).fileName() +
" with the following error: \n" + msg;
QMessageBox::warning( m_pcParet, QApplication::applicationName(), warningMsg ); QMessageBox::warning( m_pcParet, QApplication::applicationName(), warningMsg );
qDebug() << warningMsg; qDebug() << warningMsg;
stop(); stop();
@@ -730,11 +732,11 @@ void VideoHandle::playEvent()
void VideoHandle::seekEvent( int direction ) void VideoHandle::seekEvent( int direction )
{ {
if( m_pcCurrentVideoSubWindow ) if( auto* videoStreamSubWindow = qobject_cast<VideoStreamSubWindow*>( m_pcCurrentVideoSubWindow ) )
{ {
if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) if( m_acPlayingSubWindows.contains( videoStreamSubWindow ) )
{ {
if( !( (unsigned int)( m_pcCurrentVideoSubWindow->getInputStream()->getCurrFrameNum() + 1 ) >= getMaxFrameNumber() && if( !( (unsigned int)( videoStreamSubWindow->getInputStream()->getCurrFrameNum() + 1 ) >= getMaxFrameNumber() &&
direction > 0 ) ) direction > 0 ) )
{ {
for( auto playingSubWindow : m_acPlayingSubWindows ) for( auto playingSubWindow : m_acPlayingSubWindows )
@@ -745,7 +747,7 @@ void VideoHandle::seekEvent( int direction )
} }
else else
{ {
m_pcCurrentVideoSubWindow->seekRelativeEvent( direction > 0 ? true : false ); videoStreamSubWindow->seekRelativeEvent( direction > 0 ? true : false );
} }
emit changed(); emit changed();
} }
@@ -753,37 +755,37 @@ void VideoHandle::seekEvent( int direction )
void VideoHandle::seekVideo() void VideoHandle::seekVideo()
{ {
if( m_pcCurrentVideoSubWindow ) if( auto* videoStreamSubWindow = qobject_cast<VideoStreamSubWindow*>( m_pcCurrentVideoSubWindow ) )
{ {
if( m_pcCurrentVideoSubWindow->getInputStream() ) SeekStreamDialog* dialogSeekVideo = new SeekStreamDialog( videoStreamSubWindow->getInputStream(), m_pcParet );
int newFrameNum = dialogSeekVideo->runDialog();
if( newFrameNum >= 0 )
{ {
SeekStreamDialog* dialogSeekVideo = if( m_acPlayingSubWindows.contains( videoStreamSubWindow ) )
new SeekStreamDialog( m_pcCurrentVideoSubWindow->getInputStream(), m_pcParet );
int newFrameNum = dialogSeekVideo->runDialog();
if( newFrameNum >= 0 )
{ {
if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) for( auto playingSubWindow : m_acPlayingSubWindows )
{ {
for( auto playingSubWindow : m_acPlayingSubWindows ) playingSubWindow->seekAbsoluteEvent( (unsigned int)newFrameNum );
{
playingSubWindow->seekAbsoluteEvent( (unsigned int)newFrameNum );
}
} }
else
{
m_pcCurrentVideoSubWindow->seekAbsoluteEvent( (unsigned int)newFrameNum );
}
emit changed();
} }
else
{
videoStreamSubWindow->seekAbsoluteEvent( (unsigned int)newFrameNum );
}
emit changed();
} }
} }
} }
void VideoHandle::seekSliderEvent( int new_frame_num ) void VideoHandle::seekSliderEvent( int new_frame_num )
{ {
if( m_pcCurrentVideoSubWindow && !m_bIsPlaying ) // TODO: Fix this slot // TODO: Fix this slot
if( m_bIsPlaying )
return;
if( auto* videoStreamSubWindow = qobject_cast<VideoStreamSubWindow*>( m_pcCurrentVideoSubWindow ) )
{ {
if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) if( m_acPlayingSubWindows.contains( videoStreamSubWindow ) )
{ {
for( auto playingSubWindow : m_acPlayingSubWindows ) for( auto playingSubWindow : m_acPlayingSubWindows )
{ {
@@ -792,7 +794,7 @@ void VideoHandle::seekSliderEvent( int new_frame_num )
} }
else else
{ {
m_pcCurrentVideoSubWindow->seekAbsoluteEvent( (unsigned int)new_frame_num ); videoStreamSubWindow->seekAbsoluteEvent( (unsigned int)new_frame_num );
} }
emit changed(); emit changed();
} }
@@ -800,8 +802,6 @@ void VideoHandle::seekSliderEvent( int new_frame_num )
void VideoHandle::videoSelectionButtonEvent() void VideoHandle::videoSelectionButtonEvent()
{ {
VideoSubWindow* videoSubWindow;
Qt::KeyboardModifiers keyModifiers = QApplication::keyboardModifiers(); Qt::KeyboardModifiers keyModifiers = QApplication::keyboardModifiers();
if( keyModifiers & Qt::ControlModifier ) if( keyModifiers & Qt::ControlModifier )
{ {
@@ -809,7 +809,7 @@ void VideoHandle::videoSelectionButtonEvent()
m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_STREAM_SUBWINDOW ); m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_STREAM_SUBWINDOW );
for( auto subWindow : subWindowList ) for( auto subWindow : subWindowList )
{ {
videoSubWindow = qobject_cast<VideoSubWindow*>( subWindow ); auto* videoSubWindow = qobject_cast<VideoStreamSubWindow*>( subWindow );
m_acPlayingSubWindows.append( videoSubWindow ); m_acPlayingSubWindows.append( videoSubWindow );
} }
} }
@@ -829,7 +829,7 @@ void VideoHandle::videoSelectionButtonEvent()
QList<SubWindowAbstract*> selectedSubWindowList = dialogWindowsSelection.getSelectedWindows(); QList<SubWindowAbstract*> selectedSubWindowList = dialogWindowsSelection.getSelectedWindows();
for( auto window : selectedSubWindowList ) for( auto window : selectedSubWindowList )
{ {
videoSubWindow = qobject_cast<VideoSubWindow*>( window ); auto* videoSubWindow = qobject_cast<VideoStreamSubWindow*>( window );
m_acPlayingSubWindows.append( videoSubWindow ); m_acPlayingSubWindows.append( videoSubWindow );
} }
} }
+4 -3
View File
@@ -33,6 +33,7 @@
#include <QWidget> #include <QWidget>
#include "CommonDefs.h" #include "CommonDefs.h"
#include "VideoSubWindow.h"
#include "config.h" #include "config.h"
class QToolBar; class QToolBar;
@@ -43,7 +44,7 @@ class QSlider;
class SubWindowHandle; class SubWindowHandle;
class SubWindowAbstract; class SubWindowAbstract;
class VideoSubWindow; class VideoStreamSubWindow;
class FramePropertiesDock; class FramePropertiesDock;
class FrameNumberWidget; class FrameNumberWidget;
class QTimer; class QTimer;
@@ -116,8 +117,8 @@ private:
QLabel* m_pcVideoFormatLabel; QLabel* m_pcVideoFormatLabel;
QLabel* m_pcResolutionLabel; QLabel* m_pcResolutionLabel;
VideoSubWindow* m_pcCurrentVideoSubWindow; QPointer<VideoSubWindow> m_pcCurrentVideoSubWindow;
QVector<VideoSubWindow*> m_acPlayingSubWindows; QVector<VideoStreamSubWindow*> m_acPlayingSubWindows;
QTimer* m_pcPlayingTimer; QTimer* m_pcPlayingTimer;
bool m_bIsPlaying; bool m_bIsPlaying;
+595
View File
@@ -0,0 +1,595 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2021 by Joao Carreira (jfmcarreira@gmail.com)
* Luis Lucas (luisfrlucas@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file VideoStreamSubWindow.cpp
* \brief Video Sub windows handling
*/
#include "VideoStreamSubWindow.h"
#include <QScrollArea>
#include <QSettings>
#include <QStaticText>
#include <cassert>
#include "ConfigureFormatDialog.h"
#include "ModulesHandle.h"
#include "QtConcurrent/qtconcurrentrun.h"
#include "ResourceHandle.h"
#include "SubWindowAbstract.h"
#define QT_NO_CONCURRENT
/**
* \brief Functions to control data stream from stream information
*/
QDataStream& operator<<( QDataStream& out, const CalypFileInfoVector& array )
{
CalypFileInfo d;
out << array.size();
for( int i = 0; i < array.size(); i++ )
{
d = array.at( i );
out << d.m_cFilename << d.m_uiWidth << d.m_uiHeight << d.m_iPelFormat << d.m_uiBitsPelPixel << d.m_iEndianness
<< d.m_uiFrameRate << d.m_uiFileSize;
}
return out;
}
QDataStream& operator>>( QDataStream& in, CalypFileInfoVector& array )
{
CalypFileInfo d;
int array_size{ 0 };
in >> array_size;
for( int i = 0; i < array_size; i++ )
{
in >> d.m_cFilename;
in >> d.m_uiWidth;
in >> d.m_uiHeight;
in >> d.m_iPelFormat;
in >> d.m_uiBitsPelPixel;
in >> d.m_iEndianness;
in >> d.m_uiFrameRate;
in >> d.m_uiFileSize;
array.append( d );
}
return in;
}
int findCalypStreamInfo( CalypFileInfoVector array, QString filename )
{
for( int i = 0; i < array.size(); i++ )
if( array.at( i ).m_cFilename == filename )
return i;
return -1;
}
VideoStreamSubWindow::VideoStreamSubWindow( QWidget* parent )
: VideoSubWindow( VideoSubWindow::VIDEO_STREAM_SUBWINDOW, parent )
, m_pcResourceManager( nullptr )
, m_pCurrStream( NULL )
, m_bIsPlaying( false )
{
}
VideoStreamSubWindow::~VideoStreamSubWindow()
{
if( m_pcResourceManager )
m_pcResourceManager->removeResource( m_uiResourceId );
}
void VideoStreamSubWindow::resetWindowName()
{
setWindowName( QFileInfo( m_cFilename ).fileName() );
}
void VideoStreamSubWindow::updateVideoWindowInfo()
{
m_cStreamInformation = "";
if( m_pcDisplayModule )
{
m_cStreamInformation = "Module";
const auto& arraySubWindows = m_pcDisplayModule->getSubWindowList();
QStringList windowInfoList;
if( arraySubWindows.size() > 0 )
{
for( std::size_t i = 0; i < arraySubWindows.size(); i++ )
{
if( arraySubWindows[i]->getWindowName() != getWindowName() )
{
windowInfoList.append( QString( "Input %1 - " + arraySubWindows[i]->getWindowName() ).arg( i + 1 ) );
}
}
}
if( m_pcDisplayModule->getModuleRequirements() & CLP_MODULES_HAS_INFO )
{
QStringList list = QString::fromStdString( m_pcDisplayModule->moduleInfo() ).split( '\n' );
windowInfoList.append( list );
}
if( windowInfoList.size() > 0 )
{
m_pcVideoInfo->setInformationTopLeft( windowInfoList );
}
}
else if( m_pCurrStream )
{
QString m_cFormatName = QString::fromStdString( m_pCurrStream->getFormatName() );
QString m_cCodedName = QString::fromStdString( m_pCurrStream->getCodecName() );
m_cStreamInformation = m_cFormatName + " | " + m_cCodedName;
}
if( m_pcCurrFrameAsset )
{
QString m_cPelFmtName = QString::fromStdString( m_pcCurrFrameAsset->getPelFmtName() );
if( m_pCurrStream )
if( !m_pCurrStream->isNative() )
m_cPelFmtName += "*";
m_cStreamInformation += " | " + m_cPelFmtName;
}
if( m_cStreamInformation.isEmpty() )
{
m_cStreamInformation = " ";
}
}
void VideoStreamSubWindow::loadAll()
{
QApplication::setOverrideCursor( Qt::WaitCursor );
m_pCurrStream->loadAll();
refreshFrame();
QApplication::restoreOverrideCursor();
}
bool VideoStreamSubWindow::loadFile( QString cFilename, bool bForceDialog )
{
assert( m_pcResourceManager != nullptr );
ConfigureFormatDialog formatDialog( this );
unsigned int Width = 0, Height = 0, BitsPel = 8, FrameRate = 30;
int Endianness = CLP_LITTLE_ENDIAN;
int InputFormat = CLP_YUV420P;
QSettings appSettings;
if( m_pCurrStream )
m_pCurrStream->getFormat( Width, Height, InputFormat, BitsPel, Endianness, FrameRate );
else
m_uiResourceId = m_pcResourceManager->getResource( nullptr );
m_pCurrStream = m_pcResourceManager->getResourceAsset( m_uiResourceId );
bool bConfig = true;
if( !bForceDialog )
{
bConfig = guessFormat( cFilename, Width, Height, InputFormat, BitsPel, Endianness, FrameRate );
if( bConfig )
{
// Pre-load values with last opened file
Width = appSettings.value( "VideoStreamSubWindow/LastWidth" ).value<unsigned int>();
Height = appSettings.value( "VideoStreamSubWindow/LastHeight" ).value<unsigned int>();
BitsPel = appSettings.value( "VideoStreamSubWindow/LastBitsPerPixel" ).value<unsigned int>();
}
}
bool bRet = false;
for( int iPass = 0; iPass < 2 && !bRet; iPass++ )
{
if( iPass || bConfig )
{
if( formatDialog.runConfigureFormatDialog( QFileInfo( cFilename ).fileName(), Width, Height, InputFormat, BitsPel,
Endianness, FrameRate ) == QDialog::Rejected )
{
return false;
}
}
try
{
bRet = m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, BitsPel, Endianness, FrameRate, true );
}
catch( CalypFailure& e )
{
if( iPass == 1 )
throw( e );
}
}
m_sStreamInfo.m_cFilename = cFilename;
m_sStreamInfo.m_uiWidth = Width;
m_sStreamInfo.m_uiHeight = Height;
m_sStreamInfo.m_iPelFormat = InputFormat;
m_sStreamInfo.m_uiBitsPelPixel = BitsPel;
m_sStreamInfo.m_iEndianness = Endianness;
m_sStreamInfo.m_uiFrameRate = FrameRate;
m_sStreamInfo.m_uiFileSize = QFileInfo( cFilename ).size();
QVariant var;
var.setValue<unsigned int>( Width );
appSettings.setValue( "VideoStreamSubWindow/LastWidth", var );
var.setValue<unsigned int>( Height );
appSettings.setValue( "VideoStreamSubWindow/LastHeight", var );
var.setValue<unsigned int>( BitsPel );
appSettings.setValue( "VideoStreamSubWindow/LastBitsPerPixel", var );
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->startResourceWorker( m_uiResourceId );
#endif
QApplication::restoreOverrideCursor();
refreshFrame();
m_cFilename = cFilename;
updateVideoWindowInfo();
setWindowName( QFileInfo( m_cFilename ).fileName() );
return true;
}
bool VideoStreamSubWindow::loadFile( CalypFileInfo* streamInfo )
{
assert( m_pcResourceManager != nullptr );
m_uiResourceId = m_pcResourceManager->getResource( m_pCurrStream );
m_pCurrStream = m_pcResourceManager->getResourceAsset( m_uiResourceId );
if( !m_pCurrStream->open( streamInfo->m_cFilename.toStdString(), streamInfo->m_uiWidth, streamInfo->m_uiHeight,
streamInfo->m_iPelFormat, streamInfo->m_uiBitsPelPixel, streamInfo->m_iEndianness,
streamInfo->m_uiFrameRate, true ) )
{
return false;
}
m_sStreamInfo = *streamInfo;
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->startResourceWorker( m_uiResourceId );
#endif
QApplication::restoreOverrideCursor();
refreshFrame();
m_cFilename = streamInfo->m_cFilename;
updateVideoWindowInfo();
setWindowName( QFileInfo( m_cFilename ).fileName() );
return true;
}
bool VideoStreamSubWindow::guessFormat( QString filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel,
int& rEndianness, unsigned int& rFrameRate )
{
std::vector<CalypStandardResolution> stdResList = CalypStream::stdResolutionSizes();
bool bGuessed = true;
bool bGuessedByFilesize = false;
QString FilenameShort = QFileInfo( filename ).fileName();
QString fileExtension = QFileInfo( filename ).suffix();
if( filename.startsWith( "/dev/" ) )
{
return false;
}
if( !fileExtension.compare( "yuv", Qt::CaseInsensitive ) || !fileExtension.compare( "rgb", Qt::CaseInsensitive ) ||
!fileExtension.compare( "gray", Qt::CaseInsensitive ) )
{
bGuessed = false;
// Guess pixel format
auto formats_list = CalypFrame::supportedPixelFormatListNames();
for( std::size_t i = 0; i < formats_list.size(); i++ )
{
if( FilenameShort.contains( formats_list[i].c_str(), Qt::CaseInsensitive ) )
{
rInputFormat = i;
break;
}
}
if( rWidth == 0 || rHeight == 0 )
{
// Guess resolution - match resolution name
int iMatch = -1;
for( unsigned int i = 0; i < stdResList.size(); i++ )
{
if( FilenameShort.contains( QString::fromStdString( stdResList[i].shortName ) ) )
{
iMatch = i;
}
}
if( iMatch >= 0 )
{
rWidth = stdResList[iMatch].uiWidth;
rHeight = stdResList[iMatch].uiHeight;
}
// Guess resolution - match %dx%d
//QRegularExpressionMatch resolutionMatch = QRegularExpression( "_\\d*x\\d*" ).match( FilenameShort );
QRegularExpressionMatch resolutionMatch = QRegularExpression( "_[0-9]+x[0-9]+" ).match( FilenameShort );
if( resolutionMatch.hasMatch() )
{
QString resolutionString = resolutionMatch.captured( resolutionMatch.lastCapturedIndex() );
if( resolutionString.startsWith( "_" ) || resolutionString.endsWith( "_" ) )
{
resolutionString.remove( "_" );
QStringList resolutionArgs = resolutionString.split( "x" );
if( resolutionArgs.size() == 2 )
{
rWidth = resolutionArgs.at( 0 ).toUInt();
rHeight = resolutionArgs.at( 1 ).toUInt();
}
}
}
}
// Guess resolution by file size
if( rWidth == 0 && rHeight == 0 )
{
FILE* pF = fopen( filename.toStdString().c_str(), "rb" );
if( pF )
{
fseek( pF, 0, SEEK_END );
unsigned long long int uiFileSize = ftell( pF );
fclose( pF );
int count = 0, module, frame_bytes, match;
for( unsigned int i = 0; i < stdResList.size(); i++ )
{
frame_bytes =
CalypFrame::getBytesPerFrame( stdResList[i].uiWidth, stdResList[i].uiHeight, rInputFormat, 8 );
module = uiFileSize % frame_bytes;
if( module == 0 )
{
match = i;
count++;
}
}
if( count == 1 )
{
rWidth = stdResList[match].uiWidth;
rHeight = stdResList[match].uiHeight;
bGuessedByFilesize = true;
}
}
}
// [.|_]
// Guess bits per pixel - match %dbpp
QRegularExpressionMatch BppMatch = QRegularExpression( "_[0-9]+bpp" ).match( FilenameShort );
if( BppMatch.hasMatch() )
{
QString matchString = BppMatch.captured( BppMatch.lastCapturedIndex() );
matchString.remove( "_" );
matchString.remove( "bpp" );
rBitsPerPixel = matchString.toUInt();
if( !( rBitsPerPixel > 0 && rBitsPerPixel < 16 ) )
{
rBitsPerPixel = -1;
}
}
QRegularExpressionMatch BppOnlybMatch = QRegularExpression( "_[0-9]+b" ).match( FilenameShort );
if( BppOnlybMatch.hasMatch() )
{
QString matchString = BppOnlybMatch.captured( BppOnlybMatch.lastCapturedIndex() );
matchString.remove( "_" );
matchString.remove( "b" );
rBitsPerPixel = matchString.toUInt();
if( !( rBitsPerPixel > 0 && rBitsPerPixel < 16 ) )
{
rBitsPerPixel = -1;
}
}
// Guess frame rate - match %dbpp
QRegularExpressionMatch FpsMatch = QRegularExpression( "_[0-9]+fps" ).match( FilenameShort );
if( FpsMatch.hasMatch() )
{
QString matchString = FpsMatch.captured( FpsMatch.lastCapturedIndex() );
matchString.remove( "_" );
matchString.remove( "fps" );
rFrameRate = matchString.toUInt();
if( rFrameRate < 0 )
{
rFrameRate = 30;
}
}
// Guess Endianness
if( FilenameShort.contains( QStringLiteral( "be" ), Qt::CaseInsensitive ) )
{
rEndianness = CLP_BIG_ENDIAN;
}
if( FilenameShort.contains( QStringLiteral( "le" ), Qt::CaseInsensitive ) )
{
rEndianness = CLP_LITTLE_ENDIAN;
}
if( rWidth > 0 && rHeight > 0 && rInputFormat >= 0 )
bGuessed = true && !bGuessedByFilesize;
}
return !bGuessed;
}
void VideoStreamSubWindow::refreshSubWindow()
{
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->stopResourceWorker( m_uiResourceId );
#endif
if( !m_pCurrStream->reload() )
{
close();
return;
}
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->startResourceWorker( m_uiResourceId );
#endif
updateVideoWindowInfo();
refreshFrame();
}
void VideoStreamSubWindow::refreshFrame()
{
bool bSetFrame = true;
m_pcCurrFrameAsset = m_pCurrStream->getCurrFrameAsset();
if( m_pcDisplayModule )
{
//bool disableThreads = !m_bIsPlaying && hasAssociatedModule();
m_pcDisplayModule->apply( m_bIsPlaying, true );
bSetFrame = false;
}
if( bSetFrame )
VideoSubWindow::refreshFrame();
}
void VideoStreamSubWindow::refreshFrame( bool bThreaded )
{
#ifndef QT_NO_CONCURRENT
m_cRefreshResult.waitForFinished();
if( bThreaded )
{
m_cRefreshResult = QtConcurrent::run( this, &VideoSubWindow::refreshFrame );
}
else
#endif
{
refreshFrame();
}
}
bool VideoStreamSubWindow::goToNextFrame( bool bThreaded )
{
#ifndef QT_NO_CONCURRENT
m_cRefreshResult.waitForFinished();
m_cReadResult.waitForFinished();
#endif
#ifdef CALYP_MANAGED_RESOURCES
while( !m_pCurrStream->hasNextFrame() && !m_pCurrStream->isEof() )
{
}
#endif
bool bEndOfSeq = m_pCurrStream->setNextFrame();
#ifdef CALYP_MANAGED_RESOURCES
bThreaded = false;
m_pcResourceManager->wakeResourceWorker( m_uiResourceId );
#endif
if( !bEndOfSeq )
{
#ifndef QT_NO_CONCURRENT
m_cRefreshResult.waitForFinished();
if( bThreaded )
{
m_cReadResult = QtConcurrent::run( m_pCurrStream, &CalypStream::readNextFrameFillRGBBuffer );
refreshFrame( bThreaded );
}
else
#endif
{
refreshFrame( bThreaded );
#ifndef CALYP_MANAGED_RESOURCES
m_pCurrStream->readNextFrameFillRGBBuffer();
#endif
}
}
return bEndOfSeq;
}
bool VideoStreamSubWindow::saveStream( QString filename )
{
bool iRet = false;
QApplication::setOverrideCursor( Qt::WaitCursor );
// TODO: implement this
QApplication::restoreOverrideCursor();
return iRet;
}
bool VideoStreamSubWindow::isPlaying()
{
return m_bIsPlaying;
}
bool VideoStreamSubWindow::play()
{
bool isPlaying = false;
if( m_pCurrStream && m_pCurrStream->getFrameNum() > 1 )
{
isPlaying = true;
}
m_bIsPlaying = isPlaying;
return m_bIsPlaying;
}
bool VideoStreamSubWindow::playEvent()
{
bool bEndOfSeq = false;
if( m_pCurrStream && m_bIsPlaying )
{
bEndOfSeq = goToNextFrame( true );
}
return bEndOfSeq;
}
void VideoStreamSubWindow::pause()
{
m_bIsPlaying = false;
refreshFrame();
}
void VideoStreamSubWindow::seekAbsoluteEvent( unsigned int new_frame_num )
{
if( m_pCurrStream )
{
if( m_pCurrStream->seekInput( new_frame_num ) )
refreshFrame();
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->wakeResourceWorker( m_uiResourceId );
#endif
}
}
void VideoStreamSubWindow::seekRelativeEvent( bool bIsFoward )
{
if( m_pCurrStream )
{
if( bIsFoward )
{
goToNextFrame( true );
}
else
{
m_pCurrStream->seekInputRelative( bIsFoward );
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->wakeResourceWorker( m_uiResourceId );
#endif
refreshFrame();
}
}
}
void VideoStreamSubWindow::stop()
{
#ifndef QT_NO_CONCURRENT
m_cRefreshResult.waitForFinished();
m_cReadResult.waitForFinished();
#endif
m_bIsPlaying = false;
seekAbsoluteEvent( 0 );
return;
}
+132
View File
@@ -0,0 +1,132 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2021 by Joao Carreira (jfmcarreira@gmail.com)
* Luis Lucas (luisfrlucas@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file VideoStreamSubWindow.h
* \brief Video Sub windows handling
*/
#ifndef __VIDEOSTREAMSUBWINDOW_H__
#define __VIDEOSTREAMSUBWINDOW_H__
#include <QDataStream>
#include <QFuture>
#include <QRect>
#include <QString>
#include <QVector>
#include <cstdint>
#include "CommonDefs.h"
#include "VideoSubWindow.h"
#include "config.h"
#include "lib/CalypStream.h"
class QScrollArea;
class VideoInformation;
class VideoStreamSubWindow;
class ResourceHandle;
class CalypAppModuleIf;
typedef struct
{
QString m_cFilename;
unsigned int m_uiWidth;
unsigned int m_uiHeight;
int m_iPelFormat;
unsigned int m_uiBitsPelPixel;
unsigned int m_iEndianness;
unsigned int m_uiFrameRate;
unsigned long long int m_uiFileSize;
} CalypFileInfo;
typedef QVector<CalypFileInfo> CalypFileInfoVector;
QDataStream& operator<<( QDataStream& out, const CalypFileInfoVector& d );
QDataStream& operator>>( QDataStream& in, CalypFileInfoVector& d );
int findCalypStreamInfo( CalypFileInfoVector array, QString filename );
class VideoStreamSubWindow : public VideoSubWindow
{
Q_OBJECT
public:
VideoStreamSubWindow( QWidget* parent = 0 );
~VideoStreamSubWindow();
void resetWindowName() override;
void updateVideoWindowInfo() override;
bool isPlaying() override;
void stop() override;
void advanceOneFrame() override { goToNextFrame( true ); }
auto getFrameNum() -> std::uint64_t override { return m_pCurrStream->getFrameNum(); }
void setResourceManaget( ResourceHandle* resourceManager ) { m_pcResourceManager = resourceManager; }
bool loadFile( QString cFilename, bool bForceDialog = false );
bool loadFile( CalypFileInfo* streamInfo );
void loadAll();
bool saveStream( QString filename );
bool play();
void pause();
bool playEvent();
void seekAbsoluteEvent( unsigned int new_frame_num );
void seekRelativeEvent( bool bIsFoward );
CalypFileInfo getStreamInfo() { return m_sStreamInfo; }
const CalypStream* getInputStream() { return m_pCurrStream; }
const CalypStream* getCurrStream() { return m_pCurrStream; }
QString getCurrentFileName() { return m_cFilename; }
void refreshSubWindow() override;
void refreshFrame();
void refreshFrame( bool bThreaded );
private:
bool goToNextFrame( bool bThreaded );
static bool guessFormat( QString filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel,
int& rEndianness, unsigned int& rFrameRate );
private: // NO_LINT
ResourceHandle* m_pcResourceManager;
QString m_cFilename;
CalypFileInfo m_sStreamInfo;
std::size_t m_uiResourceId;
CalypStream* m_pCurrStream;
QString m_cCurrFileName;
bool m_bIsPlaying;
/**
* Threads variables
* QtConcurrent
*/
QFuture<void> m_cRefreshResult;
QFuture<void> m_cReadResult;
};
Q_DECLARE_METATYPE( CalypFileInfo ) // NOLINT
Q_DECLARE_METATYPE( CalypFileInfoVector ) // NOLINT
#endif // __VIDEOSTREAMSUBWINDOW_H__
+81 -708
View File
@@ -31,127 +31,59 @@
#include "ConfigureFormatDialog.h" #include "ConfigureFormatDialog.h"
#include "ModulesHandle.h" #include "ModulesHandle.h"
#include "QtConcurrent/qtconcurrentrun.h"
#include "ResourceHandle.h"
#include "SubWindowAbstract.h" #include "SubWindowAbstract.h"
#define QT_NO_CONCURRENT VideoInformation::VideoInformation( QWidget* parent )
: QWidget( parent ), m_bBusyWindow( false )
/**
* \brief Functions to control data stream from stream information
*/
QDataStream& operator<<( QDataStream& out, const CalypFileInfoVector& array )
{ {
CalypFileInfo d; setPalette( Qt::transparent );
out << array.size(); setAttribute( Qt::WA_TransparentForMouseEvents );
for( int i = 0; i < array.size(); i++ ) m_cTopLeftTextFont.setPointSize( 8 );
{ m_cCenterTextFont.setPointSize( 12 );
d = array.at( i ); m_pcRefreshTimer = new QTimer;
out << d.m_cFilename << d.m_uiWidth << d.m_uiHeight << d.m_iPelFormat << d.m_uiBitsPelPixel << d.m_iEndianness m_pcRefreshTimer->setSingleShot( true );
<< d.m_uiFrameRate << d.m_uiFileSize;
}
return out;
} }
QDataStream& operator>>( QDataStream& in, CalypFileInfoVector& array ) void VideoInformation::setInformationTopLeft( const QStringList& textLines )
{ {
CalypFileInfo d; m_cTopLeftTextList.clear();
int array_size{ 0 }; for( int i = 0; i < textLines.size(); i++ )
in >> array_size;
for( int i = 0; i < array_size; i++ )
{ {
in >> d.m_cFilename; m_cTopLeftTextList.append( QStaticText( textLines.at( i ) ) );
in >> d.m_uiWidth;
in >> d.m_uiHeight;
in >> d.m_iPelFormat;
in >> d.m_uiBitsPelPixel;
in >> d.m_iEndianness;
in >> d.m_uiFrameRate;
in >> d.m_uiFileSize;
array.append( d );
} }
return in;
} }
int findCalypStreamInfo( CalypFileInfoVector array, QString filename ) void VideoInformation::setBusyWindow( bool bFlag )
{ {
for( int i = 0; i < array.size(); i++ ) m_bBusyWindow = bFlag;
if( array.at( i ).m_cFilename == filename ) // Do not show the refresh screen if it takes less than 500 ms
return i; m_pcRefreshTimer->start( 500 );
return -1;
} }
/** void VideoInformation::paintEvent( QPaintEvent* event )
* \class VideoInformation
* \brief Shows information about video sub window
*/
class VideoInformation : public QWidget
{ {
private: QPainter painter( this );
QTimer* m_pcRefreshTimer; painter.setFont( m_cTopLeftTextFont );
QList<QStaticText> m_cTopLeftTextList; if( !m_cTopLeftTextList.isEmpty() && size().width() > 300 )
QFont m_cTopLeftTextFont;
QFont m_cCenterTextFont;
bool m_bBusyWindow;
public:
VideoInformation( QWidget* parent )
: QWidget( parent ), m_bBusyWindow( false )
{ {
setPalette( Qt::transparent ); QPoint topLeftCorner( 10, 10 );
setAttribute( Qt::WA_TransparentForMouseEvents ); for( int i = 0; i < m_cTopLeftTextList.size(); i++ )
m_cTopLeftTextFont.setPointSize( 8 );
m_cCenterTextFont.setPointSize( 12 );
m_pcRefreshTimer = new QTimer;
m_pcRefreshTimer->setSingleShot( true );
}
void setInformationTopLeft( const QStringList& textLines )
{
m_cTopLeftTextList.clear();
for( int i = 0; i < textLines.size(); i++ )
{ {
m_cTopLeftTextList.append( QStaticText( textLines.at( i ) ) ); painter.drawStaticText( topLeftCorner, m_cTopLeftTextList.at( i ) );
topLeftCorner += QPoint( 0, 15 );
} }
} }
void setBusyWindow( bool bFlag ) if( m_bBusyWindow && !m_pcRefreshTimer->isActive() )
{ {
m_bBusyWindow = bFlag; painter.setFont( m_cCenterTextFont );
// Do not show the refresh screen if it takes less than 500 ms painter.drawText( rect(), Qt::AlignHCenter | Qt::AlignVCenter, QStringLiteral( "Refreshing..." ) );
m_pcRefreshTimer->start( 500 ); painter.fillRect( rect(), QBrush( QColor::fromRgb( 255, 255, 255, 50 ), Qt::SolidPattern ) );
} }
}
protected:
void paintEvent( QPaintEvent* event )
{
QPainter painter( this );
painter.setFont( m_cTopLeftTextFont );
if( !m_cTopLeftTextList.isEmpty() && size().width() > 300 )
{
QPoint topLeftCorner( 10, 10 );
for( int i = 0; i < m_cTopLeftTextList.size(); i++ )
{
painter.drawStaticText( topLeftCorner, m_cTopLeftTextList.at( i ) );
topLeftCorner += QPoint( 0, 15 );
}
}
if( m_bBusyWindow && !m_pcRefreshTimer->isActive() )
{
painter.setFont( m_cCenterTextFont );
painter.drawText( rect(), Qt::AlignHCenter | Qt::AlignVCenter, QStringLiteral( "Refreshing..." ) );
painter.fillRect( rect(), QBrush( QColor::fromRgb( 255, 255, 255, 50 ), Qt::SolidPattern ) );
}
}
};
VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget* parent ) VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget* parent )
: SubWindowAbstract( parent, SubWindowAbstract::VIDEO_SUBWINDOW | category ) : SubWindowAbstract( parent, SubWindowAbstract::VIDEO_SUBWINDOW | category )
, m_pcResourceManager( nullptr )
, m_bWindowBusy( false )
, m_pCurrStream( NULL )
, m_pcReferenceSubWindow( NULL ) , m_pcReferenceSubWindow( NULL )
, m_bIsPlaying( false )
, m_pcUpdateTimer( NULL ) , m_pcUpdateTimer( NULL )
{ {
// Create a new scroll area inside the sub-window // Create a new scroll area inside the sub-window
@@ -194,17 +126,16 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget*
m_pcVideoInfo = new VideoInformation( this ); m_pcVideoInfo = new VideoInformation( this );
} }
VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, CalypAppModuleIf* displayModule, QWidget* parent )
: VideoSubWindow( category, parent )
{
m_pcCurrentDisplayModule = displayModule;
}
VideoSubWindow::~VideoSubWindow() VideoSubWindow::~VideoSubWindow()
{ {
auto tmpModules = m_associatedModules;
m_associatedModules.clear();
for( auto module : tmpModules )
{
module->disable();
}
m_pcCurrFrameAsset = nullptr; m_pcCurrFrameAsset = nullptr;
if( m_pcResourceManager )
m_pcResourceManager->removeResource( m_uiResourceId );
delete m_pcUpdateTimer; delete m_pcUpdateTimer;
} }
@@ -214,16 +145,9 @@ VideoSubWindow::~VideoSubWindow()
void VideoSubWindow::closeEvent( QCloseEvent* event ) void VideoSubWindow::closeEvent( QCloseEvent* event )
{ {
//stop(); if( m_pcDisplayModule )
auto tmpModules = m_associatedModules;
m_associatedModules.clear();
for( auto module : tmpModules )
{ {
module->disable(); m_pcDisplayModule->disable();
}
if( m_pcCurrentDisplayModule )
{
m_pcCurrentDisplayModule->disable();
event->ignore(); event->ignore();
return; return;
} }
@@ -232,24 +156,24 @@ void VideoSubWindow::closeEvent( QCloseEvent* event )
void VideoSubWindow::keyPressEvent( QKeyEvent* event ) void VideoSubWindow::keyPressEvent( QKeyEvent* event )
{ {
if( m_pcCurrentDisplayModule ) if( m_pcDisplayModule )
{ {
if( m_pcCurrentDisplayModule->getModuleRequirements() & CLP_MODULE_USES_KEYS ) if( m_pcDisplayModule->getModuleRequirements() & CLP_MODULE_USES_KEYS )
{ {
bool bRet = false; bool bRet = false;
switch( event->key() ) switch( event->key() )
{ {
case Qt::Key_A: case Qt::Key_A:
bRet = m_pcCurrentDisplayModule->getModule()->keyPressed( MODULE_KEY_LEFT ); bRet = m_pcDisplayModule->getModule()->keyPressed( MODULE_KEY_LEFT );
break; break;
case Qt::Key_D: case Qt::Key_D:
bRet = m_pcCurrentDisplayModule->getModule()->keyPressed( MODULE_KEY_RIGHT ); bRet = m_pcDisplayModule->getModule()->keyPressed( MODULE_KEY_RIGHT );
break; break;
case Qt::Key_W: case Qt::Key_W:
bRet = m_pcCurrentDisplayModule->getModule()->keyPressed( MODULE_KEY_UP ); bRet = m_pcDisplayModule->getModule()->keyPressed( MODULE_KEY_UP );
break; break;
case Qt::Key_S: case Qt::Key_S:
bRet = m_pcCurrentDisplayModule->getModule()->keyPressed( MODULE_KEY_DOWN ); bRet = m_pcDisplayModule->getModule()->keyPressed( MODULE_KEY_DOWN );
break; break;
} }
if( bRet ) if( bRet )
@@ -271,36 +195,18 @@ void VideoSubWindow::resizeEvent( QResizeEvent* event )
/** /**
* Size related handlers * Size related handlers
*/ */
QSize VideoSubWindow::sizeHint() const
{
QSize maxSize;
QWidget* p = parentWidget();
if( p )
{
maxSize = p->size();
}
else
{
maxSize = QGuiApplication::screens()[0]->availableGeometry().size();
}
return sizeHint( maxSize );
}
QSize VideoSubWindow::sizeHint( const QSize& maxSize ) const QSize VideoSubWindow::sizeHint( const QSize& maxSize ) const
{ {
QSize isize; QSize isize;
if( m_pcCurrFrameAsset ) if( m_pcCurrFrameAsset )
isize = QSize( m_pcCurrFrameAsset->getWidth() + 50, m_pcCurrFrameAsset->getHeight() + 50 );
else if( m_pCurrStream )
isize = QSize( m_pCurrStream->getWidth() + 50, m_pCurrStream->getHeight() + 50 );
// If the VideoSubWindow needs more space that the avaiable, we'll give
// to the subwindow a reasonable size preserving the image aspect ratio.
if( !( isize.width() < maxSize.width() && isize.height() < maxSize.height() ) )
{ {
isize.scale( maxSize, Qt::KeepAspectRatio ); isize = QSize( m_pcCurrFrameAsset->getWidth() + 50, m_pcCurrFrameAsset->getHeight() + 50 );
// If the VideoSubWindow needs more space that the avaiable, we'll give
// to the subwindow a reasonable size preserving the image aspect ratio.
if( !( isize.width() < maxSize.width() && isize.height() < maxSize.height() ) )
{
isize.scale( maxSize, Qt::KeepAspectRatio );
}
} }
return isize; return isize;
} }
@@ -310,348 +216,6 @@ void VideoSubWindow::updateWindowOnTimeout()
m_pcVideoInfo->update(); m_pcVideoInfo->update();
} }
void VideoSubWindow::loadAll()
{
QApplication::setOverrideCursor( Qt::WaitCursor );
m_pCurrStream->loadAll();
refreshFrame();
QApplication::restoreOverrideCursor();
}
void VideoSubWindow::refreshSubWindow()
{
if( getCategory() & SubWindowAbstract::VIDEO_STREAM_SUBWINDOW )
{
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->stopResourceWorker( m_uiResourceId );
#endif
if( !m_pCurrStream->reload() )
{
close();
return;
}
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->startResourceWorker( m_uiResourceId );
#endif
}
updateVideoWindowInfo();
refreshFrame();
}
bool VideoSubWindow::loadFile( QString cFilename, bool bForceDialog )
{
assert( m_pcResourceManager != nullptr );
ConfigureFormatDialog formatDialog( this );
unsigned int Width = 0, Height = 0, BitsPel = 8, FrameRate = 30;
int Endianness = CLP_LITTLE_ENDIAN;
int InputFormat = CLP_YUV420P;
QSettings appSettings;
if( m_pCurrStream )
m_pCurrStream->getFormat( Width, Height, InputFormat, BitsPel, Endianness, FrameRate );
else
m_uiResourceId = m_pcResourceManager->getResource( nullptr );
m_pCurrStream = m_pcResourceManager->getResourceAsset( m_uiResourceId );
bool bConfig = true;
if( !bForceDialog )
{
bConfig = guessFormat( cFilename, Width, Height, InputFormat, BitsPel, Endianness, FrameRate );
if( bConfig )
{
// Pre-load values with last opened file
Width = appSettings.value( "VideoSubWindow/LastWidth" ).value<unsigned int>();
Height = appSettings.value( "VideoSubWindow/LastHeight" ).value<unsigned int>();
BitsPel = appSettings.value( "VideoSubWindow/LastBitsPerPixel" ).value<unsigned int>();
}
}
bool bRet = false;
for( int iPass = 0; iPass < 2 && !bRet; iPass++ )
{
if( iPass || bConfig )
{
if( formatDialog.runConfigureFormatDialog( QFileInfo( cFilename ).fileName(), Width, Height, InputFormat, BitsPel,
Endianness, FrameRate ) == QDialog::Rejected )
{
return false;
}
}
try
{
bRet = m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, BitsPel, Endianness, FrameRate, true );
}
catch( CalypFailure& e )
{
if( iPass == 1 )
throw( e );
}
}
m_sStreamInfo.m_cFilename = cFilename;
m_sStreamInfo.m_uiWidth = Width;
m_sStreamInfo.m_uiHeight = Height;
m_sStreamInfo.m_iPelFormat = InputFormat;
m_sStreamInfo.m_uiBitsPelPixel = BitsPel;
m_sStreamInfo.m_iEndianness = Endianness;
m_sStreamInfo.m_uiFrameRate = FrameRate;
m_sStreamInfo.m_uiFileSize = QFileInfo( cFilename ).size();
QVariant var;
var.setValue<unsigned int>( Width );
appSettings.setValue( "VideoSubWindow/LastWidth", var );
var.setValue<unsigned int>( Height );
appSettings.setValue( "VideoSubWindow/LastHeight", var );
var.setValue<unsigned int>( BitsPel );
appSettings.setValue( "VideoSubWindow/LastBitsPerPixel", var );
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->startResourceWorker( m_uiResourceId );
#endif
QApplication::restoreOverrideCursor();
refreshFrame();
m_cFilename = cFilename;
updateVideoWindowInfo();
setWindowName( QFileInfo( m_cFilename ).fileName() );
return true;
}
bool VideoSubWindow::loadFile( CalypFileInfo* streamInfo )
{
assert( m_pcResourceManager != nullptr );
m_uiResourceId = m_pcResourceManager->getResource( m_pCurrStream );
m_pCurrStream = m_pcResourceManager->getResourceAsset( m_uiResourceId );
if( !m_pCurrStream->open( streamInfo->m_cFilename.toStdString(), streamInfo->m_uiWidth, streamInfo->m_uiHeight,
streamInfo->m_iPelFormat, streamInfo->m_uiBitsPelPixel, streamInfo->m_iEndianness,
streamInfo->m_uiFrameRate, true ) )
{
return false;
}
m_sStreamInfo = *streamInfo;
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->startResourceWorker( m_uiResourceId );
#endif
QApplication::restoreOverrideCursor();
refreshFrame();
m_cFilename = streamInfo->m_cFilename;
updateVideoWindowInfo();
setWindowName( QFileInfo( m_cFilename ).fileName() );
return true;
}
void VideoSubWindow::updateVideoWindowInfo()
{
m_cStreamInformation = "";
if( m_pcCurrentDisplayModule )
{
m_cStreamInformation = "Module";
const auto& arraySubWindows = m_pcCurrentDisplayModule->getSubWindowList();
QStringList windowInfoList;
if( arraySubWindows.size() > 0 )
{
for( std::size_t i = 0; i < arraySubWindows.size(); i++ )
{
if( arraySubWindows[i]->getWindowName() != getWindowName() )
{
windowInfoList.append( QString( "Input %1 - " + arraySubWindows[i]->getWindowName() ).arg( i + 1 ) );
}
}
}
if( m_pcCurrentDisplayModule->getModuleRequirements() & CLP_MODULES_HAS_INFO )
{
QStringList list = QString::fromStdString( m_pcCurrentDisplayModule->moduleInfo() ).split( '\n' );
windowInfoList.append( list );
}
if( windowInfoList.size() > 0 )
{
m_pcVideoInfo->setInformationTopLeft( windowInfoList );
}
}
else if( m_pCurrStream )
{
QString m_cFormatName = QString::fromStdString( m_pCurrStream->getFormatName() );
QString m_cCodedName = QString::fromStdString( m_pCurrStream->getCodecName() );
m_cStreamInformation = m_cFormatName + " | " + m_cCodedName;
}
if( m_pcCurrFrameAsset )
{
QString m_cPelFmtName = QString::fromStdString( m_pcCurrFrameAsset->getPelFmtName() );
if( m_pCurrStream )
if( !m_pCurrStream->isNative() )
m_cPelFmtName += "*";
m_cStreamInformation += " | " + m_cPelFmtName;
}
if( m_cStreamInformation.isEmpty() )
{
m_cStreamInformation = " ";
}
}
bool VideoSubWindow::guessFormat( QString filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel,
int& rEndianness, unsigned int& rFrameRate )
{
std::vector<CalypStandardResolution> stdResList = CalypStream::stdResolutionSizes();
bool bGuessed = true;
bool bGuessedByFilesize = false;
QString FilenameShort = QFileInfo( filename ).fileName();
QString fileExtension = QFileInfo( filename ).suffix();
if( filename.startsWith( "/dev/" ) )
{
return false;
}
if( !fileExtension.compare( "yuv", Qt::CaseInsensitive ) || !fileExtension.compare( "rgb", Qt::CaseInsensitive ) ||
!fileExtension.compare( "gray", Qt::CaseInsensitive ) )
{
bGuessed = false;
// Guess pixel format
QVector<ClpString> formats_list = QVector<ClpString>::fromStdVector( CalypFrame::supportedPixelFormatListNames() );
for( int i = 0; i < formats_list.size(); i++ )
{
if( FilenameShort.contains( formats_list.at( i ).c_str(), Qt::CaseInsensitive ) )
{
rInputFormat = i;
break;
}
}
if( rWidth == 0 || rHeight == 0 )
{
// Guess resolution - match resolution name
int iMatch = -1;
for( unsigned int i = 0; i < stdResList.size(); i++ )
{
if( FilenameShort.contains( QString::fromStdString( stdResList[i].shortName ) ) )
{
iMatch = i;
}
}
if( iMatch >= 0 )
{
rWidth = stdResList[iMatch].uiWidth;
rHeight = stdResList[iMatch].uiHeight;
}
// Guess resolution - match %dx%d
//QRegularExpressionMatch resolutionMatch = QRegularExpression( "_\\d*x\\d*" ).match( FilenameShort );
QRegularExpressionMatch resolutionMatch = QRegularExpression( "_[0-9]+x[0-9]+" ).match( FilenameShort );
if( resolutionMatch.hasMatch() )
{
QString resolutionString = resolutionMatch.captured( resolutionMatch.lastCapturedIndex() );
if( resolutionString.startsWith( "_" ) || resolutionString.endsWith( "_" ) )
{
resolutionString.remove( "_" );
QStringList resolutionArgs = resolutionString.split( "x" );
if( resolutionArgs.size() == 2 )
{
rWidth = resolutionArgs.at( 0 ).toUInt();
rHeight = resolutionArgs.at( 1 ).toUInt();
}
}
}
}
// Guess resolution by file size
if( rWidth == 0 && rHeight == 0 )
{
FILE* pF = fopen( filename.toStdString().c_str(), "rb" );
if( pF )
{
fseek( pF, 0, SEEK_END );
unsigned long long int uiFileSize = ftell( pF );
fclose( pF );
int count = 0, module, frame_bytes, match;
for( unsigned int i = 0; i < stdResList.size(); i++ )
{
frame_bytes =
CalypFrame::getBytesPerFrame( stdResList[i].uiWidth, stdResList[i].uiHeight, rInputFormat, 8 );
module = uiFileSize % frame_bytes;
if( module == 0 )
{
match = i;
count++;
}
}
if( count == 1 )
{
rWidth = stdResList[match].uiWidth;
rHeight = stdResList[match].uiHeight;
bGuessedByFilesize = true;
}
}
}
// [.|_]
// Guess bits per pixel - match %dbpp
QRegularExpressionMatch BppMatch = QRegularExpression( "_[0-9]+bpp" ).match( FilenameShort );
if( BppMatch.hasMatch() )
{
QString matchString = BppMatch.captured( BppMatch.lastCapturedIndex() );
matchString.remove( "_" );
matchString.remove( "bpp" );
rBitsPerPixel = matchString.toUInt();
if( !( rBitsPerPixel > 0 && rBitsPerPixel < 16 ) )
{
rBitsPerPixel = -1;
}
}
QRegularExpressionMatch BppOnlybMatch = QRegularExpression( "_[0-9]+b" ).match( FilenameShort );
if( BppOnlybMatch.hasMatch() )
{
QString matchString = BppOnlybMatch.captured( BppOnlybMatch.lastCapturedIndex() );
matchString.remove( "_" );
matchString.remove( "b" );
rBitsPerPixel = matchString.toUInt();
if( !( rBitsPerPixel > 0 && rBitsPerPixel < 16 ) )
{
rBitsPerPixel = -1;
}
}
// Guess frame rate - match %dbpp
QRegularExpressionMatch FpsMatch = QRegularExpression( "_[0-9]+fps" ).match( FilenameShort );
if( FpsMatch.hasMatch() )
{
QString matchString = FpsMatch.captured( FpsMatch.lastCapturedIndex() );
matchString.remove( "_" );
matchString.remove( "fps" );
rFrameRate = matchString.toUInt();
if( rFrameRate < 0 )
{
rFrameRate = 30;
}
}
// Guess Endianness
if( FilenameShort.contains( QStringLiteral( "be" ), Qt::CaseInsensitive ) )
{
rEndianness = CLP_BIG_ENDIAN;
}
if( FilenameShort.contains( QStringLiteral( "le" ), Qt::CaseInsensitive ) )
{
rEndianness = CLP_LITTLE_ENDIAN;
}
if( rWidth > 0 && rHeight > 0 && rInputFormat >= 0 )
bGuessed = true && !bGuessedByFilesize;
}
return !bGuessed;
}
void VideoSubWindow::updateSelectedArea( QRect area ) void VideoSubWindow::updateSelectedArea( QRect area )
{ {
m_cSelectedArea = area; m_cSelectedArea = area;
@@ -669,24 +233,24 @@ void VideoSubWindow::updateSelectedArea( QRect area )
// { // {
// m_associatedModules.erase( it ); // m_associatedModules.erase( it );
// } // }
// m_pcCurrentDisplayModule = std::move( pcModule ); // m_pcDisplayModule = std::move( pcModule );
// updateVideoWindowInfo(); // updateVideoWindowInfo();
// } // }
bool VideoSubWindow::hasAssociatedModule() bool VideoSubWindow::hasAssociatedModule()
{ {
if( m_pcCurrentDisplayModule == nullptr ) if( m_pcDisplayModule == nullptr )
return !m_associatedModules.empty(); return !m_associatedModules.empty();
return m_associatedModules.size() > 1; return m_associatedModules.size() > 1;
} }
void VideoSubWindow::setDisplayModule( CalypAppModuleIf* pcModule ) void VideoSubWindow::setDisplayModule( CalypAppModuleIf* pcModule )
{ {
if( m_pcCurrentDisplayModule != nullptr ) if( m_pcDisplayModule != nullptr )
{ {
m_pcCurrentDisplayModule->disable(); m_pcDisplayModule->disable();
} }
m_pcCurrentDisplayModule = pcModule; m_pcDisplayModule = pcModule;
updateVideoWindowInfo(); updateVideoWindowInfo();
} }
@@ -712,15 +276,15 @@ void VideoSubWindow::disableModule( CalypAppModuleIf* pcModule )
{ {
m_associatedModules.erase( it ); m_associatedModules.erase( it );
} }
if( pcModule == m_pcCurrentDisplayModule ) if( pcModule == m_pcDisplayModule )
{ {
bRefresh |= true; bRefresh |= true;
m_pcCurrentDisplayModule = nullptr; m_pcDisplayModule = nullptr;
setWindowName( QFileInfo( m_cFilename ).fileName() ); resetWindowName();
} }
if( bRefresh ) if( bRefresh )
{ {
refreshFrame(); refreshSubWindow();
updateVideoWindowInfo(); updateVideoWindowInfo();
} }
// if( pcModule ) // if( pcModule )
@@ -732,10 +296,10 @@ void VideoSubWindow::disableModule( CalypAppModuleIf* pcModule )
// ModulesHandle::destroyModuleIf( pcModule ); // ModulesHandle::destroyModuleIf( pcModule );
// bRefresh |= true; // bRefresh |= true;
// } // }
// if( pcModule == m_pcCurrentDisplayModule ) // if( pcModule == m_pcDisplayModule )
// { // {
// pcModule = m_pcCurrentDisplayModule; // pcModule = m_pcDisplayModule;
// m_pcCurrentDisplayModule = 0; // m_pcDisplayModule = 0;
// ModulesHandle::destroyModuleIf( pcModule ); // ModulesHandle::destroyModuleIf( pcModule );
// setWindowName( QFileInfo( m_cFilename ).fileName() ); // setWindowName( QFileInfo( m_cFilename ).fileName() );
// bRefresh |= true; // bRefresh |= true;
@@ -751,10 +315,10 @@ void VideoSubWindow::disableModule( CalypAppModuleIf* pcModule )
// bRefresh |= true; // bRefresh |= true;
// } // }
// assert( m_apcCurrentModule.size() == 0 ); // assert( m_apcCurrentModule.size() == 0 );
// if( m_pcCurrentDisplayModule ) // if( m_pcDisplayModule )
// { // {
// pcModule = m_pcCurrentDisplayModule; // pcModule = m_pcDisplayModule;
// m_pcCurrentDisplayModule = NULL; // m_pcDisplayModule = NULL;
// ModulesHandle::destroyModuleIf( pcModule ); // ModulesHandle::destroyModuleIf( pcModule );
// setWindowName( QFileInfo( m_cFilename ).fileName() ); // setWindowName( QFileInfo( m_cFilename ).fileName() );
// bRefresh |= true; // bRefresh |= true;
@@ -770,8 +334,8 @@ bool VideoSubWindow::disableAllModules()
while( m_associatedModules.size() > 0 ) while( m_associatedModules.size() > 0 )
{ {
auto module = m_associatedModules.back(); auto module = m_associatedModules.back();
module->disable();
m_associatedModules.pop_back(); m_associatedModules.pop_back();
module->disable();
} }
return true; return true;
} }
@@ -779,7 +343,7 @@ bool VideoSubWindow::disableAllModules()
bool VideoSubWindow::hasRunningModule() bool VideoSubWindow::hasRunningModule()
{ {
bool bRet = false; bool bRet = false;
for( int i = 0; i < m_associatedModules.size() && !bRet; i++ ) for( std::size_t i = 0; i < m_associatedModules.size() && !bRet; i++ )
{ {
bRet |= m_associatedModules.at( i )->isRunning(); bRet |= m_associatedModules.at( i )->isRunning();
} }
@@ -791,114 +355,34 @@ void VideoSubWindow::setFillWindow( bool bFlag )
m_pcVideoInfo->setBusyWindow( bFlag ); m_pcVideoInfo->setBusyWindow( bFlag );
} }
std::shared_ptr<CalypFrame> VideoSubWindow::getCurrFrameAsset()
{
if( m_pcCurrFrameAsset == nullptr && m_pCurrStream != nullptr )
{
m_pcCurrFrameAsset = m_pCurrStream->getCurrFrameAsset();
}
return m_pcCurrFrameAsset;
};
void VideoSubWindow::setCurrFrame( std::shared_ptr<CalypFrame> pcCurrFrame ) void VideoSubWindow::setCurrFrame( std::shared_ptr<CalypFrame> pcCurrFrame )
{ {
m_pcCurrFrameAsset = std::move( pcCurrFrame ); m_pcCurrFrameAsset = std::move( pcCurrFrame );
refreshFrame();
}
void VideoSubWindow::refreshFrame()
{
m_cViewArea->setImage( m_pcCurrFrameAsset ); m_cViewArea->setImage( m_pcCurrFrameAsset );
for( auto& module : m_associatedModules ) for( auto& module : m_associatedModules )
{ {
if( module.get() != m_pcCurrentDisplayModule ) if( module.get() != m_pcDisplayModule )
module->update( m_bIsPlaying ); module->update( isPlaying() );
} }
} }
void VideoSubWindow::refreshFrameOperation()
{
bool bSetFrame = false;
if( m_pCurrStream )
{
m_pcCurrFrameAsset = m_pCurrStream->getCurrFrameAsset();
bSetFrame |= true;
}
if( m_pcCurrentDisplayModule )
{
m_bWindowBusy = true;
bool disableThreads = !m_bIsPlaying && hasAssociatedModule();
m_pcCurrentDisplayModule->apply( m_bIsPlaying, disableThreads );
bSetFrame = false;
}
if( bSetFrame )
{
m_cViewArea->setImage( m_pcCurrFrameAsset );
for( auto& module : m_associatedModules )
{
if( module.get() != m_pcCurrentDisplayModule )
module->update( m_bIsPlaying );
}
}
}
void VideoSubWindow::refreshFrame( bool bThreaded )
{
#ifndef QT_NO_CONCURRENT
m_cRefreshResult.waitForFinished();
if( bThreaded )
{
m_cRefreshResult = QtConcurrent::run( this, &VideoSubWindow::refreshFrameOperation );
}
else
#endif
{
refreshFrameOperation();
}
}
bool VideoSubWindow::goToNextFrame( bool bThreaded )
{
#ifndef QT_NO_CONCURRENT
m_cRefreshResult.waitForFinished();
m_cReadResult.waitForFinished();
#endif
#ifdef CALYP_MANAGED_RESOURCES
while( !m_pCurrStream->hasNextFrame() && !m_pCurrStream->isEof() )
;
#endif
bool bEndOfSeq = m_pCurrStream->setNextFrame();
#ifdef CALYP_MANAGED_RESOURCES
bThreaded = false;
m_pcResourceManager->wakeResourceWorker( m_uiResourceId );
#endif
if( !bEndOfSeq )
{
#ifndef QT_NO_CONCURRENT
m_cRefreshResult.waitForFinished();
if( bThreaded )
{
m_cReadResult = QtConcurrent::run( m_pCurrStream, &CalypStream::readNextFrameFillRGBBuffer );
refreshFrame( bThreaded );
}
else
#endif
{
refreshFrame( bThreaded );
#ifndef CALYP_MANAGED_RESOURCES
m_pCurrStream->readNextFrameFillRGBBuffer();
#endif
}
}
return bEndOfSeq;
}
bool VideoSubWindow::save( QString filename ) bool VideoSubWindow::save( QString filename )
{ {
bool iRet = false; bool iRet = false;
QApplication::setOverrideCursor( Qt::WaitCursor ); QApplication::setOverrideCursor( Qt::WaitCursor );
std::unique_ptr<CalypFrame> new_frame{ nullptr };
CalypFrame* saveFrame = m_pcCurrFrameAsset.get(); CalypFrame* saveFrame = m_pcCurrFrameAsset.get();
if( m_cSelectedArea.isValid() ) if( m_cSelectedArea.isValid() )
{ {
saveFrame = new CalypFrame( m_pcCurrFrameAsset.get(), m_cSelectedArea.x(), m_cSelectedArea.y(), m_cSelectedArea.width(), new_frame = std::make_unique<CalypFrame>( m_pcCurrFrameAsset.get(), m_cSelectedArea.x(), m_cSelectedArea.y(), m_cSelectedArea.width(),
m_cSelectedArea.height() ); m_cSelectedArea.height() );
saveFrame = new_frame.get();
} }
if( !saveFrame ) if( !saveFrame )
{ {
@@ -909,109 +393,6 @@ bool VideoSubWindow::save( QString filename )
return iRet; return iRet;
} }
bool VideoSubWindow::saveStream( QString filename )
{
bool iRet = false;
QApplication::setOverrideCursor( Qt::WaitCursor );
// TODO: implement this
QApplication::restoreOverrideCursor();
return iRet;
}
void VideoSubWindow::setPlaying( bool isPlaying )
{
m_bIsPlaying = isPlaying;
for( auto module : m_associatedModules )
{
module->setPlaying( isPlaying );
}
}
bool VideoSubWindow::isPlaying()
{
if( getCategory() & SubWindowCategory::MODULE_SUBWINDOW )
{
for( auto window : m_pcCurrentDisplayModule->getSubWindowList() )
{
if( window->isPlaying() )
return true;
}
return false;
}
return m_bIsPlaying;
}
bool VideoSubWindow::play()
{
bool isPlaying = false;
if( m_pCurrStream && m_pCurrStream->getFrameNum() > 1 )
{
isPlaying = true;
}
setPlaying( isPlaying );
return m_bIsPlaying;
}
bool VideoSubWindow::playEvent()
{
bool bEndOfSeq = false;
if( m_pCurrStream && m_bIsPlaying )
{
bEndOfSeq = goToNextFrame( true );
}
return bEndOfSeq;
}
void VideoSubWindow::pause()
{
setPlaying( false );
refreshFrame();
}
void VideoSubWindow::seekAbsoluteEvent( unsigned int new_frame_num )
{
if( m_pCurrStream )
{
if( m_pCurrStream->seekInput( new_frame_num ) )
refreshFrame();
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->wakeResourceWorker( m_uiResourceId );
#endif
}
}
void VideoSubWindow::seekRelativeEvent( bool bIsFoward )
{
if( m_pCurrStream )
{
if( bIsFoward )
{
goToNextFrame( true );
}
else
{
m_pCurrStream->seekInputRelative( bIsFoward );
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->wakeResourceWorker( m_uiResourceId );
#endif
refreshFrame();
}
}
}
void VideoSubWindow::stop()
{
#ifndef QT_NO_CONCURRENT
m_cRefreshResult.waitForFinished();
m_cReadResult.waitForFinished();
#endif
setPlaying( false );
seekAbsoluteEvent( 0 );
return;
}
QSize VideoSubWindow::getScrollSize() 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 );
@@ -1095,14 +476,6 @@ void VideoSubWindow::updateScrollValues()
m_dVerScroll = yPos / double( m_pcScrollArea->verticalScrollBar()->maximum() ); m_dVerScroll = yPos / double( m_pcScrollArea->verticalScrollBar()->maximum() );
} }
//void VideoSubWindow::setCurScrollValues()
//{
// QScrollBar* scrollBar = m_pcScrollArea->horizontalScrollBar();
// scrollBar->setValue( m_cCurrScroll.x() );
// scrollBar = m_pcScrollArea->verticalScrollBar();
// scrollBar->setValue( m_cCurrScroll.y() );
//}
void VideoSubWindow::normalSize() void VideoSubWindow::normalSize()
{ {
double factor = 1.0; double factor = 1.0;
@@ -1149,8 +522,8 @@ void VideoSubWindow::scaleView( const QSize& size, QPoint center )
QSize imgViewSize; QSize imgViewSize;
if( m_pcCurrFrameAsset ) if( m_pcCurrFrameAsset )
imgViewSize = QSize( m_pcCurrFrameAsset->getWidth(), m_pcCurrFrameAsset->getHeight() ); imgViewSize = QSize( m_pcCurrFrameAsset->getWidth(), m_pcCurrFrameAsset->getHeight() );
else //else
imgViewSize = QSize( m_pCurrStream->getWidth(), m_pCurrStream->getHeight() ); // imgViewSize = QSize( m_pCurrStream->getWidth(), m_pCurrStream->getHeight() );
QSize newSize = imgViewSize; QSize newSize = imgViewSize;
newSize.scale( size, Qt::KeepAspectRatio ); newSize.scale( size, Qt::KeepAspectRatio );
+63 -116
View File
@@ -28,6 +28,7 @@
#include <QDataStream> #include <QDataStream>
#include <QFuture> #include <QFuture>
#include <QRect> #include <QRect>
#include <QStaticText>
#include <QString> #include <QString>
#include <QVector> #include <QVector>
@@ -45,69 +46,32 @@ class VideoSubWindow;
class ResourceHandle; class ResourceHandle;
class CalypAppModuleIf; class CalypAppModuleIf;
typedef struct /**
* \class VideoInformation
* \brief Shows information about video sub window
*/
class VideoInformation : public QWidget
{ {
QString m_cFilename; public:
unsigned int m_uiWidth; VideoInformation( QWidget* parent );
unsigned int m_uiHeight; void setInformationTopLeft( const QStringList& textLines );
int m_iPelFormat; void setBusyWindow( bool bFlag );
unsigned int m_uiBitsPelPixel;
unsigned int m_iEndianness;
unsigned int m_uiFrameRate;
unsigned long long int m_uiFileSize;
} CalypFileInfo;
typedef QVector<CalypFileInfo> CalypFileInfoVector;
QDataStream& operator<<( QDataStream& out, const CalypFileInfoVector& d ); protected:
QDataStream& operator>>( QDataStream& in, CalypFileInfoVector& d ); void paintEvent( QPaintEvent* event );
int findCalypStreamInfo( CalypFileInfoVector array, QString filename );
private:
QTimer* m_pcRefreshTimer;
QList<QStaticText> m_cTopLeftTextList;
QFont m_cTopLeftTextFont;
QFont m_cCenterTextFont;
bool m_bBusyWindow;
};
class VideoSubWindow : public SubWindowAbstract class VideoSubWindow : public SubWindowAbstract
{ {
Q_OBJECT Q_OBJECT
private:
ResourceHandle* m_pcResourceManager;
bool m_bWindowBusy;
QScrollArea* m_pcScrollArea;
QPoint m_cCurrScroll;
double m_dHorScroll;
double m_dVerScroll;
ViewArea* m_cViewArea;
VideoInformation* m_pcVideoInfo;
QString m_cFilename;
QString m_cStreamInformation;
CalypFileInfo m_sStreamInfo;
std::size_t m_uiResourceId;
CalypStream* m_pCurrStream;
std::shared_ptr<CalypFrame> m_pcCurrFrameAsset;
//CalypFrame* m_pcCurrFrame;
QRect m_cSelectedArea;
CalypAppModuleIf* m_pcCurrentDisplayModule{ nullptr };
std::vector<std::shared_ptr<CalypAppModuleIf>> m_associatedModules;
bool m_hasAssociatedModules;
VideoSubWindow* m_pcReferenceSubWindow;
// QString m_cWindowShortName;
QString m_cCurrFileName;
bool m_bIsPlaying;
QTimer* m_pcUpdateTimer;
/**
* Threads variables
* QtConcurrent
*/
QFuture<void> m_cRefreshResult;
QFuture<void> m_cReadResult;
public: public:
enum VideoSubWindowCategories enum VideoSubWindowCategories
{ {
@@ -115,41 +79,26 @@ public:
MODULE_SUBWINDOW = SubWindowAbstract::MODULE_SUBWINDOW, MODULE_SUBWINDOW = SubWindowAbstract::MODULE_SUBWINDOW,
}; };
VideoSubWindow( enum VideoSubWindowCategories category, QWidget* parent = 0 ); VideoSubWindow( enum VideoSubWindowCategories category, QWidget* parent = 0 );
VideoSubWindow( enum VideoSubWindowCategories category, CalypAppModuleIf* displayModule, QWidget* parent = 0 );
~VideoSubWindow(); ~VideoSubWindow();
void setResourceManaget( ResourceHandle* resourceManager ) { m_pcResourceManager = resourceManager; } virtual void resetWindowName() = 0;
virtual void updateVideoWindowInfo() = 0;
void updateVideoWindowInfo(); virtual bool isPlaying() = 0;
virtual void stop() = 0;
virtual void advanceOneFrame() = 0;
virtual auto getFrameNum() -> std::uint64_t { return 1; };
bool loadFile( QString cFilename, bool bForceDialog = false ); QString getVideoInformation() { return m_cStreamInformation; }
bool loadFile( CalypFileInfo* streamInfo );
void loadAll();
bool save( QString filename ); bool save( QString filename );
bool saveStream( QString filename );
void refreshSubWindow();
void refreshFrame( bool bThreaded = false );
bool play();
void pause();
bool playEvent();
void stop();
void setPlaying( bool isPlaying );
bool isPlaying();
void seekAbsoluteEvent( unsigned int new_frame_num );
void seekRelativeEvent( bool bIsFoward );
void setCurrFrame( std::shared_ptr<CalypFrame> pcCurrFrame ); void setCurrFrame( std::shared_ptr<CalypFrame> pcCurrFrame );
CalypFileInfo getStreamInfo() { return m_sStreamInfo; } auto getCurrFrame() -> CalypFrame* { return m_pcCurrFrameAsset.get(); }
QString getStreamInformation() { return m_cStreamInformation; } auto getCurrFrameAsset() -> std::shared_ptr<CalypFrame> { return m_pcCurrFrameAsset; };
const CalypStream* getInputStream() { return m_pCurrStream; } auto getViewArea() -> ViewArea* { return m_cViewArea; }
const CalypStream* getCurrStream() { return m_pCurrStream; }
CalypFrame* getCurrFrame() { return m_pcCurrFrameAsset.get(); } VideoSubWindow* getRefSubWindow() { return m_pcReferenceSubWindow; }
std::shared_ptr<CalypFrame> getCurrFrameAsset();
ViewArea* getViewArea() { return m_cViewArea; }
void setRefSubWindow( VideoSubWindow* subWindow ) void setRefSubWindow( VideoSubWindow* subWindow )
{ {
m_pcReferenceSubWindow = NULL; m_pcReferenceSubWindow = NULL;
@@ -158,59 +107,37 @@ public:
m_pcReferenceSubWindow = subWindow; m_pcReferenceSubWindow = subWindow;
} }
VideoSubWindow* getRefSubWindow() { return m_pcReferenceSubWindow; }
/** /**
* Functions to enable a module in the * Functions to enable a module in the
* current SubWindow * current SubWindow
*/ */
//void enableModule( std::shared_ptr<CalypAppModuleIf> pcModule ); auto hasModules() -> bool { return m_associatedModules.size() > 0; }
bool hasAssociatedModule(); bool hasAssociatedModule();
void setDisplayModule( CalypAppModuleIf* pcModule ); void setDisplayModule( CalypAppModuleIf* pcModule );
void associateModule( std::shared_ptr<CalypAppModuleIf> pcModule ); void associateModule( std::shared_ptr<CalypAppModuleIf> pcModule );
void disableModule( CalypAppModuleIf* pcModule ); void disableModule( CalypAppModuleIf* pcModule );
bool disableAllModules(); bool disableAllModules();
CalypAppModuleIf* getDisplayModule() { return m_pcDisplayModule; }
CalypAppModuleIf* getDisplayModule() { return m_pcCurrentDisplayModule; }
QVector<CalypAppModuleIf*> getModuleArray()
{
QVector<CalypAppModuleIf*> apcModulesArray;
if( m_pcCurrentDisplayModule )
apcModulesArray.append( m_pcCurrentDisplayModule );
for( const auto& module : m_associatedModules )
{
apcModulesArray.append( module.get() );
}
return apcModulesArray;
}
/** /**
* Virtual functions from SubWindowAbstract * Virtual functions from SubWindowAbstract
*/ */
void normalSize(); void normalSize() override;
void zoomToFit(); void zoomToFit() override;
void scaleView( double scale, QPoint center = QPoint() ); void scaleView( double scale, QPoint center = QPoint() ) override;
void zoomToFactor( double factor, QPoint center = QPoint() ); void zoomToFactor( double factor, QPoint center = QPoint() ) override;
double getScaleFactor() { return m_cViewArea->getZoomFactor(); } double getScaleFactor() override { return m_cViewArea->getZoomFactor(); }
/** /**
* Size related functions * Size related functions
*/ */
QSize sizeHint() const; QSize sizeHint( const QSize& ) const override;
QSize sizeHint( const QSize& ) const;
QString getCurrentFileName() { return m_cFilename; }
void clearWindowBusy() { m_bWindowBusy = false; }
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:
void refreshFrameOperation();
bool goToNextFrame( bool bThreaded = false );
static bool guessFormat( QString filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel,
int& rEndianness, unsigned int& rFrameRate );
bool hasRunningModule(); bool hasRunningModule();
/** /**
@@ -222,6 +149,8 @@ private:
QSize getScrollSize(); QSize getScrollSize();
protected: protected:
void refreshFrame();
void keyPressEvent( QKeyEvent* event ) override; void keyPressEvent( QKeyEvent* event ) override;
void resizeEvent( QResizeEvent* event ) override; void resizeEvent( QResizeEvent* event ) override;
void closeEvent( QCloseEvent* event ) override; void closeEvent( QCloseEvent* event ) override;
@@ -233,9 +162,27 @@ public Q_SLOTS:
void updateScrollValues(); void updateScrollValues();
void updateSelectedArea( QRect area ); void updateSelectedArea( QRect area );
void updatePixelValueStatusBar( const QPoint& pos ); void updatePixelValueStatusBar( const QPoint& pos );
protected:
VideoInformation* m_pcVideoInfo;
QString m_cStreamInformation;
std::shared_ptr<CalypFrame> m_pcCurrFrameAsset;
//bool m_bWindowBusy;
//bool m_bIsPlaying;
std::vector<std::shared_ptr<CalypAppModuleIf>> m_associatedModules;
CalypAppModuleIf* m_pcDisplayModule{ nullptr };
//bool m_hasAssociatedModules;
private:
QScrollArea* m_pcScrollArea;
QPoint m_cCurrScroll;
double m_dHorScroll;
double m_dVerScroll;
ViewArea* m_cViewArea;
QRect m_cSelectedArea;
VideoSubWindow* m_pcReferenceSubWindow;
QTimer* m_pcUpdateTimer;
}; };
Q_DECLARE_METATYPE( CalypFileInfo ) // NOLINT
Q_DECLARE_METATYPE( CalypFileInfoVector ) // NOLINT
#endif // __VIDEOSUBWINDOW_H__ #endif // __VIDEOSUBWINDOW_H__
+11 -3
View File
@@ -25,6 +25,8 @@
#include "ViewArea.h" #include "ViewArea.h"
#include <qnamespace.h>
#include <QColor> #include <QColor>
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
@@ -729,10 +731,16 @@ void ViewArea::wheelEvent( QWheelEvent* event )
QWidget* p = parentWidget(); QWidget* p = parentWidget();
QSize minimumSize = QSize( p->size().width() - 5, p->size().height() - 5 ); QSize minimumSize = QSize( p->size().width() - 5, p->size().height() - 5 );
usedScale = scaleZoomFactor( scale, event->pos(), minimumSize );
#if QT_VERSION < QT_VERSION_CHECK( 5, 14, 0 )
auto eventPosition = event->pos();
#else
auto eventPosition = event->position().toPoint();
#endif
usedScale = scaleZoomFactor( scale, eventPosition, minimumSize );
if( usedScale != 1.0 ) if( usedScale != 1.0 )
{ {
emit zoomFactorChanged_byWheel( usedScale, event->pos() ); emit zoomFactorChanged_byWheel( usedScale, eventPosition );
} }
} }
} }
@@ -743,7 +751,7 @@ void ViewArea::mousePressEvent( QMouseEvent* event )
QPoint vpos = windowToView( event->pos() ); QPoint vpos = windowToView( event->pos() );
if( event->button() == Qt::MidButton ) if( event->button() == Qt::MiddleButton )
{ {
} }
if( event->button() == Qt::LeftButton ) if( event->button() == Qt::LeftButton )
+2 -2
View File
@@ -395,7 +395,7 @@ int ConfigureFormatDialog::runConfigureFormatDialog( const QString& Filename, un
int sampling = 0; int sampling = 0;
if( rInputFormat >= 0 ) if( rInputFormat >= 0 )
{ {
ClpString pelFmtName = CalypFrame::supportedPixelFormatListNames()[rInputFormat]; std::string pelFmtName = CalypFrame::supportedPixelFormatListNames()[rInputFormat];
for( unsigned int j = 0; j < CalypFrame::supportedColorSpacesListNames().size(); j++ ) for( unsigned int j = 0; j < CalypFrame::supportedColorSpacesListNames().size(); j++ )
{ {
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames( j ).size(); i++ ) for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames( j ).size(); i++ )
@@ -442,7 +442,7 @@ int ConfigureFormatDialog::runConfigureFormatDialog( const QString& Filename, un
rHeight = m_spinBoxheight->value(); rHeight = m_spinBoxheight->value();
colorSpace = m_comboBoxColorSpace->currentIndex(); colorSpace = m_comboBoxColorSpace->currentIndex();
sampling = m_comboBoxPixelFormat->currentIndex(); sampling = m_comboBoxPixelFormat->currentIndex();
ClpString pelFmtName = CalypFrame::supportedPixelFormatListNames( colorSpace )[sampling]; std::string pelFmtName = CalypFrame::supportedPixelFormatListNames( colorSpace )[sampling];
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames().size(); i++ ) for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames().size(); i++ )
{ {
if( pelFmtName == CalypFrame::supportedPixelFormatListNames()[i] ) if( pelFmtName == CalypFrame::supportedPixelFormatListNames()[i] )
+4 -4
View File
@@ -72,13 +72,13 @@ public:
} }
return m_pcValue->text(); return m_pcValue->text();
} }
const ClpString& getName() { return m_cName; } const std::string& getName() { return m_cName; }
private: private:
QLineEdit* m_pcValue; QLineEdit* m_pcValue;
QCheckBox* m_pcChecked; QCheckBox* m_pcChecked;
QLabel* m_pcDescription; QLabel* m_pcDescription;
ClpString m_cName; std::string m_cName;
}; };
ModulesHandleOptDialog::ModulesHandleOptDialog( QWidget* parent, CalypAppModuleIf* pcCurrModuleIf ) ModulesHandleOptDialog::ModulesHandleOptDialog( QWidget* parent, CalypAppModuleIf* pcCurrModuleIf )
@@ -121,8 +121,8 @@ int ModulesHandleOptDialog::runConfiguration()
return QDialog::Rejected; return QDialog::Rejected;
} }
std::vector<ClpString> argsArray; std::vector<std::string> argsArray;
ClpString optionString; std::string optionString;
QString valueString( "" ); QString valueString( "" );
for( int i = 0; i < m_apcOptionList.size(); i++ ) for( int i = 0; i < m_apcOptionList.size(); i++ )
+6 -5
View File
@@ -418,7 +418,11 @@ void FramePropertiesDock::updateDataHistogram()
{ {
if( m_bHasFrame && isVisible() ) if( m_bHasFrame && isVisible() )
{ {
if( !m_bIsPlaying ) if( m_bIsPlaying )
{
histogramWidget->setLoadingSkipped();
}
else
{ {
if( m_cSelectionArea.isValid() ) if( m_cSelectionArea.isValid() )
{ {
@@ -437,10 +441,7 @@ void FramePropertiesDock::updateDataHistogram()
} }
histogramWidget->updateData( m_pcFrame, m_cSelectionArea.isValid() ? m_pcSelectedFrame : nullptr ); histogramWidget->updateData( m_pcFrame, m_cSelectionArea.isValid() ? m_pcSelectedFrame : nullptr );
} }
else
{
histogramWidget->setLoadingSkipped();
}
histogramWidget->update(); histogramWidget->update();
} }
else else
+6 -1
View File
@@ -6,7 +6,12 @@ FIND_PACKAGE(Qt5 REQUIRED COMPONENTS Core Gui Widgets PrintSupport)
SET(qcustomplot_SRCS qcustomplot.cpp qcustomplot.h) SET(qcustomplot_SRCS qcustomplot.cpp qcustomplot.h)
SET(CMAKE_AUTOMOC ON)
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-deprecated-enum-enum-conversion")
ENDIF()
ADD_LIBRARY(QCustomPlotLib STATIC ${qcustomplot_SRCS}) ADD_LIBRARY(QCustomPlotLib STATIC ${qcustomplot_SRCS})
TARGET_LINK_LIBRARIES(QCustomPlotLib Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport) TARGET_LINK_LIBRARIES(QCustomPlotLib Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport)
TARGET_INCLUDE_DIRECTORIES(QCustomPlotLib PUBLIC .) TARGET_INCLUDE_DIRECTORIES(QCustomPlotLib PUBLIC .)
+19 -35
View File
@@ -41,56 +41,42 @@ class HistogramWorker : public QThread
{ {
private: private:
QObject* m_parent; QObject* m_parent;
std::shared_ptr<CalypFrame> m_pcFrame; std::shared_ptr<CalypFrame> m_pcFrame{ nullptr };
public: public:
HistogramWorker( QObject* parent ) HistogramWorker( QObject* parent )
{ : m_parent{ parent } {}
m_parent = parent;
}
void reset() void reset() { m_pcFrame = nullptr; }
{
m_pcFrame = nullptr;
}
void setup( std::shared_ptr<CalypFrame> frame ) void setup( std::shared_ptr<CalypFrame> frame )
{ {
m_pcFrame = frame; m_pcFrame = std::move( frame );
run(); EventData* eventData = new EventData(); // NOLINT
//start(); eventData->starting = true;
// QCoreApplication::postEvent( m_parent, eventData );
start();
} }
void run() void run() override
{ {
if( m_pcFrame != nullptr && m_parent != nullptr ) EventData* eventData = new EventData(); // NOLINT
if( m_pcFrame != nullptr )
{ {
EventData* eventData = new EventData();
eventData->starting = true;
m_pcFrame->calcHistogram(); m_pcFrame->calcHistogram();
eventData->starting = false; eventData->frame = m_pcFrame.get();
eventData->success = true;
eventData->frame = m_pcFrame;
QCoreApplication::postEvent( m_parent, eventData );
} }
eventData->success = true;
QCoreApplication::postEvent( m_parent, eventData );
} }
/**
* Custom Event
*/
class EventData : public QEvent class EventData : public QEvent
{ {
public: public:
EventData() EventData()
: QEvent( QEvent::User ) : QEvent( QEvent::User ), frame{ nullptr } {}
{ CalypFrame* frame{ nullptr };
starting = false; bool starting{ false };
success = false; bool success{ false };
frame = NULL;
}
bool starting;
bool success;
std::shared_ptr<CalypFrame> frame;
}; };
}; };
@@ -260,7 +246,7 @@ void HistogramWidget::customEvent( QEvent* event )
return; return;
} }
if( ed->frame != m_fullImage && ed->frame != m_selectionImage ) if( ed->frame != m_fullImage.get() && ed->frame != m_selectionImage.get() )
{ {
return; return;
} }
@@ -321,8 +307,6 @@ void HistogramWidget::customEvent( QEvent* event )
emit signalHistogramComputationFailed(); emit signalHistogramComputationFailed();
} }
} }
// delete ed;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Data Loading Functions // Data Loading Functions
+2 -2
View File
@@ -9,8 +9,8 @@ PROJECT("modules_example")
# THIS FIND_PACKAGE( Calyp ) INCLUDE_DIRECTORIES( ${CALYP_INCLUDE_DIRS} ) OR # THIS FIND_PACKAGE( Calyp ) INCLUDE_DIRECTORIES( ${CALYP_INCLUDE_DIRS} ) OR
INCLUDE_DIRECTORIES(../../lib) INCLUDE_DIRECTORIES(../../lib)
ADD_LIBRARY(FrameBinarization SHARED FrameBinarization_APIv1.cpp) ADD_LIBRARY(FrameBinarizationAPIv1 SHARED FrameBinarizationAPIv1.cpp)
TARGET_LINK_LIBRARIES(FrameBinarization ${PROJECT_LIBRARY}) TARGET_LINK_LIBRARIES(FrameBinarizationAPIv1 ${PROJECT_LIBRARY})
ADD_LIBRARY(AbsoluteFrameDifferenceExample SHARED AbsoluteFrameDifferenceExample.cpp) ADD_LIBRARY(AbsoluteFrameDifferenceExample SHARED AbsoluteFrameDifferenceExample.cpp)
TARGET_LINK_LIBRARIES(AbsoluteFrameDifferenceExample ${PROJECT_LIBRARY}) TARGET_LINK_LIBRARIES(AbsoluteFrameDifferenceExample ${PROJECT_LIBRARY})
@@ -18,20 +18,20 @@
*/ */
/** /**
* \file FrameBinarization_APIv1.cpp * \file FrameBinarizationAPIv1.cpp
* \brief Binarize frame module (example of APIv1) * \brief Binarize frame module (example of APIv1)
*/ */
#include "FrameBinarization_APIv1.h" #include "FrameBinarizationAPIv1.h"
REGISTER_CLASS_MAKER( FrameBinarization_APIv1 ) REGISTER_CLASS_MAKER( FrameBinarizationAPIv1 )
FrameBinarization_APIv1::FrameBinarization_APIv1() FrameBinarizationAPIv1::FrameBinarizationAPIv1()
{ {
/* Module Definition */ /* Module Definition */
m_iModuleType = CLP_FRAME_PROCESSING_MODULE; m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_pchModuleCategory = "Utilities"; m_pchModuleCategory = "Utilities";
m_pchModuleName = "FrameBinarization_APIv1"; m_pchModuleName = "FrameBinarizationAPIv1";
m_pchModuleLongName = "Frame Binarization API v1"; m_pchModuleLongName = "Frame Binarization API v1";
m_pchModuleTooltip = "Binarize frame"; m_pchModuleTooltip = "Binarize frame";
m_uiNumberOfFrames = 1; m_uiNumberOfFrames = 1;
@@ -44,13 +44,13 @@ FrameBinarization_APIv1::FrameBinarization_APIv1()
m_uiThreshold = 128; m_uiThreshold = 128;
} }
void FrameBinarization_APIv1::create( CalypFrame* frame ) void FrameBinarizationAPIv1::create( CalypFrame* frame )
{ {
m_pcBinFrame = NULL; m_pcBinFrame = NULL;
m_pcBinFrame = new CalypFrame( frame->getWidth(), frame->getHeight(), CLP_GRAY, 8 ); m_pcBinFrame = new CalypFrame( frame->getWidth(), frame->getHeight(), CLP_GRAY, 8 );
} }
CalypFrame* FrameBinarization_APIv1::process( CalypFrame* frame ) CalypFrame* FrameBinarizationAPIv1::process( CalypFrame* frame )
{ {
const ClpPel* pPelInput = frame->getPelBufferYUV()[0][0]; const ClpPel* pPelInput = frame->getPelBufferYUV()[0][0];
ClpPel* pPelBin = m_pcBinFrame->getPelBufferYUV()[0][0]; ClpPel* pPelBin = m_pcBinFrame->getPelBufferYUV()[0][0];
@@ -62,7 +62,7 @@ CalypFrame* FrameBinarization_APIv1::process( CalypFrame* frame )
return m_pcBinFrame; return m_pcBinFrame;
} }
void FrameBinarization_APIv1::destroy() void FrameBinarizationAPIv1::destroy()
{ {
if( m_pcBinFrame ) if( m_pcBinFrame )
delete m_pcBinFrame; delete m_pcBinFrame;
@@ -18,29 +18,29 @@
*/ */
/** /**
* \file FrameBinarization_APIv1.h * \file FrameBinarizationAPIv1.h
* \brief Binarize frame module (example of APIv1) * \brief Binarize frame module (example of APIv1)
*/ */
#ifndef __FRAMEBINARIZATION_APIV1_H__ #ifndef __FRAMEBINARIZATIONAPIV1_H__
#define __FRAMEBINARIZATION_APIV1_H__ #define __FRAMEBINARIZATIONAPIV1_H__
#include "CalypModuleIf.h" #include "CalypModuleIf.h"
class FrameBinarization_APIv1 : public CalypModuleIf class FrameBinarizationAPIv1 : public CalypModuleIf
{ {
REGISTER_CLASS_FACTORY( FrameBinarization_APIv1 ) REGISTER_CLASS_FACTORY( FrameBinarizationAPIv1 )
private: private:
CalypFrame* m_pcBinFrame; CalypFrame* m_pcBinFrame;
unsigned int m_uiThreshold; unsigned int m_uiThreshold;
public: public:
FrameBinarization_APIv1(); FrameBinarizationAPIv1();
virtual ~FrameBinarization_APIv1() {} virtual ~FrameBinarizationAPIv1() {}
void create( CalypFrame* ); void create( CalypFrame* );
CalypFrame* process( CalypFrame* ); CalypFrame* process( CalypFrame* );
void destroy(); void destroy();
}; };
#endif // __FRAMEBINARIZATION_APIV1_H__ #endif // __FRAMEBINARIZATIONAPIV1_H__
+1 -2
View File
@@ -38,8 +38,7 @@ int main( int argc, char* argv[] )
double n = 0; double n = 0;
CalypStream stream; CalypStream stream;
//stream.open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/Kendo_c4_1024x768_yuv420p.yuv" ), 1024, 768, 0, 8, CLP_BIG_ENDIAN, 1, true ); stream.open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/Foreman.yuv" ), 352, 288, 0, 8, CLP_BIG_ENDIAN, 1, true );
stream.open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/SteamLocomotiveTrain_2560x1600_60_10bit_crop.yuv" ), 2560, 1600, 0, 10, CLP_LITTLE_ENDIAN, 1, true );
while( 1 ) while( 1 )
{ {
+39 -22
View File
@@ -3,8 +3,10 @@
# #
INCLUDE(GNUInstallDirs) INCLUDE(GNUInstallDirs)
SET(CMAKE_EXPORT_PACKAGE_REGISTRY ON)
EXPORT(PACKAGE MyLib)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..)
SET(Calyp_Lib_Frame_SRCS CalypPixel.cpp PixelFormats.h PixelFormats.cpp CalypFrame.h CalypFrame.cpp) SET(Calyp_Lib_Frame_SRCS CalypPixel.cpp PixelFormats.h PixelFormats.cpp CalypFrame.h CalypFrame.cpp)
@@ -22,17 +24,8 @@ SET(Calyp_Lib_OptionParser_SRCS CalypOptions.h CalypOptions.cpp)
SET(Calyp_Lib_Modules_SRCS CalypOptions.h CalypOptions.cpp) SET(Calyp_Lib_Modules_SRCS CalypOptions.h CalypOptions.cpp)
SET(Calyp_Lib_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})
LibMemory.h
CalypLib.h
CalypDefs.h
${Calyp_Lib_Frame_SRCS}
${Calyp_Lib_Stream_SRCS}
${Calyp_Lib_OptionParser_SRCS}
${Calyp_Lib_Modules_SRCS}
)
LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${PROJECT_LIBRARY})
LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
IF(USE_FFMPEG) IF(USE_FFMPEG)
@@ -41,6 +34,10 @@ IF(USE_FFMPEG)
LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${FFMPEG_LIBRARIES}) LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${FFMPEG_LIBRARIES})
LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS}) LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIRS})
LIST(APPEND CALYP_LIB_LINKER_DEPENDENCIES ${FFMPEG_LIBRARIES})
ENDIF() ENDIF()
IF(USE_OPENCV) IF(USE_OPENCV)
@@ -51,13 +48,28 @@ IF(USE_OPENCV)
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})
LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${PROJECT_LIBRARY})
LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
LIST(APPEND CALYP_LIB_LINKER_DEPENDENCIES ${OpenCV_LIBRARIES})
ENDIF() ENDIF()
SET(Calyp_Lib_HEADERS CalypDefs.h CalypFrame.h CalypStream.h CalypOptions.h CalypModuleIf.h CalypOpenCVModuleIf.h) SET(Calyp_Lib_HEADERS CalypFrame.h CalypStream.h CalypOptions.h CalypModuleIf.h)
CONFIGURE_FILE(CalypConfig.cmake.in CalypConfig.cmake @ONLY) INCLUDE(CMakePackageConfigHelpers)
INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS}) CONFIGURE_PACKAGE_CONFIG_FILE(CalypConfig.cmake.in CalypConfig.cmake INSTALL_DESTINATION share/calyp)
WRITE_BASIC_PACKAGE_VERSION_FILE(
CalypConfigVersion.cmake
VERSION ${CALYP_VERSION}
COMPATIBILITY SameMajorVersion
)
# CONFIGURE_FILE(CalypConfig.cmake.in CalypConfig.cmake @ONLY)
IF(USE_STATIC) IF(USE_STATIC)
ADD_LIBRARY(${PROJECT_LIBRARY} STATIC ${Calyp_Lib_SRCS}) ADD_LIBRARY(${PROJECT_LIBRARY} STATIC ${Calyp_Lib_SRCS})
@@ -65,27 +77,32 @@ ELSE()
ADD_LIBRARY(${PROJECT_LIBRARY} SHARED ${Calyp_Lib_SRCS}) ADD_LIBRARY(${PROJECT_LIBRARY} SHARED ${Calyp_Lib_SRCS})
ENDIF() ENDIF()
TARGET_LINK_LIBRARIES(${PROJECT_LIBRARY} ${FFMPEG_LIBRARIES} ${OpenCV_LIBRARIES}) TARGET_LINK_LIBRARIES(${PROJECT_LIBRARY} ${CALYP_LIB_LINKER_DEPENDENCIES})
# TARGET_INCLUDE_DIRECTORIES(${PROJECT_LIBRARY} PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
TARGET_INCLUDE_DIRECTORIES(${PROJECT_LIBRARY} PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
SET_TARGET_PROPERTIES(${PROJECT_LIBRARY} PROPERTIES VERSION ${CALYP_VERSION} SOVERSION ${CALYP_VERSION_MAJOR}) SET_TARGET_PROPERTIES(${PROJECT_LIBRARY} PROPERTIES VERSION ${CALYP_VERSION} SOVERSION ${CALYP_VERSION_MAJOR})
IF(USE_IWYU)
SET_PROPERTY(TARGET ${PROJECT_LIBRARY} PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
ENDIF()
EXPORT(TARGETS ${PROJECT_LIBRARY} FILE ${CMAKE_CURRENT_BINARY_DIR}/CalypTargets.cmake)
EXPORT(PACKAGE ${PROJECT_LIBRARY})
IF(NOT USE_STATIC) IF(NOT USE_STATIC)
INSTALL( INSTALL(
TARGETS ${PROJECT_LIBRARY} TARGETS ${PROJECT_LIBRARY}
EXPORT "${PROJECT_LIBRARY}Targets"
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
) )
INSTALL(FILES ${Calyp_Lib_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") INSTALL(FILES ${Calyp_Lib_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/CalypConfig.cmake DESTINATION share/calyp) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/CalypConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/CalypConfigVersion.cmake DESTINATION share/calyp)
INSTALL(EXPORT CalypTargets DESTINATION share/calyp)
ENDIF() ENDIF()
IF(BUILD_TESTS) IF(BUILD_TESTS)
ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(tests)
ENDIF()
IF(BUILD_TESTS_CATCH2)
ADD_SUBDIRECTORY(catch2) ADD_SUBDIRECTORY(catch2)
ENDIF() ENDIF()
+9 -6
View File
@@ -12,7 +12,7 @@
# #
# #
# This file will define the following variables: # This file will define the following variables:
# - CALYP_LINKER_LIBS : The list of all imported targets for OpenCV modules. # - CALYP_LIBRARIES : The list of all imported targets for OpenCV modules.
# - CALYP_CXX_FLAGS # - CALYP_CXX_FLAGS
# - CALYP_INCLUDE_DIRS : The Calyp include directories. # - CALYP_INCLUDE_DIRS : The Calyp include directories.
# - CALYP_VERSION : The version of this Calyp build: "@CALYP_VERSION@" # - CALYP_VERSION : The version of this Calyp build: "@CALYP_VERSION@"
@@ -22,15 +22,18 @@
# #
# =================================================================================================================== # ===================================================================================================================
@PACKAGE_INIT@
# ======================================================
# Variables:
# ======================================================
SET(CALYP_VERSION @CALYP_VERSION@) SET(CALYP_VERSION @CALYP_VERSION@)
SET(CALYP_VERSION_MAJOR @CALYP_VERSION_MAJOR@) SET(CALYP_VERSION_MAJOR @CALYP_VERSION_MAJOR@)
SET(CALYP_VERSION_MINOR @CALYP_VERSION_MINOR@) SET(CALYP_VERSION_MINOR @CALYP_VERSION_MINOR@)
SET(CALYP_VERSION_PATCH @CALYP_VERSION_PATCH@) SET(CALYP_VERSION_PATCH @CALYP_VERSION_PATCH@)
FIND_LIBRARY(CALYP_LIBRARY NAMES Calyp HINTS @CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ )
SET( CALYP_CXX_FLAGS "" ) SET( CALYP_CXX_FLAGS "" )
SET( CALYP_INCLUDE_DIRS "@CMAKE_CFG_INCLUDE_DIRS@" ) SET( CALYP_LIBRARIES "${CALYP_LIBRARY}" )
SET( CALYP_LINKER_LIBS "@CMAKE_CFG_LINKER_LIBSS@" ) LIST( APPEND CALYP_LIBRARIES "@CALYP_LIB_LINKER_DEPENDENCIES@")
set_and_check( CALYP_INCLUDE_DIRS "@CMAKE_CFG_INCLUDE_DIRS@" )
CHECK_REQUIRED_COMPONENTS(Calyp)
+9 -72
View File
@@ -27,16 +27,10 @@
#define __CALYPDEFS_H__ #define __CALYPDEFS_H__
#include <algorithm> #include <algorithm>
#include <cstdint>
#include <iterator> #include <iterator>
#include <memory> #include <memory>
#include <string> #include <string>
using ClpByte = std::uint8_t;
using ClpPel = std::uint16_t;
using ClpULong = std::uint64_t;
using ClpString = std::string;
enum CLP_LOG_LEVEL enum CLP_LOG_LEVEL
{ {
CLP_LOG_INFO = 1, CLP_LOG_INFO = 1,
@@ -45,94 +39,37 @@ enum CLP_LOG_LEVEL
CLP_LOG_ERROR = 4, CLP_LOG_ERROR = 4,
}; };
/**
* \enum CalypColorSpace
* \brief List of supported color spaces
* \ingroup CalypLibGrp
*/
enum CalypColorSpace
{
CLP_COLOR_INVALID = -1, //!< Invalid
CLP_COLOR_YUV = 0, //!< YUV
CLP_COLOR_RGB = 1, //!< RGB
CLP_COLOR_GRAY = 2, //!< Grayscale
CLP_COLOR_RGBA = 3, //!< RGB + Alpha
CLP_COLOR_MAX = 255, //!< Account for future formats
};
/**
* \enum CalypPixelFormats
* \brief List of supported pixel formats
* \ingroup CalypLibGrp
*/
enum CalypPixelFormats
{
CLP_INVALID_FMT = -1, //!< Invalid
CLP_YUV420P = 0, //!< YUV 420 progressive
CLP_YUV422P, //!< YUV 422 progressive
CLP_YUV444P, //!< YUV 444 progressive
CLP_YUYV422, //!< YUV 422 interleaved
CLP_GRAY, //!< Grayscale
CLP_RGB24P, //!< RGB 32 bpp progressive
CLP_RGB24, //!< RGB 32 bpp
CLP_BGR24, //!< BGR 32 bpp
CLP_RGBA32, //!< RGBA 32 bpp
CLP_BGRA32, //!< BGRA 32 bpp
CLP_MAX_FMT = 255, //!< Account for future formats
};
enum CLP_YUV_Components
{
CLP_LUMA = 0,
CLP_CHROMA_U,
CLP_CHROMA_V,
};
enum CLP_RGB_Components
{
CLP_COLOR_R = 0,
CLP_COLOR_G,
CLP_COLOR_B,
CLP_COLOR_A,
};
enum CLP_Endianness
{
CLP_BIG_ENDIAN = 0,
CLP_LITTLE_ENDIAN = 1,
};
static const double S_PI = 3.14159265358979323846; static const double S_PI = 3.14159265358979323846;
static const double S_PI_2 = 1.57079632679489661923; static const double S_PI_2 = 1.57079632679489661923;
inline ClpString clpLowercase( const ClpString& in ) inline std::string clpLowercase( const std::string& in )
{ {
ClpString out; std::string out;
std::transform( in.begin(), in.end(), std::back_inserter( out ), tolower ); std::transform( in.begin(), in.end(), std::back_inserter( out ), tolower );
return out; return out;
} }
inline ClpString clpUppercase( const ClpString& in ) inline std::string clpUppercase( const std::string& in )
{ {
ClpString out; std::string out;
std::transform( in.begin(), in.end(), std::back_inserter( out ), toupper ); std::transform( in.begin(), in.end(), std::back_inserter( out ), toupper );
return out; return out;
} }
struct CalypFailure : public std::exception struct CalypFailure : public std::exception
{ {
ClpString m_class_name; std::string m_class_name;
ClpString m_error_msg; std::string m_error_msg;
CalypFailure( ClpString error_msg ) throw() CalypFailure( std::string error_msg ) throw()
: m_error_msg( error_msg ) {} : m_error_msg( error_msg ) {}
CalypFailure( ClpString class_name, ClpString error_msg ) throw() CalypFailure( std::string class_name, std::string error_msg ) throw()
: m_class_name( class_name ), m_error_msg( error_msg ) : m_class_name( class_name ), m_error_msg( error_msg )
{ {
} }
~CalypFailure() throw() {} ~CalypFailure() throw() {}
const char* what() const throw() const char* what() const throw()
{ {
ClpString* msg = new ClpString( "[" + m_class_name + "] " + m_error_msg ); std::string* msg = new std::string( "[" + m_class_name + "] " + m_error_msg );
return msg->c_str(); return msg->c_str();
} }
}; };
+45 -34
View File
@@ -27,11 +27,10 @@
#include <cassert> #include <cassert>
#include <cmath> #include <cmath>
#include <cstdint> #include <cstdint>
#include <memory> #include <cstring>
#include <vector> #include <vector>
#include "LibMemory.h" #include "CalypDefs.h"
#include "PixelFormats.h"
#include "config.h" #include "config.h"
#ifdef USE_OPENCV #ifdef USE_OPENCV
@@ -40,12 +39,24 @@
#include <opencv2/imgproc/imgproc.hpp> #include <opencv2/imgproc/imgproc.hpp>
#endif #endif
#include "PixelFormats.h"
#include "config.h"
#define DATA_ALIGN 1 ///< use 32-bit aligned malloc/free
#if DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 )
#define xMalloc( len ) _aligned_malloc( len, 32 )
#define xFreeMem( ptr ) _aligned_free( ptr )
#else
#define xMalloc( len ) malloc( len )
#define xFreeMem( ptr ) free( ptr )
#endif
constexpr auto kMinBitsPerPixel = 8; constexpr auto kMinBitsPerPixel = 8;
constexpr auto kMaxBitsPerPixel = 16; constexpr auto kMaxBitsPerPixel = 16;
std::vector<ClpString> CalypFrame::supportedColorSpacesListNames() std::vector<std::string> CalypFrame::supportedColorSpacesListNames()
{ {
return std::vector<ClpString>{ return std::vector<std::string>{
"YUV", "YUV",
"RGB", "RGB",
"GRAY", "GRAY",
@@ -53,9 +64,9 @@ std::vector<ClpString> CalypFrame::supportedColorSpacesListNames()
}; };
} }
std::vector<ClpString> CalypFrame::supportedPixelFormatListNames() std::vector<std::string> CalypFrame::supportedPixelFormatListNames()
{ {
std::vector<ClpString> formatsList; std::vector<std::string> formatsList;
for( int i = 0; i < numberOfFormats(); i++ ) for( int i = 0; i < numberOfFormats(); i++ )
{ {
formatsList.push_back( g_CalypPixFmtDescriptorsMap.at( i ).name ); formatsList.push_back( g_CalypPixFmtDescriptorsMap.at( i ).name );
@@ -63,9 +74,9 @@ std::vector<ClpString> CalypFrame::supportedPixelFormatListNames()
return formatsList; return formatsList;
} }
std::vector<ClpString> CalypFrame::supportedPixelFormatListNames( int colorSpace ) std::vector<std::string> CalypFrame::supportedPixelFormatListNames( int colorSpace )
{ {
std::vector<ClpString> formatsList; std::vector<std::string> formatsList;
for( int i = 0; i < numberOfFormats(); i++ ) for( int i = 0; i < numberOfFormats(); i++ )
{ {
if( g_CalypPixFmtDescriptorsMap.at( i ).colorSpace == colorSpace ) if( g_CalypPixFmtDescriptorsMap.at( i ).colorSpace == colorSpace )
@@ -79,7 +90,7 @@ int CalypFrame::numberOfFormats()
return static_cast<int>( g_CalypPixFmtDescriptorsMap.size() ); return static_cast<int>( g_CalypPixFmtDescriptorsMap.size() );
} }
int CalypFrame::findPixelFormat( const ClpString& name ) int CalypFrame::findPixelFormat( const std::string& name )
{ {
for( int i = 0; i < numberOfFormats(); i++ ) for( int i = 0; i < numberOfFormats(); i++ )
{ {
@@ -101,7 +112,7 @@ public:
//! Struct with the pixel format description. //! Struct with the pixel format description.
const CalypPixelFormatDescriptor* m_pcPelFormat{ nullptr }; const CalypPixelFormatDescriptor* m_pcPelFormat{ nullptr };
ClpString m_cPelFmtName; std::string m_cPelFmtName;
unsigned int m_uiWidth{ 0 }; //!< Width of the frame unsigned int m_uiWidth{ 0 }; //!< Width of the frame
unsigned int m_uiHeight{ 0 }; //!< Height of the frame unsigned int m_uiHeight{ 0 }; //!< Height of the frame
@@ -166,7 +177,7 @@ public:
} }
mem_size += num_of_ptrs * sizeof( ClpPel* ) + sizeof( ClpPel** ) * iNumberChannels; mem_size += num_of_ptrs * sizeof( ClpPel* ) + sizeof( ClpPel** ) * iNumberChannels;
m_pppcInputPel = (ClpPel***)xMallocMem( mem_size ); m_pppcInputPel = (ClpPel***)xMalloc( mem_size );
ClpPel** pelPtrMem = (ClpPel**)( m_pppcInputPel + iNumberChannels ); ClpPel** pelPtrMem = (ClpPel**)( m_pppcInputPel + iNumberChannels );
ClpPel* pelMem = (ClpPel*)( pelPtrMem + num_of_ptrs ); ClpPel* pelMem = (ClpPel*)( pelPtrMem + num_of_ptrs );
@@ -407,7 +418,7 @@ int CalypFrame::getPelFormat() const
return d->m_iPixelFormat; return d->m_iPixelFormat;
} }
ClpString CalypFrame::getPelFmtName() std::string CalypFrame::getPelFmtName()
{ {
return d->m_pcPelFormat->name; return d->m_pcPelFormat->name;
} }
@@ -436,14 +447,14 @@ bool CalypFrame::getHasNegativeValues() const
return d->m_bHasNegativeValues; return d->m_bHasNegativeValues;
} }
ClpULong CalypFrame::getPixels( unsigned channel ) const std::uint64_t CalypFrame::getPixels( unsigned channel ) const
{ {
return getWidth( channel ) * getHeight( channel ); return getWidth( channel ) * getHeight( channel );
} }
ClpULong CalypFrame::getTotalNumberOfPixels() const std::uint64_t CalypFrame::getTotalNumberOfPixels() const
{ {
ClpULong numberPixels = 0; std::uint64_t numberPixels = 0;
for( unsigned i = 0; i < getNumberChannels(); i++ ) for( unsigned i = 0; i < getNumberChannels(); i++ )
{ {
numberPixels += getPixels( i ); numberPixels += getPixels( i );
@@ -461,7 +472,7 @@ unsigned CalypFrame::getChromaHeightRatio() const
return d->m_pcPelFormat->log2ChromaHeight; return d->m_pcPelFormat->log2ChromaHeight;
} }
ClpULong CalypFrame::getChromaLength() const std::uint64_t CalypFrame::getChromaLength() const
{ {
return getWidth( 1 ) * getHeight( 1 ); return getWidth( 1 ) * getHeight( 1 );
} }
@@ -471,19 +482,19 @@ unsigned int CalypFrame::getBitsPel() const
return d->m_uiBitsPel; return d->m_uiBitsPel;
} }
ClpULong CalypFrame::getBytesPerFrame() const std::uint64_t CalypFrame::getBytesPerFrame() const
{ {
return getBytesPerFrame( d->m_uiWidth, d->m_uiHeight, d->m_iPixelFormat, d->m_uiBitsPel ); return getBytesPerFrame( d->m_uiWidth, d->m_uiHeight, d->m_iPixelFormat, d->m_uiBitsPel );
} }
ClpULong CalypFrame::getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, int iPixelFormat, unsigned int bitsPixel ) std::uint64_t CalypFrame::getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, int iPixelFormat, unsigned int bitsPixel )
{ {
const CalypPixelFormatDescriptor* pcPelFormat = &( g_CalypPixFmtDescriptorsMap.at( iPixelFormat ) ); const CalypPixelFormatDescriptor* pcPelFormat = &( g_CalypPixFmtDescriptorsMap.at( iPixelFormat ) );
unsigned int bytesPerPixel = ( bitsPixel - 1 ) / 8 + 1; unsigned int bytesPerPixel = ( bitsPixel - 1 ) / 8 + 1;
ClpULong numberBytes = uiWidth * uiHeight; std::uint64_t numberBytes = uiWidth * uiHeight;
if( pcPelFormat->numberChannels > 1 ) if( pcPelFormat->numberChannels > 1 )
{ {
ClpULong numberBytesChroma = std::uint64_t numberBytesChroma =
CHROMASHIFT( uiWidth, pcPelFormat->log2ChromaWidth ) * CHROMASHIFT( uiHeight, pcPelFormat->log2ChromaHeight ); CHROMASHIFT( uiWidth, pcPelFormat->log2ChromaWidth ) * CHROMASHIFT( uiHeight, pcPelFormat->log2ChromaHeight );
numberBytes += ( pcPelFormat->numberChannels - 1 ) * numberBytesChroma; numberBytes += ( pcPelFormat->numberChannels - 1 ) * numberBytesChroma;
} }
@@ -558,7 +569,7 @@ CalypPixel CalypFrame::getPixel( unsigned int xPos, unsigned int yPos ) const
return PixelValue; return PixelValue;
} }
CalypPixel CalypFrame::getPixel( unsigned int xPos, unsigned int yPos, CalypColorSpace eColorSpace ) CalypPixel CalypFrame::getPixel( unsigned int xPos, unsigned int yPos, CalypColorSpace eColorSpace ) const
{ {
return getPixel( xPos, yPos ).convertPixel( eColorSpace ); return getPixel( xPos, yPos ).convertPixel( eColorSpace );
} }
@@ -675,7 +686,7 @@ void CalypFrame::frameFromBuffer( const std::vector<ClpByte>& Buff, int iEndiann
ppBuff[i] = ppBuff[i - 1] + CHROMASHIFT( d->m_uiHeight, ratioH ) * CHROMASHIFT( d->m_uiWidth, ratioW ) * bytesPixel; ppBuff[i] = ppBuff[i - 1] + CHROMASHIFT( d->m_uiHeight, ratioH ) * CHROMASHIFT( d->m_uiWidth, ratioW ) * bytesPixel;
} }
xMemSet( ClpPel, getTotalNumberOfPixels(), d->m_pppcInputPel[0][0] ); memset( d->m_pppcInputPel[0][0], 0, getTotalNumberOfPixels() * sizeof( ClpPel ) );
for( unsigned ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ ) for( unsigned ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ )
{ {
@@ -850,7 +861,7 @@ void CalypFrame::fillRGBBuffer() const
uint32_t* pARGBLine = pARGB; uint32_t* pARGBLine = pARGB;
uint32_t* pARGBAux; uint32_t* pARGBAux;
for( int y = 0; y < CHROMASHIFT( d->m_uiHeight, d->m_pcPelFormat->log2ChromaHeight ); y++ ) 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++ ) for( int i = 0; i < 1 << d->m_pcPelFormat->log2ChromaHeight; i++ )
{ {
@@ -858,7 +869,7 @@ void CalypFrame::fillRGBBuffer() const
ClpPel* pU = pLineU; ClpPel* pU = pLineU;
ClpPel* pV = pLineV; ClpPel* pV = pLineV;
pARGBAux = pARGBLine; pARGBAux = pARGBLine;
for( int x = 0; x < CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth ); x++ ) for( unsigned x = 0; x < CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth ); x++ )
{ {
int iU = *pU++; int iU = *pU++;
iU >>= shiftBits; iU >>= shiftBits;
@@ -1251,12 +1262,12 @@ bool CalypFrame::toMat( cv::Mat& cvMat, bool convertToGray, bool scale, unsigned
cv::Mat tmpMat( imgHeight, imgWidth, CV_MAKETYPE( cvPrecision, numChannels ) ); cv::Mat tmpMat( imgHeight, imgWidth, CV_MAKETYPE( cvPrecision, numChannels ) );
unsigned char* cv_data = tmpMat.data; unsigned char* cv_data = tmpMat.data;
CalypPixel currPel;
for( unsigned y = 0; y < imgHeight; y++ ) for( unsigned y = 0; y < imgHeight; y++ )
{ {
for( unsigned x = 0; x < imgWidth; x++ ) for( unsigned x = 0; x < imgWidth; x++ )
{ {
currPel = getPixel( x, y ) * scaleFactor; CalypPixel currPel = getPixel( x, y );
currPel *= scaleFactor;
for( unsigned int ch = 0; ch < numChannels; ch++ ) for( unsigned int ch = 0; ch < numChannels; ch++ )
for( unsigned b = 0; b < numBytes; b++ ) for( unsigned b = 0; b < numBytes; b++ )
{ {
@@ -1389,9 +1400,9 @@ bool CalypFrame::fromMat( cv::Mat& cvMat, int channel )
************************************************************** **************************************************************
*/ */
std::vector<ClpString> CalypFrame::supportedQualityMetricsList() std::vector<std::string> CalypFrame::supportedQualityMetricsList()
{ {
return std::vector<ClpString>{ return std::vector<std::string>{
"PSNR", "PSNR",
"MSE", "MSE",
"SSIM", "SSIM",
@@ -1399,9 +1410,9 @@ std::vector<ClpString> CalypFrame::supportedQualityMetricsList()
}; };
} }
std::vector<ClpString> CalypFrame::supportedQualityMetricsUnitsList() std::vector<std::string> CalypFrame::supportedQualityMetricsUnitsList()
{ {
return std::vector<ClpString>{ return std::vector<std::string>{
"dB", "dB",
"", "",
"", "",
@@ -1439,8 +1450,8 @@ double CalypFrame::getMSE( CalypFrame* Org, unsigned int component )
{ {
ClpPel* pPelYUV = getPelBufferYUV()[component][0]; ClpPel* pPelYUV = getPelBufferYUV()[component][0];
ClpPel* pOrgPelYUV = Org->getPelBufferYUV()[component][0]; ClpPel* pOrgPelYUV = Org->getPelBufferYUV()[component][0];
ClpULong numberOfPixels = Org->getHeight( component ) * Org->getWidth( component ); std::uint64_t numberOfPixels = Org->getHeight( component ) * Org->getWidth( component );
ClpULong ssd = 0; std::uint64_t ssd = 0;
for( unsigned int i = 0; i < numberOfPixels; i++ ) for( unsigned int i = 0; i < numberOfPixels; i++ )
{ {
int diff = int( *pPelYUV++ ) - int( *pOrgPelYUV++ ); int diff = int( *pPelYUV++ ) - int( *pOrgPelYUV++ );
@@ -1455,7 +1466,7 @@ double CalypFrame::getMSE( CalypFrame* Org, unsigned int component )
double CalypFrame::getPSNR( CalypFrame* Org, unsigned int component ) double CalypFrame::getPSNR( CalypFrame* Org, unsigned int component )
{ {
ClpULong uiMaxValue = ( 1 << Org->getBitsPel() ) - 1; std::uint64_t uiMaxValue = ( 1 << Org->getBitsPel() ) - 1;
double dPSNR = 100; double dPSNR = 100;
double dMSE = getMSE( Org, component ); double dMSE = getMSE( Org, component );
if( dMSE != 0 ) if( dMSE != 0 )
+147 -34
View File
@@ -26,15 +26,78 @@
#ifndef __CALYPFRAME_H__ #ifndef __CALYPFRAME_H__
#define __CALYPFRAME_H__ #define __CALYPFRAME_H__
#include <cstdint>
#include <memory>
#include <span>
#include <string>
#include <vector> #include <vector>
#include "CalypDefs.h"
namespace cv namespace cv
{ {
class Mat; class Mat;
} }
using ClpPel = std::uint16_t;
using ClpByte = std::uint8_t;
/**
* \enum CalypColorSpace
* \brief List of supported color spaces
* \ingroup CalypLibGrp
*/
enum CalypColorSpace
{
CLP_COLOR_INVALID = -1, //!< Invalid
CLP_COLOR_YUV = 0, //!< YUV
CLP_COLOR_RGB = 1, //!< RGB
CLP_COLOR_GRAY = 2, //!< Grayscale
CLP_COLOR_RGBA = 3, //!< RGB + Alpha
CLP_COLOR_MAX = 255, //!< Account for future formats
};
/**
* \enum CalypPixelFormats
* \brief List of supported pixel formats
* \ingroup CalypLibGrp
*/
enum CalypPixelFormats
{
CLP_INVALID_FMT = -1, //!< Invalid
CLP_YUV420P = 0, //!< YUV 420 progressive
CLP_YUV422P, //!< YUV 422 progressive
CLP_YUV444P, //!< YUV 444 progressive
CLP_YUYV422, //!< YUV 422 interleaved
CLP_GRAY, //!< Grayscale
CLP_RGB24P, //!< RGB 32 bpp progressive
CLP_RGB24, //!< RGB 32 bpp
CLP_BGR24, //!< BGR 32 bpp
CLP_RGBA32, //!< RGBA 32 bpp
CLP_BGRA32, //!< BGRA 32 bpp
CLP_MAX_FMT = 255, //!< Account for future formats
};
enum CLP_YUV_Components
{
CLP_LUMA = 0,
CLP_CHROMA_U,
CLP_CHROMA_V,
};
enum CLP_RGB_Components
{
CLP_COLOR_R = 0,
CLP_COLOR_G,
CLP_COLOR_B,
CLP_COLOR_A,
};
enum CLP_Endianness
{
CLP_INVALID_ENDIANESS = -1,
CLP_BIG_ENDIAN = 0,
CLP_LITTLE_ENDIAN = 1,
};
#define CHROMASHIFT( SIZE, SHIFT ) (unsigned int)( -( ( -( (int)( SIZE ) ) ) >> ( SHIFT ) ) ) #define CHROMASHIFT( SIZE, SHIFT ) (unsigned int)( -( ( -( (int)( SIZE ) ) ) >> ( SHIFT ) ) )
/** /**
@@ -44,27 +107,39 @@ class Mat;
*/ */
class CalypPixel class CalypPixel
{ {
private:
static constexpr std::size_t kMaxNumberOfComponents{ 4 };
int m_colorSpace{ CLP_COLOR_INVALID };
std::array<ClpPel, kMaxNumberOfComponents> m_pelComp{ 0, 0, 0, 0 };
public: public:
static int getMaxNumberOfComponents(); static std::size_t getMaxNumberOfComponents() { return kMaxNumberOfComponents; }
CalypPixel( const int& CalypColorSpace = CLP_COLOR_INVALID ); CalypPixel() = default;
CalypPixel( const int& CalypColorSpace, const ClpPel& c0 ); CalypPixel( const int CalypColorSpace, const ClpPel c0 = 0 );
CalypPixel( const int& CalypColorSpace, const ClpPel& c0, const ClpPel& c1, const ClpPel& c2 ); CalypPixel( const int CalypColorSpace, const ClpPel c0, const ClpPel c1, const ClpPel c2 );
CalypPixel( const int& CalypColorSpace, const ClpPel& c0, const ClpPel& c1, const ClpPel& c2, const ClpPel& c3 ); CalypPixel( const int CalypColorSpace, const ClpPel c0, const ClpPel c1, const ClpPel c2, const ClpPel c3 );
CalypPixel( const CalypPixel& other ); CalypPixel( const CalypPixel& other ) noexcept = default;
~CalypPixel(); CalypPixel( CalypPixel&& other ) noexcept = default;
auto operator=( const CalypPixel& other ) -> CalypPixel& = default;
auto operator=( CalypPixel&& other ) noexcept -> CalypPixel& = default;
~CalypPixel() = default;
int colorSpace() const; int colorSpace() const { return m_colorSpace; };
ClpPel operator[]( const int& channel ) const; auto components() const -> const std::array<ClpPel, kMaxNumberOfComponents>& { return m_pelComp; };
ClpPel& operator[]( const int& channel ); auto components() -> std::array<ClpPel, kMaxNumberOfComponents>& { return m_pelComp; };
CalypPixel operator=( const CalypPixel& ); ClpPel operator[]( const int& channel ) const { return m_pelComp[channel]; }
CalypPixel operator+( const CalypPixel& ); ClpPel& operator[]( const int& channel ) { return m_pelComp[channel]; }
CalypPixel operator+=( const CalypPixel& );
CalypPixel operator-( const CalypPixel& ); CalypPixel& operator+=( const CalypPixel& );
CalypPixel operator-=( const CalypPixel& ); CalypPixel& operator-=( const CalypPixel& );
CalypPixel operator*( const double& ); CalypPixel& operator*=( const double& );
CalypPixel operator+( const CalypPixel& ) const;
CalypPixel operator-( const CalypPixel& ) const;
CalypPixel operator*( const double& ) const;
/** /**
* Convert a Pixel to a new color space * Convert a Pixel to a new color space
@@ -72,11 +147,49 @@ public:
* @param eOutputSpace output color space * @param eOutputSpace output color space
* @return converted pixel * @return converted pixel
*/ */
CalypPixel convertPixel( CalypColorSpace eOutputSpace ); CalypPixel convertPixel( CalypColorSpace eOutputSpace ) const;
};
/**
* \class CalypPlane
* \ingroup CalypLibGrp CalypPlaneGrp
* \brief Frame handling class
*/
template <typename T>
class CalypPlane
{
public:
CalypPlane() noexcept = default;
CalypPlane( std::size_t width, std::size_t height ) noexcept { resize( width, height ); }
~CalypPlane() noexcept = default;
CalypPlane( const CalypPlane& buffer ) noexcept = default;
CalypPlane( CalypPlane&& buffer ) noexcept = default;
auto operator=( const CalypPlane& buffer ) -> CalypPlane& = default;
auto operator=( CalypPlane&& buffer ) noexcept -> CalypPlane& = default;
auto operator[]( std::size_t row ) const& noexcept -> const std::span<T>& { return m_rows[row]; }
auto operator[]( std::size_t row ) & noexcept -> std::span<T>& { return m_rows[row]; }
auto operator[]( std::size_t row ) const&& noexcept { return m_rows[row]; }
auto operator[]( std::size_t row ) && noexcept { return m_rows[row]; }
auto data() noexcept { return std::span<T>( m_data ); }
auto data() const noexcept { return std::span<const T>( m_data ); }
void resize( std::size_t width, std::size_t height ) noexcept
{
m_data.resize( width * height );
m_rows.resize( height );
for( std::size_t y = 0; y < height; y++ )
{
m_rows[y] = std::span<T>( m_data ).subspan( y * width, width );
}
}
private: private:
class CalypPixelPrivate; std::vector<T> m_data;
std::unique_ptr<CalypPixelPrivate> d; std::vector<std::span<T>> m_rows;
}; };
/** /**
@@ -92,17 +205,17 @@ public:
* of CalypFrame * of CalypFrame
* @return vector of strings with pixel formats names * @return vector of strings with pixel formats names
*/ */
static std::vector<ClpString> supportedColorSpacesListNames(); static std::vector<std::string> supportedColorSpacesListNames();
/** /**
* Function that handles the supported pixel formats * Function that handles the supported pixel formats
* of CalypFrame * of CalypFrame
* @return vector of strings with pixel formats names * @return vector of strings with pixel formats names
*/ */
static std::vector<ClpString> supportedPixelFormatListNames(); static std::vector<std::string> supportedPixelFormatListNames();
static std::vector<ClpString> supportedPixelFormatListNames( int colorSpace ); static std::vector<std::string> supportedPixelFormatListNames( int colorSpace );
static int numberOfFormats(); static int numberOfFormats();
static int findPixelFormat( const ClpString& name ); static int findPixelFormat( const std::string& name );
static int pelformatColorSpace( const int idx ); static int pelformatColorSpace( const int idx );
/** /**
@@ -203,7 +316,7 @@ public:
* Get pixel format information * Get pixel format information
* @return pixel format name * @return pixel format name
*/ */
ClpString getPelFmtName(); std::string getPelFmtName();
/** /**
* Get color space information * Get color space information
@@ -242,13 +355,13 @@ public:
* @param channel/component * @param channel/component
* @return number of pixels * @return number of pixels
*/ */
ClpULong getPixels( unsigned channel = 0 ) const; std::uint64_t getPixels( unsigned channel = 0 ) const;
/** /**
* Get the total number of pixels of the frame * Get the total number of pixels of the frame
* @return number of pixels * @return number of pixels
*/ */
ClpULong getTotalNumberOfPixels() const; std::uint64_t getTotalNumberOfPixels() const;
/** /**
* Get chroma width ratio * Get chroma width ratio
@@ -266,7 +379,7 @@ public:
* Get number of pixels in each chroma channel * Get number of pixels in each chroma channel
* @return number of pixels * @return number of pixels
*/ */
ClpULong getChromaLength() const; std::uint64_t getChromaLength() const;
/** /**
* Get number of bits per pixel * Get number of bits per pixel
@@ -278,13 +391,13 @@ public:
* Get number of bytes per frame of an existing frame * Get number of bytes per frame of an existing frame
* @return number of bytes per frame * @return number of bytes per frame
*/ */
ClpULong getBytesPerFrame() const; std::uint64_t getBytesPerFrame() const;
/** /**
* Get number of bytes per frame of a specific pixel format * Get number of bytes per frame of a specific pixel format
* @return number of bytes per frame * @return number of bytes per frame
*/ */
static ClpULong getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, int iPixelFormat, unsigned int bitsPixel ); static std::uint64_t getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, int iPixelFormat, unsigned int bitsPixel );
/** /**
* Reset frame pixels to zero * Reset frame pixels to zero
@@ -330,7 +443,7 @@ public:
* @param eColorSpace desired color space * @param eColorSpace desired color space
* @return pixel value * @return pixel value
*/ */
CalypPixel getPixel( unsigned int xPos, unsigned int yPos, CalypColorSpace eColorSpace ); CalypPixel getPixel( unsigned int xPos, unsigned int yPos, CalypColorSpace eColorSpace ) const;
/** /**
* Set pixel value at coordinates to a given value * Set pixel value at coordinates to a given value
@@ -430,8 +543,8 @@ public:
NUMBER_METRICS, NUMBER_METRICS,
}; };
static std::vector<ClpString> supportedQualityMetricsList(); static std::vector<std::string> supportedQualityMetricsList();
static std::vector<ClpString> supportedQualityMetricsUnitsList(); static std::vector<std::string> supportedQualityMetricsUnitsList();
double getQuality( int Metric, CalypFrame* Org, unsigned int component ); double getQuality( int Metric, CalypFrame* Org, unsigned int component );
double getMSE( CalypFrame* Org, unsigned int component ); double getMSE( CalypFrame* Org, unsigned int component );
double getPSNR( CalypFrame* Org, unsigned int component ); double getPSNR( CalypFrame* Org, unsigned int component );
+66 -25
View File
@@ -42,9 +42,16 @@
#define REGISTER_CLASS_MAKER( X ) \ #define REGISTER_CLASS_MAKER( X ) \
extern "C" CalypModulePtr Maker() { return std::make_unique<X>(); } extern "C" CalypModulePtr Maker() { return std::make_unique<X>(); }
#define REGISTER_CLASS_FACTORY( X ) \ #define REGISTER_CLASS_FACTORY( X ) \
public: \ public: \
X( const X& buffer ) \
noexcept = delete; \
X( X&& buffer ) \
noexcept = delete; \
auto operator=( const X& buffer )->X& = delete; \
auto operator=( X&& buffer ) noexcept->X& = delete; \
static CalypModulePtr Create() { return std::make_unique<X>(); } static CalypModulePtr Create() { return std::make_unique<X>(); }
#define _BASIC_MODULE_API_2_CHECK_ \ #define _BASIC_MODULE_API_2_CHECK_ \
if( apcFrameList.size() != m_uiNumberOfFrames ) \ if( apcFrameList.size() != m_uiNumberOfFrames ) \
return false; \ return false; \
@@ -76,8 +83,9 @@ enum Module_API_Version
*/ */
enum Module_Type enum Module_Type
{ {
CLP_FRAME_PROCESSING_MODULE, CLP_INVALID_MODULE = -1,
CLP_FRAME_MEASUREMENT_MODULE, CLP_FRAME_PROCESSING_MODULE = 0,
CLP_FRAME_MEASUREMENT_MODULE = 1,
CLP_MODULE_TYPE_MAX = 255, CLP_MODULE_TYPE_MAX = 255,
}; };
@@ -114,32 +122,28 @@ enum Module_Key_Supported
class CalypModuleIf class CalypModuleIf
{ {
public: public:
int m_iModuleAPI; int m_iModuleAPI{ CLP_MODULE_API_1 };
int m_iModuleType; int m_iModuleType{ CLP_INVALID_MODULE };
const char* m_pchModuleCategory; const char* m_pchModuleCategory{ "" };
const char* m_pchModuleName; const char* m_pchModuleName{ "" };
const char* m_pchModuleTooltip; const char* m_pchModuleTooltip{ "" };
const char* m_pchModuleLongName; const char* m_pchModuleLongName{ nullptr };
//! Number of frames //! Number of frames
unsigned int m_uiNumberOfFrames; unsigned int m_uiNumberOfFrames{ 1 };
//! Features/Requirements //! Features/Requirements
unsigned int m_uiModuleRequirements; unsigned int m_uiModuleRequirements{ CLP_MODULE_REQUIRES_NOTHING };
unsigned int m_iFrameBufferCount; unsigned int m_iFrameBufferCount{ 0 };
CalypFrame* m_pcOutputFrame;
CalypOptions m_cModuleOptions; CalypOptions m_cModuleOptions;
CalypModuleIf() CalypModuleIf() = default;
{ CalypModuleIf( const CalypModuleIf& other ) noexcept = delete;
m_iModuleAPI = CLP_MODULE_API_1; CalypModuleIf( CalypModuleIf&& other ) noexcept = delete;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_NOTHING; auto operator=( const CalypModuleIf& other ) -> CalypModuleIf& = delete;
m_pchModuleLongName = NULL; auto operator=( CalypModuleIf&& other ) noexcept -> CalypModuleIf& = delete;
m_pcOutputFrame = NULL; virtual ~CalypModuleIf() = default;
m_iFrameBufferCount = 0;
}
virtual ~CalypModuleIf() {}
virtual void destroy() = 0; virtual void destroy() = 0;
const char* getModuleLongName() const char* getModuleLongName()
@@ -160,11 +164,11 @@ public:
virtual CalypFrame* process( std::vector<CalypFrame*> ) { return NULL; } virtual CalypFrame* process( std::vector<CalypFrame*> ) { return NULL; }
virtual double measure( std::vector<CalypFrame*> ) { return 0; } virtual double measure( std::vector<CalypFrame*> ) { return 0; }
virtual bool keyPressed( enum Module_Key_Supported ) { return false; } virtual bool keyPressed( enum Module_Key_Supported ) { return false; }
virtual ClpString moduleInfo() { return ClpString(); } virtual std::string moduleInfo() { return std::string(); }
/** /**
* Module API version 3 * Module API version 3
*/ */
virtual CalypFrame* getProcessedFrame() { return m_pcOutputFrame; } virtual CalypFrame* getProcessedFrame() { return nullptr; }
virtual bool needFrame() { return m_iFrameBufferCount == 0 ? true : false; }; virtual bool needFrame() { return m_iFrameBufferCount == 0 ? true : false; };
virtual bool flush() virtual bool flush()
{ {
@@ -173,6 +177,43 @@ public:
}; };
}; };
namespace cv
{
class Mat;
}
/**
* \class CalypOpenCVModuleIf
* \ingroup CalypLib Calyp_Modules
* \brief Abstract class for modules using OpenCV library
*/
class CalypOpenCVModuleIf : public CalypModuleIf
{
using Mat = cv::Mat;
protected:
//const char* m_pchPythonFunctionName;
std::unique_ptr<CalypFrame> m_pcOutputFrame;
bool m_bConvertToGray;
public:
CalypOpenCVModuleIf()
{
m_bConvertToGray = false;
};
virtual ~CalypOpenCVModuleIf() {}
// Common API
bool create( std::vector<CalypFrame*> apcFrameList );
CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
void destroy();
// API using OpenCV
virtual cv::Mat* create_using_opencv( const std::vector<Mat>& apcFrameList ) { return nullptr; };
virtual Mat* process_using_opencv( const std::vector<Mat>& apcFrameList ) = 0;
virtual void destroy_using_opencv(){};
};
using CalypModulePtr = std::unique_ptr<CalypModuleIf>; using CalypModulePtr = std::unique_ptr<CalypModuleIf>;
#endif // __CALYPMODULESIF_H__ #endif // __CALYPMODULESIF_H__
+7 -22
View File
@@ -22,62 +22,47 @@
* \brief Calyp modules interface for OpenCV * \brief Calyp modules interface for OpenCV
*/ */
#include "CalypOpenCVModuleIf.h" #include "CalypModuleIf.h"
// OpenCV // OpenCV
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
using cv::Mat;
bool CalypOpenCVModuleIf::create( std::vector<CalypFrame*> apcFrameList ) bool CalypOpenCVModuleIf::create( std::vector<CalypFrame*> apcFrameList )
{ {
_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() );
for( unsigned i = 0; i < apcFrameList.size(); i++ ) for( unsigned i = 0; i < apcFrameList.size(); i++ )
{ {
acMatList[i] = new Mat; apcFrameList[i]->toMat( acMatList[i], m_bConvertToGray );
apcFrameList[i]->toMat( *acMatList[i], m_bConvertToGray );
} }
Mat* outputMat = create_using_opencv( acMatList ); Mat* outputMat = create_using_opencv( acMatList );
if( outputMat ) if( outputMat )
{ {
unsigned pelFormat = m_bConvertToGray ? CalypFrame::findPixelFormat( "GRAY" ) : apcFrameList[0]->getPelFormat(); unsigned pelFormat = m_bConvertToGray ? CalypFrame::findPixelFormat( "GRAY" ) : apcFrameList[0]->getPelFormat();
m_pcOutputFrame = new CalypFrame( outputMat->cols, outputMat->rows, pelFormat, apcFrameList[0]->getBitsPel() ); m_pcOutputFrame = std::make_unique<CalypFrame>( outputMat->cols, outputMat->rows, pelFormat, apcFrameList[0]->getBitsPel() );
bRet = true; bRet = true;
} }
else else
{ {
return false; return false;
} }
for( unsigned i = 0; i < apcFrameList.size(); i++ )
{
delete acMatList[i];
}
return bRet; return bRet;
} }
CalypFrame* CalypOpenCVModuleIf::process( std::vector<CalypFrame*> apcFrameList ) CalypFrame* CalypOpenCVModuleIf::process( std::vector<CalypFrame*> apcFrameList )
{ {
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++ )
{ {
acMatList[i] = new Mat; apcFrameList[i]->toMat( acMatList[i], m_bConvertToGray );
apcFrameList[i]->toMat( *acMatList[i], m_bConvertToGray );
} }
Mat* cvOutput = process_using_opencv( acMatList ); Mat* cvOutput = process_using_opencv( acMatList );
m_pcOutputFrame->fromMat( *cvOutput ); m_pcOutputFrame->fromMat( *cvOutput );
for( unsigned i = 0; i < apcFrameList.size(); i++ ) return m_pcOutputFrame.get();
{
delete acMatList[i];
}
return m_pcOutputFrame;
} }
void CalypOpenCVModuleIf::destroy() void CalypOpenCVModuleIf::destroy()
{ {
if( m_pcOutputFrame )
delete m_pcOutputFrame;
m_pcOutputFrame = NULL;
} }
-65
View File
@@ -1,65 +0,0 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2021 by Joao Carreira (jfmcarreira@gmail.com)
* Luis Lucas (luisfrlucas@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file CalypOpenCVModuleIf.h
* \ingroup CalypLibGroup
* \brief Calyp modules interface for OpenCV
*/
#ifndef __CALYPOPENCVMODULEIF_H__
#define __CALYPOPENCVMODULEIF_H__
#include "CalypModuleIf.h"
namespace cv
{
class Mat;
}
/**
* \class CalypOpenCVModuleIf
* \ingroup CalypLib Calyp_Modules
* \brief Abstract class for modules using OpenCV library
*/
class CalypOpenCVModuleIf : public CalypModuleIf
{
protected:
const char* m_pchPythonFunctionName;
bool m_bConvertToGray;
public:
CalypOpenCVModuleIf()
{
m_bConvertToGray = false;
};
virtual ~CalypOpenCVModuleIf() {}
// Common API
bool create( std::vector<CalypFrame*> apcFrameList );
CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
void destroy();
// API using OpenCV
virtual cv::Mat* create_using_opencv( std::vector<cv::Mat*> apcFrameList ) { return NULL; };
virtual cv::Mat* process_using_opencv( std::vector<cv::Mat*> apcFrameList ) = 0;
virtual void destroy_using_opencv(){};
};
#endif // __CALYPOPENCVMODULEIF_H__
+37 -37
View File
@@ -49,9 +49,9 @@ using namespace std;
struct ParseFailure : public std::exception struct ParseFailure : public std::exception
{ {
ClpString arg; std::string arg;
ClpString val; std::string val;
ParseFailure( ClpString arg0, ClpString val0 ) throw() ParseFailure( std::string arg0, std::string val0 ) throw()
: arg( arg0 ), val( val0 ) {} : arg( arg0 ), val( val0 ) {}
~ParseFailure() throw() {} ~ParseFailure() throw() {}
const char* what() const throw() { return "Option Parse Failure"; } const char* what() const throw() { return "Option Parse Failure"; }
@@ -61,9 +61,9 @@ struct ParseFailure : public std::exception
class boolOption : public OptionBase class boolOption : public OptionBase
{ {
public: public:
boolOption( const ClpString& name, const ClpString& desc ) boolOption( const std::string& name, const std::string& desc )
: OptionBase( name, desc, "(1-0)" ) { is_binary = true; } : OptionBase( name, desc, "(1-0)" ) { is_binary = true; }
void parse( const ClpString& arg ) { arg_count++; } void parse( const std::string& arg ) { arg_count++; }
}; };
/** Type specific option storage */ /** Type specific option storage */
@@ -71,20 +71,20 @@ template <typename T>
class StandardOption : public OptionBase class StandardOption : public OptionBase
{ {
public: public:
StandardOption( const ClpString& name, T& storage, const ClpString& desc, const ClpString& def ) StandardOption( const std::string& name, T& storage, const std::string& desc, const std::string& def )
: OptionBase( name, desc, def ), opt_storage( storage ) : OptionBase( name, desc, def ), opt_storage( storage )
{ {
is_binary = false; is_binary = false;
} }
void parse( const ClpString& arg ); void parse( const std::string& arg );
T& opt_storage; T& opt_storage;
std::vector<T> opt_storage_array; std::vector<T> opt_storage_array;
}; };
/* Generic parsing */ /* Generic parsing */
template <typename T> template <typename T>
inline void StandardOption<T>::parse( const ClpString& arg ) inline void StandardOption<T>::parse( const std::string& arg )
{ {
if( !is_binary ) if( !is_binary )
{ {
@@ -103,7 +103,7 @@ inline void StandardOption<T>::parse( const ClpString& arg )
} }
template <> template <>
inline void StandardOption<std::vector<unsigned int>>::parse( const ClpString& arg ) inline void StandardOption<std::vector<unsigned int>>::parse( const std::string& arg )
{ {
unsigned int aux_opt_storage; unsigned int aux_opt_storage;
std::istringstream arg_ss( arg, std::istringstream::in ); std::istringstream arg_ss( arg, std::istringstream::in );
@@ -121,7 +121,7 @@ inline void StandardOption<std::vector<unsigned int>>::parse( const ClpString& a
} }
template <> template <>
inline void StandardOption<std::vector<int>>::parse( const ClpString& arg ) inline void StandardOption<std::vector<int>>::parse( const std::string& arg )
{ {
int aux_opt_storage; int aux_opt_storage;
std::istringstream arg_ss( arg, std::istringstream::in ); std::istringstream arg_ss( arg, std::istringstream::in );
@@ -140,7 +140,7 @@ inline void StandardOption<std::vector<int>>::parse( const ClpString& arg )
/* string parsing is specialized */ /* string parsing is specialized */
template <> template <>
inline void StandardOption<ClpString>::parse( const ClpString& arg ) inline void StandardOption<std::string>::parse( const std::string& arg )
{ {
opt_storage = arg; opt_storage = arg;
arg_count++; arg_count++;
@@ -148,7 +148,7 @@ inline void StandardOption<ClpString>::parse( const ClpString& arg )
/* string vector parsing is specialized */ /* string vector parsing is specialized */
template <> template <>
inline void StandardOption<std::vector<ClpString>>::parse( const ClpString& arg ) inline void StandardOption<std::vector<std::string>>::parse( const std::string& arg )
{ {
opt_storage.push_back( arg ); opt_storage.push_back( arg );
arg_count++; arg_count++;
@@ -158,15 +158,15 @@ inline void StandardOption<std::vector<ClpString>>::parse( const ClpString& arg
struct FunctionOption : public OptionBase struct FunctionOption : public OptionBase
{ {
public: public:
typedef void( Func )( CalypOptions&, const ClpString& ); typedef void( Func )( CalypOptions&, const std::string& );
FunctionOption( const ClpString& name, CalypOptions& parent_, Func* func_, const ClpString& desc, const ClpString& def ) FunctionOption( const std::string& name, CalypOptions& parent_, Func* func_, const std::string& desc, const std::string& def )
: OptionBase( name, desc, def ), parent( parent_ ), func( func_ ) : OptionBase( name, desc, def ), parent( parent_ ), func( func_ )
{ {
is_binary = false; is_binary = false;
} }
void parse( const ClpString& arg ) void parse( const std::string& arg )
{ {
func( parent, arg ); func( parent, arg );
arg_count++; arg_count++;
@@ -174,7 +174,7 @@ public:
private: private:
CalypOptions& parent; CalypOptions& parent;
void ( *func )( CalypOptions&, const ClpString& ); void ( *func )( CalypOptions&, const std::string& );
}; };
/* Helper method to initiate adding options to Options */ /* Helper method to initiate adding options to Options */
@@ -185,7 +185,7 @@ private:
* with default_val as the default value * with default_val as the default value
* with desc as an optional help description * with desc as an optional help description
*/ */
CalypOptions& CalypOptions::operator()( const ClpString& name, const ClpString& desc ) CalypOptions& CalypOptions::operator()( const std::string& name, const std::string& desc )
{ {
addOption( new boolOption( name, desc ) ); addOption( new boolOption( name, desc ) );
return *this; return *this;
@@ -197,31 +197,31 @@ CalypOptions& CalypOptions::operator()( const ClpString& name, const ClpString&
* with desc as an optional help description * with desc as an optional help description
*/ */
template <typename T> template <typename T>
CalypOptions& CalypOptions::operator()( const ClpString& name, T& storage, const ClpString& desc ) CalypOptions& CalypOptions::operator()( const std::string& name, T& storage, const std::string& desc )
{ {
addOption( new StandardOption<T>( name, storage, desc, ClpString( "" ) ) ); addOption( new StandardOption<T>( name, storage, desc, std::string( "" ) ) );
return *this; return *this;
} }
template <typename T> template <typename T>
CalypOptions& CalypOptions::operator()( const ClpString& name, T& storage, const ClpString& desc, const ClpString& defaults ) CalypOptions& CalypOptions::operator()( const std::string& name, T& storage, const std::string& desc, const std::string& defaults )
{ {
addOption( new StandardOption<T>( name, storage, desc ) ); addOption( new StandardOption<T>( name, storage, desc ) );
return *this; return *this;
} }
template CalypOptions& CalypOptions::operator()( const ClpString& name, bool& storage, const ClpString& desc ); template CalypOptions& CalypOptions::operator()( const std::string& name, bool& storage, const std::string& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, unsigned int& storage, const ClpString& desc ); template CalypOptions& CalypOptions::operator()( const std::string& name, unsigned int& storage, const std::string& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, int& storage, const ClpString& desc ); template CalypOptions& CalypOptions::operator()( const std::string& name, int& storage, const std::string& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, long& storage, const ClpString& desc ); template CalypOptions& CalypOptions::operator()( const std::string& name, long& storage, const std::string& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, long long int& storage, const ClpString& desc ); template CalypOptions& CalypOptions::operator()( const std::string& name, long long int& storage, const std::string& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, ClpString& storage, const ClpString& desc ); template CalypOptions& CalypOptions::operator()( const std::string& name, std::string& storage, const std::string& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, std::vector<unsigned int>& storage, template CalypOptions& CalypOptions::operator()( const std::string& name, std::vector<unsigned int>& storage,
const ClpString& desc ); const std::string& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, std::vector<int>& storage, template CalypOptions& CalypOptions::operator()( const std::string& name, std::vector<int>& storage,
const ClpString& desc ); const std::string& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, std::vector<ClpString>& storage, template CalypOptions& CalypOptions::operator()( const std::string& name, std::vector<std::string>& storage,
const ClpString& desc ); const std::string& desc );
CalypOptions::Option::Option() CalypOptions::Option::Option()
: opt( 0 ) {} : opt( 0 ) {}
@@ -232,7 +232,7 @@ CalypOptions::Option::~Option()
delete opt; delete opt;
} }
CalypOptions::CalypOptions( const ClpString& name ) CalypOptions::CalypOptions( const std::string& name )
{ {
m_cOptionGroupName = name; m_cOptionGroupName = name;
m_bAllowUnkonw = true; m_bAllowUnkonw = true;
@@ -246,12 +246,12 @@ CalypOptions::~CalypOptions()
} }
} }
OptionBase* CalypOptions::operator[]( const ClpString& optName ) OptionBase* CalypOptions::operator[]( const std::string& optName )
{ {
return getOption( optName ); return getOption( optName );
} }
OptionBase* CalypOptions::getOption( const ClpString& optName ) OptionBase* CalypOptions::getOption( const std::string& optName )
{ {
CalypOptions::OptionMap::iterator opt_it; CalypOptions::OptionMap::iterator opt_it;
opt_it = opt_short_map.find( optName ); opt_it = opt_short_map.find( optName );
@@ -275,7 +275,7 @@ OptionBase* CalypOptions::getOption( const ClpString& optName )
return NULL; return NULL;
} }
bool CalypOptions::hasOpt( const ClpString& optName ) bool CalypOptions::hasOpt( const std::string& optName )
{ {
OptionBase* opt = getOption( optName ); OptionBase* opt = getOption( optName );
return opt ? opt->count() > 0 ? true : false : false; return opt ? opt->count() > 0 ? true : false : false;
@@ -545,7 +545,7 @@ list<const char*> CalypOptions::scanArgv( unsigned int argc, char* argv[] )
return non_option_arguments; return non_option_arguments;
} }
void CalypOptions::parse( std::vector<ClpString> args_array ) void CalypOptions::parse( std::vector<std::string> args_array )
{ {
for( unsigned int i = 0; i < args_array.size(); i++ ) for( unsigned int i = 0; i < args_array.size(); i++ )
{ {
+20 -20
View File
@@ -56,17 +56,17 @@
class OptionBase class OptionBase
{ {
public: public:
OptionBase( const ClpString& name, const ClpString& desc, const ClpString& def ) OptionBase( const std::string& name, const std::string& desc, const std::string& def )
: arg_count( 0 ), opt_string( name ), opt_desc( desc ), opt_defaults( def ) {} : arg_count( 0 ), opt_string( name ), opt_desc( desc ), opt_defaults( def ) {}
virtual ~OptionBase() {} virtual ~OptionBase() {}
/* parse argument arg, to obtain a value for the option */ /* parse argument arg, to obtain a value for the option */
virtual void parse( const ClpString& arg ) = 0; virtual void parse( const std::string& arg ) = 0;
int count() { return arg_count; } int count() { return arg_count; }
bool isBinary() { return is_binary; } bool isBinary() { return is_binary; }
int arg_count; int arg_count;
ClpString opt_string; std::string opt_string;
ClpString opt_desc; std::string opt_desc;
ClpString opt_defaults; std::string opt_defaults;
bool is_binary; bool is_binary;
}; };
@@ -82,25 +82,25 @@ public:
{ {
Option(); Option();
~Option(); ~Option();
std::list<ClpString> opt_long; std::list<std::string> opt_long;
std::list<ClpString> opt_short; std::list<std::string> opt_short;
OptionBase* opt; OptionBase* opt;
}; };
typedef std::list<Option*> OptionsList; typedef std::list<Option*> OptionsList;
CalypOptions( const ClpString& name = "" ); CalypOptions( const std::string& name = "" );
~CalypOptions(); ~CalypOptions();
int parse( unsigned int argc, char* argv[] ); int parse( unsigned int argc, char* argv[] );
void parse( std::vector<ClpString> args_array ); void parse( std::vector<std::string> args_array );
std::list<const char*>& getUnhandledArgs() { return m_aUnhandledArgs; } std::list<const char*>& getUnhandledArgs() { return m_aUnhandledArgs; }
void doHelp( std::ostream& out, unsigned columns = 80 ); void doHelp( std::ostream& out, unsigned columns = 80 );
OptionBase* operator[]( const ClpString& optName ); OptionBase* operator[]( const std::string& optName );
OptionBase* getOption( const ClpString& optName ); OptionBase* getOption( const std::string& optName );
bool hasOpt( const ClpString& optName ); bool hasOpt( const std::string& optName );
OptionsList getOptionList() { return opt_list; } OptionsList getOptionList() { return opt_list; }
void addDefaultOptions(); void addDefaultOptions();
@@ -113,7 +113,7 @@ public:
* with default_val as the default value * with default_val as the default value
* with desc as an optional help description * with desc as an optional help description
*/ */
CalypOptions& operator()( const ClpString& name, const ClpString& desc ); CalypOptions& operator()( const std::string& name, const std::string& desc );
/** /**
* Add option described by name to the parent Options list, * Add option described by name to the parent Options list,
@@ -122,28 +122,28 @@ public:
* description and range along with default value * description and range along with default value
*/ */
template <typename T> template <typename T>
CalypOptions& operator()( const ClpString& name, T& storage, const ClpString& desc ); CalypOptions& operator()( const std::string& name, T& storage, const std::string& desc );
template <typename T> template <typename T>
CalypOptions& operator()( const ClpString& name, T& storage, const ClpString& desc, const ClpString& defaults ); CalypOptions& operator()( const std::string& name, T& storage, const std::string& desc, const std::string& defaults );
bool checkListingOpts(); bool checkListingOpts();
private: private:
typedef std::map<ClpString, OptionsList> OptionMap; typedef std::map<std::string, OptionsList> OptionMap;
OptionMap opt_long_map; OptionMap opt_long_map;
OptionMap opt_short_map; OptionMap opt_short_map;
OptionsList opt_list; OptionsList opt_list;
ClpString m_cOptionGroupName; std::string m_cOptionGroupName;
bool m_bAllowUnkonw; bool m_bAllowUnkonw;
std::list<const char*> m_aUnhandledArgs; std::list<const char*> m_aUnhandledArgs;
bool storePair( bool allow_long, bool allow_short, const ClpString& name, const ClpString& value ); bool storePair( bool allow_long, bool allow_short, const std::string& name, const std::string& value );
bool storePair( const ClpString& name, const ClpString& value ); bool storePair( const std::string& name, const std::string& value );
unsigned int parseLONG( unsigned int argc, char* argv[] ); unsigned int parseLONG( unsigned int argc, char* argv[] );
unsigned int parseLONG( ClpString arg ); unsigned int parseLONG( std::string arg );
unsigned int parseSHORT( unsigned int argc, char* argv[] ); unsigned int parseSHORT( unsigned int argc, char* argv[] );
std::list<const char*> scanArgv( unsigned int argc, char* argv[] ); std::list<const char*> scanArgv( unsigned int argc, char* argv[] );
}; };
+89 -132
View File
@@ -22,204 +22,161 @@
* \brief Video Frame handling * \brief Video Frame handling
*/ */
#include <algorithm>
#include <cassert>
#include <memory> #include <memory>
#include <numeric>
#include "CalypFrame.h" #include "CalypFrame.h"
#include "PixelFormats.h" #include "PixelFormats.h"
#include "config.h" #include "config.h"
#define MAX_NUMBER_COMPONENTS 4 constexpr auto kMinPixelValue{ 0 };
constexpr auto kMaxPixelValue{ 255 };
class CalypPixel::CalypPixelPrivate
{
public:
CalypPixelPrivate( const int& ColorSpace )
{
iColorSpace = ColorSpace == CLP_COLOR_GRAY ?
CLP_COLOR_YUV :
ColorSpace;
for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ )
{
PelComp[i] = 0;
}
}
int iColorSpace;
ClpPel PelComp[MAX_NUMBER_COMPONENTS];
};
static inline void yuvToRgb( const int& iY, const int& iU, const int& iV, int& iR, int& iG, int& iB ) static inline void yuvToRgb( const int& iY, const int& iU, const int& iV, int& iR, int& iG, int& iB )
{ {
iR = iY + ( ( 1436 * ( iV - 128 ) ) >> 10 ); iR = std::clamp( iY + ( ( 1436 * ( iV - 128 ) ) >> 10 ), kMinPixelValue, kMaxPixelValue ); //NOLINT
iG = iY - ( ( 352 * ( iU - 128 ) + 731 * ( iV - 128 ) ) >> 10 ); iG = std::clamp( iY - ( ( 352 * ( iU - 128 ) + 731 * ( iV - 128 ) ) >> 10 ), kMinPixelValue, kMaxPixelValue ); //NOLINT
iB = iY + ( ( 1812 * ( iU - 128 ) ) >> 10 ); iB = std::clamp( iY + ( ( 1812 * ( iU - 128 ) ) >> 10 ), kMinPixelValue, kMaxPixelValue ); //NOLINT
iR = iR < 0 ? 0 : iR > 255 ? 255 :
iR;
iG = iG < 0 ? 0 : iG > 255 ? 255 :
iG;
iB = iB < 0 ? 0 : iB > 255 ? 255 :
iB;
} }
static inline void rgbToYuv( const int& iR, const int& iG, const int& iB, int& iY, int& iU, int& iV ) static inline void rgbToYuv( const int& iR, const int& iG, const int& iB, int& iY, int& iU, int& iV )
{ {
iY = ( 299 * iR + 587 * iG + 114 * iB + 500 ) / 1000; iY = ( 299 * iR + 587 * iG + 114 * iB + 500 ) / 1000; //NOLINT
iU = ( 1000 * ( iB - iY ) + 226816 ) / 1772; iU = ( 1000 * ( iB - iY ) + 226816 ) / 1772; //NOLINT
iV = ( 1000 * ( iR - iY ) + 179456 ) / 1402; iV = ( 1000 * ( iR - iY ) + 179456 ) / 1402; //NOLINT
} }
int CalypPixel::getMaxNumberOfComponents() CalypPixel::CalypPixel( const int ColorSpace, const ClpPel c0 )
{ {
return MAX_NUMBER_COMPONENTS; m_colorSpace = ColorSpace;
m_pelComp[0] = c0;
} }
CalypPixel::CalypPixel( const int& ColorSpace ) CalypPixel::CalypPixel( const int ColorSpace, const ClpPel c0, const ClpPel c1, const ClpPel c2 )
: d{ std::make_unique<CalypPixelPrivate>( ColorSpace ) }
{ {
m_colorSpace = ColorSpace;
m_pelComp[0] = c0;
m_pelComp[1] = c1;
m_pelComp[2] = c2;
} }
CalypPixel::CalypPixel( const int& ColorSpace, const ClpPel& c0 ) CalypPixel::CalypPixel( const int ColorSpace, const ClpPel c0, const ClpPel c1, const ClpPel c2, const ClpPel c3 )
: d{ std::make_unique<CalypPixelPrivate>( ColorSpace ) }
{ {
d->PelComp[0] = c0; m_colorSpace = ColorSpace;
m_pelComp[0] = c0;
m_pelComp[1] = c1;
m_pelComp[2] = c2;
m_pelComp[3] = c3;
} }
CalypPixel::CalypPixel( const int& ColorSpace, const ClpPel& c0, const ClpPel& c1, const ClpPel& c2 ) CalypPixel& CalypPixel::operator+=( const CalypPixel& in )
: d{ std::make_unique<CalypPixelPrivate>( ColorSpace ) }
{ {
d->PelComp[0] = c0; assert( in.colorSpace() == m_colorSpace );
d->PelComp[1] = c1; const auto& other_comp = in.components();
d->PelComp[2] = c2; std::transform( other_comp.begin(),
} other_comp.end(),
m_pelComp.begin(),
CalypPixel::CalypPixel( const int& ColorSpace, const ClpPel& c0, const ClpPel& c1, const ClpPel& c2, const ClpPel& c3 ) m_pelComp.begin(),
: d{ std::make_unique<CalypPixelPrivate>( ColorSpace ) } []( auto& p1, auto& p2 ) { return p1 + p2; } );
{
d->PelComp[0] = c0;
d->PelComp[1] = c1;
d->PelComp[2] = c2;
d->PelComp[3] = c3;
}
CalypPixel::CalypPixel( const CalypPixel& other )
: d{ std::make_unique<CalypPixelPrivate>( other.colorSpace() ) }
{
for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ )
{
d->PelComp[i] = other[i];
}
}
CalypPixel::~CalypPixel() = default;
int CalypPixel::colorSpace() const
{
return d->iColorSpace;
}
ClpPel CalypPixel::operator[]( const int& channel ) const
{
return d->PelComp[channel];
}
ClpPel& CalypPixel::operator[]( const int& channel )
{
return d->PelComp[channel];
}
CalypPixel CalypPixel::operator=( const CalypPixel& other )
{
for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ )
{
d->PelComp[i] = other[i];
}
return *this; return *this;
} }
CalypPixel CalypPixel::operator+( const CalypPixel& in ) CalypPixel& CalypPixel::operator-=( const CalypPixel& in )
{ {
CalypPixel result; assert( in.colorSpace() == m_colorSpace );
for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ ) const auto& other_comp = in.components();
{ std::transform( other_comp.begin(),
result[i] = d->PelComp[i] + in[i]; other_comp.end(),
} m_pelComp.begin(),
return result; m_pelComp.begin(),
} []( auto& p1, auto& p2 ) { return p1 - p2; } );
CalypPixel CalypPixel::operator+=( const CalypPixel& in )
{
for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ )
{
d->PelComp[i] += in[i];
}
return *this; return *this;
} }
CalypPixel CalypPixel::operator-( const CalypPixel& in ) CalypPixel& CalypPixel::operator*=( const double& op )
{ {
CalypPixel result; std::transform( m_pelComp.begin(),
for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ ) m_pelComp.end(),
{ m_pelComp.begin(),
result[i] = d->PelComp[i] - in[i]; [&op]( auto& p1 ) { return p1 * op; } );
}
return result;
}
CalypPixel CalypPixel::operator-=( const CalypPixel& in )
{
for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ )
{
d->PelComp[i] -= in[i];
}
return *this; return *this;
} }
CalypPixel CalypPixel::operator*( const double& op ) CalypPixel CalypPixel::operator+( const CalypPixel& in ) const
{ {
CalypPixel result; assert( in.colorSpace() == m_colorSpace );
for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ ) const auto& other_comp = in.components();
{ CalypPixel result{ m_colorSpace };
result[i] = d->PelComp[i] * op; std::transform( other_comp.begin(),
} other_comp.end(),
m_pelComp.begin(),
result.components().begin(),
[]( auto& p1, auto& p2 ) { return p1 + p2; } );
return result; return result;
} }
CalypPixel CalypPixel::convertPixel( CalypColorSpace eOutputSpace ) CalypPixel CalypPixel::operator-( const CalypPixel& in ) const
{ {
if( d->iColorSpace == eOutputSpace ) assert( in.colorSpace() == m_colorSpace );
const auto& other_comp = in.components();
CalypPixel result{ m_colorSpace };
std::transform( other_comp.begin(),
other_comp.end(),
m_pelComp.begin(),
result.components().begin(),
[]( auto& p1, auto& p2 ) { return p1 - p2; } );
return result;
}
CalypPixel CalypPixel::operator*( const double& op ) const
{
CalypPixel result{ m_colorSpace };
auto& comp = result.components();
std::transform( comp.begin(),
comp.end(),
comp.begin(),
[&op]( auto& p1 ) { return p1 * op; } );
return result;
}
CalypPixel CalypPixel::convertPixel( CalypColorSpace eOutputSpace ) const
{
if( m_colorSpace == eOutputSpace )
return *this; return *this;
int outA = 0; int outA = 0;
int outB = 0; int outB = 0;
int outC = 0; int outC = 0;
int outD = 0; int outD = 0;
if( d->iColorSpace == CLP_COLOR_YUV ) if( m_colorSpace == CLP_COLOR_YUV )
{ {
switch( eOutputSpace ) switch( eOutputSpace )
{ {
case CLP_COLOR_GRAY: case CLP_COLOR_GRAY:
outA = d->PelComp[0]; outA = m_pelComp[0];
break; break;
case CLP_COLOR_RGBA: case CLP_COLOR_RGBA:
outD = 255; outD = kMaxPixelValue;
case CLP_COLOR_RGB: case CLP_COLOR_RGB:
yuvToRgb( d->PelComp[0], d->PelComp[1], d->PelComp[2], outA, outB, outC ); yuvToRgb( m_pelComp[0], m_pelComp[1], m_pelComp[2], outA, outB, outC );
break; break;
default: default:
break; break;
} }
} }
if( d->iColorSpace == CLP_COLOR_RGB ) if( m_colorSpace == CLP_COLOR_RGB )
{ {
switch( eOutputSpace ) switch( eOutputSpace )
{ {
case CLP_COLOR_GRAY: case CLP_COLOR_GRAY:
rgbToYuv( d->PelComp[0], d->PelComp[1], d->PelComp[2], outA, outB, outC ); rgbToYuv( m_pelComp[0], m_pelComp[1], m_pelComp[2], outA, outB, outC );
case CLP_COLOR_YUV: case CLP_COLOR_YUV:
rgbToYuv( d->PelComp[0], d->PelComp[1], d->PelComp[2], outA, outB, outC ); rgbToYuv( m_pelComp[0], m_pelComp[1], m_pelComp[2], outA, outB, outC );
break; break;
case CLP_COLOR_RGBA: case CLP_COLOR_RGBA:
outD = 255; outD = kMaxPixelValue;
break; break;
default: default:
break; break;
+66 -61
View File
@@ -33,7 +33,6 @@
#include "CalypFrame.h" #include "CalypFrame.h"
#include "CalypStreamHandlerIf.h" #include "CalypStreamHandlerIf.h"
#include "LibMemory.h"
#include "StreamHandlerPortableMap.h" #include "StreamHandlerPortableMap.h"
#include "StreamHandlerRaw.h" #include "StreamHandlerRaw.h"
#include "config.h" #include "config.h"
@@ -49,6 +48,8 @@
constexpr auto kDefaultBitsPerPixel = 8; constexpr auto kDefaultBitsPerPixel = 8;
constexpr auto kDefaultFrameRate = 30; constexpr auto kDefaultFrameRate = 30;
auto find_stream_handler( std::string strFilename, bool bRead ) -> CalypStreamFormat::CreateStreamHandlerFn;
std::vector<CalypStreamFormat> CalypStream::supportedReadFormats() std::vector<CalypStreamFormat> CalypStream::supportedReadFormats()
{ {
INI_REGIST_CALYP_SUPPORTED_FMT; INI_REGIST_CALYP_SUPPORTED_FMT;
@@ -167,8 +168,7 @@ public:
bool isInit; bool isInit;
bool isInput; bool isInput;
CalypStreamHandlerIf* handler; std::unique_ptr<CalypStreamHandlerIf> handler;
CreateStreamHandlerFn pfctCreateHandler;
std::shared_ptr<CalypStreamFrameBuffer> frameBuffer; std::shared_ptr<CalypStreamFrameBuffer> frameBuffer;
std::deque<std::shared_ptr<CalypFrame>> frameFifo; std::deque<std::shared_ptr<CalypFrame>> frameFifo;
@@ -177,7 +177,7 @@ public:
// std::deque<std::shared_ptr<CalypFrame>> frameFifo; // std::deque<std::shared_ptr<CalypFrame>> frameFifo;
// std::size_t bufferIdx{ 0 }; // std::size_t bufferIdx{ 0 };
ClpString cFilename; std::string cFilename;
long long int iCurrFrameNum; long long int iCurrFrameNum;
bool bLoadAll; bool bLoadAll;
@@ -188,7 +188,6 @@ public:
CalypStreamPrivate() CalypStreamPrivate()
{ {
handler = nullptr; handler = nullptr;
pfctCreateHandler = nullptr;
isInput = true; isInput = true;
isInit = false; isInit = false;
bLoadAll = false; bLoadAll = false;
@@ -206,7 +205,6 @@ public:
if( handler ) if( handler )
{ {
handler->closeHandler(); handler->closeHandler();
handler->Delete();
} }
bLoadAll = false; bLoadAll = false;
@@ -240,13 +238,13 @@ public:
} }
}; };
std::vector<ClpString> CalypStreamFormat::getExts() std::vector<std::string> CalypStreamFormat::getExts()
{ {
std::vector<ClpString> arrayExt; std::vector<std::string> arrayExt;
ClpString::size_type prev_pos = 0, pos = 0; std::string::size_type prev_pos = 0, pos = 0;
while( ( pos = formatExt.find( ',', pos ) ) != ClpString::npos ) while( ( pos = formatExt.find( ',', pos ) ) != std::string::npos )
{ {
ClpString substring( formatExt.substr( prev_pos, pos - prev_pos ) ); std::string substring( formatExt.substr( prev_pos, pos - prev_pos ) );
arrayExt.push_back( substring ); arrayExt.push_back( substring );
prev_pos = ++pos; prev_pos = ++pos;
} }
@@ -254,43 +252,6 @@ std::vector<ClpString> CalypStreamFormat::getExts()
return arrayExt; return arrayExt;
} }
CreateStreamHandlerFn CalypStream::findStreamHandler( ClpString strFilename, bool bRead )
{
ClpString currExt = strFilename.substr( strFilename.find_last_of( "." ) + 1 );
currExt = clpLowercase( currExt );
std::vector<CalypStreamFormat> supportedFmts;
if( bRead )
{
supportedFmts = CalypStream::supportedReadFormats();
}
else
{
supportedFmts = CalypStream::supportedWriteFormats();
}
for( unsigned int i = 0; i < supportedFmts.size(); i++ )
{
std::vector<ClpString> arrayExt = supportedFmts[i].getExts();
for( std::vector<ClpString>::iterator e = arrayExt.begin(); e != arrayExt.end(); ++e )
{
if( currExt != "" && currExt == *e )
{
return supportedFmts[i].formatFct;
}
else if( strFilename.find( *e ) != ClpString::npos )
{
return supportedFmts[i].formatFct;
}
}
}
#ifdef USE_FFMPEG
return &StreamHandlerLibav::Create;
#else
return &StreamHandlerRaw::Create;
#endif
}
CalypStream::CalypStream() CalypStream::CalypStream()
: d{ std::make_unique<CalypStreamPrivate>() } : d{ std::make_unique<CalypStreamPrivate>() }
{ {
@@ -298,16 +259,16 @@ CalypStream::CalypStream()
CalypStream::~CalypStream() = default; CalypStream::~CalypStream() = default;
ClpString CalypStream::getFormatName() const std::string CalypStream::getFormatName() const
{ {
return !d->handler ? "" : d->handler->getFormatName(); return !d->handler ? "" : d->handler->getFormatName();
} }
ClpString CalypStream::getCodecName() const std::string CalypStream::getCodecName() const
{ {
return !d->handler ? "" : d->handler->getCodecName(); return !d->handler ? "" : d->handler->getCodecName();
} }
bool CalypStream::open( ClpString filename, ClpString resolution, ClpString input_format_name, unsigned int bitsPel, int endianness, bool hasNegative, bool CalypStream::open( std::string filename, std::string resolution, std::string input_format_name, unsigned int bitsPel, int endianness, bool hasNegative,
unsigned int frame_rate, bool bInput ) unsigned int frame_rate, bool bInput )
{ {
unsigned int width = 0; unsigned int width = 0;
@@ -333,13 +294,13 @@ bool CalypStream::open( ClpString filename, ClpString resolution, ClpString inpu
return open( filename, width, height, input_format, bitsPel, endianness, hasNegative, frame_rate, bInput ); return open( filename, width, height, input_format, bitsPel, endianness, hasNegative, frame_rate, bInput );
} }
bool CalypStream::open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, bool CalypStream::open( std::string filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness,
unsigned int frame_rate, bool bInput ) unsigned int frame_rate, bool bInput )
{ {
return open( filename, width, height, input_format, bitsPel, endianness, false, frame_rate, bInput ); return open( filename, width, height, input_format, bitsPel, endianness, false, frame_rate, bInput );
} }
bool CalypStream::open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, bool hasNegative, bool CalypStream::open( std::string filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, bool hasNegative,
unsigned int frame_rate, bool bInput ) unsigned int frame_rate, bool bInput )
{ {
if( d->isInit ) if( d->isInit )
@@ -349,13 +310,13 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei
d->isInit = false; d->isInit = false;
d->isInput = bInput; d->isInput = bInput;
d->pfctCreateHandler = CalypStream::findStreamHandler( filename, d->isInput ); auto createHandlerFct = find_stream_handler( filename, d->isInput );
if( !d->pfctCreateHandler ) if( !createHandlerFct )
{ {
throw CalypFailure( "CalypStream", "Invalid handler" ); throw CalypFailure( "CalypStream", "Invalid handler" );
} }
d->handler = d->pfctCreateHandler(); d->handler = createHandlerFct();
if( !d->handler ) if( !d->handler )
{ {
@@ -435,6 +396,13 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei
return d->isInit; return d->isInit;
} }
bool CalypStream::supportsFormating()
{
if( d->handler != nullptr )
return false;
return d->handler->m_bSupportsFormat;
}
bool CalypStream::reload() bool CalypStream::reload()
{ {
d->frameFifo.clear(); d->frameFifo.clear();
@@ -442,7 +410,7 @@ bool CalypStream::reload()
if( !d->handler->openHandler( d->cFilename, d->isInput ) ) if( !d->handler->openHandler( d->cFilename, d->isInput ) )
{ {
throw CalypFailure( "CalypStream", "Cannot open stream " + d->cFilename + " with the " + throw CalypFailure( "CalypStream", "Cannot open stream " + d->cFilename + " with the " +
ClpString( d->handler->m_pchHandlerName ) + " handler" ); std::string( d->handler->m_pchHandlerName ) + " handler" );
} }
const CalypFrame* refFrame = d->frameBuffer->ref(); const CalypFrame* refFrame = d->frameBuffer->ref();
d->handler->m_uiNBytesPerFrame = refFrame->getBytesPerFrame(); d->handler->m_uiNBytesPerFrame = refFrame->getBytesPerFrame();
@@ -464,7 +432,7 @@ bool CalypStream::reload()
return true; return true;
} }
ClpString CalypStream::getFileName() const std::string CalypStream::getFileName() const
{ {
return d->cFilename; return d->cFilename;
} }
@@ -474,7 +442,7 @@ bool CalypStream::isNative() const
return d->handler->m_bNative; return d->handler->m_bNative;
} }
ClpULong CalypStream::getFrameNum() const std::uint64_t CalypStream::getFrameNum() const
{ {
return d->handler->m_uiTotalNumberFrames; return d->handler->m_uiTotalNumberFrames;
} }
@@ -634,12 +602,12 @@ void CalypStream::writeFrame( const CalypFrame& pcFrame )
return; return;
} }
bool CalypStream::saveFrame( const ClpString& filename ) bool CalypStream::saveFrame( const std::string& filename )
{ {
return saveFrame( filename, *getCurrFrame() ); return saveFrame( filename, *getCurrFrame() );
} }
bool CalypStream::saveFrame( const ClpString& filename, const CalypFrame& saveFrame ) bool CalypStream::saveFrame( const std::string& filename, const CalypFrame& saveFrame )
{ {
CalypStream auxSaveStream; CalypStream auxSaveStream;
if( !auxSaveStream.open( filename, saveFrame.getWidth(), saveFrame.getHeight(), saveFrame.getPelFormat(), if( !auxSaveStream.open( filename, saveFrame.getWidth(), saveFrame.getHeight(), saveFrame.getPelFormat(),
@@ -696,3 +664,40 @@ bool CalypStream::seekInput( unsigned long new_frame_num )
d->readNextFrame(); d->readNextFrame();
return true; return true;
} }
auto find_stream_handler( std::string strFilename, bool bRead ) -> CalypStreamFormat::CreateStreamHandlerFn
{
std::string currExt = strFilename.substr( strFilename.find_last_of( "." ) + 1 );
currExt = clpLowercase( currExt );
std::vector<CalypStreamFormat> supportedFmts;
if( bRead )
{
supportedFmts = CalypStream::supportedReadFormats();
}
else
{
supportedFmts = CalypStream::supportedWriteFormats();
}
for( unsigned int i = 0; i < supportedFmts.size(); i++ )
{
std::vector<std::string> arrayExt = supportedFmts[i].getExts();
for( std::vector<std::string>::iterator e = arrayExt.begin(); e != arrayExt.end(); ++e )
{
if( currExt != "" && currExt == *e )
{
return supportedFmts[i].formatFct;
}
else if( strFilename.find( *e ) != std::string::npos )
{
return supportedFmts[i].formatFct;
}
}
}
#ifdef USE_FFMPEG
return &StreamHandlerLibav::Create;
#else
return &StreamHandlerRaw::Create;
#endif
}
+31 -24
View File
@@ -34,24 +34,33 @@
class CalypStreamHandlerIf; class CalypStreamHandlerIf;
typedef CalypStreamHandlerIf* ( *CreateStreamHandlerFn )( void );
struct CalypStreamFormat
{
ClpString formatName;
ClpString formatExt;
std::vector<ClpString> getExts();
ClpString formatPattern;
CreateStreamHandlerFn formatFct;
};
struct CalypStandardResolution struct CalypStandardResolution
{ {
ClpString shortName; std::string shortName;
unsigned int uiWidth; unsigned int uiWidth;
unsigned int uiHeight; unsigned int uiHeight;
}; };
/**
* \class CalypStreamFormat
* \ingroup CalypLibGrp CalypStreamGrp
* \brief Stream format handling class
*/
class CalypStreamFormat
{
public:
using CreateStreamHandlerFn = auto ( * )( void ) -> std::unique_ptr<CalypStreamHandlerIf>;
CalypStreamFormat() = default;
std::vector<std::string> getExts();
std::string formatName;
std::string formatExt;
std::string formatPattern;
CreateStreamHandlerFn formatFct;
};
/** /**
* \class CalypStream * \class CalypStream
* \ingroup CalypLibGrp CalypStreamGrp * \ingroup CalypLibGrp CalypStreamGrp
@@ -62,9 +71,6 @@ class CalypStream
public: public:
static std::vector<CalypStreamFormat> supportedReadFormats(); static std::vector<CalypStreamFormat> supportedReadFormats();
static std::vector<CalypStreamFormat> supportedWriteFormats(); static std::vector<CalypStreamFormat> supportedWriteFormats();
static CreateStreamHandlerFn findStreamHandler( ClpString strFilename, bool bRead );
static std::vector<CalypStandardResolution> stdResolutionSizes(); static std::vector<CalypStandardResolution> stdResolutionSizes();
CalypStream(); CalypStream();
@@ -74,21 +80,22 @@ public:
CalypStream& operator=( const CalypStream& other ) = delete; CalypStream& operator=( const CalypStream& other ) = delete;
~CalypStream(); ~CalypStream();
ClpString getFormatName() const; std::string getFormatName() const;
ClpString getCodecName() const; std::string getCodecName() const;
bool open( ClpString filename, ClpString resolution, ClpString input_format, unsigned int bitsPel, int endianness, bool hasNegative, unsigned int frame_rate, bool open( std::string filename, std::string resolution, std::string input_format, unsigned int bitsPel, int endianness, bool hasNegative, unsigned int frame_rate,
bool bInput ); bool bInput );
bool open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, unsigned int frame_rate, bool open( std::string filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, unsigned int frame_rate,
bool bInput ); bool bInput );
bool open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, bool hasNegative, unsigned int frame_rate, bool open( std::string filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, bool hasNegative, unsigned int frame_rate,
bool bInput ); bool bInput );
bool supportsFormating();
bool reload(); bool reload();
bool isNative() const; bool isNative() const;
ClpString getFileName() const; std::string getFileName() const;
ClpULong getFrameNum() const; std::uint64_t getFrameNum() const;
unsigned int getWidth() const; unsigned int getWidth() const;
unsigned int getHeight() const; unsigned int getHeight() const;
unsigned int getBitsPerPixel() const; unsigned int getBitsPerPixel() const;
@@ -112,8 +119,8 @@ public:
void writeFrame( const CalypFrame& pcFrame ); void writeFrame( const CalypFrame& pcFrame );
bool saveFrame( const ClpString& filename ); bool saveFrame( const std::string& filename );
static bool saveFrame( const ClpString& filename, const CalypFrame& saveFrame ); static bool saveFrame( const std::string& filename, const CalypFrame& saveFrame );
bool seekInputRelative( bool bIsFoward ); bool seekInputRelative( bool bIsFoward );
bool seekInput( unsigned long new_frame_num ); bool seekInput( unsigned long new_frame_num );
+38 -42
View File
@@ -51,12 +51,11 @@
formatsList.insert( formatsList.end(), new_fmts.begin(), new_fmts.end() ); \ formatsList.insert( formatsList.end(), new_fmts.begin(), new_fmts.end() ); \
} }
#define REGISTER_CALYP_STREAM_HANDLER( X ) \ #define REGISTER_CALYP_STREAM_HANDLER( X ) \
public: \ public: \
static CalypStreamHandlerIf* Create() { return new X(); } \ static std::unique_ptr<CalypStreamHandlerIf> Create() { return std::make_unique<X>(); } \
void Delete() { delete this; } \ static std::vector<CalypStreamFormat> supportedReadFormats(); \
static std::vector<CalypStreamFormat> supportedReadFormats(); \ static std::vector<CalypStreamFormat> supportedWriteFormats(); \
static std::vector<CalypStreamFormat> supportedWriteFormats(); \
// static int checkforSupportedFile( String, bool ); // static int checkforSupportedFile( String, bool );
/** /**
@@ -69,55 +68,52 @@ class CalypStreamHandlerIf
friend class CalypStream; friend class CalypStream;
public: public:
CalypStreamHandlerIf()
: m_bIsInput( true )
, m_bNative( true )
, m_uiWidth( 0 )
, m_uiHeight( 0 )
, m_iPixelFormat( -1 )
, m_uiBitsPerPixel( 8 )
, m_iEndianness( -1 )
, m_dFrameRate( 30 )
, m_uiCurrFrameFileIdx( 0 )
, m_uiTotalNumberFrames( 0 )
, m_uiNBytesPerFrame( 0 )
, m_isEOF( false )
{
}
virtual ~CalypStreamHandlerIf() {} virtual ~CalypStreamHandlerIf() {}
virtual void Delete() = 0;
virtual bool openHandler( ClpString strFilename, bool bInput ) = 0; virtual bool openHandler( std::string strFilename, bool bInput ) = 0;
virtual void closeHandler() = 0; virtual void closeHandler() = 0;
virtual bool configureBuffer( const CalypFrame& pcFrame ) = 0; virtual bool configureBuffer( const CalypFrame& pcFrame ) = 0;
virtual bool seek( ClpULong iFrameNum ) = 0; virtual bool seek( std::uint64_t iFrameNum ) = 0;
virtual bool read( CalypFrame& pcFrame ) = 0; virtual bool read( CalypFrame& pcFrame ) = 0;
virtual bool write( const CalypFrame& pcFrame ) = 0; virtual bool write( const CalypFrame& pcFrame ) = 0;
virtual void calculateFrameNumber(){}; virtual void calculateFrameNumber(){};
ClpString getFormatName() { return m_strFormatName; } std::string getFormatName()
ClpString getCodecName() { return m_strCodecName; } {
return m_strFormatName;
}
std::string getCodecName()
{
return m_strCodecName;
}
protected: protected:
const char* m_pchHandlerName; CalypStreamHandlerIf() = default;
CalypStreamHandlerIf( bool supportsFormats )
: m_bSupportsFormat{ supportsFormats }
{
}
ClpString m_strFormatName; const char* m_pchHandlerName{ "" };
ClpString m_strCodecName; const bool m_bSupportsFormat{ false };
bool m_bIsInput;
bool m_bNative; std::string m_strFormatName;
ClpString m_cFilename; std::string m_strCodecName;
unsigned int m_uiWidth; bool m_bIsInput{ true };
unsigned int m_uiHeight; bool m_bNative{ true };
int m_iPixelFormat; std::string m_cFilename;
unsigned int m_uiBitsPerPixel; unsigned int m_uiWidth{ 0 };
int m_iEndianness; unsigned int m_uiHeight{ 0 };
double m_dFrameRate; int m_iPixelFormat{ -1 };
ClpULong m_uiCurrFrameFileIdx; unsigned int m_uiBitsPerPixel{ 8 };
ClpULong m_uiTotalNumberFrames; int m_iEndianness{ CLP_INVALID_ENDIANESS };
double m_dFrameRate{ 30 };
std::uint64_t m_uiCurrFrameFileIdx{ 0 };
std::uint64_t m_uiTotalNumberFrames{ 0 };
std::vector<ClpByte> m_pStreamBuffer; std::vector<ClpByte> m_pStreamBuffer;
ClpULong m_uiNBytesPerFrame; std::uint64_t m_uiNBytesPerFrame{ 0 };
bool m_isEOF; bool m_isEOF{ false };
}; };
#endif // __CALYPSTREAMHANDLERIF_H__ #endif // __CALYPSTREAMHANDLERIF_H__
-117
View File
@@ -1,117 +0,0 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2021 by Joao Carreira (jfmcarreira@gmail.com)
* Luis Lucas (luisfrlucas@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file LibMemory.cpp
* \ingroup CalypLib
* \brief Memory allocation functions
*/
#ifndef __LIBMEMORY_H__
#define __LIBMEMORY_H__
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define DATA_ALIGN 1 ///< use 32-bit aligned malloc/free
#if DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 )
#define xMalloc( len ) _aligned_malloc( len, 32 )
#define xFreeMem( ptr ) _aligned_free( ptr )
#else
#define xMalloc( len ) malloc( len )
#define xFreeMem( ptr ) free( ptr )
#endif
#define xMemSet( type, len, ptr ) memset( ptr, 0, ( len ) * sizeof( type ) )
[[deprecated]] static inline void* xMallocMem( size_t nitems )
{
void* d;
if( ( d = xMalloc( nitems ) ) == NULL )
{
printf( "malloc failed.\n" );
return NULL;
}
return d;
}
[[deprecated]] static inline void* xCallocMem( size_t nitems, size_t size )
{
size_t padded_size = nitems * size;
void* d = xMallocMem( padded_size );
if( d )
memset( d, 0, (int)padded_size );
return d;
}
template <typename T>
[[deprecated]] int getMem1D( T** array1D, int dim0 )
{
if( ( *array1D = (T*)xCallocMem( dim0, sizeof( T ) ) ) == NULL )
return 0;
return ( sizeof( T* ) + dim0 * sizeof( T ) );
}
template <typename T>
[[deprecated]] void freeMem1D( T*& array1D )
{
if( array1D )
{
xFreeMem( array1D );
array1D = NULL;
}
}
template <typename T>
int getMem2D( T*** array2D, int dim0, int dim1 )
{
int i;
if( ( *array2D = (T**)xMallocMem( dim0 * sizeof( T* ) ) ) == NULL )
printf( "get_mem2Dint: array2D" );
if( ( *( *array2D ) = (T*)xCallocMem( dim0 * dim1, sizeof( T ) ) ) == NULL )
printf( "get_mem2Dint: array2D" );
for( i = 1; i < dim0; i++ )
( *array2D )[i] = ( *array2D )[i - 1] + dim1;
return dim0 * ( sizeof( T* ) + dim1 * sizeof( T ) );
}
template <typename T>
void freeMem2D( T**& array2D )
{
if( *array2D )
{
if( *array2D )
xFreeMem( *array2D );
else
printf( "free_mem2Dint: trying to free unused memory" );
xFreeMem( array2D );
array2D = NULL;
}
else
{
printf( "free_mem2Dint: trying to free unused memory" );
}
}
#endif // __LIBMEMORY_H__
-1
View File
@@ -25,7 +25,6 @@
#include "PixelFormats.h" #include "PixelFormats.h"
#include "CalypFrame.h" #include "CalypFrame.h"
#include "LibMemory.h"
#include "config.h" #include "config.h"
#ifdef USE_FFMPEG #ifdef USE_FFMPEG
#include "StreamHandlerLibav.h" #include "StreamHandlerLibav.h"
+3 -4
View File
@@ -28,7 +28,6 @@
#include <iostream> #include <iostream>
#include "CalypFrame.h" #include "CalypFrame.h"
#include "LibMemory.h"
#include "PixelFormats.h" #include "PixelFormats.h"
#if( ( LIBAVCODEC_VERSION_MAJOR > 57 ) || ( LIBAVCODEC_VERSION_MAJOR == 57 ) && ( LIBAVCODEC_VERSION_MINOR >= 37 ) ) #if( ( LIBAVCODEC_VERSION_MAJOR > 57 ) || ( LIBAVCODEC_VERSION_MAJOR == 57 ) && ( LIBAVCODEC_VERSION_MINOR >= 37 ) )
@@ -64,7 +63,7 @@ StreamHandlerLibav::StreamHandlerLibav()
m_pchHandlerName = "FFmpeg"; m_pchHandlerName = "FFmpeg";
} }
bool StreamHandlerLibav::openHandler( ClpString strFilename, bool bInput ) bool StreamHandlerLibav::openHandler( std::string strFilename, bool bInput )
{ {
const char* filename = strFilename.c_str(); const char* filename = strFilename.c_str();
@@ -333,7 +332,7 @@ bool StreamHandlerLibav::configureBuffer( const CalypFrame& pcFrame )
void StreamHandlerLibav::calculateFrameNumber() void StreamHandlerLibav::calculateFrameNumber()
{ {
ClpULong num_frames; std::uint64_t num_frames;
/*if( m_cStream->nb_frames ) /*if( m_cStream->nb_frames )
{ {
num_frames = m_cStream->nb_frames; num_frames = m_cStream->nb_frames;
@@ -440,7 +439,7 @@ bool StreamHandlerLibav::write( const CalypFrame& pcFrame )
return false; return false;
} }
bool StreamHandlerLibav::seek( ClpULong iFrameNum ) bool StreamHandlerLibav::seek( std::uint64_t iFrameNum )
{ {
if( m_uiTotalNumberFrames == 1 ) if( m_uiTotalNumberFrames == 1 )
return true; return true;
+2 -2
View File
@@ -63,11 +63,11 @@ class StreamHandlerLibav : public CalypStreamHandlerIf
public: public:
StreamHandlerLibav(); StreamHandlerLibav();
~StreamHandlerLibav() {} ~StreamHandlerLibav() {}
bool openHandler( ClpString strFilename, bool bInput ); bool openHandler( std::string strFilename, bool bInput );
void closeHandler(); void closeHandler();
bool configureBuffer( const CalypFrame& pcFrame ); bool configureBuffer( const CalypFrame& pcFrame );
void calculateFrameNumber(); void calculateFrameNumber();
bool seek( ClpULong iFrameNum ); bool seek( std::uint64_t iFrameNum );
bool read( CalypFrame& pcFrame ); bool read( CalypFrame& pcFrame );
bool write( const CalypFrame& pcFrame ); bool write( const CalypFrame& pcFrame );
+5 -6
View File
@@ -28,7 +28,6 @@
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include "CalypFrame.h" #include "CalypFrame.h"
#include "LibMemory.h"
#if CV_MAJOR_VERSION >= 3 #if CV_MAJOR_VERSION >= 3
#include <opencv2/videoio.hpp> #include <opencv2/videoio.hpp>
#endif #endif
@@ -64,7 +63,7 @@ StreamHandlerOpenCV::StreamHandlerOpenCV()
pcVideoCapture = NULL; pcVideoCapture = NULL;
} }
bool StreamHandlerOpenCV::openHandler( ClpString strFilename, bool bInput ) bool StreamHandlerOpenCV::openHandler( std::string strFilename, bool bInput )
{ {
m_cFilename = strFilename; m_cFilename = strFilename;
if( bInput ) if( bInput )
@@ -73,12 +72,12 @@ bool StreamHandlerOpenCV::openHandler( ClpString strFilename, bool bInput )
/* /*
* Special filename to handle webcam input * Special filename to handle webcam input
*/ */
if( m_cFilename.find( "/dev/video" ) != ClpString::npos ) if( m_cFilename.find( "/dev/video" ) != std::string::npos )
{ {
int iDeviceId = 0; int iDeviceId = 0;
if( m_cFilename.find( "/dev/video0" ) != ClpString::npos ) if( m_cFilename.find( "/dev/video0" ) != std::string::npos )
iDeviceId = 0; iDeviceId = 0;
else if( m_cFilename.find( "/dev/video1" ) != ClpString::npos ) else if( m_cFilename.find( "/dev/video1" ) != std::string::npos )
iDeviceId = 1; iDeviceId = 1;
m_strFormatName = "DEV"; m_strFormatName = "DEV";
@@ -131,7 +130,7 @@ bool StreamHandlerOpenCV::configureBuffer( const CalypFrame& pcFrame )
return true; return true;
} }
bool StreamHandlerOpenCV::seek( ClpULong iFrameNum ) bool StreamHandlerOpenCV::seek( std::uint64_t iFrameNum )
{ {
// m_uiCurrFrameFileIdx = // m_uiCurrFrameFileIdx =
return true; return true;
+2 -2
View File
@@ -40,10 +40,10 @@ class StreamHandlerOpenCV : public CalypStreamHandlerIf
public: public:
StreamHandlerOpenCV(); StreamHandlerOpenCV();
~StreamHandlerOpenCV() {} ~StreamHandlerOpenCV() {}
bool openHandler( ClpString strFilename, bool bInput ); bool openHandler( std::string strFilename, bool bInput );
void closeHandler(); void closeHandler();
bool configureBuffer( const CalypFrame& pcFrame ); bool configureBuffer( const CalypFrame& pcFrame );
bool seek( ClpULong iFrameNum ); bool seek( std::uint64_t iFrameNum );
bool read( CalypFrame& pcFrame ); bool read( CalypFrame& pcFrame );
bool write( const CalypFrame& pcFrame ); bool write( const CalypFrame& pcFrame );
+2 -3
View File
@@ -28,7 +28,6 @@
#include <cstdio> #include <cstdio>
#include "CalypFrame.h" #include "CalypFrame.h"
#include "LibMemory.h"
std::vector<CalypStreamFormat> StreamHandlerPortableMap::supportedReadFormats() std::vector<CalypStreamFormat> StreamHandlerPortableMap::supportedReadFormats()
{ {
@@ -48,7 +47,7 @@ std::vector<CalypStreamFormat> StreamHandlerPortableMap::supportedWriteFormats()
END_REGIST_CALYP_SUPPORTED_FMT; END_REGIST_CALYP_SUPPORTED_FMT;
} }
bool StreamHandlerPortableMap::openHandler( ClpString strFilename, bool bInput ) bool StreamHandlerPortableMap::openHandler( std::string strFilename, bool bInput )
{ {
m_bIsInput = bInput; m_bIsInput = bInput;
m_pFile = NULL; m_pFile = NULL;
@@ -132,7 +131,7 @@ bool StreamHandlerPortableMap::configureBuffer( const CalypFrame& pcFrame )
return true; return true;
} }
bool StreamHandlerPortableMap::seek( ClpULong iFrameNum ) bool StreamHandlerPortableMap::seek( std::uint64_t iFrameNum )
{ {
// m_uiCurrFrameFileIdx = // m_uiCurrFrameFileIdx =
return true; return true;
+2 -2
View File
@@ -35,10 +35,10 @@ class StreamHandlerPortableMap : public CalypStreamHandlerIf
public: public:
StreamHandlerPortableMap() { m_pchHandlerName = "PortableMaps"; } StreamHandlerPortableMap() { m_pchHandlerName = "PortableMaps"; }
~StreamHandlerPortableMap() {} ~StreamHandlerPortableMap() {}
bool openHandler( ClpString strFilename, bool bInput ); bool openHandler( std::string strFilename, bool bInput );
void closeHandler(); void closeHandler();
bool configureBuffer( const CalypFrame& pcFrame ); bool configureBuffer( const CalypFrame& pcFrame );
bool seek( ClpULong iFrameNum ); bool seek( std::uint64_t iFrameNum );
bool read( CalypFrame& pcFrame ); bool read( CalypFrame& pcFrame );
bool write( const CalypFrame& pcFrame ); bool write( const CalypFrame& pcFrame );
+8 -3
View File
@@ -27,7 +27,6 @@
#include <cstdio> #include <cstdio>
#include "CalypFrame.h" #include "CalypFrame.h"
#include "LibMemory.h"
std::vector<CalypStreamFormat> StreamHandlerRaw::supportedReadFormats() std::vector<CalypStreamFormat> StreamHandlerRaw::supportedReadFormats()
{ {
@@ -45,7 +44,13 @@ std::vector<CalypStreamFormat> StreamHandlerRaw::supportedWriteFormats()
END_REGIST_CALYP_SUPPORTED_FMT; END_REGIST_CALYP_SUPPORTED_FMT;
} }
bool StreamHandlerRaw::openHandler( ClpString strFilename, bool bInput ) StreamHandlerRaw::StreamHandlerRaw()
: CalypStreamHandlerIf{ true }
{
m_pchHandlerName = "RawVideo";
}
bool StreamHandlerRaw::openHandler( std::string strFilename, bool bInput )
{ {
m_bIsInput = bInput; m_bIsInput = bInput;
m_pFile = NULL; m_pFile = NULL;
@@ -83,7 +88,7 @@ void StreamHandlerRaw::calculateFrameNumber()
} }
} }
bool StreamHandlerRaw::seek( ClpULong iFrameNum ) bool StreamHandlerRaw::seek( std::uint64_t iFrameNum )
{ {
if( m_bIsInput && m_pFile ) if( m_bIsInput && m_pFile )
{ {
+3 -3
View File
@@ -40,13 +40,13 @@ private:
FILE* m_pFile; /**< The input file pointer >*/ FILE* m_pFile; /**< The input file pointer >*/
public: public:
StreamHandlerRaw() { m_pchHandlerName = "RawVideo"; } StreamHandlerRaw();
~StreamHandlerRaw() {} ~StreamHandlerRaw() {}
bool openHandler( ClpString strFilename, bool bInput ); bool openHandler( std::string strFilename, bool bInput );
void closeHandler(); void closeHandler();
bool configureBuffer( const CalypFrame& pcFrame ); bool configureBuffer( const CalypFrame& pcFrame );
void calculateFrameNumber(); void calculateFrameNumber();
bool seek( ClpULong iFrameNum ); bool seek( std::uint64_t iFrameNum );
bool read( CalypFrame& pcFrame ); bool read( CalypFrame& pcFrame );
bool write( const CalypFrame& pcFrame ); bool write( const CalypFrame& pcFrame );
}; };
-2
View File
@@ -8,6 +8,4 @@ SET(Calyp_Lib_Catch2_Tests_SRCS CalypFrameTests.cpp)
ADD_EXECUTABLE(CalypLibCatch2Tests ${Calyp_Lib_Catch2_Tests_SRCS}) ADD_EXECUTABLE(CalypLibCatch2Tests ${Calyp_Lib_Catch2_Tests_SRCS})
TARGET_LINK_LIBRARIES(CalypLibCatch2Tests ${PROJECT_LIBRARY} Catch2::Catch2) TARGET_LINK_LIBRARIES(CalypLibCatch2Tests ${PROJECT_LIBRARY} Catch2::Catch2)
INCLUDE(CTest)
CATCH_DISCOVER_TESTS(CalypLibCatch2Tests) CATCH_DISCOVER_TESTS(CalypLibCatch2Tests)
+12 -17
View File
@@ -34,13 +34,13 @@ protected:
// Can be omitted if not needed. // Can be omitted if not needed.
static void SetUpTestCase() static void SetUpTestCase()
{ {
pcStreamPast = new CalypStream; pcStreamPast = std::make_unique<CalypStream>();
pcStreamPast->open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8, pcStreamPast->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8,
CLP_BIG_ENDIAN, 1, true ); CLP_BIG_ENDIAN, 1, true );
pcFramePast = pcStreamPast->getCurrFrame(); pcFramePast = pcStreamPast->getCurrFrame();
pcStreamFuture = new CalypStream; pcStreamFuture = std::make_unique<CalypStream>();
pcStreamFuture->open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/BasketballDrill_F15_832x480_yuv420p.yuv" ), 832, 480, 0, 8, pcStreamFuture->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F15_832x480_yuv420p.yuv" ), 832, 480, 0, 8,
CLP_BIG_ENDIAN, 1, true ); CLP_BIG_ENDIAN, 1, true );
pcFrameFuture = pcStreamFuture->getCurrFrame(); pcFrameFuture = pcStreamFuture->getCurrFrame();
} }
@@ -50,27 +50,22 @@ protected:
// Can be omitted if not needed. // Can be omitted if not needed.
static void TearDownTestCase() static void TearDownTestCase()
{ {
pcStreamPast->close(); pcStreamPast = nullptr;
delete pcStreamPast; pcStreamFuture = nullptr;
pcStreamPast = NULL;
pcStreamFuture->close();
delete pcStreamFuture;
pcStreamFuture = NULL;
} }
// Some expensive resource shared by all tests. // Some expensive resource shared by all tests.
static CalypStream* pcStreamPast; static std::unique_ptr<CalypStream> pcStreamPast;
static CalypFrame* pcFramePast; static CalypFrame* pcFramePast;
static CalypStream* pcStreamFuture; static std::unique_ptr<CalypStream> pcStreamFuture;
static CalypFrame* pcFrameFuture; static CalypFrame* pcFrameFuture;
}; };
CalypStream* CalypFrameQualityTest::pcStreamPast = NULL; std::unique_ptr<CalypStream> CalypFrameQualityTest::pcStreamPast{ nullptr };
CalypStream* CalypFrameQualityTest::pcStreamFuture = NULL; std::unique_ptr<CalypStream> CalypFrameQualityTest::pcStreamFuture{ nullptr };
CalypFrame* CalypFrameQualityTest::pcFramePast = NULL; CalypFrame* CalypFrameQualityTest::pcFramePast{ nullptr };
CalypFrame* CalypFrameQualityTest::pcFrameFuture = NULL; CalypFrame* CalypFrameQualityTest::pcFrameFuture{ nullptr };
TEST_F( CalypFrameQualityTest, MSE ) TEST_F( CalypFrameQualityTest, MSE )
{ {
+2 -1
View File
@@ -6,7 +6,7 @@ SET(CALYP_EXTRA_MODULES_DIR
CACHE PATH "Location of extra Calyp modules" CACHE PATH "Location of extra Calyp modules"
) )
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR})
SET(Calyp_Mod_SRCS CalypModulesFactory.cpp) SET(Calyp_Mod_SRCS CalypModulesFactory.cpp)
@@ -70,6 +70,7 @@ ADD_MODULE_USE_OPENCV(SaliencyDetectionFineGrained "SaliencyDetection" VERSION 3
ADD_MODULE_USE_OPENCV(SaliencyDetectionBinWangApr2014 "SaliencyDetection" VERSION 3.3.0 MODULES saliency) ADD_MODULE_USE_OPENCV(SaliencyDetectionBinWangApr2014 "SaliencyDetection" VERSION 3.3.0 MODULES saliency)
ADD_MODULE_USE_OPENCV(FrameResampling "FrameResampling" VERSION 3.3.0 MODULES core) ADD_MODULE_USE_OPENCV(FrameResampling "FrameResampling" VERSION 3.3.0 MODULES core)
ADD_MODULE_USE_OPENCV(SaliencyBasedFiltering "SaliencyBasedFiltering" VERSION 3.1.0 MODULES core)
ADD_MODULE_USE_OPENCV(ThreeSixtySpatialtoTemporal "ThreeSixtySpatialtoTemporal" VERSION 3.1.0 MODULES core) ADD_MODULE_USE_OPENCV(ThreeSixtySpatialtoTemporal "ThreeSixtySpatialtoTemporal" VERSION 3.1.0 MODULES core)
ADD_MODULE_USE_OPENCV(ThreeSixtyFaceExtraction "ThreeSixtyFaceExtraction" VERSION 3.1.0 MODULES core) ADD_MODULE_USE_OPENCV(ThreeSixtyFaceExtraction "ThreeSixtyFaceExtraction" VERSION 3.1.0 MODULES core)
+1 -1
View File
@@ -32,7 +32,7 @@ DisparityStereoSGBM::DisparityStereoSGBM()
m_iModuleType = CLP_FRAME_PROCESSING_MODULE; m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_pchModuleCategory = "Stereo"; m_pchModuleCategory = "Stereo";
m_pchModuleName = "Disparity-SGBM"; m_pchModuleName = "Disparity-SGBM";
m_pchModuleName = "SGBM based disparity"; m_pchModuleLongName = "SGBM based disparity";
m_pchModuleTooltip = "Measure the disparity between two images using the " m_pchModuleTooltip = "Measure the disparity between two images using the "
"Stereo SGBM method (OpenCV)"; "Stereo SGBM method (OpenCV)";
m_uiNumberOfFrames = 2; m_uiNumberOfFrames = 2;
+1 -1
View File
@@ -31,7 +31,7 @@ FrameDifference::FrameDifference()
m_iModuleType = CLP_FRAME_PROCESSING_MODULE; m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_pchModuleCategory = "Measurements"; m_pchModuleCategory = "Measurements";
m_pchModuleName = "FrameDifference"; m_pchModuleName = "FrameDifference";
m_pchModuleName = "Difference"; m_pchModuleLongName = "Difference";
m_pchModuleTooltip = "Measure the difference between two images (Y plane), " m_pchModuleTooltip = "Measure the difference between two images (Y plane), "
"Y1 - Y2, with max absolute diff of 128"; "Y1 - Y2, with max absolute diff of 128";
m_uiModuleRequirements = CLP_MODULE_REQUIRES_NEW_WINDOW | CLP_MODULE_REQUIRES_OPTIONS; m_uiModuleRequirements = CLP_MODULE_REQUIRES_NEW_WINDOW | CLP_MODULE_REQUIRES_OPTIONS;
+6 -8
View File
@@ -80,26 +80,24 @@ bool FrameResampling::create( std::vector<CalypFrame*> apcFrameList )
{ {
m_iHeight = apcFrameList[0]->getHeight() * double( m_iWidth ) / double( apcFrameList[0]->getWidth() ); m_iHeight = apcFrameList[0]->getHeight() * double( m_iWidth ) / double( apcFrameList[0]->getWidth() );
} }
m_pcOutputFrame = new CalypFrame( m_iWidth, m_iHeight, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() ); m_resamplingFrame = std::make_unique<CalypFrame>( m_iWidth, m_iHeight, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() );
return m_pcOutputFrame; return true;
} }
CalypFrame* FrameResampling::process( std::vector<CalypFrame*> apcFrameList ) CalypFrame* FrameResampling::process( std::vector<CalypFrame*> apcFrameList )
{ {
m_pcOutputFrame->reset(); m_resamplingFrame->reset();
for( unsigned ch = 0; ch < apcFrameList[0]->getNumberChannels(); ch++ ) for( unsigned ch = 0; ch < apcFrameList[0]->getNumberChannels(); ch++ )
{ {
Mat inputFrame, outputFrame; Mat inputFrame, outputFrame;
cv::Size outSize( m_pcOutputFrame->getWidth( ch ), m_pcOutputFrame->getHeight( ch ) ); cv::Size outSize( m_resamplingFrame->getWidth( ch ), m_resamplingFrame->getHeight( ch ) );
apcFrameList[0]->toMat( inputFrame, true, false, ch ); apcFrameList[0]->toMat( inputFrame, true, false, ch );
cv::resize( inputFrame, outputFrame, outSize, 0, 0, m_iInterpolation ); cv::resize( inputFrame, outputFrame, outSize, 0, 0, m_iInterpolation );
m_pcOutputFrame->fromMat( outputFrame, ch ); m_resamplingFrame->fromMat( outputFrame, ch );
} }
return m_pcOutputFrame; return m_resamplingFrame.get();
} }
void FrameResampling::destroy() void FrameResampling::destroy()
{ {
if( m_pcOutputFrame )
delete m_pcOutputFrame;
} }
+1
View File
@@ -43,6 +43,7 @@ private:
int m_iWidth; int m_iWidth;
int m_iHeight; int m_iHeight;
int m_iInterpolation; int m_iInterpolation;
std::unique_ptr<CalypFrame> m_resamplingFrame;
public: public:
FrameResampling(); FrameResampling();
+2 -4
View File
@@ -26,8 +26,6 @@
#include <cassert> #include <cassert>
#include "lib/LibMemory.h"
HEVCIntraPrediction::HEVCIntraPrediction() HEVCIntraPrediction::HEVCIntraPrediction()
{ {
/* Module Definition */ /* Module Definition */
@@ -201,9 +199,9 @@ bool HEVCIntraPrediction::keyPressed( enum Module_Key_Supported value )
return false; return false;
} }
ClpString HEVCIntraPrediction::moduleInfo() std::string HEVCIntraPrediction::moduleInfo()
{ {
return ClpString( "Intra mode: " ) + std::to_string( m_uiMode ); return std::string( "Intra mode: " ) + std::to_string( m_uiMode );
} }
void HEVCIntraPrediction::destroy() void HEVCIntraPrediction::destroy()
+1 -1
View File
@@ -47,7 +47,7 @@ public:
bool create( std::vector<CalypFrame*> apcFrameList ); bool create( std::vector<CalypFrame*> apcFrameList );
CalypFrame* process( std::vector<CalypFrame*> apcFrameList ); CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
bool keyPressed( enum Module_Key_Supported value ); bool keyPressed( enum Module_Key_Supported value );
ClpString moduleInfo(); std::string moduleInfo();
void destroy(); void destroy();
}; };
+2 -6
View File
@@ -24,8 +24,6 @@
#include "InterFrameVariance.h" #include "InterFrameVariance.h"
#include "lib/LibMemory.h"
InterFrameVariance::InterFrameVariance() InterFrameVariance::InterFrameVariance()
{ {
/* Module Definition */ /* Module Definition */
@@ -56,7 +54,8 @@ bool InterFrameVariance::create( std::vector<CalypFrame*> apcFrameList )
m_pcFrameVariance = m_pcFrameVariance =
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY, 8 ); new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY, 8 );
getMem2D( &m_pVariance, apcFrameList[0]->getHeight(), apcFrameList[0]->getWidth() );
m_pVariance = CalypPlane<double>{ apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight() };
return true; return true;
} }
@@ -105,9 +104,6 @@ CalypFrame* InterFrameVariance::process( std::vector<CalypFrame*> apcFrameList )
void InterFrameVariance::destroy() void InterFrameVariance::destroy()
{ {
if( m_pVariance )
freeMem2D( m_pVariance );
m_pVariance = NULL;
if( m_pcFrameVariance ) if( m_pcFrameVariance )
delete m_pcFrameVariance; delete m_pcFrameVariance;
m_pcFrameVariance = NULL; m_pcFrameVariance = NULL;
+1 -1
View File
@@ -34,7 +34,7 @@ class InterFrameVariance : public CalypModuleIf
private: private:
CalypFrame* m_pcFrameVariance; CalypFrame* m_pcFrameVariance;
double** m_pVariance; CalypPlane<double> m_pVariance;
public: public:
InterFrameVariance(); InterFrameVariance();
+6 -10
View File
@@ -27,8 +27,6 @@
#include <cmath> #include <cmath>
#include "lib/LibMemory.h"
OptimiseDisplay::OptimiseDisplay() OptimiseDisplay::OptimiseDisplay()
{ {
/* Module Definition */ /* Module Definition */
@@ -53,11 +51,11 @@ bool OptimiseDisplay::create( std::vector<CalypFrame*> apcFrameList )
{ {
_BASIC_MODULE_API_2_CHECK_ _BASIC_MODULE_API_2_CHECK_
m_pcOptimisedFrame = new CalypFrame{ apcFrameList[0]->getWidth(), m_pcOptimisedFrame = std::make_unique<CalypFrame>( apcFrameList[0]->getWidth(),
apcFrameList[0]->getHeight(), apcFrameList[0]->getHeight(),
apcFrameList[0]->getPelFormat(), apcFrameList[0]->getPelFormat(),
apcFrameList[0]->getBitsPel(), apcFrameList[0]->getBitsPel(),
apcFrameList[0]->getHasNegativeValues() }; apcFrameList[0]->getHasNegativeValues() );
m_pcOptimisedFrame->reset(); m_pcOptimisedFrame->reset();
return true; return true;
@@ -95,11 +93,9 @@ CalypFrame* OptimiseDisplay::process( std::vector<CalypFrame*> apcFrameList )
} }
} }
} }
return m_pcOptimisedFrame; return m_pcOptimisedFrame.get();
} }
void OptimiseDisplay::destroy() void OptimiseDisplay::destroy()
{ {
delete m_pcOptimisedFrame;
m_pcOptimisedFrame = nullptr;
} }
+4 -4
View File
@@ -34,14 +34,14 @@ class OptimiseDisplay : public CalypModuleIf
REGISTER_CLASS_FACTORY( OptimiseDisplay ) REGISTER_CLASS_FACTORY( OptimiseDisplay )
private: private:
CalypFrame* m_pcOptimisedFrame; std::unique_ptr<CalypFrame> m_pcOptimisedFrame;
public: public:
OptimiseDisplay(); OptimiseDisplay();
virtual ~OptimiseDisplay() {} virtual ~OptimiseDisplay() {}
bool create( std::vector<CalypFrame*> apcFrameList ); bool create( std::vector<CalypFrame*> apcFrameList ) final;
CalypFrame* process( std::vector<CalypFrame*> apcFrameList ); CalypFrame* process( std::vector<CalypFrame*> apcFrameList ) final;
void destroy(); void destroy() final;
}; };
#endif // __OPTIMISEDISPLAY_H__ #endif // __OPTIMISEDISPLAY_H__
+45 -40
View File
@@ -32,55 +32,62 @@
SaliencyBasedFiltering::SaliencyBasedFiltering() SaliencyBasedFiltering::SaliencyBasedFiltering()
{ {
/* Module Definition */ /* Module Definition */
m_iModuleAPI = MODULE_API_2; m_iModuleAPI = CLP_MODULE_API_2;
m_iModuleType = FRAME_PROCESSING_MODULE; m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_pchModuleCategory = "Quality"; m_pchModuleCategory = "Quality";
m_pchModuleName = "SaliencyBasedFiltering"; m_pchModuleName = "SaliencyBasedFiltering";
m_pchModuleLongName = "Saliency Based Filtering";
m_pchModuleTooltip = "Image filter based on a map"; m_pchModuleTooltip = "Image filter based on a map";
m_uiModuleRequirements = MODULE_REQUIRES_NOTHING; m_uiModuleRequirements = CLP_MODULE_REQUIRES_NOTHING;
m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES; m_uiNumberOfFrames = 2;
m_pcProcessedFrame = NULL; m_pcProcessedFrame = NULL;
} }
Bool SaliencyBasedFiltering::create( std::vector<PlaYUVerFrame*> apcFrameList ) bool SaliencyBasedFiltering::create( std::vector<CalypFrame*> apcFrameList )
{ {
_BASIC_MODULE_API_2_CHECK_ _BASIC_MODULE_API_2_CHECK_
for( UInt i = 0; i < apcFrameList.size(); i++ ) for( unsigned i = 0; i < apcFrameList.size(); i++ )
{ {
if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], PlaYUVerFrame::MATCH_RESOLUTION ) ) if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_RESOLUTION ) )
return false; return false;
} }
if( apcFrameList[1]->getNumberChannels() != 1 ) if( apcFrameList[1]->getNumberChannels() != 1 )
{ {
return false; return false;
} }
m_pcProcessedFrame = new PlaYUVerFrame( apcFrameList[0] );
m_pcProcessedFrame = std::make_unique<CalypFrame>( apcFrameList[0]->getWidth(),
apcFrameList[0]->getHeight(),
apcFrameList[0]->getPelFormat(),
apcFrameList[0]->getBitsPel(),
apcFrameList[0]->getHasNegativeValues() );
return true; return true;
} }
static cv::Mat* getCvFrame( Pel* pInputPel, UInt uiWidth, UInt uiHeight ) static cv::Mat* getCvFrame( ClpPel* pInputPel, unsigned uiWidth, unsigned uiHeight )
{ {
cv::Mat* cvInput = new cv::Mat( uiHeight, uiWidth, CV_MAKETYPE( CV_8U, 1 ) ); cv::Mat* cvInput = new cv::Mat( uiHeight, uiWidth, CV_MAKETYPE( CV_8U, 1 ) );
UChar* pCvPel = cvInput->data; unsigned char* pCvPel = cvInput->data;
for( UInt i = 0; i < uiWidth * uiHeight; i++ ) for( unsigned i = 0; i < uiWidth * uiHeight; i++ )
{ {
*pCvPel++ = *pInputPel++; *pCvPel++ = *pInputPel++;
} }
return cvInput; return cvInput;
} }
static cv::Mat* filterframe( cv::Mat* cvFrame, UInt kernelSize ) static cv::Mat* filterframe( cv::Mat* cvFrame, unsigned kernelSize )
{ {
cv::Mat* cvFiltered = new cv::Mat( cvFrame->rows, cvFrame->cols, CV_MAKETYPE( CV_8U, 1 ) ); cv::Mat* cvFiltered = new cv::Mat( cvFrame->rows, cvFrame->cols, CV_MAKETYPE( CV_8U, 1 ) );
/// Initialize arguments for the filter /// Initialize arguments for the filter
cv::Point anchor = cv::Point( -1, -1 ); cv::Point anchor = cv::Point( -1, -1 );
Double delta = 0; double delta = 0;
Int ddepth = -1; int ddepth = -1;
/// Update kernel size for a normalized box filter /// Update kernel size for a normalized box filter
cv::Mat kernel = cv::Mat::ones( kernelSize, kernelSize, CV_32F ) / (Double)( kernelSize * kernelSize ); cv::Mat kernel = cv::Mat::ones( kernelSize, kernelSize, CV_32F ) / static_cast<double>( kernelSize * kernelSize );
/// Apply filter /// Apply filter
cv::filter2D( *cvFrame, *cvFiltered, ddepth, kernel, anchor, delta, cv::BORDER_DEFAULT ); cv::filter2D( *cvFrame, *cvFiltered, ddepth, kernel, anchor, delta, cv::BORDER_DEFAULT );
@@ -88,44 +95,42 @@ static cv::Mat* filterframe( cv::Mat* cvFrame, UInt kernelSize )
return cvFiltered; return cvFiltered;
} }
static void filterComponent( PlaYUVerFrame* pInput, PlaYUVerFrame* pOutput, PlaYUVerFrame* Map, UInt uiComp ) static void filterComponent( CalypFrame* pInput, CalypFrame* pOutput, CalypFrame* Map, unsigned uiComp )
{ {
Pel* pMapPel = Map->getPelBufferYUV()[0][0]; ClpPel* pMapPel = Map->getPelBufferYUV()[0][0];
Int iMapStep = 1; int iMapStep = 1;
Pel* pInputPel = pInput->getPelBufferYUV()[uiComp][0]; ClpPel* pInputPel = pInput->getPelBufferYUV()[uiComp][0];
Pel* pOutputPel = pOutput->getPelBufferYUV()[uiComp][0]; ClpPel* pOutputPel = pOutput->getPelBufferYUV()[uiComp][0];
Int iHeight = pInput->getHeight(); std::int64_t iHeight = pInput->getHeight( uiComp );
Int iWidth = pInput->getWidth(); std::int64_t iWidth = pInput->getWidth( uiComp );
if( uiComp > 0 ) if( uiComp > 0 )
{ {
iHeight = pInput->getChromaHeight();
iWidth = pInput->getChromaWidth();
iMapStep = 2; iMapStep = 2;
} }
cv::Mat* cvInput = getCvFrame( pInputPel, iWidth, iHeight ); cv::Mat* cvInput = getCvFrame( pInputPel, iWidth, iHeight );
UInt numberFilters = 1; unsigned numberFilters = 1;
UChar* pCvPel[3]; unsigned char* pCvPel[3];
cv::Mat* cvOutput[3]; cv::Mat* cvOutput[3];
for( UInt i = 0; i < numberFilters; i++ ) for( unsigned i = 0; i < numberFilters; i++ )
{ {
cvOutput[i] = filterframe( cvInput, ( 1 << ( 2 * i + 7 ) ) + 1 ); cvOutput[i] = filterframe( cvInput, ( 1 << ( 2 * i + 7 ) ) + 1 );
pCvPel[i] = cvOutput[i]->data; pCvPel[i] = cvOutput[i]->data;
} }
Int iCheckNeighbour = 8; int iCheckNeighbour = 8;
UInt uiRelevance = 0; unsigned uiRelevance = 0;
for( Int y = 0; y < iHeight; y++ ) for( int y = 0; y < iHeight; y++ )
{ {
for( Int x = 0; x < iWidth; x++ ) for( int x = 0; x < iWidth; x++ )
{ {
uiRelevance = 0; uiRelevance = 0;
// uiRelevance = *pMapPel; // uiRelevance = *pMapPel;
for( Int j = CLAMP_RANGE( y - iCheckNeighbour, 0, iHeight ); j < CLAMP_RANGE( y + iCheckNeighbour + 1, 0, iHeight ); j++ ) for( std::int64_t j = CLAMP_RANGE( y - iCheckNeighbour, 0, iHeight ); j < CLAMP_RANGE( y + iCheckNeighbour + 1, 0, iHeight ); j++ )
{ {
for( Int i = CLAMP_RANGE( x - iCheckNeighbour, 0, iWidth ); i < CLAMP_RANGE( x + iCheckNeighbour + 1, 0, iWidth ); i++ ) for( std::int64_t i = CLAMP_RANGE( x - iCheckNeighbour, 0, iWidth ); i < CLAMP_RANGE( x + iCheckNeighbour + 1, 0, iWidth ); i++ )
{ {
uiRelevance += *( pMapPel + ( ( j - y ) * iWidth ) + ( i - x ) ); uiRelevance += *( pMapPel + ( ( j - y ) * iWidth ) + ( i - x ) );
} }
@@ -141,7 +146,7 @@ static void filterComponent( PlaYUVerFrame* pInput, PlaYUVerFrame* pOutput, PlaY
//*pOutputPel = 0; //*pOutputPel = 0;
} }
for( UInt i = 0; i < numberFilters; i++ ) for( unsigned i = 0; i < numberFilters; i++ )
pCvPel[i]++; pCvPel[i]++;
pInputPel++; pInputPel++;
pOutputPel++; pOutputPel++;
@@ -151,16 +156,16 @@ static void filterComponent( PlaYUVerFrame* pInput, PlaYUVerFrame* pOutput, PlaY
} }
} }
PlaYUVerFrame* SaliencyBasedFiltering::process( std::vector<PlaYUVerFrame*> apcFrameList ) CalypFrame* SaliencyBasedFiltering::process( std::vector<CalypFrame*> apcFrameList )
{ {
PlaYUVerFrame* pcInputFrame = apcFrameList[0]; CalypFrame* pcInputFrame = apcFrameList[0];
for( UInt c = 0; c < pcInputFrame->getNumberChannels(); c++ ) for( unsigned c = 0; c < pcInputFrame->getNumberChannels(); c++ )
filterComponent( pcInputFrame, m_pcProcessedFrame, apcFrameList[1], c ); filterComponent( pcInputFrame, m_pcProcessedFrame.get(), apcFrameList[1], c );
return m_pcProcessedFrame; return m_pcProcessedFrame.get();
} }
Void SaliencyBasedFiltering::destroy() void SaliencyBasedFiltering::destroy()
{ {
} }
+7 -11
View File
@@ -24,25 +24,21 @@
#ifndef __SALIENCYBASEDFILTERING_H__ #ifndef __SALIENCYBASEDFILTERING_H__
#define __SALIENCYBASEDFILTERING_H__ #define __SALIENCYBASEDFILTERING_H__
#include <cassert> #include "lib/CalypModuleIf.h"
#include "lib/PlaYUVerModuleIf.h" class SaliencyBasedFiltering : public CalypModuleIf
class SaliencyBasedFiltering : public PlaYUVerModuleIf
{ {
REGISTER_CLASS_FACTORY( SaliencyBasedFiltering ) REGISTER_CLASS_FACTORY( SaliencyBasedFiltering )
private: private:
PlaYUVerFrame* m_pcProcessedFrame; std::unique_ptr<CalypFrame> m_pcProcessedFrame;
public: public:
SaliencyBasedFiltering(); SaliencyBasedFiltering();
virtual ~SaliencyBasedFiltering() virtual ~SaliencyBasedFiltering() {}
{ bool create( std::vector<CalypFrame*> apcFrameList );
} CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
Bool create( std::vector<PlaYUVerFrame*> apcFrameList ); void destroy();
PlaYUVerFrame* process( std::vector<PlaYUVerFrame*> apcFrameList );
Void destroy();
}; };
#endif // __SALIENCYBASEDFILTERING_H__ #endif // __SALIENCYBASEDFILTERING_H__
+19 -20
View File
@@ -45,7 +45,6 @@ SaliencyDetectionModule::SaliencyDetectionModule()
void SaliencyDetectionModule::destroy_using_opencv() void SaliencyDetectionModule::destroy_using_opencv()
{ {
delete m_pcvSaliency;
} }
SaliencyDetectionSpectral::SaliencyDetectionSpectral() SaliencyDetectionSpectral::SaliencyDetectionSpectral()
@@ -63,17 +62,17 @@ SaliencyDetectionSpectral::SaliencyDetectionSpectral()
m_bBinaryMap = false; m_bBinaryMap = false;
} }
cv::Mat* SaliencyDetectionSpectral::create_using_opencv( std::vector<Mat*> apcMatList ) cv::Mat* SaliencyDetectionSpectral::create_using_opencv( const std::vector<Mat>& apcMatList )
{ {
m_ptrSaliencyAlgorithm = StaticSaliencySpectralResidual::create(); m_ptrSaliencyAlgorithm = StaticSaliencySpectralResidual::create();
m_pcvSaliency = new Mat( apcMatList[0]->rows, apcMatList[0]->cols, CV_8UC1 ); m_pcvSaliency = std::make_unique<Mat>( apcMatList[0].rows, apcMatList[0].cols, CV_8UC1 );
return m_pcvSaliency; return m_pcvSaliency.get();
} }
Mat* SaliencyDetectionSpectral::process_using_opencv( std::vector<Mat*> apcMatList ) Mat* SaliencyDetectionSpectral::process_using_opencv( const std::vector<Mat>& apcMatList )
{ {
Mat cvSaliency; Mat cvSaliency;
m_ptrSaliencyAlgorithm->computeSaliency( *apcMatList[0], cvSaliency ); m_ptrSaliencyAlgorithm->computeSaliency( apcMatList[0], cvSaliency );
Mat cvBinaryMap; Mat cvBinaryMap;
StaticSaliencySpectralResidual spec; StaticSaliencySpectralResidual spec;
spec.computeBinaryMap( cvSaliency, *m_pcvSaliency ); spec.computeBinaryMap( cvSaliency, *m_pcvSaliency );
@@ -82,7 +81,7 @@ Mat* SaliencyDetectionSpectral::process_using_opencv( std::vector<Mat*> apcMatLi
cvSaliency *= 255; cvSaliency *= 255;
cvSaliency.convertTo( *m_pcvSaliency, CV_8UC1 ); cvSaliency.convertTo( *m_pcvSaliency, CV_8UC1 );
} }
return m_pcvSaliency; return m_pcvSaliency.get();
} }
SaliencyDetectionFineGrained::SaliencyDetectionFineGrained() SaliencyDetectionFineGrained::SaliencyDetectionFineGrained()
@@ -93,17 +92,17 @@ SaliencyDetectionFineGrained::SaliencyDetectionFineGrained()
m_pchModuleTooltip = "Measure saliency using fine grained method"; m_pchModuleTooltip = "Measure saliency using fine grained method";
} }
Mat* SaliencyDetectionFineGrained::create_using_opencv( std::vector<Mat*> apcMatList ) Mat* SaliencyDetectionFineGrained::create_using_opencv( const std::vector<Mat>& apcMatList )
{ {
m_ptrSaliencyAlgorithm = cv::saliency::StaticSaliencyFineGrained::create(); m_ptrSaliencyAlgorithm = cv::saliency::StaticSaliencyFineGrained::create();
m_pcvSaliency = new Mat( apcMatList[0]->rows, apcMatList[0]->cols, CV_8UC1 ); m_pcvSaliency = std::make_unique<Mat>( apcMatList[0].rows, apcMatList[0].cols, CV_8UC1 );
return m_pcvSaliency; return m_pcvSaliency.get();
} }
Mat* SaliencyDetectionFineGrained::process_using_opencv( std::vector<Mat*> apcMatList ) Mat* SaliencyDetectionFineGrained::process_using_opencv( const std::vector<Mat>& apcMatList )
{ {
m_ptrSaliencyAlgorithm->computeSaliency( *apcMatList[0], *m_pcvSaliency ); m_ptrSaliencyAlgorithm->computeSaliency( apcMatList[0], *m_pcvSaliency );
return m_pcvSaliency; return m_pcvSaliency.get();
} }
SaliencyDetectionBinWangApr2014::SaliencyDetectionBinWangApr2014() SaliencyDetectionBinWangApr2014::SaliencyDetectionBinWangApr2014()
@@ -114,22 +113,22 @@ SaliencyDetectionBinWangApr2014::SaliencyDetectionBinWangApr2014()
m_pchModuleTooltip = "Measure saliency using a fast self-tuning background subtraction algorithm"; m_pchModuleTooltip = "Measure saliency using a fast self-tuning background subtraction algorithm";
} }
Mat* SaliencyDetectionBinWangApr2014::create_using_opencv( std::vector<Mat*> apcMatList ) Mat* SaliencyDetectionBinWangApr2014::create_using_opencv( const std::vector<Mat>& apcMatList )
{ {
m_ptrSaliencyAlgorithm = MotionSaliencyBinWangApr2014::create(); m_ptrSaliencyAlgorithm = MotionSaliencyBinWangApr2014::create();
m_ptrSaliencyAlgorithm.dynamicCast<MotionSaliencyBinWangApr2014>()->setImagesize( apcMatList[0]->cols, apcMatList[0]->rows ); m_ptrSaliencyAlgorithm.dynamicCast<MotionSaliencyBinWangApr2014>()->setImagesize( apcMatList[0].cols, apcMatList[0].rows );
m_ptrSaliencyAlgorithm.dynamicCast<MotionSaliencyBinWangApr2014>()->init(); m_ptrSaliencyAlgorithm.dynamicCast<MotionSaliencyBinWangApr2014>()->init();
m_pcvSaliency = new Mat( apcMatList[0]->rows, apcMatList[0]->cols, CV_8UC1 ); m_pcvSaliency = std::make_unique<Mat>( apcMatList[0].rows, apcMatList[0].cols, CV_8UC1 );
return m_pcvSaliency; return m_pcvSaliency.get();
} }
Mat* SaliencyDetectionBinWangApr2014::process_using_opencv( std::vector<Mat*> apcMatList ) Mat* SaliencyDetectionBinWangApr2014::process_using_opencv( const std::vector<Mat>& apcMatList )
{ {
if( m_ptrSaliencyAlgorithm->computeSaliency( *apcMatList[0], *m_pcvSaliency ) ) if( m_ptrSaliencyAlgorithm->computeSaliency( apcMatList[0], *m_pcvSaliency ) )
{ {
*m_pcvSaliency *= 255; *m_pcvSaliency *= 255;
m_pcvSaliency->convertTo( *m_pcvSaliency, CV_8UC1 ); m_pcvSaliency->convertTo( *m_pcvSaliency, CV_8UC1 );
//cv::cvtColor(m_matSaliency, m_matSaliency, cv::COLOR_BGR2GRAY); //cv::cvtColor(m_matSaliency, m_matSaliency, cv::COLOR_BGR2GRAY);
} }
return m_pcvSaliency; return m_pcvSaliency.get();
} }
+16 -10
View File
@@ -26,14 +26,12 @@
#define __SALIENCYDETECTION_H__ #define __SALIENCYDETECTION_H__
// CalypLib // CalypLib
#include "lib/CalypOpenCVModuleIf.h" #include "lib/CalypModuleIf.h"
// OpenCV // OpenCV
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
#include <opencv2/saliency.hpp> #include <opencv2/saliency.hpp>
using cv::Mat;
/** /**
* \ingroup Calyp_Modules * \ingroup Calyp_Modules
* @defgroup Calyp_Modules_Saliency Saliency * @defgroup Calyp_Modules_Saliency Saliency
@@ -44,8 +42,10 @@ using cv::Mat;
class SaliencyDetectionModule : public CalypOpenCVModuleIf class SaliencyDetectionModule : public CalypOpenCVModuleIf
{ {
using Mat = cv::Mat;
protected: protected:
Mat* m_pcvSaliency; std::unique_ptr<Mat> m_pcvSaliency;
cv::Ptr<cv::saliency::Saliency> m_ptrSaliencyAlgorithm; cv::Ptr<cv::saliency::Saliency> m_ptrSaliencyAlgorithm;
public: public:
@@ -68,6 +68,8 @@ public:
*/ */
class SaliencyDetectionSpectral : public SaliencyDetectionModule class SaliencyDetectionSpectral : public SaliencyDetectionModule
{ {
using Mat = cv::Mat;
REGISTER_CLASS_FACTORY( SaliencyDetectionSpectral ) REGISTER_CLASS_FACTORY( SaliencyDetectionSpectral )
private: private:
bool m_bBinaryMap; bool m_bBinaryMap;
@@ -75,8 +77,8 @@ private:
public: public:
SaliencyDetectionSpectral(); SaliencyDetectionSpectral();
virtual ~SaliencyDetectionSpectral() {} virtual ~SaliencyDetectionSpectral() {}
Mat* create_using_opencv( std::vector<Mat*> apcMatList ); Mat* create_using_opencv( const std::vector<Mat>& apcMatList ) override;
Mat* process_using_opencv( std::vector<Mat*> apcMatList ); Mat* process_using_opencv( const std::vector<Mat>& apcMatList ) override;
}; };
/** /**
@@ -91,12 +93,14 @@ public:
*/ */
class SaliencyDetectionFineGrained : public SaliencyDetectionModule class SaliencyDetectionFineGrained : public SaliencyDetectionModule
{ {
using Mat = cv::Mat;
REGISTER_CLASS_FACTORY( SaliencyDetectionFineGrained ) REGISTER_CLASS_FACTORY( SaliencyDetectionFineGrained )
public: public:
SaliencyDetectionFineGrained(); SaliencyDetectionFineGrained();
virtual ~SaliencyDetectionFineGrained() {} virtual ~SaliencyDetectionFineGrained() {}
Mat* create_using_opencv( std::vector<Mat*> apcMatList ); Mat* create_using_opencv( const std::vector<Mat>& apcMatList ) override;
Mat* process_using_opencv( std::vector<Mat*> apcMatList ); Mat* process_using_opencv( const std::vector<Mat>& apcMatList ) override;
}; };
/** /**
@@ -108,12 +112,14 @@ public:
*/ */
class SaliencyDetectionBinWangApr2014 : public SaliencyDetectionModule class SaliencyDetectionBinWangApr2014 : public SaliencyDetectionModule
{ {
using Mat = cv::Mat;
REGISTER_CLASS_FACTORY( SaliencyDetectionBinWangApr2014 ) REGISTER_CLASS_FACTORY( SaliencyDetectionBinWangApr2014 )
public: public:
SaliencyDetectionBinWangApr2014(); SaliencyDetectionBinWangApr2014();
virtual ~SaliencyDetectionBinWangApr2014() {} virtual ~SaliencyDetectionBinWangApr2014() {}
Mat* create_using_opencv( std::vector<Mat*> apcMatList ); Mat* create_using_opencv( const std::vector<Mat>& apcMatList ) override;
Mat* process_using_opencv( std::vector<Mat*> apcMatList ); Mat* process_using_opencv( const std::vector<Mat>& apcMatList ) override;
}; };
#endif // __SALIENCYDETECTION_H__ #endif // __SALIENCYDETECTION_H__
+26 -26
View File
@@ -75,7 +75,7 @@ ThreeSixtyDownsampling::ThreeSixtyDownsampling()
m_bForceIntSlope = 0; m_bForceIntSlope = 0;
m_iRearrange = 0; m_iRearrange = 0;
m_iWidth = -1; m_iWidth = -1;
m_pcOutputFrame = NULL; m_pcResultedFrame = NULL;
m_pcDownsampled = NULL; m_pcDownsampled = NULL;
m_dPixelRatio = 0; m_dPixelRatio = 0;
@@ -88,9 +88,9 @@ ThreeSixtyDownsampling::ThreeSixtyDownsampling()
//#endif //#endif
} }
ClpString ThreeSixtyDownsampling::moduleInfo() std::string ThreeSixtyDownsampling::moduleInfo()
{ {
ClpString info( "" ); std::string info( "" );
info += "Interpolation: "; info += "Interpolation: ";
switch( m_iInterpolation ) switch( m_iInterpolation )
{ {
@@ -589,17 +589,17 @@ bool ThreeSixtyDownsampling::createDownsamplingMask( CalypFrame* pcInputFrame )
switch( m_uiDownsampling ) switch( m_uiDownsampling )
{ {
case 0: case 0:
m_pcOutputFrame = new CalypFrame( m_pcDownsampled->getWidth(), m_pcDownsampled->getHeight(), pcInputFrame->getPelFormat(), pcInputFrame->getBitsPel() ); m_pcResultedFrame = new CalypFrame( m_pcDownsampled->getWidth(), m_pcDownsampled->getHeight(), pcInputFrame->getPelFormat(), pcInputFrame->getBitsPel() );
break; break;
case 1: case 1:
m_pcOutputFrame = new CalypFrame( m_cvReshapePoints[0]->cols, m_cvReshapePoints[0]->rows, pcInputFrame->getPelFormat(), pcInputFrame->getBitsPel() ); m_pcResultedFrame = new CalypFrame( m_cvReshapePoints[0]->cols, m_cvReshapePoints[0]->rows, pcInputFrame->getPelFormat(), pcInputFrame->getBitsPel() );
break; break;
case 2: case 2:
m_pcOutputFrame = new CalypFrame{ pcInputFrame->getWidth(), m_pcResultedFrame = new CalypFrame{ pcInputFrame->getWidth(),
pcInputFrame->getHeight(), pcInputFrame->getHeight(),
pcInputFrame->getPelFormat(), pcInputFrame->getPelFormat(),
pcInputFrame->getBitsPel(), pcInputFrame->getBitsPel(),
pcInputFrame->getHasNegativeValues() }; pcInputFrame->getHasNegativeValues() };
break; break;
} }
return true; return true;
@@ -609,7 +609,7 @@ void ThreeSixtyDownsampling::downsamplingOperation( CalypFrame* pcInputFrame )
{ {
unsigned numBytes = m_pcDownsampled->getBitsPel() > 8 ? 2 : 1; unsigned numBytes = m_pcDownsampled->getBitsPel() > 8 ? 2 : 1;
m_pcDownsampled->reset(); m_pcDownsampled->reset();
m_pcOutputFrame->reset(); m_pcResultedFrame->reset();
for( unsigned ch = 0; ch < m_pcDownsampled->getNumberChannels(); ch++ ) for( unsigned ch = 0; ch < m_pcDownsampled->getNumberChannels(); ch++ )
{ {
int imH = int( m_pcDownsampled->getHeight( ch ) ); int imH = int( m_pcDownsampled->getHeight( ch ) );
@@ -640,12 +640,12 @@ void ThreeSixtyDownsampling::downsamplingOperation( CalypFrame* pcInputFrame )
} }
Mat_<Point> reshapePoints = *( m_cvReshapePoints[ch] ); Mat_<Point> reshapePoints = *( m_cvReshapePoints[ch] );
ClpPel** downSampPelBuff = m_pcDownsampled->getPelBufferYUV()[ch]; ClpPel** downSampPelBuff = m_pcDownsampled->getPelBufferYUV()[ch];
ClpPel* pelOutputPtr = m_pcOutputFrame->getPelBufferYUV()[ch][0]; ClpPel* pelOutputPtr = m_pcResultedFrame->getPelBufferYUV()[ch][0];
Mat outputMask( m_pcOutputFrame->getHeight( ch ), m_pcOutputFrame->getWidth( ch ), CV_8UC1, Scalar( 1 ) ); Mat outputMask( m_pcResultedFrame->getHeight( ch ), m_pcResultedFrame->getWidth( ch ), CV_8UC1, Scalar( 1 ) );
for( unsigned y = 0; y < m_pcOutputFrame->getHeight( ch ); y++ ) for( unsigned y = 0; y < m_pcResultedFrame->getHeight( ch ); y++ )
{ {
for( unsigned x = 0; x < m_pcOutputFrame->getWidth( ch ); x++ ) for( unsigned x = 0; x < m_pcResultedFrame->getWidth( ch ); x++ )
{ {
Point pt = reshapePoints.at<Point>( y, x ); Point pt = reshapePoints.at<Point>( y, x );
if( pt.x > -1 ) if( pt.x > -1 )
@@ -659,9 +659,9 @@ void ThreeSixtyDownsampling::downsamplingOperation( CalypFrame* pcInputFrame )
if( m_iInpaintMethod ) if( m_iInpaintMethod )
{ {
Mat outputFrameUnfilled, outputFrame; Mat outputFrameUnfilled, outputFrame;
m_pcOutputFrame->toMat( outputFrameUnfilled, true, false, ch ); m_pcResultedFrame->toMat( outputFrameUnfilled, true, false, ch );
cv::inpaint( outputFrameUnfilled, outputMask, outputFrame, 16, m_iInpaintMethod ); cv::inpaint( outputFrameUnfilled, outputMask, outputFrame, 16, m_iInpaintMethod );
m_pcOutputFrame->fromMat( outputFrame, ch ); m_pcResultedFrame->fromMat( outputFrame, ch );
} }
} }
} }
@@ -670,7 +670,7 @@ void ThreeSixtyDownsampling::upsamplingOperation( CalypFrame* pcInputFrame )
{ {
unsigned numBytes = m_pcDownsampled->getBitsPel() > 8 ? 2 : 1; unsigned numBytes = m_pcDownsampled->getBitsPel() > 8 ? 2 : 1;
m_pcDownsampled->reset(); m_pcDownsampled->reset();
m_pcOutputFrame->reset(); m_pcResultedFrame->reset();
for( unsigned ch = 0; ch < m_pcDownsampled->getNumberChannels(); ch++ ) for( unsigned ch = 0; ch < m_pcDownsampled->getNumberChannels(); ch++ )
{ {
Mat_<Point> reshapePoints = *( m_cvReshapePoints[ch] ); Mat_<Point> reshapePoints = *( m_cvReshapePoints[ch] );
@@ -689,7 +689,7 @@ void ThreeSixtyDownsampling::upsamplingOperation( CalypFrame* pcInputFrame )
Mat cvDownsampled; Mat cvDownsampled;
m_pcDownsampled->toMat( cvDownsampled, true, false, ch ); m_pcDownsampled->toMat( cvDownsampled, true, false, ch );
int imH = m_pcOutputFrame->getHeight( ch ); int imH = m_pcResultedFrame->getHeight( ch );
Mat cvUpsample( 1, 2 * imH, numBytes > 2 ? CV_16UC1 : CV_8UC1 ); Mat cvUpsample( 1, 2 * imH, numBytes > 2 ? CV_16UC1 : CV_8UC1 );
for( int y = 0; y < imH; y++ ) for( int y = 0; y < imH; y++ )
{ {
@@ -700,7 +700,7 @@ void ThreeSixtyDownsampling::upsamplingOperation( CalypFrame* pcInputFrame )
cv::resize( cvDownsampled.row( y ).colRange( xpos, xpos + lineWidth ), cvUpsample, cvUpsample.size(), 0, 0, m_iInterpolation ); cv::resize( cvDownsampled.row( y ).colRange( xpos, xpos + lineWidth ), cvUpsample, cvUpsample.size(), 0, 0, m_iInterpolation );
// copy to output // copy to output
ClpPel* outpel = &m_pcOutputFrame->getPelBufferYUV()[ch][y][0]; ClpPel* outpel = &m_pcResultedFrame->getPelBufferYUV()[ch][y][0];
unsigned char* cv_data = cvUpsample.data; unsigned char* cv_data = cvUpsample.data;
for( int i = 0; i < 2 * imH; i++ ) for( int i = 0; i < 2 * imH; i++ )
{ {
@@ -713,7 +713,7 @@ void ThreeSixtyDownsampling::upsamplingOperation( CalypFrame* pcInputFrame )
} }
} }
} }
//m_pcOutputFrame->copyFrom( m_pcDownsampled ); //m_pcResultedFrame->copyFrom( m_pcDownsampled );
} }
CalypFrame* ThreeSixtyDownsampling::process( std::vector<CalypFrame*> apcFrameList ) CalypFrame* ThreeSixtyDownsampling::process( std::vector<CalypFrame*> apcFrameList )
@@ -725,9 +725,9 @@ CalypFrame* ThreeSixtyDownsampling::process( std::vector<CalypFrame*> apcFrameLi
} }
if( m_uiDownsampling == 0 || m_uiDownsampling == 2 ) if( m_uiDownsampling == 0 || m_uiDownsampling == 2 )
{ {
upsamplingOperation( m_uiDownsampling == 2 ? m_pcOutputFrame : apcFrameList[0] ); upsamplingOperation( m_uiDownsampling == 2 ? m_pcResultedFrame : apcFrameList[0] );
} }
return m_pcOutputFrame; return m_pcResultedFrame;
} }
bool ThreeSixtyDownsampling::keyPressed( enum Module_Key_Supported value ) bool ThreeSixtyDownsampling::keyPressed( enum Module_Key_Supported value )
@@ -761,7 +761,7 @@ void ThreeSixtyDownsampling::destroy()
if( m_pcDownsampled ) if( m_pcDownsampled )
delete m_pcDownsampled; delete m_pcDownsampled;
m_pcDownsampled = NULL; m_pcDownsampled = NULL;
if( m_pcOutputFrame ) if( m_pcResultedFrame )
delete m_pcOutputFrame; delete m_pcResultedFrame;
m_pcOutputFrame = NULL; m_pcResultedFrame = NULL;
} }
+2 -1
View File
@@ -52,6 +52,7 @@ private:
double m_dPixelRatio; double m_dPixelRatio;
CalypFrame* m_pcResultedFrame;
CalypFrame* m_pcDownsampled; CalypFrame* m_pcDownsampled;
// Values one per channel // Values one per channel
@@ -67,7 +68,7 @@ public:
virtual ~ThreeSixtyDownsampling() {} virtual ~ThreeSixtyDownsampling() {}
bool create( std::vector<CalypFrame*> apcFrameList ); bool create( std::vector<CalypFrame*> apcFrameList );
CalypFrame* process( std::vector<CalypFrame*> apcFrameList ); CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
ClpString moduleInfo(); std::string moduleInfo();
bool keyPressed( enum Module_Key_Supported value ); bool keyPressed( enum Module_Key_Supported value );
void destroy(); void destroy();
}; };
+1 -1
View File
@@ -59,7 +59,7 @@ ThreeSixtyDynamicDownsampling::ThreeSixtyDynamicDownsampling()
m_uiFaceHeight = 0; m_uiFaceHeight = 0;
} }
void processFPSString( const ClpString& fps, ClpVideoFPStruct* pcFPSStruct ) void processFPSString( const std::string& fps, ClpVideoFPStruct* pcFPSStruct )
{ {
std::istringstream ss( fps ); std::istringstream ss( fps );
ss >> pcFPSStruct->numFaces; ss >> pcFPSStruct->numFaces;
+4 -2
View File
@@ -48,13 +48,15 @@ class ThreeSixtyDynamicDownsampling : public CalypModuleIf
REGISTER_CLASS_FACTORY( ThreeSixtyDynamicDownsampling ) REGISTER_CLASS_FACTORY( ThreeSixtyDynamicDownsampling )
private: private:
ClpString m_arrayInputDefinitionString; std::string m_arrayInputDefinitionString;
ClpString m_arrayOutputDefinitionString; std::string m_arrayOutputDefinitionString;
ClpVideoFPStruct m_cInputFPSStruct; ClpVideoFPStruct m_cInputFPSStruct;
ClpVideoFPStruct m_cOutputFPSStruct; ClpVideoFPStruct m_cOutputFPSStruct;
unsigned m_uiFaceWidth; unsigned m_uiFaceWidth;
unsigned m_uiFaceHeight; unsigned m_uiFaceHeight;
CalypFrame* m_pcOutputFrame;
public: public:
ThreeSixtyDynamicDownsampling(); ThreeSixtyDynamicDownsampling();
virtual ~ThreeSixtyDynamicDownsampling() {} virtual ~ThreeSixtyDynamicDownsampling() {}
+4 -9
View File
@@ -56,8 +56,6 @@ ThreeSixtyFaceConcatenation::ThreeSixtyFaceConcatenation()
m_uiNumberOfPartitionsPerFace = 1; m_uiNumberOfPartitionsPerFace = 1;
m_uiFacesX = 0; m_uiFacesX = 0;
m_uiFacesY = 0; m_uiFacesY = 0;
m_pcTmpFrame = NULL;
} }
bool ThreeSixtyFaceConcatenation::create( std::vector<CalypFrame*> apcFrameList ) bool ThreeSixtyFaceConcatenation::create( std::vector<CalypFrame*> apcFrameList )
@@ -90,14 +88,14 @@ bool ThreeSixtyFaceConcatenation::create( std::vector<CalypFrame*> apcFrameList
unsigned int width = apcFrameList[0]->getWidth() * m_uiFacesX; unsigned int width = apcFrameList[0]->getWidth() * m_uiFacesX;
unsigned int height = apcFrameList[0]->getHeight() * m_uiFacesY; unsigned int height = apcFrameList[0]->getHeight() * m_uiFacesY;
m_pcOutputFrame = new CalypFrame( width, height, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() ); m_pcConcatenatedFaces = std::make_unique<CalypFrame>( width, height, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() );
return true; return true;
} }
CalypFrame* ThreeSixtyFaceConcatenation::process( std::vector<CalypFrame*> apcFrameList ) CalypFrame* ThreeSixtyFaceConcatenation::process( std::vector<CalypFrame*> apcFrameList )
{ {
m_pcOutputFrame->reset(); m_pcConcatenatedFaces->reset();
switch( m_uiProjectionType ) switch( m_uiProjectionType )
{ {
@@ -107,19 +105,16 @@ CalypFrame* ThreeSixtyFaceConcatenation::process( std::vector<CalypFrame*> apcFr
CalypFrame* pcFrame = apcFrameList[i]; CalypFrame* pcFrame = apcFrameList[i];
unsigned x = i % m_uiFacesX * pcFrame->getWidth(); unsigned x = i % m_uiFacesX * pcFrame->getWidth();
unsigned y = i / m_uiFacesX * pcFrame->getHeight(); unsigned y = i / m_uiFacesX * pcFrame->getHeight();
m_pcOutputFrame->copyTo( pcFrame, x, y ); m_pcConcatenatedFaces->copyTo( pcFrame, x, y );
} }
break; break;
default: default:
assert( 0 ); assert( 0 );
} }
return m_pcOutputFrame; return m_pcConcatenatedFaces.get();
} }
void ThreeSixtyFaceConcatenation::destroy() void ThreeSixtyFaceConcatenation::destroy()
{ {
if( m_pcOutputFrame )
delete m_pcOutputFrame;
m_pcOutputFrame = NULL;
} }
+1 -1
View File
@@ -32,7 +32,7 @@ class ThreeSixtyFaceConcatenation : public CalypModuleIf
REGISTER_CLASS_FACTORY( ThreeSixtyFaceConcatenation ) REGISTER_CLASS_FACTORY( ThreeSixtyFaceConcatenation )
private: private:
CalypFrame* m_pcTmpFrame; std::unique_ptr<CalypFrame> m_pcConcatenatedFaces;
unsigned m_uiProjectionType; unsigned m_uiProjectionType;
unsigned m_uiNumberOfPartitionsPerFace; unsigned m_uiNumberOfPartitionsPerFace;
unsigned m_uiFacesX; unsigned m_uiFacesX;
+6 -9
View File
@@ -77,14 +77,14 @@ bool ThreeSixtyFaceExtraction::create( std::vector<CalypFrame*> apcFrameList )
unsigned int width = apcFrameList[0]->getWidth() / m_uiFacesX; unsigned int width = apcFrameList[0]->getWidth() / m_uiFacesX;
unsigned int height = apcFrameList[0]->getHeight() / m_uiFacesY; unsigned int height = apcFrameList[0]->getHeight() / m_uiFacesY;
m_pcOutputFrame = new CalypFrame( width, height, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() ); m_pcFrameExtractionFrame = std::make_unique<CalypFrame>( width, height, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() );
return true; return true;
} }
CalypFrame* ThreeSixtyFaceExtraction::process( std::vector<CalypFrame*> apcFrameList ) CalypFrame* ThreeSixtyFaceExtraction::process( std::vector<CalypFrame*> apcFrameList )
{ {
m_pcOutputFrame->reset(); m_pcFrameExtractionFrame->reset();
unsigned x = -1; unsigned x = -1;
unsigned y = -1; unsigned y = -1;
@@ -92,20 +92,17 @@ CalypFrame* ThreeSixtyFaceExtraction::process( std::vector<CalypFrame*> apcFrame
switch( m_uiProjectionType ) switch( m_uiProjectionType )
{ {
case 1: // Cube-map case 1: // Cube-map
x = m_uiFaceNum % m_uiFacesX * m_pcOutputFrame->getWidth(); x = m_uiFaceNum % m_uiFacesX * m_pcFrameExtractionFrame->getWidth();
y = ( m_uiFaceNum / m_uiFacesX ) * m_pcOutputFrame->getHeight(); y = ( m_uiFaceNum / m_uiFacesX ) * m_pcFrameExtractionFrame->getHeight();
break; break;
default: default:
assert( 0 ); assert( 0 );
} }
m_pcOutputFrame->copyFrom( apcFrameList[0], x, y ); m_pcFrameExtractionFrame->copyFrom( apcFrameList[0], x, y );
return m_pcOutputFrame; return m_pcFrameExtractionFrame.get();
} }
void ThreeSixtyFaceExtraction::destroy() void ThreeSixtyFaceExtraction::destroy()
{ {
if( m_pcOutputFrame )
delete m_pcOutputFrame;
m_pcOutputFrame = NULL;
} }
+2 -1
View File
@@ -32,7 +32,8 @@ class ThreeSixtyFaceExtraction : public CalypModuleIf
REGISTER_CLASS_FACTORY( ThreeSixtyFaceExtraction ) REGISTER_CLASS_FACTORY( ThreeSixtyFaceExtraction )
private: private:
CalypFrame* m_pcTmpFrame; std::unique_ptr<CalypFrame> m_pcFrameExtractionFrame;
std::unique_ptr<CalypFrame> m_pcTmpFrame;
unsigned m_uiFaceNum; unsigned m_uiFaceNum;
unsigned m_uiProjectionType; unsigned m_uiProjectionType;
unsigned m_uiNumberOfPartitionsPerFace; unsigned m_uiNumberOfPartitionsPerFace;
+4 -13
View File
@@ -25,14 +25,10 @@
#include "ThreeSixtyNxN.h" #include "ThreeSixtyNxN.h"
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
#include "lib/LibMemory.h"
//#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp> #include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/photo.hpp> #include <opencv2/photo.hpp>
#include <vector>
//using cv::InputArray;
//using cv::OutputArray;
using cv::Rect; using cv::Rect;
using cv::Scalar; using cv::Scalar;
using cv::Size; using cv::Size;
@@ -147,7 +143,6 @@ void ThreeSixtyNxN::downsamplingOperation( const CalypFrame* pcInputFrame )
ClpPel* in = &pcInputFrame->getPelBufferYUV()[ch][0][0]; ClpPel* in = &pcInputFrame->getPelBufferYUV()[ch][0][0];
ClpPel* out = &m_pcOutputFrame->getPelBufferYUV()[ch][0][0]; ClpPel* out = &m_pcOutputFrame->getPelBufferYUV()[ch][0][0];
unsigned long nn = N * N;
int n_2 = N / 2; int n_2 = N / 2;
int n1 = N - 1; int n1 = N - 1;
double dist_y; double dist_y;
@@ -175,7 +170,6 @@ void ThreeSixtyNxN::downsamplingOperation( const CalypFrame* pcInputFrame )
rx = x + y * N + out; rx = x + y * N + out;
*( rx ) = interpol_lanczos3( tx_y, tx_x, N * 2, max_value ); *( rx ) = interpol_lanczos3( tx_y, tx_x, N * 2, max_value );
//*( rx ) = interpol_cub( tx_y, tx_x, N * 2, max_value );
} }
} }
} }
@@ -202,9 +196,7 @@ void ThreeSixtyNxN::upsamplingOperation( const CalypFrame* pcInputFrame )
double Dj; double Dj;
double tx; double tx;
ClpPel* rx; ClpPel* rx;
ClpPel* linhaY; std::vector<ClpPel> linhaY( n2, 0 );
getMem1D( &linhaY, n2 );
for( y = 0; y < N; y++ ) for( y = 0; y < N; y++ )
{ {
@@ -220,7 +212,7 @@ void ThreeSixtyNxN::upsamplingOperation( const CalypFrame* pcInputFrame )
novo_x = ( dist_x > dist_y ? dist_y : ( dist_x + 1 < -dist_y ? -dist_y - 1 : dist_x ) ) + N / 2; novo_x = ( dist_x > dist_y ? dist_y : ( dist_x + 1 < -dist_y ? -dist_y - 1 : dist_x ) ) + N / 2;
novo_y = abs( dist_x ) > dist_y ? ( y < N / 2 ? dist_Lj : N - dist_Lj - 1 ) : y; novo_y = abs( dist_x ) > dist_y ? ( y < N / 2 ? dist_Lj : N - dist_Lj - 1 ) : y;
*( linhaY + x ) = *( in + (int)novo_x + (int)novo_y * N ); linhaY[x] = *( in + (int)novo_x + (int)novo_y * N );
} }
for( x = 0; x < n2; x++ ) for( x = 0; x < n2; x++ )
@@ -228,10 +220,9 @@ void ThreeSixtyNxN::upsamplingOperation( const CalypFrame* pcInputFrame )
tx = ( x + 1 ) / Dj - 1; tx = ( x + 1 ) / Dj - 1;
rx = x + y * n2 + out; rx = x + y * n2 + out;
*( rx ) = interpol_lanczos3( linhaY, tx, Lj, max_value ); *( rx ) = interpol_lanczos3( linhaY.data(), tx, Lj, max_value );
} }
} }
freeMem1D( linhaY );
} }
} }
+1
View File
@@ -39,6 +39,7 @@ class ThreeSixtyNxN : public CalypModuleIf
REGISTER_CLASS_FACTORY( ThreeSixtyNxN ) REGISTER_CLASS_FACTORY( ThreeSixtyNxN )
private: private:
unsigned m_uiDownsampling; unsigned m_uiDownsampling;
CalypFrame* m_pcOutputFrame;
void downsamplingOperation( const CalypFrame* pcInputFrame ); void downsamplingOperation( const CalypFrame* pcInputFrame );
void upsamplingOperation( const CalypFrame* pcInputFrame ); void upsamplingOperation( const CalypFrame* pcInputFrame );
+19 -26
View File
@@ -75,12 +75,17 @@ bool ThreeSixtySpatialtoTemporal::needFrame()
return false; return false;
} }
CalypFrame* ThreeSixtySpatialtoTemporal::getProcessedFrame()
{
return m_pcTempSpatialFrame != nullptr ? m_pcTempSpatialFrame.get() : nullptr;
}
bool ThreeSixtySpatialtoTemporal::create( std::vector<CalypFrame*> apcFrameList ) bool ThreeSixtySpatialtoTemporal::create( std::vector<CalypFrame*> apcFrameList )
{ {
_BASIC_MODULE_API_2_CHECK_ _BASIC_MODULE_API_2_CHECK_
unsigned int iWidth; unsigned int iWidth{ 0 };
unsigned int iHeight; unsigned int iHeight{ 0 };
if( m_uiSpatial2Temporal ) if( m_uiSpatial2Temporal )
{ {
@@ -93,10 +98,10 @@ bool ThreeSixtySpatialtoTemporal::create( std::vector<CalypFrame*> apcFrameList
iWidth = apcFrameList[0]->getWidth() / m_uiFacesX; iWidth = apcFrameList[0]->getWidth() / m_uiFacesX;
iHeight = apcFrameList[0]->getHeight() / m_uiFacesY; iHeight = apcFrameList[0]->getHeight() / m_uiFacesY;
m_pcTmpInputFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), apcFrameList[0]->getPelFormat(), m_pcTmpInputFrame = std::make_unique<CalypFrame>( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), apcFrameList[0]->getPelFormat(),
apcFrameList[0]->getBitsPel() ); apcFrameList[0]->getBitsPel() );
m_pcTmpFace = new CalypFrame( iWidth, iHeight, apcFrameList[0]->getPelFormat(), m_pcTmpFace = std::make_unique<CalypFrame>( iWidth, iHeight, apcFrameList[0]->getPelFormat(),
apcFrameList[0]->getBitsPel() ); apcFrameList[0]->getBitsPel() );
iWidth *= m_uiFacesPerFrame; iWidth *= m_uiFacesPerFrame;
} }
else else
@@ -104,8 +109,8 @@ bool ThreeSixtySpatialtoTemporal::create( std::vector<CalypFrame*> apcFrameList
iWidth = apcFrameList[0]->getWidth() * m_uiFacesX / m_uiFacesPerFrame; iWidth = apcFrameList[0]->getWidth() * m_uiFacesX / m_uiFacesPerFrame;
iHeight = apcFrameList[0]->getHeight() * m_uiFacesY; iHeight = apcFrameList[0]->getHeight() * m_uiFacesY;
} }
m_pcOutputFrame = new CalypFrame( iWidth, iHeight, apcFrameList[0]->getPelFormat(), m_pcTempSpatialFrame = std::make_unique<CalypFrame>( iWidth, iHeight, apcFrameList[0]->getPelFormat(),
apcFrameList[0]->getBitsPel() ); apcFrameList[0]->getBitsPel() );
return true; return true;
} }
@@ -125,8 +130,8 @@ CalypFrame* ThreeSixtySpatialtoTemporal::process( std::vector<CalypFrame*> apcFr
for( unsigned i = 0; i < m_uiFacesPerFrame; i++ ) for( unsigned i = 0; i < m_uiFacesPerFrame; i++ )
{ {
m_pcTmpFace->copyFrom( m_pcTmpInputFrame, m_uiCopyX, m_uiCopyY ); m_pcTmpFace->copyFrom( *m_pcTmpInputFrame, m_uiCopyX, m_uiCopyY );
m_pcOutputFrame->copyTo( m_pcTmpFace, m_pcTmpFace->getWidth() * i, 0 ); m_pcTempSpatialFrame->copyTo( *m_pcTmpFace, m_pcTmpFace->getWidth() * i, 0 );
m_iFrameBufferCount--; m_iFrameBufferCount--;
m_uiCopyX += m_pcTmpFace->getWidth(); m_uiCopyX += m_pcTmpFace->getWidth();
if( m_uiCopyX >= m_pcTmpInputFrame->getWidth() ) if( m_uiCopyX >= m_pcTmpInputFrame->getWidth() )
@@ -138,40 +143,28 @@ CalypFrame* ThreeSixtySpatialtoTemporal::process( std::vector<CalypFrame*> apcFr
} }
else else
{ {
m_pcOutputFrame->copyTo( apcFrameList[0], m_uiCopyX, m_uiCopyY ); m_pcTempSpatialFrame->copyTo( apcFrameList[0], m_uiCopyX, m_uiCopyY );
m_uiFacesCount += m_uiFacesPerFrame; m_uiFacesCount += m_uiFacesPerFrame;
m_uiCopyX += apcFrameList[0]->getWidth(); m_uiCopyX += apcFrameList[0]->getWidth();
if( m_uiCopyX >= m_pcOutputFrame->getWidth() ) if( m_uiCopyX >= m_pcTempSpatialFrame->getWidth() )
{ {
m_uiCopyX = 0; m_uiCopyX = 0;
m_uiCopyY += apcFrameList[0]->getHeight(); m_uiCopyY += apcFrameList[0]->getHeight();
} }
if( m_uiFacesCount < ( m_uiFacesX * m_uiFacesY ) ) if( m_uiFacesCount < ( m_uiFacesX * m_uiFacesY ) )
{ {
return NULL; return nullptr;
} }
m_iFrameBufferCount = 0; m_iFrameBufferCount = 0;
m_uiCopyX = 0; m_uiCopyX = 0;
m_uiCopyY = 0; m_uiCopyY = 0;
m_uiFacesCount = 0; m_uiFacesCount = 0;
return m_pcOutputFrame;
} }
return m_pcOutputFrame; return m_pcTempSpatialFrame.get();
} }
void ThreeSixtySpatialtoTemporal::destroy() void ThreeSixtySpatialtoTemporal::destroy()
{ {
if( m_pcOutputFrame )
delete m_pcOutputFrame;
m_pcOutputFrame = NULL;
if( m_pcTmpInputFrame )
delete m_pcTmpInputFrame;
m_pcTmpInputFrame = NULL;
if( m_pcTmpFace )
delete m_pcTmpFace;
m_pcTmpFace = NULL;
} }
+9 -7
View File
@@ -33,8 +33,9 @@ class ThreeSixtySpatialtoTemporal : public CalypModuleIf
REGISTER_CLASS_FACTORY( ThreeSixtySpatialtoTemporal ) REGISTER_CLASS_FACTORY( ThreeSixtySpatialtoTemporal )
private: private:
CalypFrame* m_pcTmpInputFrame; std::unique_ptr<CalypFrame> m_pcTempSpatialFrame;
CalypFrame* m_pcTmpFace; std::unique_ptr<CalypFrame> m_pcTmpInputFrame;
std::unique_ptr<CalypFrame> m_pcTmpFace;
bool m_uiSpatial2Temporal; bool m_uiSpatial2Temporal;
unsigned int m_uiFacesX; unsigned int m_uiFacesX;
unsigned int m_uiFacesY; unsigned int m_uiFacesY;
@@ -46,11 +47,12 @@ private:
public: public:
ThreeSixtySpatialtoTemporal(); ThreeSixtySpatialtoTemporal();
virtual ~ThreeSixtySpatialtoTemporal() {} virtual ~ThreeSixtySpatialtoTemporal() {}
bool create( std::vector<CalypFrame*> apcFrameList ); bool create( std::vector<CalypFrame*> apcFrameList ) override;
bool needFrame(); CalypFrame* getProcessedFrame() override;
CalypFrame* process( std::vector<CalypFrame*> apcFrameList ); bool needFrame() override;
bool flush(); CalypFrame* process( std::vector<CalypFrame*> apcFrameList ) override;
void destroy(); bool flush() override;
void destroy() override;
}; };
#endif // __THREESIXTYSPATIALTOTEMPORAL_H__ #endif // __THREESIXTYSPATIALTOTEMPORAL_H__
+9 -11
View File
@@ -36,10 +36,10 @@ protected:
// Can be omitted if not needed. // Can be omitted if not needed.
static void SetUpTestCase() static void SetUpTestCase()
{ {
ClpString moduleName = CALYP_TEST_MODULE_NAME; std::string moduleName = CALYP_TEST_MODULE_NAME;
pcStream = new CalypStream; pcStream = std::make_unique<CalypStream>();
pcStream->open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8, pcStream->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8,
CLP_BIG_ENDIAN, 1, true ); CLP_BIG_ENDIAN, 1, true );
} }
@@ -48,15 +48,13 @@ protected:
// Can be omitted if not needed. // Can be omitted if not needed.
static void TearDownTestCase() static void TearDownTestCase()
{ {
pcStream->close(); pcStream = nullptr;
delete pcStream;
pcStream = NULL;
} }
// Called before each test // Called before each test
void SetUp() void SetUp()
{ {
ClpString moduleName = CALYP_TEST_MODULE_NAME; std::string moduleName = CALYP_TEST_MODULE_NAME;
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin(); CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
@@ -70,18 +68,18 @@ protected:
} }
} }
// Called after each test
void TearDown() void TearDown()
{ {
pcModule->Delete();
} }
CalypModuleIf* pcModule; std::unique_ptr<CalypModuleIf> pcModule;
// Some expensive resource shared by all tests. // Some expensive resource shared by all tests.
static CalypStream* pcStream; static std::unique_ptr<CalypStream> pcStream;
}; };
CalypStream* TestModuleCreate::pcStream = NULL; std::unique_ptr<CalypStream> TestModuleCreate::pcStream{ nullptr };
TEST_F( TestModuleCreate, FIND_MODULE ) TEST_F( TestModuleCreate, FIND_MODULE )
{ {
@@ -36,11 +36,6 @@ protected:
// Can be omitted if not needed. // Can be omitted if not needed.
static void SetUpTestCase() static void SetUpTestCase()
{ {
ClpString moduleName = CALYP_TEST_MODULE_NAME;
pcStream = new CalypStream;
pcStream->open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8,
CLP_BIG_ENDIAN, 1, true );
} }
// Per-test-case tear-down. // Per-test-case tear-down.
@@ -48,18 +43,16 @@ protected:
// Can be omitted if not needed. // Can be omitted if not needed.
static void TearDownTestCase() static void TearDownTestCase()
{ {
pcStream->close(); pcStream = nullptr;
delete pcStream;
pcStream = NULL;
} }
// Called before each test // Called before each test
void SetUp() void SetUp()
{ {
ClpString moduleName = CALYP_TEST_MODULE_NAME; std::string moduleName = CALYP_TEST_MODULE_NAME;
pcStream = new CalypStream; pcStream = std::make_unique<CalypStream>();
pcStream->open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8, pcStream->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8,
CLP_BIG_ENDIAN, 1, true ); CLP_BIG_ENDIAN, 1, true );
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
@@ -76,16 +69,15 @@ protected:
void TearDown() void TearDown()
{ {
pcModule->Delete();
} }
CalypModuleIf* pcModule; std::unique_ptr<CalypModuleIf> pcModule;
// Some expensive resource shared by all tests. // Some expensive resource shared by all tests.
static CalypStream* pcStream; static std::unique_ptr<CalypStream> pcStream;
}; };
CalypStream* TestModuleProcessNumberOfFrames::pcStream = NULL; std::unique_ptr<CalypStream> TestModuleProcessNumberOfFrames::pcStream{ nullptr };
TEST_F( TestModuleProcessNumberOfFrames, PROCESS_OK ) TEST_F( TestModuleProcessNumberOfFrames, PROCESS_OK )
{ {
+1 -1
View File
@@ -2,7 +2,7 @@
# CMakeLists for calyp tools component # CMakeLists for calyp tools component
# #
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..)
SET(Calyp_Tools_SRCS main.cpp CalypTools.cpp CalypToolsCmdParser.cpp) SET(Calyp_Tools_SRCS main.cpp CalypTools.cpp CalypToolsCmdParser.cpp)
+8 -8
View File
@@ -49,7 +49,7 @@ CalypTools::~CalypTools() = default;
#define GET_PARAM( X, i ) X[X.size() > i ? i : X.size() - 1] #define GET_PARAM( X, i ) X[X.size() > i ? i : X.size() - 1]
void CalypTools::reportStreamInfo( const CalypStream* stream, ClpString strPrefix ) void CalypTools::reportStreamInfo( const CalypStream* stream, std::string strPrefix )
{ {
log( CLP_LOG_INFO, "%sStream name: %s \n", strPrefix.c_str(), stream->getFileName().c_str() ); log( CLP_LOG_INFO, "%sStream name: %s \n", strPrefix.c_str(), stream->getFileName().c_str() );
log( CLP_LOG_INFO, "%sResolution: %dx%d@%d \n", strPrefix.c_str(), stream->getWidth(), stream->getHeight(), stream->getFrameRate() ); log( CLP_LOG_INFO, "%sResolution: %dx%d@%d \n", strPrefix.c_str(), stream->getWidth(), stream->getHeight(), stream->getFrameRate() );
@@ -63,10 +63,10 @@ int CalypTools::openInputs()
*/ */
if( Opts().hasOpt( "input" ) ) if( Opts().hasOpt( "input" ) )
{ {
std::vector<ClpString> inputFileNames = m_apcInputs; std::vector<std::string> inputFileNames = m_apcInputs;
ClpString resolutionString( "" ); std::string resolutionString( "" );
ClpString fmtString( "yuv420p" ); std::string fmtString( "yuv420p" );
unsigned int uiBitsPerPixel = 8; unsigned int uiBitsPerPixel = 8;
unsigned int uiEndianness = 0; unsigned int uiEndianness = 0;
bool hasNegativeValues = false; bool hasNegativeValues = false;
@@ -273,7 +273,7 @@ int CalypTools::Open( int argc, char* argv[] )
*/ */
if( Opts().hasOpt( "quality" ) ) if( Opts().hasOpt( "quality" ) )
{ {
ClpString qualityMetric = m_strQualityMetric; std::string qualityMetric = m_strQualityMetric;
if( m_apcInputStreams.size() < 2 ) if( m_apcInputStreams.size() < 2 )
{ {
log( CLP_LOG_ERROR, "Invalid number of inputs! " ); log( CLP_LOG_ERROR, "Invalid number of inputs! " );
@@ -301,7 +301,7 @@ int CalypTools::Open( int argc, char* argv[] )
*/ */
if( Opts().hasOpt( "module" ) ) if( Opts().hasOpt( "module" ) )
{ {
ClpString moduleName = m_strModule; std::string moduleName = m_strModule;
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin(); CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
@@ -359,7 +359,7 @@ int CalypTools::Open( int argc, char* argv[] )
if( m_pcCurrModuleIf->m_iModuleType == CLP_FRAME_PROCESSING_MODULE ) if( m_pcCurrModuleIf->m_iModuleType == CLP_FRAME_PROCESSING_MODULE )
{ {
// Check outputs // Check outputs
std::vector<ClpString> outputFileNames; std::vector<std::string> outputFileNames;
if( Opts().hasOpt( "output" ) ) if( Opts().hasOpt( "output" ) )
outputFileNames.push_back( m_strOutput ); outputFileNames.push_back( m_strOutput );
@@ -488,7 +488,7 @@ int CalypTools::QualityOperation()
double adAverageQuality[MAX_NUMBER_INPUTS - 1][MAX_NUMBER_CHANNELS]; double adAverageQuality[MAX_NUMBER_INPUTS - 1][MAX_NUMBER_CHANNELS];
double dQuality; double dQuality;
ClpString metric_fmt = " "; std::string metric_fmt = " ";
switch( m_uiQualityMetric ) switch( m_uiQualityMetric )
{ {
case CalypFrame::PSNR_METRIC: case CalypFrame::PSNR_METRIC:
+3 -3
View File
@@ -79,12 +79,12 @@ private:
STATISTICS_OPERATION, STATISTICS_OPERATION,
}; };
ClpULong m_uiNumberOfFrames; std::uint64_t m_uiNumberOfFrames;
unsigned int m_uiNumberOfComponents; unsigned int m_uiNumberOfComponents;
std::vector<CalypStream*> m_apcInputStreams; std::vector<CalypStream*> m_apcInputStreams;
std::vector<CalypStream*> m_apcOutputStreams; std::vector<CalypStream*> m_apcOutputStreams;
void reportStreamInfo( const CalypStream* stream, ClpString strPrefix = "" ); void reportStreamInfo( const CalypStream* stream, std::string strPrefix = "" );
int openInputs(); int openInputs();
std::vector<CalypFrame*> readInput(); std::vector<CalypFrame*> readInput();
@@ -92,7 +92,7 @@ private:
FpProcess m_fpProcess; FpProcess m_fpProcess;
long long int m_iFrameNum; long long int m_iFrameNum;
std::vector<ClpString> m_pcOutputFileNames; std::vector<std::string> m_pcOutputFileNames;
int SaveOperation(); int SaveOperation();
int RateReductionOperation(); int RateReductionOperation();
+2 -2
View File
@@ -109,7 +109,7 @@ int CalypToolsCmdParser::parseToolsArgs( int argc, char* argv[] )
void CalypToolsCmdParser::listModuleHelp() void CalypToolsCmdParser::listModuleHelp()
{ {
ClpString moduleName = m_strModule; std::string moduleName = m_strModule;
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap(); CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin(); CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
@@ -154,7 +154,7 @@ void CalypToolsCmdParser::listModules()
printf( "%-33s", it->first ); printf( "%-33s", it->first );
if( bDetailed ) if( bDetailed )
{ {
ClpString ModuleNameString; std::string ModuleNameString;
auto pcCurrModuleIf = it->second(); auto pcCurrModuleIf = it->second();
if( pcCurrModuleIf->m_pchModuleCategory ) if( pcCurrModuleIf->m_pchModuleCategory )
+9 -9
View File
@@ -66,19 +66,19 @@ protected:
bool m_bShowVersion; bool m_bShowVersion;
bool m_bQuiet; bool m_bQuiet;
std::vector<ClpString> m_apcInputs; std::vector<std::string> m_apcInputs;
std::vector<ClpString> m_strResolution; std::vector<std::string> m_strResolution;
std::vector<ClpString> m_strPelFmt; std::vector<std::string> m_strPelFmt;
std::vector<ClpString> m_strBitsPerPixel; std::vector<std::string> m_strBitsPerPixel;
std::vector<ClpString> m_strEndianness; std::vector<std::string> m_strEndianness;
std::vector<ClpString> m_strHasNegativeValues; std::vector<std::string> m_strHasNegativeValues;
ClpString m_strOutput; std::string m_strOutput;
long m_iFrames; long m_iFrames;
unsigned m_uiOutEndianness; unsigned m_uiOutEndianness;
int m_iRateReductionFactor; int m_iRateReductionFactor;
ClpString m_strQualityMetric; std::string m_strQualityMetric;
ClpString m_strModule; std::string m_strModule;
bool m_bListPelFmts; bool m_bListPelFmts;
bool m_bListQuality; bool m_bListQuality;