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;
00114 NDColorMode_t colorMode;
00115 int xDim;
00116 int yDim;
00117 int colorDim;
00118 int xSize;
00119 int ySize;
00120 int colorSize;
00121 int xStride;
00122 int yStride;
00123 int colorStride;
00124 } NDArrayInfo_t;
00125
00129 typedef struct NDAttributeListNode {
00130 ELLNODE node;
00131 class NDAttribute *pNDAttribute;
00132 } NDAttributeListNode;
00133
00135 typedef union {
00136 epicsInt8 i8;
00137 epicsUInt8 ui8;
00138 epicsInt16 i16;
00139 epicsUInt16 ui16;
00140 epicsInt32 i32;
00141 epicsUInt32 ui32;
00142 epicsFloat32 f32;
00143 epicsFloat64 f64;
00144 } NDAttrValue;
00145
00149 class epicsShareFunc NDAttribute {
00150 public:
00151
00152 NDAttribute(const char *pName, const char *pDescription="",
00153 NDAttrDataType_t dataType=NDAttrUndefined, void *pValue=NULL);
00154 virtual ~NDAttribute();
00155 virtual NDAttribute* copy(NDAttribute *pAttribute);
00156 virtual int setDescription(const char *pDescription);
00157 virtual int setSource(const char *pSource);
00158 virtual int getValueInfo(NDAttrDataType_t *pDataType, size_t *pDataSize);
00159 virtual int getValue(NDAttrDataType_t dataType, void *pValue, size_t dataSize=0);
00160 virtual int setValue(NDAttrDataType_t dataType, void *pValue);
00161 virtual int updateValue();
00162 virtual int report(int details);
00163 char *pName;
00164 char *pDescription;
00165 char *pSource;
00166 NDAttrSource_t sourceType;
00167 NDAttrDataType_t dataType;
00168 friend class NDArray;
00169 friend class NDAttributeList;
00170
00171 protected:
00172 NDAttrValue value;
00173 char *pString;
00174 NDAttributeListNode listNode;
00175 };
00176
00179 class epicsShareFunc NDAttributeList {
00180 public:
00181 NDAttributeList();
00182 ~NDAttributeList();
00183 int add(NDAttribute *pAttribute);
00184 NDAttribute* add(const char *pName, const char *pDescription="",
00185 NDAttrDataType_t dataType=NDAttrUndefined, void *pValue=NULL);
00186 NDAttribute* find(const char *pName);
00187 NDAttribute* next(NDAttribute *pAttribute);
00188 int count();
00189 int remove(const char *pName);
00190 int clear();
00191 int copy(NDAttributeList *pOut);
00192 int updateValues();
00193 int report(int details);
00194
00195 private:
00196 ELLLIST list;
00197 epicsMutexId lock;
00198 };
00199
00203 class epicsShareFunc NDArray {
00204 public:
00205
00206 NDArray();
00207 ~NDArray();
00208 int initDimension (NDDimension_t *pDimension, int size);
00209 int getInfo (NDArrayInfo_t *pInfo);
00210 int reserve();
00211 int release();
00212 int report(int details);
00213 friend class NDArrayPool;
00214
00215 private:
00216 ELLNODE node;
00217 int referenceCount;
00219 public:
00220 class NDArrayPool *pNDArrayPool;
00221 int uniqueId;
00222 double timeStamp;
00224 int ndims;
00225 NDDimension_t dims[ND_ARRAY_MAX_DIMS];
00226 NDDataType_t dataType;
00227 int dataSize;
00229 void *pData;
00232 NDAttributeList *pAttributeList;
00233 };
00234
00235
00236
00244 class epicsShareFunc NDArrayPool {
00245 public:
00246 NDArrayPool (int maxBuffers, size_t maxMemory);
00247 NDArray* alloc (int ndims, int *dims, NDDataType_t dataType, int dataSize, void *pData);
00248 NDArray* copy (NDArray *pIn, NDArray *pOut, int copyData);
00249
00250 int reserve (NDArray *pArray);
00251 int release (NDArray *pArray);
00252 int convert (NDArray *pIn,
00253 NDArray **ppOut,
00254 NDDataType_t dataTypeOut,
00255 NDDimension_t *outDims);
00256 int convert (NDArray *pIn,
00257 NDArray **ppOut,
00258 NDDataType_t dataTypeOut);
00259 int report (int details);
00260 int maxBuffers ();
00261 int numBuffers ();
00262 size_t maxMemory ();
00263 size_t memorySize ();
00264 int numFree ();
00265 private:
00266 ELLLIST freeList_;
00267 epicsMutexId listLock_;
00268 int maxBuffers_;
00269 int numBuffers_;
00270 size_t maxMemory_;
00271 size_t memorySize_;
00272 int numFree_;
00273 };
00274
00275
00276 #endif