commit 60e038197906c1802a90473009d5cf985d21a3f6
parent fbe414e922dbab69858c489f8c6fdb82451b25ed
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 15 Nov 2018 10:45:35 +0100
Add several options
The "-w white_scale" is used to explicitly define the normalization
factor. If not defined, this factor is automatically computed by htpp;
the -v option can be used to print the value of this automatically
computed white_scale value.
The "-t" option provides an hint on the number of threads to use.
Finally the "--version" option is used to print version informations.
Diffstat:
4 files changed, 96 insertions(+), 20 deletions(-)
diff --git a/README.md b/README.md
@@ -29,9 +29,10 @@ informations on CMake.
## License
-htpp is a free software copyright (C) 2018 Université Paul Sabatier
-<contact-edstar@laplace.univ-tlse.fr>, |Meso|Star <contact@meso-star.com>. It
-is released under the GPL v3+ license: GNU GPL version 3 or later. You are
-welcome to redistribute it under certain conditions; refer to the COPYING file
-for details.
+htpp is a free software copyright (C) 2018 Centre National de la Recherche
+(CNRS), [|Meso|Star>](https://www.meso-star.com) <contact@meso-star.com>,
+Université Paul Sabatier <contact-edstar@laplace.univ-tlse.fr>. It is released
+under the GPL v3+ license: GNU GPL version 3 or later. You are welcome to
+redistribute it under certain conditions; refer to the COPYING file for
+details.
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (C) 2018 Université Paul Sabatier, |Meso|Star>
+# Copyright (C) 2018 CNRS, |Meso|Star>, Université Paul Sabatier
#
# 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
@@ -29,7 +29,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR})
include(rcmake)
include(rcmake_runtime)
-include_directories(${RSys_INCLUDE_DIR})
+include_directories(${RSys_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
################################################################################
# Configure and define targets
@@ -39,6 +39,9 @@ set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
+configure_file(${HTPP_SOURCE_DIR}/htpp_version.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/htpp_version.h @ONLY)
+
set(HTPP_FILES_SRC htpp.c)
set(HTPP_FILES_DOC COPYING README.md)
diff --git a/src/htpp.c b/src/htpp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2018 Université Paul Sabatier, |Meso|Star>
+/* Copyright (C) 2018 CNRS, |Meso|Star>, Université Paul Sabatier
*
* 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
@@ -15,6 +15,8 @@
#define _POSIX_C_SOURCE 200112L /* getopt/close support */
+#include "htpp_version.h"
+
#include <rsys/cstr.h>
#include <rsys/double33.h>
#include <rsys/mem_allocator.h>
@@ -32,11 +34,14 @@ struct args {
const char* input;
const char* output;
double exposure;
+ double white_scale;
int uncertainties;
+ int verbose;
int force_overwrite;
+ int nthreads;
int quit;
};
-#define ARGS_DEFAULT__ {NULL,NULL,1.0,0,0,0}
+#define ARGS_DEFAULT__ {NULL,NULL,1.0,-1.0,0,0,0,INT_MAX,0}
static const struct args ARGS_DEFAULT = ARGS_DEFAULT__;
struct img {
@@ -60,7 +65,8 @@ print_help(const char* cmd)
printf(
"Usage: %s [OPTIONS] [INPUT]\n"
-"Post process an XYZ ASCII image.\n\n", cmd);
+"Tone map a htrdr-image(5) and convert it in a regular PPM image.\n\n",
+ cmd);
printf(
" -e EXPOSURE exposure of the pixel. Default value is 1.\n");
printf(
@@ -72,12 +78,23 @@ print_help(const char* cmd)
" to standard output.\n");
printf(
" -u dump per channel uncertainties rather than luminance.\n");
-
+ printf(
+" -t THREADS hint on the number of threads to use. By default use as\n"
+" many threads as CPU cores.\n");
+ printf(
+" -v make the program verbose.\n");
+ printf(
+" -w WHITE-SCALE white scale factor used to normalize input colors.\n"
+" By the white scale factor is automatically computed from\n"
+" the luminance of the submitted colors\n");
+ printf(
+" --version display version information and exit.\n");
printf("\n");
printf(
-"%s (C) 2018 |Meso|Star>. This is free software released under the GNU GPL\n"
-"license, version 3 or later. You are free to change or redistribute it under\n"
-"certain conditions <http://gnu.org/licenses/gpl.html>.\n", cmd);
+"htpp (C) 2018 CNRS, |Meso|Star> <contact@meso-star.com>, Université Paul\n"
+"Sabatier <contact-edstar@laplace.univ-tlse.fr>. This is free software released\n"
+"under the GNU GPL license, version 3 or later. You are free to change or\n"
+"redistribute it under certain conditions <http://gnu.org/licenses/gpl.html>.\n");
}
static void
@@ -91,12 +108,27 @@ static res_T
args_init(struct args* args, const int argc, char** argv)
{
int opt;
+ int i;
res_T res = RES_OK;
ASSERT(args && argc && argv);
- while((opt = getopt(argc, argv, "e:fho:u")) != -1) {
+ FOR_EACH(i, 1, argc) {
+ if(!strcmp(argv[i], "--version")) {
+ printf("High-Tune: Post-Process %d.%d.%d\n",
+ HTPP_VERSION_MAJOR,
+ HTPP_VERSION_MINOR,
+ HTPP_VERSION_PATCH);
+ args->quit = 1;
+ goto exit;
+ }
+ }
+
+ while((opt = getopt(argc, argv, "e:fho:t:uvw:")) != -1) {
switch(opt) {
- case 'e': res = cstr_to_double(optarg, &args->exposure); break;
+ case 'e':
+ res = cstr_to_double(optarg, &args->exposure);
+ if(res == RES_OK && args->exposure < 0) res = RES_BAD_ARG;
+ break;
case 'f': args->force_overwrite = 1; break;
case 'h':
print_help(argv[0]);
@@ -104,7 +136,16 @@ args_init(struct args* args, const int argc, char** argv)
args->quit = 1;
goto exit;
case 'o': args->output = optarg; break;
+ case 't':
+ res = cstr_to_int(optarg, &args->nthreads);
+ if(res == RES_OK && args->nthreads <= 0) res = RES_BAD_ARG;
+ break;
case 'u': args->uncertainties = 1; break;
+ case 'v': args->verbose = 1; break;
+ case 'w':
+ res = cstr_to_double(optarg, &args->white_scale);
+ if(res == RES_OK && args->white_scale <= 0) res = RES_BAD_ARG;
+ break;
default: res = RES_BAD_ARG; break;
}
if(res != RES_OK) {
@@ -120,6 +161,8 @@ args_init(struct args* args, const int argc, char** argv)
args->input = argv[optind];
}
+ args->nthreads = MMIN(omp_get_num_procs(), args->nthreads);
+
exit:
optind = 1;
return res;
@@ -455,7 +498,6 @@ main(int argc, char** argv)
struct img img = IMG_NULL;
struct args args = ARGS_DEFAULT;
double Ymax;
- const int nprocs = omp_get_num_procs();
int err = 0;
int64_t i;
res_T res = RES_OK;
@@ -473,15 +515,22 @@ main(int argc, char** argv)
res = open_input_stream(args.input, &stream_in);
if(res != RES_OK) goto error;
stream_in_name = args.input;
+ } else if(args.verbose) {
+ fprintf(stderr, "Read image from standard input.\n");
}
res = img_load(&img, args.uncertainties, stream_in, stream_in_name);
if(res != RES_OK) goto error;
- Ymax = compute_img_normalization_factor(&img);
+ if(args.white_scale > 0) {
+ Ymax = args.white_scale;
+ } else {
+ Ymax = compute_img_normalization_factor(&img);
+ if(args.verbose) fprintf(stderr, "White scale = %g\n", Ymax);
+ }
- omp_set_num_threads(nprocs);
- /* Convert input HDR XYZ image in RGB LDR image */
+ omp_set_num_threads(args.nthreads);
+ /* Convert input HDR XYZ image in LDR image */
#pragma omp parallel for
for(i=0; i < (int64_t)(img.width*img.height); ++i) {
const size_t y = (size_t)i / img.width;
diff --git a/src/htpp_version.h.in b/src/htpp_version.h.in
@@ -0,0 +1,23 @@
+/* Copyright (C) 2018 CNRS, |Meso|Star>, Université Paul Sabatier
+ *
+ * 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/>. */
+
+#ifndef HTPP_VERSION_H
+#define HTPP_VERSION_H
+
+#define HTPP_VERSION_MAJOR @VERSION_MAJOR@
+#define HTPP_VERSION_MINOR @VERSION_MINOR@
+#define HTPP_VERSION_PATCH @VERSION_PATCH@
+
+#endif /* HTPP_VERSION_H */