-
Notifications
You must be signed in to change notification settings - Fork 5
/
laumemoryobject.h
291 lines (242 loc) · 8.44 KB
/
laumemoryobject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*********************************************************************************
* *
* Copyright (c) 2017, Dr. Daniel L. Lau *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions are met: *
* 1. Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* 3. All advertising materials mentioning features or use of this software *
* must display the following acknowledgement: *
* This product includes software developed by the <organization>. *
* 4. Neither the name of the <organization> nor the *
* names of its contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY Dr. Daniel L. Lau ''AS IS'' AND ANY *
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
* DISCLAIMED. IN NO EVENT SHALL Dr. Daniel L. Lau BE LIABLE FOR ANY *
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
*********************************************************************************/
#ifndef LAUMEMORYOBJECT_H
#define LAUMEMORYOBJECT_H
#ifndef Q_PROCESSOR_ARM
#include "emmintrin.h"
#endif
#include <QTime>
#include <QtCore>
#include <QDebug>
#include <QObject>
#include <QString>
#include <QMatrix4x4>
#include <QSharedData>
#include <QFileDialog>
#include <QSharedDataPointer>
namespace libtiff
{
#include "tiffio.h"
}
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
class LAUMemoryObjectData : public QSharedData
{
public:
LAUMemoryObjectData();
LAUMemoryObjectData(const LAUMemoryObjectData &other);
LAUMemoryObjectData(unsigned int cols, unsigned int rows, unsigned int chns = 1, unsigned int byts = 1, unsigned int frms = 1);
LAUMemoryObjectData(unsigned long long bytes);
~LAUMemoryObjectData();
static int instanceCounter;
unsigned int numRows, numCols, numChns, numFrms, numByts;
unsigned int stepBytes, frameBytes;
unsigned long long numBytesTotal;
void *buffer;
void allocateBuffer();
};
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
class LAUMemoryObject
{
public:
LAUMemoryObject()
{
data = new LAUMemoryObjectData();
}
LAUMemoryObject(unsigned int cols, unsigned int rows, unsigned int chns = 1, unsigned int byts = 1, unsigned int frms = 1)
{
data = new LAUMemoryObjectData(cols, rows, chns, byts, frms);
}
LAUMemoryObject(unsigned long long bytes)
{
data = new LAUMemoryObjectData(bytes);
}
LAUMemoryObject(const LAUMemoryObject &other) : data(other.data), transformMatrix(other.transformMatrix), anchorPt(other.anchorPt), elapsedTime(other.elapsedTime) { ; }
LAUMemoryObject &operator = (const LAUMemoryObject &other)
{
if (this != &other) {
data = other.data;
transformMatrix = other.transformMatrix;
anchorPt = other.anchorPt;
elapsedTime = other.elapsedTime;
}
return (*this);
}
LAUMemoryObject(QString filename);
LAUMemoryObject(libtiff::TIFF *inTiff);
bool save(QString filename = QString());
bool save(libtiff::TIFF *otTiff, int index = 0);
bool load(libtiff::TIFF *inTiff);
// SEE IF THE POINTERS ARE LOOKING AT SAME MEMORY
bool operator == (const LAUMemoryObject &other) const
{
if (this == &other) {
return (true);
}
return (data->buffer == other.data->buffer);
}
bool operator < (const LAUMemoryObject &other) const
{
if (this == &other) {
return (false);
}
return (elapsedTime < other.elapsedTime);
}
bool operator > (const LAUMemoryObject &other) const
{
if (this == &other) {
return (false);
}
return (elapsedTime > other.elapsedTime);
}
bool operator <= (const LAUMemoryObject &other) const
{
if (this == &other) {
return (true);
}
return (elapsedTime <= other.elapsedTime);
}
bool operator >= (const LAUMemoryObject &other) const
{
if (this == &other) {
return (true);
}
return (elapsedTime >= other.elapsedTime);
}
~LAUMemoryObject() { ; }
inline bool isNull() const
{
return (data->buffer == nullptr);
}
inline bool isValid() const
{
return (data->buffer != nullptr);
}
inline unsigned long long length() const
{
return (data->numBytesTotal);
}
inline QSize size() const
{
return (QSize(width(), height()));
}
inline unsigned int nugget() const
{
return (data->numChns * data->numByts);
}
inline unsigned int width() const
{
return (data->numCols);
}
inline unsigned int height() const
{
return (data->numRows);
}
inline unsigned int depth() const
{
return (data->numByts);
}
inline unsigned int colors() const
{
return (data->numChns);
}
inline unsigned int frames() const
{
return (data->numFrms);
}
inline unsigned int step() const
{
return (data->stepBytes);
}
inline unsigned int block() const
{
return (data->frameBytes);
}
inline unsigned char *pointer()
{
return (scanLine(0));
}
inline unsigned char *constPointer() const
{
return (constScanLine(0));
}
inline unsigned char *scanLine(unsigned int row, unsigned int frame = 0)
{
return (&(((unsigned char *)(data->buffer))[frame * block() + row * step()]));
}
inline unsigned char *constScanLine(unsigned int row, unsigned int frame = 0) const
{
return (&(((unsigned char *)(data->buffer))[frame * block() + row * step()]));
}
inline unsigned char *frame(unsigned int frm = 0)
{
return (scanLine(0, frm));
}
inline unsigned char *constFrame(unsigned int frm = 0) const
{
return (constScanLine(0, frm));
}
inline QMatrix4x4 transform() const
{
return (transformMatrix);
}
inline unsigned int elapsed() const
{
return (elapsedTime);
}
inline QPoint anchor() const
{
return (anchorPt);
}
inline void setTransform(QMatrix4x4 mat)
{
transformMatrix = mat;
}
inline void setElapsed(unsigned int elps)
{
elapsedTime = elps;
}
inline void setAnchor(QPoint pt)
{
anchorPt = pt;
}
protected:
QSharedDataPointer<LAUMemoryObjectData> data;
QMatrix4x4 transformMatrix;
QPoint anchorPt;
unsigned int elapsedTime;
};
Q_DECLARE_METATYPE(LAUMemoryObject);
#endif // LAUMEMORYOBJECT_H