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
/
ImfToMatlab.h
146 lines (113 loc) · 3.27 KB
/
ImfToMatlab.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
/*============================================================================
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>
============================================================================*/
#pragma once
#include <mex.h>
#include <ImfNamespace.h>
#include <ImfAttribute.h>
// Utilities to convert from OpenEXR types to Matlab types
namespace OpenEXRforMatlab
{
///////////////////////////////////////////////////////////////////////////////
// Traits for matlab types
///////////////////////////////////////////////////////////////////////////////
template<typename T>
struct mex_traits
{
static const mxClassID classID = mxUNKNOWN_CLASS;
};
template<>
struct mex_traits<double>
{
static const mxClassID classID = mxDOUBLE_CLASS;
};
template<>
struct mex_traits<float>
{
static const mxClassID classID = mxSINGLE_CLASS;
};
template<>
struct mex_traits<int8_T>
{
static const mxClassID classID = mxINT8_CLASS;
};
template<>
struct mex_traits<uint8_T>
{
static const mxClassID classID = mxUINT8_CLASS;
};
template<>
struct mex_traits<int16_T>
{
static const mxClassID classID = mxINT16_CLASS;
};
template<>
struct mex_traits<uint16_T>
{
static const mxClassID classID = mxUINT16_CLASS;
};
template<>
struct mex_traits<int32_T>
{
static const mxClassID classID = mxINT32_CLASS;
};
template<>
struct mex_traits<uint32_T>
{
static const mxClassID classID = mxUINT32_CLASS;
};
template<>
struct mex_traits<int64_T>
{
static const mxClassID classID = mxINT64_CLASS;
};
template<>
struct mex_traits<uint64_T>
{
static const mxClassID classID = mxUINT64_CLASS;
};
template<>
struct mex_traits<bool>
{
static const mxClassID classID = mxLOGICAL_CLASS;
mxLogical x;
};
///////////////////////////////////////////////////////////////////////////////
// Conversion from C++ types to Matlab versions
///////////////////////////////////////////////////////////////////////////////
template<typename T>
inline mxArray * fromScalar(T n)
{
mxArray *arr = mxCreateNumericMatrix(1, 1, mex_traits<T>::classID, mxREAL);
T * ptr = reinterpret_cast<T*>(mxGetPr(arr));
*ptr = n;
return arr;
}
template<typename T, size_t N>
inline mxArray * fromArray(const T (&arr)[N])
{
mxArray *mArr = mxCreateNumericMatrix(1, N, mex_traits<T>::classID, mxREAL);
T * ptr = reinterpret_cast<T*>(mxGetPr(mArr));
for (size_t i = 0; i != N; ++i) {
ptr[i] = arr[i];
}
return mArr;
}
// Convert the value of an attribute to a Matlab type. Returns NULL if
// the conversion fails, most likely because the conversion is not
// implemented yet.
mxArray* toMatlab(const OPENEXR_IMF_INTERNAL_NAMESPACE::Attribute & attr);
} // namespace OpenEXRforMatlab