mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
Make a library for writing and reading tiff, added tests (#347)
* removed Makefile for moench and integrated the build in CMake * broke out tiff reading and writing to its own library * moved tiff includes to include/sls * moved tiffio source to src * removed incorrectly used bps * cleanup and tests for tiffio * removed using namespace std from header * some fixing for moench04 * Program for offline processing renamed Co-authored-by: Anna Bergamaschi <anna.bergamaschi@psi.ch>
This commit is contained in:
5
slsDetectorCalibration/tiffio/tests/CMakeLists.txt
Normal file
5
slsDetectorCalibration/tiffio/tests/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-other
|
||||
# Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
target_sources(tests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-tiffio.cpp
|
||||
)
|
54
slsDetectorCalibration/tiffio/tests/test-tiffio.cpp
Normal file
54
slsDetectorCalibration/tiffio/tests/test-tiffio.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "sls/tiffIO.h"
|
||||
#include <cstdio>
|
||||
#include <ftw.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
/* Call-back to the 'remove()' function called by nftw() */
|
||||
static int remove_callback(const char *pathname,
|
||||
__attribute__((unused)) const struct stat *sbuf,
|
||||
__attribute__((unused)) int type,
|
||||
__attribute__((unused)) struct FTW *ftwb) {
|
||||
return remove(pathname);
|
||||
}
|
||||
|
||||
TEST_CASE("Write and read back data from tiff file") {
|
||||
|
||||
std::vector<float> data{1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
|
||||
/* Create the temporary directory */
|
||||
char tmp[] = "/tmp/tmpdir.XXXXXX";
|
||||
char *tmp_dirname = mkdtemp(tmp);
|
||||
|
||||
if (tmp_dirname == NULL) {
|
||||
perror("tempdir: error: Could not create tmp directory");
|
||||
CHECK(false);
|
||||
}
|
||||
|
||||
std::string fname = std::string(tmp_dirname) + std::string("/test.tif");
|
||||
std::cout << "Writing to: " << fname<< '\n';
|
||||
|
||||
WriteToTiff(data.data(), fname.c_str(), 3, 3);
|
||||
|
||||
//Readback
|
||||
uint32_t nrow, ncol;
|
||||
float* ptr = ReadFromTiff(fname.c_str(), nrow, ncol);
|
||||
CHECK(nrow == 3);
|
||||
CHECK(ncol == 3);
|
||||
uint32_t size = nrow*ncol;
|
||||
for (uint32_t i = 0; i!=size; ++i){
|
||||
CHECK(data[i] == ptr[i]);
|
||||
}
|
||||
|
||||
delete[] ptr;
|
||||
|
||||
/* Delete the temporary directory */
|
||||
if (nftw(tmp_dirname, remove_callback, FOPEN_MAX,
|
||||
FTW_DEPTH | FTW_MOUNT | FTW_PHYS) == -1) {
|
||||
perror("tempdir: error: ");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user