API
pixaccess.hpp
Go to the documentation of this file.
1 
2 
3 ///\todo document this file
4 
5 #ifndef pixaccess_h
6 #define pixaccess_h
7 
8 #include "ImageStruct.hpp"
9 
10 ///Function to cast the data type to float.
11 /** Accesses the imdata pointer at linear position idx, and then casts the result to float.
12  *
13  * \returns the value of the image at linear position idx cast to float
14  *
15  * \tparam dataT the type of the image data.
16  */
17 template<typename returnT, typename dataT>
18 returnT getPix( void *imdata, ///< [in] Pointer to the image data
19  size_t idx ///< [in] Linear position of the pixel in the imdata
20  )
21 {
22  return (returnT) ((dataT*) imdata)[idx];
23 }
24 
25 ///Get the function pointer for getPix for the type
26 template<typename returnT, int imageStructDataT>
27 returnT (*getPixPointer())(void*, size_t)
28 {
29  return &getPix<returnT, typename imageStructDataType<imageStructDataT>::type>;
30 }
31 
32 template<typename returnT>
33 returnT (*getPixPointer(int imageStructDataT))(void*, size_t)
34 {
35  switch(imageStructDataT)
36  {
37  case IMAGESTRUCT_UINT8:
38  return getPixPointer<returnT, IMAGESTRUCT_UINT8>();
39  case IMAGESTRUCT_INT8:
40  return getPixPointer<returnT, IMAGESTRUCT_INT8>();
41  case IMAGESTRUCT_UINT16:
42  return getPixPointer<returnT, IMAGESTRUCT_UINT16>();
43  break;
44  case IMAGESTRUCT_INT16:
45  return getPixPointer<returnT, IMAGESTRUCT_INT16>();
46  case IMAGESTRUCT_UINT32:
47  return getPixPointer<returnT, IMAGESTRUCT_UINT32>();
48  case IMAGESTRUCT_INT32:
49  return getPixPointer<returnT, IMAGESTRUCT_INT32>();
50  case IMAGESTRUCT_UINT64:
51  return getPixPointer<returnT, IMAGESTRUCT_UINT64>();
52  case IMAGESTRUCT_INT64:
53  return getPixPointer<returnT, IMAGESTRUCT_INT64>();
54  case IMAGESTRUCT_FLOAT:
55  return getPixPointer<returnT, IMAGESTRUCT_FLOAT>();
56  case IMAGESTRUCT_DOUBLE:
57  return getPixPointer<returnT, IMAGESTRUCT_DOUBLE>();
58  default:
59  std::cerr << "getPixPointer: Unknown or unsupported data type. " << __FILE__ << " " << __LINE__ << "\n";
60  return nullptr;
61  }
62 }
63 #endif
64 
65 
66 
#define IMAGESTRUCT_UINT16
Definition: ImageStruct.hpp:16
#define IMAGESTRUCT_INT64
Definition: ImageStruct.hpp:21
#define IMAGESTRUCT_FLOAT
Definition: ImageStruct.hpp:22
#define IMAGESTRUCT_INT32
Definition: ImageStruct.hpp:19
#define IMAGESTRUCT_UINT32
Definition: ImageStruct.hpp:18
#define IMAGESTRUCT_INT8
Definition: ImageStruct.hpp:15
#define IMAGESTRUCT_DOUBLE
Definition: ImageStruct.hpp:23
#define IMAGESTRUCT_UINT8
Definition: ImageStruct.hpp:14
#define IMAGESTRUCT_INT16
Definition: ImageStruct.hpp:17
#define IMAGESTRUCT_UINT64
Definition: ImageStruct.hpp:20
std::ostream & cerr()
returnT getPix(void *imdata, size_t idx)
Function to cast the data type to float.
Definition: pixaccess.hpp:18
returnT(*)(void *, size_t) getPixPointer()
Get the function pointer for getPix for the type.
Definition: pixaccess.hpp:27