vnl_matlab_header.h
Go to the documentation of this file.
1 // This is core/vnl/vnl_matlab_header.h
2 #ifndef vnl_matlab_header_h_
3 #define vnl_matlab_header_h_
4 
5 #undef swap32
6 #undef swap64
7 
8 //:
9 // \file
10 // \brief MATLAB header structure
11 // \author fsm
12 // \verbatim
13 // Modifications
14 // 21 Apr 2009 Kent Williams - Taking care of the byte ordering of the MAT file
15 // \endverbatim
16 
17 #include <vxl_config.h>
18 #include "vnl/vnl_export.h"
19 
20 struct VNL_EXPORT vnl_matlab_header
21 {
22  vxl_int_32 type; // sum of one byte order, one storage specifier and one precision specifier
23  vxl_int_32 rows;
24  vxl_int_32 cols;
25  vxl_int_32 imag;
26  vxl_int_32 namlen;
27 
28  enum type_t {
29  // precision specifier
30  vnl_DOUBLE_PRECISION = 0,
31  vnl_SINGLE_PRECISION = 10,
32  // storage specifier
33  vnl_COLUMN_WISE = 0,
34  vnl_ROW_WISE = 100,
35  // byte order
36  vnl_LITTLE_ENDIAN = 0,
37  vnl_BIG_ENDIAN = 1000,
38  //
39  vnl_none = 0
40  };
41 };
42 
43 namespace byteswap // byteswap routines, stolen from ITK
44 {
45  inline void
46  swap32(void *ptr)
47  {
48  char one_byte;
49  char *p = reinterpret_cast<char *>(ptr);
50  one_byte = p[0]; p[0] = p[3]; p[3] = one_byte;
51  one_byte = p[1]; p[1] = p[2]; p[2] = one_byte;
52  }
53  inline void
54  swap64(void *ptr)
55  {
56  char one_byte;
57  char *p = reinterpret_cast<char *>(ptr);
58  one_byte = p[0]; p[0] = p[7]; p[7] = one_byte;
59  one_byte = p[1]; p[1] = p[6]; p[6] = one_byte;
60  one_byte = p[2]; p[2] = p[5]; p[5] = one_byte;
61  one_byte = p[3]; p[3] = p[4]; p[4] = one_byte;
62  }
63 }
64 
65 #endif // vnl_matlab_header_h_
void swap64(void *ptr)
void swap32(void *ptr)