Commit bfdd8910b9d661bbf168b3c57fa42b8af8422dca

Authored by David Mayerich
0 parents

initial commit

CMakeLists.txt 0 โ†’ 100644
  1 +++ a/CMakeLists.txt
  1 +#Specify the version being used aswell as the language
  2 +cmake_minimum_required(VERSION 2.8)
  3 +
  4 +#Name your project here
  5 +project(2netpbm)
  6 +
  7 +#set the module directory
  8 +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
  9 +
  10 +#build the executable in the binary directory on MS Visual Studio
  11 +if ( MSVC )
  12 + SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
  13 + SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
  14 + SET( LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
  15 + SET( LIBRARY_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
  16 + add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  17 + add_definitions(-D_SCL_SECURE_NO_WARNINGS)
  18 +endif ( MSVC )
  19 +
  20 +#find packages-----------------------------------
  21 +#find OpenCV
  22 +find_package(OpenCV REQUIRED)
  23 +
  24 +#find the pthreads package
  25 +find_package(Threads)
  26 +
  27 +#find the X11 package
  28 +find_package(X11)
  29 +
  30 +#find the STIM library
  31 +find_package(STIM)
  32 +
  33 +#find Boost for Unix-based file lists
  34 +if( CMAKE_COMPILER_IS_GNUCC )
  35 + find_package(Boost COMPONENTS filesystem system)
  36 + if(Boost_FOUND)
  37 + add_definitions(-DBOOST_PRECOMPILED)
  38 + include_directories(${Boost_INCLUDE_DIR})
  39 + else(Boost_FOUND)
  40 + message(FATAL_ERROR "HSIproc requires Boost::filesystem and Boost::system when using GCC")
  41 + endif(Boost_FOUND)
  42 +endif( CMAKE_COMPILER_IS_GNUCC )
  43 +
  44 +#set the STIM include directory (either user provided or downloaded)
  45 +include_directories(${STIM_INCLUDE_DIRS})
  46 +
  47 +#Assign source files to the appropriate variables to easily associate them with executables
  48 +file(GLOB SRC_CPP "*.cpp")
  49 +file(GLOB SRC_H "*.h")
  50 +
  51 +#create an executable file
  52 +add_executable(2netpbm
  53 + ${SRC_CPP}
  54 + ${SRC_H}
  55 +)
  56 +
  57 +#set the link libraries
  58 +target_link_libraries(2netpbm
  59 + ${OpenCV_LIBS}
  60 + ${X11_LIBRARIES}
  61 +)
  62 +
  63 +#copy data files to the binary directory
  64 +file(COPY data/skyrim.jpg DESTINATION .)
  65 +file(COPY data/galaxy.jpg DESTINATION .)
0 \ No newline at end of file 66 \ No newline at end of file
FindSTIM.cmake 0 โ†’ 100644
  1 +++ a/FindSTIM.cmake
  1 +# set STIMLIB_PATH to the directory containing the stim subdirectory (the stim repository)
  2 +
  3 +include(FindPackageHandleStandardArgs)
  4 +
  5 +set(STIM_INCLUDE_DIR $ENV{STIMLIB_PATH})
  6 +
  7 +find_package_handle_standard_args(STIM DEFAULT_MSG STIM_INCLUDE_DIR)
  8 +
  9 +if(STIM_FOUND)
  10 + set(STIM_INCLUDE_DIRS ${STIM_INCLUDE_DIR})
  11 +endif()
data/galaxy.jpg 0 โ†’ 100644

313 KB

data/skyrim.jpg 0 โ†’ 100644

25.6 KB

main.cpp 0 โ†’ 100644
  1 +++ a/main.cpp
  1 +#include <iostream>
  2 +#include <vector>
  3 +#include <stim/parser/arguments.h>
  4 +#include <stim/parser/filename.h>
  5 +#include <stim/image/image.h>
  6 +
  7 +int main(int argc, char* argv[]) {
  8 + stim::arglist args;
  9 +
  10 + args.parse(argc, argv);
  11 +
  12 + if (args.nargs() == 0) {
  13 + std::cout << "Specify a file or file list to convert images to Netpbm." << std::endl;
  14 + exit(0);
  15 + }
  16 +
  17 + stim::filename fmask(args.arg(0));
  18 + stim::filepath fpath("."); //default to the current file path
  19 + if (args.nargs() == 2) fpath = args.arg(1); //if a destination path is specified, save there
  20 +
  21 + if (fmask.wildcards()) { //if the given file name contains wild cards
  22 + std::vector<stim::filename> flist; //declare an STL vector
  23 + flist = fmask.get_list(); //get the corresponding file list
  24 +
  25 + for (size_t i = 0; i < flist.size(); i++) { //for each file in the list
  26 + stim::image<unsigned char> I(flist[i].str()); //load the corresponding image
  27 + std::string outname = fpath.str() + flist[i].prefix() + ".ppm";
  28 + std::cout << "Saving " << outname << std::endl;
  29 + I.save_netpbm(outname); //save the file as a PPM
  30 + }
  31 + }
  32 + else {
  33 + stim::image<unsigned char> I(fmask.str());
  34 + I.save(fmask.str() + ".ppm");
  35 + }
  36 +}
0 \ No newline at end of file 37 \ No newline at end of file