This repository has been archived by the owner on Oct 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathMatlabToImf.cpp
169 lines (138 loc) · 4.42 KB
/
MatlabToImf.cpp
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
/*============================================================================
OpenEXR for Matlab
Distributed under the MIT License (the "License");
see accompanying file LICENSE for details
or copy at http://opensource.org/licenses/MIT
Originated from HDRITools - High Dynamic Range Image Tools
Copyright 2011 Program of Computer Graphics, Cornell University
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
-----------------------------------------------------------------------------
Authors:
Jinwei Gu <jwgu AT cs DOT cornell DOT edu>
Edgar Velazquez-Armendariz <eva5 AT cs DOT cornell DOT edu>
Manuel Leonhardt <leom AT hs-furtwangen DOT de>
============================================================================*/
#include <string>
#include <mex.h>
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wlong-long"
#pragma clang diagnostic ignored "-Wdeprecated-register"
#pragma clang diagnostic ignored "-Wextra"
#endif
#include "MatlabToImf.h"
#include <ImfAttribute.h>
#include <ImfStringAttribute.h>
#include <ImfIntAttribute.h>
#include <ImfFloatAttribute.h>
#include <ImfDoubleAttribute.h>
#include <ImfStringVectorAttribute.h>
#ifdef __clang__
#pragma clang diagnostic pop
#endif
using namespace OPENEXR_IMF_INTERNAL_NAMESPACE;
namespace
{
template <typename T>
T* toAttributeImp(const mxArray * pa)
{
mexWarnMsgIdAndTxt("OpenEXR:unsupported",
"Unsupported conversion to Imf::Attribute from \"%s\"", mxGetClassName(pa));
return NULL;
}
template <>
StringAttribute* toAttributeImp(const mxArray * pa)
{
std::string value;
OpenEXRforMatlab::toNativeCheck(pa, value);
StringAttribute* attr = new StringAttribute(value);
return attr;
}
template <>
StringVectorAttribute* toAttributeImp(const mxArray * pa)
{
StringVector value;
const mwSize numel = mxGetNumberOfElements(pa);
for (mwIndex i = 0; i != numel; ++i) {
char * txt = mxArrayToString(mxGetCell(pa, i));
assert(txt != NULL);
value.push_back(std::string(txt));
mxFree(txt);
}
StringVectorAttribute* attr = new StringVectorAttribute(value);
return attr;
}
template <>
IntAttribute* toAttributeImp(const mxArray * pa)
{
int value = 0;
OpenEXRforMatlab::convertData(&value, pa, mxGetClassID(pa), 1);
IntAttribute* attr = new IntAttribute(value);
return attr;
}
template <>
FloatAttribute* toAttributeImp(const mxArray * pa)
{
float value = 0.0f;
OpenEXRforMatlab::convertData(&value, pa, mxGetClassID(pa), 1);
FloatAttribute* attr = new FloatAttribute(value);
return attr;
}
template <>
DoubleAttribute* toAttributeImp(const mxArray * pa)
{
double value = 0.0;
OpenEXRforMatlab::convertData(&value, pa, mxGetClassID(pa), 1);
DoubleAttribute* attr = new DoubleAttribute(value);
return attr;
}
}
Attribute* OpenEXRforMatlab::toAttribute(const mxArray * pa)
{
if (mxIsChar(pa)) {
return toAttributeImp<StringAttribute> (pa);
}
else if (mxIsCell(pa)) {
mwSize numel = 0;
if (isVector(pa, numel)) {
// First pass: check if all are strings
for (mwIndex i = 0; i != numel; ++i) {
if (!mxIsChar(mxGetCell(pa, i))) {
return NULL;
}
}
return toAttributeImp<StringVectorAttribute> (pa);
}
}
else if (mxIsNumeric(pa)) {
mwSize M = 0, N = 0;
if (!isMatrix(pa, M, N)) {
return NULL;
}
if (M == 1 && N == 1) {
const mxClassID type = mxGetClassID(pa);
switch(type) {
case mxSINGLE_CLASS:
return toAttributeImp<FloatAttribute> (pa);
case mxINT8_CLASS:
case mxUINT8_CLASS:
case mxINT16_CLASS:
case mxUINT16_CLASS:
case mxINT32_CLASS:
return toAttributeImp<IntAttribute> (pa);
case mxUINT32_CLASS:
case mxINT64_CLASS:
case mxUINT64_CLASS:
case mxDOUBLE_CLASS:
return toAttributeImp<DoubleAttribute> (pa);
default:
mexWarnMsgIdAndTxt("OpenEXR:unsupported",
"Unknown scalar type: \"%s\"", mxGetClassName(pa));
return NULL;
}
}
}
return NULL;
}