htpp

htrdr-image post-processing
git clone git://git.meso-star.fr/htpp.git
Log | Files | Refs | README | LICENSE

commit 2bdabe78a638e36206a15b344bf7f08d16204ade
parent 3ba47f5d132e39de80b3493a3679f59da7b87056
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Mon, 16 Nov 2020 16:15:34 +0100

Fix MSVC build

Diffstat:
Mcmake/CMakeLists.txt | 58++++++++++++++++++++++++++++++++++------------------------
Acmake/doc/CMakeLists.txt | 145+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adoc/htpp-man.css | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/htpp.c | 42++++++++++++++++++++++++++++++++----------
4 files changed, 307 insertions(+), 34 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -19,6 +19,20 @@ project(htpp C) set(HTPP_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) +if(CMAKE_HOST_UNIX) + set(HTPP_DOC "TROFF & HTML" CACHE STRING + "Type of documentation to generate and install.") +else() + set(HTPP_DOC "HTML" CACHE STRING + "Type of documentation to generate and install.") +endif() + +set_property(CACHE HTPP_DOC PROPERTY STRINGS + "HTML" + "TROFF" + "TROFF & HTML" + "NONE") + ################################################################################ # Check dependencies ################################################################################ @@ -26,6 +40,9 @@ find_package(RCMake 0.3 REQUIRED) find_package(RSys 0.9 REQUIRED) find_package(StarCMap 0.0 REQUIRED) find_package(OpenMP 1.2 REQUIRED) +if(MSVC) + find_package(MuslGetopt REQUIRED) +endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR}) include(rcmake) @@ -33,6 +50,13 @@ include(rcmake_runtime) include_directories(${RSys_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +############################################################################### +# Build subprojects +############################################################################### +if(NOT HTPP_DOC STREQUAL "NONE") + add_subdirectory(doc) +endif() + ################################################################################ # Configure and define targets ################################################################################ @@ -52,7 +76,16 @@ rcmake_prepend_path(HTPP_FILES_SRC ${HTPP_SOURCE_DIR}) rcmake_prepend_path(HTPP_FILES_DOC ${PROJECT_SOURCE_DIR}/../) add_executable(htpp ${HTPP_FILES_SRC}) -target_link_libraries(htpp RSys StarCMap) + +if(CMAKE_COMPILER_IS_GNUCC) + set(MATH_LIB m) +endif() + +if(MSVC) + set(GETOPT_LIB MuslGetopt) +endif() + +target_link_libraries(htpp RSys StarCMap ${MATH_LIB} ${GETOPT_LIB}) set_target_properties(htpp PROPERTIES COMPILE_FLAGS "${OpenMP_C_FLAGS}") @@ -67,29 +100,6 @@ set_target_properties(htpp PROPERTIES SOVERSION ${VERSION_MAJOR}) ################################################################################ -# Man pages -############################################################################### -find_program(A2X NAMES a2x a2x.py) -if(NOT A2X) - message(WARNING - "The `a2x' program is missing. " - "The htpp man pages cannot be generated.") -else() - set(_src ${PROJECT_SOURCE_DIR}/../doc/htpp.1.txt) - set(_txt ${CMAKE_CURRENT_BINARY_DIR}/htpp.1.txt) - add_custom_command( - OUTPUT htpp.1 - COMMAND ${CMAKE_COMMAND} -E copy ${_src} ${_txt} - COMMAND ${A2X} -dmanpage -fmanpage ${_txt} - DEPENDS ${_src} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Buid ROFF man page htpp.1" - VERBATIM) - add_custom_target(man-roff ALL DEPENDS htpp.1) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/htpp.1 DESTINATION share/man/man1) -endif() - -################################################################################ # Define output & install directories ################################################################################ install(TARGETS htpp diff --git a/cmake/doc/CMakeLists.txt b/cmake/doc/CMakeLists.txt @@ -0,0 +1,145 @@ +# Copyright (C) 2018-2020 |Meso|Star> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +cmake_minimum_required(VERSION 3.0) + +string(REGEX MATCH ".*HTML.*" _html ${HTPP_DOC}) +string(REGEX MATCH ".*ROFF.*" _roff ${HTPP_DOC}) + +set(HTPP_DOC_DIR ${PROJECT_SOURCE_DIR}/../doc) + +################################################################################ +# Look for asciidoc and a2x programs +################################################################################ +if(_html) + find_program(ASCIIDOC NAMES asciidoc asciidoc.py) + if(NOT ASCIIDOC) + unset(_html) + message(WARNING + "The `asciidoc' program is missing. " + "The htpp HTML documentation cannot be generated.") + endif() +endif() + +if(_roff) + find_program(A2X NAMES a2x a2x.py) + if(NOT A2X) + unset(_roff) + message(WARNING + "The `a2x' program is missing. " + "The htpp man pages cannot be generated.") + endif() +endif() + +################################################################################ +# Copy doc files +################################################################################ +set(MAN_NAMES htpp.1) + +if(_roff OR _html) + set(MAN_FILES) + foreach(_name IN LISTS MAN_NAMES) + set(_src ${HTPP_DOC_DIR}/${_name}.txt) + set(_dst ${CMAKE_CURRENT_BINARY_DIR}/${_name}.txt) + add_custom_command( + OUTPUT ${_dst} + COMMAND ${CMAKE_COMMAND} -E copy ${_src} ${_dst} + DEPENDS ${_src} + COMMENT "Copy the asciidoc ${_src}" + VERBATIM) + list(APPEND MAN_FILES ${_dst}) + endforeach() + add_custom_target(man-copy ALL DEPENDS ${MAN_FILES}) +endif() + +################################################################################ +# ROFF man pages +################################################################################ +if(_roff) + set(A2X_OPTS -dmanpage -fmanpage) + set(MAN_FILES) + set(MAN5_FILES) + set(MAN1_FILES) + foreach(_name IN LISTS MAN_NAMES) + set(_man ${CMAKE_CURRENT_BINARY_DIR}/${_name}) + set(_txt ${CMAKE_CURRENT_BINARY_DIR}/${_name}.txt) + + add_custom_command( + OUTPUT ${_man} + COMMAND ${A2X} ${A2X_OPTS} ${_txt} + DEPENDS man-copy ${_txt} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Build ROFF man page ${_man}" + VERBATIM) + list(APPEND MAN_FILES ${_man}) + + string(REGEX MATCH "^.*.5$" _man5 ${_man}) + string(REGEX MATCH "^.*.1$" _man1 ${_man}) + if(_man1) + list(APPEND MAN1_FILES ${_man1}) + elseif(_man5) + list(APPEND MAN5_FILES ${_man5}) + else() + message(FATAL_ERROR "Unexpected man type") + endif() + endforeach() + add_custom_target(man-roff ALL DEPENDS ${MAN_FILES}) + + install(FILES ${MAN1_FILES} DESTINATION share/man/man1) + install(FILES ${MAN5_FILES} DESTINATION share/man/man5) +endif() + +################################################################################ +# HTML documentation +################################################################################ +if(_html) + set(ASCIIDOC_OPTS + -bxhtml11 + -dmanpage + --attribute themedir=${HTPP_DOC_DIR} + --theme=htpp-man) + + set(MAN_FILES) + set(MAN5_FILES) + set(MAN1_FILES) + foreach(_name IN LISTS MAN_NAMES) + set(_man ${CMAKE_CURRENT_BINARY_DIR}/${_name}.html) + set(_txt ${CMAKE_CURRENT_BINARY_DIR}/${_name}.txt) + + add_custom_command( + OUTPUT ${_man} + COMMAND ${ASCIIDOC} ${ASCIIDOC_OPTS} ${_txt} + DEPENDS man-copy ${_txt} ${HTPP_DOC_DIR}/htpp-man.css + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Build HTML man page ${_man}" + VERBATIM) + list(APPEND MAN_FILES ${_man}) + + string(REGEX MATCH "^.*.5.html$" _man5 ${_man}) + string(REGEX MATCH "^.*.1.html$" _man1 ${_man}) + if(_man1) + list(APPEND MAN1_FILES ${_man1}) + elseif(_man5) + list(APPEND MAN5_FILES ${_man5}) + else() + message(FATAL_ERROR "Unexpected man type") + endif() + endforeach() + add_custom_target(man-html ALL DEPENDS ${MAN_FILES}) + + install(FILES ${MAN1_FILES} DESTINATION share/man/man1) + install(FILES ${MAN5_FILES} DESTINATION share/man/man5) +endif() + diff --git a/doc/htpp-man.css b/doc/htpp-man.css @@ -0,0 +1,96 @@ +/* Copyright (C) 2016-2018 CNRS + * + * This is free style sheet: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This CSS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. */ + +body.manpage { + font-family:"Liberation Sans",sans-serif; + font-size:10pt; + text-align: justify; + max-width: 55em; + margin: 1em; + background: #ffffff +} + +body.manpage .monospaced, .literalblock { + margin: 2em; + color: #636261 +} + +body.manpage em { + color: #660000 +} + +body.manpage div.verseblock > pre.content { + font-family: "Liberation Mono",monospace; +} + +body.manpage h1 { + padding-bottom: 0.5em; +} +body.manpage h2 { + border-style: none; +} +body.manpage div.sectionbody { + margin-left: 3em; +} + +body.manpage code { + font-family: "Liberation Mono",monospace; +} + +body.manpage #footer { display: none; } + +body.manpage div#toctitle { display: none; } + +body.manpage div#toc { + display: block; + position:fixed; + top:0; + left:60em; + height:100%; + width: 100%; + padding:3em 0 0 0; + border-left:1px solid #dbdbdb; + background: #eeeeee +} + +body.manpage a { + font-weight: bold; + color: #225588; +} + +body.manpage div#toc a, div#toc a:link, div#toc a:visited { + margin:0; + padding-left: 2em; + color:#999999; + text-decoration:none; + font-weight: normal; +} + +body.manpage div.toclevel1 { + line-height: 1.5em; +} + +body.manpage div.toclevel2 { + margin-left: 2em; +} + +body.manpage div#toc a:hover { + color:#666666; +} + +@media print { + body.manpage div#toc { display: none; } +} + diff --git a/src/htpp.c b/src/htpp.c @@ -31,7 +31,24 @@ #include <omp.h> #include <string.h> #include <sys/stat.h> /* S_IRUSR & S_IWUSR */ -#include <unistd.h> /* getopt */ +#include <getopt.h> + +#ifdef COMPILER_CL + /* Wrap POSIX functions and constants */ +#include <io.h> +#define open _open +#define close _close +#define fdopen _fdopen +#define S_IRUSR S_IREAD +#define S_IWUSR S_IWRITE +#else + /* open/close functions */ +#include <unistd.h> +#endif + +#ifdef COMPILER_CL +#define strtok_r strtok_s +#endif enum pixcpnt { PIXCPNT_X, @@ -94,7 +111,6 @@ struct args { INT_MAX, /* #threads */ \ 0 /* Quit? */ \ } -static const struct args ARGS_DEFAULT = ARGS_DEFAULT__; struct img { char* pixels; /* row majored pixels */ @@ -105,7 +121,8 @@ struct img { /* Ranges of the loaded value */ double ranges[PIXCPNTS_COUNT__][2]; }; -static const struct img IMG_NULL; +#define IMG_NULL__ { NULL, 0, 0, 0, {{ 0, 0}} } +static const struct img IMG_NULL = IMG_NULL__; /******************************************************************************* * Helper functions @@ -196,6 +213,7 @@ parse_img_option(struct args* args, const char* str) char* key; char* val; char* tk_ctx; + const struct args args_default = ARGS_DEFAULT__; res_T res = RES_OK; if(strlen(str) >= sizeof(buf) - 1/*NULL char*/) { @@ -215,7 +233,7 @@ parse_img_option(struct args* args, const char* str) res = RES_BAD_ARG; goto error; } - args->image = ARGS_DEFAULT.image; + args->image = args_default.image; } else { @@ -261,6 +279,7 @@ parse_map_option(struct args* args, const char* str) char* key; char* val; char* tk_ctx; + const struct args args_default = ARGS_DEFAULT__; res_T res = RES_OK; if(strlen(str) >= sizeof(buf) - 1/*NULL char*/) { @@ -280,7 +299,7 @@ parse_map_option(struct args* args, const char* str) res = RES_BAD_ARG; goto error; } - args->map = ARGS_DEFAULT.map; + args->map = args_default.map; } else if(!strcmp(key, "gnuplot")) { args->map.gnuplot = 1; } else { @@ -325,8 +344,9 @@ error: static void args_release(struct args* args) { + const struct args args_default = ARGS_DEFAULT__; ASSERT(args); - *args = ARGS_DEFAULT; + *args = args_default; } static res_T @@ -725,7 +745,8 @@ img_write_gnuplot args->map.range[0], args->map.range[1])); } CHKWR(fprintf(stream, "set terminal png size %lu,%lu*(1+%g+%g)\n", - img->width, img->height, cbox_height, cbox_tmargin)); + (long unsigned)img->width, (unsigned long)img->height, + cbox_height, cbox_tmargin)); CHKWR(fprintf(stream, "set origin 0, %g\n", (cbox_height+cbox_tmargin)*0.5)); CHKWR(fprintf(stream, "set size ratio %g\n", (double)img->height/(double)img->width)); @@ -750,7 +771,8 @@ img_write_gnuplot FOR_EACH(x, 0, img->width) { double* row = (double*)(img->pixels + img->pitch*y); double* pixel = row + x*PIXCPNTS_COUNT__; - CHKWR(fprintf(stream, "%lu %lu %g\n", y, x, pixel[args->map.pixcpnt])); + CHKWR(fprintf(stream, "%lu %lu %g\n", + (unsigned long)y, (unsigned long)x, pixel[args->map.pixcpnt])); } if(y != img->height-1) { CHKWR(fprintf(stream, "\n")); @@ -774,7 +796,7 @@ compute_XYZ_normalization_factor(const struct img* img) size_t i, x, y; ASSERT(img); - CHK(Y = mem_alloc(sizeof(*Y)*img->width*img->height)); + CHK((Y = mem_alloc(sizeof(*Y)*img->width*img->height))!= NULL); /* Copy the pixel luminance in the Y array */ i = 0; @@ -971,7 +993,7 @@ main(int argc, char** argv) const char* stream_out_name = "stdout"; const char* stream_in_name = "stdin"; struct img img = IMG_NULL; - struct args args = ARGS_DEFAULT; + struct args args = ARGS_DEFAULT__; int img_is_loaded = 0; int err = 0; res_T res = RES_OK;