├── src ├── stable.cpp ├── xdog-demo.rc ├── test.png ├── xdog-demo.icns ├── xdog-demo.ico ├── resources.qrc ├── stable.h ├── main.cpp ├── CMakeLists.txt └── mainwindow.h ├── util ├── stable.cpp ├── stable.h ├── settingscheck.h ├── logwindow.h ├── cudadevicedialog.h ├── CMakeLists.txt ├── libav_encoder.h ├── settingscheck.cpp ├── imageutil.h ├── fancystyle.h ├── cudadevicedialog.ui ├── rolloutbox.h ├── videocontrols.h ├── libav_decoder.h ├── videoplayer.h ├── paramui.h ├── imageview.h ├── logwindow.cpp ├── imageutil.cpp ├── videocontrols.cpp ├── rolloutbox.cpp └── cudadevicedialog.cpp ├── .gitignore ├── version.h.in ├── gpu ├── CMakeLists.txt ├── gpu_noise.h ├── gpu_cache.h ├── gpu_convert.h ├── gpu_etf.h ├── gpu_minmax.h ├── gpu_dog2.h ├── gpu_error.h ├── gpu_bilateral.h ├── gpu_shuffle.h ├── gpu_gauss.h ├── gpu_util.h ├── gpu_stbf2.h ├── cpu_sampler.h ├── gpu_dog.h ├── gpu_binder.h ├── gpu_color.h ├── gpu_grad.h ├── gpu_noise.cu ├── gpu_plm2.h ├── gpu_oabf.h ├── gpu_error.cpp ├── gpu_blend.h ├── gpu_wog.h ├── gpu_sampler.h ├── gpu_stgauss2.cpp ├── gpu_cache.cpp ├── gpu_convert.cu ├── gpu_image.cu ├── gpu_st.h ├── gpu_dog2.cu ├── gpu_image.h ├── gpu_oabf.cu ├── cpu_image.h ├── gpu_util.cu ├── basic_image.h ├── gpu_bilateral.cu ├── gpu_minmax.cu ├── gpu_stgauss2.h ├── gpu_etf.cu ├── gpu_dog.cu ├── gpu_stgauss2.cu ├── gpu_gauss.cu └── gpu_wog.cu ├── CMakeLists.txt └── cmake ├── SetupCUDA.cmake ├── SetupCPack.cmake ├── FindLibav.cmake └── Utils.cmake /src/stable.cpp: -------------------------------------------------------------------------------- 1 | #include "stable.h" 2 | -------------------------------------------------------------------------------- /util/stable.cpp: -------------------------------------------------------------------------------- 1 | #include "stable.h" 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | CMakeLists.txt.user 3 | -------------------------------------------------------------------------------- /src/xdog-demo.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON DISCARDABLE "xdog-demo.ico" -------------------------------------------------------------------------------- /version.h.in: -------------------------------------------------------------------------------- 1 | #define PACKAGE_VERSION "@CPACK_PACKAGE_VERSION@" 2 | -------------------------------------------------------------------------------- /src/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gonzojive/xdog/HEAD/src/test.png -------------------------------------------------------------------------------- /src/xdog-demo.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gonzojive/xdog/HEAD/src/xdog-demo.icns -------------------------------------------------------------------------------- /src/xdog-demo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gonzojive/xdog/HEAD/src/xdog-demo.ico -------------------------------------------------------------------------------- /src/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | test.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /gpu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB sources *.cpp *.h *.cu) 2 | CUDA_ADD_LIBRARY(gpu ${sources}) 3 | SOURCE_GROUP(src REGULAR_EXPRESSION "c$|cpp$|hpp$|h$|ui$|qrc$|cu$") 4 | -------------------------------------------------------------------------------- /util/stable.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_STABLE_H 2 | #define INCLUDED_STABLE_H 3 | 4 | #ifdef WIN32 5 | #define WINDOWS_LEAN_AND_MEAN 6 | #define NOMINMAX 7 | #endif 8 | 9 | #include 10 | #include 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/stable.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_STABLE_H 2 | #define INCLUDED_STABLE_H 3 | 4 | #ifdef __cplusplus 5 | 6 | #ifdef WIN32 7 | #define WINDOWS_LEAN_AND_MEAN 8 | #define NOMINMAX 9 | #endif 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef min 16 | #undef min 17 | #endif 18 | #ifdef max 19 | #undef max 20 | #endif 21 | 22 | #endif 23 | #endif 24 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 2 | PROJECT(xdog-demo) 3 | 4 | SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ) 5 | SET(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "limited configs" FORCE) 6 | SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 7 | SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 8 | SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 9 | 10 | INCLUDE(Utils) 11 | INCLUDE(SetupCPack) 12 | 13 | INCLUDE(CPack) 14 | CONFIGURE_FILE(version.h.in ${PROJECT_BINARY_DIR}/version.h @ONLY) 15 | 16 | INCLUDE(SetupCUDA) 17 | 18 | FIND_PACKAGE(Libav QUIET) 19 | IF(LIBAV_FOUND) 20 | ADD_DEFINITIONS(/DHAVE_LIBAV) 21 | ENDIF() 22 | 23 | FIND_PACKAGE(Qt4) 24 | 25 | ADD_SUBDIRECTORY(gpu) 26 | ADD_SUBDIRECTORY(src) 27 | ADD_SUBDIRECTORY(util) 28 | -------------------------------------------------------------------------------- /util/settingscheck.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | extern void settingsCheck(); 19 | -------------------------------------------------------------------------------- /gpu/gpu_noise.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_noise_random(unsigned w, unsigned h, float a=0, float b=1); 21 | -------------------------------------------------------------------------------- /gpu/gpu_cache.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include 19 | 20 | void gpu_cache_alloc( void **ptr, unsigned *pitch, unsigned w, unsigned h ); 21 | void gpu_cache_free( void *ptr, unsigned pitch, unsigned w, unsigned h ); 22 | void gpu_cache_clear(); 23 | size_t gpu_cache_size(); 24 | size_t gpu_cache_total(); 25 | -------------------------------------------------------------------------------- /gpu/gpu_convert.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_8u_to_32f( const gpu_image& src ); 21 | gpu_image gpu_32f_to_8u( const gpu_image& src ); 22 | gpu_image gpu_8u_to_32f( const gpu_image& src ); 23 | gpu_image gpu_32f_to_8u( const gpu_image& src ); 24 | -------------------------------------------------------------------------------- /cmake/SetupCUDA.cmake: -------------------------------------------------------------------------------- 1 | SET(CUDA_ARCH "sm_10" CACHE STRING "CUDA architecture") 2 | SET_PROPERTY(CACHE CUDA_ARCH PROPERTY STRINGS sm_10 sm_11 sm_20 sm_21 none) 3 | IF(NOT (${CUDA_ARCH} STREQUAL none)) 4 | SET(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};;-arch=${CUDA_ARCH}") 5 | ENDIF() 6 | OPTION(CUDA_PTXAS_VERBOSE "Show ptxas verbose information" OFF) 7 | IF(${CUDA_PTXAS_VERBOSE}) 8 | SET(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};;--ptxas-options=-v") 9 | ENDIF() 10 | FIND_PACKAGE(CUDA 4.0 REQUIRED) 11 | 12 | IF(WIN32) 13 | IF(CMAKE_CL_64) 14 | SET(CUDA_LIB_DIR "${CUDA_TOOLKIT_ROOT_DIR}/lib/x64") 15 | ELSE() 16 | SET(CUDA_LIB_DIR "${CUDA_TOOLKIT_ROOT_DIR}/lib/Win32") 17 | ENDIF() 18 | ELSEIF(APPLE) 19 | SET(CUDA_LIB_DIR "${CUDA_TOOLKIT_ROOT_DIR}/lib") 20 | ELSE() 21 | IF(CMAKE_SIZEOF_VOID_P EQUAL 8) 22 | SET(CUDA_LIB_DIR "${CUDA_TOOLKIT_ROOT_DIR}/lib64") 23 | ELSE() 24 | SET(CUDA_LIB_DIR "${CUDA_TOOLKIT_ROOT_DIR}/lib") 25 | ENDIF() 26 | ENDIF() 27 | FIND_LIBRARY(CUDA_npp_LIBRARY npp HINTS "${CUDA_LIB_DIR}") 28 | FIND_LIBRARY(CUDA_curand_LIBRARY curand HINTS "${CUDA_LIB_DIR}") 29 | -------------------------------------------------------------------------------- /gpu/gpu_etf.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_etf_full( const gpu_image& src, float sigma, int N, 21 | float precision=2, bool gaussian=false ); 22 | 23 | gpu_image gpu_etf_xy( const gpu_image& src, float sigma, int N, 24 | float precision=2); 25 | -------------------------------------------------------------------------------- /gpu/gpu_minmax.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | void gpu_minmax( const gpu_image& src, float *pmin, float *pmax ); 21 | float gpu_min( const gpu_image& src ); 22 | float gpu_max( const gpu_image& src ); 23 | 24 | gpu_image gpu_normalize(const gpu_image& src); 25 | gpu_image gpu_normalize_gray(const gpu_image& src); 26 | -------------------------------------------------------------------------------- /util/logwindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | class LogWindow : public QPlainTextEdit { 19 | Q_OBJECT 20 | public: 21 | LogWindow(QWidget *parent); 22 | ~LogWindow(); 23 | virtual void closeEvent(QCloseEvent *e); 24 | virtual void contextMenuEvent(QContextMenuEvent *event); 25 | 26 | public slots: 27 | void logText(const QString& msg); 28 | 29 | public: 30 | static void install(); 31 | }; 32 | -------------------------------------------------------------------------------- /gpu/gpu_dog2.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_isotropic_dog2( const gpu_image& src, 21 | float sigma, float k, float p, float precision=2 ); 22 | 23 | gpu_image gpu_gradient_dog2( const gpu_image& src, const gpu_image& tfab, 24 | float sigma, float k, float p, float precision=2 ); 25 | -------------------------------------------------------------------------------- /gpu/gpu_error.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include 19 | 20 | extern void gpu_error_msg(cudaError_t err, const char *file, size_t line); 21 | 22 | #define GPU_CHECK_ERROR() \ 23 | { cudaError_t err = cudaGetLastError(); if (err != cudaSuccess) gpu_error_msg(err, __FILE__, __LINE__); } 24 | 25 | #define GPU_SAFE_CALL( call ) \ 26 | { cudaError_t err = call; if (err != cudaSuccess) gpu_error_msg(err, __FILE__, __LINE__); } 27 | -------------------------------------------------------------------------------- /util/cudadevicedialog.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | class Ui_CudaDeviceDialog; 19 | 20 | class CudaDeviceDialog : public QDialog { 21 | Q_OBJECT 22 | public: 23 | CudaDeviceDialog(QWidget *parent); 24 | static int select(bool force=false); 25 | 26 | protected slots: 27 | void updateInfo(int index); 28 | 29 | protected: 30 | void addItem(int pad, const QString& a, const QString& b=QString::null); 31 | QString m_infoText; 32 | Ui_CudaDeviceDialog *m; 33 | }; 34 | -------------------------------------------------------------------------------- /util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | INCLUDE(${QT_USE_FILE}) 2 | 3 | INCLUDE_DIRECTORIES( 4 | ${CMAKE_CURRENT_SOURCE_DIR} 5 | ${CMAKE_CURRENT_BINARY_DIR} 6 | ${PROJECT_SOURCE_DIR}/gpu 7 | ${PROJECT_BINARY_DIR} ) 8 | 9 | FILE(GLOB sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp *.h *.ui) 10 | IF(LIBAV_FOUND) 11 | INCLUDE_DIRECTORIES( ${LIBAV_INCLUDE_DIR} ) 12 | ELSE() 13 | LIST(REMOVE_ITEM sources 14 | libav_decoder.cpp 15 | libav_decoder.h 16 | libav_encoder.cpp 17 | libav_encoder.h ) 18 | ENDIF() 19 | 20 | QT4_AUTO_WRAP( sources ${sources} ) 21 | CUDA_ADD_LIBRARY( util STATIC ${sources} ) 22 | 23 | SOURCE_GROUP( src REGULAR_EXPRESSION "c$|cpp$|hpp$|h$|ui$|qrc$|cu$" ) 24 | SOURCE_GROUP( generated REGULAR_EXPRESSION "cxx$|ui_" ) 25 | 26 | IF(MSVC) 27 | IF(MSVC_IDE) 28 | SET_TARGET_PROPERTIES( util PROPERTIES COMPILE_FLAGS "/FIstable.h /Yustable.h" ) 29 | SET_SOURCE_FILES_PROPERTIES( stable.cpp PROPERTIES COMPILE_FLAGS "/Ycstable.h" ) 30 | ELSE() 31 | SET_TARGET_PROPERTIES( util PROPERTIES COMPILE_FLAGS "/FIstable.h" ) 32 | ENDIF() 33 | ELSE(MSVC) 34 | SET_TARGET_PROPERTIES( util PROPERTIES COMPILE_FLAGS "-include stable.h" ) 35 | ENDIF(MSVC) 36 | -------------------------------------------------------------------------------- /gpu/gpu_bilateral.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_bilateral_filter( const gpu_image& src, float sigma_d, float sigma_r, float precision=2 ); 21 | gpu_image gpu_bilateral_filter( const gpu_image& src, float sigma_d, float sigma_r, float precision=2 ); 22 | 23 | gpu_image gpu_bilateral_filter_xy( const gpu_image& src, float sigma_d, float sigma_r, float precision=2 ); 24 | gpu_image gpu_bilateral_filter_xy( const gpu_image& src, float sigma_d, float sigma_r, float precision=2 ); 25 | -------------------------------------------------------------------------------- /gpu/gpu_shuffle.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_shuffle( const gpu_image& src, int x ); 21 | gpu_image gpu_shuffle( const gpu_image& src, int x ); 22 | 23 | gpu_image gpu_shuffle( const gpu_image& src, int x, int y ); 24 | gpu_image gpu_shuffle( const gpu_image& src, int x, int y ); 25 | 26 | gpu_image gpu_shuffle( const gpu_image& src, int x, int y, int z, int w ); 27 | gpu_image gpu_shuffle( const gpu_image& src, int x, int y, int z, int w ); 28 | -------------------------------------------------------------------------------- /gpu/gpu_gauss.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_gauss_filter( const gpu_image& src, float sigma, float precision=2 ); 21 | gpu_image gpu_gauss_filter( const gpu_image& src, float sigma, float precision=2 ); 22 | 23 | gpu_image gpu_gauss_filter_xy( const gpu_image& src, float sigma, float precision=2 ); 24 | gpu_image gpu_gauss_filter_xy( const gpu_image& src, float sigma, float precision=2 ); 25 | 26 | gpu_image gpu_gauss_filter_3x3( const gpu_image& src ); 27 | gpu_image gpu_gauss_filter_5x5( const gpu_image& src ); 28 | -------------------------------------------------------------------------------- /gpu/gpu_util.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | extern gpu_image gpu_adjust( const gpu_image& src, float a, float b ); 21 | extern gpu_image gpu_adjust( const gpu_image& src, float4 a, float4 b ); 22 | 23 | extern gpu_image gpu_invert( const gpu_image& src); 24 | extern gpu_image gpu_invert( const gpu_image& src); 25 | 26 | extern gpu_image gpu_saturate( const gpu_image& src); 27 | extern gpu_image gpu_saturate( const gpu_image& src); 28 | 29 | extern gpu_image gpu_lerp( const gpu_image& src0, const gpu_image& src1, float t ); 30 | -------------------------------------------------------------------------------- /gpu/gpu_stbf2.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_stbf2_filter( const gpu_image& src, const gpu_image& st, 21 | float sigma_d, float sigma_r, float precision, float max_angle, bool adaptive, 22 | bool src_linear, bool st_linear, int order, float step_size ); 23 | 24 | gpu_image gpu_stbf2_filter( const gpu_image& src, const gpu_image& st, 25 | float sigma_d, float sigma_r, float precision, float max_angle, bool adaptive, 26 | bool src_linear, bool st_linear, int order, float step_size ); 27 | -------------------------------------------------------------------------------- /gpu/cpu_sampler.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | template 21 | struct cpu_sampler { 22 | const cpu_image& img_; 23 | cudaTextureFilterMode filter_mode_; 24 | 25 | cpu_sampler(const cpu_image& img, cudaTextureFilterMode filter_mode=cudaFilterModePoint) 26 | : img_(img), filter_mode_(filter_mode) 27 | { } 28 | 29 | unsigned w() const { 30 | return img_.w(); 31 | } 32 | 33 | unsigned h() const { 34 | return img_.w(); 35 | } 36 | 37 | T operator()(float x, float y) const { 38 | return (filter_mode_ == cudaFilterModePoint)? img_(x, y) : img_.sample_linear(x, y); 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /gpu/gpu_dog.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_isotropic_dog( const gpu_image& src, 21 | float sigma, float k, float tau, float precision=2 ); 22 | 23 | gpu_image gpu_gradient_dog( const gpu_image& src, const gpu_image& tfab, 24 | float sigma, float k, float tau, float precision=2 ); 25 | 26 | gpu_image gpu_dog_threshold_tanh( const gpu_image& src, float epsilon, float phi ); 27 | gpu_image gpu_dog_threshold_smoothstep( const gpu_image& src, float epsilon, float phi ); 28 | gpu_image gpu_dog_colorize( const gpu_image& src ); 29 | -------------------------------------------------------------------------------- /util/libav_encoder.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2011 by Jan Eric Kyprianidis 3 | // 4 | // Permission to use, copy, modify, and/or distribute this software for any 5 | // purpose with or without fee is hereby granted, provided that the above 6 | // copyright notice and this permission notice appear in all copies. 7 | // 8 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | // 16 | #pragma once 17 | 18 | class libav_encoder { 19 | public: 20 | typedef unsigned char uint8_t; 21 | typedef long long int64_t; 22 | 23 | static libav_encoder* create( const char *path, unsigned width, unsigned height, 24 | const std::pair& frame_rate, 25 | int bit_rate = 8000000 ); 26 | ~libav_encoder(); 27 | 28 | bool append_frame ( const uint8_t *buffer ); 29 | void finish (); 30 | 31 | private: 32 | struct impl; 33 | impl *m; 34 | libav_encoder(impl*); 35 | }; 36 | -------------------------------------------------------------------------------- /gpu/gpu_binder.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | #ifdef __CUDACC__ 21 | 22 | template 23 | struct gpu_binder { 24 | texture& texture_ref; 25 | 26 | __host__ gpu_binder( texture& tf, const gpu_image& img, 27 | cudaTextureFilterMode filter_mode=cudaFilterModePoint ) 28 | : texture_ref(tf) 29 | { 30 | texture_ref.filterMode = filter_mode; 31 | GPU_SAFE_CALL(cudaBindTexture2D(0, texture_ref, img.ptr(), img.w(), img.h(), img.pitch())); 32 | } 33 | 34 | __host__ ~gpu_binder() { 35 | texture_ref.filterMode = cudaFilterModePoint; 36 | cudaUnbindTexture(texture_ref); 37 | } 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /util/settingscheck.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "settingscheck.h" 17 | #include "version.h" 18 | 19 | 20 | void settingsCheck() { 21 | QSettings settings; 22 | QString current = settings.value("version").toString(); 23 | if (current != PACKAGE_VERSION) { 24 | if (current.isEmpty() || 25 | QMessageBox::warning(NULL, "Warning", 26 | QString("Version of settings is invalid (\"%1\" != \"%2\"). " 27 | "Reset settings? (Yes, unless you know what you are doing!)").arg(current).arg(PACKAGE_VERSION), 28 | QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) 29 | { 30 | settings.remove(""); 31 | } 32 | settings.setValue("version", PACKAGE_VERSION); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "mainwindow.h" 17 | #include "fancystyle.h" 18 | #include "settingscheck.h" 19 | #include "cudadevicedialog.h" 20 | #include "logwindow.h" 21 | 22 | 23 | int main(int argc, char **argv) { 24 | LogWindow::install(); 25 | QApplication::setOrganizationDomain("jkyprian.hpi3d.de"); 26 | QApplication::setOrganizationName("jkyprian"); 27 | QApplication::setApplicationName("xdogref"); 28 | QApplication app(argc, argv); 29 | QApplication::setStyle(new FancyStyle); 30 | settingsCheck(); 31 | if (CudaDeviceDialog::select() < 0) return 1; 32 | 33 | MainWindow mw; 34 | mw.showNormal(); 35 | app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); 36 | int result = app.exec(); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /gpu/gpu_color.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_srgb2linear( const gpu_image& src); 21 | gpu_image gpu_linear2srgb( const gpu_image& src); 22 | 23 | gpu_image gpu_srgb2linear( const gpu_image& src); 24 | gpu_image gpu_linear2srgb( const gpu_image& src); 25 | 26 | gpu_image gpu_rgb2lab( const gpu_image& src); 27 | gpu_image gpu_lab2rgb( const gpu_image& src); 28 | gpu_image gpu_l2rgb( const gpu_image& src ); 29 | 30 | gpu_image gpu_gray2rgb( const gpu_image& src, bool saturate=true ); 31 | gpu_image gpu_rgb2gray( const gpu_image& src ); 32 | 33 | gpu_image gpu_swap_rgba( const gpu_image& src ); 34 | -------------------------------------------------------------------------------- /gpu/gpu_grad.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_grad_central_diff( const gpu_image& src, bool normalize ); 21 | gpu_image gpu_grad_scharr_for_axis( const gpu_image& src, int axis ); 22 | gpu_image gpu_grad_scharr( const gpu_image& src, bool normalize ); 23 | 24 | gpu_image gpu_grad_to_axis( const gpu_image& src, bool squared ); 25 | gpu_image gpu_grad_from_axis( const gpu_image& src, bool squared ); 26 | gpu_image gpu_grad_to_angle( const gpu_image& src ); 27 | gpu_image gpu_grad_to_lfm( const gpu_image& src ); 28 | 29 | gpu_image gpu_grad_sobel_mag( const gpu_image& src ); 30 | gpu_image gpu_grad_sobel_mag( const gpu_image& src ); 31 | -------------------------------------------------------------------------------- /gpu/gpu_noise.cu: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_noise.h" 17 | #include 18 | 19 | 20 | static int randi() { 21 | static bool first = true; 22 | if (first) { 23 | first = false; 24 | std::srand(clock()); 25 | } 26 | return std::rand(); 27 | } 28 | 29 | 30 | static float randf() { 31 | return (float)randi()/RAND_MAX; 32 | } 33 | 34 | 35 | gpu_image gpu_noise_random(unsigned w, unsigned h, float a, float b) { 36 | float *n = new float[w * h]; 37 | float *p = n; 38 | float da = b - a; 39 | for (unsigned j = 0; j < h; ++j) { 40 | for (unsigned i = 0; i < w; ++i) { 41 | *p++ = a + da * randf(); 42 | } 43 | } 44 | 45 | gpu_image dst(n, w, h); 46 | delete[] n; 47 | return dst; 48 | } 49 | -------------------------------------------------------------------------------- /gpu/gpu_plm2.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | template 19 | struct gpu_plm2 { 20 | T *ptr; 21 | unsigned stride; 22 | unsigned w; 23 | unsigned h; 24 | 25 | __host__ gpu_plm2() { 26 | ptr = 0; 27 | stride = w = h = 0; 28 | } 29 | 30 | __host__ gpu_plm2(T *ptr, unsigned pitch, unsigned w, unsigned h) { 31 | this->ptr = ptr; 32 | this->stride = pitch / sizeof(T); 33 | this->w = w; 34 | this->h = h; 35 | } 36 | 37 | #ifdef __CUDACC__ 38 | 39 | inline __device__ T& operator()(int x, int y) { 40 | return ptr[y * stride + x]; 41 | } 42 | 43 | inline __device__ const T& operator()(int x, int y) const { 44 | return ptr[y * stride + x]; 45 | } 46 | 47 | #endif 48 | }; 49 | -------------------------------------------------------------------------------- /gpu/gpu_oabf.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_oabf_1d( const gpu_image& src, const gpu_image& lfm, 21 | float sigma_d, float sigma_r, bool tangential, float precision=2 ); 22 | 23 | gpu_image gpu_oabf_1d( const gpu_image& src, const gpu_image& lfm, 24 | float sigma_d, float sigma_r, bool tangential, float precision=2 ); 25 | 26 | gpu_image gpu_oabf( const gpu_image& src, const gpu_image& lfm, 27 | float sigma_d, float sigma_r, float precision=2); 28 | 29 | gpu_image gpu_oabf( const gpu_image& src, const gpu_image& lfm, 30 | float sigma_d, float sigma_r, float precision=2 ); 31 | -------------------------------------------------------------------------------- /util/imageutil.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | cpu_image cpu_image_from_qimage(const QImage& image); 21 | 22 | QImage cpu_data_to_qimage(const cpu_image_data *data); 23 | template 24 | inline QImage cpu_image_to_qimage(const cpu_image& image) { 25 | return cpu_data_to_qimage(image.data()); 26 | } 27 | 28 | template gpu_image gpu_image_from_qimage(const QImage& image); 29 | template <> gpu_image gpu_image_from_qimage(const QImage& image); 30 | template <> gpu_image gpu_image_from_qimage(const QImage& image); 31 | 32 | QImage gpu_image_to_qimage(const gpu_image& image); 33 | QImage gpu_image_to_qimage(const gpu_image& image); 34 | QImage gpu_image_to_qimage(const gpu_image& image); 35 | QImage gpu_image_to_qimage(const gpu_image& image); 36 | -------------------------------------------------------------------------------- /util/fancystyle.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | class FancyStyle : public QPlastiqueStyle { 19 | public: 20 | QSize sizeFromContents( ContentsType type, const QStyleOption *option, 21 | const QSize &size, const QWidget *widget ) const; 22 | 23 | void drawPrimitive( PrimitiveElement element, const QStyleOption *option, 24 | QPainter *painter, const QWidget *widget = 0 ) const; 25 | 26 | void drawControl( ControlElement element, const QStyleOption *option, 27 | QPainter *painter, const QWidget *widget) const; 28 | 29 | int styleHint( StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, 30 | QStyleHintReturn *returnData = 0 ) const; 31 | 32 | void polish(QApplication *application); 33 | void polish(QWidget *widget); 34 | QPalette standardPalette() const; 35 | }; 36 | -------------------------------------------------------------------------------- /gpu/gpu_error.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_error.h" 17 | #ifdef WIN32 18 | #include 19 | #include 20 | #else 21 | #include 22 | #include 23 | #endif 24 | 25 | 26 | void gpu_error_msg(cudaError_t err, const char *file, size_t line) { 27 | #ifdef WIN32 28 | if (!IsDebuggerPresent()) { 29 | std::ostringstream oss; 30 | oss << cudaGetErrorString(err) << "\n" 31 | << file << "(" << line << ")"; 32 | MessageBoxA(NULL, oss.str().c_str(), "CUDA Error", MB_OK | MB_ICONERROR); 33 | } else { 34 | OutputDebugStringA("CUDA Error: "); 35 | OutputDebugStringA(cudaGetErrorString(err)); 36 | OutputDebugStringA("\n"); 37 | DebugBreak(); 38 | } 39 | #else 40 | fprintf(stderr, "%s(%d): CUDA Error\n", file, (int)line); 41 | fprintf(stderr, "%s\n", cudaGetErrorString(err)); 42 | #endif 43 | exit(1); 44 | } 45 | -------------------------------------------------------------------------------- /gpu/gpu_blend.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis and Daniel Müller 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | enum gpu_blend_mode { 21 | GPU_BLEND_NORMAL, 22 | GPU_BLEND_MULTIPLY, 23 | GPU_BLEND_SCREEN, 24 | GPU_BLEND_HARD_LIGHT, 25 | GPU_BLEND_SOFT_LIGHT, 26 | GPU_BLEND_OVERLAY, 27 | GPU_BLEND_LINEAR_BURN, 28 | GPU_BLEND_DIFFERENCE, 29 | GPU_BLEND_LINEAR_DODGE 30 | }; 31 | 32 | gpu_image gpu_blend( const gpu_image& back, const gpu_image& src, 33 | gpu_blend_mode mode ); 34 | 35 | gpu_image gpu_blend( const gpu_image& back, const gpu_image& src, 36 | gpu_blend_mode mode ); 37 | 38 | 39 | //gpu_image gpu_blend_intensity( const gpu_image& back, const gpu_image& src, 40 | // gpu_blend_mode mode, float color = 1 ); 41 | 42 | gpu_image gpu_blend_intensity( const gpu_image& back, const gpu_image& src, 43 | gpu_blend_mode mode, float4 color = make_float4(1)); 44 | -------------------------------------------------------------------------------- /cmake/SetupCPack.cmake: -------------------------------------------------------------------------------- 1 | SET(CPACK_PACKAGE_VERSION_MAJOR "0") 2 | SET(CPACK_PACKAGE_VERSION_MINOR "0") 3 | SET(CPACK_PACKAGE_VERSION_PATCH "0") 4 | IF(APPLE) 5 | SET(CPACK_GENERATOR "DragNDrop") 6 | ELSE() 7 | SET(CPACK_GENERATOR "ZIP") 8 | ENDIF() 9 | set(CPACK_SOURCE_GENERATOR ZIP) 10 | 11 | IF(EXISTS ${PROJECT_SOURCE_DIR}/.git) 12 | FIND_PROGRAM(git_PROG NAMES git git.cmd) 13 | MARK_AS_ADVANCED(git_PROG) 14 | IF(git_PROG) 15 | EXECUTE_PROCESS( 16 | COMMAND ${git_PROG} describe --long 17 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 18 | OUTPUT_VARIABLE git_OUTPUT 19 | RESULT_VARIABLE git_RESULT) 20 | IF(${git_RESULT} EQUAL 0) 21 | STRING(REGEX REPLACE "v([0-9])+.[0-9]+-[0-9]+-g[0-9a-f]+.*" "\\1" CPACK_PACKAGE_VERSION_MAJOR "${git_OUTPUT}") 22 | STRING(REGEX REPLACE "v[0-9]+.([0-9])+-[0-9]+-g[0-9a-f]+.*" "\\1" CPACK_PACKAGE_VERSION_MINOR "${git_OUTPUT}") 23 | STRING(REGEX REPLACE "v[0-9]+.[0-9]+-([0-9]+-g[0-9a-f]+).*" "\\1" CPACK_PACKAGE_VERSION_PATCH "${git_OUTPUT}") 24 | ELSE() 25 | MESSAGE(WARNING ${git_OUTPUT}) 26 | ENDIF() 27 | ENDIF() 28 | ENDIF() 29 | 30 | SET(CPACK_PACKAGE_VERSION "v${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}-${CPACK_PACKAGE_VERSION_PATCH}") 31 | MESSAGE(STATUS "VERSION: ${CPACK_PACKAGE_VERSION}") 32 | 33 | SET(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}) 34 | IF(${CPACK_SYSTEM_NAME} MATCHES Windows) 35 | IF(CMAKE_CL_64) 36 | SET(CPACK_SYSTEM_NAME win64) 37 | ELSE() 38 | SET(CPACK_SYSTEM_NAME win32) 39 | ENDIF() 40 | ENDIF() 41 | IF(${CPACK_SYSTEM_NAME} MATCHES Darwin) 42 | SET(CPACK_SYSTEM_NAME mac) 43 | ENDIF() 44 | 45 | SET(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}) 46 | SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-src") 47 | SET(CPACK_SOURCE_IGNORE_FILES "/build/;/.git/") 48 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET( QT_USE_QTMAIN 1 ) 2 | INCLUDE( ${QT_USE_FILE} ) 3 | 4 | INCLUDE_DIRECTORIES( 5 | ${CMAKE_CURRENT_SOURCE_DIR} 6 | ${CMAKE_CURRENT_BINARY_DIR} 7 | ${PROJECT_SOURCE_DIR} 8 | ${PROJECT_SOURCE_DIR}/gpu 9 | ${PROJECT_SOURCE_DIR}/util 10 | ${PROJECT_BINARY_DIR} ) 11 | 12 | FILE(GLOB_RECURSE sources *.cpp *.h *.ui *.qrc) 13 | IF(WIN32) 14 | SET( sources ${sources} xdog-demo.rc ) 15 | ENDIF() 16 | IF(APPLE) 17 | SET( sources ${sources} xdog-demo.icns ) 18 | SET_SOURCE_FILES_PROPERTIES( xdog-demo.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources ) 19 | ENDIF() 20 | 21 | QT4_AUTO_WRAP( sources ${sources} ) 22 | CUDA_ADD_EXECUTABLE( xdog-demo WIN32 MACOSX_BUNDLE ${sources} ) 23 | 24 | SOURCE_GROUP( src REGULAR_EXPRESSION "c$|cpp$|hpp$|h$|ui$|qrc$|cu$" ) 25 | SOURCE_GROUP( generated REGULAR_EXPRESSION "cxx$|ui_" ) 26 | 27 | IF(MSVC) 28 | IF(MSVC_IDE) 29 | SET_TARGET_PROPERTIES( xdog-demo PROPERTIES COMPILE_FLAGS "/FIstable.h /Yustable.h" ) 30 | SET_SOURCE_FILES_PROPERTIES( stable.cpp PROPERTIES COMPILE_FLAGS "/Ycstable.h" ) 31 | ELSE() 32 | SET_TARGET_PROPERTIES( xdog-demo PROPERTIES COMPILE_FLAGS "/FIstable.h" ) 33 | ENDIF() 34 | ELSE() 35 | SET_TARGET_PROPERTIES( xdog-demo PROPERTIES COMPILE_FLAGS "-include stable.h" ) 36 | ENDIF() 37 | 38 | IF(APPLE) 39 | SET_TARGET_PROPERTIES( xdog-demo PROPERTIES MACOSX_BUNDLE_ICON_FILE "xdog-demo.icns" ) 40 | ENDIF() 41 | 42 | TARGET_LINK_LIBRARIES( xdog-demo 43 | util gpu 44 | ${QT_LIBRARIES}) 45 | 46 | IF(LIBAV_FOUND) 47 | TARGET_LINK_LIBRARIES( xdog-demo ${LIBAV_LIBRARIES} ) 48 | IF(MSVC) 49 | SET_TARGET_PROPERTIES( xdog-demo PROPERTIES LINK_FLAGS "/OPT:NOREF" ) 50 | ENDIF() 51 | ENDIF() 52 | 53 | INSTALL( TARGETS xdog-demo 54 | BUNDLE DESTINATION . 55 | RUNTIME DESTINATION . 56 | CONFIGURATIONS Debug Release ) 57 | 58 | DEPLOY_QT_CUDA(xdog-demo) 59 | -------------------------------------------------------------------------------- /util/cudadevicedialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | CudaDeviceDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 700 10 | 550 11 | 12 | 13 | 14 | 15 | 700 16 | 550 17 | 18 | 19 | 20 | Select CUDA Device 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | Qt::Horizontal 33 | 34 | 35 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | buttonBox 45 | accepted() 46 | CudaDeviceDialog 47 | accept() 48 | 49 | 50 | 248 51 | 254 52 | 53 | 54 | 157 55 | 274 56 | 57 | 58 | 59 | 60 | buttonBox 61 | rejected() 62 | CudaDeviceDialog 63 | reject() 64 | 65 | 66 | 316 67 | 260 68 | 69 | 70 | 286 71 | 274 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /util/rolloutbox.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | class RolloutBox : public QFrame { 19 | Q_OBJECT 20 | public: 21 | RolloutBox(QWidget *parent); 22 | 23 | void saveSettings(QSettings& settings); 24 | void restoreSettings(QSettings& settings); 25 | 26 | void setFrame(bool frame); 27 | QString title() const { return m_toolButton->text(); } 28 | void setTitle(const QString &title); 29 | bool isCheckable() const { return m_checkable; } 30 | void setCheckable(bool checkable); 31 | bool isChecked() const { return m_checked; } 32 | bool isExpanded() const { return m_expanded; } 33 | 34 | QWidgetList widgets() const; 35 | void addWidget(QWidget *w); 36 | void addWidget(QWidget *left, QWidget *right); 37 | 38 | public slots: 39 | void setChecked(bool checked); 40 | void setExpanded(bool expanded); 41 | void toggle(); 42 | 43 | signals: 44 | void checkChanged(bool checked = false); 45 | void toggled(bool); 46 | 47 | private: 48 | QGridLayout *m_layout; 49 | QToolButton *m_toolButton; 50 | QCheckBox *m_checkBox; 51 | bool m_checkable; 52 | bool m_checked; 53 | bool m_expanded; 54 | 55 | public: 56 | static void restoreSettings(QSettings& settings, QObject *obj); 57 | static void saveSettings(QSettings& settings, QObject *obj); 58 | }; 59 | 60 | -------------------------------------------------------------------------------- /util/videocontrols.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | class VideoControls : public QFrame { 19 | Q_OBJECT 20 | public: 21 | VideoControls(QWidget *parent); 22 | virtual ~VideoControls(); 23 | 24 | void setAutoHide(bool hide); 25 | bool autoHide() const { return m_autoHide; } 26 | bool isPlaying() const { return m_isPlaying; } 27 | bool isTracking() const { return m_isTracking; } 28 | 29 | public slots: 30 | void setFrameCount(int nframes); 31 | void setCurrentFrame(int frame); 32 | void setPlayback(bool playing); 33 | void play(); 34 | void pause(); 35 | void toogle(); 36 | 37 | signals: 38 | void stepForward(); 39 | void stepBack(); 40 | void currentFrameChanged(int frame); 41 | void currentFrameTracked(int frame); 42 | void playbackChanged(bool playing); 43 | void playbackStarted(); 44 | void playbackPaused(); 45 | void trackingChanged(bool tracking); 46 | void trackingStarted(); 47 | void trackingStopped(); 48 | 49 | protected slots: 50 | void handleSliderPressed(); 51 | void handleSliderReleased(); 52 | 53 | protected: 54 | QHBoxLayout *m_hbox; 55 | bool m_autoHide; 56 | bool m_isPlaying; 57 | bool m_isTracking; 58 | QToolButton *m_prevButton; 59 | QToolButton *m_playButton; 60 | QToolButton *m_nextButton; 61 | QSlider *m_frameSlider; 62 | QSpinBox *m_frameEdit; 63 | }; 64 | -------------------------------------------------------------------------------- /util/libav_decoder.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2011 by Jan Eric Kyprianidis 3 | // 4 | // Permission to use, copy, modify, and/or distribute this software for any 5 | // purpose with or without fee is hereby granted, provided that the above 6 | // copyright notice and this permission notice appear in all copies. 7 | // 8 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | // 16 | #pragma once 17 | 18 | class libav_decoder { 19 | public: 20 | typedef std::pair rational; 21 | typedef unsigned char uint8_t; 22 | typedef long long int64_t; 23 | 24 | static libav_decoder* open( const char *path ); 25 | ~libav_decoder(); 26 | 27 | bool next (); 28 | void rewind (); 29 | void set_time ( int64_t ts, bool exact=true ); 30 | void set_frame ( int frame, bool exact=true ); 31 | 32 | bool at_end () const; 33 | int width () const; 34 | int height () const; 35 | int64_t duration () const; 36 | int64_t start_time () const; 37 | int64_t end_time () const; 38 | int frame_count () const; 39 | rational frame_rate () const; 40 | rational time_base () const; 41 | uint8_t* buffer () const; 42 | int64_t current_time () const; 43 | int current_frame () const; 44 | double fps () const; 45 | int frame_from_time ( int64_t ts ) const; 46 | int64_t time_from_frame ( int frame ) const; 47 | int64_t ticks () const; 48 | int64_t ticks_from_time (int64_t t) const; 49 | int64_t time_from_ticks (int64_t x) const; 50 | 51 | private: 52 | struct impl; 53 | impl *m; 54 | libav_decoder(impl*); 55 | }; 56 | -------------------------------------------------------------------------------- /cmake/FindLibav.cmake: -------------------------------------------------------------------------------- 1 | # LIBAV_FOUND - system has Libav libraries 2 | # LIBAV_INCLUDE_DIR - the Libav include directory 3 | # LIBAV_LIBRARIES - link these to use Libav 4 | 5 | IF(WIN32) 6 | FIND_PATH( LIBAV_DIR include/libavformat/avformat.h PATH_SUFFIXES .. ) 7 | GET_FILENAME_COMPONENT(LIBAV_DIR ${LIBAV_DIR} ABSOLUTE ) 8 | SET(LIBAV_DIR ${LIBAV_DIR} CACHE FILEPATH "" FORCE) 9 | 10 | FIND_PATH( LIBAV_INCLUDE_DIR libavformat/avformat.h HINTS ${LIBAV_DIR}/include ) 11 | 12 | FIND_LIBRARY( LIBAV_avutil_LIBRARY avutil HINTS ${LIBAV_DIR}/lib ) 13 | FIND_LIBRARY( LIBAV_avcodec_LIBRARY avcodec HINTS ${LIBAV_DIR}/lib ) 14 | FIND_LIBRARY( LIBAV_avformat_LIBRARY avformat HINTS ${LIBAV_DIR}/lib ) 15 | FIND_LIBRARY( LIBAV_swscale_LIBRARY swscale HINTS ${LIBAV_DIR}/lib ) 16 | 17 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBAV DEFAULT_MSG 18 | LIBAV_INCLUDE_DIR 19 | LIBAV_avutil_LIBRARY 20 | LIBAV_avcodec_LIBRARY 21 | LIBAV_avformat_LIBRARY 22 | LIBAV_swscale_LIBRARY ) 23 | 24 | IF(LIBAV_FOUND) 25 | SET(LIBAV_LIBRARIES 26 | ${LIBAV_avcodec_LIBRARY} 27 | ${LIBAV_avformat_LIBRARY} 28 | ${LIBAV_avutil_LIBRARY} 29 | ${LIBAV_swscale_LIBRARY} ) 30 | ENDIF() 31 | ELSE() 32 | INCLUDE(FindPkgConfig) 33 | PKG_CHECK_MODULES( LIBAV_PKGCONF QUIET libavutil libavcodec libavformat libswscale ) 34 | 35 | FIND_PATH(LIBAV_INCLUDE_DIR libavformat/avformat.h HINTS ${LIBAV_PKGCONG_INCLUDE_DIRS}) 36 | 37 | FIND_LIBRARY( LIBAV_avutil_LIBRARY avutil HINTS ${LIBAV_PKGCONF_LIBRARY_DIRS} ) 38 | FIND_LIBRARY( LIBAV_avcodec_LIBRARY avcodec HINTS ${LIBAV_PKGCONF_LIBRARY_DIRS} ) 39 | FIND_LIBRARY( LIBAV_avformat_LIBRARY avformat HINTS ${LIBAV_PKGCONF_LIBRARY_DIRS} ) 40 | FIND_LIBRARY( LIBAV_swscale_LIBRARY swscale HINTS ${LIBAV_PKGCONF_LIBRARY_DIRS} ) 41 | 42 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBAV DEFAULT_MSG 43 | LIBAV_INCLUDE_DIR 44 | LIBAV_avcodec_LIBRARY 45 | LIBAV_avformat_LIBRARY 46 | LIBAV_avutil_LIBRARY 47 | LIBAV_swscale_LIBRARY ) 48 | 49 | IF(LIBAV_FOUND) 50 | SET(LIBAV_LIBRARIES 51 | ${LIBAV_avcodec_LIBRARY} 52 | ${LIBAV_avformat_LIBRARY} 53 | ${LIBAV_avutil_LIBRARY} 54 | ${LIBAV_swscale_LIBRARY} 55 | ${LIBAV_PKGCONF_LDFLAGS_OTHER} ) 56 | ENDIF() 57 | ENDIF() 58 | 59 | -------------------------------------------------------------------------------- /gpu/gpu_wog.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_wog_dog( const gpu_image& src, float sigma_e, float sigma_r, 21 | float tau, float phi_e, float epsilon = 0, float precision = 2 ); 22 | 23 | gpu_image gpu_wog_luminance_quant( const gpu_image& src, int nbins, float phi_q ); 24 | gpu_image gpu_wog_luminance_quant( const gpu_image& src, int nbins, 25 | float lambda_delta, float omega_delta, 26 | float lambda_phi, float omega_phi ); 27 | 28 | gpu_image gpu_wog_warp(const gpu_image& src, gpu_image& edges, float phi_w); 29 | gpu_image gpu_wog_warp_sharp( const gpu_image& src, float sigma_w, float precision_w, float phi_w); 30 | 31 | gpu_image gpu_wog_abstraction( const gpu_image& src, int n_e = 1, int n_a = 4, 32 | float sigma_d = 3, float sigma_r = 4.25f, 33 | float sigma_e1 = 1, float sigma_e2 = 1.6f, float precision_e = 2, 34 | float tau = 0.99f, float phi_e = 2, float epsilon=0, 35 | bool adaptive_quant = true, 36 | int nbins = 8, float phi_q = 2, 37 | float lambda_delta = 0, float omega_delta = 2, 38 | float lambda_phi = 0.9f, float omega_phi = 1.6f, 39 | bool warp_sharp = true, float sigma_w = 1.5f, 40 | float precision_w = 2, float phi_w = 2.7 ); 41 | -------------------------------------------------------------------------------- /gpu/gpu_sampler.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | #ifdef __CUDACC__ 21 | 22 | template& texture_ref()> 23 | struct gpu_sampler { 24 | __host__ gpu_sampler(const gpu_image& img, cudaTextureFilterMode filter_mode=cudaFilterModePoint) { 25 | texture_ref().filterMode = filter_mode; 26 | GPU_SAFE_CALL(cudaBindTexture2D(0, texture_ref(), img.ptr(), img.w(), img.h(), img.pitch())); 27 | } 28 | 29 | __host__ ~gpu_sampler() { 30 | texture_ref().filterMode = cudaFilterModePoint; 31 | cudaUnbindTexture(texture_ref()); 32 | } 33 | 34 | __device__ T operator()(float x, float y) const { 35 | return tex2D(texture_ref(), x, y); 36 | } 37 | }; 38 | 39 | 40 | template& texture_ref()> 41 | struct gpu_resampler { 42 | float2 s_; 43 | 44 | __host__ gpu_resampler(const gpu_image& img, float2 s, cudaTextureFilterMode filter_mode=cudaFilterModePoint) { 45 | s_ = s; 46 | texture_ref().filterMode = filter_mode; 47 | GPU_SAFE_CALL(cudaBindTexture2D(0, texture_ref(), img.ptr(), img.w(), img.h(), img.pitch())); 48 | } 49 | 50 | __host__ ~gpu_resampler() { 51 | texture_ref().filterMode = cudaFilterModePoint; 52 | cudaUnbindTexture(texture_ref()); 53 | } 54 | 55 | __device__ T operator()(float x, float y) const { 56 | return tex2D(texture_ref(), s_.x * x, s_.x * y); 57 | } 58 | }; 59 | 60 | 61 | template 62 | struct gpu_constant_sampler { 63 | T value; 64 | 65 | gpu_constant_sampler(T v) : value(v) { } 66 | 67 | __host__ __device__ T operator()(float ix, float iy) const { 68 | return value; 69 | } 70 | }; 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /gpu/gpu_stgauss2.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_stgauss2.h" 17 | #include "gpu_st.h" 18 | #include "cpu_sampler.h" 19 | #include 20 | 21 | 22 | struct stgauss2_path { 23 | __host__ stgauss2_path(std::deque& dst, float sigma, float precision ) 24 | : dst_(dst) 25 | { 26 | radius_ = precision * sigma; 27 | } 28 | 29 | __host__ float radius() const { 30 | return radius_; 31 | } 32 | 33 | __host__ void operator()(float sign, float u, float2 p) { 34 | if (sign < 0) 35 | dst_.push_front(make_float3(p.x, p.y, sign*u)); 36 | else 37 | dst_.push_back(make_float3(p.x, p.y, sign*u)); 38 | } 39 | 40 | std::deque& dst_; 41 | float radius_; 42 | }; 43 | 44 | 45 | std::vector gpu_stgauss2_path( int ix, int iy, const cpu_image& st, float sigma, float max_angle, 46 | bool adaptive, bool st_linear, int order, float step_size, 47 | float precision ) 48 | { 49 | cpu_sampler st_sampler(st, st_linear? cudaFilterModeLinear : cudaFilterModePoint); 50 | float2 p0 = make_float2(ix + 0.5f, iy + 0.5f); 51 | if (adaptive) { 52 | float A = st2A(st(p0.x, p0.y)); 53 | sigma *= 0.25f * (1 + A)*(1 + A); 54 | } 55 | std::deque C; 56 | float cos_max = cosf(radians(max_angle)); 57 | stgauss2_path f(C, sigma, precision); 58 | if (order == 1) st_integrate_euler(p0, st_sampler, f, cos_max, st.w(), st.h(), step_size); 59 | if (order == 2) st_integrate_rk2(p0, st_sampler, f, cos_max, st.w(), st.h(), step_size); 60 | if (order == 4) st_integrate_rk4(p0, st_sampler, f, cos_max, st.w(), st.h(), step_size); 61 | 62 | return std::vector(C.begin(), C.end()); 63 | } 64 | -------------------------------------------------------------------------------- /gpu/gpu_cache.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_cache.h" 17 | #include "cuda_runtime.h" 18 | #ifdef _MSC_VER 19 | #include 20 | #else 21 | #include 22 | #endif 23 | 24 | 25 | struct entry_t { 26 | void *ptr; 27 | unsigned pitch; 28 | unsigned w; 29 | unsigned h; 30 | }; 31 | 32 | typedef std::tr1::unordered_multimap cache_map; 33 | static cache_map g_cache; 34 | static size_t g_cache_size = 0; 35 | static size_t g_total_size = 0; 36 | 37 | 38 | void gpu_cache_alloc( void **ptr, unsigned *pitch, unsigned w, unsigned h ) { 39 | unsigned long long key = ((unsigned long long)h << 32) | (unsigned long long)w; 40 | cache_map::iterator i = g_cache.find(key); 41 | if (i != g_cache.end()) { 42 | *ptr = i->second.ptr; 43 | *pitch = i->second.pitch; 44 | g_cache.erase(i); 45 | g_cache_size -= *pitch * h; 46 | } else { 47 | size_t tmp; 48 | cudaMallocPitch(ptr, &tmp, w, h); 49 | *pitch = (unsigned)tmp; 50 | g_total_size += *pitch * h; 51 | } 52 | } 53 | 54 | 55 | void gpu_cache_free( void *ptr, unsigned pitch, unsigned w, unsigned h ) { 56 | entry_t e = { ptr, pitch, w, h }; 57 | unsigned long long key = ((unsigned long long)h << 32) | (unsigned long long)w; 58 | g_cache.insert(cache_map::value_type(key, e)); 59 | g_cache_size += pitch * h; 60 | } 61 | 62 | 63 | void gpu_cache_clear() { 64 | cache_map::iterator i; 65 | for (i = g_cache.begin(); i != g_cache.end(); ++i) { 66 | g_total_size -= i->second.pitch * i->second.h; 67 | cudaFree(i->second.ptr); 68 | } 69 | g_cache.clear(); 70 | g_cache_size = 0; 71 | } 72 | 73 | 74 | size_t gpu_cache_size() { 75 | return g_cache_size; 76 | } 77 | 78 | 79 | size_t gpu_cache_total() { 80 | return g_total_size; 81 | } 82 | -------------------------------------------------------------------------------- /util/videoplayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | class VideoPlayer : public QObject { 19 | Q_OBJECT 20 | public: 21 | VideoPlayer( QObject *parent, const QString& filename=QString::null, 22 | int cacheRadius=0, int cacheMin=32, int cacheMax=128 ); 23 | virtual ~VideoPlayer(); 24 | 25 | void saveSettings(QSettings& settings); 26 | void restoreSettings(QSettings& settings); 27 | 28 | bool open(const QString& path); 29 | void record(QObject *r); 30 | 31 | const QString& filename() const; 32 | bool isValid() const; 33 | bool isBusy() const; 34 | QSize size() const; 35 | int width() const; 36 | int height() const; 37 | int frameCount() const; 38 | double fps() const; 39 | QPair frameRate() const; 40 | QPair timeBase() const; 41 | int currentFrame() const; 42 | QImage image(int index=0) const; 43 | qint64 time(int index=0) const; 44 | bool isPlaying() const; 45 | 46 | QList slaves() const; 47 | VideoPlayer* slave(int index) const; 48 | 49 | public slots: 50 | void open(); 51 | void close(); 52 | void rewind(); 53 | void stepForward(); 54 | void stepBack(); 55 | void setCurrentFrame(int frame); 56 | void setPlayback(bool playing); 57 | void play(); 58 | void pause(); 59 | void toggle(); 60 | void setOutput(const QImage& image); 61 | void record(); 62 | 63 | signals: 64 | void videoChanged(const QSize& size); 65 | void videoChanged(int nframes); 66 | void currentFrameChanged(int frame); 67 | void currentFrameChanged(const QImage& image); 68 | void playbackChanged(bool playing); 69 | void playbackStarted(); 70 | void playbackPaused(); 71 | void outputChanged(const QImage& image); 72 | 73 | protected: 74 | void customEvent(QEvent *e); 75 | void timerEvent(QTimerEvent *e); 76 | 77 | QString m_filename; 78 | QBasicTimer m_timer; 79 | qint64 m_ticks; 80 | int m_currentFrame; 81 | QImage m_image; 82 | QImage m_output; 83 | class Thread; 84 | Thread *m_thread; 85 | int m_cacheRadius; 86 | int m_cacheMin; 87 | int m_cacheMax; 88 | }; 89 | -------------------------------------------------------------------------------- /gpu/gpu_convert.cu: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_convert.h" 17 | 18 | 19 | __global__ void imp_8u_to_32f( const gpu_plm2 src, gpu_plm2 dst ) { 20 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 21 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 22 | if (ix >= dst.w || iy >= dst.h) 23 | return; 24 | 25 | unsigned char c = src(ix, iy); 26 | dst(ix, iy) = c / 255.0f; 27 | } 28 | 29 | 30 | __global__ void imp_8u_to_32f( const gpu_plm2 src, gpu_plm2 dst ) { 31 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 32 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 33 | if (ix >= dst.w || iy >= dst.h) 34 | return; 35 | 36 | uchar4 c = src(ix, iy); 37 | dst(ix, iy) = make_float4(c.x / 255.0f, c.y / 255.0f, c.z / 255.0f, c.w / 255.0f); 38 | } 39 | 40 | 41 | __global__ void imp_32f_to_8u( const gpu_plm2 src, gpu_plm2 dst) { 42 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 43 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 44 | if (ix >= dst.w || iy >= dst.h) 45 | return; 46 | 47 | float c = clamp(src(ix, iy), 0.0f, 1.0f); 48 | dst(ix, iy) = (unsigned char)(255.0f *c); 49 | } 50 | 51 | 52 | __global__ void imp_32f_to_8u( const gpu_plm2 src, gpu_plm2 dst ) { 53 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 54 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 55 | if (ix >= dst.w || iy >= dst.h) 56 | return; 57 | 58 | float4 c = clamp(src(ix, iy), 0, 1); 59 | dst(ix, iy) = make_uchar4((int)(255.0f *c.x), (int)(255.0f *c.y), (int)(255.0f *c.z), (int)(255.0f *c.w)); 60 | } 61 | 62 | 63 | gpu_image gpu_8u_to_32f( const gpu_image& src ) { 64 | gpu_image dst(src.size()); 65 | imp_8u_to_32f<<>>(src, dst); 66 | GPU_CHECK_ERROR(); 67 | return dst; 68 | } 69 | 70 | 71 | gpu_image gpu_8u_to_32f( const gpu_image& src ) { 72 | gpu_image dst(src.size()); 73 | GPU_CHECK_ERROR(); 74 | imp_8u_to_32f<<>>(src, dst); 75 | GPU_CHECK_ERROR(); 76 | return dst; 77 | } 78 | 79 | 80 | gpu_image gpu_32f_to_8u( const gpu_image& src ) { 81 | gpu_image dst(src.size()); 82 | imp_32f_to_8u<<>>(src, dst); 83 | GPU_CHECK_ERROR(); 84 | return dst; 85 | } 86 | 87 | 88 | gpu_image gpu_32f_to_8u( const gpu_image& src ) { 89 | gpu_image dst(src.size()); 90 | imp_32f_to_8u<<>>(src, dst); 91 | GPU_CHECK_ERROR(); 92 | return dst; 93 | } 94 | -------------------------------------------------------------------------------- /util/paramui.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "rolloutbox.h" 19 | 20 | class AbstractParam; 21 | 22 | class ParamUI : public RolloutBox { 23 | Q_OBJECT 24 | public: 25 | ParamUI(QWidget *parent, QObject *object); 26 | 27 | protected: 28 | void addObjectParameters(QObject *obj); 29 | QPointer m_object; 30 | }; 31 | 32 | 33 | class ParamLabel : public QLabel { 34 | Q_OBJECT 35 | public: 36 | ParamLabel(QWidget *parent, AbstractParam *param); 37 | 38 | protected: 39 | void mouseDoubleClickEvent(QMouseEvent * e); 40 | QPointer m_param; 41 | }; 42 | 43 | 44 | class ParamCheckBox : public QCheckBox { 45 | Q_OBJECT 46 | public: 47 | ParamCheckBox(QWidget *parent, AbstractParam *param); 48 | virtual bool event(QEvent *e); 49 | 50 | protected: 51 | QPointer m_param; 52 | }; 53 | 54 | 55 | class ParamSpinBox : public QSpinBox { 56 | Q_OBJECT 57 | public: 58 | ParamSpinBox(QWidget *parent, AbstractParam *param); 59 | 60 | protected: 61 | QPointer m_param; 62 | }; 63 | 64 | 65 | class ParamDoubleSpinBox : public QDoubleSpinBox { 66 | Q_OBJECT 67 | public: 68 | ParamDoubleSpinBox(QWidget *parent, AbstractParam *param); 69 | 70 | protected: 71 | QPointer m_param; 72 | }; 73 | 74 | 75 | class ParamComboBox : public QComboBox { 76 | Q_OBJECT 77 | public: 78 | ParamComboBox(QWidget *parent, AbstractParam *param); 79 | 80 | protected slots: 81 | void setValue(const QVariant& value); 82 | void updateParam(int index); 83 | 84 | protected: 85 | QPointer m_param; 86 | }; 87 | 88 | 89 | class ParamLineEdit : public QLineEdit { 90 | Q_OBJECT 91 | public: 92 | ParamLineEdit(QWidget *parent, AbstractParam *param); 93 | 94 | protected slots: 95 | void updateParam(); 96 | 97 | protected: 98 | QPointer m_param; 99 | }; 100 | 101 | 102 | class ParamTextEdit : public QToolButton { 103 | Q_OBJECT 104 | public: 105 | ParamTextEdit(QWidget *parent, AbstractParam *param); 106 | 107 | protected slots: 108 | void edit(); 109 | 110 | protected: 111 | QPointer m_param; 112 | }; 113 | 114 | 115 | class ParamImageSelect : public QWidget { 116 | Q_OBJECT 117 | public: 118 | ParamImageSelect(QWidget *parent, AbstractParam *param); 119 | 120 | protected slots: 121 | void setImage(const QImage& image); 122 | void clear(); 123 | void edit(); 124 | 125 | protected: 126 | QPointer m_param; 127 | QString m_filename; 128 | QImage m_image; 129 | QLabel *m_label; 130 | QToolButton *m_edit; 131 | QToolButton *m_clear; 132 | }; 133 | -------------------------------------------------------------------------------- /gpu/gpu_image.cu: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_image.h" 17 | 18 | 19 | template 20 | __global__ void imp_set( gpu_plm2 dst, T value) { 21 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 22 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 23 | if (ix >= dst.w || iy >= dst.h) 24 | return; 25 | 26 | dst(ix, iy) = value; 27 | } 28 | 29 | 30 | gpu_image gpu_set( float value, unsigned w, unsigned h ) { 31 | gpu_image dst(w,h); 32 | imp_set<<>>( dst, value ); 33 | GPU_CHECK_ERROR(); 34 | return dst; 35 | } 36 | 37 | 38 | gpu_image gpu_set( float4 value, unsigned w, unsigned h ) { 39 | gpu_image dst(w,h); 40 | imp_set<<>>( dst, value ); 41 | GPU_CHECK_ERROR(); 42 | return dst; 43 | } 44 | 45 | 46 | template 47 | __global__ void imp_add( gpu_plm2 dst, const gpu_plm2 src0, const gpu_plm2 src1) { 48 | const unsigned ix = blockDim.x * blockIdx.x + threadIdx.x; 49 | const unsigned iy = blockDim.y * blockIdx.y + threadIdx.y; 50 | if (ix >= dst.w || iy >= dst.h) 51 | return; 52 | 53 | dst(ix,iy) = src0(ix,iy) + src1(ix,iy); 54 | } 55 | 56 | 57 | gpu_image gpu_add( const gpu_image& src0, const gpu_image& src1 ) { 58 | assert(src0.size() == src1.size()); 59 | gpu_image dst(src0.size()); 60 | imp_add<<>>(dst, src0, src1); 61 | GPU_CHECK_ERROR(); 62 | return dst; 63 | } 64 | 65 | 66 | gpu_image gpu_add( const gpu_image& src0, const gpu_image& src1 ) { 67 | assert(src0.size() == src1.size()); 68 | gpu_image dst(src0.size()); 69 | imp_add<<>>(dst, src0, src1); 70 | GPU_CHECK_ERROR(); 71 | return dst; 72 | } 73 | 74 | 75 | template 76 | __global__ void imp_mul( const gpu_plm2 src, gpu_plm2 dst, float value) { 77 | const unsigned ix = blockDim.x * blockIdx.x + threadIdx.x; 78 | const unsigned iy = blockDim.y * blockIdx.y + threadIdx.y; 79 | if (ix >= dst.w || iy >= dst.h) 80 | return; 81 | 82 | T c = src(ix,iy); 83 | dst(ix,iy) = c * value; 84 | } 85 | 86 | 87 | gpu_image gpu_mul( const gpu_image& src, float value ) { 88 | gpu_image dst(src.size()); 89 | imp_mul<<>>(src, dst, value); 90 | GPU_CHECK_ERROR(); 91 | return dst; 92 | } 93 | 94 | 95 | gpu_image gpu_mul( const gpu_image& src, float value ) { 96 | gpu_image dst(src.size()); 97 | imp_mul<<>>(src, dst, value); 98 | GPU_CHECK_ERROR(); 99 | return dst; 100 | } 101 | 102 | -------------------------------------------------------------------------------- /src/mainwindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "ui_mainwindow.h" 19 | #include "imageview.h" 20 | #include "videoplayer.h" 21 | #include "cpu_image.h" 22 | #include "gpu_image.h" 23 | #include "param.h" 24 | #include "paramui.h" 25 | 26 | class MainWindow : public QMainWindow, protected Ui_MainWindow, public ImageView::Handler { 27 | Q_OBJECT 28 | public: 29 | MainWindow(); 30 | ~MainWindow(); 31 | 32 | void restoreAppState(); 33 | void saveAppState(); 34 | bool event(QEvent *event); 35 | 36 | const QImage& image() const { return m_result[m_select->currentIndex()]; } 37 | 38 | protected slots: 39 | void on_actionOpen_triggered(); 40 | void on_actionAbout_triggered(); 41 | void on_actionSelectDevice_triggered(); 42 | void on_actionRecord_triggered(); 43 | void on_actionSavePNG_triggered(); 44 | void on_actionLoadSettings_triggered(); 45 | void on_actionSaveSettings_triggered(); 46 | void on_actionShowSettings_triggered(); 47 | 48 | void setDirty(); 49 | void process(); 50 | 51 | void onIndexChanged(int); 52 | void onVideoChanged(int nframes); 53 | 54 | signals: 55 | void imageChanged(const QImage&); 56 | 57 | protected: 58 | VideoPlayer *m_player; 59 | ParamUI *m_paramui; 60 | cpu_image m_st; 61 | cpu_image m_tfm; 62 | gpu_image m_noise; 63 | QImage m_result[3]; 64 | bool m_dirty; 65 | 66 | QString output; 67 | QString input_gamma; 68 | QString st_type; 69 | double sigma_c; 70 | double precision_sigma_c; 71 | int etf_N; 72 | 73 | bool enable_bf; 74 | QString filter_type; 75 | int n_a; 76 | int n_e; 77 | double sigma_dg; 78 | double sigma_rg; 79 | double sigma_dt; 80 | double sigma_rt; 81 | double bf_alpha; 82 | double precision_g; 83 | double precision_t; 84 | 85 | QString dog_type; 86 | double sigma_e; 87 | double precision_e; 88 | double dog_k; 89 | double sigma_m; 90 | double precision_m; 91 | double step_m; 92 | QString dog_adj_func; 93 | bool dog_reparam; 94 | double dog_tau; 95 | double dog_eps; 96 | double dog_phi; 97 | double dog_p; 98 | double dog_eps_p; 99 | double dog_phi_p; 100 | QString dog_fgauss; 101 | 102 | ParamGroup* dog_tau_g; 103 | ParamDouble* dog_tau_ptr; 104 | ParamDouble* dog_eps_ptr; 105 | ParamDouble* dog_phi_ptr; 106 | ParamGroup* dog_p_g; 107 | ParamDouble* dog_p_ptr; 108 | ParamDouble* dog_eps_p_ptr; 109 | ParamDouble* dog_phi_p_ptr; 110 | 111 | bool quantization; 112 | QString quant_type; 113 | int nbins; 114 | double phi_q; 115 | double lambda_delta; 116 | double omega_delta; 117 | double lambda_phi; 118 | double omega_phi; 119 | bool warp_sharp; 120 | double sigma_w; 121 | double precision_w; 122 | double phi_w; 123 | bool final_smooth; 124 | QString final_type; 125 | double sigma_a; 126 | 127 | protected slots: 128 | void dogChanged(); 129 | }; 130 | -------------------------------------------------------------------------------- /gpu/gpu_st.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | 20 | gpu_image gpu_st_central_diff( const gpu_image& src ); 21 | gpu_image gpu_st_gaussian( const gpu_image& src, float rho ); 22 | gpu_image gpu_st_gaussian( const gpu_image& src, float rho ); 23 | gpu_image gpu_st_sobel( const gpu_image& src ); 24 | gpu_image gpu_st_sobel( const gpu_image& src ); 25 | gpu_image gpu_st_scharr( const gpu_image& src ); 26 | gpu_image gpu_st_scharr( const gpu_image& src ); 27 | gpu_image gpu_st_from_gradient( const gpu_image& src ); 28 | gpu_image gpu_st_from_tangent( const gpu_image& src ); 29 | 30 | gpu_image gpu_st_tfm( const gpu_image& st ); 31 | gpu_image gpu_st_lfm( const gpu_image& st, float alpha=0 ); 32 | gpu_image gpu_st_angle( const gpu_image& st ); 33 | gpu_image gpu_st_anisotropy( const gpu_image& st ); 34 | 35 | gpu_image gpu_st_threshold_mag( const gpu_image& st, float threshold ); 36 | gpu_image gpu_st_normalize( const gpu_image& st ); 37 | gpu_image gpu_st_flatten( const gpu_image& st ); 38 | gpu_image gpu_st_rotate( const gpu_image& st, float angle ); 39 | 40 | 41 | inline __host__ __device__ float st2angle(const float4 g) { 42 | //return 0.5f * atan2(2 * g.z, g.x - g.y) + CUDART_PIO2_F; 43 | return 0.5f * atan2(-2 * g.z, g.y - g.x); 44 | } 45 | 46 | 47 | inline __host__ __device__ float2 st2tangent(const float4 g) { 48 | float phi = st2angle(g); 49 | return make_float2(cosf(phi), sinf(phi)); 50 | } 51 | 52 | 53 | inline __host__ __device__ float2 st2gradient(const float4 g) { 54 | float phi = 0.5f * atan2(2 * g.z, g.x - g.y); 55 | return make_float2(cosf(phi), sinf(phi)); 56 | } 57 | 58 | 59 | inline __host__ __device__ float2 st2lambda(float4 g) { 60 | float a = 0.5f * (g.y + g.x); 61 | float b = 0.5f * sqrtf(fmaxf(0.0f, g.y*g.y - 2*g.x*g.y + g.x*g.x + 4*g.z*g.z)); 62 | return make_float2(a + b, a - b); 63 | } 64 | 65 | 66 | inline __host__ __device__ float4 st2tfm(const float4 g) { 67 | float2 l = st2lambda(g); 68 | float2 t = st2tangent(g); 69 | return make_float4(t.x, t.y, l.x, l.y); 70 | } 71 | 72 | 73 | inline __host__ __device__ float tfm2A(float4 t) { 74 | float lambda1 = t.z; 75 | float lambda2 = t.w; 76 | return (lambda1 + lambda2 > 0)? 77 | (lambda1 - lambda2) / (lambda1 + lambda2) : 0; 78 | } 79 | 80 | 81 | inline __host__ __device__ float st2A(float4 g) { 82 | float a = 0.5f * (g.y + g.x); 83 | float b = 0.5f * sqrtf(fmaxf(0.0f, g.y*g.y - 2*g.x*g.y + g.x*g.x + 4*g.z*g.z)); 84 | float lambda1 = a + b; 85 | float lambda2 = a - b; 86 | return (lambda1 + lambda2 > 0)? 87 | (lambda1 - lambda2) / (lambda1 + lambda2) : 0; 88 | } 89 | 90 | 91 | inline __host__ __device__ float4 st2lfm(float4 g) { 92 | float2 t = st2tangent(g); 93 | return make_float4( t.x, t.y, 1, 1 ); 94 | } 95 | 96 | 97 | inline __host__ __device__ float4 st2lfm(float4 g, float alpha) { 98 | float2 t = st2tangent(g); 99 | float A = st2A(g); 100 | return make_float4( 101 | t.x, 102 | t.y, 103 | clamp((alpha + A) / alpha, 0.1f, 2.0f), 104 | clamp(alpha / (alpha + A), 0.1f, 2.0f) 105 | ); 106 | } 107 | -------------------------------------------------------------------------------- /cmake/Utils.cmake: -------------------------------------------------------------------------------- 1 | MACRO(QT4_AUTO_WRAP outfiles) 2 | FOREACH(fileName ${ARGN}) 3 | IF(fileName MATCHES "\\.h$") 4 | FILE(STRINGS ${fileName} lines REGEX Q_OBJECT) 5 | IF(lines) 6 | SET(moc_headers ${moc_headers} ${fileName}) 7 | #MESSAGE(STATUS "moc: ${fileName}") 8 | ENDIF() 9 | ENDIF() 10 | IF(fileName MATCHES "\\.ui$") 11 | SET(ui_files ${ui_files} ${fileName}) 12 | #MESSAGE(STATUS "uic: ${fileName}") 13 | ENDIF() 14 | IF(fileName MATCHES "\\.qrc$") 15 | SET(qrc_files ${qrc_files} ${fileName}) 16 | #MESSAGE(STATUS "qrc: ${fileName}") 17 | ENDIF() 18 | ENDFOREACH() 19 | QT4_WRAP_CPP(${outfiles} ${moc_headers}) 20 | QT4_WRAP_UI(${outfiles} ${ui_files}) 21 | QT4_ADD_RESOURCES(${outfiles} ${qrc_files}) 22 | ENDMACRO() 23 | 24 | 25 | MACRO(SOURCE_GROUP_BY_PATH) 26 | FOREACH(filename ${ARGV}) 27 | GET_FILENAME_COMPONENT(path "${filename}" REALPATH) 28 | FILE(RELATIVE_PATH path ${PROJECT_SOURCE_DIR} ${path}) 29 | GET_FILENAME_COMPONENT(path "${path}" PATH) 30 | string(REPLACE "/" "\\" path "${path}") 31 | IF(${filename} MATCHES "ui_|cxx$") 32 | SOURCE_GROUP("generated" FILES ${filename}) 33 | ELSEIF(${filename} MATCHES "h$|hpp$|cpp$|c$|cu$|ui$|qrc$") 34 | SOURCE_GROUP("${path}" FILES ${filename}) 35 | ENDIF() 36 | ENDFOREACH() 37 | ENDMACRO(SOURCE_GROUP_BY_PATH) 38 | 39 | 40 | MACRO(DEPLOY_QT_CUDA target) 41 | IF(WIN32) 42 | INSTALL(CODE " 43 | file(WRITE \"\${CMAKE_INSTALL_PREFIX}/qt.conf\" \"\") 44 | include(BundleUtilities) 45 | fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${target}.exe\" \"\" \"\") 46 | " COMPONENT Runtime) 47 | ELSEIF(APPLE) 48 | INSTALL(CODE " 49 | file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${target}.app/Contents/Resources/qt.conf\" \"\") 50 | include(BundleUtilities) 51 | function(gp_resolve_item_override context item exepath dirs resolved_item_var resolved_var) 52 | IF (\${item} STREQUAL \"@rpath/libcudart.dylib\") 53 | #message(\"RI: \${item} \${\${resolved_item_var}} \${\${resolved_var}}\") 54 | set(\${resolved_item_var} \"/usr/local/cuda/lib/libcudart.dylib\" PARENT_SCOPE) 55 | set(\${resolved_var} 1 PARENT_SCOPE) 56 | ENDIF() 57 | IF (\${item} STREQUAL \"@rpath/libcurand.dylib\") 58 | #message(\"RI: \${item} \${\${resolved_item_var}} \${\${resolved_var}}\") 59 | set(\${resolved_item_var} \"/usr/local/cuda/lib/libcurand.dylib\" PARENT_SCOPE) 60 | set(\${resolved_var} 1 PARENT_SCOPE) 61 | ENDIF() 62 | IF (\${item} STREQUAL \"@rpath/libnpp.dylib\") 63 | #message(\"RI: \${item} \${\${resolved_item_var}} \${\${resolved_var}}\") 64 | set(\${resolved_item_var} \"/usr/local/cuda/lib/libnpp.dylib\" PARENT_SCOPE) 65 | set(\${resolved_var} 1 PARENT_SCOPE) 66 | ENDIF() 67 | IF (\${item} STREQUAL \"@rpath/libtlshook.dylib\") 68 | #message(\"RI: \${item} \${\${resolved_item_var}} \${\${resolved_var}}\") 69 | set(\${resolved_item_var} \"/usr/local/cuda/lib/libtlshook.dylib\" PARENT_SCOPE) 70 | set(\${resolved_var} 1 PARENT_SCOPE) 71 | ENDIF() 72 | endfunction() 73 | function(gp_resolved_file_type_override file type_var) 74 | IF(\${file} MATCHES \"(CUDA.framework|libcuda.dylib)\") 75 | #message(\"GP: \${file} \${\${type_var}}\") 76 | set(\${type_var} \"system\" PARENT_SCOPE) 77 | ENDIF() 78 | endfunction() 79 | fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${target}.app\" \"\" \"\") 80 | " COMPONENT Runtime) 81 | ENDIF() 82 | ENDMACRO() 83 | 84 | 85 | IF(WIN32) 86 | OPTION(INSTALL_MSVCRT "Install Microsoft CRT" OFF) 87 | IF(${INSTALL_MSVCRT}) 88 | SET(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ".") 89 | INCLUDE(InstallRequiredSystemLibraries) 90 | ENDIF() 91 | ENDIF() 92 | -------------------------------------------------------------------------------- /gpu/gpu_dog2.cu: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_dog2.h" 17 | 18 | 19 | static texture texSRC1; 20 | static texture texSRC4; 21 | 22 | 23 | __global__ void imp_isotropic_dog2( gpu_plm2 dst, float sigma, float k, float p, float precision ) { 24 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 25 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 26 | if (ix >= dst.w || iy >= dst.h) 27 | return; 28 | 29 | float twoSigmaE2 = 2.0f * sigma * sigma; 30 | float twoSigmaR2 = twoSigmaE2 * k * k; 31 | int halfWidth = int(ceilf( precision * sigma * k )); 32 | 33 | float sumE = 0; 34 | float sumR = 0; 35 | float2 norm = make_float2(0); 36 | 37 | for ( int i = -halfWidth; i <= halfWidth; ++i ) { 38 | for ( int j = -halfWidth; j <= halfWidth; ++j ) { 39 | float d = length(make_float2(i,j)); 40 | float kE = __expf(-d *d / twoSigmaE2); 41 | float kR = __expf(-d *d / twoSigmaR2); 42 | 43 | float c = tex2D(texSRC1, ix + i, iy + j); 44 | sumE += kE * c; 45 | sumR += kR * c; 46 | norm += make_float2(kE, kR); 47 | } 48 | } 49 | 50 | sumE /= norm.x; 51 | sumR /= norm.y; 52 | 53 | float H = (1 + p) * sumE - p * sumR; 54 | dst(ix, iy) = H; 55 | } 56 | 57 | 58 | gpu_image gpu_isotropic_dog2( const gpu_image& src, float sigma, float k, float p, float precision ) 59 | { 60 | gpu_image dst(src.size()); 61 | bind(&texSRC1, src); 62 | imp_isotropic_dog2<<>>(dst, sigma, k, p, precision); 63 | GPU_CHECK_ERROR(); 64 | return dst; 65 | } 66 | 67 | 68 | __global__ void imp_gradient_dog2( gpu_plm2 dst, const gpu_plm2 tfab, 69 | float sigma, float k, float p, float precision) 70 | { 71 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 72 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 73 | if (ix >= dst.w || iy >= dst.h) 74 | return; 75 | 76 | float4 t = tfab(ix, iy); 77 | float2 n = make_float2(t.y, -t.x); 78 | float2 nabs = fabs(n); 79 | float ds = 1.0f / ((nabs.x > nabs.y)? nabs.x : nabs.y); 80 | 81 | float twoSigmaE2 = 2 * sigma * sigma; 82 | float twoSigmaR2 = twoSigmaE2 * k * k; 83 | float halfWidth = ceilf(precision * sigma * k); 84 | 85 | float sumE = tex2D(texSRC1, ix, iy); 86 | float sumR = sumE; 87 | float2 norm = make_float2(1, 1); 88 | 89 | for( float d = ds; d <= halfWidth; d += ds ) { 90 | float kE = __expf( -d * d / twoSigmaE2 ); 91 | float kR = __expf( -d * d / twoSigmaR2 ); 92 | 93 | float2 o = d*n; 94 | float c = tex2D( texSRC1, 0.5f + ix - o.x, 0.5f + iy - o.y) + 95 | tex2D( texSRC1, 0.5f + ix + o.x, 0.5f + iy + o.y); 96 | sumE += kE * c; 97 | sumR += kR * c; 98 | norm += 2 * make_float2(kE, kR); 99 | } 100 | sumE /= norm.x; 101 | sumR /= norm.y; 102 | 103 | float H = (1 + p) * sumE - p * sumR; 104 | dst(ix, iy) = H; 105 | } 106 | 107 | 108 | gpu_image gpu_gradient_dog2( const gpu_image& src, const gpu_image& tfab, 109 | float sigma, float k, float p, float precision) 110 | { 111 | gpu_image dst(src.size()); 112 | bind(&texSRC1, src); 113 | texSRC1.filterMode = cudaFilterModeLinear; 114 | imp_gradient_dog2<<>>(dst, tfab, sigma, k, p, precision); 115 | texSRC1.filterMode = cudaFilterModePoint; 116 | GPU_CHECK_ERROR(); 117 | return dst; 118 | } 119 | -------------------------------------------------------------------------------- /util/imageview.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | class ImageView : public QWidget { 19 | Q_OBJECT 20 | Q_PROPERTY(QImage image READ image WRITE setImage NOTIFY imageChanged(const QImage&)) 21 | Q_PROPERTY(double zoom READ zoom WRITE setZoom NOTIFY zoomChanged(double)) 22 | Q_PROPERTY(double resolution READ resolution WRITE setResolution NOTIFY resolutionChanged) 23 | Q_PROPERTY(double originX READ originX WRITE setOriginX NOTIFY originXChanged) 24 | Q_PROPERTY(double originY READ originY WRITE setOriginY NOTIFY originYChanged) 25 | public: 26 | ImageView(QWidget *parent); 27 | ~ImageView(); 28 | 29 | virtual void restoreSettings(QSettings& settings); 30 | virtual void saveSettings(QSettings& settings); 31 | 32 | QSize imageSize() const { return image().size(); } 33 | const QImage& image() const { return m_images[m_index]; } 34 | QPointF origin() const { return m_origin; } 35 | double originX() const { return m_origin.x(); } 36 | double originY() const { return m_origin.y(); } 37 | double zoom() const { return m_zoom; } 38 | double resolution() const { return m_resolution; } 39 | double scale() const { return m_zoom * m_resolution; } 40 | 41 | virtual QPointF view2image(const QPointF& p) const; 42 | virtual QPointF image2view(const QPointF& p) const; 43 | virtual QTransform viewTransform(const QSizeF& sz, double zoom, const QPointF& origin) const; 44 | virtual float pt2px(float pt) const; 45 | 46 | struct Handler { 47 | virtual void draw(ImageView *view, QPainter &p, const QRectF& R, const QImage& image); 48 | virtual void dragBegin(ImageView *view, QMouseEvent *e); 49 | virtual void dragMove(ImageView *view, QMouseEvent *e, const QPoint& start); 50 | virtual void dragEnd(ImageView *view, QMouseEvent *e, const QPoint& start); 51 | }; 52 | void setHandler(Handler *handler); 53 | void setOverlay(QWidget *overlay); 54 | 55 | public slots: 56 | void setImage(const QImage& image); 57 | void setOriginX(double value); 58 | void setOriginY(double value); 59 | void setZoom(double value); 60 | void setResolution(double value); 61 | void zoomIn(); 62 | void zoomOut(); 63 | void reset(); 64 | void hold(); 65 | void toggle(); 66 | void copy(); 67 | void savePNG(const QString& text=QString()); 68 | 69 | signals: 70 | void imageChanged(const QImage&); 71 | void originXChanged(double); 72 | void originYChanged(double); 73 | void zoomChanged(double); 74 | void resolutionChanged(double); 75 | 76 | protected: 77 | virtual void paintEvent( QPaintEvent* ); 78 | virtual void paint(QPainter &p, const QSizeF& sz, double zoom, const QPointF& origin); 79 | virtual void draw(QPainter& p, const QRectF& R, const QImage& image); 80 | 81 | virtual bool eventFilter( QObject *watched, QEvent *e ); 82 | virtual void leaveEvent( QEvent *e ); 83 | virtual void keyPressEvent( QKeyEvent *e ); 84 | virtual void keyReleaseEvent( QKeyEvent *e ); 85 | virtual void mousePressEvent( QMouseEvent *e ); 86 | virtual void mouseMoveEvent( QMouseEvent *e ); 87 | virtual void mouseReleaseEvent( QMouseEvent *e ); 88 | virtual void wheelEvent(QWheelEvent *e); 89 | virtual void mouseDragBegin(QMouseEvent *e); 90 | virtual void mouseDragMove(QMouseEvent *e, const QPoint& start); 91 | virtual void mouseDragEnd(QMouseEvent *e, const QPoint& start); 92 | 93 | protected: 94 | QPointF m_origin; 95 | double m_zoom; 96 | double m_resolution; 97 | bool m_spacePressed; 98 | 99 | enum Mode { MODE_NONE=0, MODE_PAN, MODE_DRAG }; 100 | Mode m_mode; 101 | QPoint m_dragStart; 102 | Qt::MouseButton m_dragButton; 103 | QPointF m_dragOrigin; 104 | QCursor m_cursor; 105 | 106 | int m_index; 107 | QImage m_images[2]; 108 | Handler *m_handler; 109 | QWidget *m_overlay; 110 | }; 111 | -------------------------------------------------------------------------------- /gpu/gpu_image.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "cpu_image.h" 19 | #include "gpu_error.h" 20 | #include "basic_image.h" 21 | #include "gpu_plm2.h" 22 | #include "gpu_cache.h" 23 | 24 | 25 | struct gpu_allocator { 26 | void alloc(void **ptr, unsigned *pitch, unsigned w, unsigned h) { 27 | gpu_cache_alloc(ptr, pitch, w, h); 28 | } 29 | void free(void *ptr, unsigned pitch, unsigned w, unsigned h) { 30 | gpu_cache_free(ptr, pitch, w, h); 31 | } 32 | }; 33 | 34 | 35 | typedef basic_image_data gpu_image_data; 36 | 37 | 38 | template class gpu_image : public basic_image { 39 | public: 40 | gpu_image() : basic_image() { } 41 | gpu_image(unsigned w, unsigned h) : basic_image(w, h) { } 42 | gpu_image(uint2 size) : basic_image(size) { } 43 | gpu_image(gpu_image_data *data) : basic_image(data) { } 44 | 45 | gpu_image(const T *src, size_t src_pitch, unsigned w, unsigned h) : basic_image(w, h) { 46 | copy(this, src, src_pitch); 47 | } 48 | 49 | gpu_image(const T *src, unsigned w, unsigned h) : basic_image(w, h) { 50 | copy(this, src, w * sizeof(T)); 51 | } 52 | 53 | gpu_image(const cpu_image& src) : basic_image(src.w(), src.h()){ 54 | copy(this, src.ptr(), src.pitch()); 55 | } 56 | 57 | gpu_image(const gpu_image& img) : basic_image(img) { } 58 | 59 | const gpu_image& operator=(const gpu_image& img) { 60 | basic_image::operator=(img); 61 | return *this; 62 | } 63 | 64 | cpu_image cpu() const { 65 | if (!this->is_valid()) return cpu_image(); 66 | cpu_image dst(this->w(), this->h()); 67 | copy(dst.ptr(), dst.pitch(), this); 68 | return dst; 69 | } 70 | 71 | dim3 threads() const { 72 | return dim3(8, 8); 73 | } 74 | 75 | dim3 blocks(dim3 threads = dim3(8, 8)) const { 76 | return dim3( (int)ceil((float)this->w() / threads.x), (int)ceil((float)this->h() / threads.y) ); 77 | } 78 | 79 | operator gpu_plm2() { 80 | if (!this->is_valid()) return gpu_plm2(); 81 | return gpu_plm2((T*)this->ptr(), this->pitch(), this->w(), this->h()); 82 | } 83 | 84 | operator const gpu_plm2() const { 85 | if (!this->is_valid()) return gpu_plm2(); 86 | return gpu_plm2((T*)this->ptr(), this->pitch(), this->w(), this->h()); 87 | } 88 | 89 | void zero() { 90 | GPU_SAFE_CALL(cudaMemset2D(this->ptr(), this->pitch(), 0, this->w()*sizeof(T), this->h())); 91 | } 92 | }; 93 | 94 | 95 | template 96 | void copy(gpu_image* dst, const void *src, size_t src_pitch) { 97 | GPU_SAFE_CALL(cudaMemcpy2D(dst->ptr(), dst->pitch(), src, src_pitch, dst->w()*sizeof(T), 98 | dst->h(), cudaMemcpyHostToDevice)); 99 | } 100 | 101 | template 102 | void copy(void *dst, size_t dst_pitch, const gpu_image* src) { 103 | GPU_SAFE_CALL(cudaMemcpy2D(dst, dst_pitch, src->ptr(), src->pitch(), src->w()*sizeof(T), 104 | src->h(), cudaMemcpyDeviceToHost)); 105 | } 106 | 107 | 108 | #ifdef __CUDACC__ 109 | 110 | template 111 | void bind(const texture* tex, const gpu_image& img) { 112 | GPU_SAFE_CALL(cudaBindTexture2D(0, *tex, img.ptr(), img.w(), img.h(), img.pitch())); 113 | } 114 | 115 | #endif 116 | 117 | gpu_image gpu_set( float value, unsigned w, unsigned h ); 118 | gpu_image gpu_set( float4 value, unsigned w, unsigned h ); 119 | gpu_image gpu_add( const gpu_image& src0, const gpu_image& src1 ); 120 | gpu_image gpu_add( const gpu_image& src0, const gpu_image& src1 ); 121 | gpu_image gpu_mul( const gpu_image& src, float value ); 122 | gpu_image gpu_mul( const gpu_image& src, float value ); 123 | -------------------------------------------------------------------------------- /gpu/gpu_oabf.cu: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_oabf.h" 17 | 18 | 19 | static texture texSRC1; 20 | static texture texSRC4; 21 | 22 | 23 | template T texSRC(float x, float y); 24 | template<> inline __device__ float texSRC(float x, float y) { return tex2D(texSRC1, x, y); } 25 | template<> inline __device__ float4 texSRC(float x, float y) { return tex2D(texSRC4, x, y); } 26 | 27 | 28 | template 29 | __global__ void imp_oabf( gpu_plm2 dst, const gpu_plm2 lfm, 30 | float sigma_d, float sigma_r, bool tangential, float precision ) 31 | { 32 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 33 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 34 | if (ix >= dst.w || iy >= dst.h) 35 | return; 36 | 37 | float4 l = lfm(ix, iy); 38 | float2 t; 39 | if (tangential) { 40 | t = make_float2(l.x, l.y); 41 | sigma_d *= l.z; 42 | } else { 43 | t = make_float2(l.y, -l.x); 44 | sigma_d *= l.w; 45 | } 46 | 47 | float twoSigmaD2 = 2.0f * sigma_d * sigma_d; 48 | float twoSigmaR2 = 2.0f * sigma_r * sigma_r; 49 | int halfWidth = int(ceilf( precision * sigma_d )); 50 | 51 | float2 tabs = fabs(t); 52 | float ds = 1.0f / ((tabs.x > tabs.y)? tabs.x : tabs.y); 53 | 54 | T c0 = texSRC(0.5f + ix, 0.5f + iy); 55 | T sum = c0; 56 | 57 | float norm = 1; 58 | for (float d = ds; d <= halfWidth; d += ds) { 59 | float2 dt = d * t; 60 | T c1 = texSRC(0.5f + ix + dt.x, 0.5f + iy + dt.y); 61 | T c2 = texSRC(0.5f + ix - dt.x, 0.5f + iy - dt.y); 62 | 63 | T e1 = c1 - c0; 64 | T e2 = c2 - c0; 65 | 66 | float kd = __expf( -dot(d,d) / twoSigmaD2 ); 67 | float kr1 = __expf( -dot(e1,e1) / twoSigmaR2 ); 68 | float kr2 = __expf( -dot(e2,e2) / twoSigmaR2 ); 69 | 70 | sum += kd * kr1 * c1; 71 | sum += kd * kr2 * c2; 72 | norm += kd * kr1 + kd * kr2; 73 | } 74 | sum /= norm; 75 | 76 | dst(ix, iy) = sum; 77 | } 78 | 79 | 80 | gpu_image gpu_oabf_1d( const gpu_image& src, const gpu_image& lfm, 81 | float sigma_d, float sigma_r, bool tangential, float precision ) 82 | { 83 | if (sigma_d <= 0) return src; 84 | gpu_image dst(src.size()); 85 | bind(&texSRC1, src); 86 | texSRC1.filterMode = cudaFilterModeLinear; 87 | imp_oabf<<>>(dst, lfm, sigma_d, sigma_r, tangential, precision); 88 | texSRC1.filterMode = cudaFilterModePoint; 89 | GPU_CHECK_ERROR(); 90 | return dst; 91 | } 92 | 93 | 94 | gpu_image gpu_oabf_1d( const gpu_image& src, const gpu_image& lfm, 95 | float sigma_d, float sigma_r, bool tangential, float precision ) 96 | { 97 | if (sigma_d <= 0) return src; 98 | gpu_image dst(src.size()); 99 | bind(&texSRC4, src); 100 | texSRC4.filterMode = cudaFilterModeLinear; 101 | imp_oabf<<>>(dst, lfm, sigma_d, sigma_r, tangential, precision); 102 | texSRC4.filterMode = cudaFilterModePoint; 103 | GPU_CHECK_ERROR(); 104 | return dst; 105 | } 106 | 107 | 108 | gpu_image gpu_oabf( const gpu_image& src, const gpu_image& lfm, 109 | float sigma_d, float sigma_r, float precision ) 110 | { 111 | gpu_image img; 112 | img = gpu_oabf_1d(src, lfm, sigma_d, sigma_r, false, precision); 113 | img = gpu_oabf_1d(img, lfm, sigma_d, sigma_r, true, precision); 114 | return img; 115 | } 116 | 117 | 118 | gpu_image gpu_oabf( const gpu_image& src, const gpu_image& lfm, 119 | float sigma_d, float sigma_r, float precision ) 120 | { 121 | gpu_image img; 122 | img = gpu_oabf_1d(src, lfm, sigma_d, sigma_r, false, precision); 123 | img = gpu_oabf_1d(img, lfm, sigma_d, sigma_r, true, precision); 124 | return img; 125 | } 126 | -------------------------------------------------------------------------------- /gpu/cpu_image.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include 19 | #include 20 | #include "gpu_math.h" 21 | #include "basic_image.h" 22 | #include 23 | 24 | 25 | class cpu_allocator { 26 | public: 27 | cpu_allocator(bool locked=false) 28 | : m_locked(locked) 29 | { } 30 | 31 | void alloc(void **ptr, unsigned *pitch, unsigned w, unsigned h) { 32 | // TODO: support for host locked memory 33 | *pitch = (4 * w + 3) / 4; 34 | *ptr = ::malloc(*pitch * h); 35 | assert(*ptr); 36 | //*ptr = _aligned_malloc(*pitch * h, 16); 37 | } 38 | void free(void *ptr, unsigned pitch, unsigned w, unsigned h) { 39 | // TODO: support for host locked memory 40 | ::free(ptr); 41 | //_aligned_free(ptr); 42 | } 43 | 44 | bool is_locked() const { return m_locked; } 45 | 46 | private: 47 | bool m_locked; 48 | }; 49 | 50 | typedef basic_image_data cpu_image_data; 51 | 52 | 53 | template class cpu_image : public basic_image { 54 | public: 55 | cpu_image() : basic_image() { } 56 | cpu_image(unsigned w, unsigned h, bool locked=false) : basic_image(w, h, cpu_allocator(locked)) { } 57 | cpu_image(uint2 size) : basic_image(size) { } 58 | cpu_image(cpu_image_data *data) : basic_image(data) { } 59 | 60 | cpu_image(const T *src, size_t src_pitch, unsigned w, unsigned h) : basic_image(w, h) { 61 | copy(this, src, src_pitch); 62 | } 63 | 64 | cpu_image(const T *src, unsigned w, unsigned h) : basic_image(w, h) { 65 | copy(this, src, w * sizeof(T)); 66 | } 67 | 68 | cpu_image(const cpu_image& img) : basic_image(img) { } 69 | 70 | const cpu_image& operator=(const cpu_image& img) { 71 | basic_image::operator=(img); 72 | return *this; 73 | } 74 | 75 | T* operator[](int y) { 76 | return reinterpret_cast(this->ptr8u() + y * this->pitch()); 77 | } 78 | 79 | const T* operator[](int y) const { 80 | return reinterpret_cast(this->ptr8u() + y * this->pitch()); 81 | } 82 | 83 | T& operator()(int x, int y) { 84 | if (x < 0) x = 0; else if (x >= (int)this->w()) x = this->w() - 1; 85 | if (y < 0) y = 0; else if (y >= (int)this->h()) y = this->h() - 1; 86 | return (*this)[y][x]; 87 | } 88 | 89 | const T& operator()(int x, int y) const { 90 | if (x < 0) x = 0; else if (x >= (int)this->w()) x = this->w() - 1; 91 | if (y < 0) y = 0; else if (y >= (int)this->h()) y = this->h() - 1; 92 | return (*this)[y][x]; 93 | } 94 | 95 | T& operator()(float x, float y) { 96 | return operator()((int)x, (int)y); 97 | } 98 | 99 | const T& operator()(float x, float y) const { 100 | return operator()((int)x, (int)y); 101 | } 102 | 103 | T& operator()(double x, double y) { 104 | return operator()((int)x, (int)y); 105 | } 106 | 107 | const T& operator()(double x, double y) const { 108 | return operator()((int)x, (int)y); 109 | } 110 | 111 | // TODO: optimize 112 | T sample_linear(float x, float y) const { 113 | x -= 0.5f; 114 | y -= 0.5f; 115 | 116 | int x0 = (int)x; 117 | int y0 = (int)y; 118 | int x1 = x0 + 1; 119 | int y1 = y0 + 1; 120 | 121 | float fx = x - floor(x); 122 | float fy = y - floor(y); 123 | 124 | T c0 = operator()(x0, y0); 125 | T c1 = operator()(x1, y0); 126 | T c2 = operator()(x0, y1); 127 | T c3 = operator()(x1, y1); 128 | 129 | return (1 - fy) * ((1 - fx) * c0 + fx * c1) + fy * ((1 - fx) * c2 + fx * c3); 130 | } 131 | }; 132 | 133 | 134 | template 135 | void copy(cpu_image* dst, const void *src, size_t src_pitch) { 136 | cudaMemcpy2D(dst->ptr(), dst->pitch(), src, src_pitch, dst->w()*sizeof(T), dst->h(), cudaMemcpyHostToHost); 137 | } 138 | 139 | template 140 | void copy(void *dst, size_t dst_pitch, const cpu_image* src) { 141 | cudaMemcpy2D(dst, dst_pitch, src->ptr(), src->pitch(), src->w()*sizeof(T), src->h(), cudaMemcpyHostToHost); 142 | } 143 | -------------------------------------------------------------------------------- /util/logwindow.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "logwindow.h" 17 | #ifdef _MSC_VER 18 | #include "windows.h" 19 | #endif 20 | 21 | 22 | static QString g_logBuffer; 23 | static LogWindow *g_logWindow = 0; 24 | 25 | 26 | class Highlighter : public QSyntaxHighlighter { 27 | public: 28 | Highlighter(QTextDocument *parent) : QSyntaxHighlighter(parent) { 29 | m_formatDebug.setForeground(Qt::gray); 30 | m_formatWarn.setForeground(Qt::red); 31 | m_formatError.setForeground(Qt::yellow); 32 | m_formatError.setBackground(Qt::red); 33 | } 34 | 35 | void highlightBlock(const QString &text) { 36 | if (text.startsWith("[DEBUG]")) { 37 | setFormat(0, text.length(), m_formatDebug); 38 | } 39 | else if (text.startsWith("[WARN]")) { 40 | setFormat(0, text.length(), m_formatWarn); 41 | } 42 | else if (text.startsWith("[ERROR]")) { 43 | setFormat(0, text.length(), m_formatError); 44 | } 45 | else if (text.startsWith("[FATAL]")) { 46 | setFormat(0, text.length(), m_formatError); 47 | } 48 | } 49 | protected: 50 | QTextCharFormat m_formatDebug; 51 | QTextCharFormat m_formatWarn; 52 | QTextCharFormat m_formatError; 53 | }; 54 | 55 | 56 | LogWindow::LogWindow(QWidget *parent) : QPlainTextEdit(parent) { 57 | setCenterOnScroll(true); 58 | setReadOnly(true); 59 | setLineWrapMode(NoWrap); 60 | setTextInteractionFlags(Qt::TextSelectableByMouse); 61 | 62 | #ifdef WIN32 63 | setFont(QFont("Consolas", 8)); 64 | #endif 65 | new Highlighter(document()); 66 | 67 | g_logWindow = this; 68 | appendPlainText(g_logBuffer.trimmed()); 69 | g_logBuffer.clear(); 70 | } 71 | 72 | 73 | LogWindow::~LogWindow() { 74 | qInstallMsgHandler(0); 75 | g_logWindow = 0; 76 | } 77 | 78 | 79 | void LogWindow::closeEvent(QCloseEvent *e) { 80 | //QSettings settings; 81 | //settings.setValue("logWindow/geometry", saveGeometry()); 82 | QPlainTextEdit::closeEvent(e); 83 | } 84 | 85 | 86 | void LogWindow::contextMenuEvent(QContextMenuEvent *event) { 87 | QMenu *menu = createStandardContextMenu(); 88 | QAction *a = new QAction("Clear", this); 89 | a->setEnabled(!document()->isEmpty()); 90 | connect(a, SIGNAL(triggered()), this, SLOT(clear())); 91 | QList L = menu->actions(); 92 | menu->insertAction(L[0], a); 93 | menu->exec(event->globalPos()); 94 | delete menu; 95 | } 96 | 97 | 98 | void LogWindow::logText(const QString& msg) { 99 | appendPlainText(msg); 100 | } 101 | 102 | 103 | static void handle_msg(QtMsgType t, const char * m) { 104 | QString msg(m); 105 | QStringList L = msg.split('\n'); 106 | msg = QString(); 107 | 108 | QString prefix; 109 | switch (t) { 110 | case QtDebugMsg: 111 | prefix = "[DEBUG] "; 112 | break; 113 | case QtWarningMsg: 114 | prefix = "[WARN] "; 115 | break; 116 | case QtCriticalMsg: 117 | prefix = "[ERROR] "; 118 | break; 119 | case QtFatalMsg: 120 | prefix = "[FATAL] "; 121 | break; 122 | } 123 | prefix += QDateTime::currentDateTime().toString("hh:mm:ss:zzz"); 124 | //prefix += QString("[%1]").arg((size_t)QThread::currentThreadId(), 8, 16); 125 | prefix += QString(" - "); 126 | 127 | for (int i = 0; i < L.size(); ++i) { 128 | msg += prefix + L[i]; 129 | if (i != L.size()-1) msg+= "\n"; 130 | } 131 | 132 | #ifdef _MSC_VER 133 | if (IsDebuggerPresent()) { 134 | OutputDebugStringA(msg.toStdString().c_str()); 135 | OutputDebugStringA("\n"); 136 | } 137 | #endif 138 | 139 | if (g_logWindow) { 140 | if (QThread::currentThread() == qApp->thread()) { 141 | g_logWindow->logText(msg); 142 | if (t != QtDebugMsg) { 143 | if (g_logWindow->isHidden()) g_logWindow->show(); 144 | } 145 | } else { 146 | QMetaObject::invokeMethod(g_logWindow, "logText", Qt::QueuedConnection, Q_ARG(QString, msg)); 147 | } 148 | } else { 149 | g_logBuffer += msg + "\n"; 150 | } 151 | } 152 | 153 | 154 | void LogWindow::install() { 155 | qInstallMsgHandler(handle_msg); 156 | } 157 | 158 | 159 | -------------------------------------------------------------------------------- /util/imageutil.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "imageutil.h" 17 | #include "gpu_convert.h" 18 | 19 | 20 | cpu_image cpu_image_from_qimage(const QImage& image) { 21 | if (!image.isNull()) { 22 | QImage qi = image; 23 | if (qi.format() != QImage::Format_RGB32) { 24 | qi = qi.convertToFormat(QImage::Format_RGB32); 25 | } 26 | return cpu_image((const uchar4*)qi.bits(), qi.bytesPerLine(), qi.width(), qi.height()); 27 | } 28 | return cpu_image(); 29 | } 30 | 31 | 32 | QImage cpu_data_to_qimage(const cpu_image_data *data) { 33 | if (!data) return QImage(); 34 | 35 | if (data->type_id() == pixel_type_id()) { 36 | QImage img(data->w(), data->h(), QImage::Format_Indexed8); 37 | for (unsigned i = 0; i < 256; ++i) img.setColor(i, 0xff000000 | (i << 16) | (i << 8) | i); 38 | const float *p = (const float*)data->ptr(); 39 | for (unsigned j = 0; j < data->h(); ++j) { 40 | unsigned char* q = img.scanLine(j); 41 | for (unsigned i = 0; i < data->w(); ++i) { 42 | *q++ = (unsigned char)(255.0f * clamp(*p++, 0.0f, 1.0f)); 43 | } 44 | } 45 | return img; 46 | } 47 | 48 | if (data->type_id() == pixel_type_id()) { 49 | QImage img(data->w(), data->h(), QImage::Format_Indexed8); 50 | for (unsigned i = 0; i < 256; ++i) img.setColor(i, 0xff000000 | (i << 16) | (i << 8) | i); 51 | const unsigned char *p = (const unsigned char*)data->ptr(); 52 | for (unsigned j = 0; j < data->h(); ++j) { 53 | unsigned char* q = img.scanLine(j); 54 | for (unsigned i = 0; i < data->w(); ++i) { 55 | *q++ = *p++; 56 | } 57 | } 58 | return img; 59 | } 60 | 61 | if (data->type_id() == pixel_type_id()) { 62 | QImage img(data->w(), data->h(), QImage::Format_RGB32); 63 | const unsigned N = data->w() * data->h(); 64 | const float4 *p = (const float4*)data->ptr(); 65 | uchar4* q = (uchar4*)img.bits(); 66 | for (unsigned i = 0; i < N; ++i) { 67 | q->x = (unsigned char)(255.0f * clamp(p->x, 0.0f, 1.0f)); 68 | q->y = (unsigned char)(255.0f * clamp(p->y, 0.0f, 1.0f)); 69 | q->z = (unsigned char)(255.0f * clamp(p->z, 0.0f, 1.0f)); 70 | q->w = 255; 71 | p++; 72 | q++; 73 | } 74 | return img; 75 | } 76 | 77 | if (data->type_id() == pixel_type_id()) { 78 | QImage img(data->w(), data->h(), QImage::Format_RGB32); 79 | const unsigned N = data->w() * data->h(); 80 | const uchar4 *p = (const uchar4*)data->ptr(); 81 | uchar4* q = (uchar4*)img.bits(); 82 | for (unsigned i = 0; i < N; ++i) { 83 | q->x = p->x; 84 | q->y = p->y; 85 | q->z = p->z; 86 | q->w = 255; 87 | p++; 88 | q++; 89 | } 90 | return img; 91 | } 92 | 93 | return QImage(); 94 | } 95 | 96 | 97 | template <> gpu_image gpu_image_from_qimage(const QImage& image) { 98 | if (!image.isNull()) { 99 | return gpu_image((uchar4*)image.bits(), image.bytesPerLine(), image.width(), image.height()); 100 | } 101 | return gpu_image(); 102 | } 103 | 104 | 105 | template <> gpu_image gpu_image_from_qimage(const QImage& image) { 106 | if (!image.isNull()) { 107 | return gpu_8u_to_32f(gpu_image_from_qimage(image)); 108 | } 109 | return gpu_image(); 110 | } 111 | 112 | 113 | QImage gpu_image_to_qimage(const gpu_image& image) { 114 | QImage dst(image.w(), image.h(), QImage::Format_Indexed8); 115 | dst.setColorCount(256); 116 | for (int i = 0; i < 256; ++i) dst.setColor(i, qRgb(i,i,i)); 117 | copy(dst.bits(), dst.bytesPerLine(), &image); 118 | return dst; 119 | } 120 | 121 | 122 | QImage gpu_image_to_qimage(const gpu_image& image) { 123 | QImage dst(image.w(), image.h(), QImage::Format_RGB32); 124 | copy(dst.bits(), dst.bytesPerLine(), &image); 125 | return dst; 126 | } 127 | 128 | 129 | QImage gpu_image_to_qimage(const gpu_image& image) { 130 | return gpu_image_to_qimage(gpu_32f_to_8u(image)); 131 | } 132 | 133 | QImage gpu_image_to_qimage(const gpu_image& image) { 134 | return gpu_image_to_qimage(gpu_32f_to_8u(image)); 135 | } 136 | -------------------------------------------------------------------------------- /gpu/gpu_util.cu: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_util.h" 17 | 18 | 19 | template 20 | __global__ void imp_adjust( const gpu_plm2 src, gpu_plm2 dst, T a, T b) { 21 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 22 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 23 | if (ix >= dst.w || iy >= dst.h) 24 | return; 25 | 26 | T c = src(ix, iy); 27 | dst(ix, iy) = a * c + b; 28 | } 29 | 30 | 31 | gpu_image gpu_adjust( const gpu_image& src, float a, float b ) { 32 | gpu_image dst(src.size()); 33 | imp_adjust<<>>(src, dst, a, b); 34 | GPU_CHECK_ERROR(); 35 | return dst; 36 | } 37 | 38 | 39 | gpu_image gpu_adjust( const gpu_image& src, float4 a, float4 b ) { 40 | gpu_image dst(src.size()); 41 | imp_adjust<<>>(src, dst, a, b); 42 | GPU_CHECK_ERROR(); 43 | return dst; 44 | } 45 | 46 | 47 | __global__ void imp_invert( const gpu_plm2 src, gpu_plm2 dst ) { 48 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 49 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 50 | if (ix >= dst.w || iy >= dst.h) 51 | return; 52 | 53 | float c = src(ix, iy); 54 | dst(ix, iy) = 1 - __saturatef(c); 55 | } 56 | 57 | 58 | gpu_image gpu_invert( const gpu_image& src ) { 59 | gpu_image dst(src.size()); 60 | imp_invert<<>>(src, dst); 61 | GPU_CHECK_ERROR(); 62 | return dst; 63 | } 64 | 65 | 66 | __global__ void imp_invert( const gpu_plm2 src, gpu_plm2 dst ) { 67 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 68 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 69 | if (ix >= dst.w || iy >= dst.h) 70 | return; 71 | 72 | float4 c = src(ix, iy); 73 | dst(ix, iy) = make_float4( 1 - __saturatef(c.x), 74 | 1 - __saturatef(c.y), 75 | 1 - __saturatef(c.z), 76 | 1 ); 77 | } 78 | 79 | 80 | gpu_image gpu_invert( const gpu_image& src ) { 81 | gpu_image dst(src.size()); 82 | imp_invert<<>>(src, dst); 83 | GPU_CHECK_ERROR(); 84 | return dst; 85 | } 86 | 87 | 88 | __global__ void imp_saturate( const gpu_plm2 src, gpu_plm2 dst ) { 89 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 90 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 91 | if (ix >= dst.w || iy >= dst.h) 92 | return; 93 | 94 | dst(ix, iy) = __saturatef(src(ix, iy)); 95 | } 96 | 97 | 98 | gpu_image gpu_saturate( const gpu_image& src ) { 99 | gpu_image dst(src.size()); 100 | imp_saturate<<>>(src, dst); 101 | GPU_CHECK_ERROR(); 102 | return dst; 103 | } 104 | 105 | 106 | __global__ void imp_saturate( const gpu_plm2 src, gpu_plm2 dst ) { 107 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 108 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 109 | if (ix >= dst.w || iy >= dst.h) 110 | return; 111 | 112 | float4 c = src(ix, iy); 113 | dst(ix, iy) = make_float4(__saturatef(c.x), __saturatef(c.y),__saturatef(c.z), 1); 114 | } 115 | 116 | 117 | gpu_image gpu_saturate( const gpu_image& src ) { 118 | gpu_image dst(src.size()); 119 | imp_saturate<<>>(src, dst); 120 | GPU_CHECK_ERROR(); 121 | return dst; 122 | } 123 | 124 | 125 | __global__ void imp_lerp( const gpu_plm2 a, const gpu_plm2 b, gpu_plm2 dst, float t) { 126 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 127 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 128 | if (ix >= dst.w || iy >= dst.h) 129 | return; 130 | 131 | float4 ca = a(ix, iy); 132 | float4 cb = b(ix, iy); 133 | dst(ix, iy) = (1-t)*ca + t * cb; 134 | } 135 | 136 | 137 | gpu_image gpu_lerp( const gpu_image& a, const gpu_image& b, float t ) { 138 | assert(a.size() == b.size()); 139 | gpu_image dst(a.size()); 140 | imp_lerp<<>>( a, b, dst, t ); 141 | GPU_CHECK_ERROR(); 142 | return dst; 143 | } 144 | -------------------------------------------------------------------------------- /gpu/basic_image.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_math.h" 19 | #include "gpu_cache.h" 20 | #include 21 | 22 | enum pixel_type_t { 23 | PIXEL_TYPE_UCHAR = 0x11, 24 | PIXEL_TYPE_UCHAR2 = 0x12, 25 | PIXEL_TYPE_UCHAR4 = 0x14, 26 | PIXEL_TYPE_FLOAT = 0x21, 27 | PIXEL_TYPE_FLOAT2 = 0x22, 28 | PIXEL_TYPE_FLOAT4 = 0x24 29 | }; 30 | 31 | template unsigned pixel_type_id(); 32 | template <> inline unsigned pixel_type_id() { return PIXEL_TYPE_UCHAR; } 33 | template <> inline unsigned pixel_type_id() { return PIXEL_TYPE_UCHAR2; } 34 | template <> inline unsigned pixel_type_id() { return PIXEL_TYPE_UCHAR4; } 35 | template <> inline unsigned pixel_type_id() { return PIXEL_TYPE_FLOAT; } 36 | template <> inline unsigned pixel_type_id() { return PIXEL_TYPE_FLOAT2; } 37 | template <> inline unsigned pixel_type_id() { return PIXEL_TYPE_FLOAT4; } 38 | 39 | 40 | template class basic_image_data { 41 | public: 42 | basic_image_data( unsigned type_id, unsigned type_size, void *ptr, unsigned pitch, 43 | unsigned w, unsigned h, A allocator=A() ) 44 | : m_nrefs(1), 45 | m_type_id(type_id), 46 | m_type_size(type_size), 47 | m_ptr(ptr), 48 | m_pitch(pitch), 49 | m_w(w), 50 | m_h(h), 51 | m_shared(ptr != 0), 52 | m_allocator(allocator) 53 | { 54 | if (!m_shared) { 55 | m_allocator.alloc(&m_ptr, &m_pitch, m_type_size * m_w, m_h); 56 | } 57 | } 58 | 59 | void add_ref() { 60 | ++m_nrefs; 61 | } 62 | 63 | void release() { 64 | --m_nrefs; 65 | if (m_nrefs == 0) delete this; 66 | } 67 | 68 | unsigned type_id() const { return m_type_id; } 69 | unsigned type_size() const { return m_type_size; } 70 | void* ptr() const { return m_ptr; } 71 | unsigned pitch() const { return m_pitch; } 72 | unsigned w() const { return m_w; } 73 | unsigned h() const { return m_h; } 74 | 75 | protected: 76 | unsigned m_nrefs; 77 | unsigned m_type_id; 78 | unsigned m_type_size; 79 | void *m_ptr; 80 | unsigned m_pitch; 81 | unsigned m_w; 82 | unsigned m_h; 83 | bool m_shared; 84 | A m_allocator; 85 | 86 | ~basic_image_data() { 87 | if (!m_shared) { 88 | m_allocator.free(m_ptr, m_pitch, m_type_size * m_w, m_h); 89 | } 90 | m_ptr = 0; 91 | m_pitch = 0; 92 | } 93 | 94 | private: 95 | basic_image_data(const basic_image_data&); 96 | const basic_image_data& operator=(const basic_image_data&); 97 | }; 98 | 99 | 100 | template class basic_image { 101 | public: 102 | typedef basic_image_data data_type; 103 | 104 | basic_image() : m(0) 105 | { } 106 | 107 | basic_image(unsigned w, unsigned h, A allocator=A()) { 108 | m = new data_type(pixel_type_id(), sizeof(T), 0, 0, w, h, allocator); 109 | } 110 | 111 | basic_image(uint2 size, A allocator=A()) { 112 | m = new data_type(pixel_type_id(), sizeof(T), 0, 0, size.x, size.y, allocator); 113 | } 114 | 115 | basic_image(data_type *data) { 116 | m = 0; 117 | if (data && (data->type_id() == pixel_type_id())) { 118 | data->add_ref(); 119 | m = data; 120 | } 121 | } 122 | 123 | basic_image(const basic_image& img) { 124 | if (img.m) img.m->add_ref(); 125 | m = img.m; 126 | } 127 | 128 | ~basic_image() { 129 | if (m) m->release(); 130 | m = 0; 131 | } 132 | 133 | const basic_image& operator=(const basic_image& img) { 134 | if (img.m) img.m->add_ref(); 135 | if (m) m->release(); 136 | m = img.m; 137 | return *this; 138 | } 139 | 140 | void swap(basic_image& img) { 141 | data_type *tmp = m; 142 | m = img.m; 143 | img.m = tmp; 144 | } 145 | 146 | data_type* data() const { return m; } 147 | bool is_valid() const { return m && m->w() && m->h(); } 148 | 149 | const T* ptr() const { return (T*)m->ptr(); } 150 | T* ptr() { return (T*)m->ptr(); } 151 | const char* ptr8u() const { return (char*)m->ptr(); } 152 | char* ptr8u() { return (char*)m->ptr(); } 153 | unsigned pitch() const { return m->pitch(); } 154 | unsigned w() const { return m->w(); } 155 | unsigned h() const { return m->h(); } 156 | uint2 size() const { return make_uint2(m->w(), m->h()); } 157 | 158 | private: 159 | data_type *m; 160 | }; 161 | -------------------------------------------------------------------------------- /gpu/gpu_bilateral.cu: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_bilateral.h" 17 | 18 | 19 | static texture texSRC1; 20 | static texture texSRC4; 21 | 22 | template T texSRC(float x, float y); 23 | template<> inline __device__ float texSRC(float x, float y) { return tex2D(texSRC1, x, y); } 24 | template<> inline __device__ float4 texSRC(float x, float y) { return tex2D(texSRC4, x, y); } 25 | 26 | 27 | template 28 | __global__ void imp_bilateral_filter( gpu_plm2 dst, float sigma_d, float sigma_r, float precision ) { 29 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 30 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 31 | if (ix >= dst.w || iy >= dst.h) 32 | return; 33 | 34 | float twoSigmaD2 = 2.0f * sigma_d * sigma_d; 35 | float twoSigmaR2 = 2.0f * sigma_r * sigma_r; 36 | int halfWidth = int(ceilf( precision * sigma_d )); 37 | 38 | T c0 = texSRC(ix, iy); 39 | T sum = make_zero(); 40 | 41 | float norm = 0.0f; 42 | for ( int i = -halfWidth; i <= halfWidth; ++i ) { 43 | for ( int j = -halfWidth; j <= halfWidth; ++j ) { 44 | float d = length(make_float2(i,j)); 45 | 46 | T c = texSRC(ix + i, iy + j); 47 | T e = c - c0; 48 | 49 | float kd = __expf( -dot(d,d) / twoSigmaD2 ); 50 | float kr = __expf( -dot(e,e) / twoSigmaR2 ); 51 | 52 | sum += kd * kr * c; 53 | norm += kd * kr; 54 | } 55 | } 56 | sum /= norm; 57 | 58 | dst(ix, iy) = sum; 59 | } 60 | 61 | 62 | gpu_image gpu_bilateral_filter(const gpu_image& src, float sigma_d, float sigma_r, float precision ) { 63 | if (sigma_d <= 0) return src; 64 | gpu_image dst(src.size()); 65 | bind(&texSRC1, src); 66 | imp_bilateral_filter<<>>(dst, sigma_d, sigma_r, precision); 67 | GPU_CHECK_ERROR(); 68 | return dst; 69 | } 70 | 71 | 72 | gpu_image gpu_bilateral_filter(const gpu_image& src, float sigma_d, float sigma_r, float precision ) { 73 | if (sigma_d < 0) return src; 74 | gpu_image dst(src.size()); 75 | bind(&texSRC4, src); 76 | imp_bilateral_filter<<>>(dst, sigma_d, sigma_r, precision); 77 | GPU_CHECK_ERROR(); 78 | return dst; 79 | } 80 | 81 | 82 | template 83 | __global__ void imp_bilateral_filter_xy( gpu_plm2 dst, float sigma_d, float sigma_r, float precision ) { 84 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 85 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 86 | if (ix >= dst.w || iy >= dst.h) 87 | return; 88 | 89 | float twoSigmaD2 = 2 * sigma_d * sigma_d; 90 | float twoSigmaR2 = 2 * sigma_r * sigma_r; 91 | int halfWidth = int(ceilf( precision * sigma_d )); 92 | 93 | T c0 = texSRC(ix, iy); 94 | T sum = make_zero(); 95 | 96 | float norm = 0; 97 | for ( int i = -halfWidth; i <= halfWidth; ++i ) { 98 | T c = texSRC(ix + dx * i, iy + dy * i); 99 | T e = c - c0; 100 | 101 | float kd = __expf( -i * i / twoSigmaD2 ); 102 | float kr = __expf( -dot(e,e) / twoSigmaR2 ); 103 | 104 | sum += kd * kr * c; 105 | norm += kd * kr; 106 | } 107 | sum /= norm; 108 | 109 | dst(ix, iy) = sum; 110 | } 111 | 112 | 113 | gpu_image gpu_bilateral_filter_xy( const gpu_image& src, float sigma_d, float sigma_r, float precision ) { 114 | if (sigma_d <= 0) return src; 115 | gpu_image dst(src.size()); 116 | gpu_image tmp(src.size()); 117 | bind(&texSRC1, src); 118 | imp_bilateral_filter_xy<<>>(tmp, sigma_d, sigma_r, precision); 119 | GPU_CHECK_ERROR(); 120 | bind(&texSRC1, tmp); 121 | imp_bilateral_filter_xy<<>>(dst, sigma_d, sigma_r, precision); 122 | GPU_CHECK_ERROR(); 123 | return dst; 124 | } 125 | 126 | 127 | gpu_image gpu_bilateral_filter_xy( const gpu_image& src, float sigma_d, float sigma_r, float precision ) { 128 | if (sigma_d <= 0) return src; 129 | gpu_image dst(src.size()); 130 | gpu_image tmp(src.size()); 131 | bind(&texSRC4, src); 132 | imp_bilateral_filter_xy<<>>(tmp, sigma_d, sigma_r, precision); 133 | GPU_CHECK_ERROR(); 134 | bind(&texSRC4, tmp); 135 | imp_bilateral_filter_xy<<>>(dst, sigma_d, sigma_r, precision); 136 | GPU_CHECK_ERROR(); 137 | return dst; 138 | } 139 | -------------------------------------------------------------------------------- /util/videocontrols.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "videocontrols.h" 17 | 18 | 19 | VideoControls::VideoControls(QWidget *parent) : QFrame (parent) { 20 | setEnabled(false); 21 | m_isTracking = false; 22 | m_isPlaying = false; 23 | m_autoHide = false; 24 | 25 | m_hbox = new QHBoxLayout(this); 26 | m_hbox->setSizeConstraint(QLayout::SetMinimumSize); 27 | m_hbox->setContentsMargins(0,0,0,0); 28 | m_hbox->setSpacing(4); 29 | 30 | m_prevButton = new QToolButton(this); 31 | m_hbox->addWidget(m_prevButton); 32 | m_prevButton->setFixedSize(24, 24); 33 | m_prevButton->setAutoRaise(true); 34 | m_prevButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaSeekBackward)); 35 | 36 | m_playButton = new QToolButton(this);; 37 | m_hbox->addWidget(m_playButton); 38 | m_playButton->setFixedSize(24, 24); 39 | m_playButton->setAutoRaise(true); 40 | m_playButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaPlay)); 41 | 42 | m_nextButton = new QToolButton(this);; 43 | m_hbox->addWidget(m_nextButton); 44 | m_nextButton->setFixedSize(24, 24); 45 | m_nextButton->setAutoRaise(true); 46 | m_nextButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaSeekForward)); 47 | 48 | m_frameSlider = new QSlider(this); 49 | m_hbox->addWidget(m_frameSlider); 50 | m_frameSlider->setMinimumHeight(24); 51 | m_frameSlider->setRange(0,0); 52 | m_frameSlider->setFocusPolicy(Qt::NoFocus); 53 | m_frameSlider->setOrientation(Qt::Horizontal); 54 | m_frameSlider->setTracking(false); 55 | 56 | m_frameEdit = new QSpinBox(this); 57 | m_hbox->addWidget(m_frameEdit); 58 | m_frameEdit->setMinimumHeight(24); 59 | m_frameEdit->setRange(0,0); 60 | m_frameEdit->setButtonSymbols(QAbstractSpinBox::NoButtons); 61 | m_frameEdit->setAlignment(Qt::AlignCenter); 62 | m_frameEdit->setKeyboardTracking(false); 63 | 64 | connect(m_prevButton, SIGNAL(clicked()), this, SIGNAL(stepBack())); 65 | connect(m_playButton, SIGNAL(clicked()), this, SLOT(toogle())); 66 | connect(m_nextButton, SIGNAL(clicked()), this, SIGNAL(stepForward())); 67 | 68 | connect(m_frameSlider, SIGNAL(valueChanged(int)), this, SIGNAL(currentFrameChanged(int))); 69 | connect(m_frameSlider, SIGNAL(sliderMoved(int)), this, SIGNAL(currentFrameTracked(int))); 70 | connect(m_frameSlider, SIGNAL(sliderPressed()), this, SLOT(handleSliderPressed())); 71 | connect(m_frameSlider, SIGNAL(sliderReleased()), this, SLOT(handleSliderReleased())); 72 | 73 | connect(m_frameEdit, SIGNAL(valueChanged(int)), this, SIGNAL(currentFrameChanged(int))); 74 | } 75 | 76 | 77 | VideoControls::~VideoControls() { 78 | } 79 | 80 | 81 | void VideoControls::setAutoHide(bool hide) { 82 | if (m_autoHide != hide) { 83 | m_autoHide = hide; 84 | this->setVisible(!m_autoHide || (m_frameSlider->maximum() > 0)); 85 | } 86 | } 87 | 88 | 89 | void VideoControls::setFrameCount(int nframes) { 90 | this->setEnabled(nframes > 1); 91 | m_frameSlider->setMaximum(nframes - 1); 92 | m_frameEdit->setMaximum(nframes - 1); 93 | this->setVisible(!m_autoHide || (nframes > 1)); 94 | } 95 | 96 | 97 | void VideoControls::setCurrentFrame(int frame) { 98 | m_frameSlider->setValue(frame); 99 | m_frameEdit->setValue(frame); 100 | } 101 | 102 | 103 | void VideoControls::setPlayback(bool playing) { 104 | if (m_isPlaying != playing) { 105 | m_isPlaying = playing; 106 | if (m_isPlaying) { 107 | m_playButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaPause)); 108 | } else { 109 | m_playButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaPlay)); 110 | } 111 | m_nextButton->setEnabled(!m_isPlaying); 112 | m_prevButton->setEnabled(!m_isPlaying); 113 | m_frameSlider->setEnabled(!m_isPlaying); 114 | m_frameEdit->setEnabled(!m_isPlaying); 115 | playbackChanged(m_isPlaying); 116 | if (m_isPlaying) { 117 | playbackStarted(); 118 | } else { 119 | playbackPaused(); 120 | } 121 | } 122 | } 123 | 124 | 125 | void VideoControls::play() { 126 | setPlayback(true); 127 | } 128 | 129 | 130 | void VideoControls::pause() { 131 | setPlayback(false); 132 | } 133 | 134 | 135 | void VideoControls::toogle() { 136 | if (m_isPlaying) { 137 | pause(); 138 | } else { 139 | play(); 140 | } 141 | } 142 | 143 | 144 | void VideoControls::handleSliderPressed() { 145 | m_isTracking = true; 146 | trackingChanged(true); 147 | trackingStarted(); 148 | } 149 | 150 | void VideoControls::handleSliderReleased() { 151 | m_isTracking = false; 152 | trackingChanged(false); 153 | trackingStopped(); 154 | } -------------------------------------------------------------------------------- /gpu/gpu_minmax.cu: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_minmax.h" 17 | #include "gpu_util.h" 18 | #include "gpu_color.h" 19 | #include 20 | 21 | 22 | template 23 | __global__ void impl_minmax(float *dst, const gpu_plm2 src) { 24 | __shared__ float sdata[2 * nThreads]; 25 | 26 | unsigned int tmin = threadIdx.x; 27 | unsigned int tmax = threadIdx.x + nThreads; 28 | float myMin = FLT_MAX; 29 | float myMax = -FLT_MAX; 30 | 31 | unsigned o = blockIdx.x * src.stride; 32 | while (o < src.h * src.stride) { 33 | unsigned int i = threadIdx.x; 34 | while (i < src.w) { 35 | volatile float v = src.ptr[o+i]; 36 | myMin = fminf(myMin, v); 37 | myMax = fmaxf(myMax, v); 38 | i += nThreads; 39 | } 40 | o += nBlocks * src.stride; 41 | } 42 | 43 | sdata[tmin] = myMin; 44 | sdata[tmax] = myMax; 45 | __syncthreads(); 46 | 47 | if (nThreads >= 512) { if (tmin < 256) { sdata[tmin] = myMin = fminf(myMin, sdata[tmin + 256]); 48 | sdata[tmax] = myMax = fmaxf(myMax, sdata[tmax + 256]); } __syncthreads(); } 49 | if (nThreads >= 256) { if (tmin < 128) { sdata[tmin] = myMin = fminf(myMin, sdata[tmin + 128]); 50 | sdata[tmax] = myMax = fmaxf(myMax, sdata[tmax + 128]); } __syncthreads(); } 51 | if (nThreads >= 128) { if (tmin < 64) { sdata[tmin] = myMin = fminf(myMin, sdata[tmin + 64]); 52 | sdata[tmax] = myMax = fmaxf(myMax, sdata[tmax + 64]); } __syncthreads(); } 53 | 54 | if (tmin < 32) { 55 | volatile float* smem = sdata; 56 | if (nThreads >= 64) { smem[tmin] = myMin = fminf(myMin, smem[tmin + 32]); 57 | smem[tmax] = myMax = fmaxf(myMax, smem[tmax + 32]); } 58 | if (nThreads >= 32) { smem[tmin] = myMin = fminf(myMin, smem[tmin + 16]); 59 | smem[tmax] = myMax = fmaxf(myMax, smem[tmax + 16]); } 60 | if (nThreads >= 16) { smem[tmin] = myMin = fminf(myMin, smem[tmin + 8]); 61 | smem[tmax] = myMax = fmaxf(myMax, smem[tmax + 8]); } 62 | if (nThreads >= 8) { smem[tmin] = myMin = fminf(myMin, smem[tmin + 4]); 63 | smem[tmax] = myMax = fmaxf(myMax, smem[tmax + 4]); } 64 | if (nThreads >= 4) { smem[tmin] = myMin = fminf(myMin, smem[tmin + 2]); 65 | smem[tmax] = myMax = fmaxf(myMax, smem[tmax + 2]); } 66 | if (nThreads >= 2) { smem[tmin] = myMin = fminf(myMin, smem[tmin + 1]); 67 | smem[tmax] = myMax = fmaxf(myMax, smem[tmax + 1]); } 68 | } 69 | 70 | if (tmin == 0) { 71 | dst[blockIdx.x] = sdata[0]; 72 | dst[blockIdx.x + nBlocks] = sdata[0 + nThreads]; 73 | } 74 | } 75 | 76 | 77 | void gpu_minmax(const gpu_image& src, float *pmin, float *pmax) { 78 | const unsigned nBlocks = 64; 79 | const unsigned nThreads = 128; 80 | 81 | static float *dst_gpu = 0; 82 | static float *dst_cpu = 0; 83 | if (!dst_cpu) { 84 | cudaMalloc(&dst_gpu, 2 * sizeof(float)*nBlocks); 85 | cudaMallocHost(&dst_cpu, 2 * sizeof(float)*nBlocks, cudaHostAllocPortable); 86 | } 87 | 88 | dim3 dimBlock(nThreads, 1, 1); 89 | dim3 dimGrid(nBlocks, 1, 1); 90 | impl_minmax<<< dimGrid, dimBlock >>>(dst_gpu, src); 91 | cudaMemcpy(dst_cpu, dst_gpu, 2*sizeof(float)*nBlocks, cudaMemcpyDeviceToHost); 92 | 93 | if (pmin) { 94 | float m = dst_cpu[0]; 95 | for (int i = 1; i < nBlocks; ++i) m = fminf(m, dst_cpu[i]); 96 | *pmin = m; 97 | } 98 | if (pmax) { 99 | float m = dst_cpu[nBlocks]; 100 | for (int i = 1; i < nBlocks; ++i) m = fmaxf(m, dst_cpu[nBlocks+i]); 101 | *pmax = m; 102 | } 103 | } 104 | 105 | 106 | float gpu_min( const gpu_image& src ) { 107 | float m; 108 | gpu_minmax(src, &m, NULL); 109 | return m; 110 | } 111 | 112 | 113 | float gpu_max( const gpu_image& src ) { 114 | float m; 115 | gpu_minmax(src, NULL, &m); 116 | return m; 117 | } 118 | 119 | 120 | gpu_image gpu_normalize(const gpu_image& src) { 121 | float pmin, pmax; 122 | gpu_minmax(src, &pmin, &pmax); 123 | return gpu_adjust(src, 1.0f / (pmax - pmin), -pmin / (pmax - pmin)); 124 | } 125 | 126 | 127 | gpu_image gpu_normalize_gray(const gpu_image& src) { 128 | float pmin, pmax; 129 | gpu_image L = gpu_rgb2gray(src); 130 | gpu_minmax(L, &pmin, &pmax); 131 | float a = 1.0f / (pmax - pmin); 132 | float b = -pmin / (pmax - pmin); 133 | return gpu_adjust(src, make_float4(a,a,a,1), make_float4(b,b,b,0)); 134 | } 135 | -------------------------------------------------------------------------------- /gpu/gpu_stgauss2.h: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #pragma once 17 | 18 | #include "gpu_image.h" 19 | #include 20 | 21 | gpu_image gpu_stgauss2_filter( const gpu_image& src, const gpu_image& st, 22 | float sigma, float max_angle, bool adaptive, 23 | bool src_linear, bool st_linear, int order, float step_size, 24 | float precision ); 25 | 26 | gpu_image gpu_stgauss2_filter( const gpu_image& src, const gpu_image& st, 27 | float sigma, float max_angle, bool adaptive, 28 | bool src_linear, bool st_linear, int order, float step_size, 29 | float precision ); 30 | 31 | std::vector gpu_stgauss2_path( int ix, int iy, const cpu_image& st, 32 | float sigma, float max_angle, bool adaptive, 33 | bool st_linear, int order, float step_size, 34 | float precision ); 35 | 36 | 37 | template 38 | inline __host__ __device__ void st_integrate_euler( float2 p0, const ST& st, F& f, float cos_max, 39 | unsigned w, unsigned h, float step_size ) 40 | { 41 | f(0, 0, p0); 42 | float2 v0 = st2tangent(st(p0.x, p0.y)); 43 | float sign = -1; 44 | do { 45 | float2 v = v0 * sign; 46 | float2 p = p0 + step_size * v; 47 | float u = step_size; 48 | while ((u < f.radius()) && 49 | (p.x >= 0) && (p.x < w) && (p.y >= 0) && (p.y < h)) 50 | { 51 | f(sign, u, p); 52 | 53 | float2 t = st2tangent(st(p.x, p.y)); 54 | float vt = dot(v, t); 55 | if (fabs(vt) <= cos_max) break; 56 | if (vt < 0) t = -t; 57 | 58 | v = t; 59 | p += step_size * t; 60 | u += step_size; 61 | } 62 | 63 | sign *= -1; 64 | } while (sign > 0); 65 | } 66 | 67 | 68 | template 69 | inline __host__ __device__ void st_integrate_rk2( float2 p0, const ST& st, F& f, float cos_max, 70 | unsigned w, unsigned h, float step_size ) 71 | { 72 | f(0, 0, p0); 73 | float2 v0 = st2tangent(st(p0.x, p0.y)); 74 | float sign = -1; 75 | do { 76 | float2 v = v0 * sign; 77 | float2 p = p0 + step_size * v; 78 | float u = step_size; 79 | while ((u < f.radius()) && 80 | (p.x >= 0) && (p.x < w) && (p.y >= 0) && (p.y < h)) 81 | { 82 | f(sign, u, p); 83 | 84 | float2 t = st2tangent(st(p.x, p.y)); 85 | float vt = dot(v, t); 86 | //if (fabs(vt) <= cos_max) break; 87 | if (vt < 0) t = -t; 88 | 89 | t = st2tangent(st(p.x + 0.5f * step_size * t.x, p.y + 0.5f * step_size * t.y)); 90 | vt = dot(v, t); 91 | if (fabs(vt) <= cos_max) break; 92 | if (vt < 0) t = -t; 93 | 94 | v = t; 95 | p += step_size * t; 96 | u += step_size; 97 | } 98 | 99 | sign *= -1; 100 | } while (sign > 0); 101 | } 102 | 103 | 104 | template 105 | inline __host__ __device__ void st_integrate_rk4( float2 p0, const ST& st, F& f, float cos_max, 106 | unsigned w, unsigned h, float step_size ) { 107 | f(0, 0, p0); 108 | float2 v0 = st2tangent(st(p0.x, p0.y)); 109 | float sign = -1; 110 | do { 111 | float2 v = v0 * sign; 112 | float2 p = p0 + step_size * v; 113 | float u = step_size; 114 | while ((u < f.radius()) && 115 | (p.x >= 0) && (p.x < w) && (p.y >= 0) && (p.y < h)) 116 | { 117 | f(sign, u, p); 118 | 119 | float2 k1 = st2tangent(st(p.x, p.y)); 120 | float vt = dot(v, k1); 121 | if (vt < 0) k1 = -k1; 122 | 123 | float2 k2 = st2tangent(st(p.x + 0.5f * step_size * k1.x, p.y + 0.5f * step_size * k1.y)); 124 | vt = dot(v, k2); 125 | if (vt < 0) k2 = -k2; 126 | 127 | float2 k3 = st2tangent(st(p.x + 0.5f * step_size * k2.x, p.y + 0.5f * step_size * k2.y)); 128 | vt = dot(v, k3); 129 | if (vt < 0) k3 = -k3; 130 | 131 | float2 k4 = st2tangent(st(p.x + step_size * k3.x, p.y + step_size * k3.y)); 132 | vt = dot(v, k4); 133 | if (vt < 0) k4 = -k4; 134 | 135 | float2 t = (k1 + 2*k2 + 2*k3 + k4) / 6.0f; 136 | vt = dot(v, t); 137 | if (fabs(vt) <= cos_max) break; 138 | v = t; 139 | p += step_size * t; 140 | u += step_size; 141 | } 142 | 143 | sign *= -1; 144 | } while (sign > 0); 145 | } 146 | -------------------------------------------------------------------------------- /gpu/gpu_etf.cu: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_etf.h" 17 | #include "gpu_minmax.h" 18 | 19 | 20 | texture texSRC1; 21 | texture texSRC2; 22 | 23 | 24 | __global__ void imp_etf_sobel( gpu_plm2 dst0, gpu_plm2 dst1 ) { 25 | const int ix = blockDim.x * blockIdx.x + threadIdx.x; 26 | const int iy = blockDim.y * blockIdx.y + threadIdx.y; 27 | if(ix >= dst0.w || iy >= dst0.h) 28 | return; 29 | 30 | float2 g; 31 | g.x = ( 32 | -0.183f * tex2D(texSRC1, ix-1, iy-1) + 33 | -0.634f * tex2D(texSRC1, ix-1, iy) + 34 | -0.183f * tex2D(texSRC1, ix-1, iy+1) + 35 | +0.183f * tex2D(texSRC1, ix+1, iy-1) + 36 | +0.634f * tex2D(texSRC1, ix+1, iy) + 37 | +0.183f * tex2D(texSRC1, ix+1, iy+1) 38 | ) * 0.5f; 39 | 40 | g.y = ( 41 | -0.183f * tex2D(texSRC1, ix-1, iy-1) + 42 | -0.634f * tex2D(texSRC1, ix, iy-1) + 43 | -0.183f * tex2D(texSRC1, ix+1, iy-1) + 44 | +0.183f * tex2D(texSRC1, ix-1, iy+1) + 45 | +0.634f * tex2D(texSRC1, ix, iy+1) + 46 | +0.183f * tex2D(texSRC1, ix+1, iy+1) 47 | ) * 0.5f; 48 | 49 | float len = length(g); 50 | if (len > 0) 51 | g /= len; 52 | 53 | dst0(ix, iy) = make_float2(-g.y, g.x); 54 | dst1(ix, iy) = len; 55 | } 56 | 57 | 58 | __global__ void imp_etf_smooth_full( gpu_plm2 dst, float sigma, float precision, bool gaussian ) { 59 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 60 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 61 | if(ix >= dst.w || iy >= dst.h) 62 | return; 63 | 64 | int halfWidth = int(ceilf( precision * sigma )); 65 | 66 | float2 p0 = tex2D(texSRC2, ix, iy); 67 | float z0 = tex2D(texSRC1, ix, iy); 68 | float2 g = make_float2(0); 69 | 70 | for ( int i = -halfWidth; i <= halfWidth; ++i ) { 71 | for ( int j = -halfWidth; j <= halfWidth; ++j ) { 72 | float d = length(make_float2(i,j)); 73 | if (d <= halfWidth) { 74 | float2 p = tex2D(texSRC2, ix + i, iy + j); 75 | float z = tex2D(texSRC1, ix + i, iy + j); 76 | 77 | float wm = 0.5f * (z - z0 + 1); 78 | float wd = dot(p0, p); 79 | float w = wm * wd; 80 | 81 | if (gaussian) w *= __expf( -0.5f * d *d / sigma / sigma ); 82 | 83 | g += w * p; 84 | } 85 | } 86 | } 87 | 88 | float len = length(g); 89 | if (len > 0) 90 | g /= len; 91 | 92 | dst(ix, iy) = make_float2(g.x, g.y); 93 | } 94 | 95 | 96 | template 97 | __global__ void imp_etf_smooth_xy( gpu_plm2 dst, float sigma, float precision ) { 98 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 99 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 100 | if(ix >= dst.w || iy >= dst.h) 101 | return; 102 | 103 | int halfWidth = int(ceilf( precision * sigma )); 104 | 105 | float2 p0 = tex2D(texSRC2, ix, iy); 106 | float z0 = tex2D(texSRC1, ix, iy); 107 | float2 g = make_float2(0); 108 | 109 | for ( int i = -halfWidth; i <= halfWidth; ++i ) { 110 | float2 p = tex2D(texSRC2, ix + dx * i, iy + dy * i); 111 | float z = tex2D(texSRC1, ix + dx * i, iy + dy * i); 112 | 113 | float wm = 0.5f * (z - z0 + 1); 114 | float wd = dot(p0, p); 115 | float w = wm * wd; 116 | 117 | g += w * p; 118 | } 119 | 120 | float len = length(g); 121 | if (len > 0) 122 | g /= len; 123 | 124 | dst(ix, iy) = make_float2(g.x, g.y); 125 | } 126 | 127 | 128 | gpu_image gpu_etf_full( const gpu_image& src, float sigma, int N, 129 | float precision, bool gaussian ) 130 | { 131 | gpu_image etf(src.size()); 132 | gpu_image mag(src.size()); 133 | { 134 | bind(&texSRC1, src); 135 | imp_etf_sobel<<>>(etf, mag); 136 | GPU_CHECK_ERROR(); 137 | 138 | float pmax; 139 | gpu_minmax(mag, 0, &pmax); 140 | if (pmax > 0) mag = gpu_mul(mag, 1 / pmax); 141 | } 142 | 143 | bind(&texSRC1, mag); 144 | for (int k = 0; k < N; ++k) { 145 | gpu_image tmp(src.size()); 146 | bind(&texSRC2, etf); 147 | imp_etf_smooth_full<<>>(tmp, sigma, precision, gaussian); 148 | GPU_CHECK_ERROR(); 149 | etf = tmp; 150 | } 151 | 152 | return etf; 153 | } 154 | 155 | 156 | gpu_image gpu_etf_xy(const gpu_image& src, float sigma, int N, float precision) { 157 | gpu_image etf(src.size()); 158 | gpu_image mag(src.size()); 159 | { 160 | bind(&texSRC1, src); 161 | imp_etf_sobel<<>>(etf, mag); 162 | GPU_CHECK_ERROR(); 163 | 164 | float pmax; 165 | gpu_minmax(mag, 0, &pmax); 166 | if (pmax > 0) mag = gpu_mul(mag, 1 / pmax); 167 | } 168 | 169 | bind(&texSRC1, mag); 170 | for (int k = 0; k < N; ++k) { 171 | gpu_image tmp(src.size()); 172 | bind(&texSRC2, etf); 173 | imp_etf_smooth_xy<1,0><<>>(tmp, sigma, precision); 174 | GPU_CHECK_ERROR(); 175 | 176 | bind(&texSRC2, tmp); 177 | imp_etf_smooth_xy<0,1><<>>(etf, sigma, precision); 178 | GPU_CHECK_ERROR(); 179 | } 180 | 181 | return etf; 182 | } 183 | -------------------------------------------------------------------------------- /util/rolloutbox.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "rolloutbox.h" 17 | 18 | 19 | RolloutBox::RolloutBox(QWidget *parent) : QFrame(parent) { 20 | m_checkable = false; 21 | m_checked = true; 22 | 23 | m_layout = new QGridLayout(this); 24 | m_layout->setContentsMargins(0,0,0,0); 25 | m_layout->setSpacing(4); 26 | m_layout->setColumnStretch(0, 50); 27 | m_layout->setColumnStretch(1, 50); 28 | m_toolButton = 0; 29 | m_expanded = true; 30 | 31 | m_toolButton = new QToolButton(this); 32 | m_layout->addWidget(m_toolButton, 0, 0); 33 | m_toolButton->setFocusPolicy(Qt::NoFocus); 34 | m_toolButton->setText("open/close"); 35 | m_toolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); 36 | m_toolButton->setVisible(false); 37 | m_toolButton->setAutoRaise(true); 38 | m_toolButton->setFixedHeight(fontMetrics().height()+6); 39 | m_toolButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); 40 | m_toolButton->setArrowType(Qt::DownArrow); 41 | QFont font(m_toolButton->font()); 42 | font.setWeight(99); 43 | m_toolButton->setFont(font); 44 | connect(m_toolButton, SIGNAL(clicked()), this, SLOT(toggle())); 45 | 46 | m_checkBox = new QCheckBox(this); 47 | m_checkBox->setChecked(true); 48 | m_checkBox->setVisible(false); 49 | m_checkBox->setFixedHeight(20); 50 | m_checkBox->setText("enable"); 51 | m_layout->addWidget(m_checkBox, 0,1); 52 | connect(m_checkBox, SIGNAL(toggled(bool)), this, SLOT(setChecked(bool))); 53 | } 54 | 55 | 56 | void RolloutBox::saveSettings(QSettings& settings) { 57 | settings.setValue("expanded", isExpanded()); 58 | saveSettings(settings, this); 59 | } 60 | 61 | 62 | void RolloutBox::restoreSettings(QSettings& settings) { 63 | setExpanded(settings.value("expanded", true).toBool()); 64 | restoreSettings(settings, this); 65 | } 66 | 67 | 68 | void RolloutBox::saveSettings(QSettings& settings, QObject *obj) { 69 | const QObjectList& L = obj->children(); 70 | for (int i = 0; i < L.size(); ++i) { 71 | RolloutBox *b = qobject_cast(L[i]); 72 | if (b) { 73 | settings.beginGroup(b->objectName()); 74 | b->saveSettings(settings); 75 | settings.endGroup(); 76 | } 77 | } 78 | } 79 | 80 | 81 | void RolloutBox::restoreSettings(QSettings& settings, QObject *obj) { 82 | const QObjectList& L = obj->children(); 83 | for (int i = 0; i < L.size(); ++i) { 84 | RolloutBox *b = qobject_cast(L[i]); 85 | if (b) { 86 | settings.beginGroup(b->objectName()); 87 | b->restoreSettings(settings); 88 | settings.endGroup(); 89 | } 90 | } 91 | } 92 | 93 | 94 | void RolloutBox::setFrame(bool frame) { 95 | if (frame) { 96 | setFrameShape(QFrame::StyledPanel); 97 | m_layout->setContentsMargins(4,4,4,4); 98 | } else { 99 | setFrameShape(QFrame::NoFrame); 100 | m_layout->setContentsMargins(0,0,0,0); 101 | } 102 | } 103 | 104 | 105 | void RolloutBox::setTitle(const QString &title) { 106 | if (!title.isEmpty()) { 107 | setFrame(true); 108 | } 109 | m_toolButton->setText(title); 110 | m_toolButton->setVisible(!title.isEmpty()); 111 | m_checkBox->setVisible(!title.isEmpty() && m_checkable); 112 | } 113 | 114 | 115 | void RolloutBox::setCheckable(bool checkable) { 116 | m_checkable = checkable; 117 | m_checkBox->setVisible(!m_toolButton->text().isEmpty() && m_checkable); 118 | } 119 | 120 | 121 | void RolloutBox::setChecked(bool checked) { 122 | if (m_checked != checked) { 123 | m_checked = checked; 124 | m_checkBox->setChecked(checked); 125 | QList L = findChildren(); 126 | for (int i = 0; i < L.size(); ++i) { 127 | if ((L[i] != m_toolButton) && (L[i] != m_checkBox)) L[i]->setEnabled(checked); 128 | } 129 | checkChanged(m_checked); 130 | } 131 | } 132 | 133 | 134 | void RolloutBox::setExpanded(bool expanded) { 135 | if (m_expanded != expanded) { 136 | QScrollArea *sa = 0; 137 | QWidget *p = parentWidget(); 138 | while (p) { 139 | sa = qobject_cast(p); 140 | if (sa) break; 141 | p = p->parentWidget(); 142 | } 143 | 144 | bool areUpdatesEnabled; 145 | if (sa) { 146 | areUpdatesEnabled = updatesEnabled(); 147 | sa->setUpdatesEnabled(false); 148 | } 149 | 150 | m_expanded = !m_expanded; 151 | QList L = findChildren(); 152 | for (int i = 0; i < L.size(); ++i) { 153 | if ((L[i] != m_toolButton) && (L[i] != m_checkBox)) L[i]->setVisible(m_expanded); 154 | } 155 | parentWidget()->updateGeometry(); 156 | 157 | if (sa) { 158 | qApp->processEvents(); 159 | if (m_expanded) sa->ensureWidgetVisible(this); 160 | sa->setUpdatesEnabled(true); 161 | } 162 | 163 | if (m_toolButton) { 164 | m_toolButton->setArrowType(m_expanded? Qt::DownArrow : Qt::RightArrow); 165 | } 166 | 167 | toggled(m_expanded); 168 | } 169 | } 170 | 171 | 172 | void RolloutBox::toggle() { 173 | setExpanded(!m_expanded); 174 | } 175 | 176 | 177 | QWidgetList RolloutBox::widgets() const { 178 | QWidgetList W; 179 | QList L = findChildren(); 180 | for (int i = 0; i < L.size(); ++i) { 181 | if ((L[i] != m_toolButton) && (L[i] != m_checkBox)) W.append(L[i]); 182 | } 183 | return W; 184 | } 185 | 186 | 187 | void RolloutBox::addWidget(QWidget *w) { 188 | w->setParent(this); 189 | m_layout->addWidget(w, m_layout->rowCount(), 0, 1, 2); 190 | } 191 | 192 | 193 | void RolloutBox::addWidget(QWidget *left, QWidget *right) { 194 | left->setParent(this); 195 | right->setParent(this); 196 | m_layout->addWidget(left, m_layout->rowCount(), 0, Qt::AlignRight); 197 | m_layout->addWidget(right, m_layout->rowCount()-1, 1); 198 | } 199 | -------------------------------------------------------------------------------- /gpu/gpu_dog.cu: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_dog.h" 17 | 18 | 19 | static texture texSRC1; 20 | static texture texSRC4; 21 | 22 | 23 | __global__ void imp_isotropic_dog( gpu_plm2 dst, float sigma, float k, float tau, float precision ) { 24 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 25 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 26 | if (ix >= dst.w || iy >= dst.h) 27 | return; 28 | 29 | float twoSigmaE2 = 2.0f * sigma * sigma; 30 | float twoSigmaR2 = twoSigmaE2 * k * k; 31 | int halfWidth = int(ceilf( precision * sigma * k )); 32 | 33 | float sumE = 0; 34 | float sumR = 0; 35 | float2 norm = make_float2(0); 36 | 37 | for ( int i = -halfWidth; i <= halfWidth; ++i ) { 38 | for ( int j = -halfWidth; j <= halfWidth; ++j ) { 39 | float d = length(make_float2(i,j)); 40 | float kE = __expf(-d *d / twoSigmaE2); 41 | float kR = __expf(-d *d / twoSigmaR2); 42 | 43 | float c = tex2D(texSRC1, ix + i, iy + j); 44 | sumE += kE * c; 45 | sumR += kR * c; 46 | norm += make_float2(kE, kR); 47 | } 48 | } 49 | 50 | sumE /= norm.x; 51 | sumR /= norm.y; 52 | 53 | float H = sumE - tau * sumR; 54 | dst(ix, iy) = H; 55 | } 56 | 57 | 58 | gpu_image gpu_isotropic_dog( const gpu_image& src, float sigma, float k, float tau, float precision ) 59 | { 60 | gpu_image dst(src.size()); 61 | bind(&texSRC1, src); 62 | imp_isotropic_dog<<>>(dst, sigma, k, tau, precision); 63 | GPU_CHECK_ERROR(); 64 | return dst; 65 | } 66 | 67 | 68 | __global__ void imp_gradient_dog( gpu_plm2 dst, const gpu_plm2 tfab, 69 | float sigma, float k, float tau, float precision) 70 | { 71 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 72 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 73 | if (ix >= dst.w || iy >= dst.h) 74 | return; 75 | 76 | float4 t = tfab(ix, iy); 77 | float2 n = make_float2(t.y, -t.x); 78 | float2 nabs = fabs(n); 79 | float ds = 1.0f / ((nabs.x > nabs.y)? nabs.x : nabs.y); 80 | 81 | float twoSigmaE2 = 2 * sigma * sigma; 82 | float twoSigmaR2 = twoSigmaE2 * k * k; 83 | float halfWidth = ceilf(precision * sigma * k); 84 | 85 | float sumE = tex2D(texSRC1, ix, iy); 86 | float sumR = sumE; 87 | float2 norm = make_float2(1, 1); 88 | 89 | for( float d = ds; d <= halfWidth; d += ds ) { 90 | float kE = __expf( -d * d / twoSigmaE2 ); 91 | float kR = __expf( -d * d / twoSigmaR2 ); 92 | 93 | float2 o = d*n; 94 | float c = tex2D( texSRC1, 0.5f + ix - o.x, 0.5f + iy - o.y) + 95 | tex2D( texSRC1, 0.5f + ix + o.x, 0.5f + iy + o.y); 96 | sumE += kE * c; 97 | sumR += kR * c; 98 | norm += 2 * make_float2(kE, kR); 99 | } 100 | sumE /= norm.x; 101 | sumR /= norm.y; 102 | 103 | float H = sumE - tau * sumR; 104 | dst(ix, iy) = H; 105 | } 106 | 107 | 108 | gpu_image gpu_gradient_dog( const gpu_image& src, const gpu_image& tfab, 109 | float sigma, float k, float tau, float precision) 110 | { 111 | gpu_image dst(src.size()); 112 | bind(&texSRC1, src); 113 | texSRC1.filterMode = cudaFilterModeLinear; 114 | imp_gradient_dog<<>>(dst, tfab, sigma, k, tau, precision); 115 | texSRC1.filterMode = cudaFilterModePoint; 116 | GPU_CHECK_ERROR(); 117 | return dst; 118 | } 119 | 120 | 121 | __global__ void imp_dog_threshold_tanh( const gpu_plm2 src, gpu_plm2 dst, float epsilon, float phi ) 122 | { 123 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 124 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 125 | if (ix >= dst.w || iy >= dst.h) 126 | return; 127 | 128 | float H = src(ix, iy); 129 | float edge = ( H > epsilon )? 1 : 1 + tanh( phi * (H - epsilon)); 130 | dst(ix, iy) = clamp(edge, 0.0f, 1.0f); 131 | } 132 | 133 | 134 | gpu_image gpu_dog_threshold_tanh( const gpu_image& src, float epsilon, float phi ) { 135 | if (phi <= 0) 136 | return src; 137 | 138 | gpu_image dst(src.size()); 139 | imp_dog_threshold_tanh<<>>(src, dst, epsilon, phi); 140 | GPU_CHECK_ERROR(); 141 | return dst; 142 | } 143 | 144 | 145 | __global__ void imp_dog_threshold_smoothstep( const gpu_plm2 src, gpu_plm2 dst, float epsilon, float phi ) 146 | { 147 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 148 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 149 | if (ix >= dst.w || iy >= dst.h) 150 | return; 151 | 152 | float H = src(ix, iy) - epsilon; 153 | float edge = ( H > 0 )? 1 : 2 * smoothstep(-2, 2, phi * H ); 154 | dst(ix, iy) = clamp(edge, 0.0f, 1.0f); 155 | } 156 | 157 | 158 | gpu_image gpu_dog_threshold_smoothstep( const gpu_image& src, float epsilon, float phi ) { 159 | if (phi <= 0) 160 | return src; 161 | 162 | gpu_image dst(src.size()); 163 | imp_dog_threshold_smoothstep<<>>(src, dst, epsilon, phi); 164 | GPU_CHECK_ERROR(); 165 | return dst; 166 | } 167 | 168 | 169 | __global__ void imp_dog_colorize( const gpu_plm2 src, gpu_plm2 dst ) 170 | { 171 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 172 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 173 | if(ix >= dst.w || iy >= dst.h) 174 | return; 175 | 176 | float H = clamp(src(ix, iy), -1.0f, 1.0f); 177 | dst(ix, iy) = make_float4( (H < 0)? -H : 0, (H > 0)? H : 0, 0, 1); 178 | } 179 | 180 | 181 | gpu_image gpu_dog_colorize( const gpu_image& src ) { 182 | gpu_image dst(src.size()); 183 | imp_dog_colorize<<>>(src, dst); 184 | GPU_CHECK_ERROR(); 185 | return dst; 186 | } 187 | -------------------------------------------------------------------------------- /gpu/gpu_stgauss2.cu: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_stgauss2.h" 17 | #include "gpu_st.h" 18 | #include "gpu_sampler.h" 19 | 20 | 21 | static texture s_texSRC1; 22 | static texture s_texSRC4; 23 | 24 | inline __host__ __device__ texture& texSRC1() { return s_texSRC1; } 25 | inline __host__ __device__ texture& texSRC4() { return s_texSRC4; } 26 | 27 | static texture s_texST; 28 | inline __host__ __device__ texture& texST() { return s_texST; } 29 | 30 | 31 | template 32 | struct stgauss2_filter { 33 | __device__ stgauss2_filter(const SRC& src, float sigma, float precision ) 34 | : src_(src) 35 | { 36 | radius_ = precision * sigma; 37 | twoSigma2_ = 2 * sigma * sigma; 38 | c_ = make_zero(); 39 | w_ = 0; 40 | } 41 | 42 | __device__ float radius() const { 43 | return radius_; 44 | } 45 | 46 | __device__ void operator()(float sign, float u, float2 p) { 47 | float k = __expf(-u * u / twoSigma2_); 48 | c_ += k * src_(p.x, p.y); 49 | w_ += k; 50 | } 51 | 52 | const SRC& src_; 53 | float radius_; 54 | float twoSigma2_; 55 | T c_; 56 | float w_; 57 | }; 58 | 59 | 60 | template 61 | __global__ void imp_stgauss2_filter( gpu_plm2 dst, SRC src, ST st, float sigma, float cos_max, 62 | bool adaptive, float step_size, float precision ) 63 | { 64 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 65 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 66 | if(ix >= dst.w || iy >= dst.h) 67 | return; 68 | 69 | float2 p0 = make_float2(ix + 0.5f, iy + 0.5f); 70 | if (adaptive) { 71 | float A = st2A(st(p0.x, p0.y)); 72 | sigma *= 0.25f * (1 + A)*(1 + A); 73 | } 74 | stgauss2_filter f(src, sigma, precision); 75 | if (order == 1) st_integrate_euler(p0, st, f, cos_max, dst.w, dst.h, step_size); 76 | if (order == 2) st_integrate_rk2(p0, st, f, cos_max, dst.w, dst.h, step_size); 77 | if (order == 4) st_integrate_rk4(p0, st, f, cos_max, dst.w, dst.h, step_size); 78 | dst(ix, iy) = f.c_ / f.w_; 79 | } 80 | 81 | 82 | gpu_image gpu_stgauss2_filter( const gpu_image& src, const gpu_image& st, 83 | float sigma, float max_angle, bool adaptive, 84 | bool src_linear, bool st_linear, int order, float step_size, 85 | float precision ) 86 | { 87 | if (sigma <= 0) return src; 88 | gpu_image dst(src.size()); 89 | 90 | gpu_sampler src_sampler(src, src_linear? cudaFilterModeLinear : cudaFilterModePoint); 91 | float cos_max = cosf(radians(max_angle)); 92 | 93 | if (src.size() == st.size()) { 94 | gpu_sampler st_sampler(st, st_linear? cudaFilterModeLinear : cudaFilterModePoint); 95 | if (order == 1) imp_stgauss2_filter<1,float><<>>(dst, src_sampler, st_sampler, sigma, cos_max, adaptive, step_size, precision); 96 | else if (order == 2) imp_stgauss2_filter<2,float><<>>(dst, src_sampler, st_sampler, sigma, cos_max, adaptive, step_size, precision); 97 | else if (order == 4) imp_stgauss2_filter<4,float><<>>(dst, src_sampler, st_sampler, sigma, cos_max, adaptive, step_size, precision); 98 | } else { 99 | float2 s = make_float2((float)st.w() / src.w(), (float)st.h() / src.h()); 100 | gpu_resampler st_sampler(st, s, st_linear? cudaFilterModeLinear : cudaFilterModePoint); 101 | if (order == 1) imp_stgauss2_filter<1,float><<>>(dst, src_sampler, st_sampler, sigma, cos_max, adaptive, step_size, precision); 102 | else if (order == 2) imp_stgauss2_filter<2,float><<>>(dst, src_sampler, st_sampler, sigma, cos_max, adaptive, step_size, precision); 103 | else if (order == 4) imp_stgauss2_filter<4,float><<>>(dst, src_sampler, st_sampler, sigma, cos_max, adaptive, step_size, precision); 104 | } 105 | GPU_CHECK_ERROR(); 106 | return dst; 107 | } 108 | 109 | 110 | gpu_image gpu_stgauss2_filter( const gpu_image& src, const gpu_image& st, 111 | float sigma, float max_angle, bool adaptive, 112 | bool src_linear, bool st_linear, int order, float step_size, 113 | float precision ) 114 | { 115 | if (sigma <= 0) return src; 116 | gpu_image dst(src.size()); 117 | 118 | gpu_sampler src_sampler(src, src_linear? cudaFilterModeLinear : cudaFilterModePoint); 119 | float cos_max = cosf(radians(max_angle)); 120 | 121 | if (src.size() == st.size()) { 122 | gpu_sampler st_sampler(st, st_linear? cudaFilterModeLinear : cudaFilterModePoint); 123 | if (order == 1) imp_stgauss2_filter<1,float4><<>>(dst, src_sampler, st_sampler, sigma, cos_max, adaptive, step_size, precision); 124 | else if (order == 2) imp_stgauss2_filter<2,float4><<>>(dst, src_sampler, st_sampler, sigma, cos_max, adaptive, step_size, precision); 125 | else if (order == 4) imp_stgauss2_filter<4,float4><<>>(dst, src_sampler, st_sampler, sigma, cos_max, adaptive, step_size, precision); 126 | } else { 127 | float2 s = make_float2((float)st.w() / src.w(), (float)st.h() / src.h()); 128 | gpu_resampler st_sampler(st, s, st_linear? cudaFilterModeLinear : cudaFilterModePoint); 129 | if (order == 1) imp_stgauss2_filter<1,float4><<>>(dst, src_sampler, st_sampler, sigma, cos_max, adaptive, step_size, precision); 130 | else if (order == 2) imp_stgauss2_filter<2,float4><<>>(dst, src_sampler, st_sampler, sigma, cos_max, adaptive, step_size, precision); 131 | else if (order == 4) imp_stgauss2_filter<4,float4><<>>(dst, src_sampler, st_sampler, sigma, cos_max, adaptive, step_size, precision); 132 | } 133 | GPU_CHECK_ERROR(); 134 | return dst; 135 | } 136 | -------------------------------------------------------------------------------- /gpu/gpu_gauss.cu: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_gauss.h" 17 | 18 | 19 | static texture texSRC1; 20 | static texture texSRC4; 21 | 22 | template T texSRC(float x, float y); 23 | template<> inline __device__ float texSRC(float x, float y) { return tex2D(texSRC1, x, y); } 24 | template<> inline __device__ float4 texSRC(float x, float y) { return tex2D(texSRC4, x, y); } 25 | 26 | static texture texSIGMA; 27 | struct texSIGMA_t { 28 | inline __device__ float operator()(int ix, int iy) { return tex2D(texSIGMA, ix, iy); } 29 | }; 30 | 31 | 32 | template 33 | __global__ void imp_gauss_filter( gpu_plm2 dst, float sigma, float precision ) { 34 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 35 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 36 | if(ix >= dst.w || iy >= dst.h) 37 | return; 38 | 39 | float twoSigma2 = 2.0f * sigma * sigma; 40 | int halfWidth = int(ceilf( precision * sigma )); 41 | 42 | T sum = make_zero(); 43 | float norm = 0; 44 | for ( int i = -halfWidth; i <= halfWidth; ++i ) { 45 | for ( int j = -halfWidth; j <= halfWidth; ++j ) { 46 | float d = length(make_float2(i,j)); 47 | float kernel = __expf( -d *d / twoSigma2 ); 48 | T c = texSRC(ix + i, iy + j); 49 | sum += kernel * c; 50 | norm += kernel; 51 | } 52 | } 53 | sum /= norm; 54 | 55 | dst(ix, iy) = sum; 56 | } 57 | 58 | 59 | gpu_image gpu_gauss_filter( const gpu_image& src, float sigma, float precision ) { 60 | gpu_image dst(src.size()); 61 | bind(&texSRC1, src); 62 | imp_gauss_filter<<>>(dst, sigma, precision); 63 | GPU_CHECK_ERROR(); 64 | return dst; 65 | } 66 | 67 | 68 | gpu_image gpu_gauss_filter( const gpu_image& src, float sigma, float precision ) { 69 | gpu_image dst(src.size()); 70 | bind(&texSRC4, src); 71 | imp_gauss_filter<<>>(dst, sigma, precision); 72 | GPU_CHECK_ERROR(); 73 | return dst; 74 | } 75 | 76 | 77 | template 78 | __global__ void imp_gauss_filter_xy( gpu_plm2 dst, float sigma, float precision ) { 79 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 80 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 81 | if (ix >= dst.w || iy >= dst.h) 82 | return; 83 | 84 | float twoSigma2 = 2.0f * sigma * sigma; 85 | int halfWidth = ceilf( precision * sigma ); 86 | 87 | T sum = texSRC(ix, iy); 88 | float norm = 1; 89 | for ( int i = 1; i <= halfWidth; ++i ) { 90 | float kernel = __expf( -i *i / twoSigma2 ); 91 | sum += kernel * (texSRC(ix + dx * i, iy + dy * i) + texSRC(ix - dx * i, iy - dy * i)); 92 | norm += 2 * kernel; 93 | } 94 | sum /= norm; 95 | 96 | dst(ix, iy) = sum; 97 | } 98 | 99 | 100 | gpu_image gpu_gauss_filter_xy( const gpu_image& src, float sigma, float precision ) { 101 | if (sigma <= 0) return src; 102 | gpu_image dst(src.size()); 103 | gpu_image tmp(src.size()); 104 | bind(&texSRC1, src); 105 | imp_gauss_filter_xy<<>>(tmp, sigma, precision); 106 | GPU_CHECK_ERROR(); 107 | bind(&texSRC1, tmp); 108 | imp_gauss_filter_xy<<>>(dst, sigma, precision); 109 | GPU_CHECK_ERROR(); 110 | return dst; 111 | } 112 | 113 | 114 | gpu_image gpu_gauss_filter_xy( const gpu_image& src, float sigma, float precision ) { 115 | if (sigma <= 0) return src; 116 | gpu_image dst(src.size()); 117 | gpu_image tmp(src.size()); 118 | bind(&texSRC4, src); 119 | imp_gauss_filter_xy<<>>(tmp, sigma, precision); 120 | GPU_CHECK_ERROR(); 121 | bind(&texSRC4, tmp); 122 | imp_gauss_filter_xy<<>>(dst, sigma, precision); 123 | GPU_CHECK_ERROR(); 124 | return dst; 125 | } 126 | 127 | 128 | // [0.216, 0.568, 0.216], sigma ~= 0.680 129 | template 130 | __global__ void imp_gauss_filter_3x3( gpu_plm2 dst ) { 131 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 132 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 133 | if (ix >= dst.w || iy >= dst.h) 134 | return; 135 | 136 | T sum = 137 | ( 0.046656f * texSRC(ix-1, iy-1) + 138 | 0.122688f * texSRC(ix, iy-1) + 139 | 0.046656f * texSRC(ix+1, iy-1) + 140 | 0.122688f * texSRC(ix-1, iy) + 141 | 0.322624f * texSRC(ix, iy) + 142 | 0.122688f * texSRC(ix+1, iy) + 143 | 0.046656f * texSRC(ix-1, iy+1) + 144 | 0.122688f * texSRC(ix, iy+1) + 145 | 0.046656f * texSRC(ix+1, iy+1) 146 | ); 147 | 148 | dst(ix, iy) = sum; 149 | } 150 | 151 | 152 | gpu_image gpu_gauss_filter_3x3( const gpu_image& src) { 153 | gpu_image dst(src.size()); 154 | bind(&texSRC4, src); 155 | imp_gauss_filter_3x3<<>>(dst); 156 | GPU_CHECK_ERROR(); 157 | return dst; 158 | } 159 | 160 | 161 | // [0.03134, 0.24, 0.45732, 0.24, 0.03134], sigma ~= 0.867 162 | template 163 | __global__ void imp_gauss_filter_5x5( gpu_plm2 dst ) { 164 | const float kernel[5][5] = { 165 | { 0.0009821956f, 0.0075216f, 0.0143324088f, 0.0075216f, 0.0009821956 }, 166 | { 0.0075216f, 0.0576f, 0.1097568f, 0.0576f, 0.0075216 }, 167 | { 0.0143324088f, 0.1097568f, 0.2091415824f, 0.1097568f, 0.0143324088 }, 168 | { 0.0075216f, 0.0576f, 0.1097568f, 0.0576f, 0.0075216 }, 169 | { 0.0009821956f, 0.0075216f, 0.0143324088f, 0.0075216f, 0.0009821956 } 170 | }; 171 | 172 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 173 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 174 | if (ix >= dst.w || iy >= dst.h) 175 | return; 176 | 177 | T sum = make_zero(); 178 | for ( int j = 0; j < 5; ++j ) { 179 | for ( int i = 0; i < 5; ++i ) { 180 | T c = texSRC(ix + i -2, iy + j - 2); 181 | sum += kernel[j][i] * c; 182 | } 183 | } 184 | 185 | dst(ix, iy) = sum; 186 | } 187 | 188 | 189 | gpu_image gpu_gauss_filter_5x5( const gpu_image& src) { 190 | gpu_image dst(src.size()); 191 | bind(&texSRC4, src); 192 | imp_gauss_filter_5x5<<>>(dst); 193 | GPU_CHECK_ERROR(); 194 | return dst; 195 | } 196 | -------------------------------------------------------------------------------- /util/cudadevicedialog.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "cudadevicedialog.h" 17 | #include "ui_cudadevicedialog.h" 18 | #include 19 | 20 | 21 | inline int ConvertSMVer2Cores(int major, int minor) { 22 | // Defines for GPU Architecture types (using the SM version to determine the # of cores per SM 23 | typedef struct { 24 | int SM; // 0xMm (hexidecimal notation), M = SM Major version, and m = SM minor version 25 | int Cores; 26 | } sSMtoCores; 27 | 28 | sSMtoCores nGpuArchCoresPerSM[] = 29 | { { 0x10, 8 }, 30 | { 0x11, 8 }, 31 | { 0x12, 8 }, 32 | { 0x13, 8 }, 33 | { 0x20, 32 }, 34 | { 0x21, 48 }, 35 | { -1, -1 } 36 | }; 37 | 38 | int index = 0; 39 | while (nGpuArchCoresPerSM[index].SM != -1) { 40 | if (nGpuArchCoresPerSM[index].SM == ((major << 4) + minor) ) { 41 | return nGpuArchCoresPerSM[index].Cores; 42 | } 43 | index++; 44 | } 45 | return -1; 46 | } 47 | 48 | 49 | 50 | CudaDeviceDialog::CudaDeviceDialog(QWidget *parent) 51 | : QDialog(parent) 52 | { 53 | m = new Ui_CudaDeviceDialog; 54 | m->setupUi(this); 55 | 56 | int deviceCount = 0; 57 | if (cudaGetDeviceCount(&deviceCount) == cudaSuccess) { 58 | for (int i = 0; i < deviceCount; ++i) { 59 | cudaDeviceProp p; 60 | cudaGetDeviceProperties(&p, i); 61 | m->comboBox->addItem(p.name); 62 | } 63 | } 64 | connect(m->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateInfo(int))); 65 | updateInfo(0); 66 | } 67 | 68 | 69 | void CudaDeviceDialog::updateInfo(int index) { 70 | m_infoText = ""; 71 | 72 | int deviceCount = 0; 73 | cudaGetDeviceCount(&deviceCount); 74 | 75 | cudaDeviceProp p; 76 | cudaGetDeviceProperties(&p, index); 77 | if (p.major == 9999 && p.minor == 9999) 78 | m_infoText += "

There is no device supporting CUDA

"; 79 | else if (deviceCount == 1) 80 | m_infoText += "

There is 1 device supporting CUDA

"; 81 | else 82 | m_infoText += QString("

There are %1 devices supporting CUDA

").arg(deviceCount); 83 | 84 | m_infoText += QString("

CUDA Driver/Runtime

"); 85 | m_infoText += ""; 86 | int driverVersion = 0, runtimeVersion = 0; 87 | cudaDriverGetVersion(&driverVersion); 88 | cudaRuntimeGetVersion(&runtimeVersion); 89 | QString error = "***ERROR*** >= 4.0 required"; 90 | addItem(1, "CUDA Driver Version:", 91 | QString("%1.%2 %3").arg(driverVersion/1000).arg(driverVersion%100) 92 | .arg((driverVersion >= 4000)? "" : error)); 93 | addItem(1, "CUDA Runtime Version:", 94 | QString("%1.%2 %3").arg(runtimeVersion/1000).arg(runtimeVersion%100) 95 | .arg((driverVersion >= 4000)? "" : error)); 96 | m_infoText += "
"; 97 | 98 | if (index < deviceCount) { 99 | m_infoText += QString("

Device %1: "%2"

").arg(index).arg(p.name); 100 | m_infoText += ""; 101 | addItem(1, "CUDA Capability Major/Minor version number:", 102 | QString("%1.%2").arg(p.major).arg(p.minor)); 103 | 104 | addItem(1, "Total amount of global memory:", QString("%1 MB").arg(p.totalGlobalMem / 1024 / 1024)); 105 | 106 | addItem(1, QString("%1 Multiprocessors x %2 CUDA Cores/MP:").arg(p.multiProcessorCount).arg(ConvertSMVer2Cores(p.major, p.minor)), 107 | QString("%1 CUDA Cores").arg(ConvertSMVer2Cores(p.major, p.minor) * p.multiProcessorCount)); 108 | 109 | addItem(1, "Total amount of constant memory:", QString("%1 bytes").arg(p.totalConstMem)); 110 | addItem(1, "Total amount of shared memory per block:", QString("%1 bytes").arg(p.sharedMemPerBlock)); 111 | addItem(1, "Total number of registers available per block:", QString("%1").arg(p.regsPerBlock)); 112 | addItem(1, "Warp size:", QString("%1").arg(p.warpSize)); 113 | addItem(1, "Maximum number of threads per block:", QString("%1").arg(p.maxThreadsPerBlock)); 114 | addItem(1, "Maximum sizes of each dimension of a block:", QString("%1 x %2 x %3") 115 | .arg(p.maxThreadsDim[0]) 116 | .arg(p.maxThreadsDim[1]) 117 | .arg(p.maxThreadsDim[2])); 118 | addItem(1, "Maximum sizes of each dimension of a grid:", QString("%1 x %2 x %3") 119 | .arg(p.maxGridSize[0]) 120 | .arg(p.maxGridSize[1]) 121 | .arg(p.maxGridSize[2])); 122 | addItem(1, "Maximum memory pitch:", QString("%1 bytes").arg(p.memPitch)); 123 | addItem(1, "Texture alignment:", QString("%1 bytes").arg(p.textureAlignment)); 124 | addItem(1, "Clock rate:", QString("%1 GHz").arg(p.clockRate * 1e-6f)); 125 | 126 | addItem(1, "Concurrent copy and execution:", p.deviceOverlap ? "yes" : "no"); 127 | addItem(1, "# of Asynchronous Copy Engines:", QString("%1").arg(p.asyncEngineCount)); 128 | addItem(1, "Run time limit on kernels:", p.kernelExecTimeoutEnabled ? "yes" : "no"); 129 | addItem(1, "Integrated:", p.integrated ? "yes" : "no"); 130 | addItem(1, "Support host page-locked memory mapping:", p.canMapHostMemory ? "yes" : "no"); 131 | 132 | addItem(1, "Compute mode:", p.computeMode == cudaComputeModeDefault ? 133 | "Default (multiple host threads can use this device simultaneously)" : 134 | p.computeMode == cudaComputeModeExclusive ? 135 | "Exclusive (only one host thread at a time can use this device)" : 136 | p.computeMode == cudaComputeModeProhibited ? 137 | "Prohibited (no host thread can use this device)" : 138 | "Unknown"); 139 | addItem(1, "Concurrent kernel execution:", p.concurrentKernels ? "yes" : "no"); 140 | addItem(1, "Device has ECC support enabled:", p.ECCEnabled ? "yes" : "no"); 141 | addItem(1, "Device is using TCC driver mode:", p.tccDriver ? "yes" : "no"); 142 | 143 | m_infoText += "
"; 144 | } 145 | m_infoText += ""; 146 | m->info->setHtml(m_infoText); 147 | 148 | m->buttonBox->button(QDialogButtonBox::Ok)->setEnabled((driverVersion >= 4000) && (runtimeVersion >= 4000)); 149 | } 150 | 151 | 152 | void CudaDeviceDialog::addItem(int pad, const QString& a, const QString& b) { 153 | m_infoText += ""; 154 | m_infoText += QString("").arg(30*pad); 155 | m_infoText += a; 156 | m_infoText += ""; 157 | m_infoText += b; 158 | m_infoText += ""; 159 | m_infoText += ""; 160 | } 161 | 162 | 163 | int CudaDeviceDialog::select(bool force) { 164 | QSettings settings; 165 | int N = force? -1 : settings.value("cudaDevice", -1).toInt(); 166 | 167 | if (N < 0) { 168 | int deviceCount = 0; 169 | if (cudaGetDeviceCount(&deviceCount) != cudaSuccess) { 170 | QMessageBox::critical(NULL, "Error", "cudaGetDeviceCount FAILED CUDA Driver and Runtime version may be mismatched!"); 171 | exit(1); 172 | } else { 173 | if (deviceCount == 0) { 174 | QMessageBox::critical(NULL, "Error", "No device supporting CUDA found."); 175 | exit(1); 176 | } 177 | } 178 | 179 | CudaDeviceDialog dlg(NULL); 180 | if (dlg.exec() == QDialog::Accepted) { 181 | N = dlg.m->comboBox->currentIndex(); 182 | } 183 | } 184 | 185 | if (N >= 0) { 186 | settings.setValue("cudaDevice", N); 187 | cudaSetDevice(N); 188 | cudaDeviceProp p; 189 | cudaGetDeviceProperties(&p, N); 190 | qDebug() << "Selected CUDA Device" << N << ":" << p.name; 191 | } 192 | return N; 193 | } 194 | -------------------------------------------------------------------------------- /gpu/gpu_wog.cu: -------------------------------------------------------------------------------- 1 | // 2 | // by Jan Eric Kyprianidis 3 | // Copyright (C) 2010-2012 Computer Graphics Systems Group at the 4 | // Hasso-Plattner-Institut, Potsdam, Germany 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | #include "gpu_wog.h" 17 | #include "gpu_color.h" 18 | #include "gpu_bilateral.h" 19 | #include "gpu_blend.h" 20 | #include "gpu_shuffle.h" 21 | #include "gpu_grad.h" 22 | #include "gpu_gauss.h" 23 | #include "gpu_binder.h" 24 | #include 25 | 26 | 27 | static texture texSRC1; 28 | static texture texSRC4; 29 | 30 | 31 | __global__ void imp_wog_dog( gpu_plm2 dst, float sigma_e, float sigma_r, 32 | float tau, float phi_e, float epsilon, float precision ) { 33 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 34 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 35 | if (ix >= dst.w || iy >= dst.h) 36 | return; 37 | 38 | float twoSigmaE2 = 2.0f * sigma_e * sigma_e; 39 | float twoSigmaR2 = 2.0f * sigma_r * sigma_r; 40 | int halfWidth = int(ceilf( precision * sigma_r )); 41 | 42 | float sumE = 0; 43 | float sumR = 0; 44 | float2 norm = make_float2(0); 45 | 46 | for ( int i = -halfWidth; i <= halfWidth; ++i ) { 47 | for ( int j = -halfWidth; j <= halfWidth; ++j ) { 48 | float d = length(make_float2(i,j)); 49 | float kE = __expf(-d *d / twoSigmaE2); 50 | float kR = __expf(-d *d / twoSigmaR2); 51 | 52 | float c = tex2D(texSRC1, ix + i, iy + j); 53 | sumE += kE * c; 54 | sumR += kR * c; 55 | norm += make_float2(kE, kR); 56 | } 57 | } 58 | 59 | sumE /= norm.x; 60 | sumR /= norm.y; 61 | 62 | float H = sumE - tau * sumR; 63 | float edge = ( H > epsilon )? 1 : 1 + tanhf( phi_e * (H - epsilon) ); 64 | dst(ix, iy) = clamp(edge, 0.0f, 1.0f); 65 | } 66 | 67 | 68 | gpu_image gpu_wog_dog( const gpu_image& src, float sigma_e, float sigma_r, 69 | float tau, float phi_e, float epsilon, float precision ) 70 | { 71 | gpu_image dst(src.size()); 72 | bind(&texSRC1, src); 73 | imp_wog_dog<<>>(dst, sigma_e, sigma_r, tau, phi_e, epsilon, precision); 74 | GPU_CHECK_ERROR(); 75 | return dst; 76 | } 77 | 78 | 79 | __global__ void imp_wog_luminance_quant( const gpu_plm2 src, gpu_plm2 dst, int nbins, float phi_q) { 80 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 81 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 82 | if (ix >= dst.w || iy >= dst.h) 83 | return; 84 | 85 | float3 c = make_float3(src(ix, iy)); 86 | float delta_q = 100.01f / nbins; 87 | float qn = delta_q * (floor(c.x / delta_q) + 0.5f); 88 | float qc = qn + 0.5f * delta_q * tanhf(phi_q * (c.x - qn)); 89 | dst(ix, iy) = make_float4( qc, c.y, c.z, 1 ); 90 | } 91 | 92 | 93 | gpu_image gpu_wog_luminance_quant( const gpu_image& src, int nbins, float phi_q) { 94 | gpu_image dst(src.size()); 95 | imp_wog_luminance_quant<<>>(src, dst, nbins, phi_q); 96 | GPU_CHECK_ERROR(); 97 | return dst; 98 | } 99 | 100 | 101 | __global__ void imp_wog_luminance_quant( gpu_plm2 dst, int nbins, 102 | float lambda_delta, float omega_delta, 103 | float lambda_phi, float omega_phi ) 104 | { 105 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 106 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 107 | if (ix >= dst.w || iy >= dst.h) 108 | return; 109 | 110 | float3 c = make_float3(tex2D(texSRC4, ix, iy)); 111 | float gx = 0.5f * (tex2D(texSRC4, ix - 1, iy).x - tex2D(texSRC4, ix + 1, iy).x); 112 | float gy = 0.5f * (tex2D(texSRC4, ix, iy - 1).x - tex2D(texSRC4, ix, iy + 1).x); 113 | float grad = sqrtf(gx * gx + gy * gy); 114 | grad = clamp(grad, lambda_delta, omega_delta); 115 | grad = (grad - lambda_delta) / (omega_delta - lambda_delta); 116 | 117 | float phi_q = lambda_phi + grad * (omega_phi - lambda_phi); 118 | float delta_q = 100.01f / nbins; 119 | float qn = delta_q * (floor(c.x / delta_q) + 0.5f); 120 | float qc = qn + 0.5f * delta_q * tanhf(phi_q * (c.x - qn)); 121 | 122 | dst(ix, iy) = make_float4( qc, c.y, c.z, 1 ); 123 | } 124 | 125 | 126 | gpu_image gpu_wog_luminance_quant( const gpu_image& src, int nbins, 127 | float lambda_delta, float omega_delta, 128 | float lambda_phi, float omega_phi ) 129 | { 130 | gpu_image dst(src.size()); 131 | gpu_binder src_(texSRC4, src); 132 | imp_wog_luminance_quant<<>>( dst, nbins, lambda_delta, omega_delta, 133 | lambda_phi, omega_phi ); 134 | GPU_CHECK_ERROR(); 135 | return dst; 136 | } 137 | 138 | 139 | __global__ void imp_wog_warp( gpu_plm2 dst, float phi_w ) 140 | { 141 | const int ix = __mul24(blockDim.x, blockIdx.x) + threadIdx.x; 142 | const int iy = __mul24(blockDim.y, blockIdx.y) + threadIdx.y; 143 | if (ix >= dst.w || iy >= dst.h) 144 | return; 145 | 146 | float gx = 0.5f * (tex2D(texSRC1, ix - 1, iy) - tex2D(texSRC1, ix + 1, iy)); 147 | float gy = 0.5f * (tex2D(texSRC1, ix, iy - 1) - tex2D(texSRC1, ix, iy + 1)); 148 | 149 | float4 c = tex2D(texSRC4, ix + gx * phi_w, iy + gy * phi_w); 150 | dst(ix, iy) = c; 151 | } 152 | 153 | 154 | gpu_image gpu_wog_warp(const gpu_image& src, gpu_image& edges, float phi_w) { 155 | gpu_image dst(src.size()); 156 | gpu_binder src_(texSRC4, src, cudaFilterModeLinear); 157 | gpu_binder edges_(texSRC1, edges); 158 | imp_wog_warp<<>>( dst, phi_w ); 159 | GPU_CHECK_ERROR(); 160 | return dst; 161 | } 162 | 163 | 164 | gpu_image gpu_wog_warp_sharp( const gpu_image& src, 165 | float sigma_w, float precision_w, float phi_w) 166 | { 167 | gpu_image S = gpu_grad_sobel_mag(src); 168 | S = gpu_gauss_filter_xy(S, sigma_w, precision_w); 169 | return gpu_wog_warp(src, S, phi_w); 170 | } 171 | 172 | 173 | gpu_image gpu_wog_abstraction( const gpu_image& src, int n_e, int n_a, 174 | float sigma_d, float sigma_r, 175 | float sigma_e1, float sigma_e2, float precision_e, 176 | float tau, float phi_e, float epsilon, 177 | bool adaptive_quant, 178 | int nbins, float phi_q, 179 | float lambda_delta, float omega_delta, 180 | float lambda_phi, float omega_phi, 181 | bool warp_sharp, float sigma_w, 182 | float precision_w, float phi_w ) 183 | { 184 | gpu_image img; 185 | gpu_image L; 186 | 187 | { 188 | img = gpu_rgb2lab(src); 189 | gpu_image E = img; 190 | gpu_image A = img; 191 | 192 | int N = std::max(n_e, n_a); 193 | for (int i = 0; i < N; ++i) { 194 | img = gpu_bilateral_filter(img, sigma_d, sigma_r); 195 | if (i == (n_e - 1)) E = img; 196 | if (i == (n_a - 1)) A = img; 197 | } 198 | img = A; 199 | 200 | L = gpu_shuffle(E, 0); 201 | L = gpu_wog_dog( L, sigma_e1, sigma_e2, tau, phi_e, epsilon, precision_e ); 202 | } 203 | 204 | if (adaptive_quant) { 205 | img = gpu_wog_luminance_quant( img, nbins, lambda_delta, omega_delta, lambda_phi, omega_phi ); 206 | } else { 207 | img = gpu_wog_luminance_quant( img, nbins, phi_q ); 208 | } 209 | 210 | img = gpu_lab2rgb(img); 211 | img = gpu_blend_intensity(img, L, GPU_BLEND_MULTIPLY); 212 | 213 | if (warp_sharp) { 214 | img = gpu_wog_warp_sharp(img, sigma_w, precision_w, phi_w); 215 | } 216 | 217 | return img; 218 | } 219 | --------------------------------------------------------------------------------