diff -Nru libvidstab-1.1.0/CMakeLists.txt libvidstab-1.1.0+git-20201110.f9166e9/CMakeLists.txt --- libvidstab-1.1.0/CMakeLists.txt 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/CMakeLists.txt 2020-11-10 06:59:25.000000000 +0000 @@ -1,32 +1,34 @@ -cmake_minimum_required (VERSION 2.6) -project (vid.stab) - -SET(CMAKE_BUILTTYPE None) +cmake_minimum_required (VERSION 2.8.5) +project (vid.stab C) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/") include (FindSSE) +include (GNUInstallDirs) +find_package(OpenMP) set(MAJOR_VERSION 1) -set(MINOR_VERSION 1) +set(MINOR_VERSION 2) set(PATCH_VERSION 0) set(VIDSTAB_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}${PATCH_VERSION}) +# Default to release builds if no explicit build type specified. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Release") +endif() + option(BUILD_SHARED_LIBS "build shared libraries instead of static libraries" ON) option(USE_OMP "use parallelization use OMP" ON) -# determine lib suffix -get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS) -if (LIB64 STREQUAL "TRUE") - set(LIBSUFFIX 64) -else() - set(LIBSUFFIX "") -endif() +set(CMAKE_C_STANDARD 99) + +add_definitions(-Wall -Wno-pointer-sign) -add_definitions( -Wall -O3 -g -Wno-pointer-sign -fPIC -std=gnu99) -# add_definitions( -Wall -O0 -g -Wno-pointer-sign ) +if(NOT WIN32) + add_definitions(-fPIC) +endif() ### ORC is not used in any active code at the moment ### # I tried it with 0.4.14 @@ -45,8 +47,8 @@ add_definitions( -DUSE_SSE2 -msse2 -ffast-math ) endif() -if(USE_OMP) -add_definitions(-fopenmp -DUSE_OMP) +if(USE_OMP AND OPENMP_FOUND) +add_definitions(${OpenMP_C_FLAGS} -DUSE_OMP) endif() set(SOURCES src/frameinfo.c src/transformtype.c src/libvidstab.c @@ -72,21 +74,23 @@ target_link_libraries(vidstab ${ORC_LIBRARIES}) set(PKG_EXTRA_LIBS "${PKG_EXTRA_LIBS} ${ORC_LIBRARIES}") endif() -if(USE_OMP) -target_link_libraries(vidstab gomp) -set(PKG_EXTRA_LIBS "${PKG_EXTRA_LIBS} -lgomp") +if(USE_OMP AND OPENMP_FOUND) +if(TARGET OpenMP::OpenMP_C) +target_link_libraries(vidstab OpenMP::OpenMP_C) +endif() +set(PKG_EXTRA_LIBS "${PKG_EXTRA_LIBS} ${OpenMP_C_FLAGS}") endif() #if(!NOHEADERS) FILE(GLOB HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h") -INSTALL(FILES ${HEADERS} DESTINATION include/vid.stab) +INSTALL(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vid.stab) #endif() INSTALL(TARGETS vidstab - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib${LIB_SUFFIX} - ARCHIVE DESTINATION lib${LIB_SUFFIX} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) include(create_pkgconfig_file) diff -Nru libvidstab-1.1.0/CMakeModules/create_pkgconfig_file.cmake libvidstab-1.1.0+git-20201110.f9166e9/CMakeModules/create_pkgconfig_file.cmake --- libvidstab-1.1.0/CMakeModules/create_pkgconfig_file.cmake 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/CMakeModules/create_pkgconfig_file.cmake 2020-11-10 06:59:25.000000000 +0000 @@ -10,8 +10,8 @@ file(WRITE "${_pkgfname}" "# file generated by vid.stab cmake build prefix=${CMAKE_INSTALL_PREFIX} -libdir=\${prefix}/lib${LIB_SUFFIX} -includedir=\${prefix}/include +libdir=${CMAKE_INSTALL_FULL_LIBDIR} +includedir=${CMAKE_INSTALL_FULL_INCLUDEDIR} Name: ${name} Description: ${desc} @@ -21,5 +21,5 @@ ") - install(FILES ${_pkgfname} DESTINATION lib${LIB_SUFFIX}/pkgconfig) -endmacro() \ No newline at end of file + install(FILES ${_pkgfname} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +endmacro() diff -Nru libvidstab-1.1.0/CMakeModules/FindSSE.cmake libvidstab-1.1.0+git-20201110.f9166e9/CMakeModules/FindSSE.cmake --- libvidstab-1.1.0/CMakeModules/FindSSE.cmake 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/CMakeModules/FindSSE.cmake 2020-11-10 06:59:25.000000000 +0000 @@ -4,7 +4,7 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux") EXEC_PROGRAM(cat ARGS "/proc/cpuinfo" OUTPUT_VARIABLE CPUINFO) - STRING(REGEX REPLACE "^.*(sse2).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(sse2).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "sse2" "${SSE_THERE}" SSE2_TRUE) IF (SSE2_TRUE) set(SSE2_FOUND true CACHE BOOL "SSE2 available on host") @@ -13,14 +13,14 @@ ENDIF (SSE2_TRUE) # /proc/cpuinfo apparently omits sse3 :( - STRING(REGEX REPLACE "^.*[^s](sse3).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*[^s](sse3).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "sse3" "${SSE_THERE}" SSE3_TRUE) IF (NOT SSE3_TRUE) - STRING(REGEX REPLACE "^.*(T2300).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(T2300).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "T2300" "${SSE_THERE}" SSE3_TRUE) ENDIF (NOT SSE3_TRUE) - STRING(REGEX REPLACE "^.*(ssse3).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(ssse3).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "ssse3" "${SSE_THERE}" SSSE3_TRUE) IF (SSE3_TRUE OR SSSE3_TRUE) set(SSE3_FOUND true CACHE BOOL "SSE3 available on host") @@ -33,7 +33,7 @@ set(SSSE3_FOUND false CACHE BOOL "SSSE3 available on host") ENDIF (SSSE3_TRUE) - STRING(REGEX REPLACE "^.*(sse4_1).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(sse4_1).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "sse4_1" "${SSE_THERE}" SSE41_TRUE) IF (SSE41_TRUE) set(SSE4_1_FOUND true CACHE BOOL "SSE4.1 available on host") @@ -44,7 +44,7 @@ EXEC_PROGRAM("/usr/sbin/sysctl -n machdep.cpu.features" OUTPUT_VARIABLE CPUINFO) - STRING(REGEX REPLACE "^.*[^S](SSE2).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*[^S](SSE2).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "SSE2" "${SSE_THERE}" SSE2_TRUE) IF (SSE2_TRUE) set(SSE2_FOUND true CACHE BOOL "SSE2 available on host") @@ -52,7 +52,7 @@ set(SSE2_FOUND false CACHE BOOL "SSE2 available on host") ENDIF (SSE2_TRUE) - STRING(REGEX REPLACE "^.*[^S](SSE3).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*[^S](SSE3).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "SSE3" "${SSE_THERE}" SSE3_TRUE) IF (SSE3_TRUE) set(SSE3_FOUND true CACHE BOOL "SSE3 available on host") @@ -60,7 +60,7 @@ set(SSE3_FOUND false CACHE BOOL "SSE3 available on host") ENDIF (SSE3_TRUE) - STRING(REGEX REPLACE "^.*(SSSE3).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(SSSE3).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "SSSE3" "${SSE_THERE}" SSSE3_TRUE) IF (SSSE3_TRUE) set(SSSE3_FOUND true CACHE BOOL "SSSE3 available on host") @@ -68,7 +68,7 @@ set(SSSE3_FOUND false CACHE BOOL "SSSE3 available on host") ENDIF (SSSE3_TRUE) - STRING(REGEX REPLACE "^.*(SSE4.1).*$" "\\1" SSE_THERE ${CPUINFO}) + STRING(REGEX REPLACE "^.*(SSE4.1).*$" "\\1" SSE_THERE "${CPUINFO}") STRING(COMPARE EQUAL "SSE4.1" "${SSE_THERE}" SSE41_TRUE) IF (SSE41_TRUE) set(SSE4_1_FOUND true CACHE BOOL "SSE4.1 available on host") diff -Nru libvidstab-1.1.0/debian/changelog libvidstab-1.1.0+git-20201110.f9166e9/debian/changelog --- libvidstab-1.1.0/debian/changelog 2018-10-13 17:27:10.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/debian/changelog 2021-05-24 09:58:04.000000000 +0000 @@ -1,3 +1,22 @@ +libvidstab (1.1.0+git-20201110.f9166e9-2ppa1) focal; urgency=low + + * Update to upstream master commit. + + -- Hung-Yi Chen Mon, 24 May 2021 17:58:04 +0800 + +libvidstab (1.1.0+git-20190213.aeabc8d-2ppa1) focal; urgency=low + + * Update to upstream master commit. + + -- Hung-Yi Chen Tue, 13 Aug 2019 09:45:04 +0800 + +libvidstab (1.1.0-2ppa1~focal) focal; urgency=low + + * Backport from disco. + + -- Hung-Yi Chen Tue, 18 Jun 2019 22:47:35 +0800 + + libvidstab (1.1.0-2) unstable; urgency=low [James Cowgill] diff -Nru libvidstab-1.1.0/debian/compat libvidstab-1.1.0+git-20201110.f9166e9/debian/compat --- libvidstab-1.1.0/debian/compat 2018-08-01 06:24:49.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/debian/compat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -10 diff -Nru libvidstab-1.1.0/debian/control libvidstab-1.1.0+git-20201110.f9166e9/debian/control --- libvidstab-1.1.0/debian/control 2018-10-13 17:27:06.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/debian/control 2021-05-24 09:58:04.000000000 +0000 @@ -1,10 +1,10 @@ Source: libvidstab Priority: optional -Maintainer: Keng-Yu Lin +Maintainer: Hung-Yi Chen Build-Depends: cmake, - debhelper (>= 10.2.1) -Standards-Version: 4.1.5 + debhelper-compat (= 12), +Standards-Version: 4.1.4 Section: libs Homepage: http://public.hronopik.de/vid.stab/ diff -Nru libvidstab-1.1.0/debian/copyright libvidstab-1.1.0+git-20201110.f9166e9/debian/copyright --- libvidstab-1.1.0/debian/copyright 2018-08-01 06:39:07.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/debian/copyright 2021-05-24 09:58:04.000000000 +0000 @@ -10,6 +10,7 @@ Files: debian/* Copyright: 2013 Rogério Brito 2018 Keng-Yu Lin + 2021 Hung-Yi Chen License: GPL-2.0+ License: GPL-2.0+ diff -Nru libvidstab-1.1.0/debian/patches/0001-use-GNUInstallDirs-for-automatic-Multi-Arch-support.patch libvidstab-1.1.0+git-20201110.f9166e9/debian/patches/0001-use-GNUInstallDirs-for-automatic-Multi-Arch-support.patch --- libvidstab-1.1.0/debian/patches/0001-use-GNUInstallDirs-for-automatic-Multi-Arch-support.patch 2018-08-01 06:39:07.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/debian/patches/0001-use-GNUInstallDirs-for-automatic-Multi-Arch-support.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,71 +0,0 @@ -From 8019116661556a800166ee84947f8808feef3086 Mon Sep 17 00:00:00 2001 -From: Andreas Cadhalpun -Date: Sun, 26 Apr 2015 20:01:43 +0200 -Subject: [PATCH 1/2] use GNUInstallDirs for automatic Multi-Arch support - ---- - CMakeLists.txt | 13 +++++++++---- - CMakeModules/create_pkgconfig_file.cmake | 8 ++++---- - 2 files changed, 13 insertions(+), 8 deletions(-) - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index e9a2af4..256663c 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -44,6 +44,11 @@ set(HEADERS src/frameinfo.h src/transformtype.h src/libvidstab.h - src/transform.h src/motiondetect.h src/serialize.h - src/localmotion2transform.h src/boxblur.h src/vsvector.h ) - -+# Installation paths -+include(GNUInstallDirs) -+set(BIN_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING "Relative installation path for binaries.") -+set(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE STRING "Relative installation path for libraries.") -+set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE STRING "Relative installation path for headers.") - - # Create the vidstab library - add_library (vidstab ${SOURCES}) -@@ -63,13 +68,13 @@ endif() - - #if(!NOHEADERS) - FILE(GLOB HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h") --INSTALL(FILES ${HEADERS} DESTINATION include/vid.stab) -+INSTALL(FILES ${HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/vid.stab) - #endif() - - INSTALL(TARGETS vidstab -- RUNTIME DESTINATION bin -- LIBRARY DESTINATION lib${LIB_SUFFIX} -- ARCHIVE DESTINATION lib${LIB_SUFFIX} -+ RUNTIME DESTINATION ${BIN_INSTALL_DIR} -+ LIBRARY DESTINATION ${LIB_INSTALL_DIR} -+ ARCHIVE DESTINATION ${LIB_INSTALL_DIR} - ) - - include(create_pkgconfig_file) -diff --git a/CMakeModules/create_pkgconfig_file.cmake b/CMakeModules/create_pkgconfig_file.cmake -index da31712..3c8fd10 100644 ---- a/CMakeModules/create_pkgconfig_file.cmake -+++ b/CMakeModules/create_pkgconfig_file.cmake -@@ -10,8 +10,8 @@ macro (create_pkgconfig_file name desc) - - file(WRITE "${_pkgfname}" "# file generated by vid.stab cmake build - prefix=${CMAKE_INSTALL_PREFIX} --libdir=\${prefix}/lib${LIB_SUFFIX} --includedir=\${prefix}/include -+libdir=\${prefix}/${LIB_INSTALL_DIR} -+includedir=\${prefix}/${INCLUDE_INSTALL_DIR} - - Name: ${name} - Description: ${desc} -@@ -21,5 +21,5 @@ Cflags: -I\${includedir} - - ") - -- install(FILES ${_pkgfname} DESTINATION lib${LIB_SUFFIX}/pkgconfig) --endmacro() -\ No newline at end of file -+ install(FILES ${_pkgfname} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -+endmacro() --- -2.1.4 - diff -Nru libvidstab-1.1.0/debian/patches/0002-tests-return-0-upon-success.patch libvidstab-1.1.0+git-20201110.f9166e9/debian/patches/0002-tests-return-0-upon-success.patch --- libvidstab-1.1.0/debian/patches/0002-tests-return-0-upon-success.patch 2018-08-01 06:39:07.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/debian/patches/0002-tests-return-0-upon-success.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ -From 55653d91626d7617a43dc9870380b41f2e4b5ccb Mon Sep 17 00:00:00 2001 -From: Andreas Cadhalpun -Date: Sun, 26 Apr 2015 20:05:40 +0200 -Subject: [PATCH 2/2] tests: return 0 upon success - ---- - tests/testframework.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/tests/testframework.c b/tests/testframework.c -index a38851c..a889560 100644 ---- a/tests/testframework.c -+++ b/tests/testframework.c -@@ -36,7 +36,7 @@ int unittest_summary(){ - fprintf(stderr, "UNIT TESTs succeeded:\t %s%i/%i\033[0m\n", - units_failed>0 ? "\033[1;31m" : "\033[1;32m", - units_success, units_success + units_failed); -- return units_failed==0; -+ return units_failed!=0; - - } - --- -2.1.4 - diff -Nru libvidstab-1.1.0/debian/patches/series libvidstab-1.1.0+git-20201110.f9166e9/debian/patches/series --- libvidstab-1.1.0/debian/patches/series 2018-08-01 06:39:07.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -0001-use-GNUInstallDirs-for-automatic-Multi-Arch-support.patch -0002-tests-return-0-upon-success.patch diff -Nru libvidstab-1.1.0/.github/workflows/c-cpp.yml libvidstab-1.1.0+git-20201110.f9166e9/.github/workflows/c-cpp.yml --- libvidstab-1.1.0/.github/workflows/c-cpp.yml 1970-01-01 00:00:00.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/.github/workflows/c-cpp.yml 2020-11-10 06:59:25.000000000 +0000 @@ -0,0 +1,28 @@ +name: C/C++ CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: cmake + run: cmake . + - name: make + run: make + - name: cmake tests + run: cmake . + working-directory: tests + - name: make tests + run: make + working-directory: tests + - name: run tests + run: ./tests --all + working-directory: tests diff -Nru libvidstab-1.1.0/src/motiondetect.c libvidstab-1.1.0+git-20201110.f9166e9/src/motiondetect.c --- libvidstab-1.1.0/src/motiondetect.c 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/src/motiondetect.c 2020-11-10 06:59:25.000000000 +0000 @@ -92,7 +92,7 @@ #ifdef USE_OMP if(md->conf.numThreads==0) md->conf.numThreads=VS_MAX(omp_get_max_threads()*0.8,1); - vs_log_info(md->conf.modName, "Multitheading: use %i threads\n",md->conf.numThreads); + vs_log_info(md->conf.modName, "Multithreading: use %i threads\n",md->conf.numThreads); #endif vsFrameAllocate(&md->prev, &md->fi); @@ -107,6 +107,10 @@ md->hasSeenOneFrame = 0; md->frameNum = 0; + if(md->serializationMode != ASCII_SERIALIZATION_MODE && md->serializationMode != BINARY_SERIALIZATION_MODE) { + md->serializationMode = BINARY_SERIALIZATION_MODE; + } + // TODO: get rid of shakiness parameter in the long run md->conf.shakiness = VS_MIN(10,VS_MAX(1,md->conf.shakiness)); md->conf.accuracy = VS_MIN(15,VS_MAX(1,md->conf.accuracy)); @@ -521,8 +525,8 @@ vs_log_msg(md->modName, "Minerror: %f\n", minerror); #endif - if (unlikely(fabs(tx) >= maxShift + stepSize - 1 || - fabs(ty) >= maxShift + stepSize)) { + if (unlikely(abs(tx) >= maxShift + stepSize - 1 || + abs(ty) >= maxShift + stepSize)) { #ifdef STABVERBOSE vs_log_msg(md->modName, "maximal shift "); #endif @@ -601,7 +605,7 @@ } } - if (fabs(tx) >= maxShift + stepSize - 1 || fabs(ty) >= maxShift + stepSize - 1) { + if (abs(tx) >= maxShift + stepSize - 1 || abs(ty) >= maxShift + stepSize - 1) { #ifdef STABVERBOSE vs_log_msg(md->modName, "maximal shift "); #endif diff -Nru libvidstab-1.1.0/src/motiondetect.h libvidstab-1.1.0+git-20201110.f9166e9/src/motiondetect.h --- libvidstab-1.1.0/src/motiondetect.h 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/src/motiondetect.h 2020-11-10 06:59:25.000000000 +0000 @@ -36,6 +36,9 @@ #include "vsvector.h" #include "frameinfo.h" +#define ASCII_SERIALIZATION_MODE 1 +#define BINARY_SERIALIZATION_MODE 2 + typedef struct _vsmotiondetectconfig { /* meta parameter for maxshift and fieldsize between 1 and 15 */ int shakiness; @@ -81,6 +84,7 @@ VSFrame prev; // frame buffer for last frame (copied) short hasSeenOneFrame; // true if we have a valid previous frame int initialized; // 1 if initialized and 2 if configured + int serializationMode; // 1 if ascii and 2 if binary int frameNum; } VSMotionDetect; @@ -91,6 +95,8 @@ " (translation, rotation) about subsequent frames." " See also transform.\n" "Options\n" + " 'fileformat' the type of file format used to write the transforms\n" + " 1: ascii (human readable) file format 2: binary (smaller) file format\n" " 'result' path to the file used to write the transforms\n" " (def:inputfile.stab)\n" " 'shakiness' how shaky is the video and how quick is the camera?\n" diff -Nru libvidstab-1.1.0/src/serialize.c libvidstab-1.1.0+git-20201110.f9166e9/src/serialize.c --- libvidstab-1.1.0/src/serialize.c 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/src/serialize.c 2020-11-10 06:59:25.000000000 +0000 @@ -30,19 +30,149 @@ #include "transformtype_operations.h" #include "motiondetect.h" +#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \ + defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ || \ + defined(__BIG_ENDIAN__) || \ + defined(__ARMEB__) || \ + defined(__THUMBEB__) || \ + defined(__AARCH64EB__) || \ + defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__) +// It's a big-endian target architecture +#define __IS_BIG_ENDIAN__ +#include +static double byteSwapDouble(double v) +{ + char in[8], out[8]; + double result; + memcpy(in, &v, 8); + out[0] = in[7]; + out[1] = in[6]; + out[2] = in[5]; + out[3] = in[4]; + out[4] = in[3]; + out[5] = in[2]; + out[6] = in[1]; + out[7] = in[0]; + memcpy(&result, out, 8); + return result; +} +#elif defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || \ + defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ || \ + defined(__LITTLE_ENDIAN__) || \ + defined(__ARMEL__) || \ + defined(__THUMBEL__) || \ + defined(__AARCH64EL__) || \ + defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) +// It's a little-endian target architecture +#define __IS_LITTLE_ENDIAN__ +#else +#error "I don't know what architecture this is!" +#endif + const char* modname = "vid.stab - serialization"; +int vsPrepareFileText(const VSMotionDetect* md, FILE* f); +int vsPrepareFileBinary(const VSMotionDetect* md, FILE* f); +int vsWriteToFileText(const VSMotionDetect* md, FILE* f, const LocalMotions* lms); +int vsWriteToFileBinary(const VSMotionDetect* md, FILE* f, const LocalMotions* lms); +int vsStoreLocalmotionsText(FILE* f, const LocalMotions* lms); +int vsStoreLocalmotionsBinary(FILE* f, const LocalMotions* lms); +int storeLocalmotionText(FILE* f, const LocalMotion* lm); +int storeLocalmotionBinary(FILE* f, const LocalMotion* lm); +LocalMotions vsRestoreLocalmotionsText(FILE* f); +LocalMotions vsRestoreLocalmotionsBinary(FILE* f); +LocalMotion restoreLocalmotionText(FILE* f); +LocalMotion restoreLocalmotionBinary(FILE* f); +int vsReadFileVersionText(FILE* f); +int vsReadFileVersionBinary(FILE* f); +int vsReadFromFileText(FILE* f, LocalMotions* lms); +int vsReadFromFileBinary(FILE* f, LocalMotions* lms); + +int readInt16(int16_t* i, FILE* f){ + int result = fread(i, sizeof(int16_t), 1, f); + #ifdef __IS_BIG_ENDIAN__ + if(result>0) *i = __bswap_16(*i); + #endif + return result; +} + +int readInt32(int32_t* i, FILE* f){ + int result = fread(i, sizeof(int32_t), 1, f); + #ifdef __IS_BIG_ENDIAN__ + if(result>0) *i = __bswap_32(*i); + #endif + return result; +} + +int readDouble(double* d, FILE* f){ + int result = fread(d, sizeof(double), 1, f); + #ifdef __IS_BIG_ENDIAN__ + if(result>0) *d = byteSwapDouble(*d); + #endif + return result; +} + +int writeInt16(const int16_t* i, FILE* f){ + int16_t val = *i; + #ifdef __IS_BIG_ENDIAN__ + val = __bswap_16(val); + #endif + return fwrite((const void*)&val, sizeof(int16_t), 1, f); +} + +int writeInt32(const int32_t* i, FILE* f){ + int32_t val = *i; + #ifdef __IS_BIG_ENDIAN__ + val = __bswap_32(val); + #endif + return fwrite((const void*)&val, sizeof(int32_t), 1, f); +} + +int writeDouble(const double* d, FILE* f){ + double val = *d; + #ifdef __IS_BIG_ENDIAN__ + val = byteSwapDouble(val); + #endif + return fwrite((const void*)&val, sizeof(double), 1, f); +} -int storeLocalmotion(FILE* f, const LocalMotion* lm){ - return fprintf(f,"(LM %i %i %i %i %i %lf %lf)", lm->v.x,lm->v.y,lm->f.x,lm->f.y,lm->f.size, +int storeLocalmotion(FILE* f, const LocalMotion* lm, int serializationMode){ + if(serializationMode == BINARY_SERIALIZATION_MODE){ + return storeLocalmotionBinary(f, lm); + } else { + return storeLocalmotionText(f, lm); + } +} + +int storeLocalmotionText(FILE* f, const LocalMotion* lm) { + return fprintf(f,"(LM %hi %hi %hi %hi %hi %lf %lf)", lm->v.x,lm->v.y,lm->f.x,lm->f.y,lm->f.size, lm->contrast, lm->match); } +int storeLocalmotionBinary(FILE* f, const LocalMotion* lm) { + if (writeInt16(&lm->v.x, f)<=0) return 0; + if (writeInt16(&lm->v.y, f)<=0) return 0; + if (writeInt16(&lm->f.x, f)<=0) return 0; + if (writeInt16(&lm->f.y, f)<=0) return 0; + if (writeInt16(&lm->f.size, f)<=0) return 0; + if (writeDouble(&lm->contrast, f)<=0) return 0; + if (writeDouble(&lm->match, f)<=0) return 0; + return 1; +} + /// restore local motion from file -LocalMotion restoreLocalmotion(FILE* f){ +LocalMotion restoreLocalmotion(FILE* f, const int serializationMode){ + if(serializationMode == BINARY_SERIALIZATION_MODE) { + return restoreLocalmotionBinary(f); + } else { + return restoreLocalmotionText(f); + } +} + +LocalMotion restoreLocalmotionText(FILE* f){ LocalMotion lm; char c; - if(fscanf(f,"(LM %i %i %i %i %i %lf %lf", &lm.v.x,&lm.v.y,&lm.f.x,&lm.f.y,&lm.f.size, + if(fscanf(f,"(LM %hi %hi %hi %hi %hi %lf %lf", &lm.v.x,&lm.v.y,&lm.f.x,&lm.f.y,&lm.f.size, &lm.contrast, &lm.match) != 7) { vs_log_error(modname, "Cannot parse localmotion!\n"); return null_localmotion(); @@ -55,20 +185,64 @@ return lm; } -int vsStoreLocalmotions(FILE* f, const LocalMotions* lms){ +LocalMotion restoreLocalmotionBinary(FILE* f){ + LocalMotion lm; + + if (readInt16(&lm.v.x, f)<=0) goto parse_error_handling; + if (readInt16(&lm.v.y, f)<=0) goto parse_error_handling; + if (readInt16(&lm.f.x, f)<=0) goto parse_error_handling; + if (readInt16(&lm.f.y, f)<=0) goto parse_error_handling; + if (readInt16(&lm.f.size, f)<=0) goto parse_error_handling; + if (readDouble(&lm.contrast, f)<=0) goto parse_error_handling; + if (readDouble(&lm.match, f)<=0) goto parse_error_handling; + + return lm; + +parse_error_handling: + vs_log_error(modname, "Cannot parse localmotion!\n"); + return null_localmotion(); +} + +int vsStoreLocalmotions(FILE* f, const LocalMotions* lms, const int serializationMode){ + if(serializationMode == BINARY_SERIALIZATION_MODE) { + return vsStoreLocalmotionsBinary(f, lms); + } else { + return vsStoreLocalmotionsText(f, lms); + } +} + +int vsStoreLocalmotionsText(FILE* f, const LocalMotions* lms){ int len = vs_vector_size(lms); int i; fprintf(f,"List %i [",len); for (i=0; i0) fprintf(f,","); - if(storeLocalmotion(f,LMGet(lms,i)) <= 0) return 0; + if(storeLocalmotion(f,LMGet(lms,i),ASCII_SERIALIZATION_MODE) <= 0) return 0; } fprintf(f,"]"); return 1; } +int vsStoreLocalmotionsBinary(FILE* f, const LocalMotions* lms){ + const int len = vs_vector_size(lms); + int i; + if(writeInt32(&len, f)<=0) return 0; + for (i=0; i0) while((c=fgetc(f)) && c!=',' && c!=EOF); - LocalMotion lm = restoreLocalmotion(f); + LocalMotion lm = restoreLocalmotion(f,ASCII_SERIALIZATION_MODE); vs_vector_append_dup(&lms,&lm,sizeof(LocalMotion)); } } @@ -98,36 +272,140 @@ return lms; } +LocalMotions vsRestoreLocalmotionsBinary(FILE* f){ + LocalMotions lms; + int i; + int len; + vs_vector_init(&lms,0); + if(readInt32(&len, f) <= 0) { + vs_log_error(modname, "Cannot parse localmotions list!\n"); + return lms; + } + if (len>0){ + vs_vector_init(&lms,len); + for (i=0; iconf.accuracy); - fprintf(f, "# shakiness = %d\n", md->conf.shakiness); - fprintf(f, "# stepsize = %d\n", md->conf.stepSize); - fprintf(f, "# mincontrast = %f\n", md->conf.contrastThreshold); - return VS_OK; + if(md->serializationMode == BINARY_SERIALIZATION_MODE) { + return vsPrepareFileBinary(md, f); + } else { + return vsPrepareFileText(md, f); + } +} + +int vsPrepareFileText(const VSMotionDetect* md, FILE* f){ + if(!f) return VS_ERROR; + fprintf(f, "VID.STAB %i\n", LIBVIDSTAB_FILE_FORMAT_VERSION); + fprintf(f, "# accuracy = %d\n", md->conf.accuracy); + fprintf(f, "# shakiness = %d\n", md->conf.shakiness); + fprintf(f, "# stepsize = %d\n", md->conf.stepSize); + fprintf(f, "# mincontrast = %f\n", md->conf.contrastThreshold); + return VS_OK; +} + +int vsPrepareFileBinary(const VSMotionDetect* md, FILE* f){ + static const unsigned char kFileFormatVersion = LIBVIDSTAB_FILE_FORMAT_VERSION; + if(!f) return VS_ERROR; + fprintf(f, "TRF%hhu", kFileFormatVersion); + writeInt32(&md->conf.accuracy, f); + writeInt32(&md->conf.shakiness, f); + writeInt32(&md->conf.stepSize, f); + writeDouble(&md->conf.contrastThreshold, f); + return VS_OK; } int vsWriteToFile(const VSMotionDetect* md, FILE* f, const LocalMotions* lms){ + if(md->serializationMode == BINARY_SERIALIZATION_MODE) { + return vsWriteToFileBinary(md, f, lms); + } else { + return vsWriteToFileText(md, f, lms); + } +} + +int vsWriteToFileText(const VSMotionDetect* md, FILE* f, const LocalMotions* lms){ if(!f || !lms) return VS_ERROR; if(fprintf(f, "Frame %i (", md->frameNum)>0 - && vsStoreLocalmotions(f,lms)>0 && fprintf(f, ")\n")) + && vsStoreLocalmotions(f, lms, ASCII_SERIALIZATION_MODE)>0 && fprintf(f, ")\n")) return VS_OK; else return VS_ERROR; } +int vsWriteToFileBinary(const VSMotionDetect* md, FILE* f, const LocalMotions* lms){ + if(!f || !lms) return VS_ERROR; + + if(writeInt32(&md->frameNum, f)<=0) return VS_ERROR; + if(vsStoreLocalmotions(f, lms, BINARY_SERIALIZATION_MODE)<=0) return VS_ERROR; + + return VS_OK; +} + +int vsGuessSerializationMode(FILE* f){ + int serializationMode = ASCII_SERIALIZATION_MODE; + const int pos = ftell(f); + + if(fgetc(f) == 'T' + && fgetc(f) == 'R' + && fgetc(f) == 'F') { + serializationMode = BINARY_SERIALIZATION_MODE; + } + + fseek(f, pos, SEEK_SET); + return serializationMode; +} + /// reads the header of the file and return the version number -int vsReadFileVersion(FILE* f){ +int vsReadFileVersion(FILE* f, const int serializationMode){ + if(serializationMode == BINARY_SERIALIZATION_MODE) { + return vsReadFileVersionBinary(f); + } else { + return vsReadFileVersionText(f); + } +} + +int vsReadFileVersionText(FILE* f){ if(!f) return VS_ERROR; int version; - if(fscanf(f, "VID.STAB %i\n", &version)!=1) + if(fscanf(f, "VID.STAB %i\n", &version)!=LIBVIDSTAB_FILE_FORMAT_VERSION) return VS_ERROR; else return version; } -int vsReadFromFile(FILE* f, LocalMotions* lms){ +int vsReadFileVersionBinary(FILE* f){ + if(!f) return VS_ERROR; + unsigned char version; + VSMotionDetectConfig conf; + + if(fscanf(f, "TRF%hhu\n", &version)!=LIBVIDSTAB_FILE_FORMAT_VERSION) goto parse_error_handling; + if(readInt32(&conf.accuracy, f)<=0) goto parse_error_handling; + if(readInt32(&conf.shakiness, f)<=0) goto parse_error_handling; + if(readInt32(&conf.stepSize, f)<=0) goto parse_error_handling; + if(readDouble(&conf.contrastThreshold, f)<=0) goto parse_error_handling; + + return version; +parse_error_handling: + return VS_ERROR; +} + +int vsReadFromFile(FILE* f, LocalMotions* lms, const int serializationMode){ + if(serializationMode == BINARY_SERIALIZATION_MODE) { + return vsReadFromFileBinary(f,lms); + } else { + return vsReadFromFileText(f,lms); + } +} + +int vsReadFromFileText(FILE* f, LocalMotions* lms){ char c = fgetc(f); if(c=='F') { int num; @@ -135,7 +413,7 @@ vs_log_error(modname,"cannot read file, expect 'Frame num (...'"); return VS_ERROR; } - *lms = vsRestoreLocalmotions(f); + *lms = vsRestoreLocalmotions(f,ASCII_SERIALIZATION_MODE); if(fscanf(f,")\n")<0) { vs_log_error(modname,"cannot read file, expect '...)'"); return VS_ERROR; @@ -144,9 +422,9 @@ } else if(c=='#') { char l[1024]; if(fgets(l, sizeof(l), f)==0) return VS_ERROR; - return vsReadFromFile(f,lms); + return vsReadFromFile(f,lms,ASCII_SERIALIZATION_MODE); } else if(c=='\n' || c==' ') { - return vsReadFromFile(f,lms); + return vsReadFromFile(f,lms,ASCII_SERIALIZATION_MODE); } else if(c==EOF) { return VS_ERROR; } else { @@ -156,8 +434,16 @@ } } +int vsReadFromFileBinary(FILE* f, LocalMotions* lms){ + int frameNum; + if(readInt32(&frameNum, f)<=0) return VS_ERROR; + *lms = vsRestoreLocalmotions(f, BINARY_SERIALIZATION_MODE); + return frameNum; +} + int vsReadLocalMotionsFile(FILE* f, VSManyLocalMotions* mlms){ - int version = vsReadFileVersion(f); + const int serializationMode = vsGuessSerializationMode(f); + int version = vsReadFileVersion(f, serializationMode); if(version<1) // old format or unknown return VS_ERROR; if(version>1){ @@ -171,7 +457,7 @@ int index; int oldindex = 0; LocalMotions lms; - while((index = vsReadFromFile(f,&lms)) != VS_ERROR){ + while((index = vsReadFromFile(f,&lms,serializationMode)) != VS_ERROR){ if(index > oldindex+1){ vs_log_info(modname,"VID.STAB file: index of frames is not continuous %i -< %i", oldindex, index); diff -Nru libvidstab-1.1.0/src/serialize.h libvidstab-1.1.0+git-20201110.f9166e9/src/serialize.h --- libvidstab-1.1.0/src/serialize.h 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/src/serialize.h 2020-11-10 06:59:25.000000000 +0000 @@ -25,6 +25,8 @@ #ifndef __SERIALIZE_H #define __SERIALIZE_H +#define LIBVIDSTAB_FILE_FORMAT_VERSION 1 + #include "transformtype.h" #include "motiondetect.h" #include "transform.h" @@ -36,12 +38,14 @@ #define VSMLMGet(manylocalmotions,index) \ ((LocalMotions*)vs_vector_get(manylocalmotions,index)) +/// guess the serialization mode of the local motions file +int vsGuessSerializationMode(FILE* f); /// stores local motions to file -int vsStoreLocalmotions(FILE* f, const LocalMotions* lms); +int vsStoreLocalmotions(FILE* f, const LocalMotions* lms, const int serializationMode); /// restores local motions from file -LocalMotions vsRestoreLocalmotions(FILE* f); +LocalMotions vsRestoreLocalmotions(FILE* f, const int serializationMode); /// writes the header to the file that is to be holding the local motions @@ -51,13 +55,13 @@ int vsWriteToFile(const VSMotionDetect* td, FILE* f, const LocalMotions* lms); /// reads the header of the file and return the version number (used by readLocalmotionsFile) -int vsReadFileVersion(FILE* f); +int vsReadFileVersion(FILE* f, const int serializationMode); /* * reads the next set of localmotions from the file, return VS_ERROR on error or * if nothing is read (used by readLocalmotionsFile) */ -int vsReadFromFile(FILE* f, LocalMotions* lms); +int vsReadFromFile(FILE* f, LocalMotions* lms, const int serializationMode); /* * reads the entire file of localmotions, return VS_ERROR on error or if nothing is read diff -Nru libvidstab-1.1.0/src/transform.c libvidstab-1.1.0+git-20201110.f9166e9/src/transform.c --- libvidstab-1.1.0/src/transform.c 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/src/transform.c 2020-11-10 06:59:25.000000000 +0000 @@ -455,7 +455,16 @@ for (int i = 0; i < trans->len; i++) { zooms[i] = transform_get_required_zoom(&ts[i], w, h); } - meanzoom = mean(zooms, trans->len) + td->conf.zoom; // add global zoom + + double prezoom = 0.; + double postzoom = 0.; + if(td->conf.zoom>0.){ + prezoom = td->conf.zoom; + } else if(td->conf.zoom < 0.){ + postzoom = td->conf.zoom; + } + + meanzoom = mean(zooms, trans->len) + prezoom; // add global zoom // forward - propagation (to make the zooming smooth) req = meanzoom; for (int i = 0; i < trans->len; i++) { @@ -467,7 +476,7 @@ req = meanzoom; for (int i = trans->len-1; i >= 0; i--) { req = VS_MAX(req, zooms[i]); - ts[i].zoom=VS_MAX(ts[i].zoom,req); + ts[i].zoom=VS_MAX(ts[i].zoom,req) + postzoom; req= VS_MAX(meanzoom, req - td->conf.zoomSpeed); } vs_free(zooms); diff -Nru libvidstab-1.1.0/src/transformfixedpoint.c libvidstab-1.1.0+git-20201110.f9166e9/src/transformfixedpoint.c --- libvidstab-1.1.0/src/transformfixedpoint.c 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/src/transformfixedpoint.c 2020-11-10 06:59:25.000000000 +0000 @@ -74,7 +74,8 @@ // pixel at border of source image short val_border = PIX(img, img_linesize, VS_MAX(VS_MIN(ix_f, width-1),0), VS_MAX(VS_MIN(iy_f, height-1),0)); - *rv = (def * c + val_border * (w - c)) / w; + int32_t res = (def * c + val_border * (w - c)) / w; + *rv = (res >= 0) ? ((res < 255) ? res : 255) : 0; }else{ short v1 = PIXEL(img, img_linesize, ix_c, iy_c, width, height, def); short v2 = PIXEL(img, img_linesize, ix_c, iy_f, width, height, def); @@ -86,7 +87,8 @@ fp16 y_c = iToFp16(iy_c); fp16 s = fp16To8(v1*(x - x_f)+v3*(x_c - x))*fp16To8(y - y_f) + fp16To8(v2*(x - x_f) + v4*(x_c - x))*fp16To8(y_c - y) + 1; - *rv = fp16ToIRound(s); + int32_t res = fp16ToIRound(s); + *rv = (res >= 0) ? ((res < 255) ? res : 255) : 0; } } @@ -151,7 +153,7 @@ PIX(img, img_linesize, ix_f+1, iy_f+2), PIX(img, img_linesize, ix_f+2, iy_f+2)); short res = bicub_kernel(y-y_f, v1, v2, v3, v4); - *rv = res < 255 ? res : 255; + *rv = (res >= 0) ? ((res < 255) ? res : 255) : 0; } } @@ -180,7 +182,7 @@ fp16To8(v2*(x - x_f) + v4*(x_c - x))*fp16To8(y_c - y); // it is underestimated due to truncation, so we add one short res = fp16ToI(s); - *rv = res < 255 ? res+1 : 255; + *rv = (res >= 0) ? ((res < 255) ? res+1 : 255) : 0; } } @@ -199,7 +201,7 @@ short v2 = PIXEL(img, img_linesize, ix_f, y_n, width, height, def); fp16 s = v1*(x - x_f) + v2*(x_c - x); short res = fp16ToI(s); - *rv = res < 255 ? res : 255; + *rv = (res >= 0) ? ((res < 255) ? res : 255) : 0; } /** interpolateZero: nearest neighbor interpolation function, see interpolate */ @@ -209,7 +211,8 @@ { int32_t ix_n = fp16ToIRound(x); int32_t iy_n = fp16ToIRound(y); - *rv = (uint8_t) PIXEL(img, img_linesize, ix_n, iy_n, width, height, def); + int32_t res = PIXEL(img, img_linesize, ix_n, iy_n, width, height, def); + *rv = (res >= 0) ? ((res < 255) ? res : 255) : 0; } @@ -250,7 +253,8 @@ fp16 y_c = iToFp16(iy_c); fp16 s = fp16To8(v1*(x - x_f)+v3*(x_c - x))*fp16To8(y - y_f) + fp16To8(v2*(x - x_f) + v4*(x_c - x))*fp16To8(y_c - y); - *rv = fp16ToIRound(s); + int32_t res = fp16ToIRound(s); + *rv = (res >= 0) ? ((res < 255) ? res : 255) : 0; } } diff -Nru libvidstab-1.1.0/src/transformfixedpoint.h libvidstab-1.1.0+git-20201110.f9166e9/src/transformfixedpoint.h --- libvidstab-1.1.0/src/transformfixedpoint.h 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/src/transformfixedpoint.h 2020-11-10 06:59:25.000000000 +0000 @@ -20,13 +20,6 @@ * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * - * This work is licensed under the Creative Commons - * Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of - * this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ - * or send a letter to Creative Commons, 543 Howard Street, 5th Floor, - * San Francisco, California, 94105, USA. - * This EXCLUDES COMMERCIAL USAGE - * */ #ifndef __TRANSFORMFIXEDPOINT_H #define __TRANSFORMFIXEDPOINT_H diff -Nru libvidstab-1.1.0/src/transformfloat.c libvidstab-1.1.0+git-20201110.f9166e9/src/transformfloat.c --- libvidstab-1.1.0/src/transformfloat.c 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/src/transformfloat.c 2020-11-10 06:59:25.000000000 +0000 @@ -44,7 +44,8 @@ short v4 = PIXEL(img, img_linesize, x_f, y_f, width, height, def); float s = (v1*(x - x_f)+v3*(x_c - x))*(y - y_f) + (v2*(x - x_f) + v4*(x_c - x))*(y_c - y); - *rv = (uint8_t)s; + int32_t res = (int32_t)s; + *rv = (res >= 0) ? ((res < 255) ? res : 255) : 0; } /** taken from http://en.wikipedia.org/wiki/Bicubic_interpolation for alpha=-0.5 @@ -92,7 +93,8 @@ PIX(img, img_linesize, x_f, y_f+2), PIX(img, img_linesize, x_f+1, y_f+2), PIX(img, img_linesize, x_f+2, y_f+2)); - *rv = (uint8_t)_FLT(bicub_kernel)(y-y_f, v1, v2, v3, v4); + int32_t res = (int32_t)_FLT(bicub_kernel)(y-y_f, v1, v2, v3, v4); + *rv = (res >= 0) ? ((res < 255) ? res : 255) : 0; } } @@ -115,7 +117,8 @@ short v4 = PIX(img, img_linesize, x_f, y_f); float s = (v1*(x - x_f)+v3*(x_c - x))*(y - y_f) + (v2*(x - x_f) + v4*(x_c - x))*(y_c - y); - *rv = (uint8_t)s; + int32_t res = (int32_t)s; + *rv = (res >= 0) ? ((res < 255) ? res : 255) : 0; } } @@ -131,7 +134,8 @@ float v1 = PIXEL(img, img_linesize, x_c, y_n, width, height, def); float v2 = PIXEL(img, img_linesize, x_f, y_n, width, height, def); float s = v1*(x - x_f) + v2*(x_c - x); - *rv = (uint8_t)s; + int32_t res = (int32_t)s; + *rv = (res >= 0) ? ((res < 255) ? res : 255) : 0; } /** interpolateZero: nearest neighbor interpolation function, see interpolate */ @@ -178,7 +182,8 @@ short v4 = PIXELN(img, img_linesize, x_f, y_f, width, height, N, channel, def); float s = (v1*(x - x_f)+v3*(x_c - x))*(y - y_f) + (v2*(x - x_f) + v4*(x_c - x))*(y_c - y); - *rv = (uint8_t)s; + int32_t res = (int32_t)s; + *rv = (res >= 0) ? ((res < 255) ? res : 255) : 0; } } diff -Nru libvidstab-1.1.0/src/transformfloat.h libvidstab-1.1.0+git-20201110.f9166e9/src/transformfloat.h --- libvidstab-1.1.0/src/transformfloat.h 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/src/transformfloat.h 2020-11-10 06:59:25.000000000 +0000 @@ -20,12 +20,6 @@ * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * - * This work is licensed under the Creative Commons - * Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of - * this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ - * or send a letter to Creative Commons, 543 Howard Street, 5th Floor, - * San Francisco, California, 94105, USA. - * This EXCLUDES COMMERCIAL USAGE * */ #ifndef __TRANSFORMFLOAT_H diff -Nru libvidstab-1.1.0/src/transform.h libvidstab-1.1.0+git-20201110.f9166e9/src/transform.h --- libvidstab-1.1.0/src/transform.h 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/src/transform.h 2020-11-10 06:59:25.000000000 +0000 @@ -26,6 +26,7 @@ #include #include +#include #include "transformtype.h" #include "frameinfo.h" #include "vidstabdefines.h" diff -Nru libvidstab-1.1.0/src/transformtype.c libvidstab-1.1.0+git-20201110.f9166e9/src/transformtype.c --- libvidstab-1.1.0/src/transformtype.c 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/src/transformtype.c 2020-11-10 06:59:25.000000000 +0000 @@ -39,6 +39,12 @@ VSTransform t; t.x = x; t.y = y; + while (alpha < -M_PI){ + alpha += 2.0*M_PI; + } + while (alpha > M_PI){ + alpha -= 2.0*M_PI; + } t.alpha = alpha; t.zoom = zoom; t.barrel = barrel; diff -Nru libvidstab-1.1.0/src/transformtype.h libvidstab-1.1.0+git-20201110.f9166e9/src/transformtype.h --- libvidstab-1.1.0/src/transformtype.h 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/src/transformtype.h 2020-11-10 06:59:25.000000000 +0000 @@ -24,6 +24,7 @@ #define __TRANSFORMTYPE_H #include +#include #include "vsvector.h" /* structure to hold information about frame transformations @@ -44,15 +45,15 @@ /** stores x y and size of a measurement field */ typedef struct _field { - int x; // middle position x - int y; // middle position y - int size; // size of field + int16_t x; // middle position x + int16_t y; // middle position y + int16_t size; // size of field } Field; /** stores x y coordinates (integer) */ typedef struct _vec { - int x; // middle position x - int y; // middle position y + int16_t x; // middle position x + int16_t y; // middle position y } Vec; /* structure to hold information about local motion. diff -Nru libvidstab-1.1.0/tests/CMakeLists.txt libvidstab-1.1.0+git-20201110.f9166e9/tests/CMakeLists.txt --- libvidstab-1.1.0/tests/CMakeLists.txt 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/tests/CMakeLists.txt 2020-11-10 06:59:25.000000000 +0000 @@ -5,13 +5,18 @@ cmake_minimum_required (VERSION 2.6) project (vid.stab) -SET(CMAKE_BUILTTYPE None) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../CMakeModules/") +include (FindSSE) + option(USE_OMP "use parallelization use OMP" ON) -#add_definitions( -Wall -O3 -Wno-pointer-sign -DTESTING -std=gnu99) -add_definitions( -Wall -O0 -g -Wno-pointer-sign -DTESTING -std=gnu99) +# Default to debug builds if no explicit build type specified. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug") +endif() + +add_definitions(-Wall -Wno-pointer-sign -DTESTING -std=gnu99) find_package(Orc) if(ORC_FOUND) add_definitions( -DUSE_ORC ${ORC_DEFINITIONS}) @@ -20,7 +25,9 @@ add_definitions( -DDISABLE_ORC) endif() +if(SSE2_FOUND) add_definitions( -DUSE_SSE2 -msse2 -ffast-math -fno-show-column ) # -DUSE_SSE2_ASM +endif() if(USE_OMP) add_definitions(-fopenmp -DUSE_OMP) diff -Nru libvidstab-1.1.0/tests/testframework.c libvidstab-1.1.0+git-20201110.f9166e9/tests/testframework.c --- libvidstab-1.1.0/tests/testframework.c 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/tests/testframework.c 2020-11-10 06:59:25.000000000 +0000 @@ -36,7 +36,7 @@ fprintf(stderr, "UNIT TESTs succeeded:\t %s%i/%i\033[0m\n", units_failed>0 ? "\033[1;31m" : "\033[1;32m", units_success, units_success + units_failed); - return units_failed==0; + return units_failed!=0; } diff -Nru libvidstab-1.1.0/tests/testframework.h libvidstab-1.1.0+git-20201110.f9166e9/tests/testframework.h --- libvidstab-1.1.0/tests/testframework.h 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/tests/testframework.h 2020-11-10 06:59:25.000000000 +0000 @@ -2,7 +2,10 @@ #define __TESTFRAMEWORK_H #include + +#if defined(__linux__) #include +#endif int contains(char **list, int len, const char *str, const char* descr); void unittest_init(); diff -Nru libvidstab-1.1.0/tests/test_motiondetect.c libvidstab-1.1.0+git-20201110.f9166e9/tests/test_motiondetect.c --- libvidstab-1.1.0/tests/test_motiondetect.c 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/tests/test_motiondetect.c 2020-11-10 06:59:25.000000000 +0000 @@ -19,7 +19,9 @@ int i; int start = timeOfDayinMS(); +#ifdef USE_OMP omp_set_dynamic( 1 ); +#endif md.conf.numThreads=threads; for(i=0; i #include #include + +#if defined(__linux__) #include +#endif #ifdef USE_OMP #include @@ -117,7 +120,9 @@ } if(all || contains(argv,argc,"--testSR", "store_restore")){ - UNIT(test_store_restore(&testdata)); + UNIT(test_store_restore(&testdata, ASCII_SERIALIZATION_MODE)); + UNIT(test_store_restore(&testdata, BINARY_SERIALIZATION_MODE)); + UNIT(test_store_restore(&testdata, 0)); // test default binary selection } if(all || contains(argv,argc,"--testCT", "contrastImg")){ diff -Nru libvidstab-1.1.0/tests/test_store_restore.c libvidstab-1.1.0+git-20201110.f9166e9/tests/test_store_restore.c --- libvidstab-1.1.0/tests/test_store_restore.c 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/tests/test_store_restore.c 2020-11-10 06:59:25.000000000 +0000 @@ -8,10 +8,13 @@ return 1; } -int test_store_restore(TestData* testdata){ +int test_store_restore(TestData* testdata, int serializationMode){ VSMotionDetectConfig mdconf = vsMotionDetectGetDefaultConfig("test_motionDetect"); VSMotionDetect md; + + md.serializationMode = serializationMode; test_bool(vsMotionDetectInit(&md, &mdconf, &testdata->fi) == VS_OK); + serializationMode = md.serializationMode; LocalMotions lms; int i; @@ -21,12 +24,12 @@ } FILE* f = fopen("lmtest","w"); - vsStoreLocalmotions(f,&lms); + vsStoreLocalmotions(f,&lms,serializationMode); fclose(f); f = fopen("lmtest","r"); - LocalMotions test = vsRestoreLocalmotions(f); + LocalMotions test = vsRestoreLocalmotions(f,serializationMode); fclose(f); - vsStoreLocalmotions(stderr,&test); + vsStoreLocalmotions(stderr,&test,ASCII_SERIALIZATION_MODE); compare_localmotions(&lms,&test); fprintf(stderr,"\n** LM and LMS OKAY\n"); @@ -39,12 +42,12 @@ fclose(f); f = fopen("lmstest","r"); - test_bool(vsReadFileVersion(f)==1); + test_bool(vsReadFileVersion(f,serializationMode)==1); LocalMotions read1; - test_bool(vsReadFromFile(f,&read1)==1); + test_bool(vsReadFromFile(f,&read1,serializationMode)==1); compare_localmotions(&lms,&read1); LocalMotions read2; - test_bool(vsReadFromFile(f,&read2)==2); + test_bool(vsReadFromFile(f,&read2,serializationMode)==2); compare_localmotions(&test,&read2); fclose(f); fprintf(stderr,"** Reading file stepwise OKAY\n"); diff -Nru libvidstab-1.1.0/transcode/CMakeLists.txt libvidstab-1.1.0+git-20201110.f9166e9/transcode/CMakeLists.txt --- libvidstab-1.1.0/transcode/CMakeLists.txt 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/transcode/CMakeLists.txt 2020-11-10 06:59:25.000000000 +0000 @@ -1,16 +1,17 @@ cmake_minimum_required (VERSION 2.6) project (vid.stab.transcode) -SET(CMAKE_BUILTTYPE None) - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../CMakeModules/") # set your transcode path here! set(TRANSCODE_ROOT ../../transcode) +# Default to release builds if no explicit build type specified. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Release") +endif() -add_definitions( -Wall -O3 -Wno-pointer-sign -DTRANSCODE -std=gnu99) -#add_definitions( -Wall -O0 -g -Wno-pointer-sign ) +add_definitions(-Wall -Wno-pointer-sign -DTRANSCODE -std=gnu99) # I tried it with 0.4.14 # 0.4.10 did not work (not all opcode implemented) # find_package(Orc) // it actually not used by any active code diff -Nru libvidstab-1.1.0/transcode/filter_deshake.c libvidstab-1.1.0+git-20201110.f9166e9/transcode/filter_deshake.c --- libvidstab-1.1.0/transcode/filter_deshake.c 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/transcode/filter_deshake.c 2020-11-10 06:59:25.000000000 +0000 @@ -79,6 +79,8 @@ " It also generates a file with relative transform information\n" " to be used by the transform filter separately." "Options\n" + " 'fileformat' the type of file format used to write the transforms\n" + " 1: ascii (human readable) file format 2: binary (smaller) file format\n" " 'smoothing' number of frames*2 + 1 used for lowpass filtering \n" " used for stabilizing (def: 10)\n" " 'shakiness' how shaky is the video and how quick is the camera?\n" @@ -213,6 +215,7 @@ return(TC_IMPORT_ERROR); } + optstr_get(options, "fileformat", "%d", &md->serializationMode); optstr_get(options, "result", "%[^:]", sd->result); optstr_get(options, "shakiness", "%d", &mdconf.shakiness); optstr_get(options, "accuracy", "%d", &mdconf.accuracy); diff -Nru libvidstab-1.1.0/transcode/filter_stabilize.c libvidstab-1.1.0+git-20201110.f9166e9/transcode/filter_stabilize.c --- libvidstab-1.1.0/transcode/filter_stabilize.c 2017-05-30 08:23:59.000000000 +0000 +++ libvidstab-1.1.0+git-20201110.f9166e9/transcode/filter_stabilize.c 2020-11-10 06:59:25.000000000 +0000 @@ -173,6 +173,7 @@ return(TC_IMPORT_ERROR); } + optstr_get(options, "fileformat", "%d", &md->serializationMode); optstr_get(options, "result", "%[^:]", sd->result); optstr_get(options, "shakiness", "%d", &conf.shakiness); optstr_get(options, "accuracy", "%d", &conf.accuracy);