102 Commits
Author SHA1 Message Date
jfmcarreira 5b4cdddde4 Disable DEBUG_ASSERT 2021-11-28 23:27:33 +00:00
jfmcarreira c43cb2bd0a Version bump 2.1.0 2021-11-28 20:36:33 +00:00
jfmcarreira e6970fb953 Fix windows build 2021-11-28 20:34:41 +00:00
jfmcarreira aac02a9959 Fix missing include 2021-11-28 18:23:05 +00:00
jfmcarreira 500e0e85ba Add macro to protect against the Qt version 2021-11-28 01:46:37 +00:00
jfmcarreira d4886a7fee Fix fetch content to build main product 2021-11-27 23:28:27 +00:00
jfmcarreira f3919ac8e8 Change cmake fetch content 2021-11-27 22:51:58 +00:00
jfmcarreira 562fd915fe Add build checks 2021-11-27 01:04:51 +00:00
jfmcarreira f3df40cdf7 Code cleanup 2021-11-27 00:52:32 +00:00
jfmcarreira 1bb2773abc Add support to filter components to display 2021-11-27 00:45:56 +00:00
jfmcarreira a5e0554286 Tidy up CalypFrame 2021-10-30 20:01:20 +01:00
jfmcarreira dc56de6f30 Fix memory leak in modules tests 2021-10-30 17:53:12 +01:00
jfmcarreira 0cc89ab949 Fix problem creating opencv mat from CalypFrame 2021-10-30 17:49:24 +01:00
jfmcarreira 480a7f1d38 Refactor ClpPixelFormats enum 2021-10-27 23:17:32 +01:00
jfmcarreira bb2a1ac228 Refactor pixel formats enum 2021-10-27 23:07:46 +01:00
jfmcarreira 90a5c32bb6 Fix option errors and add dummy module 2021-10-24 22:18:25 +01:00
jfmcarreira acc9d8ea98 Fix modules errors 2021-10-24 17:55:52 +01:00
jfmcarreira 6f91b6c04f Refactor CalypOption 2021-10-24 17:26:13 +01:00
jfmcarreira b1ca7dff0b Improve safety of class methods 2021-10-24 11:25:22 +01:00
jfmcarreira f5df1b3f9d Refactor code based on lib changes 2021-10-24 00:56:39 +01:00
jfmcarreira bd1bbef22b Fix CalypStream and CalypFrame methods 2021-10-23 23:38:03 +01:00
jfmcarreira 3a9aa5e498 Fix warnings and remove warnings are erros from tests checks 2021-10-20 00:54:10 +01:00
jfmcarreira 5499312fca Fix compilation erros 2021-10-20 00:28:49 +01:00
jfmcarreira 93cf60e34a Improvements on CalypModuleIf
Add type safe flags
Replace MACRO with templates (WIP)
2021-10-19 23:42:18 +01:00
jfmcarreira 09ec5213c3 Fix compilation errors and add new tests 2021-10-15 23:40:41 +01:00
jfmcarreira 26f3dc7612 Fix wrong filename in tests 2021-10-13 00:21:22 +01:00
jfmcarreira 6ce220be82 Check if file exists before running tests 2021-10-13 00:08:33 +01:00
jfmcarreira cc84c42fd4 Checkout LFS content for tests 2021-10-12 23:57:08 +01:00
jfmcarreira 8d2a9e6100 Fix build.yml 2021-10-12 21:10:56 +01:00
jfmcarreira c05aa73e86 Fix github action 2021-10-11 23:25:03 +01:00
jfmcarreira ddc9f40329 Fix repository with test data (fix last commit) 2021-10-11 23:14:10 +01:00
jfmcarreira e87049dccf Fix repository with test data 2021-10-11 23:12:50 +01:00
jfmcarreira 1c1afa7bfc Code clean up and add initial support to run tests in CI enviroment 2021-10-11 23:07:08 +01:00
jfmcarreira 366d69b5c9 Always use RAW format if first try to open file fails 2021-10-10 23:04:39 +01:00
jfmcarreira 26a718a06a Open .raw formats as raw video 2021-10-10 22:26:31 +01:00
jfmcarreira 3b31453221 Add support to signall if the format supports user configuration 2021-10-10 22:25:32 +01:00
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
jfmcarreira 4aebcb979c Version bump 2.0.1 2021-09-26 01:13:24 +01:00
jfmcarreira f8aa92b7fa Remove C++20 methods not available on Windows 2021-09-26 01:11:44 +01:00
jfmcarreira a2f7f10fea Merge remote-tracking branch 'upstream/master' 2021-09-25 17:56:17 +01:00
jfmcarreira 223bd859a9 Version bump 2.0.0 2021-09-25 17:47:18 +01:00
jfmcarreira b148f28dab Update README.md 2021-09-25 17:44:23 +01:00
jfmcarreira b383eff34f Update CI and fix compilation errors on windows 2021-09-25 17:41:16 +01:00
jfmcarreira 1ec77b64c6 Merge remote-tracking branch 'upstream/master' 2021-09-25 17:25:24 +01:00
jfmcarreira 237bc1cc2e CI - Fix cmake config step 2021-09-25 17:20:38 +01:00
jfmcarreira d4913ed2d2 Update build.yml 2021-09-25 17:18:17 +01:00
jfmcarreira 113e86e583 Updata build action 2021-09-25 17:16:29 +01:00
jfmcarreira 9ea9d845c7 Update version CI config and README 2021-09-25 17:02:03 +01:00
jfmcarreira 48afd0be45 Remove the use of QRecursiveMutex 2021-09-22 01:20:01 +01:00
jfmcarreira 1e4de99fba Remove span include 2021-09-22 00:59:13 +01:00
jfmcarreira d446ee7ac1 Fix compiler flags 2021-09-22 00:31:45 +01:00
jfmcarreira 357971c68b Make the use of FetchContent optional 2021-09-21 22:31:08 +01:00
jfmcarreira 6be534d00c Fix warnings 2021-09-21 01:09:37 +01:00
jfmcarreira 437325c96f Clean up some redundant code 2021-09-20 01:51:54 +01:00
jfmcarreira 94444e38ec Refactor modules ownership 2021-09-19 21:50:15 +01:00
jfmcarreira a093efce9c Changes in CalypStream buffers 2021-09-18 16:26:14 +01:00
jfmcarreira de80c85596 Refactor the use of multiple threads for streams 2021-09-12 23:43:11 +01:00
jfmcarreira 9a63a57458 Reset window title when the last subwindow is closed 2021-09-12 14:35:44 +01:00
jfmcarreira 2451494677 Change CalypStream to RAII management with two buffers 2021-09-12 13:01:26 +01:00
jfmcarreira ffe1bf688d Improve the use of threads and sleep when not in use 2021-09-07 02:00:30 +01:00
jfmcarreira bf5235352b Start using resource handler to manage different streams 2021-09-06 22:43:21 +01:00
jfmcarreira 463e1a58b9 Make module instances unique ptrs 2021-09-04 13:57:12 +01:00
jfmcarreira 8ef5b31268 Reduce the use of C-pointers in CalypFrame and CalypStream 2021-07-10 16:28:10 +01:00
jfmcarreira be82c6ca89 Merge remote-tracking branch 'origin/devel' into devel 2021-07-10 12:40:25 +01:00
jfmcarreira 304c0f6683 Fix the module skip while playing 2021-06-10 23:45:09 +01:00
jfmcarreira 83a9decc26 Remove compiler flag exclusively from MacOS 2021-06-10 11:32:20 +01:00
145 changed files with 5498 additions and 3952 deletions

No files matched your search

+6 -6
View File
@@ -1,4 +1,4 @@
image: Visual Studio 2017
image: Visual Studio 2019
configuration: Release
platform:
- x64
@@ -16,7 +16,7 @@ init:
- ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
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 opencv
- 'C:\Tools\opencv\build\setup_vars_opencv4.cmd'
@@ -32,10 +32,10 @@ build_script:
- mv C:\Projects\calyp C:\Projects\calyp-deployment\cmake-helper\
- mkdir 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 --build . --target ALL_BUILD -- /p:Configuration=Release > log_build
- cmake --build . --target INSTALL -- /p:Configuration=Release > log_install
- cmake --build . --target PACKAGE -- /p:Configuration=Release > log_pkg
- 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
- cmake --build . --target INSTALL -- /p:Configuration=Release
- cmake --build . --target PACKAGE -- /p:Configuration=Release
after_build:
- IF "%APPVEYOR_REPO_BRANCH%" == "master" (CALL ..\calyp-deployment\scripts\deploy-to-github.bat)
+45
View File
@@ -0,0 +1,45 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-bounds-constant-array-index, -readability-magic-numbers,-cppcoreguidelines-avoid-magic-numbers'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
CheckOptions:
- key: llvm-else-after-return.WarnOnConditionVariables
value: '0'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons
value: '0'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: '0'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: '1'
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
- key: llvm-qualified-auto.AddConstToQualified
value: '0'
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: llvm-else-after-return.WarnOnUnfixable
value: '0'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: readability-magic-numbers.IgnorePowersOf2IntegerValues
value: '1'
-31
View File
@@ -1,31 +0,0 @@
name: Build and Test
on:
push:
branches:
- devel
jobs:
build:
runs-on: ubuntu-latest
steps:
- 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
- name: Build CMake
uses: ashutoshvarma/action-cmake-build@v1
with:
build-dir: ${{ runner.workspace }}/build
# will set the CC & CXX for cmake
cc: gcc
cxx: g++
build-type: Release
# Extra options pass to cmake while configuring project
configure-options: -DBUILD_TESTS=ON -DUSE_WERROR=ON
run-test: true
#ctest-options: -R mytest
# install the build using cmake --install
install-build: true
# run build using '-j [parallel]' to use multiple threads to build
parallel: 14
+61
View File
@@ -0,0 +1,61 @@
name: Build on Linux
on:
push:
branches:
- master
- devel
pull_request:
branches: [ master ]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
check-build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
steps:
- name: Install dependencies
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
- name: Build with default options
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Build without threads
run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON -DCALYP_MANAGED_RESOURCES=OFF -DCALYP_THREADED_MODULES=OFF; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
check-tests:
runs-on: ubuntu-latest
steps:
- name: Install dependencies
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
- name: Check out tests data
uses: actions/checkout@master
with:
repository: 'pixlra/calyp-testdata'
path: ${{github.workspace}}/tests_data
- 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.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON -DCALYP_TEST_DATA_DIR=${{github.workspace}}/tests_data
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: CalypLib tests
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t test
+4 -1
View File
@@ -1,6 +1,6 @@
# Created by https://www.gitignore.io/api/c++,clion,linux
# Edit at https://www.gitignore.io/?templates=c++,clion,linux
deps/**
### C++ ###
# Prerequisites
*.d
@@ -144,3 +144,6 @@ doc/
# CLang
compile_commands.json
# Build dirs
build*
+1 -1
View File
@@ -1,5 +1,5 @@
language: cpp
dist: xenial
dist: bionic
before_install:
- sudo apt-get -qq update
- sudo apt-get install build-essential cmake qtbase5-dev libavcodec-dev libavformat-dev libavutil-dev libopencv-dev libopencv-video-dev libopencv-contrib-dev libgtest-dev
+74 -41
View File
@@ -17,9 +17,9 @@ SET(PROJECT_LIBRARY
CACHE INTERNAL "" FORCE
)
SET(CALYP_VERSION_MAJOR "1")
SET(CALYP_VERSION_MINOR "2")
SET(CALYP_VERSION_PATCH "1")
SET(CALYP_VERSION_MAJOR "2")
SET(CALYP_VERSION_MINOR "1")
SET(CALYP_VERSION_PATCH "0")
SET(CALYP_VERSION
"${CALYP_VERSION_MAJOR}.${CALYP_VERSION_MINOR}.${CALYP_VERSION_PATCH}"
CACHE INTERNAL "" FORCE
@@ -47,15 +47,17 @@ OPTION(BUILD_APP "Build GUI Application" ON)
OPTION(BUILD_TOOLS "Build Command Line Application" ON)
OPTION(BUILD_EXAMPLES "Build Examples" OFF)
OPTION(BUILD_DOC "Build Documentation" OFF)
OPTION(BUILD_TESTS "Build Google Tests" OFF)
OPTION(BUILD_TESTS_CATCH2 "Build Catch2 Tests" OFF)
OPTION(BUILD_TESTS "Build Tests" OFF)
OPTION(BUILD_WITH_SANITIZERS "Build with sanitizers" OFF)
OPTION(BUILD_WITH_THREAD_SANITIZER "Build with thread sanitizer" OFF)
OPTION(USE_FERVOR "Add Fervor support" OFF)
OPTION(USE_DYNLOAD "Use dynamic load of modules" ON)
OPTION(USE_SSE "Build with SSE support" OFF)
OPTION(USE_SSE "Build with SSE support" ON)
OPTION(USE_WERROR "Warnings as errors" OFF)
OPTION(USE_STATIC "Use static libs" OFF)
OPTION(USE_IWYU "Use include what you use tool" OFF)
# ####################################################################################################################################################
# Release configuration
@@ -100,7 +102,11 @@ SET(UPDATE_CHANNEL
# ####################################################################################################################################################
# Dependencies
# ####################################################################################################################################################
INCLUDE(FetchContent)
SET(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/deps")
# Doxygen
IF(BUILD_DOC)
FIND_PACKAGE(Doxygen)
SET(BUILD_DOC ${Doxygen_FOUND})
@@ -112,8 +118,25 @@ SET_PACKAGE_PROPERTIES(
TYPE OPTIONAL
)
INCLUDE(FetchContent)
# Type safe
FETCHCONTENT_DECLARE(
type_safe
GIT_REPOSITORY https://github.com/foonathan/type_safe
GIT_TAG v0.2.2
SOURCE_DIR "${CMAKE_BINARY_DIR}/deps/type_safe"
)
SET_PACKAGE_PROPERTIES(
type_safe PROPERTIES
URL "https://github.com/foonathan/type_safe"
DESCRIPTION "Zero overhead abstractions that use the C++ type system to prevent bugs."
TYPE REQUIRED
)
FETCHCONTENT_MAKEAVAILABLE(type_safe)
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/deps/type_safe/include/ ${CMAKE_BINARY_DIR}/deps/type_safe/external/debug_assert/)
ADD_DEFINITIONS(-DTYPE_SAFE_ENABLE_ASSERTIONS=0 -DTYPE_SAFE_ENABLE_PRECONDITION_CHECKS=0 -DDEBUG_ASSERT_DISABLE)
# Catch2 and Google Tests
IF(BUILD_TESTS)
FETCHCONTENT_DECLARE(googletest URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip)
# For Windows: Prevent overriding the parent project's compiler/linker settings
@@ -121,7 +144,11 @@ IF(BUILD_TESTS)
ON
CACHE BOOL "" FORCE
)
FETCHCONTENT_MAKEAVAILABLE(googletest)
FETCHCONTENT_DECLARE(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.1
)
SET_PACKAGE_PROPERTIES(
googletest PROPERTIES
@@ -129,30 +156,27 @@ IF(BUILD_TESTS)
DESCRIPTION "Google unit tests"
TYPE OPTIONAL
)
SET(CALYP_TEST_DATA_DIR
"CALYP_TEST_DATA_DIR"
CACHE PATH "Location of video information for testing"
)
ENDIF()
IF(BUILD_TESTS_CATCH2)
FETCHCONTENT_DECLARE(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.1
)
FETCHCONTENT_MAKEAVAILABLE(Catch2)
SET_PACKAGE_PROPERTIES(
Catch2 PROPERTIES
URL "https://github.com/catchorg/Catch2"
DESCRIPTION "Catch2 unit tests"
TYPE OPTIONAL
)
INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/_deps/catch2-src/contrib/Catch.cmake)
FETCHCONTENT_MAKEAVAILABLE(googletest Catch2)
INCLUDE(${CMAKE_BINARY_DIR}/deps/catch2-src/contrib/Catch.cmake)
INCLUDE(CTest)
ENABLE_TESTING()
SET(CALYP_TEST_DATA_DIR
"CALYP_TEST_DATA_DIR"
CACHE PATH "Location of video information for testing"
)
ENDIF()
# OpenCV
OPTION(USE_OPENCV "Add OpenCV support" ON)
IF(USE_OPENCV)
@@ -178,6 +202,7 @@ SET_PACKAGE_PROPERTIES(
TYPE OPTIONAL
)
# FFmpeg
OPTION(USE_FFMPEG "Add FFMPEG support" ON)
IF(USE_FFMPEG)
FIND_PACKAGE(FFmpeg COMPONENTS AVCODEC AVFORMAT AVUTIL SWSCALE)
@@ -219,37 +244,42 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
# ####################################################################################################################################################
SET(CMAKE_CXX_STANDARD 20)
ADD_DEFINITIONS(-std=gnu++20)
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)
MESSAGE(STATUS "No build type selected, default to Release")
SET(CMAKE_BUILD_TYPE "Release")
ENDIF()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -funroll-loops -ftree-vectorizer-verbose")
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(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -funroll-loops")
# 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)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
ENDIF()
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -DCLP_DEBUG")
IF(BUILD_WITH_SANITIZERS)
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fsanitize=leak -fsanitize=undefined")
ENDIF()
IF(BUILD_WITH_THREAD_SANITIZER)
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=thread")
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
@@ -262,7 +292,10 @@ ADD_FEATURE_INFO(SSE USE_SSE "SSE instructions support")
ADD_FEATURE_INFO(WErrors USE_WERROR "Warnings as errors")
ADD_SUBDIRECTORY(lib)
ADD_SUBDIRECTORY(modules)
IF(${BUILD_TOOLS} OR ${BUILD_APP})
ADD_SUBDIRECTORY(modules)
ENDIF()
IF(${BUILD_TOOLS})
ADD_SUBDIRECTORY(tools)
+9 -7
View File
@@ -3,9 +3,11 @@
## Build Status
Master branch | Development branch
------------ | -------------
[![Linux Status](https://travis-ci.org/pixlra/calyp.svg?branch=master)](https://travis-ci.org/pixlra/calyp.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) | Comming soon!
| 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)
## Features
@@ -20,7 +22,7 @@ Master branch | Development branch
- Constant growing libs for stream and frame processing (CalypStream and CalypFrame)
- Advanced API for frame/video processing algorithms
- Frame level quality measurement API based on the CalypFrame class
- Powefull command-line tool for quality and frame processing algorithms (uses the referred APIs)
- Powerful command-line tool for quality and frame processing algorithms (uses the referred APIs)
## Modules
- CalypLib: Low level library
@@ -30,7 +32,7 @@ Master branch | Development branch
## Supported Quality Metrics
- Peak Signal-to-Noise Ratio (PSNR)
- Structural SIMilarity (SSIM)
- Structural SIMilarity (SSIM)
- Mean Square Error (MSE)
- Weighted Spherical PSNR (WS-PSNR)
@@ -73,13 +75,13 @@ Master branch | Development branch
* **Dependencies**
1. an ordinary C++ development environment (g++, make, C++ libraries and headers, ...)
2. cmake
3. a Qt development environment: QtCore, QtGui, QtWidgets, QtPrintSupport and QtConcurrent (version 4 or higher)
3. a Qt development environment: QtCore, QtGui, QtWidgets, QtPrintSupport and QtConcurrent (version 5 or higher)
4. Optional: QtDBus, OpenCV, FFmpeg
* **List of required commands**
```
mkdir build
cd build
cmake -DUSE_QT4=OFF -DUSE_FFMPEG=ON -DUSE_OPENCV=ON .. (for FFmpeg and OpenCV support)
cmake -DUSE_FFMPEG=ON -DUSE_OPENCV=ON .. (for FFmpeg and OpenCV support)
make
make install
```
+19 -3
View File
@@ -3,12 +3,14 @@
#
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}/widgets
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/external ${CMAKE_CURRENT_SOURCE_DIR}/dialog
${CMAKE_CURRENT_SOURCE_DIR}/docks ${CMAKE_CURRENT_SOURCE_DIR}/widgets
)
OPTION(USE_QTDBUS "Build with QtDBus" ON)
OPTION(USE_FERVOR "Add Fervor support" OFF)
OPTION(CALYP_MANAGED_RESOURCES "Handle streams in separate threads" ON)
OPTION(CALYP_THREADED_MODULES "Use threads for modules" ON)
ADD_SUBDIRECTORY(external)
@@ -34,6 +36,14 @@ IF(USE_QTDBUS)
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
# Main
main.cpp
@@ -43,14 +53,16 @@ SET(Calyp_App_SRCS
MdiSubWindow.cpp
SubWindowAbstract.cpp
# Module Video
ResourceHandle.cpp
VideoHandle.cpp
VideoSubWindow.cpp
VideoStreamSubWindow.cpp
ModuleSubWindow.cpp
ViewArea.cpp
GridManager.cpp
# Module Quality
QualityHandle.cpp
PlotSubWindow.cpp
external/qcustomplot/qcustomplot.cpp
# Module Plugins
ModulesHandle.cpp
CalypAppModuleIf.cpp
@@ -124,6 +136,10 @@ QT5_ADD_RESOURCES(Calyp_App_RCC ${Calyp_App_RCC})
# Instruct CMake to run moc automatically when needed.
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
IF(WIN32)
SET(WINDOWS_RES_FILE ${CMAKE_CURRENT_BINARY_DIR}/resources.obj)
+139 -101
View File
@@ -28,23 +28,52 @@
#include <QApplication>
#include <QDockWidget>
#include "ModuleHandleDock.h"
#include "ModuleSubWindow.h"
#include "VideoSubWindow.h"
#include "lib/CalypFrame.h"
#include "lib/CalypStream.h"
CalypAppModuleIf::CalypAppModuleIf( QObject* parent, QAction* action, CalypModuleIf* module )
: m_bIsRunning( false )
, m_pcModuleAction( action )
, m_pcModule( module )
, m_pcDisplaySubWindow( NULL )
, m_pcDockWidget( NULL )
, m_pcModuleDock( NULL )
, m_pcModuleStream( NULL )
, m_pcProcessedFrame( NULL )
, m_dMeasurementResult( 0 )
CalypAppModuleIf::CalypAppModuleIf( QObject* parent, QAction* action, CalypModulePtr&& module )
: m_pcModuleAction( action ), m_pcModule( std ::move( module ) )
{
setParent( parent );
for( int i = 0; i < CLP_MODULE_MAX_NUM_FRAMES; i++ )
#ifdef CALYP_THREADED_MODULES
setObjectName( m_pcModule->m_pchModuleName );
#endif
m_frameList.reserve( m_pcModule->m_uiNumberOfFrames );
m_frameListPtr.reserve( m_pcModule->m_uiNumberOfFrames );
m_pcSubWindow.resize( m_pcModule->m_uiNumberOfFrames, nullptr );
}
CalypAppModuleIf::~CalypAppModuleIf()
{
#ifdef CALYP_THREADED_MODULES
wait();
#endif
if( m_pcModuleDock )
{
m_pcSubWindow[i] = NULL;
auto* ptr = m_pcModuleDock;
m_pcModuleDock = NULL;
ptr->close();
delete ptr;
}
if( m_pcDisplaySubWindow )
{
auto* ptr = m_pcDisplaySubWindow;
m_pcDisplaySubWindow = NULL;
ptr->closeSubWindow();
delete ptr;
}
if( m_pcDockWidget )
{
m_pcDockWidget->close();
delete m_pcDockWidget;
}
if( m_pcModule )
{
m_pcModule->destroy();
m_pcModule = nullptr;
}
}
@@ -52,7 +81,7 @@ void CalypAppModuleIf::update( bool isPlaying )
{
if( m_pcDisplaySubWindow )
{
m_pcDisplaySubWindow->refreshFrame();
m_pcDisplaySubWindow->refreshSubWindow();
}
else
{
@@ -60,7 +89,15 @@ void CalypAppModuleIf::update( bool isPlaying )
}
}
bool CalypAppModuleIf::isRunning()
// void CalypAppModuleIf::setPlaying( bool isPlaying )
// {
// if( m_pcDisplaySubWindow )
// {
// m_pcDisplaySubWindow->setPlaying( isPlaying );
// }
// }
bool CalypAppModuleIf::isRunning() const
{
#ifdef CALYP_THREADED_MODULES
return QThread::isRunning();
@@ -69,12 +106,20 @@ bool CalypAppModuleIf::isRunning()
#endif
}
void CalypAppModuleIf::run()
{
bool result = process();
if( result )
{
EventData* eventData = new EventData( m_bSuccess, this );
QCoreApplication::postEvent( parent(), eventData );
}
}
bool CalypAppModuleIf::apply( bool isPlaying, bool disableThreads )
{
bool bRet = false;
QApplication::setOverrideCursor( Qt::WaitCursor );
if( m_pcModule->m_iModuleType == CLP_FRAME_PROCESSING_MODULE )
bool moduleExecuted = false;
if( m_pcModule->m_iModuleType == ClpModuleType::FrameProcessing )
{
if( m_pcDisplaySubWindow )
{
@@ -85,8 +130,20 @@ bool CalypAppModuleIf::apply( bool isPlaying, bool disableThreads )
m_pcSubWindow[0]->setFillWindow( true );
}
}
if( !( isPlaying && ( m_pcModule->m_uiModuleRequirements & CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY ) ) )
if( !( isPlaying && m_pcModule->m_uiModuleRequirements.is_set( ClpModuleFeature::SkipWhilePlaying ) ) )
{
m_frameList.clear();
for( unsigned int i = 0; i < m_pcModule->m_uiNumberOfFrames; i++ )
{
m_frameList.push_back( m_pcSubWindow[i]->getCurrFrameAsset() );
}
// Skip module is is already running
if( isRunning() )
return moduleExecuted;
moduleExecuted = true;
#ifdef CALYP_THREADED_MODULES
if( !disableThreads )
{
@@ -96,49 +153,51 @@ bool CalypAppModuleIf::apply( bool isPlaying, bool disableThreads )
else
#endif
{
run();
QApplication::setOverrideCursor( Qt::WaitCursor );
process();
QApplication::restoreOverrideCursor();
show();
}
if( m_pcDisplaySubWindow || m_pcModule->m_iModuleType == CLP_FRAME_MEASUREMENT_MODULE )
{
bRet = true;
}
}
else
{
bRet = true;
}
QApplication::restoreOverrideCursor();
return bRet;
return moduleExecuted;
}
void CalypAppModuleIf::run()
bool CalypAppModuleIf::process()
{
m_bIsRunning = true;
m_bSuccess = false;
std::vector<CalypFrame*> apcFrameList;
for( unsigned int i = 0; i < m_pcModule->m_uiNumberOfFrames; i++ )
if( m_frameList.empty() )
return false;
#ifdef CALYP_THREADED_MODULES
QMutexLocker locker( &m_Mutex );
#endif
m_frameListPtr.clear();
for( auto& frame : m_frameList )
{
apcFrameList.push_back( m_pcSubWindow[i]->getCurrFrame() );
m_frameListPtr.push_back( frame.get() );
}
if( m_pcModule->m_iModuleType == CLP_FRAME_PROCESSING_MODULE )
if( m_pcModule->m_iModuleType == ClpModuleType::FrameProcessing )
{
CalypFrame* framePtr{ nullptr };
if( m_pcModule->m_iModuleAPI >= CLP_MODULE_API_2 )
{
m_pcProcessedFrame = m_pcModule->process( apcFrameList );
framePtr = m_pcModule->process( m_frameListPtr );
}
else
{
m_pcProcessedFrame = m_pcModule->process( m_pcSubWindow[0]->getCurrFrame() );
framePtr = m_pcModule->process( m_pcSubWindow[0]->getCurrFrame() );
}
assert( framePtr != nullptr );
m_pcProcessedFrame = std::shared_ptr<CalypFrame>{ framePtr, []( CalypFrame* ptr ) {} };
}
else if( m_pcModule->m_iModuleType == CLP_FRAME_MEASUREMENT_MODULE )
else if( m_pcModule->m_iModuleType == ClpModuleType::FrameMeasurement )
{
if( m_pcModule->m_iModuleAPI >= CLP_MODULE_API_2 )
{
m_dMeasurementResult = m_pcModule->measure( apcFrameList );
m_dMeasurementResult = m_pcModule->measure( m_frameListPtr );
}
else
{
@@ -147,82 +206,61 @@ void CalypAppModuleIf::run()
}
else
{
return;
return false;
}
m_bSuccess = true;
m_bIsRunning = false;
#ifdef CALYP_THREADED_MODULES
EventData* eventData = new EventData( m_bSuccess, this );
if( parent() )
QCoreApplication::postEvent( parent(), eventData );
#endif
return;
return true;
}
void CalypAppModuleIf::show()
{
#ifdef CALYP_THREADED_MODULES
if( m_canceling )
return;
#endif
switch( m_pcModule->m_iModuleType )
{
case CLP_FRAME_PROCESSING_MODULE:
if( m_pcDisplaySubWindow )
case ClpModuleType::FrameProcessing: {
auto displayWindow = qobject_cast<VideoSubWindow*>( m_pcDisplaySubWindow );
if( displayWindow == nullptr )
displayWindow = m_pcSubWindow[0];
#ifdef CALYP_THREADED_MODULES
if( m_Mutex.try_lock() )
{
m_pcDisplaySubWindow->setCurrFrame( m_pcProcessedFrame );
m_pcDisplaySubWindow->setFillWindow( isRunning() );
}
else
{
m_pcSubWindow[0]->setCurrFrame( m_pcProcessedFrame );
m_pcSubWindow[0]->setFillWindow( isRunning() );
displayWindow->setFillWindow( false );
displayWindow->setCurrFrame( m_pcProcessedFrame );
m_Mutex.unlock();
}
#else
displayWindow->setFillWindow( false );
displayWindow->setCurrFrame( m_pcProcessedFrame );
#endif
break;
case CLP_FRAME_MEASUREMENT_MODULE:
m_pcModuleDock->setModulueReturnValue( m_dMeasurementResult );
}
case ClpModuleType::FrameMeasurement:
m_pcModuleDock->setModuleReturnValue( m_dMeasurementResult );
break;
default:
assert( false );
}
}
void CalypAppModuleIf::destroy()
void CalypAppModuleIf::disable()
{
if( m_bIsRunning )
QApplication::setOverrideCursor( Qt::WaitCursor );
#ifdef CALYP_THREADED_MODULES
m_canceling = true;
m_Mutex.lock();
m_Mutex.unlock();
#endif
m_frameList.clear();
m_frameListPtr.clear();
while( m_pcSubWindow.size() > 0 )
{
QApplication::setOverrideCursor( Qt::WaitCursor );
while( m_bIsRunning )
{
}
QApplication::restoreOverrideCursor();
}
if( m_pcModuleDock )
{
m_pcModuleDock->close();
m_pcModuleDock = NULL;
}
if( m_pcDockWidget )
{
m_pcDockWidget->close();
m_pcDockWidget = NULL;
}
if( m_pcDisplaySubWindow )
m_pcDisplaySubWindow->closeSubWindow();
m_pcDisplaySubWindow = NULL;
for( int i = 0; i < CLP_MODULE_MAX_NUM_FRAMES; i++ )
{
if( m_pcSubWindow[i] )
{
m_pcSubWindow[i]->disableModule( this );
m_pcSubWindow[i] = NULL;
}
}
if( m_pcModuleStream )
{
m_pcModuleStream->close();
delete m_pcModuleStream;
m_pcModuleStream = NULL;
}
if( m_pcModule )
{
m_pcModule->destroy();
m_pcModule->Delete();
m_pcModule = NULL;
auto window = m_pcSubWindow.back();
m_pcSubWindow.erase( m_pcSubWindow.end() - 1 );
if( window != nullptr )
window->disableModule( this );
}
QApplication::restoreOverrideCursor();
}
+49 -44
View File
@@ -26,6 +26,7 @@
#define __CALYPAPPMODULESIF_H__
#include <QEvent>
#include <QPointer>
#include <QVector>
#include <cstdio>
#include <iostream>
@@ -33,87 +34,91 @@
#include "config.h"
#ifdef CALYP_THREADED_MODULES
#include <QMutex>
#include <QThread>
#endif
#include "CommonDefs.h"
#include "ModuleHandleDock.h"
#include "lib/CalypFrame.h"
// #include "lib/CalypFrame.h"
#include "lib/CalypModuleIf.h"
#include "lib/CalypStream.h"
// #include "lib/CalypStream.h"
class QAction;
class QDockWidget;
#define CLP_MODULE_MAX_NUM_FRAMES 5
class CalypStream;
class CalypFrame;
class VideoSubWindow;
class ModuleSubWindow;
class CalypAppModuleIf
class CalypAppModuleIf : std::enable_shared_from_this<CalypAppModuleIf>,
#ifdef CALYP_THREADED_MODULES
: public QThread
public QThread
#else
: public QObject
public QObject
#endif
{
friend class ModulesHandle;
friend class ModuleHandleDock;
friend class ModulesHandleOptDialog;
private:
bool m_bIsRunning;
bool m_bSuccess;
QAction* m_pcModuleAction;
CalypModuleIf* m_pcModule;
VideoSubWindow* m_pcSubWindow[CLP_MODULE_MAX_NUM_FRAMES];
VideoSubWindow* m_pcDisplaySubWindow;
QDockWidget* m_pcDockWidget;
ModuleHandleDock* m_pcModuleDock;
CalypStream* m_pcModuleStream;
CalypFrame* m_pcProcessedFrame;
double m_dMeasurementResult;
public:
class EventData : public QEvent
{
public:
EventData( bool success, CalypAppModuleIf* module )
: QEvent( QEvent::User )
: QEvent( QEvent::User ), m_bSuccess{ success }, m_pcModule{ module }
{
m_bSuccess = success;
m_pcModule = module;
}
bool m_bSuccess;
CalypAppModuleIf* m_pcModule;
QPointer<CalypAppModuleIf> m_pcModule;
};
CalypAppModuleIf( QObject* parent, QAction* action, CalypModuleIf* module );
virtual ~CalypAppModuleIf() {}
QList<VideoSubWindow*> getSubWindowList()
{
QList<VideoSubWindow*> arraySubWindows;
for( int i = 0; i < CLP_MODULE_MAX_NUM_FRAMES; i++ )
if( m_pcSubWindow[i] )
arraySubWindows.append( m_pcSubWindow[i] );
return arraySubWindows;
}
CalypAppModuleIf( QObject* parent, QAction* action, CalypModulePtr&& module );
~CalypAppModuleIf();
CalypModuleIf* getModule() { return m_pcModule; }
unsigned int getModuleRequirements() { return m_pcModule->m_uiModuleRequirements; }
ClpString moduleInfo() { return m_pcModule->moduleInfo(); }
auto getSubWindowList() const -> const std::vector<VideoSubWindow*>& { return m_pcSubWindow; }
CalypModuleIf* getModule() { return m_pcModule.get(); }
auto getModuleRequirements() const -> ClpModuleFeatures { return m_pcModule->m_uiModuleRequirements; }
std::string moduleInfo() const { return m_pcModule->moduleInfo(); }
void update( bool isPlaying );
bool apply( bool isPlaying = false, bool disableThreads = false );
bool isRunning();
bool process();
// void setPlaying( bool isPlaying );
bool isRunning() const;
void show();
void destroy();
void disable();
protected:
virtual void run();
private:
bool m_bSuccess{ false };
QAction* m_pcModuleAction{ nullptr };
CalypModulePtr m_pcModule{ nullptr };
std::vector<VideoSubWindow*> m_pcSubWindow;
// The module owns the related widgets
ModuleSubWindow* m_pcDisplaySubWindow{ nullptr };
QDockWidget* m_pcDockWidget{ nullptr };
ModuleHandleDock* m_pcModuleDock{ nullptr };
std::unique_ptr<CalypStream> m_pcModuleStream{ nullptr };
std::vector<std::shared_ptr<CalypFrame>> m_frameList;
std::vector<CalypFrame*> m_frameListPtr;
std::shared_ptr<CalypFrame> m_pcProcessedFrame{ nullptr };
double m_dMeasurementResult{ 0 };
#ifdef CALYP_THREADED_MODULES
QMutex m_Mutex;
std::atomic<bool> m_canceling{ false };
#endif
};
#endif // __CALYPAPPMODULESIF_H__
+1 -1
View File
@@ -52,7 +52,7 @@ void GridManager::setGridSize( int newsize )
////////////////////////////////////////////////////////////////////////////////
// Grid Drawer
////////////////////////////////////////////////////////////////////////////////
void GridManager::drawGrid( QPixmap& image, const QRect& area, QPainter* painter )
void GridManager::drawGrid( const QImage& image, const QRect& area, QPainter* painter )
{
int offsetx = 0; // Grid offset doesn't applies to SCODE
int offsety = 0; // project for now...
+1 -1
View File
@@ -55,7 +55,7 @@ public:
void setGridSize( int newsize );
void drawGrid( QPixmap& image, const QRect& area, QPainter* painter );
void drawGrid( const QImage& image, const QRect& area, QPainter* painter );
/**
* @returns a QRect defined by the grid that contains the point (x, y).
+73 -49
View File
@@ -33,6 +33,7 @@
#include <QDropEvent>
#include <QSignalMapper>
#include <QtDebug>
#include <memory>
#include "AboutDialog.h"
#include "ModulesHandle.h"
@@ -58,6 +59,8 @@ MainWindow::MainWindow()
m_pDBusAdaptor = new DBusAppAdaptor( this );
#endif
m_appResourceHandle = std::make_unique<ResourceHandle>();
m_pcWindowHandle = new SubWindowHandle( this );
m_appModuleVideo = new VideoHandle( this, m_pcWindowHandle );
@@ -76,15 +79,15 @@ MainWindow::MainWindow()
setWindowTitle( QApplication::applicationName() );
setWindowIcon( QIcon( ":logos/calyp-icon.png" ) );
setUnifiedTitleAndToolBarOnMac( true );
setCentralWidget( m_pcWindowHandle );
setCentralWidget( m_pcWindowHandle->getWidget() );
setAcceptDrops( true );
setBackgroundRole( QPalette::Background );
setBackgroundRole( QPalette::Window );
connect( m_pcWindowHandle, SIGNAL( windowActivated() ), this, SLOT( update() ) );
connect( m_pcWindowHandle, SIGNAL( changed() ), this, SLOT( update() ) );
connect( m_appModuleVideo, SIGNAL( changed() ), this, SLOT( update() ) );
connect( m_appModuleQuality, SIGNAL( changed() ), this, SLOT( update() ) );
connect( m_appModuleExtensions, SIGNAL( changed() ), this, SLOT( update() ) );
connect( m_pcWindowHandle, &SubWindowHandle::windowActivated, this, &MainWindow::updateMainWindow );
connect( m_pcWindowHandle, &SubWindowHandle::changed, this, &MainWindow::updateMainWindow, Qt::QueuedConnection );
connect( m_appModuleVideo, &VideoHandle::changed, this, &MainWindow::updateMainWindow, Qt::QueuedConnection );
connect( m_appModuleQuality, &QualityHandle::changed, this, &MainWindow::updateMainWindow, Qt::QueuedConnection );
connect( m_appModuleExtensions, &ModulesHandle::changed, this, &MainWindow::updateMainWindow, Qt::QueuedConnection );
}
bool MainWindow::parseArgs( int argc, char* argv[] )
@@ -92,9 +95,9 @@ bool MainWindow::parseArgs( int argc, char* argv[] )
bool bRet = false;
CalypOptions pcCmdParser;
std::vector<ClpString> m_apcInputs;
ClpString strResolution( "" );
ClpString strPelFmt( "" );
std::vector<std::string> m_apcInputs;
std::string strResolution( "" );
std::string strPelFmt( "" );
pcCmdParser.addOptions() /**/
( "input,i", m_apcInputs, "input file" ) /**/
@@ -182,34 +185,52 @@ void MainWindow::closeAll()
m_pcWindowHandle->removeAllSubWindow();
}
void MainWindow::loadFile( QString fileName, CalypFileInfo* pStreamInfo )
void MainWindow::loadFile( CalypFileInfo pStreamInfo )
{
QString filename{ pStreamInfo.m_cFilename };
loadFile( std::move( filename ), std::move( pStreamInfo ) );
}
void MainWindow::loadFile( QString fileName, std::optional<CalypFileInfo> streamInfo )
{
if( !QFileInfo( fileName ).exists() )
{
printMessage( "File " + fileName + " do not exist!", CLP_LOG_ERROR );
return;
}
VideoSubWindow* videoSubWindow = MainWindow::findVideoStreamSubWindow( m_pcWindowHandle, fileName );
auto* videoSubWindow = MainWindow::findVideoStreamSubWindow( m_pcWindowHandle, fileName );
if( videoSubWindow )
{
m_pcWindowHandle->setActiveSubWindow( videoSubWindow );
return;
}
videoSubWindow = new VideoSubWindow( VideoSubWindow::VIDEO_STREAM_SUBWINDOW ); // createSubWindow();
if( !pStreamInfo )
videoSubWindow = new VideoStreamSubWindow(); // createSubWindow();
videoSubWindow->setResourceManaget( m_appResourceHandle.get() );
if( !streamInfo.has_value() )
{
int idx = findCalypStreamInfo( m_aRecentFileStreamInfo, fileName );
pStreamInfo = (CalypFileInfo*)( idx >= 0 ? &m_aRecentFileStreamInfo.at( idx ) : NULL );
auto idx = findCalypStreamInfo( m_aRecentFileStreamInfo, fileName );
if( idx >= 0 )
streamInfo = m_aRecentFileStreamInfo.at( idx );
}
try
{
bool opened = false;
if( !pStreamInfo )
if( streamInfo.has_value() )
{
try
{
opened = videoSubWindow->loadFile( std::move( *streamInfo ) );
}
catch( CalypFailure& e )
{
}
}
if( !opened )
opened = videoSubWindow->loadFile( fileName );
else
opened = videoSubWindow->loadFile( pStreamInfo );
if( opened )
{
@@ -256,12 +277,12 @@ QStringList MainWindow::showFileDialog( bool bRead )
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 )
{
QString currFmt( QString::fromStdString( supportedFmts[i].formatName ) );
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( " *." );
currFmt.append( "*." );
@@ -299,7 +320,7 @@ void MainWindow::open()
{
if( !fileNameList.at( i ).isEmpty() )
{
loadFile( fileNameList.at( i ) );
loadFile( std::move( fileNameList.at( i ) ) );
}
}
}
@@ -312,9 +333,10 @@ void MainWindow::open()
void MainWindow::openRecent()
{
QAction* action = qobject_cast<QAction*>( sender() );
CalypFileInfo recentFile = action->data().value<CalypFileInfo>();
if( action )
loadFile( recentFile.m_cFilename, &recentFile );
{
loadFile( action->data().value<CalypFileInfo>() );
}
}
void MainWindow::saveFrame()
@@ -375,9 +397,8 @@ void MainWindow::saveStream()
void MainWindow::format()
{
if( m_pcCurrentVideoSubWindow )
if( auto* pcVideoSubWindow = qobject_cast<VideoStreamSubWindow*>( m_pcCurrentVideoSubWindow ) )
{
VideoSubWindow* pcVideoSubWindow = m_pcCurrentVideoSubWindow;
try
{
if( pcVideoSubWindow->loadFile( pcVideoSubWindow->getCurrentFileName(), true ) )
@@ -395,7 +416,7 @@ void MainWindow::format()
m_pcCurrentSubWindow->close();
}
m_pcCurrentSubWindow = NULL;
update();
updateMainWindow();
}
}
@@ -405,7 +426,7 @@ void MainWindow::reload()
{
m_pcCurrentSubWindow->refreshSubWindow();
m_pcCurrentSubWindow = NULL;
update();
updateMainWindow();
}
}
@@ -426,15 +447,15 @@ void MainWindow::reloadAll()
}
}
m_pcCurrentSubWindow = NULL;
update();
updateMainWindow();
}
void MainWindow::loadAll()
{
if( m_pcCurrentVideoSubWindow )
if( auto* pcVideoSubWindow = qobject_cast<VideoStreamSubWindow*>( m_pcCurrentVideoSubWindow ) )
{
printMessage( "Loading file into memory...", CLP_LOG_INFO );
m_pcCurrentVideoSubWindow->loadAll();
pcVideoSubWindow->loadAll();
printMessage( "File loaded", CLP_LOG_INFO );
}
}
@@ -524,24 +545,23 @@ void MainWindow::dropEvent( QDropEvent* event )
// ----------------------- Sub Window Functions -----------------------
VideoSubWindow* MainWindow::findVideoStreamSubWindow( const SubWindowHandle* windowManager,
const QString& fileName )
VideoStreamSubWindow* MainWindow::findVideoStreamSubWindow( const SubWindowHandle* windowManager,
const QString& fileName )
{
QString canonicalFilePath = QFileInfo( fileName ).canonicalFilePath();
VideoSubWindow* pcSubWindow;
QList<SubWindowAbstract*> subWindowList = windowManager->findSubWindow( SubWindowAbstract::VIDEO_STREAM_SUBWINDOW );
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 )
return qobject_cast<VideoSubWindow*>( pcSubWindow );
return pcSubWindow;
}
return 0;
return nullptr;
}
// ----------------------- Update Functions -----------------------
void MainWindow::update()
void MainWindow::updateMainWindow()
{
SubWindowAbstract* activeSubWindow = m_pcWindowHandle->activeSubWindow();
QCoreApplication::processEvents();
@@ -595,10 +615,17 @@ void MainWindow::updateMenus()
{
bool hasSubWindow = ( m_pcWindowHandle->activeSubWindow() != 0 );
bool hasVideoStreamSubWindow = false;
if( m_pcCurrentSubWindow )
if( m_pcCurrentSubWindow->getCategory() & SubWindowAbstract::VIDEO_STREAM_SUBWINDOW )
hasVideoStreamSubWindow = true;
bool hasVideoStreamSubWindow{ false };
bool supportsFormat{ false };
if( m_pcCurrentSubWindow && m_pcCurrentSubWindow->getCategory() & SubWindowAbstract::VIDEO_STREAM_SUBWINDOW )
{
hasVideoStreamSubWindow = true;
if( auto* pcVideoSubWindow = qobject_cast<VideoStreamSubWindow*>( m_pcCurrentVideoSubWindow ) )
{
supportsFormat = pcVideoSubWindow->supportsFormatConfiguration();
}
}
m_arrayMenu[RECENT_MENU]->setEnabled( m_aRecentFileStreamInfo.size() > 0 ? true : false );
@@ -608,7 +635,7 @@ void MainWindow::updateMenus()
m_arrayActions[RELOAD_ACT]->setEnabled( hasSubWindow );
m_arrayActions[RELOAD_ALL_ACT]->setEnabled( hasSubWindow );
m_arrayActions[FORMAT_ACT]->setEnabled( hasVideoStreamSubWindow );
m_arrayActions[FORMAT_ACT]->setEnabled( supportsFormat );
m_arrayActions[LOAD_ALL_ACT]->setEnabled( hasVideoStreamSubWindow );
m_arrayActions[ZOOM_IN_ACT]->setEnabled( hasSubWindow );
@@ -802,12 +829,9 @@ void MainWindow::createMenus()
menuBar()->addMenu( m_appModuleVideo->createVideoMenu() );
menuBar()->addMenu( m_appModuleVideo->createImageMenu() );
QMenu* QualityMenu = m_appModuleQuality->createMenu();
menuBar()->addMenu( QualityMenu );
QMenu* ModuleMenu = m_appModuleExtensions->createMenu();
menuBar()->addMenu( ModuleMenu );
QMenu* windowMenu = m_pcWindowHandle->createMenu();
menuBar()->addMenu( windowMenu );
menuBar()->addMenu( m_appModuleQuality->createMenu() );
menuBar()->addMenu( m_appModuleExtensions->createMenu() );
menuBar()->addMenu( m_pcWindowHandle->createMenu() );
menuBar()->addSeparator();
+14 -8
View File
@@ -36,16 +36,19 @@
#ifndef __MAINWINDOW_H__
#define __MAINWINDOW_H__
#include <QMainWindow>
#include <QString>
#include <QVector>
#include <optional>
#include "CommonDefs.h"
#include "VideoStreamSubWindow.h"
#include "VideoSubWindow.h"
#include "config.h"
#ifdef USE_QTDBUS
#include "DBusAppAdaptor.h"
#endif
#include <QMainWindow>
#include <QString>
#include <QVector>
#include "ResourceHandle.h"
class QCloseEvent;
class QDragEnterEvent;
@@ -58,6 +61,7 @@ class QSignalMapper;
class CalypOptions;
class CalypStream;
class SubWindowHandle;
class VideoStreamSubWindow;
class VideoHandle;
class QualityHandle;
class ModulesHandle;
@@ -73,7 +77,8 @@ class MainWindow : public QMainWindow
public:
MainWindow();
bool parseArgs( int argc, char* argv[] );
void loadFile( QString fileName, CalypFileInfo* pStreamInfo = NULL );
void loadFile( CalypFileInfo pStreamInfo );
void loadFile( QString fileName, std::optional<CalypFileInfo> pStreamInfo = {} );
public Q_SLOTS:
void printMessage( const QString& msg );
@@ -114,7 +119,7 @@ private Q_SLOTS:
void dragEnterEvent( QDragEnterEvent* event );
void dropEvent( QDropEvent* event );
void update();
void updateMainWindow();
void updateZoomFactorSBox();
private:
@@ -129,8 +134,8 @@ private:
QString m_cLastOpenPath;
QStringList showFileDialog( bool bRead );
static VideoSubWindow* findVideoStreamSubWindow( const SubWindowHandle* windowManager,
const QString& fileName );
static VideoStreamSubWindow* findVideoStreamSubWindow( const SubWindowHandle* windowManager,
const QString& fileName );
void updateMenus();
@@ -158,6 +163,7 @@ private:
* Quality
* Modules
*/
std::unique_ptr<ResourceHandle> m_appResourceHandle;
VideoHandle* m_appModuleVideo;
QualityHandle* m_appModuleQuality;
ModulesHandle* m_appModuleExtensions;
+1 -1
View File
@@ -32,7 +32,7 @@ MdiSubWindow::MdiSubWindow( QWidget* parent )
: QMdiSubWindow( parent )
{
setAttribute( Qt::WA_DeleteOnClose );
setBackgroundRole( QPalette::Background );
setBackgroundRole( QPalette::Window );
}
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().is_set( ClpModuleFeature::HasInfo ) )
{
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__
+105 -125
View File
@@ -27,6 +27,7 @@
#include <cstdio>
#include "MainWindow.h"
#include "ModuleSubWindow.h"
#include "ModulesHandleOptDialog.h"
#include "SubWindowHandle.h"
#include "SubWindowSelectorDialog.h"
@@ -35,7 +36,7 @@
#include "modules/CalypModulesFactory.h"
ModulesHandle::ModulesHandle( QWidget* parent, SubWindowHandle* windowManager, VideoHandle* moduleVideo )
: QWidget( parent ), m_pcParent( parent ), m_pcMainWindowManager( windowManager ), m_appModuleVideo( moduleVideo )
: m_pcParent( parent ), m_pcMainWindowManager( windowManager ), m_appModuleVideo( moduleVideo )
{
setParent( m_pcParent );
}
@@ -50,32 +51,32 @@ void ModulesHandle::createActions()
connect( m_pcActionMapper, SIGNAL( mapped( int ) ), this, SLOT( processOpt( int ) ) );
// m_arrayActions[FORCE_PLAYING_REFRESH_ACT] = new QAction( "Refresh while
// playing", parent() );
// playing", m_pcParent );
// m_arrayActions[FORCE_PLAYING_REFRESH_ACT]->setStatusTip( "Force module
// refreshing while playing" );
// m_arrayActions[FORCE_PLAYING_REFRESH_ACT]->setCheckable( true );
m_arrayActions[LOAD_EXTERNAL_ACT] = new QAction( "Load external module", parent() );
m_arrayActions[LOAD_EXTERNAL_ACT] = new QAction( "Load external module", m_pcParent );
m_arrayActions[LOAD_EXTERNAL_ACT]->setStatusTip( "Load an externally build module" );
connect( m_arrayActions[LOAD_EXTERNAL_ACT], SIGNAL( triggered() ), this, SLOT( loadExternalModule() ) );
connect( m_arrayActions[LOAD_EXTERNAL_ACT], &QAction::triggered, this, &ModulesHandle::loadExternalModule );
m_arrayActions[APPLY_ALL_ACT] = new QAction( "Apply to All", parent() );
m_arrayActions[APPLY_ALL_ACT] = new QAction( "Apply to All", m_pcParent );
m_arrayActions[APPLY_ALL_ACT]->setStatusTip( "Apply module to all frames and save the result" );
connect( m_arrayActions[APPLY_ALL_ACT], SIGNAL( triggered() ), m_pcActionMapper, SLOT( map() ) );
m_pcActionMapper->setMapping( m_arrayActions[APPLY_ALL_ACT], APPLY_ALL_ACT );
m_arrayActions[SWAP_FRAMES_ACT] = new QAction( "Swap frames", parent() );
m_arrayActions[SWAP_FRAMES_ACT] = new QAction( "Swap frames", m_pcParent );
m_arrayActions[SWAP_FRAMES_ACT]->setStatusTip( "Swap Sub Window order" );
connect( m_arrayActions[SWAP_FRAMES_ACT], SIGNAL( triggered() ), m_pcActionMapper, SLOT( map() ) );
m_pcActionMapper->setMapping( m_arrayActions[SWAP_FRAMES_ACT], SWAP_FRAMES_ACT );
m_arrayActions[DISABLE_ACT] = new QAction( "Disable Modules", parent() );
connect( m_arrayActions[DISABLE_ACT], SIGNAL( triggered() ), this, SLOT( destroyWindowModules() ) );
m_arrayActions[DISABLE_ACT] = new QAction( "Disable Modules", m_pcParent );
connect( m_arrayActions[DISABLE_ACT], &QAction::triggered, this, &ModulesHandle::destroyWindowModules );
m_arrayActions[DISABLE_ALL_ACT] = new QAction( "Disable All Modules", parent() );
connect( m_arrayActions[DISABLE_ALL_ACT], SIGNAL( triggered() ), this, SLOT( destroyAllModulesIf() ) );
m_arrayActions[DISABLE_ALL_ACT] = new QAction( "Disable All Modules", m_pcParent );
connect( m_arrayActions[DISABLE_ALL_ACT], &QAction::triggered, this, &ModulesHandle::destroyAllModulesIf );
m_arrayActions[FORCE_NEW_WINDOW_ACT] = new QAction( "Use New Window", parent() );
m_arrayActions[FORCE_NEW_WINDOW_ACT] = new QAction( "Use New Window", m_pcParent );
m_arrayActions[FORCE_NEW_WINDOW_ACT]->setStatusTip(
"Show module result in a new window. Some modules already force this "
"feature" );
@@ -84,21 +85,16 @@ void ModulesHandle::createActions()
QMenu* ModulesHandle::createMenu()
{
m_pcModulesMenu = new QMenu( "&Modules", this );
m_pcModulesMenu = new QMenu( "&Modules", m_pcParent );
buildMenu();
return m_pcModulesMenu;
}
void ModulesHandle::buildMenu()
{
CalypModuleIf* pcCurrModuleIf;
QString ModuleIfinternalName;
QAction* currAction;
QMenu* currSubMenu;
for( int i = 0; i < m_arrayModulesActions.size(); i++ )
for( auto& action : m_arrayModulesActions )
{
delete m_arrayModulesActions.at( i );
delete action;
}
m_arrayModulesActions.clear();
m_pcModulesMenu->clear();
@@ -108,10 +104,10 @@ void ModulesHandle::buildMenu()
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
for( ; it != moduleFactoryMap.end(); ++it )
{
pcCurrModuleIf = it->second();
ModuleIfinternalName = QString::fromLocal8Bit( it->first );
auto pcCurrModuleIf = it->second();
QString ModuleIfinternalName = QString::fromLocal8Bit( it->first );
currSubMenu = NULL;
QMenu* currSubMenu{ nullptr };
if( pcCurrModuleIf->m_iModuleAPI <= CLP_MODULE_API_2 )
{
if( pcCurrModuleIf->m_pchModuleCategory )
@@ -132,7 +128,7 @@ void ModulesHandle::buildMenu()
}
}
currAction = new QAction( pcCurrModuleIf->getModuleLongName(), parent() );
QAction* currAction = new QAction( pcCurrModuleIf->getModuleLongName(), m_pcParent );
QString moduleTooltip = pcCurrModuleIf->m_pchModuleTooltip;
if( pcCurrModuleIf->m_uiNumberOfFrames > 1 )
moduleTooltip += QString( " | Requires %1 frames" ).arg( pcCurrModuleIf->m_uiNumberOfFrames );
@@ -140,15 +136,13 @@ void ModulesHandle::buildMenu()
currAction->setStatusTip( moduleTooltip );
currAction->setData( ModuleIfinternalName );
currAction->setCheckable( false );
connect( currAction, SIGNAL( triggered() ), this, SLOT( activateModule() ) );
connect( currAction, &QAction::triggered, this, &ModulesHandle::activateModule );
m_arrayModulesActions.append( currAction );
if( currSubMenu )
currSubMenu->addAction( currAction );
else
m_pcModulesMenu->addAction( currAction );
pcCurrModuleIf->Delete();
}
m_pcModulesMenu->addAction( m_arrayActions[LOAD_EXTERNAL_ACT] );
@@ -162,20 +156,20 @@ void ModulesHandle::buildMenu()
void ModulesHandle::updateMenus()
{
VideoSubWindow* pcSubWindow = qobject_cast<VideoSubWindow*>( m_pcMainWindowManager->activeSubWindow() );
bool hasSubWindow = pcSubWindow ? true : false;
QAction* currModuleAction;
VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow<VideoSubWindow>();
bool hasSubWindow = pcSubWindow != nullptr ? true : false;
for( int i = 0; i < m_arrayModulesActions.size(); i++ )
{
currModuleAction = m_arrayModulesActions.at( i );
//currModuleAction->setEnabled( hasSubWindow );
auto* currModuleAction = m_arrayModulesActions.at( i );
// currModuleAction->setEnabled( hasSubWindow );
currModuleAction->setChecked( false );
}
//for( int i = 0; i < m_pcModulesSubMenuList.size(); i++ )
// for( int i = 0; i < m_pcModulesSubMenuList.size(); i++ )
//{
// m_pcModulesSubMenuList.at( i )->setEnabled( hasSubWindow );
//}
// }
for( int i = 0; i < m_arrayActions.size(); i++ )
{
@@ -183,22 +177,21 @@ void ModulesHandle::updateMenus()
}
m_arrayActions[LOAD_EXTERNAL_ACT]->setEnabled( true );
m_arrayActions[FORCE_NEW_WINDOW_ACT]->setEnabled( hasSubWindow );
m_arrayActions[DISABLE_ALL_ACT]->setEnabled( m_pcCalypAppModuleIfList.size() > 0 );
m_arrayActions[DISABLE_ALL_ACT]->setEnabled( true );
if( pcSubWindow )
{
QList<CalypAppModuleIf*> apcCurrentModule = pcSubWindow->getModuleArray();
m_arrayActions[DISABLE_ACT]->setEnabled( apcCurrentModule.size() > 0 );
m_arrayActions[DISABLE_ACT]->setEnabled( pcSubWindow->hasModules() );
if( pcSubWindow->getDisplayModule() )
{
m_arrayActions[APPLY_ALL_ACT]->setEnabled( true );
m_arrayActions[SWAP_FRAMES_ACT]->setEnabled( true );
}
for( int i = 0; i < apcCurrentModule.size(); i++ )
{
currModuleAction = apcCurrentModule.at( i )->m_pcModuleAction;
currModuleAction->setChecked( true );
}
// for( int i = 0; i < apcCurrentModule.size(); i++ )
// {
// currModuleAction = apcCurrentModule.at( i )->m_pcModuleAction;
// currModuleAction->setChecked( true );
// }
}
}
@@ -216,22 +209,21 @@ void ModulesHandle::writeSettings()
void ModulesHandle::processOpt( int index )
{
VideoSubWindow* pcSubWindow = qobject_cast<VideoSubWindow*>( m_pcMainWindowManager->activeSubWindow() );
VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow<VideoSubWindow>();
if( pcSubWindow )
{
CalypAppModuleIf* pcCurrentModule = pcSubWindow->getDisplayModule();
if( pcCurrentModule )
{
CalypAppModuleIf* pcCurrModule = pcCurrentModule;
switch( index )
{
case INVALID_OPT:
break;
case SWAP_FRAMES_ACT:
swapModulesWindowsIf( pcCurrModule );
swapModulesWindowsIf( pcCurrentModule );
break;
case APPLY_ALL_ACT:
applyAllModuleIf( pcCurrModule );
applyAllModuleIf( pcCurrentModule );
break;
default:
Q_ASSERT( 0 );
@@ -266,7 +258,7 @@ void ModulesHandle::activateModule()
Qt::KeyboardModifiers keyModifiers = QApplication::keyboardModifiers();
bool bTmpForceNewWindow = false;
VideoSubWindow* pcVideoSubWindow = qobject_cast<VideoSubWindow*>( m_pcMainWindowManager->activeSubWindow() );
VideoSubWindow* pcVideoSubWindow = m_pcMainWindowManager->activeSubWindow<VideoSubWindow>();
if( !pcVideoSubWindow )
{
return;
@@ -278,9 +270,12 @@ void ModulesHandle::activateModule()
}
QString ModuleIfName = pcAction->data().toString();
CalypModuleIf* pcCurrModuleIf =
CalypModulesFactory::Get()->CreateModule( ModuleIfName.toLocal8Bit().constData() );
CalypAppModuleIf* pcCurrAppModuleIf = new CalypAppModuleIf( this, pcAction, pcCurrModuleIf );
auto pcCurrModuleIf = CalypModulesFactory::Get()->CreateModule( ModuleIfName.toLocal8Bit().constData() );
if( pcCurrModuleIf == nullptr )
{
return;
}
auto pcCurrAppModuleIf = std::make_shared<CalypAppModuleIf>( this, pcAction, std::move( pcCurrModuleIf ) );
QList<VideoSubWindow*> videoSubWindowList;
int numberOfFrames = pcCurrAppModuleIf->m_pcModule->m_uiNumberOfFrames;
@@ -288,7 +283,7 @@ void ModulesHandle::activateModule()
{
int minNumFrames = numberOfFrames;
int maxNumFrames = numberOfFrames;
if( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements & CLP_MODULES_VARIABLE_NUM_FRAMES )
if( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements.is_set( ClpModuleFeature::VariableNumOfFrames ) )
{
minNumFrames = numberOfFrames;
maxNumFrames = 255;
@@ -337,7 +332,7 @@ void ModulesHandle::activateModule()
{
videoSubWindowList.clear();
qobject_cast<MainWindow*>( m_pcParent )->printMessage( "Error! Incompatible frames", CLP_LOG_ERROR );
destroyModuleIf( pcCurrAppModuleIf );
// destroyModuleIf( pcCurrAppModuleIf );
return;
}
}
@@ -352,7 +347,7 @@ void ModulesHandle::activateModule()
{
qobject_cast<MainWindow*>( m_pcParent )
->printMessage( "Error! There is no windows to apply the module", CLP_LOG_ERROR );
destroyModuleIf( pcCurrAppModuleIf );
// destroyModuleIf( pcCurrAppModuleIf );
return;
}
@@ -361,13 +356,13 @@ void ModulesHandle::activateModule()
pcCurrAppModuleIf->m_pcSubWindow[i] = videoSubWindowList.at( i );
}
if( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements & CLP_MODULE_REQUIRES_OPTIONS )
if( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements.is_set( ClpModuleFeature::Options ) )
{
ModulesHandleOptDialog moduleOptDialog( m_pcParent, pcCurrAppModuleIf );
ModulesHandleOptDialog moduleOptDialog( m_pcParent, pcCurrAppModuleIf.get() );
if( moduleOptDialog.runConfiguration() == QDialog::Rejected )
{
qobject_cast<MainWindow*>( m_pcParent )->printMessage( "Module canceled by user!", CLP_LOG_WARNINGS );
destroyModuleIf( pcCurrAppModuleIf );
// destroyModuleIf( pcCurrAppModuleIf );
return;
}
}
@@ -376,14 +371,12 @@ void ModulesHandle::activateModule()
QString windowName;
VideoSubWindow* pcModuleSubWindow = NULL;
if( pcCurrAppModuleIf->m_pcModule->m_iModuleType == CLP_FRAME_PROCESSING_MODULE )
if( pcCurrAppModuleIf->m_pcModule->m_iModuleType == ClpModuleType::FrameProcessing )
{
if( ( pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements & CLP_MODULE_REQUIRES_NEW_WINDOW ) || bShowModulesNewWindow )
if( bShowModulesNewWindow || pcCurrAppModuleIf->m_pcModule->m_uiModuleRequirements.is_set( ClpModuleFeature::NewWindow ) )
{
pcModuleSubWindow = new VideoSubWindow( VideoSubWindow::MODULE_SUBWINDOW );
windowName.append( QStringLiteral( "Module " ) );
windowName.append( pcCurrAppModuleIf->m_pcModule->m_pchModuleLongName );
auto pcModuleSubWindow = new ModuleSubWindow( pcCurrAppModuleIf.get() );
pcModuleSubWindow->resetWindowName();
pcCurrAppModuleIf->m_pcDisplaySubWindow = pcModuleSubWindow;
// connect( pcModuleSubWindow->getViewArea(), SIGNAL( selectionChanged( QRect ) ), m_appModuleVideo,
// SLOT( updateSelectionArea( QRect ) ) );
@@ -392,11 +385,15 @@ void ModulesHandle::activateModule()
// connect( pcModuleSubWindow, SIGNAL( scrollBarMoved_SWindow( const QPoint ) ), m_appModuleVideo,
// SLOT( moveAllScrollBars( const QPoint ) ) );
}
else
{
pcCurrAppModuleIf->m_pcSubWindow[0]->setDisplayModule( pcCurrAppModuleIf.get() );
}
}
else if( pcCurrAppModuleIf->m_pcModule->m_iModuleType == CLP_FRAME_MEASUREMENT_MODULE )
else if( pcCurrAppModuleIf->m_pcModule->m_iModuleType == ClpModuleType::FrameMeasurement )
{
pcCurrAppModuleIf->m_pcDisplaySubWindow = NULL;
pcCurrAppModuleIf->m_pcModuleDock = new ModuleHandleDock( m_pcParent, pcCurrAppModuleIf );
pcCurrAppModuleIf->m_pcModuleDock = new ModuleHandleDock( m_pcParent, pcCurrAppModuleIf.get() );
QString titleDockWidget;
titleDockWidget.append( pcCurrAppModuleIf->m_pcModule->m_pchModuleName );
titleDockWidget.append( " Information" );
@@ -408,19 +405,9 @@ void ModulesHandle::activateModule()
->addDockWidget( Qt::RightDockWidgetArea, pcCurrAppModuleIf->m_pcDockWidget );
}
// Associate module with subwindows
if( !pcCurrAppModuleIf->m_pcDisplaySubWindow && !pcCurrAppModuleIf->m_pcModuleDock )
for( int i = 0; i < videoSubWindowList.size(); i++ )
{
pcCurrAppModuleIf->m_pcSubWindow[0]->enableModule( pcCurrAppModuleIf );
}
else
{
if( pcCurrAppModuleIf->m_pcDisplaySubWindow )
pcCurrAppModuleIf->m_pcDisplaySubWindow->enableModule( pcCurrAppModuleIf );
for( int i = 0; i < videoSubWindowList.size(); i++ )
{
pcCurrAppModuleIf->m_pcSubWindow[i]->associateModule( pcCurrAppModuleIf );
}
pcCurrAppModuleIf->m_pcSubWindow[i]->associateModule( pcCurrAppModuleIf );
}
// Create Module
@@ -443,19 +430,19 @@ void ModulesHandle::activateModule()
if( !moduleCreated )
{
qobject_cast<MainWindow*>( m_pcParent )->printMessage( "Error! Module cannot be created", CLP_LOG_ERROR );
destroyModuleIf( pcCurrAppModuleIf );
// destroyModuleIf( pcCurrAppModuleIf );
return;
}
pcCurrAppModuleIf->apply( false, true );
QCoreApplication::processEvents();
if( pcModuleSubWindow )
if( pcCurrAppModuleIf->m_pcDisplaySubWindow )
{
pcModuleSubWindow->setWindowName( windowName );
m_pcMainWindowManager->addSubWindow( pcModuleSubWindow );
pcModuleSubWindow->show();
m_appModuleVideo->addSubWindow( pcModuleSubWindow );
m_pcMainWindowManager->addSubWindow( pcCurrAppModuleIf->m_pcDisplaySubWindow );
pcCurrAppModuleIf->m_pcDisplaySubWindow->show();
m_appModuleVideo->addSubWindow( pcCurrAppModuleIf->m_pcDisplaySubWindow );
}
else
{
@@ -465,44 +452,39 @@ void ModulesHandle::activateModule()
videoSubWindowList.at( 0 )->setWindowName( windowName );
}
m_pcCalypAppModuleIfList.append( pcCurrAppModuleIf );
// Change ownership of the module
// if( !pcCurrAppModuleIf->m_pcDisplaySubWindow && !pcCurrAppModuleIf->m_pcModuleDock )
// {
// pcCurrAppModuleIf->m_pcSubWindow[0]->enableModule( pcCurrAppModuleIf );
// }
// else if( pcCurrAppModuleIf->m_pcDisplaySubWindow )
// {
// pcCurrAppModuleIf->m_pcDisplaySubWindow->enableModule( pcCurrAppModuleIf );
// }
emit changed();
}
void ModulesHandle::destroyModuleIf( CalypAppModuleIf* pcCurrModuleIf )
{
if( pcCurrModuleIf )
{
pcCurrModuleIf->destroy();
}
}
void ModulesHandle::destroyWindowModules()
{
VideoSubWindow* pcVideoSubWindow = qobject_cast<VideoSubWindow*>( m_pcMainWindowManager->activeSubWindow() );
VideoSubWindow* pcVideoSubWindow = m_pcMainWindowManager->activeSubWindow<VideoSubWindow>();
if( pcVideoSubWindow )
{
pcVideoSubWindow->disableModule();
pcVideoSubWindow->disableAllModules();
emit changed();
}
}
void ModulesHandle::destroyAllModulesIf()
{
for( int i = 0; i < m_pcCalypAppModuleIfList.size(); i++ )
bool emit_changed = false;
QList<SubWindowAbstract*> windowsList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW );
for( auto window : windowsList )
{
destroyModuleIf( m_pcCalypAppModuleIfList.at( i ) );
}
emit changed();
}
void ModulesHandle::applyModuleIf( QList<CalypAppModuleIf*> pcCurrModuleIfList, bool isPlaying, bool disableThreads )
{
for( int i = 0; i < pcCurrModuleIfList.size() && !isPlaying; i++ )
{
pcCurrModuleIfList.at( i )->apply( isPlaying, disableThreads );
emit_changed |= qobject_cast<VideoSubWindow*>( window )->disableAllModules();
}
if( emit_changed )
emit changed();
}
void ModulesHandle::applyAllModuleIf( CalypAppModuleIf* pcCurrModuleIf )
@@ -511,21 +493,18 @@ void ModulesHandle::applyAllModuleIf( CalypAppModuleIf* pcCurrModuleIf )
{
if( !pcCurrModuleIf->m_pcModuleStream )
{
unsigned int Width = 0, Height = 0, FrameRate = 30;
int BitsPixel, InputFormat = -1;
QString supported = tr( "Supported Files (" );
QStringList formatsList;
std::vector<CalypStreamFormat> supportedFmts = CalypStream::supportedWriteFormats();
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 )
{
QString currFmt( QString::fromStdString( supportedFmts[i].formatName ) );
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( " *." );
currFmt.append( "*." );
@@ -546,18 +525,17 @@ void ModulesHandle::applyAllModuleIf( CalypAppModuleIf* pcCurrModuleIf )
{
return;
}
Width = pcCurrModuleIf->m_pcProcessedFrame->getWidth();
Height = pcCurrModuleIf->m_pcProcessedFrame->getHeight();
InputFormat = pcCurrModuleIf->m_pcProcessedFrame->getPelFormat();
BitsPixel = pcCurrModuleIf->m_pcProcessedFrame->getBitsPel();
FrameRate = pcCurrModuleIf->m_pcSubWindow[0]->getInputStream()->getFrameRate();
auto Width = pcCurrModuleIf->m_pcProcessedFrame->getWidth();
auto Height = pcCurrModuleIf->m_pcProcessedFrame->getHeight();
auto InputFormat = pcCurrModuleIf->m_pcProcessedFrame->getPelFormat();
auto BitsPixel = pcCurrModuleIf->m_pcProcessedFrame->getBitsPel();
auto FrameRate = 30;
pcCurrModuleIf->m_pcModuleStream = new CalypStream;
pcCurrModuleIf->m_pcModuleStream = std::unique_ptr<CalypStream>();
if( !pcCurrModuleIf->m_pcModuleStream->open( fileName.toStdString(), Width, Height, InputFormat, BitsPixel,
CLP_LITTLE_ENDIAN, FrameRate, false ) )
CLP_LITTLE_ENDIAN, FrameRate, CalypStream::Type::Output ) )
{
delete pcCurrModuleIf->m_pcModuleStream;
pcCurrModuleIf->m_pcModuleStream = NULL;
pcCurrModuleIf->m_pcModuleStream = nullptr;
return;
}
}
@@ -565,11 +543,11 @@ void ModulesHandle::applyAllModuleIf( CalypAppModuleIf* pcCurrModuleIf )
if( pcCurrModuleIf->m_pcModuleStream )
{
unsigned int numberOfWindows = pcCurrModuleIf->m_pcModule->m_uiNumberOfFrames;
ClpULong currFrames = 0;
ClpULong numberOfFrames = -1;
std::uint64_t currFrames = 0;
std::uint64_t numberOfFrames = -1;
for( unsigned int i = 0; i < numberOfWindows; i++ )
{
currFrames = pcCurrModuleIf->m_pcSubWindow[i]->getInputStream()->getFrameNum();
currFrames = pcCurrModuleIf->m_pcSubWindow[i]->getFrameNum();
if( currFrames < numberOfFrames )
numberOfFrames = currFrames;
pcCurrModuleIf->m_pcSubWindow[i]->stop();
@@ -579,11 +557,10 @@ void ModulesHandle::applyAllModuleIf( CalypAppModuleIf* pcCurrModuleIf )
{
pcCurrModuleIf->apply( false, true );
QCoreApplication::processEvents();
pcCurrModuleIf->m_pcModuleStream->writeFrame( pcCurrModuleIf->m_pcProcessedFrame );
pcCurrModuleIf->m_pcModuleStream->writeFrame( *pcCurrModuleIf->m_pcProcessedFrame );
for( unsigned int i = 0; i < numberOfWindows; i++ )
{
pcCurrModuleIf->m_pcSubWindow[i]->play();
pcCurrModuleIf->m_pcSubWindow[i]->playEvent();
pcCurrModuleIf->m_pcSubWindow[i]->advanceOneFrame();
}
}
for( unsigned int i = 0; i < numberOfWindows; i++ )
@@ -609,12 +586,15 @@ void ModulesHandle::swapModulesWindowsIf( CalypAppModuleIf* pcCurrModuleIf )
void ModulesHandle::customEvent( QEvent* event )
{
if( !event )
{
return;
}
CalypAppModuleIf::EventData* eventData = (CalypAppModuleIf::EventData*)event;
if( eventData->m_bSuccess )
{
event->accept();
// The module could be freed by the time the event is processed
if( eventData->m_pcModule.isNull() )
return;
eventData->m_pcModule->show();
}
}
+1 -5
View File
@@ -39,7 +39,7 @@ class SubWindowHandle;
class CalypAppModuleIf;
class SubWindowHandle;
class ModulesHandle : public QWidget
class ModulesHandle : public QObject
{
Q_OBJECT
public:
@@ -55,10 +55,6 @@ public:
void readSettings();
void writeSettings();
static void destroyModuleIf( CalypAppModuleIf* pcCurrModuleIf );
static void applyModuleIf( QList<CalypAppModuleIf*> pcCurrModuleIfList, bool isPlaying = false,
bool disableThreads = false );
private:
QWidget* m_pcParent;
SubWindowHandle* m_pcMainWindowManager;
-1
View File
@@ -29,7 +29,6 @@
#include <QSize>
#include "qcustomplot.h"
//#include "external/qcustomplot/qcustomplot.h"
void PlotSubWindow::definePlotColors()
{
+16 -18
View File
@@ -32,10 +32,9 @@
#include "SubWindowHandle.h"
#include "SubWindowSelectorDialog.h"
#include "VideoSubWindow.h"
#include "lib/LibMemory.h"
QualityHandle::QualityHandle( QWidget* parent, SubWindowHandle* windowManager )
: m_pcParet( parent ), m_pcMainWindowManager( windowManager )
: m_pcParent( parent ), m_pcMainWindowManager( windowManager )
{
}
@@ -71,7 +70,7 @@ void QualityHandle::createActions()
QMenu* QualityHandle::createMenu()
{
m_pcMenuQuality = new QMenu( "Quality", this );
m_pcMenuQuality = new QMenu( "Quality", m_pcParent );
m_pcSubMenuQualityMetrics = m_pcMenuQuality->addMenu( "Quality Metrics" );
m_pcSubMenuQualityMetrics->addActions( m_actionGroupQualityMetric->actions() );
m_pcMenuQuality->addAction( m_arrayActions[SELECT_CURR_REF_ACT] );
@@ -83,8 +82,8 @@ QMenu* QualityHandle::createMenu()
QDockWidget* QualityHandle::createDock()
{
m_pcQualityHandleSideBar = new QualityMeasurementSidebar( m_pcParet, m_pcMainWindowManager );
m_pcQualityHandleDock = new QDockWidget( tr( "Quality Measurement" ), this );
m_pcQualityHandleSideBar = new QualityMeasurementSidebar( m_pcParent, m_pcMainWindowManager );
m_pcQualityHandleDock = new QDockWidget( tr( "Quality Measurement" ), m_pcParent );
m_pcQualityHandleDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
m_pcQualityHandleDock->setWidget( m_pcQualityHandleSideBar );
@@ -99,7 +98,7 @@ QDockWidget* QualityHandle::createDock()
void QualityHandle::updateMenus()
{
VideoSubWindow* pcCurrentVideoSubWindow = qobject_cast<VideoSubWindow*>( m_pcMainWindowManager->activeSubWindow() );
VideoSubWindow* pcCurrentVideoSubWindow = m_pcMainWindowManager->activeSubWindow<VideoSubWindow>();
bool hasSubWindow = pcCurrentVideoSubWindow ? true : false;
bool hasReference = false;
bool isReference = false;
@@ -157,8 +156,8 @@ void QualityHandle::update( VideoSubWindow* currSubWindow )
void QualityHandle::measureQuality( QVector<VideoSubWindow*> apcWindowList )
{
unsigned numberOfWindows = apcWindowList.size();
ClpULong currFrames = 0;
ClpULong numberOfFrames = -1;
std::uint64_t currFrames = 0;
std::uint64_t numberOfFrames = -1;
//! Check reference window
for( unsigned i = 0; i < numberOfWindows; i++ )
@@ -170,21 +169,20 @@ void QualityHandle::measureQuality( QVector<VideoSubWindow*> apcWindowList )
}
VideoSubWindow* pcReferenceWindow = apcWindowList.at( 0 )->getRefSubWindow();
numberOfFrames = pcReferenceWindow->getInputStream()->getFrameNum();
numberOfFrames = pcReferenceWindow->getFrameNum();
for( unsigned i = 0; i < numberOfWindows; i++ )
{
currFrames = apcWindowList.at( i )->getInputStream()->getFrameNum();
currFrames = apcWindowList.at( i )->getFrameNum();
if( currFrames < numberOfFrames )
numberOfFrames = currFrames;
apcWindowList.at( i )->stop();
}
pcReferenceWindow->stop();
ProgressBar* pcProgressBar = new ProgressBar( m_pcParet, numberOfFrames );
ProgressBar* pcProgressBar = new ProgressBar( m_pcParent, numberOfFrames );
QVector<double>* padQualityValues = new QVector<double>[numberOfWindows + 1];
double* padAverageQuality = new double[numberOfWindows + 1];
double dCurrentQuality;
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++ )
{
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 );
padQualityValues[i + 1].append( dCurrentQuality );
apcWindowList.at( i )->seekRelativeEvent( true );
apcWindowList.at( i )->advanceOneFrame();
}
pcReferenceWindow->seekRelativeEvent( true );
pcReferenceWindow->advanceOneFrame();
pcProgressBar->incrementProgress( 1 );
}
for( unsigned int i = 0; i < numberOfWindows; i++ )
@@ -249,7 +247,7 @@ void QualityHandle::slotQualityMetricChanged( int idx )
void QualityHandle::slotSelectCurrentAsReference()
{
VideoSubWindow* pcRefSubWindow = qobject_cast<VideoSubWindow*>( m_pcMainWindowManager->activeSubWindow() );
VideoSubWindow* pcRefSubWindow = m_pcMainWindowManager->activeSubWindow<VideoSubWindow>();
if( pcRefSubWindow )
{
VideoSubWindow* pcVideoSubWindow;
@@ -269,7 +267,7 @@ void QualityHandle::slotSelectCurrentAsReference()
void QualityHandle::slotPlotQualitySingle()
{
VideoSubWindow* pcSubWindow = qobject_cast<VideoSubWindow*>( m_pcMainWindowManager->activeSubWindow() );
VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow<VideoSubWindow>();
if( pcSubWindow )
{
if( pcSubWindow->getRefSubWindow() )
@@ -293,7 +291,7 @@ void QualityHandle::slotPlotQualitySingle()
void QualityHandle::slotPlotQualitySeveral()
{
VideoSubWindow* pcSubWindow = qobject_cast<VideoSubWindow*>( m_pcMainWindowManager->activeSubWindow() );
VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow<VideoSubWindow>();
if( pcSubWindow )
{
QVector<VideoSubWindow*> apcWindowList;
+3 -3
View File
@@ -25,18 +25,18 @@
#ifndef __QUALITYMEASUREMENT_H__
#define __QUALITYMEASUREMENT_H__
#include <QFuture>
#include <QtCore>
#include <QtWidgets>
#include "CommonDefs.h"
#include "QFuture"
#include "QualityMeasurementSidebar.h"
#include "config.h"
class SubWindowHandle;
class VideoSubWindow;
class QualityHandle : public QWidget
class QualityHandle : public QObject
{
Q_OBJECT
public:
@@ -54,7 +54,7 @@ public:
void update( VideoSubWindow* currSubWindow );
private:
QWidget* m_pcParet;
QWidget* m_pcParent;
SubWindowHandle* m_pcMainWindowManager;
enum
+167
View File
@@ -0,0 +1,167 @@
/* This file is a part of Calyp project
* Copyright (C) 2014-2021 by Joao Carreira (jfmcarreira@gmail.com)
* Luis Lucas (luisfrlucas@gmail.com)
* Joao Santos (joaompssantos@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 ResourceHandle.cpp
* \brief Handle resources
*/
#include "ResourceHandle.h"
#include <QCoreApplication>
#include <QEvent>
#include <QFileInfo>
#include <QMutex>
#include <QThread>
#include <chrono>
#include <iostream>
#include <memory>
#include <optional>
ResourceWorker::ResourceWorker( std::shared_ptr<CalypStream> stream )
{
m_pcStream = stream;
}
void ResourceWorker::stop()
{
m_bStop = true;
wake();
wait();
}
void ResourceWorker::wake()
{
m_Mutex.lock();
m_ResourceIdle.wakeAll();
m_Mutex.unlock();
}
void ResourceWorker::run()
{
m_bStop = false;
// Loop forever
while( !m_bStop )
{
//auto start = std::chrono::steady_clock::now();
m_pcStream->readNextFrameFillRGBBuffer();
// auto end = std::chrono::steady_clock::now();
// std::cout << "Elapsed time reading and processing a frame: "
// << std::chrono::duration_cast<std::chrono::milliseconds>( end - start ).count()
// << " ms" << std::endl;
// if( !m_pcStream->hasWritingSlot() )
// {
// m_Mutex.lock();
// m_ResourceIdle.wait( &m_Mutex );
// m_Mutex.unlock();
// }
while( !m_bStop && !m_pcStream->hasWritingSlot() )
{
// Wait here
}
}
}
ResourceHandle::ResourceHandle()
{
}
auto ResourceHandle::addResource() -> std::size_t
{
auto resource_id = unique_id;
unique_id++;
auto newStreamResource = std::make_shared<CalypStream>();
auto newStreamResourceWorker = std::make_unique<ResourceWorker>( newStreamResource );
m_apcStreamResourcesList[resource_id] = newStreamResource;
m_apcStreamResourcesWorkersList[resource_id] = std::move( newStreamResourceWorker );
return resource_id;
}
auto ResourceHandle::getResource( CalypStream* ptr ) -> std::size_t
{
if( ptr != nullptr )
{
for( std::size_t i = 0; i < m_apcStreamResourcesList.size(); i++ )
{
if( m_apcStreamResourcesList[i].get() == ptr )
return i;
}
}
return addResource();
}
auto ResourceHandle::getResourceAsset( std::size_t id ) -> CalypStream*
{
if( m_apcStreamResourcesWorkersList.count( id ) )
{
return m_apcStreamResourcesList[id].get();
}
return nullptr;
}
void ResourceHandle::removeResource( std::size_t id )
{
if( !m_apcStreamResourcesWorkersList.count( id ) )
{
assert( false );
return;
}
// Remove worker first
m_apcStreamResourcesWorkersList[id]->stop();
m_apcStreamResourcesWorkersList[id] = nullptr;
// Then the underlying stream
m_apcStreamResourcesList[id] = nullptr;
}
void ResourceHandle::stopResourceWorker( std::size_t id )
{
if( !m_apcStreamResourcesWorkersList.count( id ) )
{
assert( false );
return;
}
m_apcStreamResourcesWorkersList[id]->stop();
}
void ResourceHandle::startResourceWorker( std::size_t id )
{
if( !m_apcStreamResourcesWorkersList.count( id ) )
{
assert( false );
return;
}
m_apcStreamResourcesWorkersList[id]->setObjectName(
"RW-" +
QFileInfo( QString::fromStdString( m_apcStreamResourcesList[id]->getFileName() ) ).completeBaseName() );
m_apcStreamResourcesWorkersList[id]->start();
}
void ResourceHandle::wakeResourceWorker( std::size_t id )
{
if( !m_apcStreamResourcesWorkersList.count( id ) )
{
assert( false );
return;
}
m_apcStreamResourcesWorkersList[id]->wake();
}
+73
View File
@@ -0,0 +1,73 @@
/* 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 ResourceHandle.h
* \brief Handle multiple sub-windows
*/
#ifndef __RESOURCEHANDLE_H__
#define __RESOURCEHANDLE_H__
#include <QMutex>
#include <QThread>
#include <QVector>
#include <QWaitCondition>
#include "CommonDefs.h"
#include "lib/CalypStream.h"
class ResourceWorker : public QThread
{
private:
QMutex m_Mutex;
QWaitCondition m_ResourceIdle;
std::shared_ptr<CalypStream> m_pcStream;
bool m_bStop{ false };
public:
ResourceWorker( std::shared_ptr<CalypStream> stream );
void stop();
void wake();
void run();
};
class ResourceHandle
{
public:
ResourceHandle();
~ResourceHandle() = default;
auto getResource( CalypStream* ptr ) -> std::size_t;
auto getResourceAsset( std::size_t id ) -> CalypStream*;
void removeResource( std::size_t id );
void stopResourceWorker( std::size_t id );
void startResourceWorker( std::size_t id );
void wakeResourceWorker( std::size_t id );
private:
auto addResource() -> std::size_t;
private:
std::size_t unique_id{ 0 };
std::map<std::size_t, std::shared_ptr<CalypStream>> m_apcStreamResourcesList;
std::map<std::size_t, std::unique_ptr<ResourceWorker>> m_apcStreamResourcesWorkersList;
};
#endif // __RESOURCEHANDLE_H__
+15 -3
View File
@@ -26,8 +26,10 @@
#include <QCloseEvent>
#include <QFocusEvent>
#include <QGuiApplication>
#include <QHBoxLayout>
#include <QIcon>
#include <QScreen>
#include <QScrollBar>
#include "MdiSubWindow.h"
@@ -40,7 +42,7 @@ SubWindowAbstract::SubWindowAbstract( QWidget* parent, unsigned int category )
// setFocusPolicy( Qt::WheelFocus );
setFocusPolicy( Qt::StrongFocus );
setAttribute( Qt::WA_DeleteOnClose );
setBackgroundRole( QPalette::Background );
setBackgroundRole( QPalette::Window );
setWindowIcon( QIcon( ":/logos/calyp-icon.png" ) );
@@ -87,10 +89,20 @@ bool SubWindowAbstract::mayClose()
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();
}
+1 -1
View File
@@ -107,7 +107,7 @@ public:
* Size related functions
*/
virtual QSize sizeHint() const;
virtual QSize sizeHint( const QSize& ) const;
virtual QSize sizeHint( const QSize& maxSize ) const;
/**
* Window name
+34 -21
View File
@@ -49,7 +49,7 @@ public:
MdiArea( QWidget* parent = 0 )
: QMdiArea( parent ), m_pixmapLogo( ":/logos/calyp-logo.png" )
{
setBackgroundRole( QPalette::Background );
setBackgroundRole( QPalette::Window );
}
void appendLogMessage( const QString& msg )
@@ -85,7 +85,7 @@ private:
};
SubWindowHandle::SubWindowHandle( QWidget* parent )
: QWidget( parent )
: m_pcApp( qobject_cast<MainWindow*>( parent ) )
{
m_iWindowMode = -1;
m_pcWindowManagerLayout = NULL;
@@ -94,7 +94,7 @@ SubWindowHandle::SubWindowHandle( QWidget* parent )
m_apcSubWindowList.clear();
m_apcMdiSubWindowList.clear();
m_pcApp = qobject_cast<MainWindow*>( parentWidget() );
m_pcCentralWidget = new QWidget;
// setWindowMode( DETACHEDSUBWINDOWMODE );
setWindowMode( MDISUBWINDOWMODE );
}
@@ -152,8 +152,8 @@ void SubWindowHandle::setWindowMode( int iWindowMode )
m_apcSubWindowList.at( i )->resize( m_apcSubWindowList.at( i )->sizeHint() );
m_apcSubWindowList.at( i )->show();
}
setVisible( false );
parentWidget()->update();
m_pcCentralWidget->setVisible( false );
m_pcApp->update();
m_pcApp->showNormal();
qApp->processEvents();
QSize screenSize = QGuiApplication::screens()[0]->availableGeometry().size();
@@ -164,13 +164,13 @@ void SubWindowHandle::setWindowMode( int iWindowMode )
if( iWindowMode == MDISUBWINDOWMODE )
{
setVisible( true );
m_pcCentralWidget->setVisible( true );
m_pcMdiArea = new MdiArea;
m_pcMdiArea->setActivationOrder( QMdiArea::ActivationHistoryOrder );
connect( m_pcMdiArea, SIGNAL( subWindowActivated( QMdiSubWindow* ) ), this, SLOT( updateActiveSubWindow() ) );
m_pcWindowManagerLayout = new QHBoxLayout( this );
m_pcWindowManagerLayout = new QHBoxLayout( m_pcCentralWidget );
m_pcWindowManagerLayout->addWidget( m_pcMdiArea );
setLayout( m_pcWindowManagerLayout );
m_pcCentralWidget->setLayout( m_pcWindowManagerLayout );
for( int i = 0; i < m_apcSubWindowList.size(); i++ )
{
addMdiSubWindow( m_apcSubWindowList.at( i ) );
@@ -182,6 +182,10 @@ void SubWindowHandle::setWindowMode( int iWindowMode )
{
m_pcApp->setWindowTitle( QApplication::applicationName() + " :: " + m_pcActiveWindow->getWindowName() );
}
else
{
m_pcApp->setWindowTitle( QApplication::applicationName() );
}
}
m_iWindowMode = iWindowMode;
// tileSubWindows();
@@ -218,6 +222,10 @@ void SubWindowHandle::updateActiveSubWindow( SubWindowAbstract* window )
{
m_pcApp->setWindowTitle( QApplication::applicationName() + " :: " + m_pcActiveWindow->getWindowName() );
}
else
{
m_pcApp->setWindowTitle( QApplication::applicationName() );
}
}
}
@@ -237,9 +245,9 @@ void SubWindowHandle::addSubWindow( SubWindowAbstract* window )
if( window )
{
connect( window, SIGNAL( updateStatusBar( const QString& ) ), m_pcApp,
SLOT( printMessage( const QString& ) ) );
SLOT( printMessage( const QString& ) ) );
connect( window, SIGNAL( zoomFactorChanged( const double, const QPoint ) ), m_pcApp,
SLOT( updateZoomFactorSBox() ) );
SLOT( updateZoomFactorSBox() ) );
if( m_iWindowMode == DETACHEDSUBWINDOWMODE )
{
connect( window, SIGNAL( aboutToActivate( SubWindowAbstract* ) ), this,
@@ -278,7 +286,12 @@ void SubWindowHandle::removeSubWindow( int windowIdx )
if( !m_apcSubWindowList.isEmpty() )
m_apcSubWindowList.front()->setFocus();
else
m_pcActiveWindow = NULL;
m_pcActiveWindow = nullptr;
if( m_pcActiveWindow == nullptr )
{
m_pcApp->setWindowTitle( QApplication::applicationName() );
}
emit changed();
}
@@ -307,11 +320,6 @@ void SubWindowHandle::removeActiveSubWindow()
removeSubWindow( m_pcActiveWindow );
}
SubWindowAbstract* SubWindowHandle::activeSubWindow() const
{
return m_pcActiveWindow;
}
QList<SubWindowAbstract*> SubWindowHandle::findSubWindow( const unsigned int uiCategory ) const
{
QList<SubWindowAbstract*> apcSubWindowList;
@@ -478,12 +486,12 @@ void SubWindowHandle::createActions()
m_actionGroupWindowMode->actions().at( m_iWindowMode )->setChecked( true );
m_arrayActions[CLOSE_ACT] = new QAction( tr( "&Close" ), this );
m_arrayActions[CLOSE_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogCloseButton ) );
m_arrayActions[CLOSE_ACT]->setIcon( m_pcApp->style()->standardIcon( QStyle::SP_DialogCloseButton ) );
m_arrayActions[CLOSE_ACT]->setStatusTip( tr( "Close the active window" ) );
connect( m_arrayActions[CLOSE_ACT], SIGNAL( triggered() ), this, SLOT( removeActiveSubWindow() ) );
m_arrayActions[CLOSE_ACT] = new QAction( tr( "&Close" ), this );
m_arrayActions[CLOSE_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogCloseButton ) );
m_arrayActions[CLOSE_ACT]->setIcon( m_pcApp->style()->standardIcon( QStyle::SP_DialogCloseButton ) );
m_arrayActions[CLOSE_ACT]->setStatusTip( tr( "Close the active window" ) );
connect( m_arrayActions[CLOSE_ACT], SIGNAL( triggered() ), this, SLOT( removeActiveSubWindow() ) );
@@ -506,14 +514,14 @@ void SubWindowHandle::createActions()
m_arrayActions[NEXT_WINDOWS_ACT] = new QAction( tr( "Ne&xt" ), this );
m_arrayActions[NEXT_WINDOWS_ACT]->setShortcuts( QKeySequence::NextChild );
m_arrayActions[NEXT_WINDOWS_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_ArrowRight ) ) );
m_arrayActions[NEXT_WINDOWS_ACT]->setIcon( QIcon( m_pcApp->style()->standardIcon( QStyle::SP_ArrowRight ) ) );
m_arrayActions[NEXT_WINDOWS_ACT]->setStatusTip( tr( "Move the focus to the next window" ) );
// connect( m_arrayActions[NEXT_WINDOWS_ACT], SIGNAL( triggered() ), this,
// SLOT( activateNextSubWindow() ) );
m_arrayActions[PREVIOUS_WINDOWS_ACT] = new QAction( tr( "Pre&vious" ), this );
m_arrayActions[PREVIOUS_WINDOWS_ACT]->setShortcuts( QKeySequence::PreviousChild );
m_arrayActions[PREVIOUS_WINDOWS_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_ArrowLeft ) ) );
m_arrayActions[PREVIOUS_WINDOWS_ACT]->setIcon( QIcon( m_pcApp->style()->standardIcon( QStyle::SP_ArrowLeft ) ) );
m_arrayActions[PREVIOUS_WINDOWS_ACT]->setStatusTip( tr( "Move the focus to the previous window" ) );
// connect( m_arrayActions[PREVIOUS_WINDOWS_ACT], SIGNAL( triggered() ),
// this, SLOT( activatePreviousSubWindow() ) );
@@ -524,12 +532,17 @@ void SubWindowHandle::createActions()
QMenu* SubWindowHandle::createMenu()
{
m_pcMenuWindow = new QMenu( "&Window", this );
m_pcMenuWindow = new QMenu( "&Window", m_pcApp );
updateMenu();
connect( m_pcMenuWindow, SIGNAL( aboutToShow() ), this, SLOT( updateMenu() ) );
return m_pcMenuWindow;
}
auto SubWindowHandle::getWidget() -> QWidget*
{
return m_pcCentralWidget;
}
void SubWindowHandle::updateMenu()
{
m_pcMenuWindow->clear();
+10 -2
View File
@@ -42,7 +42,7 @@ class SubWindowAbstract;
class MdiArea;
class MdiSubWindow;
class SubWindowHandle : public QWidget
class SubWindowHandle : public QObject
{
Q_OBJECT
@@ -53,7 +53,12 @@ public:
void addSubWindow( SubWindowAbstract* widget );
SubWindowAbstract* activeSubWindow() const;
template <class T = SubWindowAbstract>
T* activeSubWindow() const
{
static_assert( std::is_base_of<SubWindowAbstract, T>::value, "T must inherit from SubWindowAbstract" );
return qobject_cast<T*>( m_pcActiveWindow );
}
QList<SubWindowAbstract*> findSubWindow( const unsigned int uiCategory = 0 ) const;
QList<SubWindowAbstract*> findSubWindow( const QString& aName, const unsigned int uiCategory = 0 ) const;
@@ -62,6 +67,8 @@ public:
void createActions();
QMenu* createMenu();
auto getWidget() -> QWidget*;
void readSettings();
void writeSettings();
@@ -76,6 +83,7 @@ private:
int m_iWindowMode;
QList<SubWindowAbstract*> m_apcSubWindowList;
QWidget* m_pcCentralWidget;
QHBoxLayout* m_pcWindowManagerLayout;
MdiArea* m_pcMdiArea;
QList<MdiSubWindow*> m_apcMdiSubWindowList;
+181 -77
View File
@@ -29,8 +29,10 @@
#include <QLabel>
#include <QSignalMapper>
#include <QSlider>
#include <QTimer>
#include <QToolBar>
#include <QtGui>
#include <memory>
#include "FrameNumberWidget.h"
#include "FramePropertiesDock.h"
@@ -38,38 +40,37 @@
#include "SeekStreamDialog.h"
#include "SubWindowHandle.h"
#include "SubWindowSelectorDialog.h"
#include "VideoStreamSubWindow.h"
#include "VideoSubWindow.h"
#include "lib/CalypFrame.h"
VideoHandle::VideoHandle( QWidget* parent, SubWindowHandle* windowManager )
: m_pcParet( parent ), m_pcMainWindowManager( windowManager )
: m_pcParent( parent ), m_pcMainWindowManager( windowManager )
{
m_pcCurrentVideoSubWindow = NULL;
m_bIsPlaying = false;
m_pcPlayingTimer = new QTimer;
m_pcFrameRateFeedbackTimer = new QElapsedTimer;
m_pcPlayingTimer = new QTimer( this );
m_pcFrameRateFeedbackTimer = std::make_unique<QElapsedTimer>();
m_pcPlayingTimer->setTimerType( Qt::PreciseTimer );
connect( m_pcPlayingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) );
connect( m_pcPlayingTimer, &QTimer::timeout,
this, &VideoHandle::playEvent );
m_acPlayingSubWindows.clear();
}
VideoHandle::~VideoHandle()
{
delete m_pcPlayingTimer;
delete m_pcFrameRateFeedbackTimer;
}
VideoHandle::~VideoHandle() = default;
void VideoHandle::createActions()
{
m_arrayActions.resize( TOTAL_ACT );
m_arrayActions[PLAY_ACT] = new QAction( "Play", this );
m_arrayActions[PLAY_ACT]->setStatusTip( "Play/Pause" );
m_arrayActions[PLAY_ACT]->setIcon( QIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaPlay ) ) );
m_arrayActions[PLAY_ACT]->setIcon( QIcon( m_pcParent->style()->standardIcon( QStyle::SP_MediaPlay ) ) );
m_arrayActions[PLAY_ACT]->setShortcut( Qt::Key_Space );
connect( m_arrayActions[PLAY_ACT], SIGNAL( triggered() ), this, SLOT( play() ) );
m_arrayActions[STOP_ACT] = new QAction( "Stop", this );
m_arrayActions[STOP_ACT]->setStatusTip( "Stop" );
m_arrayActions[STOP_ACT]->setIcon( QIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaStop ) ) );
m_arrayActions[STOP_ACT]->setIcon( QIcon( m_pcParent->style()->standardIcon( QStyle::SP_MediaStop ) ) );
connect( m_arrayActions[STOP_ACT], SIGNAL( triggered() ), this, SLOT( stop() ) );
m_mapperVideoSeek = new QSignalMapper( this );
@@ -78,7 +79,7 @@ void VideoHandle::createActions()
m_arrayActions[VIDEO_BACKWARD_ACT] = new QAction( "Video Backward", this );
m_arrayActions[VIDEO_BACKWARD_ACT]->setStatusTip( "Seek backward" );
m_arrayActions[VIDEO_BACKWARD_ACT]->setIcon(
QIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaSeekBackward ) ) );
QIcon( m_pcParent->style()->standardIcon( QStyle::SP_MediaSeekBackward ) ) );
m_arrayActions[VIDEO_BACKWARD_ACT]->setShortcut( Qt::Key_Left );
connect( m_arrayActions[VIDEO_BACKWARD_ACT], SIGNAL( triggered() ), m_mapperVideoSeek, SLOT( map() ) );
m_mapperVideoSeek->setMapping( m_arrayActions[VIDEO_BACKWARD_ACT], 0 );
@@ -86,7 +87,7 @@ void VideoHandle::createActions()
m_arrayActions[VIDEO_FORWARD_ACT] = new QAction( "Video Forward", this );
m_arrayActions[VIDEO_FORWARD_ACT]->setStatusTip( "Seek forward" );
m_arrayActions[VIDEO_FORWARD_ACT]->setIcon(
QIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaSeekForward ) ) );
QIcon( m_pcParent->style()->standardIcon( QStyle::SP_MediaSeekForward ) ) );
m_arrayActions[VIDEO_FORWARD_ACT]->setShortcut( Qt::Key_Right );
connect( m_arrayActions[VIDEO_FORWARD_ACT], SIGNAL( triggered() ), m_mapperVideoSeek, SLOT( map() ) );
m_mapperVideoSeek->setMapping( m_arrayActions[VIDEO_FORWARD_ACT], 1 );
@@ -123,6 +124,24 @@ void VideoHandle::createActions()
connect( m_pcFrameSlider, SIGNAL( valueChanged( int ) ), this, SLOT( seekSliderEvent( int ) ) );
// ------------ Image ------------
m_mapperComponent = new QSignalMapper( this );
m_actionGroupComponent = new QActionGroup( this );
m_actionGroupComponent->setExclusive( true );
m_mapperComponent->setMapping( m_actionGroupComponent->addAction( "All" ), -1 );
m_mapperComponent->setMapping( m_actionGroupComponent->addAction( "Red" ), 0 );
m_mapperComponent->setMapping( m_actionGroupComponent->addAction( "Green" ), 1 );
m_mapperComponent->setMapping( m_actionGroupComponent->addAction( "Blue" ), 2 );
m_mapperComponent->setMapping( m_actionGroupComponent->addAction( "Alpha" ), 3 );
for( int i = 0; i < m_actionGroupComponent->actions().size(); i++ )
{
m_actionGroupComponent->actions().at( i )->setCheckable( true );
m_actionGroupComponent->actions().at( i )->setVisible( false );
connect( m_actionGroupComponent->actions().at( i ), SIGNAL( triggered() ), m_mapperComponent, SLOT( map() ) );
}
m_actionGroupComponent->actions().at( 0 )->setChecked( true );
m_actionGroupComponent->actions().at( 0 )->setVisible( true );
connect( m_mapperComponent, SIGNAL( mapped( int ) ), this, SLOT( setComponent( int ) ) );
m_actionGroupTools = new QActionGroup( this );
m_actionGroupTools->setExclusive( true );
@@ -158,9 +177,11 @@ void VideoHandle::createActions()
m_mapperGrid = new QSignalMapper( this );
m_actionGroupGrid = new QActionGroup( this );
m_actionGroupGrid->setExclusive( true );
m_mapperGrid->setMapping( m_actionGroupGrid->addAction( "4x4" ), 4 );
m_mapperGrid->setMapping( m_actionGroupGrid->addAction( "8x8" ), 8 );
m_mapperGrid->setMapping( m_actionGroupGrid->addAction( "16x16" ), 16 );
m_mapperGrid->setMapping( m_actionGroupGrid->addAction( "64x64" ), 64 );
m_mapperGrid->setMapping( m_actionGroupGrid->addAction( "128x128" ), 128 );
for( int i = 0; i < m_actionGroupGrid->actions().size(); i++ )
{
@@ -178,7 +199,7 @@ void VideoHandle::createActions()
QMenu* VideoHandle::createVideoMenu()
{
m_pcMenuVideo = new QMenu( "Video", m_pcParet );
m_pcMenuVideo = new QMenu( "Video", m_pcParent );
m_pcMenuVideo->addAction( m_arrayActions[PLAY_ACT] );
m_pcMenuVideo->addAction( m_arrayActions[STOP_ACT] );
m_pcMenuVideo->addAction( m_arrayActions[VIDEO_BACKWARD_ACT] );
@@ -193,7 +214,9 @@ QMenu* VideoHandle::createVideoMenu()
QMenu* VideoHandle::createImageMenu()
{
m_pcMenuImage = new QMenu( "Image", m_pcParet );
m_pcMenuImage = new QMenu( "Image", m_pcParent );
m_menuComponent = m_pcMenuImage->addMenu( "Component" );
m_menuComponent->addActions( m_actionGroupComponent->actions() );
m_pcMenuImage->addAction( m_arrayActions[NAVIGATION_TOOL_ACT] );
m_pcMenuImage->addAction( m_arrayActions[SELECTION_TOOL_ACT] );
m_pcMenuImage->addAction( m_arrayActions[BLOCK_SELECTION_TOOL_ACT] );
@@ -228,8 +251,8 @@ QToolBar* VideoHandle::createToolBar()
QDockWidget* VideoHandle::createDock()
{
m_pcFramePropertiesSideBar = new FramePropertiesDock( m_pcParet, &m_bIsPlaying );
m_pcFramePropertiesDock = new QDockWidget( tr( "Frame Information" ), m_pcParet );
m_pcFramePropertiesSideBar = new FramePropertiesDock( m_pcParent, &m_bIsPlaying );
m_pcFramePropertiesDock = new QDockWidget( tr( "Frame Information" ), m_pcParent );
m_pcFramePropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
m_pcFramePropertiesDock->setWidget( m_pcFramePropertiesSideBar );
connect( m_pcFramePropertiesDock, SIGNAL( visibilityChanged( bool ) ), this, SLOT( update() ) );
@@ -268,9 +291,65 @@ QWidget* VideoHandle::createStatusBarMessage()
return pcStatusBarWidget;
}
void VideoHandle::updateComponentMenu()
{
VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow<VideoSubWindow>();
if( pcSubWindow == nullptr )
{
m_menuComponent->setEnabled( false );
return;
}
const auto* frame = pcSubWindow->getCurrFrame();
if( frame == nullptr )
{
m_menuComponent->setEnabled( false );
return;
}
m_menuComponent->setEnabled( true );
for( int i = 1; i < m_actionGroupComponent->actions().size(); i++ )
{
m_actionGroupComponent->actions()[i]->setChecked( false );
m_actionGroupComponent->actions()[i]->setVisible( false );
}
switch( frame->getColorSpace() )
{
case CLP_COLOR_GRAY:
m_actionGroupComponent->actions().at( 1 )->setText( QStringLiteral( "Gray" ) );
m_actionGroupComponent->actions().at( 1 )->setVisible( true );
break;
case CLP_COLOR_YUV:
m_actionGroupComponent->actions().at( 1 )->setText( QStringLiteral( "Luminance" ) );
m_actionGroupComponent->actions().at( 1 )->setVisible( true );
m_actionGroupComponent->actions().at( 2 )->setText( QStringLiteral( "Chrominance U (Cb)" ) );
m_actionGroupComponent->actions().at( 2 )->setVisible( true );
m_actionGroupComponent->actions().at( 3 )->setText( QStringLiteral( "Chrominance V (Cr)" ) );
m_actionGroupComponent->actions().at( 3 )->setVisible( true );
break;
case CLP_COLOR_RGBA:
m_actionGroupComponent->actions().at( 4 )->setText( QStringLiteral( "Alpha" ) );
m_actionGroupComponent->actions().at( 4 )->setVisible( true );
[[fallthrough]];
case CLP_COLOR_RGB:
m_actionGroupComponent->actions().at( 1 )->setText( QStringLiteral( "Red" ) );
m_actionGroupComponent->actions().at( 1 )->setVisible( true );
m_actionGroupComponent->actions().at( 2 )->setText( QStringLiteral( "Green" ) );
m_actionGroupComponent->actions().at( 2 )->setVisible( true );
m_actionGroupComponent->actions().at( 3 )->setText( QStringLiteral( "Blue" ) );
m_actionGroupComponent->actions().at( 3 )->setVisible( true );
break;
default:
Q_ASSERT( false );
}
auto component = pcSubWindow->getViewArea()->getFilteredChannel();
int idx = component.has_value() ? *component : 0;
m_actionGroupComponent->actions().at( idx )->setChecked( true );
}
void VideoHandle::updateMenus()
{
VideoSubWindow* pcSubWindow = qobject_cast<VideoSubWindow*>( m_pcMainWindowManager->activeSubWindow() );
VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow<VideoSubWindow>();
bool hasSubWindow = pcSubWindow ? true : false;
m_arrayActions[PLAY_ACT]->setEnabled( hasSubWindow );
@@ -296,6 +375,8 @@ void VideoHandle::updateMenus()
m_arrayActions[SELECTION_TOOL_ACT]->setEnabled( hasSubWindow );
m_arrayActions[BLOCK_SELECTION_TOOL_ACT]->setEnabled( hasSubWindow );
m_arrayActions[SHOW_GRID_ACT]->setEnabled( hasSubWindow );
updateComponentMenu();
}
void VideoHandle::readSettings()
@@ -326,10 +407,16 @@ void VideoHandle::update()
{
if( m_pcCurrentVideoSubWindow )
{
CalypStream* pcStream = m_pcCurrentVideoSubWindow->getInputStream();
CalypFrame* pcFrame = m_pcCurrentVideoSubWindow->getCurrFrame();
bool isPlaying{ false };
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;
if( pcFrame )
@@ -363,8 +450,7 @@ void VideoHandle::update()
}
}
m_pcResolutionLabel->setText( resolution );
m_pcFramePropertiesSideBar->setFrame( pcFrame, m_pcCurrentVideoSubWindow->isPlaying() );
m_pcFramePropertiesSideBar->setFrame( pcFrame, isPlaying );
m_pcFrameNumInfo->setTotalFrameNum( total_frame_num );
m_pcFrameNumInfo->setCurrFrameNum( frame_num );
@@ -382,12 +468,12 @@ void VideoHandle::update()
if( m_pcCurrentVideoSubWindow->isPlaying() )
{
m_arrayActions[PLAY_ACT]->setText( "Pause" );
m_arrayActions[PLAY_ACT]->setIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaPause ) );
m_arrayActions[PLAY_ACT]->setIcon( m_pcParent->style()->standardIcon( QStyle::SP_MediaPause ) );
}
else
{
m_arrayActions[PLAY_ACT]->setText( "Play" );
m_arrayActions[PLAY_ACT]->setIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaPlay ) );
m_arrayActions[PLAY_ACT]->setIcon( m_pcParent->style()->standardIcon( QStyle::SP_MediaPlay ) );
}
}
else
@@ -435,18 +521,21 @@ void VideoHandle::addSubWindow( VideoSubWindow* window )
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 );
m_acPlayingSubWindows.at( pos )->stop();
int pos = m_acPlayingSubWindows.indexOf( videoStreamSubWindow );
m_acPlayingSubWindows.remove( pos );
if( m_acPlayingSubWindows.size() < 2 )
{
m_arrayActions[VIDEO_LOCK_ACT]->setVisible( false );
}
}
if( subWindow == m_pcCurrentVideoSubWindow )
{
m_pcFramePropertiesSideBar->reset();
}
}
void VideoHandle::zoomToFactorAll( const double scale, const QPoint center )
@@ -539,18 +628,18 @@ unsigned long VideoHandle::getMaxFrameNumber()
unsigned long maxFrames = INT_MAX;
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++ )
{
currFrames = m_acPlayingSubWindows.at( i )->getInputStream()->getFrameNum();
currFrames = m_acPlayingSubWindows.at( i )->getFrameNum();
if( currFrames < maxFrames )
maxFrames = currFrames;
}
}
else
{
maxFrames = m_pcCurrentVideoSubWindow->getInputStream()->getFrameNum();
maxFrames = m_pcCurrentVideoSubWindow->getFrameNum();
}
}
return maxFrames;
@@ -563,9 +652,9 @@ void VideoHandle::setTimerStatus()
{
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 )
{
@@ -594,13 +683,12 @@ void VideoHandle::configureFrameRateTimer()
void VideoHandle::play()
{
if( !m_pcCurrentVideoSubWindow )
auto* videoStreamSubWindow = qobject_cast<VideoStreamSubWindow*>( m_pcCurrentVideoSubWindow );
if( videoStreamSubWindow == nullptr )
return;
if( !m_pcCurrentVideoSubWindow->getInputStream() )
return;
if( !m_pcCurrentVideoSubWindow->isPlaying() ) // Not playing
if( !videoStreamSubWindow->isPlaying() ) // Not playing
{
if( m_acPlayingSubWindows.size() < 2 )
{
@@ -609,9 +697,9 @@ void VideoHandle::play()
m_acPlayingSubWindows.at( i )->pause();
}
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++ )
{
@@ -622,7 +710,7 @@ void VideoHandle::play()
}
else
{
if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) )
if( m_acPlayingSubWindows.contains( videoStreamSubWindow ) )
{
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
@@ -631,12 +719,11 @@ void VideoHandle::play()
}
else
{
m_pcCurrentVideoSubWindow->pause();
videoStreamSubWindow->pause();
}
}
setTimerStatus();
emit changed();
// update();
}
void VideoHandle::stop()
@@ -673,8 +760,10 @@ void VideoHandle::calculateRealFrameRate()
void VideoHandle::playEvent()
{
// 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
// Lets assum 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
// So no changed is emmited
bool bShouldRefreshUI = false;
calculateRealFrameRate();
@@ -707,25 +796,28 @@ void VideoHandle::playEvent()
}
catch( const char* msg )
{
QString warningMsg = "Error while playing " +
QFileInfo( m_pcCurrentVideoSubWindow->getCurrentFileName() ).fileName() +
" with the following error: \n" + msg;
QMessageBox::warning( m_pcParet, QApplication::applicationName(), warningMsg );
QString warningMsg = "Error while playing " + m_pcCurrentVideoSubWindow->getWindowName() + " with the following error: \n" + msg;
QMessageBox::warning( m_pcParent, QApplication::applicationName(), warningMsg );
qDebug() << warningMsg;
stop();
m_pcCurrentVideoSubWindow->close();
}
if( bShouldRefreshUI )
emit changed();
// auto end = std::chrono::steady_clock::now();
// std::cout << "Elapsed time going to next frame: "
// << std::chrono::duration_cast<std::chrono::milliseconds>( end - start ).count()
// << " ms" << std::endl;
}
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 ) )
{
for( auto playingSubWindow : m_acPlayingSubWindows )
@@ -736,7 +828,7 @@ void VideoHandle::seekEvent( int direction )
}
else
{
m_pcCurrentVideoSubWindow->seekRelativeEvent( direction > 0 ? true : false );
videoStreamSubWindow->seekRelativeEvent( direction > 0 ? true : false );
}
emit changed();
}
@@ -744,37 +836,37 @@ void VideoHandle::seekEvent( int direction )
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_pcParent );
int newFrameNum = dialogSeekVideo->runDialog();
if( newFrameNum >= 0 )
{
SeekStreamDialog* dialogSeekVideo =
new SeekStreamDialog( m_pcCurrentVideoSubWindow->getInputStream(), m_pcParet );
int newFrameNum = dialogSeekVideo->runDialog();
if( newFrameNum >= 0 )
if( m_acPlayingSubWindows.contains( videoStreamSubWindow ) )
{
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 )
{
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 )
{
@@ -783,7 +875,7 @@ void VideoHandle::seekSliderEvent( int new_frame_num )
}
else
{
m_pcCurrentVideoSubWindow->seekAbsoluteEvent( (unsigned int)new_frame_num );
videoStreamSubWindow->seekAbsoluteEvent( (unsigned int)new_frame_num );
}
emit changed();
}
@@ -791,8 +883,6 @@ void VideoHandle::seekSliderEvent( int new_frame_num )
void VideoHandle::videoSelectionButtonEvent()
{
VideoSubWindow* videoSubWindow;
Qt::KeyboardModifiers keyModifiers = QApplication::keyboardModifiers();
if( keyModifiers & Qt::ControlModifier )
{
@@ -800,13 +890,13 @@ void VideoHandle::videoSelectionButtonEvent()
m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_STREAM_SUBWINDOW );
for( auto subWindow : subWindowList )
{
videoSubWindow = qobject_cast<VideoSubWindow*>( subWindow );
auto* videoSubWindow = qobject_cast<VideoStreamSubWindow*>( subWindow );
m_acPlayingSubWindows.append( videoSubWindow );
}
}
else
{
SubWindowSelectorDialog dialogWindowsSelection( m_pcParet, m_pcMainWindowManager,
SubWindowSelectorDialog dialogWindowsSelection( m_pcParent, m_pcMainWindowManager,
SubWindowAbstract::VIDEO_STREAM_SUBWINDOW );
QStringList cWindowListNames;
for( auto playingSubWindow : m_acPlayingSubWindows )
@@ -820,7 +910,7 @@ void VideoHandle::videoSelectionButtonEvent()
QList<SubWindowAbstract*> selectedSubWindowList = dialogWindowsSelection.getSelectedWindows();
for( auto window : selectedSubWindowList )
{
videoSubWindow = qobject_cast<VideoSubWindow*>( window );
auto* videoSubWindow = qobject_cast<VideoStreamSubWindow*>( window );
m_acPlayingSubWindows.append( videoSubWindow );
}
}
@@ -851,6 +941,20 @@ void VideoHandle::videoSelectionButtonEvent()
}
}
void VideoHandle::setComponent( int component )
{
if( m_pcCurrentVideoSubWindow == nullptr )
return;
if( component < 0 )
{
m_pcCurrentVideoSubWindow->getViewArea()->clearFilteredChannel();
}
else
{
m_pcCurrentVideoSubWindow->getViewArea()->setFilteredChannel( static_cast<std::size_t>( component ) );
}
}
void VideoHandle::setTool( int tool )
{
m_uiViewTool = tool;
+17 -8
View File
@@ -25,6 +25,7 @@
#ifndef __VIDEOHANDLE_H__
#define __VIDEOHANDLE_H__
#include <QElapsedTimer>
#include <QMenu>
#include <QPoint>
#include <QThread>
@@ -32,6 +33,7 @@
#include <QWidget>
#include "CommonDefs.h"
#include "VideoSubWindow.h"
#include "config.h"
class QToolBar;
@@ -39,13 +41,13 @@ class QDockWidget;
class QSignalMapper;
class QLabel;
class QSlider;
class QElapsedTimer;
class SubWindowHandle;
class SubWindowAbstract;
class VideoSubWindow;
class VideoStreamSubWindow;
class FramePropertiesDock;
class FrameNumberWidget;
class QTimer;
class VideoHandle : public QObject
{
@@ -70,7 +72,7 @@ public:
void addSubWindow( VideoSubWindow* subWindow );
private:
QWidget* m_pcParet;
QWidget* m_pcParent;
SubWindowHandle* m_pcMainWindowManager;
enum
{
@@ -95,6 +97,11 @@ private:
QSlider* m_pcFrameSlider;
FrameNumberWidget* m_pcFrameNumInfo;
// Filter component actions
QMenu* m_menuComponent;
QActionGroup* m_actionGroupComponent;
QSignalMapper* m_mapperComponent;
// Tools Actions
QActionGroup* m_actionGroupTools;
QSignalMapper* m_mapperTools;
@@ -115,20 +122,21 @@ private:
QLabel* m_pcVideoFormatLabel;
QLabel* m_pcResolutionLabel;
VideoSubWindow* m_pcCurrentVideoSubWindow;
QVector<VideoSubWindow*> m_acPlayingSubWindows;
QPointer<VideoSubWindow> m_pcCurrentVideoSubWindow;
QVector<VideoStreamSubWindow*> m_acPlayingSubWindows;
QTimer* m_pcPlayingTimer;
bool m_bIsPlaying;
unsigned int m_uiNumberPlayedFrames;
unsigned int m_uiRealAverageFrameRate;
QElapsedTimer* m_pcFrameRateFeedbackTimer;
unsigned int m_uiNumberPlayedFrames{ 0 };
unsigned int m_uiRealAverageFrameRate{ 0 };
std::unique_ptr<QElapsedTimer> m_pcFrameRateFeedbackTimer;
void configureFrameRateTimer();
void calculateRealFrameRate();
unsigned long getMaxFrameNumber();
void setTimerStatus();
void updateComponentMenu();
Q_SIGNALS:
void changed();
@@ -148,6 +156,7 @@ private Q_SLOTS:
void seekEvent( int direction );
void seekVideo();
void videoSelectionButtonEvent();
void setComponent( int component );
void setTool( int tool );
void toggleGrid( bool checked );
void setGridSize( int size );
+604
View File
@@ -0,0 +1,604 @@
/* 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 << d.m_bForceRaw;
}
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;
in >> d.m_bForceRaw;
array.append( d );
}
return in;
}
auto findCalypStreamInfo( const CalypFileInfoVector& array, const QString& filename ) -> int
{
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() & ClpModuleFeature::HasInfo )
{
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;
auto InputFormat = ClpPixelFormats::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 };
bool forceRaw{ 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, iPass == 1, CalypStream::Type::Input );
forceRaw = iPass > 0;
}
catch( CalypFailure& e )
{
if( iPass > 0 )
throw( e );
}
}
if( !bRet )
{
return false;
}
m_sStreamInfo.m_cFilename = cFilename;
m_sStreamInfo.m_uiWidth = Width;
m_sStreamInfo.m_uiHeight = Height;
m_sStreamInfo.m_iPelFormat = static_cast<std::int64_t>( InputFormat );
m_sStreamInfo.m_uiBitsPelPixel = BitsPel;
m_sStreamInfo.m_iEndianness = Endianness;
m_sStreamInfo.m_uiFrameRate = FrameRate;
m_sStreamInfo.m_uiFileSize = QFileInfo( cFilename ).size();
m_sStreamInfo.m_bForceRaw = forceRaw;
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,
static_cast<ClpPixelFormats>( streamInfo.m_iPelFormat ), streamInfo.m_uiBitsPelPixel, streamInfo.m_iEndianness,
streamInfo.m_uiFrameRate, streamInfo.m_bForceRaw, CalypStream::Type::Input ) )
{
return false;
}
m_cFilename = streamInfo.m_cFilename;
m_sStreamInfo = std::move( streamInfo );
#ifdef CALYP_MANAGED_RESOURCES
m_pcResourceManager->startResourceWorker( m_uiResourceId );
#endif
QApplication::restoreOverrideCursor();
refreshFrame();
updateVideoWindowInfo();
setWindowName( QFileInfo( m_cFilename ).fileName() );
return true;
}
bool VideoStreamSubWindow::guessFormat( const QString& filename, unsigned int& rWidth, unsigned int& rHeight, ClpPixelFormats& 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
const auto& formats_list = CalypFrame::supportedPixelFormatListNames();
for( const auto& [key, name] : formats_list )
{
if( FilenameShort.contains( QString::fromStdString( std::string( name ) ), Qt::CaseInsensitive ) )
{
rInputFormat = key;
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 != ClpPixelFormats::Invalid )
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( const 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;
}
+135
View File
@@ -0,0 +1,135 @@
/* 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;
struct CalypFileInfo
{
QString m_cFilename;
unsigned int m_uiWidth;
unsigned int m_uiHeight;
int m_iPelFormat;
unsigned int m_uiBitsPelPixel;
int m_iEndianness;
unsigned int m_uiFrameRate;
unsigned long long int m_uiFileSize;
bool m_bForceRaw{ false };
};
using CalypFileInfoVector = QVector<CalypFileInfo>;
QDataStream& operator<<( QDataStream& out, const CalypFileInfoVector& d );
QDataStream& operator>>( QDataStream& in, CalypFileInfoVector& d );
auto findCalypStreamInfo( const CalypFileInfoVector& array, const QString& filename ) -> int;
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 supportsFormatConfiguration() const { return m_pCurrStream->supportsFormatConfiguration(); };
bool loadFile( QString cFilename, bool bForceDialog = false );
bool loadFile( CalypFileInfo streamInfo );
void loadAll();
bool saveStream( const 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( const QString& filename, unsigned int& rWidth, unsigned int& rHeight, ClpPixelFormats& 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__
+203 -735
View File
File diff suppressed because it is too large. Load diff
+76 -112
View File
@@ -28,9 +28,11 @@
#include <QDataStream>
#include <QFuture>
#include <QRect>
#include <QStaticText>
#include <QString>
#include <QVector>
#include "CalypAppModuleIf.h"
#include "CommonDefs.h"
#include "SubWindowAbstract.h"
#include "ViewArea.h"
@@ -41,67 +43,35 @@ class QScrollArea;
class VideoInformation;
class VideoSubWindow;
class ResourceHandle;
class CalypAppModuleIf;
typedef struct
/**
* \class VideoInformation
* \brief Shows information about video sub window
*/
class VideoInformation : public QWidget
{
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;
public:
VideoInformation( QWidget* parent );
void setInformationTopLeft( const QStringList& textLines );
void setBusyWindow( bool bFlag );
QDataStream& operator<<( QDataStream& out, const CalypFileInfoVector& d );
QDataStream& operator>>( QDataStream& in, CalypFileInfoVector& d );
int findCalypStreamInfo( CalypFileInfoVector array, QString filename );
protected:
void paintEvent( QPaintEvent* event ) override;
private:
QTimer* m_pcRefreshTimer;
QList<QStaticText> m_cTopLeftTextList;
QFont m_cTopLeftTextFont;
QFont m_cCenterTextFont;
bool m_bBusyWindow;
};
class VideoSubWindow : public SubWindowAbstract
{
Q_OBJECT
private:
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;
CalypStream* m_pCurrStream;
CalypFrame* m_pcCurrFrame;
QRect m_cSelectedArea;
CalypAppModuleIf* m_pcCurrentDisplayModule;
QList<CalypAppModuleIf*> m_apcCurrentModule;
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:
enum VideoSubWindowCategories
{
@@ -111,89 +81,63 @@ public:
VideoSubWindow( enum VideoSubWindowCategories category, QWidget* parent = 0 );
~VideoSubWindow();
void updateVideoWindowInfo();
virtual void resetWindowName() = 0;
virtual void updateVideoWindowInfo() = 0;
bool loadFile( QString cFilename, bool bForceDialog = false );
bool loadFile( CalypFileInfo* streamInfo );
void loadAll();
bool save( QString filename );
bool saveStream( QString filename );
virtual bool isPlaying() = 0;
virtual void stop() = 0;
virtual void advanceOneFrame() = 0;
virtual auto getFrameNum() -> std::uint64_t { return 1; };
void refreshSubWindow();
void refreshFrame( bool bThreaded = false );
QString getVideoInformation() { return m_cStreamInformation; }
bool save( const QString& filename );
bool play();
void pause();
bool playEvent();
void stop();
void setCurrFrame( std::shared_ptr<CalypFrame> pcCurrFrame );
bool isPlaying();
void seekAbsoluteEvent( unsigned int new_frame_num );
void seekRelativeEvent( bool bIsFoward );
auto getCurrFrame() -> CalypFrame* { return m_pcCurrFrameAsset.get(); }
auto getCurrFrameAsset() -> std::shared_ptr<CalypFrame> { return m_pcCurrFrameAsset; };
auto getViewArea() -> ViewArea* { return m_cViewArea; }
void setCurrFrame( CalypFrame* pcCurrFrame );
CalypFileInfo getStreamInfo() { return m_sStreamInfo; }
QString getStreamInformation() { return m_cStreamInformation; }
CalypStream* getInputStream() { return m_pCurrStream; }
CalypStream* getCurrStream() { return m_pCurrStream; }
CalypFrame* getCurrFrame() { return m_pcCurrFrame; }
ViewArea* getViewArea() { return m_cViewArea; }
VideoSubWindow* getRefSubWindow() { return m_pcReferenceSubWindow; }
void setRefSubWindow( VideoSubWindow* subWindow )
{
m_pcReferenceSubWindow = NULL;
if( subWindow )
if( m_pcCurrFrame->haveSameFmt( subWindow->getCurrFrame() ) )
if( m_pcCurrFrameAsset->haveSameFmt( subWindow->getCurrFrame() ) )
m_pcReferenceSubWindow = subWindow;
}
VideoSubWindow* getRefSubWindow() { return m_pcReferenceSubWindow; }
/**
* Functions to enable a module in the
* current SubWindow
*/
void enableModule( CalypAppModuleIf* pcModule );
void disableModule( CalypAppModuleIf* pcModule = NULL );
void associateModule( CalypAppModuleIf* pcModule );
CalypAppModuleIf* getDisplayModule() { return m_pcCurrentDisplayModule; }
QList<CalypAppModuleIf*> getModuleArray()
{
QList<CalypAppModuleIf*> apcModulesArray;
if( m_pcCurrentDisplayModule )
apcModulesArray.append( m_pcCurrentDisplayModule );
apcModulesArray.append( m_apcCurrentModule );
return apcModulesArray;
}
auto hasModules() -> bool { return m_associatedModules.size() > 0; }
bool hasAssociatedModule();
void setDisplayModule( CalypAppModuleIf* pcModule );
void associateModule( std::shared_ptr<CalypAppModuleIf> pcModule );
void disableModule( CalypAppModuleIf* pcModule );
bool disableAllModules();
CalypAppModuleIf* getDisplayModule() { return m_pcDisplayModule; }
/**
* Virtual functions from SubWindowAbstract
*/
void normalSize();
void zoomToFit();
void scaleView( double scale, QPoint center = QPoint() );
void zoomToFactor( double factor, QPoint center = QPoint() );
void normalSize() override;
void zoomToFit() override;
void scaleView( double scale, QPoint center = QPoint() ) override;
void zoomToFactor( double factor, QPoint center = QPoint() ) override;
double getScaleFactor() { return m_cViewArea->getZoomFactor(); }
double getScaleFactor() override { return m_cViewArea->getZoomFactor(); }
/**
* Size related functions
*/
QSize sizeHint() const;
QSize sizeHint( const QSize& ) const;
QSize sizeHint( const QSize& ) const override;
QString getCurrentFileName() { return m_cFilename; }
void clearWindowBusy() { m_bWindowBusy = false; }
void setFillWindow( bool bFlag );
void adjustScrollBarToRatio( const double& horRatio, const double& verRatio );
void adjustScrollBarToRatio( const double horRatio, const double verRatio );
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();
/**
@@ -205,9 +149,11 @@ private:
QSize getScrollSize();
protected:
void keyPressEvent( QKeyEvent* event );
void resizeEvent( QResizeEvent* event );
void closeEvent( QCloseEvent* event );
void refreshFrame();
void keyPressEvent( QKeyEvent* event ) override;
void resizeEvent( QResizeEvent* event ) override;
void closeEvent( QCloseEvent* event ) override;
public Q_SLOTS:
void updateWindowOnTimeout();
@@ -216,9 +162,27 @@ public Q_SLOTS:
void updateScrollValues();
void updateSelectedArea( QRect area );
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{ 0 };
double m_dVerScroll{ 0 };
ViewArea* m_cViewArea;
QRect m_cSelectedArea;
VideoSubWindow* m_pcReferenceSubWindow;
QTimer* m_pcUpdateTimer;
};
Q_DECLARE_METATYPE( CalypFileInfo )
Q_DECLARE_METATYPE( CalypFileInfoVector )
#endif // __VIDEOSUBWINDOW_H__
+159 -119
View File
@@ -25,6 +25,9 @@
#include "ViewArea.h"
#include <qcolor.h>
#include <qnamespace.h>
#include <QColor>
#include <QCoreApplication>
#include <QDebug>
@@ -40,65 +43,98 @@
#include "GridManager.h"
static const QColor selectionColor = Qt::cyan;
static const QColor imageMaskColor = Qt::green;
static const QColor eraserColor = Qt::red;
#if QT_VERSION >= QT_VERSION_CHECK( 5, 14, 0 )
constexpr auto kSelectionColor = QColorConstants::Cyan;
constexpr auto kImageMaskColor = QColorConstants::Green;
constexpr auto kEraserColor = QColorConstants::Red;
#else
static const QColor kSelectionColor = Qt::cyan;
static const QColor kImageMaskColor = Qt::green;
static const QColor kEraserColor = Qt::red;
#endif
constexpr double kMaxZoom = 100.0;
constexpr double kMinZoom = 0.01;
ViewArea::ViewArea( QWidget* parent )
: QWidget( parent )
{
setMouseTracking( true );
m_pcCurrFrame = NULL;
m_pixmap = QPixmap();
m_grid = GridManager();
m_mask = QBitmap();
m_selectedArea = QRect();
m_dZoomFactor = 1;
m_xOffset = 0;
m_yOffset = 0;
m_mode = NormalMode;
m_eTool = NavigationTool;
m_bGridVisible = false;
m_snapToGrid = false;
m_blockTrackEnable = false;
m_visibleZoomRect = true;
m_zoomWinTimer.setSingleShot( true );
m_zoomWinTimer.setInterval( 2000 );
connect( &m_zoomWinTimer, SIGNAL( timeout() ), this, SLOT( update() ) );
}
void ViewArea::setImage( CalypFrame* pcFrame )
void ViewArea::setImage( std::shared_ptr<CalypFrame> frame )
{
m_pcCurrFrame = pcFrame;
m_uiPixelHalfScale = 1 << ( m_pcCurrFrame->getBitsPel() - 1 );
m_pcCurrFrame->fillRGBBuffer();
QImage qimg = QImage( m_pcCurrFrame->getRGBBuffer(), m_pcCurrFrame->getWidth(), m_pcCurrFrame->getHeight(),
QImage::Format_ARGB32 );
setImage( QPixmap::fromImage( qimg ) );
}
m_nextFrame = frame;
m_uiPixelHalfScale = 1 << ( m_nextFrame->getBitsPel() - 1 );
if( m_filterSingleChannel.has_value() )
{
m_nextFrame->fillRGBBuffer( m_filterSingleChannel );
}
else
{
m_nextFrame->fillRGBBuffer();
}
void ViewArea::setImage( const QPixmap& pixmap )
{
m_pixmap = pixmap;
m_mask = QBitmap( pixmap.width(), pixmap.height() );
m_mask.clear();
m_image = QImage( m_nextFrame->getRGBBuffer(),
m_nextFrame->getWidth(),
m_nextFrame->getHeight(),
QImage::Format_ARGB32 );
// m_mask = QBitmap( pixmap.width(), pixmap.height() );
// m_mask.clear();
updateSize();
update();
updateGeometry();
initZoomWinRect();
}
void ViewArea::clear()
// void ViewArea::clear()
// {
// m_image = QImage();
// m_mask = QBitmap();
// m_mode = NormalMode;
// updateSize();
// update();
// updateGeometry();
// }
auto ViewArea::getFilteredChannel() -> std::optional<std::size_t>
{
m_pixmap = QPixmap();
m_mask = QBitmap();
m_mode = NormalMode;
updateSize();
return m_filterSingleChannel;
}
void ViewArea::setFilteredChannel( std::size_t channel )
{
m_filterSingleChannel = channel;
if( m_nextFrame != nullptr )
{
m_nextFrame->fillRGBBuffer( m_filterSingleChannel );
m_image = QImage( m_nextFrame->getRGBBuffer(),
m_nextFrame->getWidth(),
m_nextFrame->getHeight(),
QImage::Format_ARGB32 );
}
update();
}
void ViewArea::clearFilteredChannel()
{
m_filterSingleChannel = {};
if( m_nextFrame != nullptr )
{
m_nextFrame->fillRGBBuffer( m_filterSingleChannel );
m_image = QImage( m_nextFrame->getRGBBuffer(),
m_nextFrame->getWidth(),
m_nextFrame->getHeight(),
QImage::Format_ARGB32 );
}
update();
updateGeometry();
}
void ViewArea::setTool( unsigned int view )
@@ -166,14 +202,14 @@ void ViewArea::setZoomFactor( double f )
double ViewArea::scaleZoomFactor( double scale, QPoint center, QSize minimumSize )
{
double maxZoom = 100.0;
double minZoom = 0.01; //( 1.0 / m_pixmap.width() );
Q_ASSERT( !m_image.isNull() );
double new_scale = 1.0;
if( ( m_dZoomFactor == minZoom ) && ( scale < 1 ) )
if( ( m_dZoomFactor == kMinZoom ) && ( scale < 1 ) )
return new_scale;
if( ( m_dZoomFactor == maxZoom ) && ( scale > 1 ) )
if( ( m_dZoomFactor == kMaxZoom ) && ( scale > 1 ) )
return new_scale;
double newZoomFactor = m_dZoomFactor * scale * 100.0;
@@ -183,10 +219,10 @@ double ViewArea::scaleZoomFactor( double scale, QPoint center, QSize minimumSize
if( !minimumSize.isNull() )
{
double cw = m_pixmap.width() * m_dZoomFactor;
double ch = m_pixmap.height() * m_dZoomFactor;
double fw = m_pixmap.width() * newZoomFactor;
double fh = m_pixmap.height() * newZoomFactor;
double cw = m_image.width() * m_dZoomFactor;
double ch = m_image.height() * m_dZoomFactor;
double fw = m_image.width() * newZoomFactor;
double fh = m_image.height() * newZoomFactor;
double mw = minimumSize.width();
double mh = minimumSize.height();
@@ -214,16 +250,16 @@ double ViewArea::scaleZoomFactor( double scale, QPoint center, QSize minimumSize
new_scale = scale;
if( newZoomFactor < minZoom )
if( newZoomFactor < kMinZoom )
{
newZoomFactor = minZoom;
newZoomFactor = kMinZoom;
new_scale = newZoomFactor / m_dZoomFactor;
}
else
{
if( newZoomFactor > maxZoom )
if( newZoomFactor > kMaxZoom )
{
newZoomFactor = maxZoom;
newZoomFactor = kMaxZoom;
new_scale = newZoomFactor / m_dZoomFactor;
}
}
@@ -319,45 +355,45 @@ void ViewArea::setSnapToGrid( bool enable )
void ViewArea::initZoomWinRect()
{
int iMinX = 80;
int iMinY = 80;
double iMinX = 80;
double iMinY = 80;
int iMaxX = iMinX * 5;
int iMaxY = iMinY * 5;
double iMaxX = iMinX * 5;
double iMaxY = iMinY * 5;
double dSizeRatio, dWinZoomRatio;
int iHorizontalImg = ( m_pixmap.width() > m_pixmap.height() ) ? 1 : 0;
bool iHorizontalImg = m_image.width() > m_image.height();
if( iHorizontalImg )
{
dSizeRatio = (double)m_pixmap.width() / (double)m_pixmap.height();
dSizeRatio = (double)m_image.width() / (double)m_image.height();
}
else
{
dSizeRatio = (double)m_pixmap.height() / (double)m_pixmap.width();
dSizeRatio = (double)m_image.height() / (double)m_image.width();
}
if( dSizeRatio > 5.0 )
{
if( iHorizontalImg )
{
dWinZoomRatio = (double)( m_pixmap.width() * 1024 / iMaxX ) / 1000.0;
dWinZoomRatio = static_cast<double>( m_image.width() ) * 1024.0 / iMaxX / 1000.0;
}
else
{
dWinZoomRatio = (double)( m_pixmap.height() * 1024 / iMaxY ) / 1000.0;
dWinZoomRatio = static_cast<double>( m_image.height() ) * 1024.0 / iMaxY / 1000.0;
}
}
else
{
if( iHorizontalImg )
{
dWinZoomRatio = (double)( m_pixmap.height() * 1024 / iMinY ) / 1000.0;
dWinZoomRatio = static_cast<double>( m_image.height() ) * 1024.0 / iMinY / 1000.0;
}
else
{
dWinZoomRatio = (double)( m_pixmap.width() * 1024 / iMinX ) / 1000.0;
dWinZoomRatio = static_cast<double>( m_image.width() ) * 1024.0 / iMinX / 1000.0;
}
}
@@ -369,8 +405,8 @@ void ViewArea::initZoomWinRect()
////////////////////////////////////////////////////////////////////////////////
void ViewArea::updateSize()
{
int w = m_pixmap.width() * m_dZoomFactor;
int h = m_pixmap.height() * m_dZoomFactor;
int w = m_image.width() * m_dZoomFactor;
int h = m_image.height() * m_dZoomFactor;
setMinimumSize( w, h );
QWidget* p = parentWidget();
@@ -388,17 +424,17 @@ void ViewArea::updateSize()
void ViewArea::updateOffset()
{
if( width() > m_pixmap.width() * m_dZoomFactor )
if( width() > m_image.width() * m_dZoomFactor )
{
m_xOffset = ( width() - m_pixmap.width() * m_dZoomFactor ) / 2;
m_xOffset = ( width() - m_image.width() * m_dZoomFactor ) / 2;
}
else
{
m_xOffset = 0;
}
if( height() > m_pixmap.height() * m_dZoomFactor )
if( height() > m_image.height() * m_dZoomFactor )
{
m_yOffset = ( height() - m_pixmap.height() * m_dZoomFactor ) / 2;
m_yOffset = ( height() - m_image.height() * m_dZoomFactor ) / 2;
}
else
{
@@ -411,7 +447,7 @@ void ViewArea::updateOffset()
////////////////////////////////////////////////////////////////////////////////
void ViewArea::resizeEvent( QResizeEvent* event )
{
if( size().isEmpty() || m_pixmap.isNull() )
if( size().isEmpty() || m_image.isNull() )
return;
updateOffset();
@@ -424,12 +460,11 @@ void ViewArea::resizeEvent( QResizeEvent* event )
void ViewArea::paintEvent( QPaintEvent* event )
{
m_currFrame = m_nextFrame;
QRect winRect = event->rect();
if( visibleRegion().isEmpty() )
return;
if( size().isEmpty() || m_pixmap.isNull() )
if( visibleRegion().isEmpty() || size().isEmpty() || m_image.isNull() || m_currFrame == nullptr )
return;
QSize windowSize = parentWidget()->size();
@@ -442,15 +477,14 @@ void ViewArea::paintEvent( QPaintEvent* event )
// This line is for fast paiting. Only visible area of the image is painted.
// We take the exposed rect from the event (that gives us scroll/expose
// optimizations for free – no need
// to draw the whole pixmap if your widget is only partially exposed), and
// reverse map it with the painter matrix.
// optimizations for free – no need to draw the whole pixmap if your widget
// is only partially exposed), and reverse map it with the painter matrix.
// That gives us the part of the pixmap that has actually been exposed.
// See:
// http://blog.qt.digia.com/blog/2006/05/13/fast-transformed-pixmapimage-drawing/
QRect exposedRect = painter.worldTransform().inverted().mapRect( event->rect() ).adjusted( -1, -1, 1, 1 );
// See: http://blog.qt.digia.com/blog/2006/05/13/fast-transformed-pixmapimage-drawing/
QRect exposedRect = painter.worldTransform().inverted().mapRect( winRect ).adjusted( -1, -1, 1, 1 );
// Draw the pixmap.
painter.drawPixmap( exposedRect, m_pixmap, exposedRect );
// painter.drawPixmap( exposedRect, m_pixmap, exposedRect );
painter.drawImage( exposedRect, m_image, exposedRect );
// Draw the Grid if it's visible.
if( m_bGridVisible )
@@ -468,33 +502,33 @@ void ViewArea::paintEvent( QPaintEvent* event )
// is, is referenced to the not scaled image.
// To know what image area we need to update, just intersects the
// rectangle area with the image area.
vr &= QRect( 0, 0, m_pixmap.width(), m_pixmap.height() );
vr &= QRect( 0, 0, m_image.width(), m_image.height() );
// Set up for the grid drawer.
painter.setRenderHint( QPainter::Antialiasing );
// Draw grid.
m_grid.drawGrid( m_pixmap, vr, &painter );
m_grid.drawGrid( m_image, vr, &painter );
}
painter.restore();
// Draw a border around the image.
/* if( m_xOffset || m_yOffset )
{
painter.setPen( Qt::black );
painter.drawRect( m_xOffset - 1, m_yOffset - 1, m_pixmap.width() *
m_dZoomFactor + 1, m_pixmap.height() *
m_dZoomFactor + 1 );
}*/
{
painter.setPen( Qt::black );
painter.drawRect( m_xOffset - 1, m_yOffset - 1, m_image.width() *
m_dZoomFactor + 1, m_image.height() *
m_dZoomFactor + 1 );
}*/
int frFormat = m_pcCurrFrame->getColorSpace();
int frFormat = m_currFrame->getColorSpace();
// Draw pixel values in grid
if( m_dZoomFactor >= 60.0 || ( frFormat != CLP_COLOR_RGBA && m_dZoomFactor >= 50.0 ) )
{
int imageWidth = m_pixmap.width();
int imageHeight = m_pixmap.height();
int imageWidth = m_image.width();
int imageHeight = m_image.height();
;
QFont font( "Helvetica" );
@@ -512,7 +546,7 @@ void ViewArea::paintEvent( QPaintEvent* event )
QRect pixelRect( viewToWindow( pixelTopLeft ), QSize( m_dZoomFactor, m_dZoomFactor ) );
QString pixelValue;
CalypPixel pixel = m_pcCurrFrame->getPixel( pixelTopLeft.x(), pixelTopLeft.y() );
CalypPixel pixel = m_currFrame->getPixel( pixelTopLeft.x(), pixelTopLeft.y() );
if( frFormat == CLP_COLOR_YUV || frFormat == CLP_COLOR_GRAY )
{
@@ -559,33 +593,33 @@ void ViewArea::paintEvent( QPaintEvent* event )
painter.drawLine( viewToWindow( QPoint( 0, y ) ), viewToWindow( QPoint( imageWidth, y ) ) );
}
}
bool showZoomRect = m_pixmap.width() * m_dZoomFactor > windowSize.width() ||
m_pixmap.height() * m_dZoomFactor > windowSize.height();
bool showZoomRect = m_image.width() * m_dZoomFactor > windowSize.width() ||
m_image.height() * m_dZoomFactor > windowSize.height();
// VISIBLE ZOOM RECT
if( m_visibleZoomRect && m_zoomWinTimer.isActive() && showZoomRect )
{
double dRatio = m_dZoomWinRatio;
QRect cImg = QRect( 0, 0, m_pixmap.width(), m_pixmap.height() );
QRect cImg = QRect( 0, 0, m_image.width(), m_image.height() );
QPoint cZWinRBpos = QPoint( winRect.bottomRight() ) - QPoint( 15, 15 );
QRect cImgWinRect( 0, 0, round( (double)cImg.width() / dRatio ), round( (double)cImg.height() / dRatio ) );
cImgWinRect.moveBottomRight( cZWinRBpos );
QRect vr = windowToView( winRect );
QRect cVisibleImg = vr & cImg;
//cVisibleImg.moveTopLeft(vr.topLeft());
// cVisibleImg.moveTopLeft(vr.topLeft());
QRect cVisibleWinRect;
cVisibleWinRect.setLeft( floor( (double)cVisibleImg.x() / dRatio ) );
cVisibleWinRect.setTop( floor( (double)cVisibleImg.y() / dRatio ) );
cVisibleWinRect.setRight( round( (double)cVisibleImg.right() / dRatio ) );
cVisibleWinRect.setBottom( round( (double)cVisibleImg.bottom() / dRatio ) );
//painter.fillRect( cImgWinRect, QBrush( QColor( 128, 128, 128, 128 ) ) );
// painter.fillRect( cImgWinRect, QBrush( QColor( 128, 128, 128, 128 ) ) );
painter.setPen( QColor( 50, 50, 50, 128 ) );
//painter.drawRect( cImgWinRect );
// painter.drawRect( cImgWinRect );
painter.setOpacity( 0.7 );
painter.drawPixmap( cImgWinRect, m_pixmap );
painter.drawImage( cImgWinRect, m_image );
painter.setOpacity( 1 );
cVisibleWinRect.moveTopLeft( cImgWinRect.topLeft() + cVisibleWinRect.topLeft() );
@@ -606,7 +640,7 @@ void ViewArea::paintEvent( QPaintEvent* event )
painter.setPen( QColor( 255, 255, 255, 128 ) );
painter.drawRect( cVisibleWinRect );
//qDebug() << "Debug VisibleZoomRect: " << winRect << vr << cImgWinRect << cVisibleWinRect << cVisibleImg << dRatio;
// qDebug() << "Debug VisibleZoomRect: " << winRect << vr << cImgWinRect << cVisibleWinRect << cVisibleImg << dRatio;
}
QRect sr = viewToWindow( m_selectedArea );
@@ -617,7 +651,7 @@ void ViewArea::paintEvent( QPaintEvent* event )
if( m_newShape || m_blockTrackEnable )
{
// Set the tool color
QColor selectColor = selectionColor;
QColor selectColor = kSelectionColor;
selectColor.setAlpha( 120 );
@@ -642,7 +676,7 @@ void ViewArea::paintEvent( QPaintEvent* event )
painter.setBrush( fill );
painter.setPen( Qt::NoPen );
QPainterPath myPath;
QRect imgr = viewToWindow( QRect( 0, 0, m_pixmap.width(), m_pixmap.height() ) );
QRect imgr = viewToWindow( QRect( 0, 0, m_image.width(), m_image.height() ) );
myPath.addRect( imgr );
myPath.addRect( sr ); // m_selectedArea
@@ -671,7 +705,7 @@ void ViewArea::paintEvent( QPaintEvent* event )
if( m_maskColor.isValid() )
color = m_maskColor;
else
color = imageMaskColor;
color = kImageMaskColor;
color.setAlpha( 120 );
painter.setPen( color );
@@ -691,16 +725,16 @@ void ViewArea::paintEvent( QPaintEvent* event )
if( m_maskColor.isValid() )
color = m_maskColor;
else
color = imageMaskColor;
color = kImageMaskColor;
break;
}
case EraserTool: {
color = eraserColor;
color = kEraserColor;
break;
}
default:
color = selectionColor; // ?Problems!
color = kSelectionColor; // ?Problems!
}
color.setAlpha( 120 );
@@ -738,10 +772,16 @@ void ViewArea::wheelEvent( QWheelEvent* event )
QWidget* p = parentWidget();
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 )
{
emit zoomFactorChanged_byWheel( usedScale, event->pos() );
emit zoomFactorChanged_byWheel( usedScale, eventPosition );
}
}
}
@@ -752,7 +792,7 @@ void ViewArea::mousePressEvent( QMouseEvent* event )
QPoint vpos = windowToView( event->pos() );
if( event->button() == Qt::MidButton )
if( event->button() == Qt::MiddleButton )
{
}
if( event->button() == Qt::LeftButton )
@@ -899,24 +939,24 @@ void ViewArea::mouseMoveEvent( QMouseEvent* event )
}
}
/* else // if tool() == BlockSelectionTool || MaskTool || EraserTool
{
m_blockTrackEnable = false;
// If cursor is inside the selected area, we most redraw
// the selection rect because it may be smaller.
if( m_selectedArea.contains( actualPos ) )
{
m_selectedArea = m_grid.rectContains( m_lastPos );
}
{
m_blockTrackEnable = false;
// If cursor is inside the selected area, we most redraw
// the selection rect because it may be smaller.
if( m_selectedArea.contains( actualPos ) )
{
m_selectedArea = m_grid.rectContains( m_lastPos );
}
m_selectedArea = m_selectedArea.united( m_grid.rectContains( actualPos ) );
}
*/
m_selectedArea = m_selectedArea.united( m_grid.rectContains( actualPos ) );
}
*/
if( tool() == SelectionTool )
{
// intercept the selected area with the image area to limit the
// selection only to the image area, preventing it to come outside
// the image.
m_selectedArea &= QRect( 0, 0, m_pixmap.width(), m_pixmap.height() );
m_selectedArea &= QRect( 0, 0, m_image.width(), m_image.height() );
// Update only the united area
// updateRect = updateRect.united( viewToWindow( m_selectedArea ) );
@@ -1000,7 +1040,7 @@ void ViewArea::mouseReleaseEvent( QMouseEvent* event )
bool ViewArea::isPosValid( const QPoint& pos ) const
{
if( pos.x() < 0 || pos.y() < 0 || pos.x() >= m_pixmap.width() || pos.y() >= m_pixmap.height() )
if( pos.x() < 0 || pos.y() < 0 || pos.x() >= m_image.width() || pos.y() >= m_image.height() )
return false;
else
return true;
@@ -1091,6 +1131,6 @@ void ViewArea::updateMask( const QRect& rect )
break;
}
default: /* Do Nothing */
;
;
}
}
+25 -26
View File
@@ -56,17 +56,15 @@ public:
ViewArea( QWidget* parent = 0 );
void setImage( CalypFrame* pcFrame );
void setImage( const QPixmap& pixmap );
void setImage( std::shared_ptr<CalypFrame> frame );
auto getFilteredChannel() -> std::optional<std::size_t>;
void setFilteredChannel( std::size_t channel );
void clearFilteredChannel();
void setMode( int mode );
void setMaskColor( const QColor& color = QColor() );
/**
* Clears any contents.
*/
void clear();
/**
* Select tool from the menu
*/
@@ -83,8 +81,6 @@ public:
*/
void clearMask();
QPixmap image() const { return m_pixmap; }
QBitmap mask() const { return m_mask; }
QRect selectedArea() const { return m_selectedArea; }
GridManager gridManager() const { return m_grid; }
QColor maskColor() const { return m_maskColor; }
@@ -110,12 +106,12 @@ public Q_SLOTS:
// void setSelectedArea( QRect &rect );
protected:
void paintEvent( QPaintEvent* event );
void resizeEvent( QResizeEvent* event );
void mousePressEvent( QMouseEvent* event );
void mouseMoveEvent( QMouseEvent* event );
void mouseReleaseEvent( QMouseEvent* event );
void wheelEvent( QWheelEvent* event );
void paintEvent( QPaintEvent* event ) override;
void resizeEvent( QResizeEvent* event ) override;
void mousePressEvent( QMouseEvent* event ) override;
void mouseMoveEvent( QMouseEvent* event ) override;
void mouseReleaseEvent( QMouseEvent* event ) override;
void wheelEvent( QWheelEvent* event ) override;
void updateSize();
void updateOffset();
@@ -150,33 +146,36 @@ private:
QPoint viewToWindow( const QPoint& pt ) const;
QRect viewToWindow( const QRect& rc ) const;
CalypFrame* m_pcCurrFrame;
std::shared_ptr<CalypFrame> m_currFrame;
QImage m_image;
std::shared_ptr<CalypFrame> m_nextFrame;
std::optional<std::size_t> m_filterSingleChannel;
ClpPel m_uiPixelHalfScale;
Tool m_eTool;
bool m_bGridVisible;
Tool m_eTool{ NavigationTool };
bool m_bGridVisible{ false };
QTimer m_zoomWinTimer;
double m_dZoomWinRatio;
double m_dZoomFactor;
double m_dZoomFactor{ 1.0 };
QPixmap m_pixmap;
// QPixmap m_pixmap;
QBitmap m_mask;
QRect m_selectedArea;
QPoint m_lastPos;
QPoint m_lastWindowPos;
GridManager m_grid;
ViewMode m_mode;
ViewMode m_mode{ NormalMode };
QColor m_maskColor;
int m_xOffset;
int m_yOffset;
bool m_blockTrackEnable;
int m_xOffset{ 0 };
int m_yOffset{ 0 };
bool m_blockTrackEnable{ false };
bool m_newShape;
bool m_snapToGrid;
bool m_snapToGrid{ false };
bool m_cursorInGrid;
bool m_visibleZoomRect;
bool m_visibleZoomRect{ true };
};
#endif // __VIEWAREA_H__
+28 -31
View File
@@ -382,8 +382,28 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget* parent )
setFixedSize( MainLayout->sizeHint() );
}
auto findPelFormatColorSpace( ClpPixelFormats rInputFormat ) -> std::pair<int, std::int64_t>
{
if( rInputFormat != ClpPixelFormats::Invalid )
{
auto pelFmtName = CalypFrame::pixelFormatName( rInputFormat );
for( unsigned int j = 0; j < CalypFrame::supportedColorSpacesListNames().size(); j++ )
{
const auto& formats_list = CalypFrame::supportedPixelFormatListNames( j );
for( const auto& [key, name] : formats_list )
{
if( pelFmtName == name )
{
return std::make_pair( j, static_cast<int>( key ) );
}
}
}
}
return std::make_pair( 0, 0 );
}
int ConfigureFormatDialog::runConfigureFormatDialog( const QString& Filename, unsigned int& rWidth, unsigned int& rHeight,
int& rInputFormat, unsigned int& rBits, int& rEndianess, unsigned int& rFrameRate )
ClpPixelFormats& rInputFormat, unsigned int& rBits, int& rEndianess, unsigned int& rFrameRate )
{
// Set default values
// setWindowTitle( "Configure resolution for " + Filename );
@@ -391,24 +411,8 @@ int ConfigureFormatDialog::runConfigureFormatDialog( const QString& Filename, un
m_spinBoxWidth->setValue( rWidth );
m_spinBoxheight->setValue( rHeight );
int colorSpace = 0;
int sampling = 0;
if( rInputFormat >= 0 )
{
ClpString pelFmtName = CalypFrame::supportedPixelFormatListNames()[rInputFormat];
for( unsigned int j = 0; j < CalypFrame::supportedColorSpacesListNames().size(); j++ )
{
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames( j ).size(); i++ )
{
if( pelFmtName == CalypFrame::supportedPixelFormatListNames( j )[i] )
{
colorSpace = j;
sampling = i;
break;
}
}
}
}
auto [colorSpace, sampling] = findPelFormatColorSpace( rInputFormat );
m_comboBoxColorSpace->setCurrentIndex( colorSpace );
m_comboBoxPixelFormat->setCurrentIndex( sampling );
m_spinBoxBits->setValue( rBits );
@@ -441,16 +445,8 @@ int ConfigureFormatDialog::runConfigureFormatDialog( const QString& Filename, un
rWidth = m_spinBoxWidth->value();
rHeight = m_spinBoxheight->value();
colorSpace = m_comboBoxColorSpace->currentIndex();
sampling = m_comboBoxPixelFormat->currentIndex();
ClpString pelFmtName = CalypFrame::supportedPixelFormatListNames( colorSpace )[sampling];
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames().size(); i++ )
{
if( pelFmtName == CalypFrame::supportedPixelFormatListNames()[i] )
{
rInputFormat = i;
break;
}
}
sampling = m_comboBoxPixelFormat->currentData().toInt();
rInputFormat = static_cast<ClpPixelFormats>( sampling );
rBits = m_spinBoxBits->value();
rEndianess = m_comboBoxEndianness->currentIndex();
rFrameRate = m_spinBoxFrameRate->value();
@@ -512,9 +508,10 @@ void ConfigureFormatDialog::slotColorSpaceChange( int idx )
return;
m_comboBoxPixelFormat->clear();
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames( idx ).size(); i++ )
const auto& formats_list = CalypFrame::supportedPixelFormatListNames( idx );
for( const auto& [key, name] : formats_list )
{
m_comboBoxPixelFormat->insertItem( i, CalypFrame::supportedPixelFormatListNames( idx )[i].c_str() );
m_comboBoxPixelFormat->addItem( QString::fromStdString( std::string( name ) ), static_cast<int>( key ) );
}
m_comboBoxPixelFormat->setCurrentIndex( 0 );
}
+2 -2
View File
@@ -38,7 +38,7 @@ class QSpinBox;
class QString;
class QWidget;
typedef QVector<CalypStandardResolution> CalypStandardResolutionVector;
using CalypStandardResolutionVector = QVector<CalypStandardResolution>;
QDataStream& operator<<( QDataStream& out, const CalypStandardResolutionVector& array );
QDataStream& operator>>( QDataStream& in, CalypStandardResolutionVector& array );
@@ -51,7 +51,7 @@ class ConfigureFormatDialog : public QDialog
public:
ConfigureFormatDialog( QWidget* parent = 0 );
int runConfigureFormatDialog( const QString& Filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBits,
int runConfigureFormatDialog( const QString& Filename, unsigned int& rWidth, unsigned int& rHeight, ClpPixelFormats& rInputFormat, unsigned int& rBits,
int& rEndianess, unsigned int& rFrameRate );
void readSettings();
+19 -22
View File
@@ -36,18 +36,17 @@
class QLineEdit;
class OpionConfiguration : public QWidget
class OptionConfiguration : public QWidget
{
public:
OpionConfiguration( OptionBase* option )
OptionConfiguration( CalypOptions::OptionBase* option )
: m_cName{ option->opt_string }
{
m_pcChecked = NULL;
m_cName = option->opt_string;
m_pcDescription = new QLabel;
auto* pcDescription = new QLabel;
QString desc = QString::fromStdString( option->opt_desc );
m_pcDescription->setText( desc );
pcDescription->setText( desc );
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget( m_pcDescription, 0, Qt::AlignLeft );
layout->addWidget( pcDescription, 0, Qt::AlignLeft );
if( !option->isBinary() )
{
m_pcValue = new QLineEdit;
@@ -64,7 +63,7 @@ public:
layout->setContentsMargins( 1, 1, 1, 1 );
setLayout( layout );
}
const QString getValue() const
auto getValue() const -> QString
{
if( m_pcChecked )
{
@@ -72,13 +71,12 @@ public:
}
return m_pcValue->text();
}
const ClpString& getName() { return m_cName; }
auto getName() const -> std::string { return m_cName; }
private:
QLineEdit* m_pcValue;
QCheckBox* m_pcChecked;
QLabel* m_pcDescription;
ClpString m_cName;
QLineEdit* m_pcValue{ nullptr };
QCheckBox* m_pcChecked{ nullptr };
std::string m_cName;
};
ModulesHandleOptDialog::ModulesHandleOptDialog( QWidget* parent, CalypAppModuleIf* pcCurrModuleIf )
@@ -87,13 +85,12 @@ ModulesHandleOptDialog::ModulesHandleOptDialog( QWidget* parent, CalypAppModuleI
resize( 400, 10 );
setWindowTitle( "Select module parameters" );
const CalypOptions::OptionsList& moduleOptions = m_pcCurrModuleIf->m_pcModule->m_cModuleOptions.getOptionList();
auto& moduleOptions = m_pcCurrModuleIf->m_pcModule->m_cModuleOptions.getOptionList();
QVBoxLayout* optionsLayout = new QVBoxLayout;
OpionConfiguration* pcOption;
for( CalypOptions::OptionsList::const_iterator it = moduleOptions.begin(); it != moduleOptions.end(); ++it )
for( auto& option : moduleOptions )
{
pcOption = new OpionConfiguration( ( *it )->opt );
auto pcOption = new OptionConfiguration( option->base_opt.get() );
m_apcOptionList.append( pcOption );
optionsLayout->addWidget( pcOption );
}
@@ -121,17 +118,17 @@ int ModulesHandleOptDialog::runConfiguration()
return QDialog::Rejected;
}
std::vector<ClpString> argsArray;
ClpString optionString;
std::vector<std::string> argsArray;
std::string optionString;
QString valueString( "" );
for( int i = 0; i < m_apcOptionList.size(); i++ )
for( const auto& option : m_apcOptionList )
{
valueString = m_apcOptionList.at( i )->getValue();
valueString = option->getValue();
if( !valueString.isEmpty() )
{
optionString.append( "--" );
optionString.append( m_apcOptionList.at( i )->getName() );
optionString.append( option->getName() );
if( !( valueString == "true" ) )
{
optionString.append( "=" );
+2 -2
View File
@@ -32,7 +32,7 @@
#include "CommonDefs.h"
#include "config.h"
class OpionConfiguration;
class OptionConfiguration;
/**
*
@@ -47,7 +47,7 @@ public:
private:
CalypAppModuleIf* m_pcCurrModuleIf;
QVector<OpionConfiguration*> m_apcOptionList;
QVector<OptionConfiguration*> m_apcOptionList;
};
#endif // __MODULEHANDLEOPTDIALOG_H__
+1 -1
View File
@@ -33,7 +33,7 @@
#include "lib/CalypStream.h"
SeekStreamDialog::SeekStreamDialog( CalypStream* pcCurrStream, QWidget* parent )
SeekStreamDialog::SeekStreamDialog( const CalypStream* pcCurrStream, QWidget* parent )
: QDialog( parent, Qt::Dialog | Qt::WindowTitleHint ), m_iSelectedFrameNum()
{
m_iSelectedFrameNum = pcCurrStream->getCurrFrameNum();
+1 -1
View File
@@ -42,7 +42,7 @@ class SeekStreamDialog : public QDialog
Q_OBJECT
public:
SeekStreamDialog( CalypStream* pcCurrStream, QWidget* parent = 0 );
SeekStreamDialog( const CalypStream* pcCurrStream, QWidget* parent = 0 );
int runDialog();
private:
+26 -12
View File
@@ -230,6 +230,8 @@ FramePropertiesDock::FramePropertiesDock( QWidget* parent, bool* pbMainPlaySwitc
statisticsLayout->addWidget( labelStdDevValue, gridRow++, 1 );
statisticsLayout->addWidget( medianLabel, gridRow, 0 );
statisticsLayout->addWidget( labelMedianValue, gridRow++, 1 );
statisticsLayout->addWidget( percentileLabel, gridRow, 0 );
statisticsLayout->addWidget( labelPercentileValue, gridRow++, 1 );
statisticsLayout->addWidget( entropyLabel, gridRow, 0 );
statisticsLayout->addWidget( labelEntropyValue, gridRow++, 1 );
@@ -278,11 +280,15 @@ QSize FramePropertiesDock::sizeHint() const
void FramePropertiesDock::reset()
{
m_pcFrame = nullptr;
m_pcSelectedFrame = nullptr;
m_bHasFrame = false;
m_cSelectionArea = QRect();
m_iLastFrameType = -1;
labelRangeValue->clear();
labelNEBinsValue->clear();
labelMeanValue->clear();
labelPixelsValue->clear();
@@ -290,6 +296,7 @@ void FramePropertiesDock::reset()
labelCountValue->clear();
labelMedianValue->clear();
labelPercentileValue->clear();
labelEntropyValue->clear();
// Remove the histogram data from memory
histogramWidget->reset();
@@ -297,7 +304,7 @@ void FramePropertiesDock::reset()
setEnabled( false );
}
void FramePropertiesDock::setFrame( CalypFrame* pcFrame, bool isPlaying )
void FramePropertiesDock::setFrame( std::shared_ptr<CalypFrame> pcFrame, bool isPlaying )
{
int colorSpace = pcFrame->getColorSpace();
if( m_iLastFrameType != colorSpace )
@@ -365,7 +372,7 @@ void FramePropertiesDock::setFrame( CalypFrame* pcFrame, bool isPlaying )
if( pcFrame )
{
m_bHasFrame = true;
m_cFrame = CalypFrame( pcFrame );
m_pcFrame = pcFrame;
}
else
{
@@ -389,8 +396,10 @@ void FramePropertiesDock::setSelection( const QRect& selectionArea )
*/
if( bSelectionChanged )
{
m_cSelectedFrame = CalypFrame( m_cFrame, selectionArea.x(), selectionArea.y(), selectionArea.width(),
selectionArea.height() );
m_pcSelectedFrame = std::make_shared<CalypFrame>( *m_pcFrame, selectionArea.x(),
selectionArea.y(),
selectionArea.width(),
selectionArea.height() );
}
updateDataHistogram();
selectionImageButton->click();
@@ -409,11 +418,19 @@ void FramePropertiesDock::updateDataHistogram()
{
if( m_bHasFrame && isVisible() )
{
if( !m_bIsPlaying )
if( m_bIsPlaying )
{
histogramWidget->setLoadingSkipped();
}
else
{
if( m_cSelectionArea.isValid() )
{
m_cSelectedFrame = CalypFrame( m_cFrame, m_cSelectionArea.x(), m_cSelectionArea.y(), m_cSelectionArea.width(), m_cSelectionArea.height() );
m_pcSelectedFrame = std::make_shared<CalypFrame>( *m_pcFrame,
m_cSelectionArea.x(),
m_cSelectionArea.y(),
m_cSelectionArea.width(),
m_cSelectionArea.height() );
fullImageButton->show();
selectionImageButton->show();
}
@@ -422,12 +439,9 @@ void FramePropertiesDock::updateDataHistogram()
fullImageButton->hide();
selectionImageButton->hide();
}
histogramWidget->updateData( &m_cFrame, m_cSelectionArea.isValid() ? &m_cSelectedFrame : nullptr );
}
else
{
histogramWidget->setLoadingSkipped();
histogramWidget->updateData( m_pcFrame, m_cSelectionArea.isValid() ? m_pcSelectedFrame : nullptr );
}
histogramWidget->update();
}
else
@@ -448,7 +462,7 @@ void FramePropertiesDock::updateStatistiques()
if( channel == CalypFrame::HIST_ALL_CHANNELS )
channel = colorsCB->itemData( colorsCB->currentIndex() ).toInt();
CalypFrame* frame;
std::shared_ptr<CalypFrame> frame;
if( histogramWidget->m_renderingType == HistogramWidget::FullImageHistogram )
frame = histogramWidget->m_fullImage;
+3 -3
View File
@@ -43,14 +43,14 @@ public:
QSize sizeHint() const;
void setFrame( CalypFrame* m_pcFrame, bool isPlaying );
void setFrame( std::shared_ptr<CalypFrame> m_pcFrame, bool isPlaying );
void setSelection( const QRect& selectionArea );
void reset();
void stopHistogram();
private:
CalypFrame m_cFrame;
CalypFrame m_cSelectedFrame;
std::shared_ptr<CalypFrame> m_pcFrame;
std::shared_ptr<CalypFrame> m_pcSelectedFrame;
int m_iLastFrameType;
bool m_bIsPlaying;
bool m_bHasFrame;
+4 -6
View File
@@ -58,9 +58,9 @@ ModuleHandleDock::ModuleHandleDock( QWidget* parent, CalypAppModuleIf* moduleIf
setEnabled( true );
}
ModuleHandleDock::~ModuleHandleDock() {}
ModuleHandleDock::~ModuleHandleDock() = default;
void ModuleHandleDock::setModulueReturnValue( double value )
void ModuleHandleDock::setModuleReturnValue( double value )
{
labelModulueReturnValue->clear();
QString strValue = QString( "%1" ).arg( value );
@@ -69,11 +69,9 @@ void ModuleHandleDock::setModulueReturnValue( double value )
void ModuleHandleDock::visibilityChangedSlot( bool visiblity )
{
if( !visiblity && m_pcCurrModuleIf )
if( !visiblity )
{
CalypAppModuleIf* pcCurrentModule = m_pcCurrModuleIf;
m_pcCurrModuleIf = NULL;
ModulesHandle::destroyModuleIf( pcCurrentModule );
m_pcCurrModuleIf->disable();
}
}
+1 -1
View File
@@ -42,7 +42,7 @@ public:
ModuleHandleDock( QWidget* parent, CalypAppModuleIf* moduleIf );
~ModuleHandleDock();
void setModulueReturnValue( double value );
void setModuleReturnValue( double value );
QSize sizeHint() const;
+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(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})
TARGET_LINK_LIBRARIES(QCustomPlotLib Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport)
TARGET_INCLUDE_DIRECTORIES(QCustomPlotLib PUBLIC .)
+26 -36
View File
@@ -41,52 +41,42 @@ class HistogramWorker : public QThread
{
private:
QObject* m_parent;
CalypFrame* m_pcFrame;
std::shared_ptr<CalypFrame> m_pcFrame{ nullptr };
public:
HistogramWorker( QObject* parent )
{
m_pcFrame = NULL;
m_parent = parent;
}
: m_parent{ parent } {}
void setup( CalypFrame* frame )
void reset() { m_pcFrame = nullptr; }
void setup( std::shared_ptr<CalypFrame> frame )
{
m_pcFrame = frame;
//run();
m_pcFrame = std::move( frame );
EventData* eventData = new EventData(); // NOLINT
eventData->starting = true;
// QCoreApplication::postEvent( m_parent, eventData );
start();
}
void run()
void run() override
{
if( m_pcFrame && m_parent )
EventData* eventData = new EventData(); // NOLINT
if( m_pcFrame != nullptr )
{
EventData* eventData = new EventData();
eventData->starting = true;
m_pcFrame->calcHistogram();
eventData->starting = false;
eventData->success = true;
eventData->frame = m_pcFrame;
QCoreApplication::postEvent( m_parent, eventData );
eventData->frame = m_pcFrame.get();
}
eventData->success = true;
QCoreApplication::postEvent( m_parent, eventData );
}
/**
* Custom Event
*/
class EventData : public QEvent
{
public:
EventData()
: QEvent( QEvent::User )
{
starting = false;
success = false;
frame = NULL;
}
bool starting;
bool success;
CalypFrame* frame;
: QEvent( QEvent::User ), frame{ nullptr } {}
CalypFrame* frame{ nullptr };
bool starting{ false };
bool success{ false };
};
};
@@ -231,8 +221,10 @@ void HistogramWidget::reset()
d->guideVisible = false;
d->clearFlag = HistogramWidgetPrivate::HistogramNone;
// Remove histogram data from memory.
m_fullImage = NULL;
m_selectionImage = NULL;
m_fullImage = nullptr;
m_selectionImage = nullptr;
m_imageWorker->setup( nullptr );
m_selectionWorker->setup( nullptr );
update();
}
@@ -254,7 +246,7 @@ void HistogramWidget::customEvent( QEvent* event )
return;
}
if( ed->frame != m_fullImage && ed->frame != m_selectionImage )
if( ed->frame != m_fullImage.get() && ed->frame != m_selectionImage.get() )
{
return;
}
@@ -315,8 +307,6 @@ void HistogramWidget::customEvent( QEvent* event )
emit signalHistogramComputationFailed();
}
}
// delete ed;
}
////////////////////////////////////////////////////////////////////////////////
// Data Loading Functions
@@ -371,7 +361,7 @@ void HistogramWidget::stopHistogramComputation()
// Update Data Methods
////////////////////////////////////////////////////////////////////////////////
void HistogramWidget::updateData( CalypFrame* pcFrame, CalypFrame* pcFrameSelection )
void HistogramWidget::updateData( std::shared_ptr<CalypFrame> pcFrame, std::shared_ptr<CalypFrame> pcFrameSelection )
{
d->imageBits = pcFrame->getBitsPel();
switch( pcFrame->getColorSpace() )
@@ -489,7 +479,7 @@ void HistogramWidget::paintEvent( QPaintEvent* )
int wWidth = width() - 1;
int wHeight = height() - 1;
double max;
CalypFrame* frame;
std::shared_ptr<CalypFrame> frame;
if( m_renderingType == ImageSelectionHistogram && m_selectionImage )
frame = m_selectionImage;
+3 -5
View File
@@ -90,7 +90,7 @@ public:
void stopHistogramComputation();
/** Update full image histogram data. */
void updateData( CalypFrame* pcFrame, CalypFrame* pcFrameSelection );
void updateData( std::shared_ptr<CalypFrame> pcFrame, std::shared_ptr<CalypFrame> pcFrameSelection );
/** @see @p HistogramOption */
void setOptions( HistogramOptions options = AllOptions );
@@ -113,12 +113,10 @@ public:
/** Full image */
HistogramWorker* m_imageWorker;
// CalypFrameStats* m_imageHistogram;
CalypFrame* m_fullImage;
std::shared_ptr<CalypFrame> m_fullImage;
/** Histogram area selection */
HistogramWorker* m_selectionWorker;
// CalypFrameStats* m_selectionHistogram;
CalypFrame* m_selectionImage;
std::shared_ptr<CalypFrame> m_selectionImage;
Q_SIGNALS:
void signalintervalChanged( int min, int max );
+3
View File
@@ -55,4 +55,7 @@
/* Fervor update lib */
#cmakedefine USE_FERVOR
/* Use a resource manager to manage streams in different threads */
#cmakedefine CALYP_MANAGED_RESOURCES
#endif // __CONFIG_CALYP_H__
@@ -33,15 +33,15 @@ AbsoluteFrameDifferenceExample::AbsoluteFrameDifferenceExample()
/* Module Definition */
m_iModuleAPI = CLP_MODULE_API_2; // Use API version 2 (recommended).
// See this example for details on the functions prototype
m_iModuleType = CLP_FRAME_PROCESSING_MODULE; // Apply module to the frames or to the whole sequence.
m_iModuleType = ClpModuleType::FrameProcessing; // Apply module to the frames or to the whole sequence.
m_pchModuleCategory = "Measurements"; // Category (sub-menu)
m_pchModuleName = "AbsoluteDifferenceExample"; // Name
m_pchModuleLongName = "Absolute Difference Example"; // Name
m_pchModuleTooltip = "Measure the absolute difference " // Description
"between two images (Y plane), e. g., abs( Y1 - Y2 )";
m_uiNumberOfFrames = 2; // Number of Frames required (ONE_FRAME, TWO_FRAMES, THREE_FRAMES)
m_uiModuleRequirements = CLP_MODULE_REQUIRES_NEW_WINDOW; // Module requirements (check CalypModulesIf.h).
// Several requirements should be "or" between each others.
m_uiNumberOfFrames = 2; // Number of Frames required (ONE_FRAME, TWO_FRAMES, THREE_FRAMES)
m_uiModuleRequirements = ClpModuleFeature::NewWindow; // Module requirements (check CalypModulesIf.h).
// Several requirements should be "or" between each others.
m_pcFrameDifference = NULL;
}
@@ -56,7 +56,7 @@ bool AbsoluteFrameDifferenceExample::create( std::vector<CalypFrame*> apcFrameLi
return false;
m_pcFrameDifference =
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY );
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), ClpPixelFormats::Gray );
return true;
}
+2 -2
View File
@@ -9,8 +9,8 @@ PROJECT("modules_example")
# THIS FIND_PACKAGE( Calyp ) INCLUDE_DIRECTORIES( ${CALYP_INCLUDE_DIRS} ) OR
INCLUDE_DIRECTORIES(../../lib)
ADD_LIBRARY(FrameBinarization SHARED FrameBinarization_APIv1.cpp)
TARGET_LINK_LIBRARIES(FrameBinarization ${PROJECT_LIBRARY})
ADD_LIBRARY(FrameBinarizationAPIv1 SHARED FrameBinarizationAPIv1.cpp)
TARGET_LINK_LIBRARIES(FrameBinarizationAPIv1 ${PROJECT_LIBRARY})
ADD_LIBRARY(AbsoluteFrameDifferenceExample SHARED AbsoluteFrameDifferenceExample.cpp)
TARGET_LINK_LIBRARIES(AbsoluteFrameDifferenceExample ${PROJECT_LIBRARY})
@@ -18,24 +18,24 @@
*/
/**
* \file FrameBinarization_APIv1.cpp
* \file FrameBinarizationAPIv1.cpp
* \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 */
m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_iModuleType = ClpModuleType::FrameProcessing;
m_pchModuleCategory = "Utilities";
m_pchModuleName = "FrameBinarization_APIv1";
m_pchModuleName = "FrameBinarizationAPIv1";
m_pchModuleLongName = "Frame Binarization API v1";
m_pchModuleTooltip = "Binarize frame";
m_uiNumberOfFrames = 1;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_OPTIONS;
m_uiModuleRequirements = ClpModuleFeature::Options;
m_cModuleOptions.addOptions() /**/
( "threshold", m_uiThreshold, "Threshold level for binarization (0-255) [128]" );
@@ -44,13 +44,13 @@ FrameBinarization_APIv1::FrameBinarization_APIv1()
m_uiThreshold = 128;
}
void FrameBinarization_APIv1::create( CalypFrame* frame )
void FrameBinarizationAPIv1::create( CalypFrame* frame )
{
m_pcBinFrame = NULL;
m_pcBinFrame = new CalypFrame( frame->getWidth(), frame->getHeight(), CLP_GRAY, 8 );
m_pcBinFrame = new CalypFrame( frame->getWidth(), frame->getHeight(), ClpPixelFormats::Gray, 8 );
}
CalypFrame* FrameBinarization_APIv1::process( CalypFrame* frame )
CalypFrame* FrameBinarizationAPIv1::process( CalypFrame* frame )
{
const ClpPel* pPelInput = frame->getPelBufferYUV()[0][0];
ClpPel* pPelBin = m_pcBinFrame->getPelBufferYUV()[0][0];
@@ -62,7 +62,7 @@ CalypFrame* FrameBinarization_APIv1::process( CalypFrame* frame )
return m_pcBinFrame;
}
void FrameBinarization_APIv1::destroy()
void FrameBinarizationAPIv1::destroy()
{
if( m_pcBinFrame )
delete m_pcBinFrame;
@@ -18,29 +18,29 @@
*/
/**
* \file FrameBinarization_APIv1.h
* \file FrameBinarizationAPIv1.h
* \brief Binarize frame module (example of APIv1)
*/
#ifndef __FRAMEBINARIZATION_APIV1_H__
#define __FRAMEBINARIZATION_APIV1_H__
#ifndef __FRAMEBINARIZATIONAPIV1_H__
#define __FRAMEBINARIZATIONAPIV1_H__
#include "CalypModuleIf.h"
class FrameBinarization_APIv1 : public CalypModuleIf
class FrameBinarizationAPIv1 : public CalypModuleIf
{
REGISTER_CLASS_FACTORY( FrameBinarization_APIv1 )
REGISTER_CLASS_FACTORY( FrameBinarizationAPIv1 )
private:
CalypFrame* m_pcBinFrame;
unsigned int m_uiThreshold;
public:
FrameBinarization_APIv1();
virtual ~FrameBinarization_APIv1() {}
FrameBinarizationAPIv1();
virtual ~FrameBinarizationAPIv1() {}
void create( CalypFrame* );
CalypFrame* process( CalypFrame* );
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;
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( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/SteamLocomotiveTrain_2560x1600_60_10bit_crop.yuv" ), 2560, 1600, 0, 10, CLP_LITTLE_ENDIAN, 1, true );
stream.open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/Foreman.yuv" ), 352, 288, 0, 8, CLP_BIG_ENDIAN, 1, true );
while( 1 )
{
+39 -22
View File
@@ -3,8 +3,10 @@
#
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)
@@ -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_SRCS
LibMemory.h
CalypLib.h
CalypDefs.h
${Calyp_Lib_Frame_SRCS}
${Calyp_Lib_Stream_SRCS}
${Calyp_Lib_OptionParser_SRCS}
${Calyp_Lib_Modules_SRCS}
)
SET(Calyp_Lib_SRCS CalypLib.h CalypDefs.h ${Calyp_Lib_Frame_SRCS} ${Calyp_Lib_Stream_SRCS} ${Calyp_Lib_OptionParser_SRCS} ${Calyp_Lib_Modules_SRCS})
LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${PROJECT_LIBRARY})
LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
IF(USE_FFMPEG)
@@ -41,6 +34,10 @@ IF(USE_FFMPEG)
LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${FFMPEG_LIBRARIES})
LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIRS})
LIST(APPEND CALYP_LIB_LINKER_DEPENDENCIES ${FFMPEG_LIBRARIES})
ENDIF()
IF(USE_OPENCV)
@@ -51,13 +48,28 @@ IF(USE_OPENCV)
LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${OpenCV_LIBRARIES})
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()
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)
ADD_LIBRARY(${PROJECT_LIBRARY} STATIC ${Calyp_Lib_SRCS})
@@ -65,27 +77,32 @@ ELSE()
ADD_LIBRARY(${PROJECT_LIBRARY} SHARED ${Calyp_Lib_SRCS})
ENDIF()
TARGET_LINK_LIBRARIES(${PROJECT_LIBRARY} ${FFMPEG_LIBRARIES} ${OpenCV_LIBRARIES})
TARGET_INCLUDE_DIRECTORIES(${PROJECT_LIBRARY} PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
TARGET_LINK_LIBRARIES(${PROJECT_LIBRARY} ${CALYP_LIB_LINKER_DEPENDENCIES})
# 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})
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)
INSTALL(
TARGETS ${PROJECT_LIBRARY}
EXPORT "${PROJECT_LIBRARY}Targets"
RUNTIME DESTINATION bin
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
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()
IF(BUILD_TESTS)
ADD_SUBDIRECTORY(tests)
ENDIF()
IF(BUILD_TESTS_CATCH2)
ADD_SUBDIRECTORY(catch2)
ENDIF()
+9 -6
View File
@@ -12,7 +12,7 @@
#
#
# 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_INCLUDE_DIRS : The Calyp include directories.
# - 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_MAJOR @CALYP_VERSION_MAJOR@)
SET(CALYP_VERSION_MINOR @CALYP_VERSION_MINOR@)
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_INCLUDE_DIRS "@CMAKE_CFG_INCLUDE_DIRS@" )
SET( CALYP_LINKER_LIBS "@CMAKE_CFG_LINKER_LIBSS@" )
SET( CALYP_LIBRARIES "${CALYP_LIBRARY}" )
LIST( APPEND CALYP_LIBRARIES "@CALYP_LIB_LINKER_DEPENDENCIES@")
set_and_check( CALYP_INCLUDE_DIRS "@CMAKE_CFG_INCLUDE_DIRS@" )
CHECK_REQUIRED_COMPONENTS(Calyp)
+12 -73
View File
@@ -26,15 +26,11 @@
#ifndef __CALYPDEFS_H__
#define __CALYPDEFS_H__
#include <algorithm>
#include <iterator>
#include <memory>
#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
{
CLP_LOG_INFO = 1,
@@ -43,94 +39,37 @@ enum CLP_LOG_LEVEL
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_2 = 1.57079632679489661923;
inline ClpString clpLowercase( const ClpString& in )
inline std::string clpLowercase( const std::string& in )
{
ClpString out;
transform( in.begin(), in.end(), std::back_inserter( out ), tolower );
std::string out;
std::transform( in.begin(), in.end(), std::back_inserter( out ), tolower );
return out;
}
inline ClpString clpUppercase( const ClpString& in )
inline std::string clpUppercase( const std::string& in )
{
ClpString out;
transform( in.begin(), in.end(), std::back_inserter( out ), toupper );
std::string out;
std::transform( in.begin(), in.end(), std::back_inserter( out ), toupper );
return out;
}
struct CalypFailure : public std::exception
{
ClpString m_class_name;
ClpString m_error_msg;
CalypFailure( ClpString error_msg ) throw()
std::string m_class_name;
std::string m_error_msg;
CalypFailure( std::string error_msg ) throw()
: 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 )
{
}
~CalypFailure() 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();
}
};
+337 -286
View File
File diff suppressed because it is too large. Load diff
+316 -199
View File
@@ -26,15 +26,79 @@
#ifndef __CALYPFRAME_H__
#define __CALYPFRAME_H__
#include <array>
#include <map>
#include <memory>
#include <optional>
#include <span>
#include "CalypDefs.h"
#include <string>
#include <vector>
namespace cv
{
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 ClpPixelFormats
* \brief List of supported pixel formats
* \ingroup CalypLibGrp
*/
enum class ClpPixelFormats : int
{
Invalid = -1, //!< Invalid
YUV420p = 0, //!< YUV 420 progressive
YUV422p, //!< YUV 422 progressive
YUV444p, //!< YUV 444 progressive
YUYV422, //!< YUV 422 interleaved
Gray, //!< Grayscale
RGB24p, //!< RGB 32 bpp progressive
RGB24, //!< RGB 32 bpp
BGR24, //!< BGR 32 bpp
RGBA32, //!< RGBA 32 bpp
BGRA32, //!< BGRA 32 bpp
};
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 ) ) )
/**
@@ -44,39 +108,95 @@ class Mat;
*/
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:
static int getMaxNumberOfComponents();
static constexpr std::size_t getMaxNumberOfComponents() { return kMaxNumberOfComponents; }
CalypPixel( const int& CalypColorSpace = CLP_COLOR_INVALID );
CalypPixel( const int& CalypColorSpace, const ClpPel& c0 );
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 CalypPixel& other );
~CalypPixel();
CalypPixel() = default;
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, const ClpPel c3 );
CalypPixel( const CalypPixel& other ) noexcept = default;
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;
ClpPel& operator[]( const int& channel );
auto components() const -> const std::array<ClpPel, kMaxNumberOfComponents>& { return m_pelComp; };
auto components() -> std::array<ClpPel, kMaxNumberOfComponents>& { return m_pelComp; };
CalypPixel operator=( const CalypPixel& );
CalypPixel operator+( const CalypPixel& );
CalypPixel operator+=( const CalypPixel& );
CalypPixel operator-( const CalypPixel& );
CalypPixel operator-=( const CalypPixel& );
CalypPixel operator*( const double& );
ClpPel operator[]( const std::size_t channel ) const { return m_pelComp[channel]; }
ClpPel& operator[]( const std::size_t channel ) { return m_pelComp[channel]; }
CalypPixel& operator+=( const CalypPixel& );
CalypPixel& operator-=( const CalypPixel& );
CalypPixel& operator*=( const double );
CalypPixel operator+( const CalypPixel& ) const;
CalypPixel operator-( const CalypPixel& ) const;
CalypPixel operator*( const double ) const;
auto operator==( const CalypPixel& other ) const -> bool;
friend std::ostream& operator<<( std::ostream& os, const CalypPixel& p );
/**
* Convert a Pixel to a new color space
* @param inputPixel input pixel (CalypPixel)
* @param eOutputSpace output color space
* @return converted pixel
*/
CalypPixel convertPixel( CalypColorSpace eOutputSpace );
* Convert a Pixel to a new color space
* @param inputPixel input pixel (CalypPixel)
* @param eOutputSpace output color space
* @return converted pixel
*/
CalypPixel convertPixel( CalypColorSpace eOutputSpace ) const;
};
std::ostream& operator<<( std::ostream& os, const CalypPixel& p );
/**
* \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:
class CalypPixelPrivate;
std::unique_ptr<CalypPixelPrivate> d;
std::vector<T> m_data;
std::vector<std::span<T>> m_rows;
};
/**
@@ -88,38 +208,24 @@ class CalypFrame
{
public:
/**
* Function that handles the supported color space
* of CalypFrame
* @return vector of strings with pixel formats names
*/
static std::vector<ClpString> supportedColorSpacesListNames();
/**
* Function that handles the supported pixel formats
* of CalypFrame
* @return vector of strings with pixel formats names
*/
static std::vector<ClpString> supportedPixelFormatListNames();
static std::vector<ClpString> supportedPixelFormatListNames( int colorSpace );
static int numberOfFormats();
static int findPixelFormat( const ClpString& name );
static int pelformatColorSpace( const int idx );
/**
* Default constructor. Frame is not valid
* Function that handles the supported color space
* of CalypFrame
* @return vector of strings with pixel formats names
*/
CalypFrame();
static std::vector<std::string> supportedColorSpacesListNames();
/**
* Creates a new frame using the following configuration
*
* @param width width of the frame
* @param height height of the frame
* @param pel_format pixel format index (always use PixelFormats enum)
*
* @note this function might misbehave if the pixel format enum is not correct
*/
CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel = 8 );
* Function that handles the supported pixel formats
* of CalypFrame
* @return vector of strings with pixel formats names
*/
static constexpr auto numberOfFormats() -> std::size_t;
static auto findPixelFormat( const std::string& name ) -> std::optional<ClpPixelFormats>;
static auto findPixelFormat( const std::string_view name ) -> std::optional<ClpPixelFormats>;
static auto pelformatColorSpace( ClpPixelFormats idx ) -> int;
static auto supportedPixelFormatListNames() -> std::map<ClpPixelFormats, std::string_view>;
static auto supportedPixelFormatListNames( int colorSpace ) -> std::map<ClpPixelFormats, std::string_view>;
static auto pixelFormatName( ClpPixelFormats idx ) -> const std::string_view;
/**
* Creates a new frame using the following configuration
@@ -130,7 +236,18 @@ public:
*
* @note this function might misbehave if the pixel format enum is not correct
*/
CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel, bool has_negative_values );
CalypFrame( unsigned int width, unsigned int height, ClpPixelFormats pelFormat, unsigned bitsPixel = 8 );
/**
* Creates a new frame using the following configuration
*
* @param width width of the frame
* @param height height of the frame
* @param pel_format pixel format index (always use PixelFormats enum)
*
* @note this function might misbehave if the pixel format enum is not correct
*/
CalypFrame( unsigned int width, unsigned int height, ClpPixelFormats pelFormat, unsigned bitsPixel, bool has_negative_values );
/**
* Move contructor
@@ -147,12 +264,11 @@ public:
CalypFrame& operator=( CalypFrame&& other ) noexcept;
/**
* Copy contructor
*
* @param other existing frame to copy from
*/
* Copy contructor
*
* @param other existing frame to copy from
*/
CalypFrame( const CalypFrame& other );
CalypFrame( const CalypFrame* other );
/**
* Copy-assignement contructor
@@ -162,23 +278,23 @@ public:
CalypFrame& operator=( const CalypFrame& other );
/**
* Creates and new frame with the configuration of an existing one and copy
* its contents. This function only copies a specific region from the existing
* frame
*
* @param other existing frame to copy from
* @param posX position X to crop from
* @param posY position Y to crop from
* @param areaWidth crop width
* @param areaHeight crop height
*/
* Creates and new frame with the configuration of an existing one and copy
* its contents. This function only copies a specific region from the existing
* frame
*
* @param other existing frame to copy from
* @param posX position X to crop from
* @param posY position Y to crop from
* @param areaWidth crop width
* @param areaHeight crop height
*/
CalypFrame( const CalypFrame& other, unsigned int x, unsigned int y, unsigned int width, unsigned int height );
CalypFrame( const CalypFrame* other, unsigned int x, unsigned int y, unsigned int width, unsigned int height );
~CalypFrame();
/** Format match opts
*/
*/
enum FormatMatching
{
MATCH_COLOR_SPACE = 1,
@@ -191,50 +307,50 @@ public:
};
/**
* Check if two CalypFrames have the same fmt
* @param other frame to compare with
* @param match matching conditions (use enum FormatMatching)
* @return true if format matches
*/
* Check if two CalypFrames have the same fmt
* @param other frame to compare with
* @param match matching conditions (use enum FormatMatching)
* @return true if format matches
*/
bool haveSameFmt( const CalypFrame& other, unsigned int match = MATCH_ALL ) const;
bool haveSameFmt( const CalypFrame* other, unsigned int match = MATCH_ALL ) const;
/**
* Get pixel format information
* @return pixel format index
*/
int getPelFormat() const;
* Get pixel format information
* @return pixel format index
*/
ClpPixelFormats getPelFormat() const;
/**
* Get pixel format information
* @return pixel format name
*/
ClpString getPelFmtName();
* Get pixel format information
* @return pixel format name
*/
auto getPelFmtName() const -> std::string;
/**
* Get color space information
* @return get color space index
*/
* Get color space information
* @return get color space index
*/
int getColorSpace() const;
/**
* Get the number of channels
* @return number of channels
*/
* Get the number of channels
* @return number of channels
*/
unsigned getNumberChannels() const;
/**
* Get width of the frame
* @param channel/component
* @return number of pixels
*/
* Get width of the frame
* @param channel/component
* @return number of pixels
*/
unsigned int getWidth( unsigned channel = 0 ) const;
/**
* Get height of the frame
* @param channel/component
* @return number of pixels
*/
* Get height of the frame
* @param channel/component
* @return number of pixels
*/
unsigned int getHeight( unsigned channel = 0 ) const;
/**
@@ -244,143 +360,144 @@ public:
bool getHasNegativeValues() const;
/**
* Get number of pixels of the frame
* @param channel/component
* @return number of pixels
*/
ClpULong getPixels( unsigned channel = 0 ) const;
* Get number of pixels of the frame
* @param channel/component
* @return number of pixels
*/
std::uint64_t getPixels( unsigned channel = 0 ) const;
/**
* Get the total number of pixels of the frame
* @return number of pixels
*/
ClpULong getTotalNumberOfPixels() const;
std::uint64_t getTotalNumberOfPixels() const;
/**
* Get chroma width ratio
* @return ratio multiple of 2
*/
* Get chroma width ratio
* @return ratio multiple of 2
*/
unsigned getChromaWidthRatio() const;
/**
* Get chroma height ratio
* @return ratio multiple of 2
*/
* Get chroma height ratio
* @return ratio multiple of 2
*/
unsigned getChromaHeightRatio() const;
/**
* Get number of pixels in each chroma channel
* @return number of pixels
*/
ClpULong getChromaLength() const;
* Get number of pixels in each chroma channel
* @return number of pixels
*/
std::uint64_t getChromaLength() const;
/**
* Get number of bits per pixel
* @return number of bits
*/
* Get number of bits per pixel
* @return number of bits
*/
unsigned int getBitsPel() const;
/**
* Get number of bytes per frame of an existing frame
* @return number of bytes per frame
*/
ClpULong getBytesPerFrame() const;
* Get number of bytes per frame of an existing frame
* @return number of bytes per frame
*/
std::uint64_t getBytesPerFrame() const;
/**
* Get number of bytes per frame of a specific pixel format
* @return number of bytes per frame
*/
static ClpULong getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, int iPixelFormat, unsigned int bitsPixel );
* Get number of bytes per frame of a specific pixel format
* @return number of bytes per frame
*/
static std::uint64_t getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, ClpPixelFormats pelFormat, unsigned int bitsPixel );
/**
* Reset frame pixels to zero
*/
* Reset frame pixels to zero
*/
void reset();
ClpPel*** getPelBufferYUV() const;
ClpPel*** getPelBufferYUV();
unsigned char* getRGBBuffer() const;
auto getRGBBuffer() const -> const unsigned char*;
/**
* Get pixel value at coordinates
* @param ch frame channel
* @param xPos position in X axis
* @param yPos position in Y axis
* @param ch frame channel
* @param xPos position in X axis
* @param yPos position in Y axis
* @param absolute whether it should return positive/negative values
* @return pixel value
*/
* @return pixel value
*/
ClpPel operator()( unsigned int ch, unsigned int xPos, unsigned int yPos, bool absolute = true ) const;
/**
* Get pixel value at coordinates
* @param xPos position in X axis
* @param yPos position in Y axis
* @return pixel value
*/
* Get pixel value at coordinates
* @param xPos position in X axis
* @param yPos position in Y axis
* @return pixel value
*/
CalypPixel operator()( unsigned int xPos, unsigned int yPos ) const;
/**
* Get pixel value at coordinates
* @param xPos position in X axis
* @param yPos position in Y axis
* @return pixel value
*/
* Get pixel value at coordinates
* @param xPos position in X axis
* @param yPos position in Y axis
* @return pixel value
*/
CalypPixel getPixel( unsigned int xPos, unsigned int yPos ) const;
/**
* Get pixel value at coordinates
* in the desired color space
* @param xPos position in X axis
* @param yPos position in Y axis
* @param eColorSpace desired color space
* @return pixel value
*/
CalypPixel getPixel( unsigned int xPos, unsigned int yPos, CalypColorSpace eColorSpace );
* Get pixel value at coordinates
* in the desired color space
* @param xPos position in X axis
* @param yPos position in Y axis
* @param eColorSpace desired color space
* @return pixel value
*/
CalypPixel getPixel( unsigned int xPos, unsigned int yPos, CalypColorSpace eColorSpace ) const;
/**
* Set pixel value at coordinates to a given value
* @param xPos position in X axis
* @param yPos position in Y axis
*/
* Set pixel value at coordinates to a given value
* @param xPos position in X axis
* @param yPos position in Y axis
*/
void setPixel( unsigned int xPos, unsigned int yPos, CalypPixel pixel );
/**
* Copy a frame into the current buffer
* @param other frame to be copied
*/
* Copy a frame into the current buffer
* @param other frame to be copied
*/
void copyFrom( const CalypFrame& other );
void copyFrom( const CalypFrame* other );
/**
* Copy a region from a reference corresponding to the size
* of the size of the current frame
* @param other frame to be copied
* @param x x position on the reference frame
* @param y y position on the reference frame
*/
* Copy a region from a reference corresponding to the size
* of the size of the current frame
* @param other frame to be copied
* @param x x position on the reference frame
* @param y y position on the reference frame
*/
void copyFrom( const CalypFrame& other, unsigned x, unsigned y );
void copyFrom( const CalypFrame* other, unsigned x, unsigned y );
/**
* Copy a reference frame to a specific location on the current frame
* The whole reference frame is copied
* @param other frame to be copied
* @param x x position on the current frame
* @param y y position on the current frame
*/
void copyTo( const CalypFrame& other, unsigned x, unsigned y );
void copyTo( const CalypFrame* other, unsigned x, unsigned y );
* Copy a reference frame to a specific location on the current frame
* The whole reference frame is copied
* @param other frame to be copied
* @param x x position on the current frame
* @param y y position on the current frame
*/
void copyTo( const CalypFrame& other, unsigned x, unsigned y ) const;
void copyTo( const CalypFrame* other, unsigned x, unsigned y ) const;
void frameFromBuffer( const std::vector<ClpByte>&, int, unsigned long );
void frameFromBuffer( const std::vector<ClpByte>&, int );
void frameToBuffer( std::vector<ClpByte>&, int );
void frameToBuffer( std::vector<ClpByte>&, int ) const;
void fillRGBBuffer();
void fillRGBBuffer( std::optional<std::size_t> channel ) const;
void fillRGBBuffer() const;
/**
* Histogram
*/
* Histogram
*/
enum HistogramChannels
{
HIST_CHAN_ONE = 0,
@@ -399,32 +516,32 @@ public:
};
void calcHistogram();
unsigned int getMinimumPelValue( unsigned channel );
unsigned int getMaximumPelValue( unsigned channel );
unsigned int getMinimumPelValue( unsigned channel ) const;
unsigned int getMaximumPelValue( unsigned channel ) const;
unsigned int getMaximum( unsigned channel );
unsigned int getNumPixelsRange( unsigned channel, unsigned int start, unsigned int end );
double getMean( unsigned channel, unsigned int start, unsigned int end );
int getMedian( unsigned channel, unsigned int start, unsigned int end );
double getStdDev( unsigned channel, unsigned int start, unsigned int end );
double getHistogramValue( unsigned channel, unsigned int bin );
unsigned int getNEBins( unsigned channel );
int getNumHistogramSegment();
double getEntropy( unsigned channel, unsigned int start, unsigned int end );
unsigned int getMaximum( unsigned channel ) const;
unsigned int getNumPixelsRange( unsigned channel, unsigned int start, unsigned int end ) const;
double getMean( unsigned channel, unsigned int start, unsigned int end ) const;
int getMedian( unsigned channel, unsigned int start, unsigned int end ) const;
double getStdDev( unsigned channel, unsigned int start, unsigned int end ) const;
double getHistogramValue( unsigned channel, unsigned int bin ) const;
unsigned int getNEBins( unsigned channel ) const;
int getNumHistogramSegment() const;
double getEntropy( unsigned channel, unsigned int start, unsigned int end ) const;
/**
* interface with OpenCV lib
*/
bool toMat( cv::Mat& cvMat, bool convertToGray = false, bool scale = true, unsigned channel = 0 );
* interface with OpenCV lib
*/
bool toMat( cv::Mat& cvMat, bool convertToGray = false, bool scale = true, unsigned channel = 0 ) const;
bool fromMat( cv::Mat& cvMat, int iChannel = -1 );
/**
* \ingroup CalypFrameGrp
* @defgroup CalypFrameQualityMetricsGrp Calyp Frame Quality Metrics interface
* @{
* Quality metrics interface
*
*/
* \ingroup CalypFrameGrp
* @defgroup CalypFrameQualityMetricsGrp Calyp Frame Quality Metrics interface
* @{
* Quality metrics interface
*
*/
enum QualityMetrics
{
@@ -436,8 +553,8 @@ public:
NUMBER_METRICS,
};
static std::vector<ClpString> supportedQualityMetricsList();
static std::vector<ClpString> supportedQualityMetricsUnitsList();
static std::vector<std::string> supportedQualityMetricsList();
static std::vector<std::string> supportedQualityMetricsUnitsList();
double getQuality( int Metric, CalypFrame* Org, unsigned int component );
double getMSE( CalypFrame* Org, unsigned int component );
double getPSNR( CalypFrame* Org, unsigned int component );
+103 -49
View File
@@ -34,17 +34,25 @@
* @}
*/
#include <memory>
#include <type_safe/flag_set.hpp>
#include <vector>
#include "CalypFrame.h"
#include "CalypOptions.h"
#define REGISTER_CLASS_MAKER( X ) \
extern "C" CalypModuleIf* Maker() { return new X; }
#define REGISTER_CLASS_FACTORY( X ) \
public: \
static CalypModuleIf* Create() { return new X(); } \
void Delete() { delete this; }
extern "C" CalypModulePtr Maker() { return std::make_unique<X>(); }
#define REGISTER_CLASS_FACTORY( X ) \
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>(); }
#define _BASIC_MODULE_API_2_CHECK_ \
if( apcFrameList.size() != m_uiNumberOfFrames ) \
return false; \
@@ -64,8 +72,9 @@ public: \
*/
enum Module_API_Version
{
CLP_MODULE_API_1,
CLP_MODULE_API_2,
CLP_MODULE_API_INVALID = -1,
CLP_MODULE_API_1 = 0,
CLP_MODULE_API_2 = 1,
CLP_MODULE_API_3,
};
@@ -74,11 +83,11 @@ enum Module_API_Version
* Type of module
* @see m_iModuleType
*/
enum Module_Type
enum class ClpModuleType : std::uint8_t
{
CLP_FRAME_PROCESSING_MODULE,
CLP_FRAME_MEASUREMENT_MODULE,
CLP_MODULE_TYPE_MAX = 255,
Invalid,
FrameProcessing,
FrameMeasurement,
};
/** Module_Features Enum
@@ -86,18 +95,20 @@ enum Module_Type
* Features/Requirements of a module
* @see m_uiModuleRequirements
*/
enum Module_Features
enum class ClpModuleFeature
{
CLP_MODULE_REQUIRES_NOTHING = 0,
CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY = 1,
CLP_MODULE_REQUIRES_OPTIONS = 2,
CLP_MODULE_REQUIRES_NEW_WINDOW = 4,
CLP_MODULE_USES_KEYS = 8,
CLP_MODULES_VARIABLE_NUM_FRAMES = 16,
CLP_MODULES_HAS_INFO = 32,
CLP_MODULE_REQURES_MAX = 1024,
None,
SkipWhilePlaying,
Options,
NewWindow,
KeysShortcuts,
VariableNumOfFrames,
HasInfo,
_flag_set_size
};
using ClpModuleFeatures = type_safe::flag_set<ClpModuleFeature>;
enum Module_Key_Supported
{
MODULE_KEY_LEFT,
@@ -114,34 +125,14 @@ enum Module_Key_Supported
class CalypModuleIf
{
public:
int m_iModuleAPI;
int m_iModuleType;
const char* m_pchModuleCategory;
const char* m_pchModuleName;
const char* m_pchModuleTooltip;
const char* m_pchModuleLongName;
CalypModuleIf() = default;
CalypModuleIf( const CalypModuleIf& buffer ) noexcept = delete;
CalypModuleIf( CalypModuleIf&& buffer ) noexcept = delete;
auto operator=( const CalypModuleIf& buffer ) -> CalypModuleIf& = delete;
auto operator=( CalypModuleIf&& buffer ) noexcept -> CalypModuleIf& = delete;
//! Number of frames
unsigned int m_uiNumberOfFrames;
//! Features/Requirements
unsigned int m_uiModuleRequirements;
unsigned int m_iFrameBufferCount;
CalypFrame* m_pcOutputFrame;
CalypOptions m_cModuleOptions;
CalypModuleIf()
{
m_iModuleAPI = CLP_MODULE_API_1;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_NOTHING;
m_pchModuleLongName = NULL;
m_pcOutputFrame = NULL;
m_iFrameBufferCount = 0;
}
virtual ~CalypModuleIf() {}
virtual void Delete() = 0;
virtual void destroy() = 0;
virtual ~CalypModuleIf() = default;
virtual void destroy(){};
const char* getModuleLongName()
{
@@ -161,17 +152,80 @@ public:
virtual CalypFrame* process( std::vector<CalypFrame*> ) { return NULL; }
virtual double measure( std::vector<CalypFrame*> ) { return 0; }
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
*/
virtual CalypFrame* getProcessedFrame() { return m_pcOutputFrame; }
virtual CalypFrame* getProcessedFrame() { return nullptr; }
virtual bool needFrame() { return m_iFrameBufferCount == 0 ? true : false; };
virtual bool flush()
{
m_iFrameBufferCount = 0;
return true;
};
public:
int m_iModuleAPI{ CLP_MODULE_API_1 };
ClpModuleType m_iModuleType{ ClpModuleType::Invalid };
const char* m_pchModuleCategory{ "" };
const char* m_pchModuleName{ "" };
const char* m_pchModuleTooltip{ "" };
const char* m_pchModuleLongName{ nullptr };
//! Number of frames
unsigned int m_uiNumberOfFrames{ 1 };
//! Features/Requirements
ClpModuleFeatures m_uiModuleRequirements{ ClpModuleFeature::None };
unsigned int m_iFrameBufferCount{ 0 };
CalypOptions m_cModuleOptions;
};
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;
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(){};
protected:
// const char* m_pchPythonFunctionName;
std::unique_ptr<CalypFrame> m_pcOutputFrame;
bool m_bConvertToGray;
};
using CalypModulePtr = std::unique_ptr<CalypModuleIf>;
template <typename T>
class CalypModuleInstace
{
public:
static CalypModulePtr Create() { return std::make_unique<T>(); }
};
#endif // __CALYPMODULESIF_H__
+10 -22
View File
@@ -22,62 +22,50 @@
* \brief Calyp modules interface for OpenCV
*/
#include "CalypOpenCVModuleIf.h"
#include "CalypFrame.h"
#include "CalypModuleIf.h"
// OpenCV
#include <opencv2/opencv.hpp>
using cv::Mat;
#include "PixelFormats.h"
bool CalypOpenCVModuleIf::create( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
bool bRet = false;
std::vector<Mat*> acMatList( apcFrameList.size() );
std::vector<Mat> acMatList( apcFrameList.size() );
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 );
if( outputMat )
{
unsigned pelFormat = m_bConvertToGray ? CalypFrame::findPixelFormat( "GRAY" ) : apcFrameList[0]->getPelFormat();
m_pcOutputFrame = new CalypFrame( outputMat->cols, outputMat->rows, pelFormat, apcFrameList[0]->getBitsPel() );
auto pelFormat = m_bConvertToGray ? ClpPixelFormats::Gray : apcFrameList[0]->getPelFormat();
m_pcOutputFrame = std::make_unique<CalypFrame>( outputMat->cols, outputMat->rows, pelFormat, apcFrameList[0]->getBitsPel() );
bRet = true;
}
else
{
return false;
}
for( unsigned i = 0; i < apcFrameList.size(); i++ )
{
delete acMatList[i];
}
return bRet;
}
CalypFrame* CalypOpenCVModuleIf::process( std::vector<CalypFrame*> apcFrameList )
{
m_pcOutputFrame->reset();
std::vector<Mat*> acMatList( apcFrameList.size() );
std::vector<Mat> acMatList( apcFrameList.size() );
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 );
m_pcOutputFrame->fromMat( *cvOutput );
for( unsigned i = 0; i < apcFrameList.size(); i++ )
{
delete acMatList[i];
}
return m_pcOutputFrame;
return m_pcOutputFrame.get();
}
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__
+150 -157
View File
@@ -40,51 +40,51 @@
#include <cstring>
#include <iostream>
#include <memory>
#include <sstream>
#include "config.h"
#include "lib/CalypModuleIf.h"
using namespace std;
struct ParseFailure : public std::exception
{
ClpString arg;
ClpString val;
ParseFailure( ClpString arg0, ClpString val0 ) throw()
: arg( arg0 ), val( val0 ) {}
std::string arg;
std::string val;
ParseFailure( std::string arg0, std::string val0 ) throw()
: arg{ std::move( arg0 ) }, val{ std::move( val0 ) } {}
ParseFailure( ParseFailure&& other ) noexcept = delete;
ParseFailure& operator=( ParseFailure&& other ) noexcept = delete;
ParseFailure( const ParseFailure& other ) = delete;
ParseFailure& operator=( const ParseFailure& other ) = delete;
~ParseFailure() throw() {}
const char* what() const throw() { return "Option Parse Failure"; }
const char* what() const throw() override { return "Option Parse Failure"; }
};
/** Type specific option storage */
class boolOption : public OptionBase
class boolOption : public CalypOptions::OptionBase
{
public:
boolOption( const ClpString& name, const ClpString& desc )
: OptionBase( name, desc, "(1-0)" ) { is_binary = true; }
void parse( const ClpString& arg ) { arg_count++; }
boolOption( const std::string& name, const std::string& desc )
: CalypOptions::OptionBase( name, desc, "(1-0)" ) { is_binary = true; }
void parse( const std::string& arg ) override { arg_count++; }
};
/** Type specific option storage */
template <typename T>
class StandardOption : public OptionBase
class StandardOption : public CalypOptions::OptionBase
{
public:
StandardOption( const ClpString& name, T& storage, const ClpString& desc, const ClpString& def )
: OptionBase( name, desc, def ), opt_storage( storage )
{
is_binary = false;
}
StandardOption( const std::string& name, T& storage, const std::string& desc, const std::string& def )
: CalypOptions::OptionBase( name, desc, def ), opt_storage( storage ) {}
void parse( const ClpString& arg );
void parse( const std::string& arg ) override;
T& opt_storage;
std::vector<T> opt_storage_array;
};
/* Generic parsing */
template <typename T>
inline void StandardOption<T>::parse( const ClpString& arg )
inline void StandardOption<T>::parse( const std::string& arg )
{
if( !is_binary )
{
@@ -103,9 +103,9 @@ inline void StandardOption<T>::parse( const ClpString& arg )
}
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{ 0 };
std::istringstream arg_ss( arg, std::istringstream::in );
arg_ss.exceptions( std::ios::failbit );
try
@@ -121,9 +121,9 @@ inline void StandardOption<std::vector<unsigned int>>::parse( const ClpString& a
}
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{ 0 };
std::istringstream arg_ss( arg, std::istringstream::in );
arg_ss.exceptions( std::ios::failbit );
try
@@ -140,7 +140,7 @@ inline void StandardOption<std::vector<int>>::parse( const ClpString& arg )
/* string parsing is specialized */
template <>
inline void StandardOption<ClpString>::parse( const ClpString& arg )
inline void StandardOption<std::string>::parse( const std::string& arg )
{
opt_storage = arg;
arg_count++;
@@ -148,33 +148,33 @@ inline void StandardOption<ClpString>::parse( const ClpString& arg )
/* string vector parsing is specialized */
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 );
arg_count++;
}
/** Option class for argument handling using a user provided function */
struct FunctionOption : public OptionBase
struct FunctionOption : public CalypOptions::OptionBase
{
public:
typedef void( Func )( CalypOptions&, const ClpString& );
using OptFunc = std::function<void( CalypOptions&, const std::string& )>;
FunctionOption( const ClpString& name, CalypOptions& parent_, Func* func_, const ClpString& desc, const ClpString& def )
: OptionBase( name, desc, def ), parent( parent_ ), func( func_ )
public:
FunctionOption( const std::string& name, CalypOptions& parent, OptFunc func, const std::string& desc, const std::string& def )
: CalypOptions::OptionBase( name, desc, def ), m_parent( parent ), m_func( func )
{
is_binary = false;
}
void parse( const ClpString& arg )
void parse( const std::string& arg ) override
{
func( parent, arg );
m_func( m_parent, arg );
arg_count++;
}
private:
CalypOptions& parent;
void ( *func )( CalypOptions&, const ClpString& );
CalypOptions& m_parent;
OptFunc m_func;
};
/* Helper method to initiate adding options to Options */
@@ -185,9 +185,15 @@ private:
* with default_val as the default value
* 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 ) );
addOptionInternal( std::make_unique<boolOption>( name, desc ) );
return *this;
}
CalypOptions& CalypOptions::addOption( const std::string& name, const std::string& desc )
{
addOptionInternal( std::make_unique<boolOption>( name, desc ) );
return *this;
}
@@ -197,114 +203,99 @@ CalypOptions& CalypOptions::operator()( const ClpString& name, const ClpString&
* with desc as an optional help description
*/
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( "" ) ) );
addOptionInternal( std::make_unique<StandardOption<T>>( name, storage, desc, std::string( "" ) ) );
return *this;
}
template <typename T>
CalypOptions& CalypOptions::addOption( const std::string& name, T& storage, const std::string& desc )
{
addOptionInternal( std::make_unique<StandardOption<T>>( name, storage, desc, std::string( "" ) ) );
return *this;
}
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 ) );
addOptionInternal( std::make_unique<StandardOption<T>>( name, storage, desc ) );
return *this;
}
template CalypOptions& CalypOptions::operator()( const ClpString& name, bool& storage, const ClpString& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, unsigned int& storage, const ClpString& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, int& storage, const ClpString& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, long& storage, const ClpString& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, long long int& storage, const ClpString& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, ClpString& storage, const ClpString& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, std::vector<unsigned int>& storage,
const ClpString& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, std::vector<int>& storage,
const ClpString& desc );
template CalypOptions& CalypOptions::operator()( const ClpString& name, std::vector<ClpString>& storage,
const ClpString& desc );
CalypOptions::Option::Option()
: opt( 0 ) {}
CalypOptions::Option::~Option()
template <typename T>
CalypOptions& CalypOptions::addOption( const std::string& name, T& storage, const std::string& desc, const std::string& defaults )
{
if( opt )
delete opt;
addOptionInternal( std::make_unique<StandardOption<T>>( name, storage, desc ) );
return *this;
}
CalypOptions::CalypOptions( const ClpString& name )
template CalypOptions& CalypOptions::operator()( const std::string& name, bool& storage, const std::string& desc );
template CalypOptions& CalypOptions::operator()( const std::string& name, unsigned int& storage, const std::string& desc );
template CalypOptions& CalypOptions::operator()( const std::string& name, int& storage, const std::string& desc );
template CalypOptions& CalypOptions::operator()( const std::string& name, long& storage, const std::string& desc );
template CalypOptions& CalypOptions::operator()( const std::string& name, long long int& storage, const std::string& desc );
template CalypOptions& CalypOptions::operator()( const std::string& name, std::string& storage, const std::string& desc );
template CalypOptions& CalypOptions::operator()( const std::string& name, std::vector<unsigned int>& storage,
const std::string& desc );
template CalypOptions& CalypOptions::operator()( const std::string& name, std::vector<int>& storage,
const std::string& desc );
template CalypOptions& CalypOptions::operator()( const std::string& name, std::vector<std::string>& storage,
const std::string& desc );
CalypOptions::CalypOptions( std::string name )
: m_cOptionGroupName{ std::move( name ) }
{
m_cOptionGroupName = name;
m_bAllowUnkonw = true;
}
CalypOptions::~CalypOptions()
{
for( CalypOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ )
{
delete *it;
}
}
OptionBase* CalypOptions::operator[]( const ClpString& optName )
CalypOptions::OptionBase* CalypOptions::operator[]( const std::string& optName )
{
return getOption( optName );
}
OptionBase* CalypOptions::getOption( const ClpString& optName )
CalypOptions::OptionBase* CalypOptions::getOption( const std::string& optName )
{
CalypOptions::OptionMap::iterator opt_it;
std::map<std::string, std::list<Option*>>::iterator opt_it;
opt_it = opt_short_map.find( optName );
if( opt_it != opt_short_map.end() )
{
OptionsList opt_list = ( *opt_it ).second;
for( CalypOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it )
auto opt_list = ( *opt_it ).second;
for( auto& option : opt_list )
{
return ( *it )->opt;
return option->base_opt.get();
}
}
opt_it = opt_long_map.find( optName );
if( opt_it != opt_long_map.end() )
{
OptionsList opt_list = ( *opt_it ).second;
for( CalypOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it )
auto opt_list = ( *opt_it ).second;
for( auto& option : opt_list )
{
return ( *it )->opt;
return option->base_opt.get();
}
}
return NULL;
}
bool CalypOptions::hasOpt( const ClpString& optName )
bool CalypOptions::hasOpt( const std::string& optName )
{
OptionBase* opt = getOption( optName );
return opt ? opt->count() > 0 ? true : false : false;
}
void CalypOptions::addDefaultOptions()
{
addOptions() /**/
( "help", "produce help message" ) /**/
( "version", "show version and exit" ) /**/
( "pel_fmts", "list pixel formats" ) /**/
( "quality_metrics", "list supported quality metrics" ) /**/
( "module_list", "list supported modules" ) /**/
( "module_list_full", "detailed list supported modules" );
}
CalypOptions& CalypOptions::addOptions()
{
return *this;
}
void CalypOptions::addOption( OptionBase* opt )
void CalypOptions::addOptionInternal( std::unique_ptr<OptionBase> opt )
{
Option* names = new Option();
names->opt = opt;
string& opt_string = opt->opt_string;
auto names = std::make_unique<Option>();
names->base_opt = std::move( opt );
opt = nullptr;
const std::string& opt_string = names->base_opt->opt_string;
size_t opt_start = 0;
for( size_t opt_end = 0; opt_end != string::npos; )
for( size_t opt_end = 0; opt_end != std::string::npos; )
{
opt_end = opt_string.find_first_of( ',', opt_start );
bool force_short = 0;
@@ -313,36 +304,37 @@ void CalypOptions::addOption( OptionBase* opt )
opt_start++;
force_short = 1;
}
string opt_name = opt_string.substr( opt_start, opt_end - opt_start );
std::string opt_name = opt_string.substr( opt_start, opt_end - opt_start );
if( force_short || opt_name.size() == 1 )
{
names->opt_short.push_back( opt_name );
opt_short_map[opt_name].push_back( names );
opt_short_map[opt_name].push_back( names.get() );
}
else
{
names->opt_long.push_back( opt_name );
opt_long_map[opt_name].push_back( names );
opt_long_map[opt_name].push_back( names.get() );
}
opt_start += opt_end + 1;
}
opt_list.push_back( names );
opt_list.push_back( std::move( names ) );
}
static void setOptions( CalypOptions::OptionsList& opt_list, const string& value )
static void setOptions( std::list<CalypOptions::Option*>& opt_list, const std::string& value )
{
/* multiple options may be registered for the same name:
* allow each to parse value */
for( CalypOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it )
* allow each to parse value
*/
for( auto& option : opt_list )
{
( *it )->opt->parse( value );
option->base_opt->parse( value );
}
}
bool CalypOptions::storePair( bool allow_long, bool allow_short, const string& name, const string& value )
bool CalypOptions::storePair( bool allow_long, bool allow_short, const std::string& name, const std::string& value )
{
bool found = false;
CalypOptions::OptionMap::iterator opt_it;
std::map<std::string, std::list<Option*>>::iterator opt_it;
if( allow_long )
{
opt_it = opt_long_map.find( name );
@@ -367,7 +359,7 @@ bool CalypOptions::storePair( bool allow_long, bool allow_short, const string& n
if( !m_bAllowUnkonw )
{
/* not found */
cerr << "Unknown option: `" << name << "' (value:`" << value << "')" << endl;
std::cerr << "Unknown option: `" << name << "' (value:`" << value << "')" << std::endl;
}
return false;
}
@@ -376,7 +368,7 @@ bool CalypOptions::storePair( bool allow_long, bool allow_short, const string& n
return true;
}
bool CalypOptions::storePair( const string& name, const string& value )
bool CalypOptions::storePair( const std::string& name, const std::string& value )
{
return storePair( true, true, name, value );
}
@@ -384,19 +376,19 @@ bool CalypOptions::storePair( const string& name, const string& value )
/**
* returns number of extra arguments consumed
*/
unsigned int CalypOptions::parseLONG( unsigned int argc, char* argv[] )
unsigned int CalypOptions::parseLONG( unsigned int argc, char* argv[] ) // NOLINT
{
/* gnu style long options can take the forms:
* --option=arg
* --option arg
*/
string arg( argv[0] );
size_t arg_opt_start = arg.find_first_not_of( '-' );
size_t arg_opt_sep = arg.find_first_of( '=' );
string option = arg.substr( arg_opt_start, arg_opt_sep - arg_opt_start );
std::string arg( argv[0] );
std::size_t arg_opt_start = arg.find_first_not_of( '-' );
std::size_t arg_opt_sep = arg.find_first_of( '=' );
std::string option = arg.substr( arg_opt_start, arg_opt_sep - arg_opt_start );
unsigned int extra_argc_consumed = 0;
if( arg_opt_sep == string::npos )
if( arg_opt_sep == std::string::npos )
{
/* no argument found => argument in argv[1] (maybe) */
/* xxx, need to handle case where option isn't required */
@@ -416,7 +408,7 @@ unsigned int CalypOptions::parseLONG( unsigned int argc, char* argv[] )
else
{
/* argument occurs after option_sep */
string val = arg.substr( arg_opt_sep + 1 );
std::string val = arg.substr( arg_opt_sep + 1 );
storePair( true, false, option, val );
}
return extra_argc_consumed;
@@ -425,7 +417,7 @@ unsigned int CalypOptions::parseLONG( unsigned int argc, char* argv[] )
/**
* returns number of extra arguments consumed
*/
unsigned int CalypOptions::parseLONG( string arg )
unsigned int CalypOptions::parseLONG( const std::string& arg )
{
/* gnu style long options can take the forms:
* --option=arg
@@ -433,10 +425,10 @@ unsigned int CalypOptions::parseLONG( string arg )
*/
size_t arg_opt_start = arg.find_first_not_of( '-' );
size_t arg_opt_sep = arg.find_first_of( '=' );
string option = arg.substr( arg_opt_start, arg_opt_sep - arg_opt_start );
std::string option = arg.substr( arg_opt_start, arg_opt_sep - arg_opt_start );
unsigned int extra_argc_consumed = 0;
if( arg_opt_sep == string::npos )
if( arg_opt_sep == std::string::npos )
{
/* no argument found => argument in argv[1] (maybe) */
/* xxx, need to handle case where option isn't required */
@@ -448,36 +440,36 @@ unsigned int CalypOptions::parseLONG( string arg )
else
{
/* argument occurs after option_sep */
string val = arg.substr( arg_opt_sep + 1 );
std::string val = arg.substr( arg_opt_sep + 1 );
storePair( true, false, option, val );
}
return extra_argc_consumed;
}
unsigned int CalypOptions::parseSHORT( unsigned int argc, char* argv[] )
unsigned int CalypOptions::parseSHORT( unsigned int argc, char* argv[] ) // NOLINT
{
/* short options can take the forms:
* --option arg
* -option arg
*/
string arg( argv[0] );
size_t arg_opt_start = arg.find_first_not_of( '-' );
string option = arg.substr( arg_opt_start );
std::string arg( argv[0] );
std::size_t arg_opt_start = arg.find_first_not_of( '-' );
std::string option = arg.substr( arg_opt_start );
/* lookup option */
/* argument in argv[1] */
/* xxx, need to handle case where option isn't required */
if( argc == 1 )
{
cerr << "Not processing option without argument `" << option << "'" << endl;
std::cerr << "Not processing option without argument `" << option << "'" << std::endl;
return 0; /* run out of argv for argument */
}
storePair( false, true, option, string( argv[1] ) );
storePair( false, true, option, std::string( argv[1] ) );
return 1;
}
int CalypOptions::parse( unsigned int argc, char* argv[] )
int CalypOptions::parse( unsigned int argc, char* argv[] ) // NOLINT
{
try
{
@@ -499,10 +491,11 @@ int CalypOptions::parse( unsigned int argc, char* argv[] )
return 0;
}
list<const char*> CalypOptions::scanArgv( unsigned int argc, char* argv[] )
// NOLINTNEXTLINE(*-avoid-c-arrays)
std::list<const char*> CalypOptions::scanArgv( unsigned int argc, char* argv[] )
{
/* a list for anything that didn't get handled as an option */
list<const char*> non_option_arguments;
std::list<const char*> non_option_arguments;
for( unsigned int i = 1; i < argc; i++ )
{
@@ -545,7 +538,7 @@ list<const char*> CalypOptions::scanArgv( unsigned int argc, char* argv[] )
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++ )
{
@@ -560,13 +553,13 @@ static const char spaces[41] = " ";
* using the formatting: "-x, --long",
* if a short/long option isn't specified, it is not printed
*/
static void doHelpOpt( ostream& out, const CalypOptions::Option& entry, unsigned int pad_short = 0 )
static void doHelpOpt( std::ostream& out, const CalypOptions::Option& entry, unsigned int pad_short = 0 )
{
pad_short = min( pad_short, 8u );
pad_short = std::min( pad_short, 8u );
if( !entry.opt_short.empty() )
{
unsigned int pad = max( (int)pad_short - (int)entry.opt_short.front().size(), 0 );
unsigned int pad = std::max( (int)pad_short - (int)entry.opt_short.front().size(), 0 );
out << "-" << entry.opt_short.front();
if( !entry.opt_long.empty() )
{
@@ -587,19 +580,19 @@ static void doHelpOpt( ostream& out, const CalypOptions::Option& entry, unsigned
}
/* format the help text */
void CalypOptions::doHelp( ostream& out, unsigned int columns )
void CalypOptions::doHelp( std::ostream& out, unsigned int columns )
{
const unsigned int pad_short = 3;
/* first pass: work out the longest option name */
unsigned int max_width = 0;
for( CalypOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ )
for( auto& opt : opt_list )
{
ostringstream line( ios_base::out );
doHelpOpt( line, **it, pad_short );
max_width = max( max_width, (unsigned int)line.tellp() );
std::ostringstream line( std::ios_base::out );
doHelpOpt( line, *opt, pad_short );
max_width = std::max( max_width, (unsigned int)line.tellp() );
}
unsigned int opt_width = min( max_width + 2, 28u + pad_short ) + 2;
unsigned int opt_width = std::min( max_width + 2, 28u + pad_short ) + 2;
unsigned int desc_width = columns - opt_width;
/* second pass: write out formatted option and help text.
@@ -607,17 +600,17 @@ void CalypOptions::doHelp( ostream& out, unsigned int columns )
* - if the option text is longer than opt_width, place the help
* text at opt_width on the next line.
*/
for( CalypOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ )
for( auto& opt : opt_list )
{
ostringstream line( ios_base::out );
std::ostringstream line( std::ios_base::out );
line << " ";
doHelpOpt( line, **it, pad_short );
doHelpOpt( line, *opt, pad_short );
const string& opt_desc = ( *it )->opt->opt_desc;
const std::string& opt_desc = opt->base_opt->opt_desc;
if( opt_desc.empty() )
{
/* no help text: output option, skip further processing */
cout << line.str() << endl;
std::cout << line.str() << std::endl;
continue;
}
size_t currlength = size_t( line.tellp() );
@@ -625,17 +618,17 @@ void CalypOptions::doHelp( ostream& out, unsigned int columns )
{
/* if option text is too long (and would collide with the
* help text, split onto next line */
line << endl;
line << std::endl;
currlength = 0;
}
/* split up the help text, taking into account new lines,
* (add opt_width of padding to each new line) */
for( size_t newline_pos = 0, cur_pos = 0; cur_pos != string::npos; currlength = 0 )
for( std::size_t newline_pos = 0, cur_pos = 0; cur_pos != std::string::npos; currlength = 0 )
{
/* print any required padding space for vertical alignment */
line << &( spaces[40 - opt_width + currlength] );
newline_pos = opt_desc.find_first_of( '\n', newline_pos );
if( newline_pos != string::npos )
if( newline_pos != std::string::npos )
{
/* newline found, print substring (newline needn't be stripped) */
newline_pos++;
@@ -652,14 +645,14 @@ void CalypOptions::doHelp( ostream& out, unsigned int columns )
/* find a suitable point to split text (avoid spliting in middle of word)
*/
size_t split_pos = opt_desc.find_last_of( ' ', cur_pos + desc_width );
if( split_pos != string::npos )
if( split_pos != std::string::npos )
{
/* eat up multiple space characters */
split_pos = opt_desc.find_last_not_of( ' ', split_pos ) + 1;
}
/* bad split if no suitable space to split at. fall back to width */
bool bad_split = split_pos == string::npos || split_pos <= cur_pos;
bool bad_split = split_pos == std::string::npos || split_pos <= cur_pos;
if( bad_split )
{
split_pos = cur_pos + desc_width;
@@ -677,10 +670,9 @@ void CalypOptions::doHelp( ostream& out, unsigned int columns )
{
break;
}
line << endl;
line << std::endl;
}
cout << line.str() << endl;
std::cout << line.str() << std::endl;
}
}
@@ -690,24 +682,25 @@ bool CalypOptions::checkListingOpts()
if( hasOpt( "version" ) )
{
std::cout << "Calyp version " << CALYP_VERSION_STRING << "\n";
std::cout << "Calyp version" << CALYP_VERSION_STRING << std::endl;
bRet |= true;
}
if( hasOpt( "pel_fmts" ) )
{
printf( "Calyp supported pixel formats: \n" );
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames().size(); i++ )
std::cout << "Calyp supported pixel formats:" << std::endl;
const auto& fmt_list = CalypFrame::supportedPixelFormatListNames();
for( const auto& [key, name] : fmt_list )
{
printf( " %s\n", CalypFrame::supportedPixelFormatListNames()[i].c_str() );
std::cout << " " << name << std::endl;
}
bRet |= true;
}
if( hasOpt( "quality_metrics" ) )
{
printf( "Calyp supported quality metrics: \n" );
std::cout << "Calyp supported quality metrics:" << std::endl;
for( unsigned int i = 0; i < CalypFrame::supportedQualityMetricsList().size(); i++ )
{
printf( " %s\n", CalypFrame::supportedQualityMetricsList()[i].c_str() );
std::cout << " " << CalypFrame::supportedQualityMetricsList()[i] << std::endl;
}
bRet |= true;
}
+61 -55
View File
@@ -42,33 +42,10 @@
#include <list>
#include <map>
#include <vector>
#include "CalypDefs.h"
/**
* \class OptionBase
* \ingroup CalypLibGrp
* \brief Virtual base class for storing information relating to a
* specific option This base class describes common elements.
* Type specific information should be stored in a derived class.
*/
class OptionBase
{
public:
OptionBase( const ClpString& name, const ClpString& desc, const ClpString& def )
: arg_count( 0 ), opt_string( name ), opt_desc( desc ), opt_defaults( def ) {}
virtual ~OptionBase() {}
/* parse argument arg, to obtain a value for the option */
virtual void parse( const ClpString& arg ) = 0;
int count() { return arg_count; }
bool isBinary() { return is_binary; }
int arg_count;
ClpString opt_string;
ClpString opt_desc;
ClpString opt_defaults;
bool is_binary;
};
/**
* \class CalypOptions
* \ingroup CalypLibGrp
@@ -77,34 +54,56 @@ public:
class CalypOptions
{
public:
/**
* Virtual base class for storing information relating to a
* specific option This base class describes common elements.
* Type specific information should be stored in a derived class.
*/
class OptionBase
{
public:
OptionBase( std::string name, std::string desc, std::string def )
: opt_string{ std::move( name ) }, opt_desc{ std::move( desc ) }, opt_defaults{ std::move( def ) } {}
OptionBase( OptionBase&& other ) noexcept = delete;
OptionBase& operator=( OptionBase&& other ) noexcept = delete;
OptionBase( const OptionBase& other ) = delete;
OptionBase& operator=( const OptionBase& other ) = delete;
virtual ~OptionBase() = default;
/* parse argument arg, to obtain a value for the option */
virtual void parse( const std::string& arg ) = 0;
auto count() const -> std::size_t { return arg_count; }
auto isBinary() const -> bool { return is_binary; }
std::string opt_string;
std::string opt_desc;
std::string opt_defaults;
protected:
std::size_t arg_count{ 0 };
bool is_binary{ false };
};
struct Option
{
Option();
~Option();
std::list<ClpString> opt_long;
std::list<ClpString> opt_short;
OptionBase* opt;
std::list<std::string> opt_long;
std::list<std::string> opt_short;
std::unique_ptr<OptionBase> base_opt{ nullptr };
};
typedef std::list<Option*> OptionsList;
CalypOptions( const ClpString& name = "" );
~CalypOptions();
CalypOptions() = default;
CalypOptions( std::string name );
int parse( unsigned int argc, char* argv[] );
void parse( std::vector<ClpString> args_array );
int parse( unsigned int argc, char* argv[] ); // NOLINT
void parse( std::vector<std::string> args_array );
std::list<const char*>& getUnhandledArgs() { return m_aUnhandledArgs; }
void doHelp( std::ostream& out, unsigned columns = 80 );
OptionBase* operator[]( const ClpString& optName );
OptionBase* getOption( const ClpString& optName );
CalypOptions::OptionBase* operator[]( const std::string& optName );
CalypOptions::OptionBase* getOption( const std::string& optName );
bool hasOpt( const ClpString& optName );
bool hasOpt( const std::string& optName );
OptionsList getOptionList() { return opt_list; }
void addDefaultOptions();
auto getOptionList() -> const std::list<std::unique_ptr<Option>>& { return opt_list; }
CalypOptions& addOptions();
void addOption( OptionBase* opt );
/**
* Add option described by name to the parent Options list,
@@ -112,7 +111,8 @@ public:
* with default_val as the default value
* 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 );
CalypOptions& addOption( const std::string& name, const std::string& desc );
/**
* Add option described by name to the parent Options list,
@@ -121,30 +121,36 @@ public:
* description and range along with default value
*/
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>
CalypOptions& addOption( const std::string& name, T& storage, const std::string& desc );
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 );
template <typename T>
CalypOptions& addOption( const std::string& name, T& storage, const std::string& desc, const std::string& defaults );
bool checkListingOpts();
private:
typedef std::map<ClpString, OptionsList> OptionMap;
OptionMap opt_long_map;
OptionMap opt_short_map;
void addOptionInternal( std::unique_ptr<OptionBase> opt );
OptionsList opt_list;
private:
std::map<std::string, std::list<Option*>> opt_long_map;
std::map<std::string, std::list<Option*>> opt_short_map;
ClpString m_cOptionGroupName;
bool m_bAllowUnkonw;
std::list<std::unique_ptr<Option>> opt_list;
std::string m_cOptionGroupName{ "" };
bool m_bAllowUnkonw{ true };
std::list<const char*> m_aUnhandledArgs;
bool storePair( bool allow_long, bool allow_short, const ClpString& name, const ClpString& value );
bool storePair( const ClpString& name, const ClpString& value );
unsigned int parseLONG( unsigned int argc, char* argv[] );
unsigned int parseLONG( ClpString arg );
unsigned int parseSHORT( unsigned int argc, char* argv[] );
std::list<const char*> scanArgv( unsigned int argc, char* argv[] );
bool storePair( bool allow_long, bool allow_short, const std::string& name, const std::string& value );
bool storePair( const std::string& name, const std::string& value );
unsigned int parseLONG( unsigned int argc, char* argv[] ); // NOLINT
unsigned int parseLONG( const std::string& arg );
unsigned int parseSHORT( unsigned int argc, char* argv[] ); // NOLINT
std::list<const char*> scanArgv( unsigned int argc, char* argv[] ); // NOLINT
};
#endif // __CALYPOPTIONS_H__
+110 -132
View File
@@ -22,204 +22,182 @@
* \brief Video Frame handling
*/
#include <algorithm>
#include <cassert>
#include <memory>
#include <numeric>
#include "CalypFrame.h"
#include "PixelFormats.h"
#include "config.h"
#define MAX_NUMBER_COMPONENTS 4
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];
};
constexpr auto kMinPixelValue{ 0 };
constexpr auto kMaxPixelValue{ 255 };
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 );
iG = iY - ( ( 352 * ( iU - 128 ) + 731 * ( iV - 128 ) ) >> 10 );
iB = iY + ( ( 1812 * ( iU - 128 ) ) >> 10 );
iR = iR < 0 ? 0 : iR > 255 ? 255 :
iR;
iG = iG < 0 ? 0 : iG > 255 ? 255 :
iG;
iB = iB < 0 ? 0 : iB > 255 ? 255 :
iB;
iR = std::clamp( iY + ( ( 1436 * ( iV - 128 ) ) >> 10 ), kMinPixelValue, kMaxPixelValue ); // NOLINT
iG = std::clamp( iY - ( ( 352 * ( iU - 128 ) + 731 * ( iV - 128 ) ) >> 10 ), kMinPixelValue, kMaxPixelValue ); // NOLINT
iB = std::clamp( iY + ( ( 1812 * ( iU - 128 ) ) >> 10 ), kMinPixelValue, kMaxPixelValue ); // NOLINT
}
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;
iU = ( 1000 * ( iB - iY ) + 226816 ) / 1772;
iV = ( 1000 * ( iR - iY ) + 179456 ) / 1402;
iY = ( 299 * iR + 587 * iG + 114 * iB + 500 ) / 1000; // NOLINT
iU = ( 1000 * ( iB - iY ) + 226816 ) / 1772; // NOLINT
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 )
: d{ std::make_unique<CalypPixelPrivate>( ColorSpace ) }
CalypPixel::CalypPixel( const int ColorSpace, const ClpPel c0, const ClpPel c1, const ClpPel c2 )
{
m_colorSpace = ColorSpace;
m_pelComp[0] = c0;
m_pelComp[1] = c1;
m_pelComp[2] = c2;
}
CalypPixel::CalypPixel( const int& ColorSpace, const ClpPel& c0 )
: d{ std::make_unique<CalypPixelPrivate>( ColorSpace ) }
CalypPixel::CalypPixel( const int ColorSpace, const ClpPel c0, const ClpPel c1, const ClpPel c2, const ClpPel c3 )
{
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 )
: d{ std::make_unique<CalypPixelPrivate>( ColorSpace ) }
CalypPixel& CalypPixel::operator+=( const CalypPixel& in )
{
d->PelComp[0] = c0;
d->PelComp[1] = c1;
d->PelComp[2] = c2;
}
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;
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];
}
assert( in.colorSpace() == m_colorSpace );
const auto& other_comp = in.components();
std::transform( other_comp.begin(),
other_comp.end(),
m_pelComp.begin(),
m_pelComp.begin(),
[]( auto& p1, auto& p2 ) { return p1 + p2; } );
return *this;
}
CalypPixel CalypPixel::operator+( const CalypPixel& in )
CalypPixel& CalypPixel::operator-=( const CalypPixel& in )
{
CalypPixel result;
for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ )
{
result[i] = d->PelComp[i] + in[i];
}
return result;
}
CalypPixel CalypPixel::operator+=( const CalypPixel& in )
{
for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ )
{
d->PelComp[i] += in[i];
}
assert( in.colorSpace() == m_colorSpace );
const auto& other_comp = in.components();
std::transform( other_comp.begin(),
other_comp.end(),
m_pelComp.begin(),
m_pelComp.begin(),
[]( auto& p1, auto& p2 ) { return p1 - p2; } );
return *this;
}
CalypPixel CalypPixel::operator-( const CalypPixel& in )
CalypPixel& CalypPixel::operator*=( const double op )
{
CalypPixel result;
for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ )
{
result[i] = d->PelComp[i] - in[i];
}
return result;
}
CalypPixel CalypPixel::operator-=( const CalypPixel& in )
{
for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ )
{
d->PelComp[i] -= in[i];
}
std::transform( m_pelComp.begin(),
m_pelComp.end(),
m_pelComp.begin(),
[&op]( auto& p1 ) { return p1 * op; } );
return *this;
}
CalypPixel CalypPixel::operator*( const double& op )
CalypPixel CalypPixel::operator+( const CalypPixel& in ) const
{
CalypPixel result;
for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ )
{
result[i] = d->PelComp[i] * op;
}
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::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;
}
auto CalypPixel::operator==( const CalypPixel& other ) const -> bool
{
return colorSpace() == other.colorSpace() &&
std::equal( m_pelComp.begin(), m_pelComp.end(), other.components().begin() );
}
std::ostream& operator<<( std::ostream& os, const CalypPixel& p )
{
#ifdef CLP_DEBUG
if( p.colorSpace() == CLP_COLOR_RGB || p.colorSpace() == CLP_COLOR_YUV )
{
os << "(" << p[0] << ", " << p[1] << ", " << p[2] << ")";
}
else
{
os << "(" << p[0] << ", " << p[1] << ", " << p[2] << ", " << p[3] << ")";
}
#endif
return os;
}
CalypPixel CalypPixel::convertPixel( CalypColorSpace eOutputSpace ) const
{
if( m_colorSpace == eOutputSpace )
return *this;
int outA = 0;
int outB = 0;
int outC = 0;
int outD = 0;
if( d->iColorSpace == CLP_COLOR_YUV )
if( m_colorSpace == CLP_COLOR_YUV )
{
switch( eOutputSpace )
{
case CLP_COLOR_GRAY:
outA = d->PelComp[0];
outA = m_pelComp[0];
break;
case CLP_COLOR_RGBA:
outD = 255;
outD = kMaxPixelValue;
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;
default:
break;
}
}
if( d->iColorSpace == CLP_COLOR_RGB )
if( m_colorSpace == CLP_COLOR_RGB )
{
switch( eOutputSpace )
{
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:
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;
case CLP_COLOR_RGBA:
outD = 255;
outD = kMaxPixelValue;
break;
default:
break;
+407 -310
View File
@@ -25,9 +25,15 @@
// Self
#include "CalypStream.h"
#include <cassert>
#include <deque>
#include <iostream>
#include <memory>
#include <mutex>
#include <string>
#include "CalypFrame.h"
#include "CalypStreamHandlerIf.h"
#include "LibMemory.h"
#include "StreamHandlerPortableMap.h"
#include "StreamHandlerRaw.h"
#include "config.h"
@@ -40,6 +46,11 @@
#include <cstdio>
constexpr auto kDefaultBitsPerPixel = 8;
constexpr auto kDefaultFrameRate = 30;
auto find_stream_handler( const std::string& strFilename, bool bRead ) -> CalypStreamFormat::CreateStreamHandlerFn;
std::vector<CalypStreamFormat> CalypStream::supportedReadFormats()
{
INI_REGIST_CALYP_SUPPORTED_FMT;
@@ -96,84 +107,268 @@ std::vector<CalypStandardResolution> CalypStream::stdResolutionSizes()
return stdResList;
}
class CalypStreamBufferPrivate
struct CalypStreamFrameBuffer : std::enable_shared_from_this<CalypStreamFrameBuffer>
{
private:
std::vector<CalypFrame*> m_apcFrameBuffer;
unsigned int m_uiIndex;
std::mutex buffer_mutex;
std::vector<std::unique_ptr<CalypFrame>> framePool;
std::size_t bufferIdx{ 0 };
public:
CalypStreamBufferPrivate( unsigned int size, unsigned int width, unsigned int height, int pelFormat, int bitsPixel, bool hasNegative )
CalypStreamFrameBuffer( std::size_t size, unsigned int width, unsigned int height, ClpPixelFormats pelFormat, unsigned int bitsPixel, bool hasNegative )
{
for( unsigned int i = 0; i < size; i++ )
framePool.reserve( size );
for( std::size_t i = 0; i < size; i++ )
{
m_apcFrameBuffer.push_back( new CalypFrame( width, height, pelFormat, bitsPixel, hasNegative ) );
framePool.push_back( std::make_unique<CalypFrame>( width, height, pelFormat, bitsPixel, hasNegative ) );
}
m_uiIndex = 0;
bufferIdx = framePool.size();
}
~CalypStreamBufferPrivate()
{
while( !m_apcFrameBuffer.empty() )
{
delete m_apcFrameBuffer.back();
m_apcFrameBuffer.pop_back();
}
}
void increase( unsigned int newSize )
{
for( unsigned int i = m_apcFrameBuffer.size(); i < newSize; i++ )
{
m_apcFrameBuffer.push_back( new CalypFrame( m_apcFrameBuffer.at( 0 ) ) );
}
}
unsigned int size() { return m_apcFrameBuffer.size(); }
void setIndex( unsigned int i ) { m_uiIndex = i; }
CalypFrame* frame( int i ) { return m_apcFrameBuffer.at( i ); }
CalypStreamFrameBuffer( const CalypStreamFrameBuffer& ) = delete;
CalypStreamFrameBuffer( CalypStreamFrameBuffer&& ) = delete;
CalypStreamFrameBuffer& operator=( const CalypStreamFrameBuffer& ) = delete;
CalypStreamFrameBuffer& operator=( CalypStreamFrameBuffer&& ) = delete;
CalypFrame* current() { return m_apcFrameBuffer.at( m_uiIndex ); }
CalypFrame* next() { return m_apcFrameBuffer.at( nextIndex() ); }
void setNextFrame() { m_uiIndex = nextIndex(); }
~CalypStreamFrameBuffer() = default;
private:
inline int nextIndex() { return m_uiIndex + 1 >= m_apcFrameBuffer.size() ? 0 : m_uiIndex + 1; }
inline int prevIndex() { return m_uiIndex - 1 < 0 ? m_apcFrameBuffer.size() - 1 : m_uiIndex - 1; }
void increase( std::size_t newSize )
{
framePool.reserve( newSize );
auto oldSize = framePool.size();
for( std::size_t i = oldSize; i < newSize; i++ )
{
framePool.push_back( std::make_unique<CalypFrame>( framePool[0]->getWidth(),
framePool[0]->getHeight(),
framePool[0]->getPelFormat(),
framePool[0]->getBitsPel(),
framePool[0]->getHasNegativeValues() ) );
}
bufferIdx += newSize - oldSize;
}
CalypFrame* ref() { return framePool[0].get(); }
std::shared_ptr<CalypFrame> getFrame()
{
const std::lock_guard<std::mutex> lock( buffer_mutex );
assert( bufferIdx > 0 );
bufferIdx--;
auto frame = framePool[bufferIdx].release();
auto deleter = [this, lifetime = shared_from_this()]( CalypFrame* p ) {
const std::lock_guard<std::mutex> lock( buffer_mutex );
framePool[bufferIdx].reset( p );
bufferIdx++;
};
return std::shared_ptr<CalypFrame>{ frame, deleter };
}
};
struct CalypStreamPrivate
class CalypStream::CalypStreamPrivate
{
public:
std::recursive_mutex stream_mutex;
CalypStream::Type streamType;
bool isInit;
bool isInput;
CalypStreamHandlerIf* handler;
CreateStreamHandlerFn pfctCreateHandler;
std::unique_ptr<CalypStreamHandlerIf> handler;
CalypStreamBufferPrivate* frameBuffer;
std::shared_ptr<CalypStreamFrameBuffer> frameBuffer;
std::deque<std::shared_ptr<CalypFrame>> frameFifo;
ClpString cFilename;
std::string cFilename;
long long int iCurrFrameNum;
bool bLoadAll;
CalypStreamPrivate( const CalypStreamPrivate& ) = delete;
CalypStreamPrivate( CalypStreamPrivate&& ) = delete;
CalypStreamPrivate& operator=( const CalypStreamPrivate& ) = delete;
CalypStreamPrivate& operator=( CalypStreamPrivate&& ) = delete;
CalypStreamPrivate()
{
handler = nullptr;
pfctCreateHandler = nullptr;
frameBuffer = nullptr;
isInput = true;
streamType = CalypStream::Type::Input;
isInit = false;
bLoadAll = false;
iCurrFrameNum = -1;
cFilename = "";
}
~CalypStreamPrivate()
{
close();
}
bool open( std::string filename, unsigned int width, unsigned int height, ClpPixelFormats input_format, unsigned int bitsPel, int endianness, bool hasNegative,
unsigned int frame_rate, bool forceRaw, CalypStream::Type type )
{
if( isInit )
{
close();
}
isInit = false;
streamType = type;
bool isInput = streamType == CalypStream::Type::Input;
if( forceRaw )
{
handler = StreamHandlerRaw::Create();
}
else
{
auto createHandlerFct = find_stream_handler( filename, isInput );
if( !createHandlerFct )
{
throw CalypFailure( "CalypStream", "Invalid handler" );
}
handler = createHandlerFct();
}
if( !handler )
{
throw CalypFailure( "CalypStream", "Cannot create handler" );
}
cFilename = std::move( filename );
handler->m_uiWidth = width;
handler->m_uiHeight = height;
handler->m_iPixelFormat = input_format;
handler->m_uiBitsPerPixel = bitsPel;
handler->m_iEndianness = bitsPel > 8 ? endianness : CLP_BIG_ENDIAN;
handler->m_dFrameRate = frame_rate;
if( !handler->openHandler( cFilename, isInput ) )
{
close();
throw CalypFailure( "CalypStream", "Cannot create the stream handler" );
return isInit;
}
if( handler->m_uiWidth <= 0 || handler->m_uiHeight <= 0 || handler->m_iPixelFormat == ClpPixelFormats::Invalid )
{
close();
throw CalypFailure( "CalypStream", "Incorrect configuration: width, height or pixel format" );
return isInit;
}
frameFifo.clear();
// Keep past, current and future frames
std::size_t bufferSize = isInput ? 6 : 1;
try
{
frameBuffer = std::make_shared<CalypStreamFrameBuffer>( bufferSize,
handler->m_uiWidth,
handler->m_uiHeight,
handler->m_iPixelFormat,
handler->m_uiBitsPerPixel,
hasNegative );
}
catch( CalypFailure& e )
{
close();
throw CalypFailure( "CalypStream", "Cannot allocated frame buffer" );
return isInit;
}
const CalypFrame* refFrame = frameBuffer->ref();
handler->m_uiNBytesPerFrame = refFrame->getBytesPerFrame();
// Some handlers need to know how long is a frame to get frame number
handler->calculateFrameNumber();
if( isInput && handler->m_uiTotalNumberFrames == 0 )
{
close();
throw CalypFailure( "CalypStream", "Incorrect configuration: less than one frame" );
return isInit;
}
if( !handler->configureBuffer( *refFrame ) )
{
close();
throw CalypFailure( "CalypStream", "Cannot allocated buffers" );
return isInit;
}
iCurrFrameNum = -1;
isInit = true;
seekInput( 0 );
isInit = true;
return isInit;
}
void close()
{
if( handler )
{
handler->closeHandler();
}
bLoadAll = false;
isInit = false;
}
bool seekInput( unsigned long new_frame_num )
{
const std::lock_guard<std::recursive_mutex> lock( stream_mutex );
if( !isInit || new_frame_num >= handler->m_uiTotalNumberFrames || long( new_frame_num ) == iCurrFrameNum )
return false;
iCurrFrameNum = new_frame_num;
if( bLoadAll )
return true;
frameFifo.clear();
if( !handler->seek( iCurrFrameNum ) )
{
throw CalypFailure( "CalypStream", "Cannot seek file into desired position" );
}
readNextFrame();
if( handler->m_uiTotalNumberFrames > 1 )
readNextFrame();
return true;
}
bool readNextFrame( bool fillRgbBuffer = false )
{
const std::lock_guard<std::recursive_mutex> lock( stream_mutex );
if( !isInit || streamType != CalypStream::Type::Input || handler->m_uiCurrFrameFileIdx >= handler->m_uiTotalNumberFrames )
return false;
if( bLoadAll )
return true;
auto frame = frameBuffer->getFrame();
if( !handler->read( *frame ) )
{
throw CalypFailure( "CalypStream", "Cannot read frame from stream" );
return false;
}
frameFifo.push_back( frame );
if( fillRgbBuffer )
{
frame->fillRGBBuffer();
}
return true;
}
};
std::vector<ClpString> CalypStreamFormat::getExts()
std::vector<std::string> CalypStreamFormat::getExts()
{
std::vector<ClpString> arrayExt;
ClpString::size_type prev_pos = 0, pos = 0;
while( ( pos = formatExt.find( ',', pos ) ) != ClpString::npos )
std::vector<std::string> arrayExt;
std::string::size_type prev_pos = 0, pos = 0;
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 );
prev_pos = ++pos;
}
@@ -181,69 +376,27 @@ std::vector<ClpString> CalypStreamFormat::getExts()
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()
: d( new CalypStreamPrivate )
: d{ std::make_unique<CalypStreamPrivate>() }
{
}
CalypStream::~CalypStream()
{
close();
delete d;
}
CalypStream::~CalypStream() = default;
ClpString CalypStream::getFormatName() const
std::string CalypStream::getFormatName() const
{
return !d->handler ? "" : d->handler->getFormatName();
}
ClpString CalypStream::getCodecName() const
std::string CalypStream::getCodecName() const
{
return !d->handler ? "" : d->handler->getCodecName();
}
bool CalypStream::open( ClpString filename, ClpString resolution, ClpString input_format_name, unsigned int bitsPel, int endianness, bool hasNegative,
unsigned int frame_rate, bool bInput )
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, CalypStream::Type type )
{
unsigned int width = 0;
unsigned int height = 0;
int input_format = -1;
if( resolution.size() > 0 )
{
@@ -253,123 +406,55 @@ bool CalypStream::open( ClpString filename, ClpString resolution, ClpString inpu
return false;
}
}
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames().size(); i++ )
const auto input_format = CalypFrame::findPixelFormat( input_format_name );
if( !input_format.has_value() )
{
if( clpLowercase( CalypFrame::supportedPixelFormatListNames()[i] ) == clpLowercase( input_format_name ) )
{
input_format = i;
break;
}
return false;
}
return open( filename, width, height, input_format, bitsPel, endianness, hasNegative, frame_rate, bInput );
return d->open( std::move( filename ), width, height, *input_format, bitsPel, endianness, hasNegative, frame_rate, false, type );
}
bool CalypStream::open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness,
unsigned int frame_rate, bool bInput )
bool CalypStream::open( std::string filename, unsigned int width, unsigned int height, ClpPixelFormats input_format, unsigned int bitsPel, int endianness,
unsigned int frame_rate, CalypStream::Type type )
{
return open( filename, width, height, input_format, bitsPel, endianness, false, frame_rate, bInput );
return d->open( std::move( filename ), width, height, input_format, bitsPel, endianness, false, frame_rate, false, type );
}
bool CalypStream::open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, bool hasNegative,
unsigned int frame_rate, bool bInput )
bool CalypStream::open( std::string filename, unsigned int width, unsigned int height, ClpPixelFormats input_format, unsigned int bitsPel, int endianness, bool hasNegative,
unsigned int frame_rate, CalypStream::Type type )
{
if( d->isInit )
{
close();
}
d->isInit = false;
d->isInput = bInput;
return d->open( std::move( filename ), width, height, input_format, bitsPel, endianness, hasNegative, frame_rate, false, type );
}
d->pfctCreateHandler = CalypStream::findStreamHandler( filename, d->isInput );
if( !d->pfctCreateHandler )
{
throw CalypFailure( "CalypStream", "Invalid handler" );
}
bool CalypStream::open( std::string filename, unsigned int width, unsigned int height, ClpPixelFormats input_format, unsigned int bitsPel, int endianness,
unsigned int frame_rate, bool forceRaw, CalypStream::Type type )
{
return d->open( std::move( filename ), width, height, input_format, bitsPel, endianness, false, frame_rate, forceRaw, type );
}
d->handler = d->pfctCreateHandler();
if( !d->handler )
{
throw CalypFailure( "CalypStream", "Cannot create handler" );
}
d->cFilename = filename;
d->handler->m_cFilename = filename;
d->handler->m_uiWidth = width;
d->handler->m_uiHeight = height;
d->handler->m_iPixelFormat = input_format;
d->handler->m_uiBitsPerPixel = bitsPel;
d->handler->m_iEndianness = endianness;
d->handler->m_dFrameRate = frame_rate;
if( !d->handler->openHandler( d->cFilename, d->isInput ) )
{
close();
return d->isInit;
}
if( d->handler->m_uiWidth <= 0 || d->handler->m_uiHeight <= 0 || d->handler->m_iPixelFormat < 0 )
{
close();
//throw CalypFailure( "CalypStream", "Incorrect configuration: width, height or pixel format" );
return d->isInit;
}
// Keep past, current and future frames
try
{
d->frameBuffer = new CalypStreamBufferPrivate( d->isInput ? 3 : 1, d->handler->m_uiWidth, d->handler->m_uiHeight,
d->handler->m_iPixelFormat, d->handler->m_uiBitsPerPixel, hasNegative );
}
catch( CalypFailure& e )
{
close();
throw CalypFailure( "CalypStream", "Cannot allocated frame buffer" );
return d->isInit;
}
d->handler->m_uiNBytesPerFrame = d->frameBuffer->current()->getBytesPerFrame();
// Some handlers need to know how long is a frame to get frame number
d->handler->calculateFrameNumber();
if( d->isInput && d->handler->m_uiTotalNumberFrames == 0 )
{
close();
throw CalypFailure( "CalypStream", "Incorrect configuration: less than one frame" );
return d->isInit;
}
if( !d->handler->configureBuffer( d->frameBuffer->current() ) )
{
close();
throw CalypFailure( "CalypStream", "Cannot allocated buffers" );
return d->isInit;
}
d->iCurrFrameNum = -1;
d->isInit = true;
seekInput( 0 );
d->isInit = true;
return d->isInit;
bool CalypStream::supportsFormatConfiguration()
{
if( d->handler == nullptr )
return false;
return d->handler->m_bSupportsFormat;
}
bool CalypStream::reload()
{
d->frameFifo.clear();
d->handler->closeHandler();
if( !d->handler->openHandler( d->cFilename, d->isInput ) )
if( !d->handler->openHandler( d->cFilename, d->streamType == CalypStream::Type::Input ) )
{
throw CalypFailure( "CalypStream", "Cannot open stream " + d->cFilename + " with the " +
ClpString( d->handler->m_pchHandlerName ) + " handler" );
std::string( d->handler->m_pchHandlerName ) + " handler" );
}
d->handler->m_uiNBytesPerFrame = d->frameBuffer->current()->getBytesPerFrame();
const CalypFrame* refFrame = d->frameBuffer->ref();
d->handler->m_uiNBytesPerFrame = refFrame->getBytesPerFrame();
d->handler->calculateFrameNumber();
d->handler->configureBuffer( d->frameBuffer->current() );
d->handler->configureBuffer( *refFrame );
if( d->handler->m_uiWidth <= 0 || d->handler->m_uiHeight <= 0 || d->handler->m_iPixelFormat < 0 ||
if( d->handler->m_uiWidth <= 0 || d->handler->m_uiHeight <= 0 || d->handler->m_iPixelFormat == ClpPixelFormats::Invalid ||
d->handler->m_uiBitsPerPixel == 0 || d->handler->m_uiTotalNumberFrames == 0 )
{
return false;
@@ -378,30 +463,13 @@ bool CalypStream::reload()
{
d->iCurrFrameNum = 0;
}
int currFrameNum = d->iCurrFrameNum;
auto currFrameNum = d->iCurrFrameNum;
d->iCurrFrameNum = -1;
seekInput( currFrameNum );
return true;
}
void CalypStream::close()
{
if( !d->isInit )
return;
if( d->handler )
{
d->handler->closeHandler();
d->handler->Delete();
}
if( d->frameBuffer )
delete d->frameBuffer;
d->bLoadAll = false;
d->isInit = false;
}
ClpString CalypStream::getFileName() const
std::string CalypStream::getFileName() const
{
return d->cFilename;
}
@@ -411,7 +479,7 @@ bool CalypStream::isNative() const
return d->handler->m_bNative;
}
ClpULong CalypStream::getFrameNum() const
std::uint64_t CalypStream::getFrameNum() const
{
return d->handler->m_uiTotalNumberFrames;
}
@@ -441,7 +509,7 @@ long CalypStream::getCurrFrameNum() const
return d->iCurrFrameNum;
}
void CalypStream::getFormat( unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPel, int& rEndianness,
void CalypStream::getFormat( unsigned int& rWidth, unsigned int& rHeight, ClpPixelFormats& rInputFormat, unsigned int& rBitsPerPel, int& rEndianness,
unsigned int& rFrameRate ) const
{
if( d->isInit )
@@ -451,22 +519,37 @@ void CalypStream::getFormat( unsigned int& rWidth, unsigned int& rHeight, int& r
rInputFormat = d->handler->m_iPixelFormat;
rBitsPerPel = d->handler->m_uiBitsPerPixel;
rEndianness = d->handler->m_iEndianness;
rFrameRate = d->handler->m_dFrameRate;
rFrameRate = static_cast<unsigned>( std::max( 0.0, d->handler->m_dFrameRate ) );
}
else
{
rWidth = 0;
rHeight = 0;
rInputFormat = CLP_YUV420P;
rBitsPerPel = 8;
rInputFormat = ClpPixelFormats::YUV420p;
rBitsPerPel = kDefaultBitsPerPixel;
rEndianness = 0;
rFrameRate = 30;
rFrameRate = kDefaultFrameRate;
}
}
auto CalypStream::hasNextFrame() -> bool
{
return d->frameFifo.size() > 1;
}
auto CalypStream::hasWritingSlot() -> bool
{
return !d->bLoadAll && d->frameBuffer->bufferIdx > 0;
}
/**
* @brief Read operations
*/
void CalypStream::loadAll()
{
if( d->bLoadAll || !d->isInput )
const std::lock_guard<std::recursive_mutex> lock( d->stream_mutex );
if( d->bLoadAll || d->streamType != CalypStream::Type::Input )
return;
try
@@ -475,41 +558,79 @@ void CalypStream::loadAll()
}
catch( CalypFailure& e )
{
close();
d->close();
throw CalypFailure( "CalypStream", "Cannot allocated frame buffer for the whole stream" );
}
seekInput( 0 );
for( unsigned int i = 2; i < d->frameBuffer->size(); i++ )
for( unsigned int i = 2; i < d->handler->m_uiTotalNumberFrames; i++ )
{
readFrame( d->frameBuffer->frame( i ) );
d->readNextFrame( false );
}
d->bLoadAll = true;
d->iCurrFrameNum = 0;
}
bool CalypStream::readFrame( CalypFrame* frame )
std::unique_ptr<CalypFrame> CalypStream::getCurrFrame( std::unique_ptr<CalypFrame> buffer )
{
if( !d->isInit || !d->isInput || d->handler->m_uiCurrFrameFileIdx >= d->handler->m_uiTotalNumberFrames )
return false;
if( buffer == nullptr )
buffer = std::make_unique<CalypFrame>( *d->frameFifo.front() );
else
buffer->copyFrom( *d->frameFifo.front() );
return buffer;
}
auto CalypStream::getCurrFrameAsset() -> std::shared_ptr<CalypFrame>
{
if( d->bLoadAll )
return true;
if( !d->handler->read( frame ) )
{
throw CalypFailure( "CalypStream", "Cannot read frame from stream" );
return false;
}
return true;
return d->frameFifo[d->iCurrFrameNum];
return d->frameFifo.front();
}
void CalypStream::writeFrame()
auto CalypStream::getCurrFrame() -> CalypFrame*
{
writeFrame( d->frameBuffer->current() );
if( d->bLoadAll )
return d->frameFifo[d->iCurrFrameNum].get();
return d->frameFifo.front().get();
}
void CalypStream::writeFrame( CalypFrame* pcFrame )
bool CalypStream::isEof()
{
if( d->iCurrFrameNum + 1 >= (long)( d->handler->m_uiTotalNumberFrames ) )
{
return true;
}
return false;
}
bool CalypStream::setNextFrame()
{
if( isEof() )
{
return true;
}
d->iCurrFrameNum++;
if( !d->bLoadAll )
{
assert( d->frameFifo.size() > 1 );
d->frameFifo.pop_front();
}
return false;
}
void CalypStream::readNextFrame()
{
d->readNextFrame();
}
void CalypStream::readNextFrameFillRGBBuffer()
{
d->readNextFrame( true );
}
/**
* @brief Write operations
*/
void CalypStream::writeFrame( const CalypFrame& pcFrame )
{
if( !d->handler->write( pcFrame ) )
{
@@ -518,76 +639,36 @@ void CalypStream::writeFrame( CalypFrame* pcFrame )
return;
}
bool CalypStream::saveFrame( const ClpString& filename )
bool CalypStream::saveFrame( const std::string& filename )
{
return saveFrame( filename, d->frameBuffer->current() );
return saveFrame( filename, *getCurrFrame() );
}
bool CalypStream::saveFrame( const ClpString& filename, CalypFrame* saveFrame )
bool CalypStream::saveFrame( const std::string& filename, const CalypFrame& saveFrame )
{
CalypStream auxSaveStream;
if( !auxSaveStream.open( filename, saveFrame->getWidth(), saveFrame->getHeight(), saveFrame->getPelFormat(),
saveFrame->getBitsPel(), CLP_LITTLE_ENDIAN, 1, false ) )
if( !auxSaveStream.open( filename, saveFrame.getWidth(), saveFrame.getHeight(), saveFrame.getPelFormat(),
saveFrame.getBitsPel(), CLP_LITTLE_ENDIAN, 1, Type::Output ) )
{
return false;
}
auxSaveStream.writeFrame( saveFrame );
auxSaveStream.close();
return true;
}
bool CalypStream::setNextFrame()
{
bool bEndOfSeq = false;
if( d->iCurrFrameNum + 1 < (long)( d->handler->m_uiTotalNumberFrames ) )
{
d->frameBuffer->setNextFrame();
d->iCurrFrameNum++;
}
else
{
bEndOfSeq = true;
}
return bEndOfSeq;
}
void CalypStream::readNextFrame()
{
readFrame( d->frameBuffer->next() );
}
void CalypStream::readNextFrameFillRGBBuffer()
{
readNextFrame();
d->frameBuffer->next()->fillRGBBuffer();
return;
}
CalypFrame* CalypStream::getCurrFrame( CalypFrame* pyuv_image ) const
{
if( pyuv_image == NULL )
pyuv_image = new CalypFrame( d->frameBuffer->current() );
else
pyuv_image->copyFrom( d->frameBuffer->current() );
return pyuv_image;
}
CalypFrame* CalypStream::getCurrFrame() const
{
return d->frameBuffer->current();
}
/**
* @brief Seek operations
*/
bool CalypStream::seekInputRelative( bool bIsFoward )
{
if( !d->isInit || !d->isInput )
if( !d->isInit || d->streamType != Type::Input )
return false;
bool bRet = false;
if( bIsFoward )
{
bRet = !setNextFrame();
readFrame( d->frameBuffer->next() );
d->readNextFrame();
}
else
{
@@ -599,26 +680,42 @@ bool CalypStream::seekInputRelative( bool bIsFoward )
bool CalypStream::seekInput( unsigned long new_frame_num )
{
if( !d->isInit || new_frame_num >= d->handler->m_uiTotalNumberFrames || long( new_frame_num ) == d->iCurrFrameNum )
return false;
d->iCurrFrameNum = new_frame_num;
if( d->bLoadAll )
{
d->frameBuffer->setIndex( d->iCurrFrameNum );
return true;
}
if( !d->handler->seek( d->iCurrFrameNum ) )
{
throw CalypFailure( "CalypStream", "Cannot seek file into desired position" );
}
d->frameBuffer->setIndex( 0 );
readFrame( d->frameBuffer->current() );
if( d->handler->m_uiTotalNumberFrames > 1 )
readFrame( d->frameBuffer->next() );
return true;
return d->seekInput( new_frame_num );
}
auto find_stream_handler( const 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
}
+85 -48
View File
@@ -26,28 +26,39 @@
#ifndef __CALYPSTREAM_H__
#define __CALYPSTREAM_H__
#include "CalypDefs.h"
#include <memory>
#include <vector>
#include "CalypFrame.h"
class CalypFrame;
class CalypStreamHandlerIf;
typedef CalypStreamHandlerIf* ( *CreateStreamHandlerFn )( void );
typedef struct
struct CalypStandardResolution
{
ClpString formatName;
ClpString formatExt;
std::vector<ClpString> getExts();
ClpString formatPattern;
CreateStreamHandlerFn formatFct;
} CalypStreamFormat;
typedef struct
{
ClpString shortName;
std::string shortName;
unsigned int uiWidth;
unsigned int uiHeight;
} CalypStandardResolution;
};
/**
* \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
@@ -57,67 +68,93 @@ typedef struct
class CalypStream
{
public:
enum class Type
{
Input,
Output
};
static std::vector<CalypStreamFormat> supportedReadFormats();
static std::vector<CalypStreamFormat> supportedWriteFormats();
static CreateStreamHandlerFn findStreamHandler( ClpString strFilename, bool bRead );
static std::vector<CalypStandardResolution> stdResolutionSizes();
CalypStream();
CalypStream( CalypStream&& other ) noexcept = delete;
CalypStream& operator=( CalypStream&& other ) noexcept = delete;
CalypStream( const CalypStream& other ) = delete;
CalypStream& operator=( const CalypStream& other ) = delete;
~CalypStream();
ClpString getFormatName() const;
;
ClpString getCodecName() const;
;
std::string getFormatName() 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 bInput );
bool open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, unsigned int frame_rate,
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 bInput );
bool open( std::string filename,
std::string resolution,
std::string input_format,
unsigned int bitsPel,
int endianness,
bool hasNegative,
unsigned int frame_rate,
Type type );
bool open( std::string filename, unsigned int width, unsigned int height, ClpPixelFormats input_format, unsigned int bitsPel, int endianness,
unsigned int frame_rate, CalypStream::Type type );
bool open( std::string filename,
unsigned int width,
unsigned int height,
ClpPixelFormats input_format,
unsigned int bitsPel,
int endianness,
bool hasNegative,
unsigned int frame_rate,
Type type );
bool open( std::string filename,
unsigned int width,
unsigned int height,
ClpPixelFormats input_format,
unsigned int bitsPel,
int endianness,
unsigned int frame_rate,
bool forceRaw,
Type type );
bool supportsFormatConfiguration();
bool reload();
void close();
bool isNative() const;
ClpString getFileName() const;
ClpULong getFrameNum() const;
std::string getFileName() const;
std::uint64_t getFrameNum() const;
unsigned int getWidth() const;
unsigned int getHeight() const;
unsigned int getBitsPerPixel() const;
int getEndianess() const;
long getCurrFrameNum() const;
double getFrameRate() const;
void getFormat( unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPel, int& rEndianness,
void getFormat( unsigned int& rWidth, unsigned int& rHeight, ClpPixelFormats& rInputFormat, unsigned int& rBitsPerPel, int& rEndianness,
unsigned int& rFrameRate ) const;
auto hasNextFrame() -> bool;
auto hasWritingSlot() -> bool;
void loadAll();
void writeFrame();
void writeFrame( CalypFrame* pcFrame );
bool saveFrame( const ClpString& filename );
static bool saveFrame( const ClpString& filename, CalypFrame* saveFrame );
CalypFrame* getCurrFrame( CalypFrame* ) const;
// continuous read control
std::unique_ptr<CalypFrame> getCurrFrame( std::unique_ptr<CalypFrame> buffer );
auto getCurrFrameAsset() -> std::shared_ptr<CalypFrame>;
auto getCurrFrame() -> CalypFrame*;
bool isEof();
bool setNextFrame();
void readNextFrame();
void readNextFrameFillRGBBuffer();
CalypFrame* getCurrFrame() const;
void writeFrame( const CalypFrame& pcFrame );
bool saveFrame( const std::string& filename );
static bool saveFrame( const std::string& filename, const CalypFrame& saveFrame );
bool seekInputRelative( bool bIsFoward );
bool seekInput( unsigned long new_frame_num );
private:
bool readFrame( CalypFrame* frame );
private:
struct CalypStreamPrivate* d;
class CalypStreamPrivate;
std::unique_ptr<CalypStreamPrivate> d;
};
#endif // __CALYPSTREAM_H__
+41 -45
View File
@@ -27,6 +27,7 @@
#include <vector>
#include "CalypDefs.h"
#include "CalypStream.h"
#define INI_REGIST_CALYP_SUPPORTED_FMT \
@@ -51,12 +52,11 @@
formatsList.insert( formatsList.end(), new_fmts.begin(), new_fmts.end() ); \
}
#define REGISTER_CALYP_STREAM_HANDLER( X ) \
public: \
static CalypStreamHandlerIf* Create() { return new X(); } \
void Delete() { delete this; } \
static std::vector<CalypStreamFormat> supportedReadFormats(); \
static std::vector<CalypStreamFormat> supportedWriteFormats(); \
#define REGISTER_CALYP_STREAM_HANDLER( X ) \
public: \
static std::unique_ptr<CalypStreamHandlerIf> Create() { return std::make_unique<X>(); } \
static std::vector<CalypStreamFormat> supportedReadFormats(); \
static std::vector<CalypStreamFormat> supportedWriteFormats(); \
// static int checkforSupportedFile( String, bool );
/**
@@ -69,55 +69,51 @@ class CalypStreamHandlerIf
friend class CalypStream;
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 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 bool configureBuffer( CalypFrame* pcFrame ) = 0;
virtual bool seek( ClpULong iFrameNum ) = 0;
virtual bool read( CalypFrame* pcFrame ) = 0;
virtual bool write( CalypFrame* pcFrame ) = 0;
virtual bool configureBuffer( const CalypFrame& pcFrame ) = 0;
virtual bool seek( std::uint64_t iFrameNum ) = 0;
virtual bool read( CalypFrame& pcFrame ) = 0;
virtual bool write( const CalypFrame& pcFrame ) = 0;
virtual void calculateFrameNumber(){};
ClpString getFormatName() { return m_strFormatName; }
ClpString getCodecName() { return m_strCodecName; }
std::string getFormatName()
{
return m_strFormatName;
}
std::string getCodecName()
{
return m_strCodecName;
}
protected:
const char* m_pchHandlerName;
CalypStreamHandlerIf() = default;
CalypStreamHandlerIf( bool supportsFormats )
: m_bSupportsFormat{ supportsFormats }
{
}
ClpString m_strFormatName;
ClpString m_strCodecName;
bool m_bIsInput;
bool m_bNative;
ClpString m_cFilename;
unsigned int m_uiWidth;
unsigned int m_uiHeight;
int m_iPixelFormat;
unsigned int m_uiBitsPerPixel;
int m_iEndianness;
double m_dFrameRate;
ClpULong m_uiCurrFrameFileIdx;
ClpULong m_uiTotalNumberFrames;
const char* m_pchHandlerName{ "" };
const bool m_bSupportsFormat{ false };
std::string m_strFormatName;
std::string m_strCodecName;
bool m_bIsInput{ true };
bool m_bNative{ true };
unsigned int m_uiWidth{ 0 };
unsigned int m_uiHeight{ 0 };
ClpPixelFormats m_iPixelFormat{ ClpPixelFormats::Invalid };
unsigned int m_uiBitsPerPixel{ 8 };
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;
ClpULong m_uiNBytesPerFrame;
bool m_isEOF;
std::uint64_t m_uiNBytesPerFrame{ 0 };
bool m_isEOF{ false };
};
#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__
+21 -22
View File
@@ -25,7 +25,6 @@
#include "PixelFormats.h"
#include "CalypFrame.h"
#include "LibMemory.h"
#include "config.h"
#ifdef USE_FFMPEG
#include "StreamHandlerLibav.h"
@@ -44,11 +43,11 @@
#define ADD_FFMPEG_PEL_FMT( fmt ) 0
#endif
const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
const std::map<ClpPixelFormats, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
{
CLP_YUV420P,
ClpPixelFormats::YUV420p,
{
"YUV420p",
"YUV420p"sv,
CLP_COLOR_YUV,
3,
3,
@@ -63,9 +62,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_YUV422P,
ClpPixelFormats::YUV422p,
{
"YUV422p",
"YUV422p"sv,
CLP_COLOR_YUV,
3,
3,
@@ -80,9 +79,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_YUV444P,
ClpPixelFormats::YUV444p,
{
"YUV444p",
"YUV444p"sv,
CLP_COLOR_YUV,
3,
3,
@@ -97,9 +96,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_YUYV422,
ClpPixelFormats::YUYV422,
{
"YUYV422",
"YUYV422"sv,
CLP_COLOR_YUV,
3,
1,
@@ -114,9 +113,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_GRAY,
ClpPixelFormats::Gray,
{
"GRAY",
"GRAY"sv,
CLP_COLOR_GRAY,
1,
1,
@@ -127,9 +126,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_RGB24P,
ClpPixelFormats::RGB24p,
{
"RGBp",
"RGBp"sv,
CLP_COLOR_RGB,
3,
3,
@@ -144,9 +143,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_RGB24,
ClpPixelFormats::RGB24,
{
"RGB",
"RGB"sv,
CLP_COLOR_RGB,
3,
1,
@@ -161,9 +160,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_BGR24,
ClpPixelFormats::BGR24,
{
"BGR",
"BGR"sv,
CLP_COLOR_RGB,
3,
1,
@@ -178,9 +177,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_RGBA32,
ClpPixelFormats::RGBA32,
{
"RGBA",
"RGBA"sv,
CLP_COLOR_RGBA,
4,
1,
@@ -196,9 +195,9 @@ const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap = {
},
},
{
CLP_BGRA32,
ClpPixelFormats::BGRA32,
{
"BGRA",
"BGRA"sv,
CLP_COLOR_RGBA,
4,
1,
+19 -12
View File
@@ -29,11 +29,21 @@
#include "CalypFrame.h"
#define CHROMA_RESAMPLING( X ) ( ( ( X + 1 ) >> 1 ) << 1 )
using namespace std::string_view_literals;
#define CHROMARATIO( SIZE, RATIO ) ( RATIO > 1 ? ( ( SIZE + 1 ) / RATIO ) : SIZE )
template <typename T>
inline constexpr T CHROMA_RESAMPLING( T in )
{
return ( ( ( in + 1 ) >> 1 ) << 1 );
}
typedef struct CalypComponentDescriptor
template <typename T, typename R>
inline constexpr T CHROMARATIO( T size, R ratio )
{
return ( ratio > 1 ? ( ( size + 1 ) / ratio ) : size );
}
struct CalypComponentDescriptor
{
/**
* Which of the 4 planes contains the component.
@@ -51,8 +61,7 @@ typedef struct CalypComponentDescriptor
* Elements are bits for bitstream formats, bytes otherwise.
*/
unsigned short offset_plus1;
} CalypComponentDescriptor;
};
/**
* Descriptor that unambiguously describes how the bits of a pixel are
@@ -63,9 +72,9 @@ typedef struct CalypComponentDescriptor
* and all the YUV variants) AVPixFmtDescriptor just stores how values
* are stored not what these values represent.
*/
typedef struct CalypPixelFormatDescriptor
struct CalypPixelFormatDescriptor
{
const char* name;
std::string_view name;
int colorSpace;
@@ -102,11 +111,9 @@ typedef struct CalypPixelFormatDescriptor
* otherwise 0 is luma, 1 is chroma-U and 2 is chroma-V.
*/
CalypComponentDescriptor comp[4];
};
} CalypPixelFormatDescriptor;
#define MAX_NUMBER_PLANES 3
extern const std::map<int, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap;
static constexpr std::size_t kNumberOfPixelFormats{ 10 };
extern const std::map<ClpPixelFormats, CalypPixelFormatDescriptor> g_CalypPixFmtDescriptorsMap;
#endif // __PIXELFORMATS_H__
+28 -33
View File
@@ -28,7 +28,6 @@
#include <iostream>
#include "CalypFrame.h"
#include "LibMemory.h"
#include "PixelFormats.h"
#if( ( LIBAVCODEC_VERSION_MAJOR > 57 ) || ( LIBAVCODEC_VERSION_MAJOR == 57 ) && ( LIBAVCODEC_VERSION_MINOR >= 37 ) )
@@ -64,7 +63,7 @@ StreamHandlerLibav::StreamHandlerLibav()
m_pchHandlerName = "FFmpeg";
}
bool StreamHandlerLibav::openHandler( ClpString strFilename, bool bInput )
bool StreamHandlerLibav::openHandler( std::string strFilename, bool bInput )
{
const char* filename = strFilename.c_str();
@@ -91,7 +90,7 @@ bool StreamHandlerLibav::openHandler( ClpString strFilename, bool bInput )
// }
// Register all components of FFmpeg
//av_register_all();
// av_register_all();
/* open input file, and allocate format context */
if( avformat_open_input( &m_cFmtCtx, filename, NULL, NULL ) < 0 )
@@ -173,8 +172,8 @@ bool StreamHandlerLibav::openHandler( ClpString strFilename, bool bInput )
m_uiBitsPerPixel = 8;
/**
* Auxiliar conversation to re-use similar pixfmt
*/
* Auxiliar conversation to re-use similar pixfmt
*/
int auxPixFmt = m_ffPixFmt;
switch( m_ffPixFmt )
{
@@ -198,20 +197,16 @@ bool StreamHandlerLibav::openHandler( ClpString strFilename, bool bInput )
auxPixFmt = AV_PIX_FMT_GRAY8;
}
m_iPixelFormat = CLP_INVALID_FMT;
for( int i = 0; i < CalypFrame::numberOfFormats(); i++ )
m_iPixelFormat = ClpPixelFormats::Invalid;
m_bNative = false;
auto found_fmt = std::find_if( g_CalypPixFmtDescriptorsMap.begin(), g_CalypPixFmtDescriptorsMap.end(),
[auxPixFmt]( const auto& fmt ) {
return fmt.second.ffmpegPelFormat == auxPixFmt;
} );
if( found_fmt != g_CalypPixFmtDescriptorsMap.end() )
{
if( g_CalypPixFmtDescriptorsMap.at( i ).ffmpegPelFormat == auxPixFmt )
{
m_iPixelFormat = i;
break;
}
}
if( m_iPixelFormat == CLP_INVALID_FMT )
{
m_bNative = false;
//throw CalypFailure( "StreamHandlerLibav", "Cannot open file using FFmpeg libs - unsupported pixel format" );
//return false;
m_bNative = true;
m_iPixelFormat = found_fmt->first;
}
double fr = 30;
@@ -250,27 +245,27 @@ bool StreamHandlerLibav::openHandler( ClpString strFilename, bool bInput )
if( !m_bNative )
{
int newPelFmt = -1;
ClpPixelFormats newPelFmt{ ClpPixelFormats::Invalid };
const AVPixFmtDescriptor* ffPelDesc = av_pix_fmt_desc_get( AVPixelFormat( m_ffPixFmt ) );
if( ffPelDesc->flags & AV_PIX_FMT_FLAG_PAL )
{
newPelFmt = CLP_RGB24;
newPelFmt = ClpPixelFormats::RGB24;
}
else if( ffPelDesc->flags & AV_PIX_FMT_FLAG_ALPHA )
{
newPelFmt = CLP_RGBA32;
newPelFmt = ClpPixelFormats::RGBA32;
}
else if( ffPelDesc->flags & AV_PIX_FMT_FLAG_RGB )
{
newPelFmt = CLP_RGB24;
newPelFmt = ClpPixelFormats::RGB24;
}
else if( ffPelDesc->nb_components == 1 )
{
newPelFmt = CLP_GRAY;
newPelFmt = ClpPixelFormats::Gray;
}
else
{
newPelFmt = CLP_YUV444P;
newPelFmt = ClpPixelFormats::YUV444p;
}
m_iPixelFormat = newPelFmt;
@@ -325,15 +320,15 @@ void StreamHandlerLibav::closeHandler()
m_bHasStream = false;
}
bool StreamHandlerLibav::configureBuffer( CalypFrame* pcFrame )
bool StreamHandlerLibav::configureBuffer( const CalypFrame& pcFrame )
{
m_pStreamBuffer.resize( pcFrame->getBytesPerFrame() );
m_pStreamBuffer.resize( pcFrame.getBytesPerFrame() );
return true;
}
void StreamHandlerLibav::calculateFrameNumber()
{
ClpULong num_frames;
std::uint64_t num_frames;
/*if( m_cStream->nb_frames )
{
num_frames = m_cStream->nb_frames;
@@ -354,7 +349,7 @@ void StreamHandlerLibav::calculateFrameNumber()
m_uiTotalNumberFrames = num_frames;
}
bool StreamHandlerLibav::read( CalypFrame* pcFrame )
bool StreamHandlerLibav::read( CalypFrame& pcFrame )
{
int bGotFrame = 0;
bool bErrors = false;
@@ -370,8 +365,8 @@ bool StreamHandlerLibav::read( CalypFrame* pcFrame )
bReadPkt = true;
else
return false;
//if( iRet == AVERROR_EOF )
// m_isEOF = true;
// if( iRet == AVERROR_EOF )
// m_isEOF = true;
}
else
{
@@ -428,19 +423,19 @@ bool StreamHandlerLibav::read( CalypFrame* pcFrame )
av_image_copy_to_buffer( m_pStreamBuffer.data(), m_uiFrameBufferSize, decFrame->data,
decFrame->linesize, AVPixelFormat( m_ffPixFmt ), m_uiWidth, m_uiHeight, 1 );
pcFrame->frameFromBuffer( m_pStreamBuffer, m_iEndianness );
pcFrame.frameFromBuffer( m_pStreamBuffer, m_iEndianness );
m_uiCurrFrameFileIdx++;
return true;
}
return false;
}
bool StreamHandlerLibav::write( CalypFrame* pcFrame )
bool StreamHandlerLibav::write( const CalypFrame& pcFrame )
{
return false;
}
bool StreamHandlerLibav::seek( ClpULong iFrameNum )
bool StreamHandlerLibav::seek( std::uint64_t iFrameNum )
{
if( m_uiTotalNumberFrames == 1 )
return true;
+5 -5
View File
@@ -63,13 +63,13 @@ class StreamHandlerLibav : public CalypStreamHandlerIf
public:
StreamHandlerLibav();
~StreamHandlerLibav() {}
bool openHandler( ClpString strFilename, bool bInput );
bool openHandler( std::string strFilename, bool bInput );
void closeHandler();
bool configureBuffer( CalypFrame* pcFrame );
bool configureBuffer( const CalypFrame& pcFrame );
void calculateFrameNumber();
bool seek( ClpULong iFrameNum );
bool read( CalypFrame* pcFrame );
bool write( CalypFrame* pcFrame );
bool seek( std::uint64_t iFrameNum );
bool read( CalypFrame& pcFrame );
bool write( const CalypFrame& pcFrame );
unsigned int getStreamDuration() { return m_uiSecs; }
unsigned char* m_pchFrameBuffer;
+26 -25
View File
@@ -28,7 +28,8 @@
#include <opencv2/opencv.hpp>
#include "CalypFrame.h"
#include "LibMemory.h"
#include "PixelFormats.h"
#if CV_MAJOR_VERSION >= 3
#include <opencv2/videoio.hpp>
#endif
@@ -61,32 +62,32 @@ std::vector<CalypStreamFormat> StreamHandlerOpenCV::supportedWriteFormats()
StreamHandlerOpenCV::StreamHandlerOpenCV()
{
m_pchHandlerName = "OpenCV";
pcVideoCapture = NULL;
m_pcVideoCapture = NULL;
}
bool StreamHandlerOpenCV::openHandler( ClpString strFilename, bool bInput )
bool StreamHandlerOpenCV::openHandler( std::string strFilename, bool bInput )
{
m_cFilename = strFilename;
m_cFilename = std::move( strFilename );
if( bInput )
{
#if( CV_VERSION_MAJOR >= 3 )
/*
* 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;
if( m_cFilename.find( "/dev/video0" ) != ClpString::npos )
if( m_cFilename.find( "/dev/video0" ) != std::string::npos )
iDeviceId = 0;
else if( m_cFilename.find( "/dev/video1" ) != ClpString::npos )
else if( m_cFilename.find( "/dev/video1" ) != std::string::npos )
iDeviceId = 1;
m_strFormatName = "DEV";
m_strCodecName = "Raw Video";
pcVideoCapture = new VideoCapture( iDeviceId );
m_pcVideoCapture = new VideoCapture( iDeviceId );
#if CV_MAJOR_VERSION >= 4
m_uiWidth = pcVideoCapture->get( cv::CAP_PROP_FRAME_WIDTH );
m_uiHeight = pcVideoCapture->get( cv::CAP_PROP_FRAME_HEIGHT );
m_uiWidth = m_pcVideoCapture->get( cv::CAP_PROP_FRAME_WIDTH );
m_uiHeight = m_pcVideoCapture->get( cv::CAP_PROP_FRAME_HEIGHT );
#else
m_uiWidth = pcVideoCapture->get( CV_CAP_PROP_FRAME_WIDTH );
m_uiHeight = pcVideoCapture->get( CV_CAP_PROP_FRAME_HEIGHT );
@@ -104,10 +105,10 @@ bool StreamHandlerOpenCV::openHandler( ClpString strFilename, bool bInput )
m_dFrameRate = 1;
}
m_uiBitsPerPixel = 8;
m_iPixelFormat = CalypFrame::findPixelFormat( "BGR" );
m_iPixelFormat = ClpPixelFormats::BGR24;
m_uiTotalNumberFrames = 1;
if( pcVideoCapture )
if( m_pcVideoCapture )
{
m_uiTotalNumberFrames = 2;
}
@@ -118,50 +119,50 @@ bool StreamHandlerOpenCV::openHandler( ClpString strFilename, bool bInput )
void StreamHandlerOpenCV::closeHandler()
{
if( pcVideoCapture )
if( m_pcVideoCapture )
{
pcVideoCapture->release();
delete pcVideoCapture;
pcVideoCapture = NULL;
m_pcVideoCapture->release();
delete m_pcVideoCapture;
m_pcVideoCapture = NULL;
}
}
bool StreamHandlerOpenCV::configureBuffer( CalypFrame* pcFrame )
bool StreamHandlerOpenCV::configureBuffer( const CalypFrame& pcFrame )
{
return true;
}
bool StreamHandlerOpenCV::seek( ClpULong iFrameNum )
bool StreamHandlerOpenCV::seek( std::uint64_t iFrameNum )
{
// m_uiCurrFrameFileIdx =
return true;
}
bool StreamHandlerOpenCV::read( CalypFrame* pcFrame )
bool StreamHandlerOpenCV::read( CalypFrame& pcFrame )
{
bool bRet = false;
if( pcVideoCapture )
if( m_pcVideoCapture )
{
Mat cvMat;
bRet = pcVideoCapture->read( cvMat );
bRet = m_pcVideoCapture->read( cvMat );
if( bRet )
bRet = pcFrame->fromMat( cvMat );
bRet = pcFrame.fromMat( cvMat );
}
else
{
Mat cvMat = cv::imread( m_cFilename );
bRet = pcFrame->fromMat( cvMat );
bRet = pcFrame.fromMat( cvMat );
}
if( bRet )
m_uiCurrFrameFileIdx++;
return bRet;
}
bool StreamHandlerOpenCV::write( CalypFrame* pcFrame )
bool StreamHandlerOpenCV::write( const CalypFrame& pcFrame )
{
bool bRet = false;
Mat cvFrame;
bRet = pcFrame->toMat( cvFrame, false, true );
bRet = pcFrame.toMat( cvFrame, false, true );
if( !bRet )
return bRet;
bRet = cv::imwrite( m_cFilename, cvFrame );
+7 -6
View File
@@ -40,15 +40,16 @@ class StreamHandlerOpenCV : public CalypStreamHandlerIf
public:
StreamHandlerOpenCV();
~StreamHandlerOpenCV() {}
bool openHandler( ClpString strFilename, bool bInput );
bool openHandler( std::string strFilename, bool bInput );
void closeHandler();
bool configureBuffer( CalypFrame* pcFrame );
bool seek( ClpULong iFrameNum );
bool read( CalypFrame* pcFrame );
bool write( CalypFrame* pcFrame );
bool configureBuffer( const CalypFrame& pcFrame );
bool seek( std::uint64_t iFrameNum );
bool read( CalypFrame& pcFrame );
bool write( const CalypFrame& pcFrame );
private:
cv::VideoCapture* pcVideoCapture;
std::string m_cFilename;
cv::VideoCapture* m_pcVideoCapture;
};
#endif // __STREAMHANDLEROPENCV_H__
+14 -14
View File
@@ -28,7 +28,7 @@
#include <cstdio>
#include "CalypFrame.h"
#include "LibMemory.h"
#include "PixelFormats.h"
std::vector<CalypStreamFormat> StreamHandlerPortableMap::supportedReadFormats()
{
@@ -48,7 +48,7 @@ std::vector<CalypStreamFormat> StreamHandlerPortableMap::supportedWriteFormats()
END_REGIST_CALYP_SUPPORTED_FMT;
}
bool StreamHandlerPortableMap::openHandler( ClpString strFilename, bool bInput )
bool StreamHandlerPortableMap::openHandler( std::string strFilename, bool bInput )
{
m_bIsInput = bInput;
m_pFile = NULL;
@@ -80,7 +80,7 @@ bool StreamHandlerPortableMap::openHandler( ClpString strFilename, bool bInput )
}
}
m_uiBitsPerPixel = log( m_iMaxValue + 1 ) / log( 2 );
m_iPixelFormat = m_iMagicNumber == 1 || m_iMagicNumber == 2 || m_iMagicNumber == 5 ? CLP_GRAY : CLP_RGB24;
m_iPixelFormat = m_iMagicNumber == 1 || m_iMagicNumber == 2 || m_iMagicNumber == 5 ? ClpPixelFormats::Gray : ClpPixelFormats::RGB24;
}
else
{
@@ -89,17 +89,17 @@ bool StreamHandlerPortableMap::openHandler( ClpString strFilename, bool bInput )
if( m_uiBitsPerPixel == 1 )
{
m_iMagicNumber = 1;
m_iPixelFormat = CalypFrame::findPixelFormat( "GRAY" );
m_iPixelFormat = ClpPixelFormats::Gray;
}
else if( colorSpace == CLP_COLOR_GRAY )
{
m_iMagicNumber = 5;
m_iPixelFormat = CalypFrame::findPixelFormat( "GRAY" );
m_iPixelFormat = ClpPixelFormats::Gray;
}
else if( colorSpace == CLP_COLOR_RGB )
{
m_iMagicNumber = 6;
m_iPixelFormat = CalypFrame::findPixelFormat( "RGB" );
m_iPixelFormat = ClpPixelFormats::RGB24;
}
else
{
@@ -126,32 +126,32 @@ void StreamHandlerPortableMap::closeHandler()
fclose( m_pFile );
}
bool StreamHandlerPortableMap::configureBuffer( CalypFrame* pcFrame )
bool StreamHandlerPortableMap::configureBuffer( const CalypFrame& pcFrame )
{
m_pStreamBuffer.resize( pcFrame->getBytesPerFrame() );
m_pStreamBuffer.resize( pcFrame.getBytesPerFrame() );
return true;
}
bool StreamHandlerPortableMap::seek( ClpULong iFrameNum )
bool StreamHandlerPortableMap::seek( std::uint64_t iFrameNum )
{
// m_uiCurrFrameFileIdx =
return true;
}
bool StreamHandlerPortableMap::read( CalypFrame* pcFrame )
bool StreamHandlerPortableMap::read( CalypFrame& pcFrame )
{
unsigned long long int processed_bytes = fread( m_pStreamBuffer.data(), sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile );
if( processed_bytes != m_uiNBytesPerFrame )
return false;
pcFrame->frameFromBuffer( m_pStreamBuffer, CLP_BIG_ENDIAN );
pcFrame.frameFromBuffer( m_pStreamBuffer, CLP_BIG_ENDIAN );
m_uiCurrFrameFileIdx++;
return true;
}
bool StreamHandlerPortableMap::write( CalypFrame* pcFrame )
bool StreamHandlerPortableMap::write( const CalypFrame& pcFrame )
{
CalypFrame pcRGBFrame( pcFrame->getWidth(), pcFrame->getHeight(),
m_iPixelFormat, pcFrame->getBitsPel() );
CalypFrame pcRGBFrame( pcFrame.getWidth(), pcFrame.getHeight(),
m_iPixelFormat, pcFrame.getBitsPel() );
pcRGBFrame.copyFrom( pcFrame );
fseek( m_pFile, 0, SEEK_SET );
fprintf( m_pFile, "P%d\n%d %d\n", m_iMagicNumber, m_uiWidth, m_uiHeight );
+5 -5
View File
@@ -35,12 +35,12 @@ class StreamHandlerPortableMap : public CalypStreamHandlerIf
public:
StreamHandlerPortableMap() { m_pchHandlerName = "PortableMaps"; }
~StreamHandlerPortableMap() {}
bool openHandler( ClpString strFilename, bool bInput );
bool openHandler( std::string strFilename, bool bInput );
void closeHandler();
bool configureBuffer( CalypFrame* pcFrame );
bool seek( ClpULong iFrameNum );
bool read( CalypFrame* pcFrame );
bool write( CalypFrame* pcFrame );
bool configureBuffer( const CalypFrame& pcFrame );
bool seek( std::uint64_t iFrameNum );
bool read( CalypFrame& pcFrame );
bool write( const CalypFrame& pcFrame );
private:
FILE* m_pFile; /**< The input file pointer >*/
+19 -10
View File
@@ -25,9 +25,9 @@
#include "StreamHandlerRaw.h"
#include <cstdio>
#include <filesystem>
#include "CalypFrame.h"
#include "LibMemory.h"
std::vector<CalypStreamFormat> StreamHandlerRaw::supportedReadFormats()
{
@@ -35,6 +35,7 @@ std::vector<CalypStreamFormat> StreamHandlerRaw::supportedReadFormats()
REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerRaw::Create, "Raw YUV Video", "yuv" );
REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerRaw::Create, "Raw Gray Video", "gray" );
REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerRaw::Create, "Raw RGB Video", "rgb" );
REGIST_CALYP_SUPPORTED_FMT( &StreamHandlerRaw::Create, "Raw Video", "raw" );
END_REGIST_CALYP_SUPPORTED_FMT;
}
@@ -45,7 +46,13 @@ std::vector<CalypStreamFormat> StreamHandlerRaw::supportedWriteFormats()
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_pFile = NULL;
@@ -55,7 +62,9 @@ bool StreamHandlerRaw::openHandler( ClpString strFilename, bool bInput )
return false;
}
calculateFrameNumber();
m_strFormatName = "YUV";
std::string fileExtension = std::filesystem::path{ strFilename }.extension().string();
fileExtension.erase( fileExtension.begin() );
m_strFormatName = clpUppercase( fileExtension );
m_strCodecName = "Raw Video";
return true;
}
@@ -66,9 +75,9 @@ void StreamHandlerRaw::closeHandler()
fclose( m_pFile );
}
bool StreamHandlerRaw::configureBuffer( CalypFrame* pcFrame )
bool StreamHandlerRaw::configureBuffer( const CalypFrame& pcFrame )
{
m_pStreamBuffer.resize( pcFrame->getBytesPerFrame() );
m_pStreamBuffer.resize( pcFrame.getBytesPerFrame() );
return true;
}
@@ -83,7 +92,7 @@ void StreamHandlerRaw::calculateFrameNumber()
}
}
bool StreamHandlerRaw::seek( ClpULong iFrameNum )
bool StreamHandlerRaw::seek( std::uint64_t iFrameNum )
{
if( m_bIsInput && m_pFile )
{
@@ -94,7 +103,7 @@ bool StreamHandlerRaw::seek( ClpULong iFrameNum )
return false;
}
bool StreamHandlerRaw::read( CalypFrame* pcFrame )
bool StreamHandlerRaw::read( CalypFrame& pcFrame )
{
if( !m_pFile || m_pStreamBuffer.empty() || m_uiNBytesPerFrame == 0 )
return false;
@@ -102,13 +111,13 @@ bool StreamHandlerRaw::read( CalypFrame* pcFrame )
if( processed_bytes != m_uiNBytesPerFrame )
return false;
m_uiCurrFrameFileIdx++;
pcFrame->frameFromBuffer( m_pStreamBuffer, m_iEndianness );
pcFrame.frameFromBuffer( m_pStreamBuffer, m_iEndianness );
return true;
}
bool StreamHandlerRaw::write( CalypFrame* pcFrame )
bool StreamHandlerRaw::write( const CalypFrame& pcFrame )
{
pcFrame->frameToBuffer( m_pStreamBuffer, m_iEndianness );
pcFrame.frameToBuffer( m_pStreamBuffer, m_iEndianness );
unsigned long long int processed_bytes = fwrite( m_pStreamBuffer.data(), sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile );
if( processed_bytes != m_uiNBytesPerFrame )
return false;
+6 -6
View File
@@ -40,15 +40,15 @@ private:
FILE* m_pFile; /**< The input file pointer >*/
public:
StreamHandlerRaw() { m_pchHandlerName = "RawVideo"; }
StreamHandlerRaw();
~StreamHandlerRaw() {}
bool openHandler( ClpString strFilename, bool bInput );
bool openHandler( std::string strFilename, bool bInput );
void closeHandler();
bool configureBuffer( CalypFrame* pcFrame );
bool configureBuffer( const CalypFrame& pcFrame );
void calculateFrameNumber();
bool seek( ClpULong iFrameNum );
bool read( CalypFrame* pcFrame );
bool write( CalypFrame* pcFrame );
bool seek( std::uint64_t iFrameNum );
bool read( CalypFrame& pcFrame );
bool write( const CalypFrame& pcFrame );
};
#endif // __STREAMHANDLERRAW_H__
+9 -4
View File
@@ -2,12 +2,17 @@
# CMakeLists for Calyp lis tests using catch2
#
# ADD_DEFINITIONS(-DCALYP_TEST_DATA_DIR=\"${CALYP_TEST_DATA_DIR}\")
FETCHCONTENT_MAKEAVAILABLE(Catch2)
SET(Calyp_Lib_Catch2_Tests_SRCS CalypFrameTests.cpp)
SET(Calyp_Lib_Catch2_Tests_SRCS
CalypLibTests.cpp
CalypStreamTests.cpp
CalypFrameTests.cpp
)
ADD_DEFINITIONS(-DCALYP_TEST_DATA_DIR=\"${CALYP_TEST_DATA_DIR}\")
ADD_EXECUTABLE(CalypLibCatch2Tests ${Calyp_Lib_Catch2_Tests_SRCS})
TARGET_LINK_LIBRARIES(CalypLibCatch2Tests ${PROJECT_LIBRARY} Catch2::Catch2)
INCLUDE(CTest)
CATCH_DISCOVER_TESTS(CalypLibCatch2Tests)
+15 -16
View File
@@ -22,7 +22,6 @@
* \brief CalypFrame general tests
*/
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include "CalypFrame.h"
@@ -30,32 +29,32 @@
TEST_CASE( "create a 256x128 frame with 8 bits in YUV420 format", "CalypFrame" )
{
// Constructor: CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel = 8 );
CalypFrame testFrame( 256, 128, CLP_YUV420P, 8 );
CalypFrame testFrame( 256, 128, ClpPixelFormats::YUV420p, 8 );
REQUIRE( testFrame.getWidth() == 256 );
REQUIRE( testFrame.getHeight() == 128 );
REQUIRE( testFrame.getPelFormat() == CLP_YUV420P );
REQUIRE( testFrame.getBitsPel() == 8 );
CHECK( testFrame.getWidth() == 256 );
CHECK( testFrame.getHeight() == 128 );
CHECK( testFrame.getPelFormat() == ClpPixelFormats::YUV420p );
CHECK( testFrame.getBitsPel() == 8 );
}
TEST_CASE( "create a 256x128 frame with 10 bits in YUV420 format", "CalypFrame" )
{
// Constructor: CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel = 8 );
CalypFrame testFrame( 256, 128, CLP_YUV420P, 10 );
CalypFrame testFrame( 256, 128, ClpPixelFormats::YUV420p, 10 );
REQUIRE( testFrame.getWidth() == 256 );
REQUIRE( testFrame.getHeight() == 128 );
REQUIRE( testFrame.getPelFormat() == CLP_YUV420P );
REQUIRE( testFrame.getBitsPel() == 10 );
CHECK( testFrame.getWidth() == 256 );
CHECK( testFrame.getHeight() == 128 );
CHECK( testFrame.getPelFormat() == ClpPixelFormats::YUV420p );
CHECK( testFrame.getBitsPel() == 10 );
}
TEST_CASE( "create a 256x128 frame with 16 bits in YUV420 format", "CalypFrame" )
{
// Constructor: CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel = 8 );
CalypFrame testFrame( 256, 128, CLP_YUV420P, 16 );
CalypFrame testFrame( 256, 128, ClpPixelFormats::YUV420p, 16 );
REQUIRE( testFrame.getWidth() == 256 );
REQUIRE( testFrame.getHeight() == 128 );
REQUIRE( testFrame.getPelFormat() == CLP_YUV420P );
REQUIRE( testFrame.getBitsPel() == 16 );
CHECK( testFrame.getWidth() == 256 );
CHECK( testFrame.getHeight() == 128 );
CHECK( testFrame.getPelFormat() == ClpPixelFormats::YUV420p );
CHECK( testFrame.getBitsPel() == 16 );
}
+26
View File
@@ -0,0 +1,26 @@
/* This file is a part of plaYUVer 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 CalypLibTests.cpp
* \brief CalypLib main test file
*/
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
+279
View File
@@ -0,0 +1,279 @@
/* This file is a part of plaYUVer 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 CalypStreamTests.cpp
* \brief CalypStream general tests
*/
#include <catch2/catch.hpp>
#include <filesystem>
#include <iostream>
#include <variant>
#include "CalypFrame.h"
#include "CalypStream.h"
constexpr int kFrameRate{ 30 };
constexpr auto kStreamType = CalypStream::Type::Input;
auto getFileTestFilename( const char* test_sequence ) -> std::string
{
return std::string( CALYP_TEST_DATA_DIR ) + std::string( "/" ) + std::string( test_sequence );
}
TEST_CASE( "Can open a YUV 420p file", "CalypStream" )
{
constexpr int kWidth{ 352 };
constexpr int kHeight{ 288 };
constexpr auto kInputFormat{ ClpPixelFormats::YUV420p };
constexpr int kBitsPel{ 8 };
constexpr auto KEndianness{ CLP_INVALID_ENDIANESS };
const auto kFilename = getFileTestFilename( "Foreman.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
CalypStream test_stream;
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, kStreamType );
REQUIRE( result );
CHECK( test_stream.getWidth() == kWidth );
CHECK( test_stream.getHeight() == kHeight );
CHECK( test_stream.getBitsPerPixel() == kBitsPel );
CHECK( test_stream.getFormatName() == "YUV" );
CHECK( test_stream.getCodecName() == "Raw Video" );
CHECK( test_stream.getEndianess() == CLP_BIG_ENDIAN );
const auto* frame = test_stream.getCurrFrame();
CHECK( frame->getPixel( 2, 0 ) == CalypPixel{ CLP_COLOR_YUV, 201, 129, 125 } );
CHECK( frame->getPixel( 336, 278 ) == CalypPixel{ CLP_COLOR_YUV, 99, 111, 142 } );
}
TEST_CASE( "Can open a YUV file", "CalypStream" )
{
constexpr int kWidth{ 352 };
constexpr int kHeight{ 288 };
constexpr int kBitsPel{ 8 };
constexpr auto KEndianness{ CLP_INVALID_ENDIANESS };
auto common_checks = []( auto& stream ) {
return stream.getWidth() == kWidth &&
stream.getHeight() == kHeight &&
stream.getBitsPerPixel() == kBitsPel &&
stream.getFormatName() == "YUV" &&
stream.getCodecName() == "Raw Video" &&
stream.getEndianess() == CLP_BIG_ENDIAN;
};
SECTION( "YUV420p" )
{
constexpr auto kInputFormat{ ClpPixelFormats::YUV420p };
const auto kFilename = getFileTestFilename( "Foreman.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
CalypStream test_stream;
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, kStreamType );
REQUIRE( result );
CHECK( common_checks( test_stream ) );
const auto* frame = test_stream.getCurrFrame();
CHECK( frame->getColorSpace() == CLP_COLOR_YUV );
CHECK( frame->getPelFmtName() == "YUV420p" );
CHECK( frame->getPelFormat() == kInputFormat );
}
SECTION( "YUV422p" )
{
constexpr auto kInputFormat{ ClpPixelFormats::YUV422p };
const auto kFilename = getFileTestFilename( "Foreman_352x288_yuv422p.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
CalypStream test_stream;
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, kStreamType );
REQUIRE( result );
CHECK( common_checks( test_stream ) );
const auto* frame = test_stream.getCurrFrame();
CHECK( frame->getColorSpace() == CLP_COLOR_YUV );
CHECK( frame->getPelFmtName() == "YUV422p" );
CHECK( frame->getPelFormat() == kInputFormat );
}
SECTION( "YUV444p" )
{
constexpr auto kInputFormat{ ClpPixelFormats::YUV444p };
const auto kFilename = getFileTestFilename( "Foreman_352x288_yuv444p.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
CalypStream test_stream;
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, kStreamType );
REQUIRE( result );
CHECK( common_checks( test_stream ) );
const auto* frame = test_stream.getCurrFrame();
CHECK( frame->getColorSpace() == CLP_COLOR_YUV );
CHECK( frame->getPelFmtName() == "YUV444p" );
CHECK( frame->getPelFormat() == kInputFormat );
}
SECTION( "YUYV422" )
{
constexpr auto kInputFormat{ ClpPixelFormats::YUYV422 };
const auto kFilename = getFileTestFilename( "Foreman_352x288_yuyv422.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
CalypStream test_stream;
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, kStreamType );
REQUIRE( result );
CHECK( common_checks( test_stream ) );
const auto* frame = test_stream.getCurrFrame();
CHECK( frame->getColorSpace() == CLP_COLOR_YUV );
CHECK( frame->getPelFmtName() == "YUYV422" );
CHECK( frame->getPelFormat() == kInputFormat );
}
}
TEST_CASE( "Can open a RGB file", "CalypStream" )
{
constexpr int kWidth{ 352 };
constexpr int kHeight{ 288 };
constexpr int kBitsPel{ 8 };
constexpr auto KEndianness{ CLP_INVALID_ENDIANESS };
auto common_checks = []( auto& stream ) {
return stream.getWidth() == kWidth &&
stream.getHeight() == kHeight &&
stream.getBitsPerPixel() == kBitsPel &&
stream.getFormatName() == "YUV" &&
stream.getCodecName() == "Raw Video" &&
stream.getEndianess() == CLP_BIG_ENDIAN;
};
SECTION( "RGB24" )
{
constexpr auto kInputFormat{ ClpPixelFormats::RGB24 };
const auto kFilename = getFileTestFilename( "Foreman_352x288_rgb24.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
CalypStream test_stream;
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, kStreamType );
REQUIRE( result );
CHECK( common_checks( test_stream ) );
const auto* frame = test_stream.getCurrFrame();
CHECK( frame->getColorSpace() == CLP_COLOR_RGB );
CHECK( frame->getPelFmtName() == "RGB" );
CHECK( frame->getPelFormat() == kInputFormat );
std::cout << test_stream.getFormatName();
}
SECTION( "BGR24" )
{
constexpr auto kInputFormat{ ClpPixelFormats::BGR24 };
const auto kFilename = getFileTestFilename( "Foreman_352x288_bgr24.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
CalypStream test_stream;
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, kStreamType );
REQUIRE( result );
CHECK( common_checks( test_stream ) );
const auto* frame = test_stream.getCurrFrame();
CHECK( frame->getColorSpace() == CLP_COLOR_RGB );
CHECK( frame->getPelFmtName() == "BGR" );
CHECK( frame->getPelFormat() == kInputFormat );
}
}
TEST_CASE( "Can open a GRAY file", "CalypStream" )
{
constexpr int kWidth{ 352 };
constexpr int kHeight{ 288 };
constexpr int kBitsPel{ 8 };
constexpr auto KEndianness{ CLP_INVALID_ENDIANESS };
auto common_checks = []( auto& stream ) {
return stream.getWidth() == kWidth &&
stream.getHeight() == kHeight &&
stream.getBitsPerPixel() == kBitsPel &&
stream.getFormatName() == "YUV" &&
stream.getCodecName() == "Raw Video" &&
stream.getEndianess() == CLP_BIG_ENDIAN;
};
constexpr auto kInputFormat{ ClpPixelFormats::Gray };
const auto kFilename = getFileTestFilename( "Foreman_352x288_gray.yuv" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
CalypStream test_stream;
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, kStreamType );
REQUIRE( result );
CHECK( common_checks( test_stream ) );
const auto* frame = test_stream.getCurrFrame();
CHECK( frame->getColorSpace() == CLP_COLOR_GRAY );
CHECK( frame->getPelFmtName() == "GRAY" );
CHECK( frame->getPelFormat() == kInputFormat );
}
TEST_CASE( "Can open .batatas file as RAW video", "CalypStream" )
{
constexpr int kWidth{ 352 };
constexpr int kHeight{ 288 };
constexpr auto kInputFormat{ ClpPixelFormats::YUV420p };
constexpr int kBitsPel{ 8 };
constexpr auto KEndianness{ CLP_INVALID_ENDIANESS };
const auto kFilename = getFileTestFilename( "Foreman.batatas" );
REQUIRE( std::filesystem::exists( std::filesystem::path( kFilename ) ) );
bool force_raw{ false };
SECTION( "Without forcing raw video" )
{
CalypStream test_stream;
bool result{ false };
try
{
result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, force_raw, kStreamType );
}
catch( ... )
{
// NOLINT
}
CHECK( !result );
}
SECTION( "Forcing raw video" )
{
force_raw = true;
CalypStream test_stream;
auto result = test_stream.open( kFilename, kWidth, kHeight, kInputFormat, kBitsPel, KEndianness, kFrameRate, force_raw, kStreamType );
REQUIRE( result );
CHECK( test_stream.getWidth() == kWidth );
CHECK( test_stream.getHeight() == kHeight );
CHECK( test_stream.getBitsPerPixel() == kBitsPel );
CHECK( test_stream.getFormatName() == "BATATAS" );
CHECK( test_stream.getCodecName() == "Raw Video" );
CHECK( test_stream.getEndianess() == CLP_BIG_ENDIAN );
const auto* frame = test_stream.getCurrFrame();
CHECK( frame->getPixel( 2, 0 ) == CalypPixel{ CLP_COLOR_YUV, 201, 129, 125 } );
CHECK( frame->getPixel( 336, 278 ) == CalypPixel{ CLP_COLOR_YUV, 99, 111, 142 } );
}
}
+14 -19
View File
@@ -34,14 +34,14 @@ protected:
// Can be omitted if not needed.
static void SetUpTestCase()
{
pcStreamPast = new CalypStream;
pcStreamPast->open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, 0, 8,
CLP_BIG_ENDIAN, 1, true );
pcStreamPast = std::make_unique<CalypStream>();
pcStreamPast->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F10_832x480_yuv420p.yuv" ), 832, 480, ClpPixelFormats::YUV420p, 8,
CLP_BIG_ENDIAN, 1, CalypStream::Type::Input );
pcFramePast = pcStreamPast->getCurrFrame();
pcStreamFuture = new CalypStream;
pcStreamFuture->open( ClpString( CALYP_TEST_DATA_DIR ) + ClpString( "/BasketballDrill_F15_832x480_yuv420p.yuv" ), 832, 480, 0, 8,
CLP_BIG_ENDIAN, 1, true );
pcStreamFuture = std::make_unique<CalypStream>();
pcStreamFuture->open( std::string( CALYP_TEST_DATA_DIR ) + std::string( "/BasketballDrill_F15_832x480_yuv420p.yuv" ), 832, 480, ClpPixelFormats::YUV420p, 8,
CLP_BIG_ENDIAN, 1, CalypStream::Type::Input );
pcFrameFuture = pcStreamFuture->getCurrFrame();
}
@@ -50,27 +50,22 @@ protected:
// Can be omitted if not needed.
static void TearDownTestCase()
{
pcStreamPast->close();
delete pcStreamPast;
pcStreamPast = NULL;
pcStreamFuture->close();
delete pcStreamFuture;
pcStreamFuture = NULL;
pcStreamPast = nullptr;
pcStreamFuture = nullptr;
}
// Some expensive resource shared by all tests.
static CalypStream* pcStreamPast;
static std::unique_ptr<CalypStream> pcStreamPast;
static CalypFrame* pcFramePast;
static CalypStream* pcStreamFuture;
static std::unique_ptr<CalypStream> pcStreamFuture;
static CalypFrame* pcFrameFuture;
};
CalypStream* CalypFrameQualityTest::pcStreamPast = NULL;
CalypStream* CalypFrameQualityTest::pcStreamFuture = NULL;
CalypFrame* CalypFrameQualityTest::pcFramePast = NULL;
CalypFrame* CalypFrameQualityTest::pcFrameFuture = NULL;
std::unique_ptr<CalypStream> CalypFrameQualityTest::pcStreamPast{ nullptr };
std::unique_ptr<CalypStream> CalypFrameQualityTest::pcStreamFuture{ nullptr };
CalypFrame* CalypFrameQualityTest::pcFramePast{ nullptr };
CalypFrame* CalypFrameQualityTest::pcFrameFuture{ nullptr };
TEST_F( CalypFrameQualityTest, MSE )
{
+8 -15
View File
@@ -29,19 +29,19 @@ AbsoluteFrameDifference::AbsoluteFrameDifference()
/* Module Definition */
m_iModuleAPI = CLP_MODULE_API_2; // Use API version 2 (recommended).
// See this example for details on the functions prototype
m_iModuleType = CLP_FRAME_PROCESSING_MODULE; // Apply module to the frames or to
m_iModuleType = ClpModuleType::FrameProcessing; // Apply module to the frames or to
// the whole sequence.
m_pchModuleCategory = "Measurements"; // Category (sub-menu)
m_pchModuleName = "AbsoluteFrameDifference"; // Name (no spaces)
m_pchModuleLongName = "Absolute Difference"; // Long Name
m_pchModuleTooltip = "Measure the absolute difference " // Description
"between two images (Y plane), e. g., abs( Y1 - Y2 )";
m_uiNumberOfFrames = 2; // Number of frames required
m_uiModuleRequirements = CLP_MODULE_REQUIRES_NEW_WINDOW; // Module requirements
// (check
// CalypModulesIf.h).
m_uiNumberOfFrames = 2; // Number of frames required
m_uiModuleRequirements = ClpModuleFeature::NewWindow; // Module requirements
// (check
// CalypModulesIf.h).
// Several requirements should be "or" between each others.
m_pcFrameDifference = NULL;
m_pcFrameDifference = nullptr;
}
bool AbsoluteFrameDifference::create( std::vector<CalypFrame*> apcFrameList )
@@ -52,7 +52,7 @@ bool AbsoluteFrameDifference::create( std::vector<CalypFrame*> apcFrameList )
if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_COLOR_SPACE_IGNORE_GRAY | CalypFrame::MATCH_COLOR_SPACE | CalypFrame::MATCH_RESOLUTION | CalypFrame::MATCH_BITS ) )
return false;
m_pcFrameDifference = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY, apcFrameList[0]->getBitsPel() );
m_pcFrameDifference = std::make_unique<CalypFrame>( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), ClpPixelFormats::Gray, apcFrameList[0]->getBitsPel() );
return true;
}
@@ -77,12 +77,5 @@ CalypFrame* AbsoluteFrameDifference::process( std::vector<CalypFrame*> apcFrameL
}
}
}
return m_pcFrameDifference;
}
void AbsoluteFrameDifference::destroy()
{
if( m_pcFrameDifference )
delete m_pcFrameDifference;
m_pcFrameDifference = NULL;
return m_pcFrameDifference.get();
}
+3 -6
View File
@@ -28,19 +28,16 @@
// CalypLib
#include "lib/CalypModuleIf.h"
class AbsoluteFrameDifference : public CalypModuleIf
class AbsoluteFrameDifference : public CalypModuleIf,
public CalypModuleInstace<AbsoluteFrameDifference>
{
REGISTER_CLASS_FACTORY( AbsoluteFrameDifference )
private:
CalypFrame* m_pcFrameDifference;
std::unique_ptr<CalypFrame> m_pcFrameDifference;
public:
AbsoluteFrameDifference();
virtual ~AbsoluteFrameDifference() {}
bool create( std::vector<CalypFrame*> apcFrameList );
CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
void destroy();
};
#endif // __FRAMEDIFFERENCE_H__
+8 -13
View File
@@ -1,21 +1,21 @@
#
# CMakeLists for calyp modules component
#
OPTION(CALYP_THREADED_MODULES "Use threads for modules" ON)
SET(CALYP_EXTRA_MODULES_DIR
"CALYP_EXTRA_MODULES_DIR"
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)
#
# Modules List
#
# SET( MODULE_LOCATION "")
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_MODULE_USE_OPENCV(DummyOpencvModule "DummyOpencvModule" VERSION 3.1.0 MODULES core)
ENDIF()
ADD_MODULE(FilterComponentLuma "FilterComponent")
ADD_MODULE(FilterComponentChromaU "FilterComponent")
@@ -36,6 +36,8 @@ ADD_MODULE(WeightedPSNR "WeightedPSNR")
ADD_MODULE(HEVCIntraPrediction "HEVCIntraPrediction")
ADD_MODULE(OptimiseDisplay "OptimiseDisplay")
ADD_MODULE_USE_OPENCV(ShapeDetection "ShapeDetection" VERSION 3.1.0 MODULES core)
ADD_MODULE_USE_OPENCV(
MeasureOpticalFlowDualTVL1
"MeasureOpticalFlowDualTVL1"
@@ -72,6 +74,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(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(ThreeSixtyFaceExtraction "ThreeSixtyFaceExtraction" VERSION 3.1.0 MODULES core)
@@ -86,15 +89,7 @@ ADD_MODULE_USE_OPENCV(
imgproc
photo
)
ADD_MODULE_USE_OPENCV(
ThreeSixtyDynamicDownsampling
"ThreeSixtyDynamicDownsampling"
VERSION
3.1.0
MODULES
core
imgproc
)
# ADD_MODULE_USE_OPENCV( ThreeSixtyDynamicDownsampling "ThreeSixtyDynamicDownsampling" VERSION 3.1.0 MODULES core imgproc )
ADD_MODULE_USE_OPENCV(
ThreeSixtyNxN
"ThreeSixtyNxN"
+2 -6
View File
@@ -39,10 +39,6 @@
CalypModulesFactory::CalypModulesFactory(){ REGISTER_ALL_MODULES }
CalypModulesFactory::~CalypModulesFactory()
{
m_FactoryMap.clear();
}
void CalypModulesFactory::Register( const char* moduleName, CreateModuleFn pfnCreate )
{
@@ -70,7 +66,7 @@ bool CalypModulesFactory::RegisterDl( const char* dlName )
#endif
}
CalypModuleIf* CalypModulesFactory::CreateModule( const char* moduleName )
CalypModulePtr CalypModulesFactory::CreateModule( const char* moduleName )
{
CalypModulesFactoryMap& moduleFactoryMap = CalypModulesFactory::Get()->getMap();
CalypModulesFactoryMap::iterator it = moduleFactoryMap.begin();
@@ -81,5 +77,5 @@ CalypModuleIf* CalypModulesFactory::CreateModule( const char* moduleName )
return it->second();
}
}
return NULL;
return nullptr;
}
+3 -3
View File
@@ -32,7 +32,7 @@
#define REGISTER_MODULE( X ) Register( "X", &( X::Create ) );
typedef CalypModuleIf* ( *CreateModuleFn )( void );
typedef CalypModulePtr ( *CreateModuleFn )( void );
typedef std::map<const char*, CreateModuleFn> CalypModulesFactoryMap;
// Factory for creating instances of CalypModuleIf
@@ -44,7 +44,7 @@ private:
CalypModulesFactoryMap m_FactoryMap;
public:
~CalypModulesFactory();
~CalypModulesFactory() = default;
static CalypModulesFactory* Get()
{
@@ -55,7 +55,7 @@ public:
void Register( const char* moduleName, CreateModuleFn pfnCreate );
bool RegisterDl( const char* dlName );
CalypModuleIf* CreateModule( const char* moduleName );
CalypModulePtr CreateModule( const char* moduleName );
CalypModulesFactoryMap& getMap() { return m_FactoryMap; }
};
+5 -3
View File
@@ -25,18 +25,20 @@
#include "DisparityStereoBM.h"
#include "lib/CalypFrame.h"
DisparityStereoBM::DisparityStereoBM()
{
/* Module Definition */
m_iModuleAPI = CLP_MODULE_API_2;
m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_iModuleType = ClpModuleType::FrameProcessing;
m_pchModuleCategory = "Stereo";
m_pchModuleName = "Disparity-BM";
m_pchModuleLongName = "Block macth based disparity";
m_pchModuleTooltip = "Measure the disparity between two images using the "
"Stereo BM method (OpenCV)";
m_uiNumberOfFrames = 2;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY | CLP_MODULE_REQUIRES_NEW_WINDOW | CLP_MODULE_REQUIRES_OPTIONS;
m_uiModuleRequirements = ClpModuleFeature::SkipWhilePlaying | ClpModuleFeature::NewWindow | ClpModuleFeature::Options;
m_cModuleOptions.addOptions() /**/
( "block_size", m_uiBlockSize, "Block Size (positive odd number) [9]" );
@@ -49,7 +51,7 @@ bool DisparityStereoBM::create( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
m_pcDisparityFrame =
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY );
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), ClpPixelFormats::Gray );
if( ( m_uiBlockSize % 2 ) == 0 )
{
m_uiBlockSize++;
+4 -4
View File
@@ -29,14 +29,14 @@ DisparityStereoSGBM::DisparityStereoSGBM()
{
/* Module Definition */
m_iModuleAPI = CLP_MODULE_API_2;
m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_iModuleType = ClpModuleType::FrameProcessing;
m_pchModuleCategory = "Stereo";
m_pchModuleName = "Disparity-SGBM";
m_pchModuleName = "SGBM based disparity";
m_pchModuleLongName = "SGBM based disparity";
m_pchModuleTooltip = "Measure the disparity between two images using the "
"Stereo SGBM method (OpenCV)";
m_uiNumberOfFrames = 2;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY | CLP_MODULE_REQUIRES_NEW_WINDOW | CLP_MODULE_REQUIRES_OPTIONS;
m_uiModuleRequirements = ClpModuleFeature::SkipWhilePlaying | ClpModuleFeature::NewWindow | ClpModuleFeature::Options;
m_cModuleOptions.addOptions() /**/
( "block_size", m_uiBlockSize, "Block Size (positive odd number) [3]" )( "HHAlgorithm", m_bUseHH,
@@ -51,7 +51,7 @@ bool DisparityStereoSGBM::create( std::vector<CalypFrame*> apcFrameList )
{
_BASIC_MODULE_API_2_CHECK_
m_pcDisparityFrame =
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY );
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), ClpPixelFormats::Gray );
if( ( m_uiBlockSize % 2 ) == 0 )
{
m_uiBlockSize++;
+60
View File
@@ -0,0 +1,60 @@
/* 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 DummyOpencvModule.cpp
*/
#include "DummyOpencvModule.h"
#include <cstdlib>
//#include <opencv2/video/video.hpp>
using cv::Mat;
using cv::Ptr;
using namespace cv::saliency;
DummyOpencvModule::DummyOpencvModule()
{
/* Module Definition */
m_iModuleAPI = CLP_MODULE_API_2;
m_iModuleType = ClpModuleType::FrameProcessing;
m_pchModuleCategory = "Dummy";
m_pchModuleName = "DummyOpencvModule";
m_pchModuleLongName = "Shape detection";
m_pchModuleTooltip = "Detect shapes in images";
m_uiNumberOfFrames = 1;
m_uiModuleRequirements = ClpModuleFeature::NewWindow | ClpModuleFeature::Options;
m_bConvertToGray = false;
m_cModuleOptions.addOptions()( "Convert to Gray", m_bConvertToGray, "Measure a binary saliency map [false]" );
}
cv::Mat* DummyOpencvModule::create_using_opencv( const std::vector<Mat>& apcMatList )
{
m_resultImage = std::make_unique<Mat>( apcMatList[0].rows, apcMatList[0].cols, CV_8UC1 );
return m_resultImage.get();
}
Mat* DummyOpencvModule::process_using_opencv( const std::vector<Mat>& apcMatList )
{
apcMatList[0].copyTo( *m_resultImage );
return m_resultImage.get();
}
+50
View File
@@ -0,0 +1,50 @@
/* 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 DummyOpencvModule.h
* \brief Modules to detect curves shape
*/
#ifndef __DUMMYOPENCVMODULE_H__
#define __DUMMYOPENCVMODULE_H__
// CalypLib
#include "lib/CalypModuleIf.h"
// OpenCV
#include <opencv2/core/core.hpp>
#include <opencv2/saliency.hpp>
class DummyOpencvModule : public CalypOpenCVModuleIf,
public CalypModuleInstace<DummyOpencvModule>
{
using Mat = cv::Mat;
private:
std::unique_ptr<Mat> m_resultImage;
public:
DummyOpencvModule();
virtual ~DummyOpencvModule() = default;
Mat* create_using_opencv( const std::vector<Mat>& apcMatList ) override;
Mat* process_using_opencv( const std::vector<Mat>& apcMatList ) override;
};
#endif // __DUMMYOPENCVMODULE_H__
+2 -2
View File
@@ -28,13 +28,13 @@ EightBitsSampling::EightBitsSampling()
{
/* Module Definition */
m_iModuleAPI = CLP_MODULE_API_2;
m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_iModuleType = ClpModuleType::FrameProcessing;
m_pchModuleCategory = "Conversions";
m_pchModuleName = "BitsResampling";
m_pchModuleLongName = "Re-sampling frame (bpp)";
m_pchModuleTooltip = "Re-sampling frame to a different value of bits per pixel";
m_uiNumberOfFrames = 1;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_OPTIONS;
m_uiModuleRequirements = ClpModuleFeature::Options;
m_cModuleOptions.addOptions() /**/
( "num_bits", m_iNumberOfBits, "Number of bits/pixel (8-16) [8]" );
+5 -15
View File
@@ -30,19 +30,16 @@ FilterComponentModule::FilterComponentModule()
{
/* Module Definition */
m_iModuleAPI = CLP_MODULE_API_2;
m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_iModuleType = ClpModuleType::FrameProcessing;
m_uiNumberOfFrames = 1;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_NOTHING;
m_uiModuleRequirements = ClpModuleFeature::None;
m_pchModuleCategory = "Filtering";
m_pcFilteredFrame = NULL;
}
bool FilterComponentModule::createFilter( unsigned int uiWidth, unsigned int uiHeight, unsigned int bitsPixel )
{
m_pcFilteredFrame = NULL;
m_pcFilteredFrame = new CalypFrame( uiWidth, uiHeight, CLP_GRAY, bitsPixel );
return true;
m_pcFilteredFrame = std::make_unique<CalypFrame>( uiWidth, uiHeight, ClpPixelFormats::Gray, bitsPixel );
return m_pcFilteredFrame != nullptr;
}
CalypFrame* FilterComponentModule::filterComponent( CalypFrame* InputFrame, int Component )
@@ -51,14 +48,7 @@ CalypFrame* FilterComponentModule::filterComponent( CalypFrame* InputFrame, int
ClpPel*** pppInputPelYUV = InputFrame->getPelBufferYUV();
memcpy( pppOutputPelYUV[CLP_LUMA][0], pppInputPelYUV[Component][0],
m_pcFilteredFrame->getWidth() * m_pcFilteredFrame->getHeight() * sizeof( ClpPel ) );
return m_pcFilteredFrame;
}
void FilterComponentModule::destroy()
{
if( m_pcFilteredFrame )
delete m_pcFilteredFrame;
m_pcFilteredFrame = NULL;
return m_pcFilteredFrame.get();
}
FilterComponentLuma::FilterComponentLuma()
+7 -8
View File
@@ -31,22 +31,21 @@
class FilterComponentModule : public CalypModuleIf
{
private:
CalypFrame* m_pcFilteredFrame;
std::unique_ptr<CalypFrame> m_pcFilteredFrame{ nullptr };
public:
FilterComponentModule();
virtual ~FilterComponentModule() {}
bool create( std::vector<CalypFrame*> apcFrameList ) = 0;
CalypFrame* process( std::vector<CalypFrame*> apcFrameList ) = 0;
void destroy();
bool createFilter( unsigned int uiWidth, unsigned int uiHeight, unsigned int bitsPixel );
CalypFrame* filterComponent( CalypFrame* InputFrame, int Component );
};
class FilterComponentLuma : public FilterComponentModule
class FilterComponentLuma : public FilterComponentModule,
public CalypModuleInstace<FilterComponentLuma>
{
REGISTER_CLASS_FACTORY( FilterComponentLuma )
public:
FilterComponentLuma();
virtual ~FilterComponentLuma() {}
@@ -54,9 +53,9 @@ public:
CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
};
class FilterComponentChromaU : public FilterComponentModule
class FilterComponentChromaU : public FilterComponentModule,
public CalypModuleInstace<FilterComponentChromaU>
{
REGISTER_CLASS_FACTORY( FilterComponentChromaU )
public:
FilterComponentChromaU();
virtual ~FilterComponentChromaU() {}
@@ -64,9 +63,9 @@ public:
CalypFrame* process( std::vector<CalypFrame*> apcFrameList );
};
class FilterComponentChromaV : public FilterComponentModule
class FilterComponentChromaV : public FilterComponentModule,
public CalypModuleInstace<FilterComponentChromaV>
{
REGISTER_CLASS_FACTORY( FilterComponentChromaV )
public:
FilterComponentChromaV();
virtual ~FilterComponentChromaV() {}
+3 -3
View File
@@ -27,13 +27,13 @@
FrameBinarization::FrameBinarization()
{
/* Module Definition */
m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_iModuleType = ClpModuleType::FrameProcessing;
m_pchModuleCategory = "Utilities";
m_pchModuleLongName = "Binarization";
m_pchModuleName = "FrameBinarization";
m_pchModuleTooltip = "Binarize frame";
m_uiNumberOfFrames = 1;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_OPTIONS;
m_uiModuleRequirements = ClpModuleFeature::Options;
m_cModuleOptions.addOptions() /**/
( "threshold", m_uiThreshold, "Threshold level for binarization (0-255) [128]" );
@@ -45,7 +45,7 @@ FrameBinarization::FrameBinarization()
void FrameBinarization::create( CalypFrame* frame )
{
m_pcBinFrame = NULL;
m_pcBinFrame = new CalypFrame( frame->getWidth(), frame->getHeight(), CLP_GRAY, 8 );
m_pcBinFrame = new CalypFrame( frame->getWidth(), frame->getHeight(), ClpPixelFormats::Gray, 8 );
}
CalypFrame* FrameBinarization::process( CalypFrame* frame )
+2 -2
View File
@@ -28,13 +28,13 @@ FrameConcatenation::FrameConcatenation()
{
/* Module Definition */
m_iModuleAPI = CLP_MODULE_API_2;
m_iModuleType = CLP_FRAME_PROCESSING_MODULE;
m_iModuleType = ClpModuleType::FrameProcessing;
m_pchModuleCategory = "Utilities";
m_pchModuleLongName = "Frame Concatenation";
m_pchModuleName = "FrameConc";
m_pchModuleTooltip = "Concatenate frames side-by-side";
m_uiNumberOfFrames = 2;
m_uiModuleRequirements = CLP_MODULE_REQUIRES_OPTIONS | CLP_MODULE_REQUIRES_NEW_WINDOW;
m_uiModuleRequirements = ClpModuleFeature::Options | ClpModuleFeature::NewWindow;
m_cModuleOptions.addOptions() /**/
( "ShiftHorizontal", m_iShiftHor, "Amount of pixels to shift in horizontal direction" );
Loaded 100 of 145 files, more files were not shown because too many files have changed in this diff. Show more