mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-21 17:18:00 +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:
48
slsDetectorCalibration/tiffio/src/tiffIO.cpp
Normal file
48
slsDetectorCalibration/tiffio/src/tiffIO.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-other
|
||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
|
||||
#include "sls/tiffIO.h"
|
||||
#include <iostream>
|
||||
#include <tiffio.h>
|
||||
|
||||
void *WriteToTiff(float *imgData, const char *imgname, int nrow, int ncol) {
|
||||
constexpr uint32_t sampleperpixel = 1;
|
||||
TIFF *tif = TIFFOpen(imgname, "w");
|
||||
if (tif) {
|
||||
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, ncol);
|
||||
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, nrow);
|
||||
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, sampleperpixel);
|
||||
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32);
|
||||
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
|
||||
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
||||
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
|
||||
TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
|
||||
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP,
|
||||
TIFFDefaultStripSize(tif, ncol * sampleperpixel));
|
||||
|
||||
for (int irow = 0; irow < nrow; irow++) {
|
||||
TIFFWriteScanline(tif, &imgData[irow * ncol], irow, 0);
|
||||
}
|
||||
TIFFClose(tif);
|
||||
} else {
|
||||
std::cout << "could not open file " << imgname << " for writing\n";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
float *ReadFromTiff(const char *imgname, uint32_t &nrow, uint32_t &ncol) {
|
||||
TIFF *tif = TIFFOpen(imgname, "r");
|
||||
if (tif) {
|
||||
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &ncol);
|
||||
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &nrow);
|
||||
float *imgData = new float[ncol * nrow];
|
||||
for (uint32_t irow = 0; irow < nrow; ++irow) {
|
||||
TIFFReadScanline(tif, &imgData[irow * ncol], irow);
|
||||
}
|
||||
TIFFClose(tif);
|
||||
return imgData;
|
||||
} else {
|
||||
std::cout << "could not open file " << imgname << " for reading\n";
|
||||
return nullptr;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user