00001
00012 #ifndef ND_ARRAY_H
00013 #define ND_ARRAY_H
00014
00015 #include <ellLib.h>
00016 #include <epicsMutex.h>
00017 #include <epicsTypes.h>
00018
00020 #define ND_ARRAY_MAX_DIMS 10
00021
00022 #define ND_SUCCESS 0
00023
00024 #define ND_ERROR -1
00025
00026 #define MAX_ATTRIBUTE_STRING_SIZE 256
00027
00029 typedef enum
00030 {
00031 NDInt8,
00032 NDUInt8,
00033 NDInt16,
00034 NDUInt16,
00035 NDInt32,
00036 NDUInt32,
00037 NDFloat32,
00038 NDFloat64
00039 } NDDataType_t;
00040
00042 typedef enum
00043 {
00044 NDAttrInt8 = NDInt8,
00045 NDAttrUInt8 = NDUInt8,
00046 NDAttrInt16 = NDInt16,
00047 NDAttrUInt16 = NDUInt16,
00048 NDAttrInt32 = NDInt32,
00049 NDAttrUInt32 = NDUInt32,
00050 NDAttrFloat32 = NDFloat32,
00051 NDAttrFloat64 = NDFloat64,
00052 NDAttrString,
00053 NDAttrUndefined
00054 } NDAttrDataType_t;
00055
00057 typedef enum
00058 {
00059 NDAttrSourceDriver,
00060 NDAttrSourceParam,
00061 NDAttrSourceEPICSPV
00062 } NDAttrSource_t;
00063
00065 typedef enum
00066 {
00067 NDColorModeMono,
00068 NDColorModeBayer,
00069 NDColorModeRGB1,
00070 NDColorModeRGB2,
00071 NDColorModeRGB3,
00072 NDColorModeYUV444,
00073 NDColorModeYUV422,
00074 NDColorModeYUV411
00075 } NDColorMode_t;
00076
00081 typedef enum
00082 {
00083 NDBayerRGGB = 0,
00084 NDBayerGBRG = 1,
00085 NDBayerGRBG = 2,
00086 NDBayerBGGR = 3
00087 } NDBayerPattern_t;
00088
00090 typedef struct NDDimension {
00091 int size;
00092 int offset;
00097 int binning;
00101 int reverse;
00105 } NDDimension_t;
00106
00108 typedef struct NDArrayInfo {
00109 int nElements;
00110 int bytesPerElement;
00111 int totalBytes;
00113 } NDArrayInfo_t;
00114
00118 typedef struct NDAttributeListNode {
00119 ELLNODE node;
00120 class NDAttribute *pNDAttribute;
00121 } NDAttributeListNode;
00122
00124 typedef union {
00125 epicsInt8 i8;
00126 epicsUInt8 ui8;
00127 epicsInt16 i16;
00128 epicsUInt16 ui16;
00129 epicsInt32 i32;
00130 epicsUInt32 ui32;
00131 epicsFloat32 f32;
00132 epicsFloat64 f64;
00133 } NDAttrValue;
00134
00138 class NDAttribute {
00139 public:
00140
00141 NDAttribute(const char *pName, const char *pDescription="",
00142 NDAttrDataType_t dataType=NDAttrUndefined, void *pValue=NULL);
00143 virtual ~NDAttribute();
00144 virtual NDAttribute* copy(NDAttribute *pAttribute);
00145 virtual int setDescription(const char *pDescription);
00146 virtual int setSource(const char *pSource);
00147 virtual int getValueInfo(NDAttrDataType_t *pDataType, size_t *pDataSize);
00148 virtual int getValue(NDAttrDataType_t dataType, void *pValue, size_t dataSize=0);
00149 virtual int setValue(NDAttrDataType_t dataType, void *pValue);
00150 virtual int updateValue();
00151 virtual int report(int details);
00152 char *pName;
00153 char *pDescription;
00154 char *pSource;
00155 NDAttrSource_t sourceType;
00156 NDAttrDataType_t dataType;
00157 friend class NDArray;
00158 friend class NDAttributeList;
00159
00160 protected:
00161 NDAttrValue value;
00162 char *pString;
00163 NDAttributeListNode listNode;
00164 };
00165
00168 class NDAttributeList {
00169 public:
00170 NDAttributeList();
00171 ~NDAttributeList();
00172 int add(NDAttribute *pAttribute);
00173 NDAttribute* add(const char *pName, const char *pDescription="",
00174 NDAttrDataType_t dataType=NDAttrUndefined, void *pValue=NULL);
00175 NDAttribute* find(const char *pName);
00176 NDAttribute* next(NDAttribute *pAttribute);
00177 int count();
00178 int remove(const char *pName);
00179 int clear();
00180 int copy(NDAttributeList *pOut);
00181 int updateValues();
00182 int report(int details);
00183
00184 private:
00185 ELLLIST list;
00186 epicsMutexId lock;
00187 };
00188
00192 class NDArray {
00193 public:
00194
00195 NDArray();
00196 ~NDArray();
00197 int initDimension (NDDimension_t *pDimension, int size);
00198 int getInfo (NDArrayInfo_t *pInfo);
00199 int reserve();
00200 int release();
00201 int report(int details);
00202 friend class NDArrayPool;
00203
00204 private:
00205 ELLNODE node;
00206 int referenceCount;
00207 void *owner;
00209 public:
00210 int uniqueId;
00211 double timeStamp;
00213 int ndims;
00214 NDDimension_t dims[ND_ARRAY_MAX_DIMS];
00215 NDDataType_t dataType;
00216 int dataSize;
00218 void *pData;
00221 NDAttributeList *pAttributeList;
00222 };
00223
00224
00225
00233 class NDArrayPool {
00234 public:
00235 NDArrayPool (int maxBuffers, size_t maxMemory);
00236 NDArray* alloc (int ndims, int *dims, NDDataType_t dataType, int dataSize, void *pData);
00237 NDArray* copy (NDArray *pIn, NDArray *pOut, int copyData);
00238
00239 int reserve (NDArray *pArray);
00240 int release (NDArray *pArray);
00241 int convert (NDArray *pIn,
00242 NDArray **ppOut,
00243 NDDataType_t dataTypeOut,
00244 NDDimension_t *outDims);
00245 int report (int details);
00246 private:
00247 ELLLIST freeList;
00248 epicsMutexId listLock;
00249 int maxBuffers;
00250 int numBuffers;
00251 size_t maxMemory;
00252 size_t memorySize;
00253 int numFree;
00254 };
00255
00256
00257 #endif