QXRD  0.11.16
qxrdimagedataformathis.cpp
Go to the documentation of this file.
1 #define _CRT_SECURE_NO_WARNINGS
2 
4 #include "qcepimagedata.h"
5 #include "qcepmaskdata.h"
6 #include <QFileInfo>
7 #include "qcepimagedata-ptr.h"
8 
10 
12  : QcepImageDataFormat<double>(name)
13 {
14 }
15 
17 {
18  return Specific;
19 }
20 
21 typedef struct {
22  quint16 FileType;
23  quint16 unk;
24  quint16 HeaderSize; // Size of this file header in Bytes
25  quint32 FileSize; // Size of the whole file in Bytes
26  quint16 ImageHeaderSize; // Size of the image header in Bytes
27  quint16 ULX, ULY, BRX, BRY; // bounding rectangle of the image
28  quint16 NrOfFrames; // self explanatory
29  quint16 Correction; // 0 = none, 1 = offset, 2 = gain, 4 = bad pixel, (ored)
30  double IntegrationTime; // frame time in microseconds
31  quint16 TypeOfNumbers; // short, long integer, float, signed/u};
32 } HISHeader;
33 
35 {
36 }
37 
39 {
40 // printf("QxrdImageDataFormatHis::canLoadFile(%s)\n", qPrintable(path));
41 
42  QxrdImageDataFormatHis* res = NULL;
43 
44  FILE *file = fopen(qPrintable(path), "rb");
45  HISHeader h;
46 
47  if (file) {
48  checkError(fread(&h.FileType, 2, 1, file));
49  checkError(fread(&h.unk, 2, 1, file));
50  checkError(fread(&h.HeaderSize, 2, 1, file));
51  checkError(fread(&h.FileSize, 4, 1, file));
52  checkError(fread(&h.ImageHeaderSize, 2, 1, file));
53  checkError(fread(&h.ULX, 2, 1, file));
54  checkError(fread(&h.ULY, 2, 1, file));
55  checkError(fread(&h.BRX, 2, 1, file));
56  checkError(fread(&h.BRY, 2, 1, file));
57  checkError(fread(&h.NrOfFrames, 2, 1, file));
58  checkError(fread(&h.Correction, 2, 1, file));
59  checkError(fread(&h.IntegrationTime, 8, 1, file));
60  checkError(fread(&h.TypeOfNumbers, 2, 1, file));
61 
62  if (h.FileType == 0x7000 &&
63  h.HeaderSize == 100 &&
64  (h.TypeOfNumbers == 4 || h.TypeOfNumbers == 32)) {
65  res = this;
66  }
67 
68  fclose(file);
69  }
70 
71  return res;
72 }
73 
75 {
76  return NULL;
77 }
78 
80 {
81 // printf("QxrdImageDataFormatHis::loadFile(%s)\n", qPrintable(path));
82 
83  FILE *file = fopen(qPrintable(path), "rb");
84 
85  HISHeader h;
86 
87  if (file) {
88  checkError(fread(&h.FileType, 2, 1, file));
89  checkError(fread(&h.unk, 2, 1, file));
90  checkError(fread(&h.HeaderSize, 2, 1, file));
91  checkError(fread(&h.FileSize, 4, 1, file));
92  checkError(fread(&h.ImageHeaderSize, 2, 1, file));
93  checkError(fread(&h.ULX, 2, 1, file));
94  checkError(fread(&h.ULY, 2, 1, file));
95  checkError(fread(&h.BRX, 2, 1, file));
96  checkError(fread(&h.BRY, 2, 1, file));
97  checkError(fread(&h.NrOfFrames, 2, 1, file));
98  checkError(fread(&h.Correction, 2, 1, file));
99  checkError(fread(&h.IntegrationTime, 8, 1, file));
100  checkError(fread(&h.TypeOfNumbers, 2, 1, file));
101 
102  int width = h.BRX-h.ULX+1;
103  int height = h.BRY-h.ULY+1;
104 
105  fseek(file, 100, SEEK_SET);
106 
107  img -> resize(width, height);
108 
109  if (h.TypeOfNumbers == 4) {
110  quint16 pix;
111  for (int y=0; y<height; y++) {
112  for (int x=0; x<width; x++) {
113  checkError(fread(&pix, 2, 1, file));
114  img -> setValue(x,(height-y-1),pix);
115  }
116  }
117  } else if (h.TypeOfNumbers == 32) {
118  quint32 pix;
119  for (int y=0; y<height; y++) {
120  for (int x=0; x<width; x++) {
121  checkError(fread(&pix, 4, 1, file));
122  img -> setValue(x,(height-y-1),pix);
123  }
124  }
125  }
126 
127  fclose(file);
128 
129  img -> calculateRange();
130 
131  img -> setDefaultFileName(path);
132 
133  return this;
134  }
135 
136  return NULL;
137 }
138 
139 QxrdImageDataFormatHis* QxrdImageDataFormatHis::saveFile(QString /*path*/, QcepImageData<double> * /*img*/, int /*canOverwrite*/)
140 {
141  return NULL;
142 }
QxrdImageDataFormatHis * canSaveFile(QString path)
QxrdImageDataFormatHis * loadFile(QString path, QcepImageData< double > *img)
static QxrdImageDataFormatHis fmt
QxrdImageDataFormatHis(QString name="his")
QxrdImageDataFormatHis * canLoadFile(QString path)
QxrdImageDataFormatHis * saveFile(QString path, QcepImageData< double > *img, int)