Line data Source code
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 : */
18 : template<typename returnT, typename dataT>
19 0 : returnT 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 0 : return (returnT) ((dataT*) imdata)[idx];
24 : }
25 :
26 : ///Get the function pointer for getPix for the type
27 : template<typename returnT, int imageStructDataT>
28 0 : returnT (*getPixPointer())(void*, size_t)
29 : {
30 0 : return &getPix<returnT, typename imageStructDataType<imageStructDataT>::type>;
31 : }
32 :
33 : template<typename returnT>
34 0 : returnT (*getPixPointer(int imageStructDataT))(void*, size_t)
35 : {
36 0 : switch(imageStructDataT)
37 : {
38 0 : case IMAGESTRUCT_UINT8:
39 0 : return getPixPointer<returnT, IMAGESTRUCT_UINT8>();
40 0 : case IMAGESTRUCT_INT8:
41 0 : return getPixPointer<returnT, IMAGESTRUCT_INT8>();
42 0 : case IMAGESTRUCT_UINT16:
43 0 : return getPixPointer<returnT, IMAGESTRUCT_UINT16>();
44 : break;
45 0 : case IMAGESTRUCT_INT16:
46 0 : return getPixPointer<returnT, IMAGESTRUCT_INT16>();
47 0 : case IMAGESTRUCT_UINT32:
48 0 : return getPixPointer<returnT, IMAGESTRUCT_UINT32>();
49 0 : case IMAGESTRUCT_INT32:
50 0 : return getPixPointer<returnT, IMAGESTRUCT_INT32>();
51 0 : case IMAGESTRUCT_UINT64:
52 0 : return getPixPointer<returnT, IMAGESTRUCT_UINT64>();
53 0 : case IMAGESTRUCT_INT64:
54 0 : return getPixPointer<returnT, IMAGESTRUCT_INT64>();
55 0 : case IMAGESTRUCT_FLOAT:
56 0 : return getPixPointer<returnT, IMAGESTRUCT_FLOAT>();
57 0 : case IMAGESTRUCT_DOUBLE:
58 0 : return getPixPointer<returnT, IMAGESTRUCT_DOUBLE>();
59 0 : default:
60 0 : std::cerr << "getPixPointer: Unknown or unsupported data type. " << __FILE__ << " " << __LINE__ << "\n";
61 0 : return nullptr;
62 : }
63 : }
64 : #endif
65 :
66 :
67 :
|