SapBuffer.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. #ifndef _SAPBUFFER_H_
  2. #define _SAPBUFFER_H_
  3. // SapBuffer.h : header file
  4. //
  5. #include "SapClassBasicDef.h"
  6. // Forward declarations
  7. #if !defined(POSIX_HOSTPC)
  8. class SAPCLASSBASIC_CLASS SapDisplay;
  9. #endif
  10. //
  11. // SapBuffer class declaration
  12. //
  13. class SAPCLASSBASIC_CLASS SapBuffer : public SapXferNode
  14. {
  15. public:
  16. // Buffer types
  17. typedef int Type; // For compatibility with old Sapera++ application code
  18. enum _Type
  19. {
  20. TypeDefault = -1,
  21. TypeVirtual = CORBUFFER_VAL_TYPE_VIRTUAL,
  22. TypeContiguous = CORBUFFER_VAL_TYPE_CONTIGUOUS,
  23. TypeScatterGather = CORBUFFER_VAL_TYPE_SCATTER_GATHER,
  24. TypeOffscreen = CORBUFFER_VAL_TYPE_OFFSCREEN,
  25. TypeOffscreenVideo = CORBUFFER_VAL_TYPE_OFFSCREEN | CORBUFFER_VAL_TYPE_VIDEO,
  26. TypeOverlay = CORBUFFER_VAL_TYPE_OVERLAY | CORBUFFER_VAL_TYPE_VIDEO,
  27. TypeDummy = CORBUFFER_VAL_TYPE_DUMMY,
  28. TypePhysical = CORBUFFER_VAL_TYPE_PHYSICAL,
  29. TypeScatterGatherPhysical= CORBUFFER_VAL_TYPE_SCATTER_GATHER | CORBUFFER_VAL_TYPE_PHYSICAL,
  30. TypeUnmapped = CORBUFFER_VAL_TYPE_UNMAPPED,
  31. TypeScatterGatherUnmapped= CORBUFFER_VAL_TYPE_SCATTER_GATHER | CORBUFFER_VAL_TYPE_UNMAPPED
  32. };
  33. // Buffer states
  34. typedef int State;
  35. enum _State
  36. {
  37. StateEmpty = CORBUFFER_VAL_STATE_EMPTY,
  38. StateOverflow = CORBUFFER_VAL_STATE_OVERFLOW,
  39. StateFull = CORBUFFER_VAL_STATE_FULL
  40. };
  41. // Color Conversion filter options
  42. typedef int ColorAlign;
  43. enum _ColorAlign
  44. {
  45. ColorAlignGBRG = CORBUFFER_VAL_COLOR_ALIGN_GB_RG,
  46. ColorAlignBGGR = CORBUFFER_VAL_COLOR_ALIGN_BG_GR,
  47. ColorAlignRGGB = CORBUFFER_VAL_COLOR_ALIGN_RG_GB,
  48. ColorAlignGRBG = CORBUFFER_VAL_COLOR_ALIGN_GR_BG,
  49. ColorAlignRGBG = CORBUFFER_VAL_COLOR_ALIGN_RG_BG,
  50. ColorAlignBGRG = CORBUFFER_VAL_COLOR_ALIGN_BG_RG
  51. };
  52. typedef int ColorMethod;
  53. enum _ColorMethod
  54. {
  55. ColorMethod1 = CORBUFFER_VAL_COLOR_METHOD_1,
  56. ColorMethod2 = CORBUFFER_VAL_COLOR_METHOD_2,
  57. ColorMethod3 = CORBUFFER_VAL_COLOR_METHOD_3,
  58. ColorMethod4 = CORBUFFER_VAL_COLOR_METHOD_4,
  59. ColorMethod5 = CORBUFFER_VAL_COLOR_METHOD_5,
  60. ColorMethod6 = CORBUFFER_VAL_COLOR_METHOD_6,
  61. ColorMethod7 = CORBUFFER_VAL_COLOR_METHOD_7
  62. };
  63. // Bayer filter options (obsolete)
  64. typedef int BayerAlign;
  65. enum _BayerAlign
  66. {
  67. BayerAlignGBRG = CORBUFFER_VAL_BAYER_ALIGN_GB_RG,
  68. BayerAlignBGGR = CORBUFFER_VAL_BAYER_ALIGN_BG_GR,
  69. BayerAlignRGGB = CORBUFFER_VAL_BAYER_ALIGN_RG_GB,
  70. BayerAlignGRBG = CORBUFFER_VAL_BAYER_ALIGN_GR_BG
  71. };
  72. typedef int BayerMethod;
  73. enum _BayerMethod
  74. {
  75. BayerMethod1 = CORBUFFER_VAL_BAYER_METHOD_1,
  76. BayerMethod2 = CORBUFFER_VAL_BAYER_METHOD_2,
  77. BayerMethod3 = CORBUFFER_VAL_BAYER_METHOD_3,
  78. BayerMethod4 = CORBUFFER_VAL_BAYER_METHOD_4,
  79. BayerMethod5 = CORBUFFER_VAL_BAYER_METHOD_5,
  80. BayerMethod6 = CORBUFFER_VAL_BAYER_METHOD_6,
  81. BayerMethodInterpolate = CORBUFFER_VAL_BAYER_METHOD_1,
  82. BayerMethodGoldenEagle = CORBUFFER_VAL_BAYER_METHOD_2,
  83. BayerMethodEagle = CORBUFFER_VAL_BAYER_METHOD_3
  84. };
  85. typedef int FileFormat;
  86. enum _FileFormat
  87. {
  88. FileFormatBMP = CORFILE_VAL_FORMAT_BMP,
  89. FileFormatTIFF = CORFILE_VAL_FORMAT_TIFF,
  90. FileFormatCRC = CORFILE_VAL_FORMAT_CRC,
  91. FileFormatRAW = CORFILE_VAL_FORMAT_RAW,
  92. FileFormatJPEG = CORFILE_VAL_FORMAT_JPEG,
  93. FileFormatJPEG2000 = CORFILE_VAL_FORMAT_JPEG_2000,
  94. FileFormatColorCorrection = CORFILE_FORMAT_COLOR_CORRECTION,
  95. FileFormatAVI = CORFILE_VAL_FORMAT_AVI
  96. };
  97. typedef struct
  98. {
  99. void* virtualAddress;
  100. void* virtualBaseAddress;
  101. UINT64 offset;
  102. size_t size;
  103. int refCount;
  104. } LOCK_INFO, *PLOCK_INFO;
  105. public:
  106. // Constructor/Destructor
  107. SapBuffer(int count = SapDefBufferCount, int width = SapDefWidth, int height = SapDefHeight, SapFormat format = SapDefFormat, Type type = SapDefBufferType, SapLocation loc = SapLocation::ServerSystem);
  108. SapBuffer(int count, ULONG_PTR physAddress[], int width = SapDefWidth, int height = SapDefHeight, SapFormat format = SapDefFormat, Type type = TypeContiguous);
  109. SapBuffer(int count, void *virtAddress[], int width = SapDefWidth, int height = SapDefHeight, SapFormat format = SapDefFormat, Type type = TypeScatterGather);
  110. SapBuffer(int count, SapXferNode *pSrcNode, Type type = SapDefBufferType, SapLocation loc = SapLocation::ServerSystem);
  111. SapBuffer(const char *fileName, Type type = SapDefBufferType, SapLocation loc = SapLocation::ServerSystem);
  112. SapBuffer(int count, const char *bufName, int width = SapDefWidth, int height = SapDefHeight, SapFormat format = SapDefFormat, Type type = TypeScatterGather, SapLocation loc= SapLocation::ServerSystem);
  113. SapBuffer(int count, const char *bufName, SapXferNode *pSrcNode, Type type = SapDefBufferType, SapLocation loc= SapLocation::ServerSystem);
  114. SapBuffer(const char *bufName, int startIndex, int count, Type type = TypeVirtual, SapLocation loc= SapLocation::ServerSystem);
  115. #if !defined(POSIX_HOSTPC)
  116. SapBuffer(int count, SapDisplay *pDisplay, int width = SapDefWidth, int height = SapDefHeight, SapFormat format = SapDefFormat, Type type = SapDefBufferType);
  117. SapBuffer(int count, SapDisplay *pDisplay, SapXferNode *pSrcNode, Type type = SapDefBufferType);
  118. #endif
  119. SapBuffer(const SapBuffer &buf);
  120. virtual ~SapBuffer();
  121. SapBuffer &operator= (const SapBuffer &buf);
  122. // Module create/destroy
  123. virtual BOOL Create();
  124. virtual BOOL Destroy();
  125. // SapXferNode type information
  126. XferNodeType GetXferNodeType() { return (m_pBufferMulti != NULL) ? NodeTypeBufferMulti : NodeTypeBuffer; }
  127. // Access to implementation
  128. int GetCount() const { return m_Count; }
  129. int GetWidth() const { return m_XferParams[0].GetWidth(); }
  130. int GetHeight() const { return m_XferParams[0].GetHeight(); }
  131. SapFormat GetFormat() const { return m_XferParams[0].GetFormat(); }
  132. Type GetType() const { return m_Type; }
  133. int GetPixelDepth() const { return m_PixelDepth; }
  134. int GetPixelDepthCap() const;
  135. int GetBytesPerPixel() const;
  136. int GetPitch() const;
  137. void GetParameters(int *count, int *width, int *height, SapFormat *format, Type *type) const;
  138. const char* GetBufName() const { return m_BufName;}
  139. virtual BOOL SetCount(int count);
  140. virtual BOOL SetWidth(int width);
  141. virtual BOOL SetHeight(int height);
  142. virtual BOOL SetFormat(SapFormat format);
  143. virtual BOOL SetType(Type type);
  144. virtual BOOL SetPixelDepth(int pixelDepth);
  145. virtual BOOL SetVirtualAddress( void* virtAddress[]);
  146. virtual BOOL SetPhysicalAddress(ULONG_PTR physAddress[]);
  147. virtual BOOL SetParameters(int count, int width, int height, SapFormat format, Type type);
  148. virtual BOOL SetParameters(int count, void* virtAddress[], int width, int height, SapFormat format, Type type);
  149. virtual BOOL SetParameters(int count, ULONG_PTR physAddress[], int width, int height, SapFormat format, Type type);
  150. virtual BOOL SetParametersFromFile(const char *fileName, Type type);
  151. float GetFrameRate() const { return m_FrameRate; }
  152. virtual void SetFrameRate(float frameRate) { m_FrameRate = frameRate; }
  153. virtual BOOL GetAddress( void **pData);
  154. virtual BOOL GetAddress( void* virtualBaseAddress, void **pData);
  155. virtual BOOL GetAddress(int index, void **pData);
  156. virtual BOOL GetAddress(int index, void* virtualBaseAddress, void **pData);
  157. virtual BOOL GetAddress(UINT64 offset, size_t size, void **pData);
  158. virtual BOOL GetAddress(UINT64 offset, size_t size, void* virtualBaseAddress, void **pData);
  159. virtual BOOL GetAddress(int index, UINT64 offset, size_t size, void **pData);
  160. virtual BOOL GetAddress(int index, UINT64 offset, size_t size, void* virtualBaseAddress, void **pData);
  161. virtual BOOL ReleaseAddress(void *pData);
  162. virtual BOOL ReleaseAddress(int index, void *pData= NULL);
  163. virtual BOOL IsMapped( int index);
  164. virtual BOOL IsMapped();
  165. virtual BOOL GetCounterStamp(int *pCounterStamp);
  166. virtual BOOL GetCounterStamp(int index, int *pCounterStamp);
  167. virtual BOOL GetHostCounterStamp(UINT64 *pCounterStamp);
  168. virtual BOOL GetHostCounterStamp(int index, UINT64 *pCounterStamp);
  169. virtual BOOL GetDeviceTimeStamp(UINT64 *pTimeStamp);
  170. virtual BOOL GetDeviceTimeStamp(int index, UINT64 *pTimeStamp);
  171. virtual BOOL GetSpaceUsed(int *pSpaceUsed);
  172. virtual BOOL GetSpaceUsed(int index, int *pSpaceUsed);
  173. virtual CORHANDLE *GetHandles() const { return m_bInitOK ? m_pBuffers : NULL; }
  174. virtual CORHANDLE GetHandle(int index) const;
  175. virtual CORHANDLE GetHandle() const { return GetHandle(m_Index); }
  176. virtual CORHANDLE operator[] (int index) const { return GetHandle(index); }
  177. virtual int GetIndex() const { return m_Index; }
  178. virtual BOOL SetIndex(int index);
  179. virtual void ResetIndex() { m_Index = m_Count - 1; }
  180. virtual void Next() { m_Index = (m_Index + 1 == m_Count) ? 0 : m_Index + 1; }
  181. virtual BOOL IsCapabilityValid(int cap);
  182. virtual BOOL GetCapability(int cap, void *pValue);
  183. virtual BOOL GetCapability(int index, int cap, void *pValue);
  184. virtual BOOL IsParameterValid(int param);
  185. virtual BOOL IsParameterValid(int index, int param);
  186. virtual BOOL GetParameter(int param, void *pValue);
  187. virtual BOOL GetParameter(int index, int param, void *pValue);
  188. virtual BOOL SetParameter(int param, int value);
  189. virtual BOOL SetParameter(int index, int param, int value);
  190. virtual BOOL SetParameter(int param, void *pValue);
  191. virtual BOOL SetParameter(int index, int param, void *pValue);
  192. // Access to derived class implementation
  193. virtual CORBUFFER GetTrash() const { return CORHANDLE_NULL; }
  194. virtual SapBuffer *GetParent() { return this; }
  195. virtual SapBuffer *GetRoot() { return this; }
  196. // State manipulation
  197. virtual BOOL SetState(State state);
  198. virtual BOOL SetState(int index, State state);
  199. virtual BOOL SetAllState(State state);
  200. virtual BOOL GetState(State *pState);
  201. virtual BOOL GetState(int index, State *pState);
  202. // Page number management, relevant for planar and multi-format buffers only
  203. virtual BOOL GetNumPages(int *pNumPages);
  204. virtual BOOL SetPage(int page);
  205. virtual BOOL SetPage(int index, int page);
  206. virtual BOOL SetAllPage(int page);
  207. virtual BOOL GetPage(int *pPage);
  208. virtual BOOL GetPage(int index, int *pPage);
  209. // Management of multi-format buffers
  210. virtual BOOL IsMultiFormat();
  211. virtual BOOL GetPageFormat(SapFormat *pageFormat);
  212. // Buffer manipulation
  213. virtual BOOL Clear();
  214. virtual BOOL Clear(int index);
  215. virtual BOOL Clear(SapData value);
  216. virtual BOOL Clear(int index, SapData value);
  217. virtual BOOL Load(const char *fileName, int bufIndex, int numBuffers = 0, int frameIndex = 0, const char *options = "-format auto");
  218. virtual BOOL Save(const char *fileName, const char *options, int bufIndex = -1, int numBuffers = 0);
  219. virtual BOOL Read(UINT64 offset, int numElements, void *pData);
  220. virtual BOOL Read(int index, UINT64 offset, int numElements, void *pData);
  221. virtual BOOL ReadElement(int x, int y, void *pData);
  222. virtual BOOL ReadElement(int index, int x, int y, void *pData);
  223. virtual BOOL ReadElement(int x, int y, SapData *pData);
  224. virtual BOOL ReadElement(int index, int x, int y, SapData *pData);
  225. virtual BOOL ReadLine(int x1, int y1, int x2, int y2, void *pData, int *numRead);
  226. virtual BOOL ReadLine(int index, int x1, int y1, int x2, int y2, void *pData, int *numRead);
  227. virtual BOOL ReadRect(int x, int y, int width, int height, void *pData);
  228. virtual BOOL ReadRect(int index, int x, int y, int width, int height, void *pData);
  229. virtual BOOL Write(UINT64 offset, int numElements, const void *pData);
  230. virtual BOOL Write(int index, UINT64 offset, int numElements, const void *pData);
  231. virtual BOOL WriteElement(int x, int y, const void *pData);
  232. virtual BOOL WriteElement(int index, int x, int y, const void *pData);
  233. virtual BOOL WriteElement(int x, int y, SapData data);
  234. virtual BOOL WriteElement(int index, int x, int y, SapData data);
  235. virtual BOOL WriteLine(int x1, int y1, int x2, int y2, const void *pData, int *numWritten);
  236. virtual BOOL WriteLine(int index, int x1, int y1, int x2, int y2, const void *pData, int *numWritten);
  237. virtual BOOL WriteRect(int x, int y, int width, int height, const void *pData);
  238. virtual BOOL WriteRect(int index, int x, int y, int width, int height, const void *pData);
  239. virtual BOOL Copy(SapBuffer *pSrc);
  240. virtual BOOL Copy(SapBuffer *pSrc, int srcIndex, int dstIndex);
  241. virtual BOOL CopyAll(SapBuffer *pSrc);
  242. virtual BOOL CopyRect(SapBuffer *pSrc, int srcIndex, int xSrc, int ySrc, int width, int height, int dstIndex, int xDest, int yDest);
  243. virtual BOOL ColorConvert(SapBuffer *pSrc, ColorAlign align, ColorMethod method, SapDataFRGB wbCoef, SapLut *pLut = NULL);
  244. virtual BOOL ColorConvert(SapBuffer *pSrc, int srcIndex, int dstIndex, ColorAlign align, ColorMethod method, SapDataFRGB wbCoef, SapLut *pLut = NULL);
  245. virtual BOOL ColorWhiteBalance(ColorAlign align, SapDataFRGB *pWbCoef);
  246. virtual BOOL ColorWhiteBalance(int index, ColorAlign align, SapDataFRGB *pWbCoef);
  247. virtual BOOL SplitComponents(SapBuffer *pSrc);
  248. virtual BOOL SplitComponents(SapBuffer *pSrc, int srcIndex);
  249. virtual BOOL SplitComponents(SapBuffer *pFirstDst, SapBuffer *pSecondDst, SapBuffer *pThirdDst);
  250. virtual BOOL SplitComponents(SapBuffer *pFirstDst, SapBuffer *pSecondDst, SapBuffer *pThirdDst, int srcIndex);
  251. virtual BOOL SplitComponents(SapBuffer *pDst[], int dstCount);
  252. virtual BOOL SplitComponents(SapBuffer *pDst[], int dstCount, int srcIndex);
  253. virtual BOOL MergeComponents(SapBuffer *pSrc);
  254. virtual BOOL MergeComponents(SapBuffer *pSrc, int dstIndex);
  255. virtual BOOL MergeComponents(SapBuffer *pFirstSrc, SapBuffer *pSecondSrc, SapBuffer *pThirdSrc);
  256. virtual BOOL MergeComponents(SapBuffer *pFirstSrc, SapBuffer *pSecondSrc, SapBuffer *pThirdSrc, int dstIndex);
  257. virtual BOOL MergeComponents(SapBuffer *pSrc[], int srcCount);
  258. virtual BOOL MergeComponents(SapBuffer *pSrc[], int srcCount, int dstIndex);
  259. // Remote access
  260. virtual BOOL Register(const char *name);
  261. virtual BOOL Unregister();
  262. // Available buffer type inquiry
  263. static BOOL IsBufferTypeSupported(int serverIndex, Type bufType);
  264. static BOOL IsBufferTypeSupported(const char *serverName, Type bufType);
  265. static BOOL IsBufferTypeSupported(SapLocation loc, Type bufType);
  266. // Obsolete state manipulation methods
  267. virtual BOOL Empty() { return SetState(m_Index, StateEmpty); }
  268. virtual BOOL Empty(int index) { return SetState(index, StateEmpty); }
  269. virtual BOOL EmptyAll() { return SetAllState(StateEmpty); }
  270. // Obsolete methods, use class SapBufferRoi instead
  271. virtual int GetNumRoi() const { return 0; }
  272. virtual const LPRECT GetRoi(int index) const { return NULL; }
  273. virtual BOOL AddRoi(RECT roi) { return FALSE; }
  274. virtual BOOL RemoveAllRoi() { return FALSE; }
  275. virtual CORBUFFER GetChild(int roiIndex, int bufIndex) const { return CORHANDLE_NULL; }
  276. // Obsolete prototypes for these methods
  277. virtual BOOL Load(const char *fileName, const char *options = "-format auto", int index = -1, int numFrames = 0);
  278. virtual BOOL ReadElement(int x, int y, int *red, int *green, int *blue);
  279. // Obsolete methods, use color conversion instead
  280. virtual BOOL BayerConvert(SapBuffer *pSrc, BayerAlign align, BayerMethod method, SapDataFRGB wbCoef, SapLut *pLut = NULL);
  281. virtual BOOL BayerConvert(SapBuffer *pSrc, int srcIndex, int dstIndex, BayerAlign align, BayerMethod method, SapDataFRGB wbCoef, SapLut *pLut = NULL);
  282. virtual BOOL BayerWhiteBalance(BayerAlign align, SapDataFRGB *pWbCoef);
  283. virtual BOOL BayerWhiteBalance(int index, BayerAlign align, SapDataFRGB *pWbCoef);
  284. protected:
  285. // Utility methods
  286. #if defined(POSIX_HOSTPC)
  287. virtual void Construct(const char *bufName, void *pDisplay);
  288. #else
  289. virtual void Construct(const char *bufName, SapDisplay *pDisplay);
  290. #endif
  291. void UpdatePixelDepth(int index);
  292. static FileFormat GetFileFormatFromOptions(const char *options);
  293. protected:
  294. // Buffer-related variables
  295. int m_Count; // Number of buffers
  296. Type m_Type; // Buffer type
  297. int m_Index; // Index of last grabbed buffer
  298. BOOL m_PixelDepthCap; // Pixel depth capability
  299. int m_PixelDepth; // Number of actual data bits per pixel
  300. int m_DataSize; // Number of bytes per pixel
  301. int m_Pitch; // Byte offset between start addresses of consecutive lines
  302. int m_NumPages; // Number of pages, relevant for planar and multi-format buffers only
  303. BOOL m_IsMultiFormat; // Indicates multi-format buffers
  304. SapFormat *m_PageFormat; // Individual page formats for multi-format buffers
  305. ULONG_PTR *m_PhysAddress; // Physical addresses for creating buffers
  306. void **m_VirtAddress; // Virtual addresses for creating buffers
  307. PLOCK_INFO m_LockInfo; // Information for locked buffers ( video, physical)
  308. CRITICAL_SECTION m_criticalSection;
  309. // Shared buffer related variables
  310. char m_BufName[CORHANDLE_MAX_STRLEN]; // Name of the shared buffer objects
  311. CORBUFFER* m_pRemoteBuffers;
  312. CORBUFFER m_BufferSharedInfo; // Buffer handle to shared buffer information
  313. int m_StartIndex;
  314. // File-related variables
  315. float m_FrameRate; // Number of frames per second
  316. // Display object when buffer creation is done from a display handle
  317. #if defined(POSIX_HOSTPC)
  318. void *m_pDisplay; // No video/display based buffers.
  319. #else
  320. SapDisplay *m_pDisplay;
  321. #endif
  322. // Sapera handles
  323. CORBUFFER *m_pBuffers; // Table of buffer handles
  324. CORBUFFERMULTI m_pBufferMulti;
  325. };
  326. #endif // _SAPBUFFER_H_