Commit 58d19933 authored by Teresa's avatar Teresa Committed by Sebastien Petitdemange

Tiff implementation

parent e4464f51
......@@ -73,6 +73,10 @@ ifneq ($(COMPILE_EDFGZ_SAVING),0)
CORE_LDLIBS += -lz
endif
ifneq ($(COMPILE_TIFF_SAVING),0)
CORE_LDLIBS += -ltiff
endif
ifneq ($(COMPILE_CONFIG),0)
CORE_LDLIBS += -L../third-party/libconfig/lib/.libs -Wl,-rpath=$(shell pwd)/../third-party/libconfig/lib/.libs -lconfig++
endif
......
......@@ -46,6 +46,7 @@ COMPILE_CBF_SAVING=0
COMPILE_NXS_SAVING=0
COMPILE_FITS_SAVING=0
COMPILE_EDFGZ_SAVING=0
COMPILE_TIFF_SAVING=0
COMPILE_CONFIG=1
LINK_STRICT_VERSION=0
export COMPILE_CORE COMPILE_SPS_IMAGE COMPILE_SIMULATOR \
......@@ -54,5 +55,5 @@ export COMPILE_CORE COMPILE_SPS_IMAGE COMPILE_SIMULATOR \
COMPILE_MYTHEN COMPILE_UEYE COMPILE_XH COMPILE_XPAD COMPILE_PERKINELMER \
COMPILE_ANDOR COMPILE_PHOTONICSCIENCE COMPILE_PCO COMPILE_MARCCD \
COMPILE_POINTGREY COMPILE_IMXPAD COMPILE_CBF_SAVING COMPILE_NXS_SAVING \
COMPILE_FITS_SAVING COMPILE_EDFGZ_SAVING COMPILE_CONFIG\
COMPILE_FITS_SAVING COMPILE_EDFGZ_SAVING COMPILE_TIFF_SAVING COMPILE_CONFIG\
LINK_STRICT_VERSION
......@@ -68,6 +68,7 @@ namespace lima {
NXS, ///< Soleil Nexus format
FITS, ///< Flexible Image Transport Layer (NOST)
EDFGZ, ///< EDF format with gzip compression
TIFFFormat, ///< TIFF format
};
enum SavingMode
......@@ -417,6 +418,8 @@ namespace lima {
aFileFormatHumanPt = "FITS";break;
case CtSaving::EDFGZ:
aFileFormatHumanPt = "EDF gzip";break;
case CtSaving::TIFFFormat:
aFileFormatHumanPt = "TIFF";break;
default:
aFileFormatHumanPt = "RAW";break;
}
......@@ -435,6 +438,7 @@ namespace lima {
else if(buffer == "fits") fileFormat = CtSaving::FITS;
else if(buffer == "edf gzip") fileFormat = CtSaving::EDFGZ;
else if(buffer == "raw") fileFormat = CtSaving::RAW;
else if(buffer == "tiff") fileFormat = CtSaving::TIFFFormat;
else
{
std::ostringstream msg;
......
......@@ -69,6 +69,7 @@
<exclude>**/CtSaving_Cbf.cpp</exclude>
<exclude>**/CtSaving_Fits.cpp</exclude>
<exclude>**/CtSpsImage.cpp</exclude>
<exclude>**/CtSaving_Tiff.cpp</exclude>
</excludes>
<includePaths>
<includePath>${project.basedir}/include</includePath>
......
......@@ -124,6 +124,7 @@ using namespace lima;
NXS,
FITS,
EDFGZ,
TIFFFormat,
};
enum SavingMode {
......
......@@ -49,6 +49,10 @@
#include "CtSaving_Fits.h"
#endif
#ifdef WITH_TIFF_SAVING
#include "CtSaving_Tiff.h"
#endif
#include "TaskMgr.h"
#include "SinkTask.h"
......@@ -158,6 +162,11 @@ void CtSaving::Parameters::checkValid() const
THROW_CTL_ERROR(InvalidValue) << "CBF file format does not support "
"multi frame per file";
break;
case TIFFFormat :
if(framesPerFile > 1)
THROW_CTL_ERROR(InvalidValue) << "TIFF file format does not support "
"multi frame per file";
break;
#endif
#ifndef __unix
#pragma message ( "--- WARNING / TODO - no cases???" )
......@@ -291,6 +300,12 @@ void CtSaving::Stream::createSaveContainer()
#ifndef WITH_EDFGZ_SAVING
THROW_CTL_ERROR(NotSupported) << "Lima is not compiled with the edf gzip "
"saving option, not managed";
#endif
goto common;
case TIFFFormat:
#ifndef WITH_TIFF_SAVING
THROW_CTL_ERROR(NotSupported) << "Lima is not compiled with the tiff "
"saving option, not managed";
#endif
goto common;
case RAW:
......@@ -329,6 +344,12 @@ void CtSaving::Stream::createSaveContainer()
case FITS:
m_save_cnt = new SaveContainerFits(*this);
break;
#endif
#ifdef WITH_TIFF_SAVING
case TIFFFormat:
m_save_cnt = new SaveContainerTiff(*this);
m_pars.framesPerFile = 1;
break;
#endif
default:
break;
......@@ -1593,6 +1614,7 @@ void CtSaving::_prepare()
case EDF: fileFormat = HwSavingCtrlObj::EDF_FORMAT_STR;break;
case CBFFormat: fileFormat = HwSavingCtrlObj::CBF_FORMAT_STR;break;
case HARDWARE_SPECIFIC: fileFormat = m_specific_hardware_format;break;
case TIFFFormat: fileFormat = HwSavingCtrlObj::TIFF_FORMAT_STR;break;
default:
THROW_CTL_ERROR(NotSupported) << "Not supported yet";break;
}
......
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This 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 software 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/>.
//###########################################################################
#ifdef __unix
#include <sys/time.h>
#else
#include <time_compat.h>
#endif
#include <iostream>
#include <memory>
#include <numeric>
#include <functional>
#include <sstream>
#include "CtSaving_Tiff.h"
using namespace lima;
/** @brief saving container
*
* This class manage file saving
*/
SaveContainerTiff::SaveContainerTiff(CtSaving::Stream& stream) :
CtSaving::SaveContainer(stream)
{
DEB_CONSTRUCTOR();
}
SaveContainerTiff::~SaveContainerTiff()
{
DEB_DESTRUCTOR();
}
bool SaveContainerTiff::_open(const std::string &filename,
std::ios_base::openmode flags)
{
DEB_MEMBER_FUNCT();
_filename = filename;
return true;
}
void SaveContainerTiff::_close()
{
DEB_MEMBER_FUNCT();
}
void SaveContainerTiff::_writeFile(Data &aData,
CtSaving::HeaderMap &aHeader,
CtSaving::FileFormat aFormat)
{
DEB_MEMBER_FUNCT();
TIFF *image;
if((image = TIFFOpen((const char*)_filename.c_str(), "w")) == NULL)
{
DEB_TRACE()<<"SaveContainerTiff::_writeFile() - not able to open tiff file";
throw LIMA_CTL_EXC(Error,"SaveContainerTiff::_writeFile() - not able to open tiff file");
}
/* If additional info wants to be written */
char add_info[1000] = "\0";
sprintf(add_info,"Frame number %d", aData.frameNumber);
TIFFSetField(image, TIFFTAG_IMAGEWIDTH, aData.dimensions[0]);
TIFFSetField(image, TIFFTAG_IMAGELENGTH, aData.dimensions[1]);
printf("Teresa: _writeFile (tiff) \n");
printf("Teresa: dim[0] %d \n", aData.dimensions[0]);
printf("Teresa: dim[1] %d \n", aData.dimensions[1]);
switch(aData.type)
{
case Data::UINT8:
printf("Teresa: data type uint8\n");
break;
case Data::INT8:
printf("Teresa: data type int8\n");
break;
case Data::UINT16:
printf("Teresa: data type uint16\n");
break;
case Data::INT16:
printf("Teresa: data type int16\n");
break;
case Data::UINT32:
printf("Teresa: data type uint32\n");
break;
case Data::INT32:
printf("Teresa: data type int32\n");
break;
case Data::UINT64:
printf("Teresa: data type uint64\n");
break;
case Data::INT64:
printf("Teresa: data type int64\n");
break;
case Data::FLOAT:
printf("Teresa: data type float\n");
break;
case Data::DOUBLE:
printf("Teresa: data type double\n");
break;
default:
break; // @todo ERROR has to be manage
}
// Tengo que revisar que hacer con el datatype. Afecta a:
// -> TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 8);
// -> TIFFWriteEncodedStrip(image, 0, (unsigned char*)aData.data(), (aData.dimensions[0]* aData.dimensions[1] * 2)); (el factor 2 y el cast a (unsigned char*)
// TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 16);
// TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(image, TIFFTAG_SAMPLEFORMAT, 3);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, aData.dimensions[1]);
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(image, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); // set the origin of the image.
//TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
//TIFFSetField(image, TIFFTAG_XRESOLUTION, 150.0);
//TIFFSetField(image, TIFFTAG_YRESOLUTION, 150.0);
//TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
TIFFSetField(image, TIFFTAG_SOFTWARE, "Lima image");
TIFFSetField(image, TIFFTAG_IMAGEDESCRIPTION, add_info);
_writeTIFF(image, aData.data(), aData.dimensions[0], aData.dimensions[1], 1, aData.type);
for (int i = 0; i < 40000; i++){
if (((uint32*)aData.data())[i] != 0.){
printf("Teresa: buf %d %f \n",i, ((uint32*)aData.data())[5000]);
}
}
// Write the information to the file
// long w_size = TIFFWriteEncodedStrip(image, 0, (unsigned char*)aData.data(), (aData.dimensions[0]* aData.dimensions[1] * 4));
// long w_size = TIFFWriteEncodedStrip(image, 0, (unsigned char*)aData.data(), (aData.dimensions[0]* aData.dimensions[1] * 4));
// DEB_TRACE() << "Bytes written to tif file : " << w_size;
// printf("Teresa: Bytes written to tif file %d \n:", w_size);
// Close the file
TIFFClose(image);
}
int SaveContainerTiff::_writeTIFF(TIFF * tif, void *data, size_t w, size_t h,
size_t c, Data::TYPE datatype)
{
uint32 rowsperstrip;
int ok;
size_t k, i;
uint32 *line;
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (uint32) w);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (uint32) h);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_SEPARATE);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (uint16) c);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, (uint16) sizeof(uint32) * 8);
TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
rowsperstrip = TIFFDefaultStripSize(tif, (uint32) h);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
ok = 1;
for (k = 0; ok && k < c; k++)
for (i = 0; ok && i < h; i++) {
line = (uint32 *) ((uint32*)data + (i + k * h) * w);
if (TIFFWriteScanline(tif, line, (uint32) i, (tsample_t) k) < 0) {
fprintf(stderr, "writeTIFF: error writing row %i\n", (int) i);
ok = 0;
}
}
return ok;
}
//###########################################################################
//
// Copyright (C) 2012 Alexander Lenz <alexander.lenz@frm2.tum.de>
//
// This 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 software 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 CTSAVING_TIFF_H
#define CTSAVING_TIFF_H
#include <tiffio.h>
#include "CtSaving.h"
namespace lima {
class SaveContainerTiff : public CtSaving::SaveContainer
{
DEB_CLASS_NAMESPC(DebModControl,"Saving TIFF Container","Control");
public:
SaveContainerTiff(CtSaving::Stream& stream);
virtual ~SaveContainerTiff();
protected:
virtual bool _open(const std::string &filename,
std::ios_base::openmode flags);
virtual void _close();
virtual void _writeFile(Data &data,
CtSaving::HeaderMap &aHeader,
CtSaving::FileFormat);
private:
CtSaving::FileFormat m_format;
Mutex m_lock;
std::string _filename;
int _writeTIFF(TIFF * tif, void *data, size_t w, size_t h,
size_t c, Data::TYPE datatype);
};
}
#endif // CTSAVING_TIFF_H
......@@ -51,6 +51,10 @@ ifndef COMPILE_EDFGZ_SAVING
COMPILE_EDFGZ_SAVING = 0
endif
ifndef COMPILE_TIFF_SAVING
COMPILE_TIFF_SAVING = 0
endif
ifneq ($(COMPILE_CBF_SAVING),0)
ct-objs += CtSaving_Cbf.o
INCLUDES += -I../../third-party/CBFLib/include
......@@ -78,6 +82,11 @@ ifneq ($(COMPILE_EDFGZ_SAVING),0)
CXXFLAGS += -DWITH_EDFGZ_SAVING
endif
ifneq ($(COMPILE_TIFF_SAVING),0)
ct-objs += CtSaving_Tiff.o
CXXFLAGS += -DWITH_TIFF_SAVING
endif
ifndef COMPILE_SPS_IMAGE
COMPILE_SPS_IMAGE = 0
endif
......
......@@ -45,6 +45,7 @@ namespace lima
static const char *RAW_FORMAT_STR;
static const char *EDF_FORMAT_STR;
static const char *CBF_FORMAT_STR;
static const char *TIFF_FORMAT_STR;
explicit HwSavingCtrlObj(int capabilities = 0);
virtual ~HwSavingCtrlObj();
......
......@@ -34,6 +34,7 @@ public:
static const char *RAW_FORMAT_STR;
static const char *EDF_FORMAT_STR;
static const char *CBF_FORMAT_STR;
static const char *TIFF_FORMAT_STR;
explicit HwSavingCtrlObj(int capabilities = 0);
virtual ~HwSavingCtrlObj();
......
......@@ -28,6 +28,7 @@ using namespace lima;
const char* HwSavingCtrlObj::RAW_FORMAT_STR = "RAW"; ///< Raw format (no header)
const char* HwSavingCtrlObj::EDF_FORMAT_STR = "EDF"; ///< EDF format (Esrf Data Format)
const char* HwSavingCtrlObj::CBF_FORMAT_STR = "CBF"; ///< CBF format
const char* HwSavingCtrlObj::TIFF_FORMAT_STR = "TIFF"; ///< TIFF format
#ifdef __linux__
class HwSavingCtrlObj::DirectoryCallback : public DirectoryEvent::Callback
{
......
......@@ -193,6 +193,10 @@ INSTALL_CONFIG_DEFINES += -DWITH_FITS_SAVING
INSTALL_DEPS += cfitsio.install CCfits.install
endif
ifneq ($(COMPILE_TIFF_SAVING),0)
INSTALL_CONFIG_DEFINES += -DWITH_TIFF_SAVING
endif
ifneq ($(COMPILE_CONFIG_CONTEXT),0)
INSTALL_CONFIG_DEFINES += -DWITH_CONFIG_CONTEXT
INSTALL_DEPS += libconfig.install
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment