commit a54d9fadc2a53e775dcdbc3291f018158f06cbd8
parent 4f8c845ccfbeb31a09d8b37265122a5b9dfdba35
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 26 Jul 2018 12:00:37 +0200
Remove the OpenEXR support
Diffstat:
5 files changed, 29 insertions(+), 189 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -14,7 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
cmake_minimum_required(VERSION 2.8)
-project(htrdr C CXX)
+project(htrdr C)
enable_testing()
set(HTRDR_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src)
@@ -23,9 +23,6 @@ option(NO_TEST "Do not build the tests" OFF)
################################################################################
# Check dependencies
################################################################################
-get_filename_component(_current_source_dir ${CMAKE_CURRENT_LIST_FILE} PATH)
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${_current_source_dir})
-
find_package(RCMake 0.3 REQUIRED)
find_package(RSys 0.6 REQUIRED)
find_package(Star3D 0.5 REQUIRED)
@@ -36,17 +33,11 @@ find_package(StarVX REQUIRED)
find_package(HTCP REQUIRED)
find_package(HTMIE REQUIRED)
find_package(OpenMP 1.2 REQUIRED)
-find_package(OpenEXR REQUIRED)
-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR})
include(rcmake)
include(rcmake_runtime)
-if(CMAKE_COMPILER_IS_GNUCXX)
- string(REPLACE "-fno-rtti" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
-endif()
-
include_directories(
${RSys_INCLUDE_DIR}
${Star3D_INCLUDE_DIR}
@@ -55,17 +46,7 @@ include_directories(
${StarSP_INCLUDE_DIR}
${StarVX_INCLUDE_DIR}
${HTCP_INCLUDE_DIR}
- ${HTMIE_INCLUDE_DIR}
- ${OPENEXR_INCLUDE_DIR})
-
-################################################################################
-# Build the EXR static library
-################################################################################
-set_source_files_properties(${HTRDR_SOURCE_DIR}/htrdr_openexr.c
- PROPERTIES LANGUAGE CXX)
-
-add_library(htrdr_openexr STATIC ${HTRDR_SOURCE_DIR}/htrdr_openexr.c)
-target_link_libraries(htrdr_openexr ${OPENEXR_LIBRARIES})
+ ${HTMIE_INCLUDE_DIR})
################################################################################
# Configure and define targets
@@ -98,15 +79,13 @@ set(HTRDR_FILES_INC
htrdr_solve.h)
set(HTDRD_FILES_DOC COPYING README.md)
-
# Prepend each file in the `HTRDR_FILES_<SRC|INC>' list by `HTRDR_SOURCE_DIR'
rcmake_prepend_path(HTRDR_FILES_SRC ${HTRDR_SOURCE_DIR})
rcmake_prepend_path(HTRDR_FILES_INC ${HTRDR_SOURCE_DIR})
rcmake_prepend_path(HTRDR_FILES_DOC ${PROJECT_SOURCE_DIR}/../)
add_executable(htrdr ${HTRDR_FILES_SRC} ${HTRDR_FILES_INC})
-target_link_libraries(htrdr HTCP HTMIE RSys Star3D Star3DAW StarSF StarSP
- StarVX htrdr_openexr)
+target_link_libraries(htrdr HTCP HTMIE RSys Star3D Star3DAW StarSF StarSP StarVX)
if(CMAKE_COMPILER_IS_GNUCC)
target_link_libraries(htrdr m)
diff --git a/src/htrdr.c b/src/htrdr.c
@@ -19,7 +19,6 @@
#include "htrdr_args.h"
#include "htrdr_buffer.h"
#include "htrdr_camera.h"
-#include "htrdr_openexr.h"
#include "htrdr_sky.h"
#include "htrdr_sun.h"
#include "htrdr_solve.h"
@@ -143,19 +142,17 @@ error:
}
static res_T
-dump_buffer
+dump_accum_buffer
(struct htrdr* htrdr,
struct htrdr_buffer* buf,
const char* stream_name,
FILE* stream)
{
struct htrdr_buffer_layout layout;
- const char* mem;
- float* pixels = NULL;
- size_t ipix_slice;
size_t x, y;
res_T res = RES_OK;
ASSERT(htrdr && buf && stream_name && stream);
+ (void)stream_name;
htrdr_buffer_get_layout(buf, &layout);
if(layout.elmt_size != sizeof(struct htrdr_accum)
@@ -168,35 +165,17 @@ dump_buffer
goto error;
}
- /* Allocate the slice memory */
- pixels = MEM_CALLOC
- (htrdr->allocator, layout.width*layout.height, sizeof(*pixels));
- if(!pixels) {
- htrdr_log_err(htrdr,
- "%s: could not allocate the memory of the OpenEXR slice.\n", FUNC_NAME);
- res = RES_MEM_ERR;
- goto error;
- }
-
- /* Define the slice data from the buf */
- mem = (const char*)htrdr_buffer_get_data(buf);
- ipix_slice = 0;
FOR_EACH(y, 0, layout.height) {
- const struct htrdr_accum* row =
- (const struct htrdr_accum*)(mem + y*layout.pitch);
FOR_EACH(x, 0, layout.width) {
- const struct htrdr_accum* accum = row + x;
+ const struct htrdr_accum* accum = htrdr_buffer_at(buf, x, y);
const double E = accum->nweights
- ? accum->sum_weights / (double)accum->nweights
- : 0;
- pixels[ipix_slice] = (float)E;
+ ? accum->sum_weights / (double)accum->nweights : 0;
fprintf(stream, "%g ", E);
}
fprintf(stream, "\n");
}
exit:
- if(pixels) MEM_RM(htrdr->allocator, pixels);
return res;
error:
goto exit;
@@ -260,6 +239,7 @@ htrdr_init
struct htrdr* htrdr)
{
double proj_ratio;
+ const char* output_name = NULL;
res_T res = RES_OK;
ASSERT(args && htrdr);
@@ -272,6 +252,8 @@ htrdr_init
logger_set_stream(&htrdr->logger, LOG_ERROR, print_err, NULL);
logger_set_stream(&htrdr->logger, LOG_WARNING, print_warn, NULL);
+ str_init(htrdr->allocator, &htrdr->output_name);
+
htrdr->dump_vtk = args->dump_vtk;
htrdr->verbose = args->verbose;
htrdr->nthreads = MMIN(args->nthreads, (unsigned)omp_get_num_procs());
@@ -279,11 +261,17 @@ htrdr_init
if(!args->output) {
htrdr->output = stdout;
- htrdr->output_name = "<stdout>";
+ output_name = "<stdout>";
} else {
res = open_output_stream(htrdr, args);
if(res != RES_OK) goto error;
- htrdr->output_name = "todo";
+ output_name = args->output;
+ }
+ res = str_set(&htrdr->output_name, output_name);
+ if(res != RES_OK) {
+ htrdr_log_err(htrdr,
+ "could not store the name of the output stream `%s'.\n", output_name);
+ goto error;
}
res = svx_device_create
@@ -293,8 +281,11 @@ htrdr_init
goto error;
}
+ /* Disable the Star-3D verbosity since the Embree backend print some messages
+ * on stdout rather than stderr. This is annoying since stdout may be used by
+ * htrdr to write output data */
res = s3d_device_create
- (&htrdr->logger, htrdr->allocator, args->verbose, &htrdr->s3d);
+ (&htrdr->logger, htrdr->allocator, 0, &htrdr->s3d);
if(res != RES_OK) {
htrdr_log_err(htrdr, "could not create the Star-3D device.\n");
goto error;
@@ -312,7 +303,7 @@ htrdr_init
args->image.definition[1], /* Height */
args->image.definition[0]*sizeof(struct htrdr_accum), /* Pitch */
sizeof(struct htrdr_accum), /* Element size */
- 16, /* Alignement */
+ 16, /* Alignment */
&htrdr->buf);
if(res != RES_OK) goto error;
@@ -371,6 +362,7 @@ htrdr_release(struct htrdr* htrdr)
if(htrdr->sun) htrdr_sun_ref_put(htrdr->sun);
if(htrdr->cam) htrdr_camera_ref_put(htrdr->cam);
if(htrdr->buf) htrdr_buffer_ref_put(htrdr->buf);
+ str_release(&htrdr->output_name);
logger_release(&htrdr->logger);
}
@@ -392,7 +384,9 @@ htrdr_run(struct htrdr* htrdr)
time_dump(&t0, TIME_ALL, NULL, buf, sizeof(buf));
htrdr_log(htrdr, "Elapsed time: %s\n", buf);
- dump_buffer(htrdr, htrdr->buf, htrdr->output_name, htrdr->output);
+ res = dump_accum_buffer
+ (htrdr, htrdr->buf, str_cget(&htrdr->output_name), htrdr->output);
+ if(res != RES_OK) goto error;
}
exit:
return res;
diff --git a/src/htrdr.h b/src/htrdr.h
@@ -18,6 +18,7 @@
#include <rsys/logger.h>
#include <rsys/ref_count.h>
+#include <rsys/str.h>
/* Forward declarations */
struct htrdr_args;
@@ -50,7 +51,7 @@ struct htrdr {
size_t spp; /* #samples per pixel */
FILE* output;
- const char* output_name;
+ struct str output_name;
unsigned nthreads;
int dump_vtk;
diff --git a/src/htrdr_openexr.c b/src/htrdr_openexr.c
@@ -1,98 +0,0 @@
-/* Copyright (C) 2018 Université Paul Sabatier, |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/>. */
-
-#include "htrdr_openexr.h"
-
-#include <OpenEXR/Iex.h>
-#include <OpenEXR/ImfChannelList.h>
-#include <OpenEXR/ImfFrameBuffer.h>
-#include <OpenEXR/ImfIO.h>
-#include <OpenEXR/ImfOutputFile.h>
-
-/*******************************************************************************
- * Helper class
- ******************************************************************************/
-class OFStream : public Imf::OStream {
-public:
- OFStream(FILE* stream, const char* filename)
- : OStream(filename), _stream(stream) {}
-
- void write(const char c[], int n)
- {
- if(n < 0 || fwrite(c, 1, n, _stream) != (size_t)n) {
- std::stringstream s;
- s << "Error writing the OpenEXR image into`" << fileName() << "'.";
-
- throw Iex::IoExc(s);
- }
- }
-
- Imf::Int64 tellp()
- {
- const long l = ftell(_stream);
- if(l == -1) Iex::throwErrnoExc();
- return Imf::Int64(l);
- }
-
- void seekp(Imf::Int64 pos)
- {
- const int err = fseek(_stream, long(pos), SEEK_SET);
- if(err == -1) Iex::throwErrnoExc();
- }
-
-private:
- FILE* _stream;
-};
-
-/*******************************************************************************
- * Local functions
- ******************************************************************************/
-res_T
-htrdr_openexr_write
- (const float* pixels,
- const size_t width,
- const size_t height,
- const size_t pitch,
- const char* output_name,
- FILE* output)
-{
- res_T res = RES_OK;
-
- /* Init the OpenEXR slice */
- Imf::Slice slice
- (Imf::FLOAT, (char*)pixels, sizeof(*pixels), pitch);
-
- /* Setup the OpenEXR framebuffer */
- Imf::FrameBuffer framebuffer;
- framebuffer.insert("L", slice);
-
- /* Define the OpenEXR header */
- Imf::Header header((int)width, (int)height);
- header.channels().insert("L", Imf::FLOAT);
-
- /* Setup the OpenEXR output file from the submitted C stream */
- OFStream out_stream(output, output_name);
- Imf::OutputFile out_file(out_stream, header);
-
- /* Write data */
- out_file.setFrameBuffer(framebuffer);
- try {
- out_file.writePixels((int)height);
- } catch(...) {
- res = RES_IO_ERR;
- }
- return res;
-}
-
diff --git a/src/htrdr_openexr.h b/src/htrdr_openexr.h
@@ -1,36 +0,0 @@
-/* Copyright (C) 2018 Université Paul Sabatier, |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/>. */
-
-#ifndef HTRDR_OPENEXR_H
-#define HTRDR_OPENEXR_H
-
-#include <rsys/rsys.h>
-#include <stdio.h>
-
-BEGIN_DECLS
-
-extern res_T
-htrdr_openexr_write
- (const float* pixels,
- const size_t width,
- const size_t height,
- const size_t pitch,
- const char* output_name,
- FILE* output);
-
-END_DECLS
-
-#endif /* HTRDR_OPENEXR_H */
-