API
 
Loading...
Searching...
No Matches
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#include <iostream>
10
11///Function to cast the data type to float.
12/** Accesses the imdata pointer at linear position idx, and then casts the result to float.
13 *
14 * \returns the value of the image at linear position idx cast to float
15 *
16 * \tparam dataT the type of the image data.
17 */
18template<typename returnT, typename dataT>
19returnT getPix( void *imdata, ///< [in] Pointer to the image data
20 size_t idx ///< [in] Linear position of the pixel in the imdata
21 )
22{
23 return (returnT) ((dataT*) imdata)[idx];
24}
25
26///Get the function pointer for getPix for the type
27template<typename returnT, int imageStructDataT>
28returnT (*getPixPointer())(void*, size_t)
29{
30 return &getPix<returnT, typename imageStructDataType<imageStructDataT>::type>;
31}
32
33template<typename returnT>
34returnT (*getPixPointer(int imageStructDataT))(void*, size_t)
35{
36 switch(imageStructDataT)
37 {
39 return getPixPointer<returnT, IMAGESTRUCT_UINT8>();
41 return getPixPointer<returnT, IMAGESTRUCT_INT8>();
43 return getPixPointer<returnT, IMAGESTRUCT_UINT16>();
44 break;
46 return getPixPointer<returnT, IMAGESTRUCT_INT16>();
48 return getPixPointer<returnT, IMAGESTRUCT_UINT32>();
50 return getPixPointer<returnT, IMAGESTRUCT_INT32>();
52 return getPixPointer<returnT, IMAGESTRUCT_UINT64>();
54 return getPixPointer<returnT, IMAGESTRUCT_INT64>();
56 return getPixPointer<returnT, IMAGESTRUCT_FLOAT>();
58 return getPixPointer<returnT, IMAGESTRUCT_DOUBLE>();
59 default:
60 std::cerr << "getPixPointer: Unknown or unsupported data type. " << __FILE__ << " " << __LINE__ << "\n";
61 return nullptr;
62 }
63}
64#endif
65
66
67
#define IMAGESTRUCT_UINT16
#define IMAGESTRUCT_INT64
#define IMAGESTRUCT_FLOAT
#define IMAGESTRUCT_INT32
#define IMAGESTRUCT_UINT32
#define IMAGESTRUCT_INT8
#define IMAGESTRUCT_DOUBLE
#define IMAGESTRUCT_UINT8
#define IMAGESTRUCT_INT16
#define IMAGESTRUCT_UINT64
returnT getPix(void *imdata, size_t idx)
Function to cast the data type to float.
Definition pixaccess.hpp:19
returnT(*)(void *, size_t) getPixPointer()
Get the function pointer for getPix for the type.
Definition pixaccess.hpp:28