1 #define _CRT_SECURE_NO_WARNINGS
26 printf(
"QxrdFileSaver::QxrdFileSaver(%p)\n",
this);
33 printf(
"QxrdFileSaver::~QxrdFileSaver(%p)\n",
this);
75 proc -> prop_SaverQueueLength()->incValue(1);
84 proc -> prop_SaverQueueLength()->incValue(-1);
90 QFileInfo f(filePath);
94 dir.mkpath(dir.absolutePath());
108 QString base = f.completeBaseName();
109 QString suff = f.suffix();
116 width = acq->get_FileOverflowWidth();
119 for (
int i=1; ; i++) {
120 QString newname = dir.filePath(base+QString().sprintf(
"-%0*d.",width,i)+suff);
121 QFileInfo f(newname);
132 #define TIFFCHECK(a) if (res && ((a)==0)) { res = 0; }
138 INVOKE_CHECK(QMetaObject::invokeMethod(
this,
"saveImageDataPrivate",
139 Qt::QueuedConnection,
140 Q_ARG(QString, name),
143 Q_ARG(
int, canOverwrite)));
183 INVOKE_CHECK(QMetaObject::invokeMethod(
this,
"saveDoubleDataPrivate",
184 Qt::QueuedConnection,
188 Q_ARG(
int,canOverwrite)));
201 int nrows = image -> get_Height();
202 int ncols = image -> get_Width();
210 TIFF* tif = TIFFOpen(qPrintable(name),
"w");
214 TIFFCHECK(TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, ncols));
215 TIFFCHECK(TIFFSetField(tif, TIFFTAG_IMAGELENGTH, nrows));
216 TIFFCHECK(TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1));
218 TIFFCHECK(TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG));
219 TIFFCHECK(TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32));
220 TIFFCHECK(TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP));
222 TIFFCHECK(TIFFSetField(tif, TIFFTAG_DOCUMENTNAME, qPrintable(image->get_FileName())));
223 TIFFCHECK(TIFFSetField(tif, TIFFTAG_DATETIME, qPrintable(image->get_DateTime().toString(
"yyyy:MM:dd hh:mm:ss"))));
225 QVector<float> buffvec(ncols);
226 float* buffer = buffvec.data();
228 for (
int y=0; y<nrows; y++) {
229 for (
int x=0; x<ncols; x++) {
230 buffer[x] = image->value(x,y);
233 TIFFCHECK(TIFFWriteScanline(tif, buffer, y, 0));
238 image -> set_FileBase(QFileInfo(name).fileName());
239 image -> set_FileName(name);
240 image -> set_Title(name);
242 image -> set_ObjectSaved(
true);
244 image -> saveMetaData();
249 if (proc->get_SaveOverflowFiles()) {
253 proc -> updateEstimatedTime(proc -> prop_SaveSubtractedTime(), tic.elapsed());
254 proc -> set_FileName(name);
258 arg(name).arg(tic.restart()));
299 INVOKE_CHECK(QMetaObject::invokeMethod(
this,
"saveMaskDataPrivate",
300 Qt::QueuedConnection,
303 Q_ARG(
int,canOverwrite)));
313 int nrows = image -> get_Height();
314 int ncols = image -> get_Width();
322 TIFF* tif = TIFFOpen(qPrintable(name),
"w");
327 TIFFCHECK(TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, ncols));
328 TIFFCHECK(TIFFSetField(tif, TIFFTAG_IMAGELENGTH, nrows));
329 TIFFCHECK(TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1));
330 TIFFCHECK(TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE));
331 TIFFCHECK(TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG));
332 TIFFCHECK(TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8));
333 TIFFCHECK(TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT));
335 TIFFCHECK(TIFFSetField(tif, TIFFTAG_DOCUMENTNAME, qPrintable(image->get_FileName())));
336 TIFFCHECK(TIFFSetField(tif, TIFFTAG_DATETIME, qPrintable(image->get_DateTime().toString(
"yyyy:MM:dd hh:mm:ss"))));
338 QVector<quint8> buffvec(ncols);
339 quint8* buffer = buffvec.data();
341 for (
int y=0; y<nrows; y++) {
342 for (
int x=0; x<ncols; x++) {
343 buffer[x] = image->value(x,y);
346 TIFFCHECK(TIFFWriteScanline(tif, buffer, y, 0));
351 image -> set_FileBase(QFileInfo(name).fileName());
352 image -> set_FileName(name);
353 image -> set_Title(name);
355 image -> set_ObjectSaved(
true);
357 image -> saveMetaData();
374 INVOKE_CHECK(QMetaObject::invokeMethod(
this,
"saveRaw32DataPrivate",
375 Qt::QueuedConnection,
379 Q_ARG(
int,canOverwrite)));
392 int nrows = image -> get_Height();
393 int ncols = image -> get_Width();
405 TIFF* tif = TIFFOpen(qPrintable(name),
"w");
409 int nsum = image->get_SummedExposures();
411 TIFFCHECK(TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, ncols));
412 TIFFCHECK(TIFFSetField(tif, TIFFTAG_IMAGELENGTH, nrows));
413 TIFFCHECK(TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1));
415 TIFFCHECK(TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG));
418 TIFFCHECK(TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8));
419 }
else if (nsum == 1) {
420 TIFFCHECK(TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16));
422 TIFFCHECK(TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32));
425 TIFFCHECK(TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT));
427 TIFFCHECK(TIFFSetField(tif, TIFFTAG_DOCUMENTNAME, qPrintable(image->get_FileName())));
428 TIFFCHECK(TIFFSetField(tif, TIFFTAG_DATETIME, qPrintable(image->get_DateTime().toString(
"yyyy:MM:dd hh:mm:ss"))));
431 QVector<quint8> buffvec(ncols);
432 quint8* buffer = buffvec.data();
434 for (
int y=0; y<nrows; y++) {
435 for (
int x=0; x<ncols; x++) {
436 buffer[x] = image->value(x,y);
439 TIFFCHECK(TIFFWriteScanline(tif, buffer, y, 0));
441 }
else if (nsum == 1) {
442 QVector<quint16> buffvec(ncols);
443 quint16* buffer = buffvec.data();
445 for (
int y=0; y<nrows; y++) {
446 for (
int x=0; x<ncols; x++) {
447 buffer[x] = image->value(x,y);
450 TIFFCHECK(TIFFWriteScanline(tif, buffer, y, 0));
453 QVector<quint32> buffvec(ncols);
454 quint32* buffer = buffvec.data();
456 for (
int y=0; y<nrows; y++) {
457 for (
int x=0; x<ncols; x++) {
458 buffer[x] = image->value(x,y);
461 TIFFCHECK(TIFFWriteScanline(tif, buffer, y, 0));
467 image -> set_FileBase(QFileInfo(name).fileName());
468 image -> set_FileName(name);
469 image -> set_Title(name);
471 image -> set_ObjectSaved(
true);
473 image -> saveMetaData(name);
479 if (proc->get_SaveOverflowFiles()) {
483 proc -> updateEstimatedTime(acq -> prop_Raw32SaveTime(), tic.elapsed());
484 proc -> set_FileName(name);
488 arg(name).arg(tic.restart()));
507 INVOKE_CHECK(QMetaObject::invokeMethod(
this,
"saveRaw16DataPrivate",
508 Qt::QueuedConnection,
512 Q_ARG(
int,canOverwrite)))
525 int nrows = image -> get_Height();
526 int ncols = image -> get_Width();
534 TIFF* tif = TIFFOpen(qPrintable(name),
"w");
539 TIFFCHECK(TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, ncols));
540 TIFFCHECK(TIFFSetField(tif, TIFFTAG_IMAGELENGTH, nrows));
541 TIFFCHECK(TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1));
543 TIFFCHECK(TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG));
544 TIFFCHECK(TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16));
545 TIFFCHECK(TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT));
547 TIFFCHECK(TIFFSetField(tif, TIFFTAG_DOCUMENTNAME, qPrintable(image->get_FileName())));
548 TIFFCHECK(TIFFSetField(tif, TIFFTAG_DATETIME, qPrintable(image->get_DateTime().toString(
"yyyy:MM:dd hh:mm:ss"))));
550 QVector<quint16> buffvec(ncols);
551 quint16* buffer = buffvec.data();
553 for (
int y=0; y<nrows; y++) {
554 for (
int x=0; x<ncols; x++) {
555 buffer[x] = image->value(x,y);
558 TIFFCHECK(TIFFWriteScanline(tif, buffer, y, 0));
563 image -> set_FileBase(QFileInfo(name).fileName());
564 image -> set_FileName(name);
565 image -> set_Title(name);
567 image -> set_ObjectSaved(
true);
569 image -> saveMetaData(name);
575 if (proc->get_SaveOverflowFiles()) {
579 proc -> updateEstimatedTime(acq -> prop_Raw16SaveTime(), tic.elapsed());
580 proc -> set_FileName(name);
584 arg(name).arg(tic.restart()));
603 INVOKE_CHECK(QMetaObject::invokeMethod(
this,
"saveTextDataPrivate",
604 Qt::QueuedConnection,
608 Q_ARG(
int,canOverwrite)))
618 int nrows = image -> get_Height();
619 int ncols = image -> get_Width();
623 QString base = f.completeBaseName();
624 QString suff = f.suffix();
627 name = dir.filePath(base+
".txt");
636 FILE* file = fopen(qPrintable(name),
"a");
640 QString separator =
"\t";
643 separator = proc -> get_SaveAsTextSeparator();
647 strncpy(sep,qPrintable(separator),10);
652 nperline = proc -> get_SaveAsTextPerLine();
655 for (
int y=0; y<nrows; y++) {
656 for (
int x=0; x<ncols; x++) {
657 if (nperline && ((x % nperline)==0)) {
662 fprintf(file,
"%g",image->value(x,y));
669 image -> set_FileBase(QFileInfo(name).fileName());
670 image -> set_FileName(name);
671 image -> set_Title(name);
673 image -> set_ObjectSaved(
true);
675 image -> saveMetaData();
678 if (proc->get_SaveOverflowFiles()) {
682 proc -> set_FileName(name);
693 INVOKE_CHECK(QMetaObject::invokeMethod(
this,
"writeOutputScanPrivate",
694 Qt::QueuedConnection,
697 Q_ARG(QString,fileName)));
707 if (fileName.isNull()) {
717 fileName = image -> get_FileName();
720 QFileInfo fi(fileName);
722 QString fileBase = fi.completeBaseName();
723 QString extension =
".avg";
728 extension = exp->get_ScanFileExtension();
731 QString name = QDir(dir).filePath(fileBase+extension);
737 FILE *f = fopen(qPrintable(name),
"a");
763 INVOKE_CHECK(QMetaObject::invokeMethod(
this,
"writeOutputScanPrivate",
764 Qt::QueuedConnection,
765 Q_ARG(FILE*, logFile),
767 Q_ARG(QString,fileName)))
776 }
else if (logFile) {
781 if (fileName.isNull()) {
790 fileName = image -> get_FileName();
791 imageNumber = image -> get_ImageNumber();
794 fprintf(logFile,
"#S %d qxrd.integrate \"%s\" %g %g\n",
796 qPrintable(fileName),
800 fprintf(logFile,
"#D %s\n", qPrintable(QDateTime::currentDateTime().toString(
"ddd MMM d hh:mm:ss yyyy")));
801 fprintf(logFile,
"#N 2\n");
802 fprintf(logFile,
"#L x y\n");
804 int n = data->size();
805 const double *x = data->x();
806 const double *y = data->y();
812 negh = exp->get_ScanDataNegative();
816 for (
int i=0; i<n; i++) {
817 fprintf(logFile,
"%E %E\n", x[i], y[i]);
819 }
else if (negh == 1) {
820 for (
int i=0; i<n; i++) {
822 fprintf(logFile,
"%E %E\n", x[i], y[i]);
824 fprintf(logFile,
"%E %E\n", x[i], 0.0);
828 for (
int i=0; i<n; i++) {
830 fprintf(logFile,
"%E %E\n", x[i], y[i]);
840 proc -> updateEstimatedTime(proc -> prop_SaveIntegratedDataTime(), tic.restart());
850 QString ovfname = name+
".overflow";
852 FILE *ovfile = fopen(qPrintable(ovfname),
"w+");
855 int novf = overflow ->countOverflowPixels();
857 fprintf(ovfile,
"#S %d overflow pixels for file %s\n", novf, qPrintable(name));
858 fprintf(ovfile,
"#N 3\n");
859 fprintf(ovfile,
"#L x y d\n");
861 int ncols = overflow -> get_Width();
862 int nrows = overflow -> get_Height();
864 for (
int row=0; row<nrows; row++) {
865 for (
int col=0; col<ncols; col++) {
866 if (overflow->value(col,row)) {
867 fprintf(ovfile,
"%d\t%d\t1\n", col, row);
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
void writeOutputScanPrivate(FILE *logFile, QcepIntegratedDataPtr data, QString fileName=QString())
QxrdDataProcessorWPtr m_Processor
virtual void criticalMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QxrdExperimentWPtr experiment() const
void saveOverflowData(QString name, QcepMaskDataPtr overflow)
QWeakPointer< QxrdDataProcessor > QxrdDataProcessorWPtr
QxrdFileSaver(QcepAllocatorWPtr allocator)
void saveRaw16DataPrivate(QString name, QcepInt16ImageDataPtr image, QcepMaskDataPtr overflow, int canOverwrite)
qint64 qcepDebug(int cond)
QSharedPointer< QxrdAcquisition > QxrdAcquisitionPtr
QxrdAcquisitionWPtr acquisition() const
void saveInt32Data(QString name, QcepInt32ImageDataPtr image, QcepMaskDataPtr overflow, int canOverwrite)
QSharedPointer< QxrdDataProcessor > QxrdDataProcessorPtr
QxrdExperimentWPtr m_Experiment
void saveRaw32DataPrivate(QString name, QcepInt32ImageDataPtr image, QcepMaskDataPtr overflow, int canOverwrite)
void mkPath(QString filePath)
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
QSharedPointer< QcepIntegratedData > QcepIntegratedDataPtr
void saveDoubleData(QString name, QcepDoubleImageDataPtr image, QcepMaskDataPtr overflow, int canOverwrite)
QString uniqueFileName(QString name)
#define INVOKE_CHECK(res)
QcepAllocatorWPtr m_Allocator
void saveTextDataPrivate(QString name, QcepDoubleImageDataPtr image, QcepMaskDataPtr overflow, int canOverwrite)
void saveTextData(QString name, QcepDoubleImageDataPtr image, QcepMaskDataPtr overflow, int canOverwrite)
QxrdAcquisitionWPtr m_Acquisition
void saveRaw16Data(QString name, QcepInt16ImageDataPtr image, QcepMaskDataPtr overflow, int canOverwrite)
QWeakPointer< QcepAllocator > QcepAllocatorWPtr
void saveRaw32Data(QString name, QcepInt32ImageDataPtr image, QcepMaskDataPtr overflow, int canOverwrite)
void saveDoubleDataPrivate(QString name, QcepDoubleImageDataPtr image, QcepMaskDataPtr overflow, int canOverwrite)
void saveImageData(QString name, QcepImageDataBasePtr image, QcepMaskDataPtr overflow, int canOverwrite)
void saveMaskData(QString name, QcepMaskDataPtr image, int canOverwrite)
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QWeakPointer< QxrdAcquisition > QxrdAcquisitionWPtr
QSharedPointer< QcepInt32ImageData > QcepInt32ImageDataPtr
QcepApplication * g_Application
void writeOutputScan(FILE *logFile, QcepIntegratedDataPtr data, QString fileName=QString())
void setProcessor(QxrdDataProcessorWPtr proc)
QSharedPointer< QcepImageDataBase > QcepImageDataBasePtr
QSharedPointer< QcepInt16ImageData > QcepInt16ImageDataPtr
QSharedPointer< QcepMaskData > QcepMaskDataPtr
void saveImageDataPrivate(QString name, QcepImageDataBasePtr image, QcepMaskDataPtr overflow, int canOverwrite)
void saveMaskDataPrivate(QString name, QcepMaskDataPtr image, int canOverwrite)
void setExperiment(QxrdExperimentWPtr expt)
void setAcquisition(QxrdAcquisitionWPtr acq)
void saveInt16Data(QString name, QcepInt16ImageDataPtr image, QcepMaskDataPtr overflow, int canOverwrite)
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr