SapData.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. #ifndef _SAPDATA_H_
  2. #define _SAPDATA_H_
  3. // SapData.h : header file
  4. //
  5. #include "SapClassBasicDef.h"
  6. //
  7. // Basic definitions available to all classes
  8. //
  9. // Sapera data formats
  10. typedef int SapFormat; // For compatibility with old Sapera++ application code
  11. enum _SapFormat
  12. {
  13. SapFormatUnknown = 0,
  14. // Monochrome data formats
  15. SapFormatMono8 = CORDATA_FORMAT_MONO8,
  16. SapFormatInt8 = CORDATA_FORMAT_INT8,
  17. SapFormatUint8 = CORDATA_FORMAT_UINT8,
  18. SapFormatMono16 = CORDATA_FORMAT_MONO16,
  19. SapFormatInt16 = CORDATA_FORMAT_INT16,
  20. SapFormatUint16 = CORDATA_FORMAT_UINT16,
  21. SapFormatMono24 = CORDATA_FORMAT_MONO24,
  22. SapFormatInt24 = CORDATA_FORMAT_INT24,
  23. SapFormatUint24 = CORDATA_FORMAT_UINT24,
  24. SapFormatMono32 = CORDATA_FORMAT_MONO32,
  25. SapFormatInt32 = CORDATA_FORMAT_INT32,
  26. SapFormatUint32 = CORDATA_FORMAT_UINT32,
  27. SapFormatMono64 = CORDATA_FORMAT_MONO64,
  28. SapFormatInt64 = CORDATA_FORMAT_INT64,
  29. SapFormatUint64 = CORDATA_FORMAT_UINT64,
  30. // Color RGB data formats
  31. SapFormatRGB5551 = CORDATA_FORMAT_RGB5551, // 16-bit
  32. SapFormatRGB565 = CORDATA_FORMAT_RGB565, // 16-bit
  33. SapFormatRGB888 = CORDATA_FORMAT_RGB888, // 24-bit
  34. SapFormatRGBR888 = CORDATA_FORMAT_RGBR888, // 24-bit
  35. SapFormatRGB8888 = CORDATA_FORMAT_RGB8888, // 32-bit
  36. SapFormatRGB101010 = CORDATA_FORMAT_RGB101010, // 32-bit
  37. SapFormatRGB161616 = CORDATA_FORMAT_RGB161616, // 48-bit
  38. SapFormatRGB16161616 = CORDATA_FORMAT_RGB16161616, // 64-bit
  39. // Bi-color data formats
  40. SapFormatBICOLOR88 = CORDATA_FORMAT_BICOLOR88,
  41. SapFormatBICOLOR1616 = CORDATA_FORMAT_BICOLOR1616,
  42. // Multispectral RGB-IR formats
  43. SapFormatRGB888_MONO8 = CORDATA_FORMAT_RGB888_MONO8,
  44. SapFormatRGB161616_MONO16 = CORDATA_FORMAT_RGB161616_MONO16,
  45. // Planar monochrome formats
  46. SapFormatMono8P2 = CORDATA_FORMAT_MONO8P2,
  47. SapFormatMono8P3 = CORDATA_FORMAT_MONO8P3,
  48. SapFormatMono16P2 = CORDATA_FORMAT_MONO16P2,
  49. SapFormatMono16P3 = CORDATA_FORMAT_MONO16P3,
  50. SapFormatMono8P4 = CORDATA_FORMAT_MONO8P4,
  51. SapFormatMono16P4 = CORDATA_FORMAT_MONO16P4,
  52. // Color HSV data formats
  53. SapFormatHSV = CORDATA_FORMAT_HSV,
  54. // Color YUV data formats
  55. SapFormatUYVY = CORDATA_FORMAT_UYVY,
  56. SapFormatYUY2 = CORDATA_FORMAT_YUY2,
  57. SapFormatYVYU = CORDATA_FORMAT_YVYU,
  58. SapFormatYUYV = CORDATA_FORMAT_YUYV,
  59. SapFormatY411 = CORDATA_FORMAT_Y411, // 4:1:1 also known as Y41P
  60. SapFormatY211 = CORDATA_FORMAT_Y211, // 2:1:1
  61. SapFormatYUV = CORDATA_FORMAT_YUV,
  62. SapFormatAYU2 = CORDATA_FORMAT_AYUV,
  63. SapFormatIYU1 = CORDATA_FORMAT_IYU1,
  64. SapFormatIYU2 = CORDATA_FORMAT_IYU2,
  65. // Other data formats
  66. SapFormatFloat = CORDATA_FORMAT_FLOAT,
  67. SapFormatComplex = CORDATA_FORMAT_COMPLEX, // Real and imaginary components
  68. SapFormatPoint = CORDATA_FORMAT_POINT, // X and Y integer components
  69. SapFormatFPoint = CORDATA_FORMAT_FPOINT, // Like Fpoint, but components are float instead of integer
  70. SapFormatMono1 = CORDATA_FORMAT_MONO1, // 1-bit monochrome
  71. SapFormatUint1 = CORDATA_FORMAT_UINT1,
  72. SapFormatBinary = CORDATA_FORMAT_BINARY,
  73. SapFormatHSI = CORDATA_FORMAT_HSI,
  74. SapFormatLAB = CORDATA_FORMAT_LAB,
  75. SapFormatLAB16161616 = CORDATA_FORMAT_LAB16161616,
  76. SapFormatLAB101010 = CORDATA_FORMAT_LAB101010,
  77. // Planar formats
  78. SapFormatRGBP8 = CORDATA_FORMAT_RGBP8, // 8-bit RGB
  79. SapFormatRGBP16 = CORDATA_FORMAT_RGBP16, // 16-bit RGB
  80. SapFormatYUVP8 = CORDATA_FORMAT_YUVP8, // 8-bit YUV
  81. SapFormatYUVP16 = CORDATA_FORMAT_YUVP16, // 16-bit YUV
  82. SapFormatHSVP8 = CORDATA_FORMAT_HSVP8, // 8-bit HSV
  83. SapFormatHSVP16 = CORDATA_FORMAT_HSVP16, // 16-bit HSV
  84. SapFormatHSIP8 = CORDATA_FORMAT_HSIP8, // 8-bit HSI
  85. SapFormatHSIP16 = CORDATA_FORMAT_HSIP16, // 16-bit HSI
  86. SapFormatLABP8 = CORDATA_FORMAT_LABP8, // 8-bit LAB
  87. SapFormatLABP16 = CORDATA_FORMAT_LABP16, // 16-bit LAB
  88. // Additional monochrome data formats used by look-up tables
  89. SapFormatMono9 = CORDATA_FORMAT_MONO9,
  90. SapFormatMono10 = CORDATA_FORMAT_MONO10,
  91. SapFormatMono11 = CORDATA_FORMAT_MONO11,
  92. SapFormatMono12 = CORDATA_FORMAT_MONO12,
  93. SapFormatMono13 = CORDATA_FORMAT_MONO13,
  94. SapFormatMono14 = CORDATA_FORMAT_MONO14,
  95. SapFormatMono15 = CORDATA_FORMAT_MONO15,
  96. SapFormatUint9 = CORDATA_FORMAT_UINT9,
  97. SapFormatUint10 = CORDATA_FORMAT_UINT10,
  98. SapFormatUint11 = CORDATA_FORMAT_UINT11,
  99. SapFormatUint12 = CORDATA_FORMAT_UINT12,
  100. SapFormatUint13 = CORDATA_FORMAT_UINT13,
  101. SapFormatUint14 = CORDATA_FORMAT_UINT14,
  102. SapFormatUint15 = CORDATA_FORMAT_UINT15,
  103. SapFormatInt9 = CORDATA_FORMAT_INT9,
  104. SapFormatInt10 = CORDATA_FORMAT_INT10,
  105. SapFormatInt11 = CORDATA_FORMAT_INT11,
  106. SapFormatInt12 = CORDATA_FORMAT_INT12,
  107. SapFormatInt13 = CORDATA_FORMAT_INT13,
  108. SapFormatInt14 = CORDATA_FORMAT_INT14,
  109. SapFormatInt15 = CORDATA_FORMAT_INT15,
  110. // Interlaced color data formats used by look-up tables, data stored as:
  111. // RGBRGBRGB ...
  112. SapFormatColorI8 = CORDATA_FORMAT_COLORI8,
  113. SapFormatColorI9 = CORDATA_FORMAT_COLORI9,
  114. SapFormatColorI10 = CORDATA_FORMAT_COLORI10,
  115. SapFormatColorI11 = CORDATA_FORMAT_COLORI11,
  116. SapFormatColorI12 = CORDATA_FORMAT_COLORI12,
  117. SapFormatColorI13 = CORDATA_FORMAT_COLORI13,
  118. SapFormatColorI14 = CORDATA_FORMAT_COLORI14,
  119. SapFormatColorI15 = CORDATA_FORMAT_COLORI15,
  120. SapFormatColorI16 = CORDATA_FORMAT_COLORI16,
  121. // Non-interlaced color data formats used by look-up tables, data stored as:
  122. // RRRRRR ... GGGGGG ... BBBBBB
  123. SapFormatColorNI8 = CORDATA_FORMAT_COLORNI8,
  124. SapFormatColorNI9 = CORDATA_FORMAT_COLORNI9,
  125. SapFormatColorNI10 = CORDATA_FORMAT_COLORNI10,
  126. SapFormatColorNI11 = CORDATA_FORMAT_COLORNI11,
  127. SapFormatColorNI12 = CORDATA_FORMAT_COLORNI12,
  128. SapFormatColorNI13 = CORDATA_FORMAT_COLORNI13,
  129. SapFormatColorNI14 = CORDATA_FORMAT_COLORNI14,
  130. SapFormatColorNI15 = CORDATA_FORMAT_COLORNI15,
  131. SapFormatColorNI16 = CORDATA_FORMAT_COLORNI16
  132. };
  133. // Format categories
  134. enum SapFormatType
  135. {
  136. SapFormatTypeUnknown,
  137. SapFormatTypeMono,
  138. SapFormatTypeRGB,
  139. SapFormatTypeYUV,
  140. SapFormatTypeHSI,
  141. SapFormatTypeHSV,
  142. SapFormatTypeFloat,
  143. SapFormatTypeComplex,
  144. SapFormatTypePoint,
  145. SapFormatTypeFPoint,
  146. SapFormatTypeFRGB,
  147. SapFormatTypeColor,
  148. SapFormatTypeRGBA,
  149. SapFormatTypeLAB,
  150. SapFormatTypeLABA,
  151. SapFormatTypeBiColor,
  152. };
  153. // Default values for parameters used in various classes
  154. const int SapDefWidth = 640;
  155. const int SapDefHeight = 480;
  156. const SapFormat SapDefFormat = SapFormatMono8;
  157. const int SapDefPixelDepth = 8;
  158. const int SapDefPixelShift = 0;
  159. const int SapDefBufferCount = 1;
  160. const int SapDefLutEntries = (1 << CORDATA_FORMAT_DATADEPTH(SapFormatUint8));
  161. #define SapDefBufferType SapBuffer::TypeDefault
  162. #define SapDefFrameType SapXferParams::FrameInterlaced
  163. #define SapDefFieldOrder SapXferParams::FieldOrderOddEven
  164. //
  165. // SapData class declaration
  166. //
  167. class SAPCLASSBASIC_CLASS SapData
  168. {
  169. public:
  170. // Constructor
  171. SapData()
  172. { m_Type = SapFormatTypeUnknown; Clear(); }
  173. virtual ~SapData() {}
  174. virtual void Clear() { memset(&m_Data, 0, sizeof(m_Data)); }
  175. // Access to implementation
  176. CORDATA GetData() const { return m_Data; }
  177. SapFormatType GetType() const { return m_Type; }
  178. void SetData(CORDATA data) { m_Data = data; }
  179. protected:
  180. CORDATA m_Data;
  181. SapFormatType m_Type;
  182. };
  183. //
  184. // Derived classes declarations
  185. //
  186. class SAPCLASSBASIC_CLASS SapDataMono : public SapData
  187. {
  188. public:
  189. // Constructors
  190. SapDataMono()
  191. { m_Type = SapFormatTypeMono; }
  192. SapDataMono(int mono)
  193. { m_Type = SapFormatTypeMono; m_Data.mono = mono; }
  194. SapDataMono(const SapData &data)
  195. { m_Type = SapFormatTypeMono; m_Data = data.GetData(); }
  196. SapDataMono &operator=(const SapData &data) { m_Type = SapFormatTypeMono; m_Data = data.GetData(); return *this; }
  197. // Data access methods
  198. int Mono() { return m_Data.mono; }
  199. void Set(int mono) { m_Data.mono = mono; }
  200. };
  201. class SAPCLASSBASIC_CLASS SapDataRGBA : public SapData
  202. {
  203. public:
  204. // Constructors
  205. SapDataRGBA()
  206. { m_Type = SapFormatTypeRGBA; }
  207. SapDataRGBA(int red, int green, int blue, int alpha)
  208. { m_Type = SapFormatTypeRGBA; m_Data.rgba.red = (UINT16)red; m_Data.rgba.green = (UINT16)green; m_Data.rgba.blue = (UINT16)blue; m_Data.rgba.alpha = (UINT16)alpha;}
  209. SapDataRGBA(const SapData &data)
  210. { m_Type = SapFormatTypeRGBA; m_Data = data.GetData(); }
  211. SapDataRGBA &operator=(const SapData &data) { m_Type = SapFormatTypeRGBA; m_Data = data.GetData(); return *this; }
  212. // Data access methods
  213. int Red() { return m_Data.rgba.red; }
  214. int Green() { return m_Data.rgba.green; }
  215. int Blue() { return m_Data.rgba.blue; }
  216. int Alpha() { return m_Data.rgba.alpha; }
  217. void Set(int red, int green, int blue, int alpha) { m_Data.rgba.red = (UINT16)red; m_Data.rgba.green = (UINT16)green; m_Data.rgba.blue = (UINT16)blue; m_Data.rgba.alpha = (UINT16)alpha;}
  218. };
  219. class SAPCLASSBASIC_CLASS SapDataRGB : public SapData
  220. {
  221. public:
  222. // Constructors
  223. SapDataRGB()
  224. { m_Type = SapFormatTypeRGB; }
  225. SapDataRGB(int red, int green, int blue)
  226. { m_Type = SapFormatTypeRGB; m_Data.rgb.red = red; m_Data.rgb.green = green; m_Data.rgb.blue = blue; }
  227. SapDataRGB(const SapData &data)
  228. { m_Type = SapFormatTypeRGB; m_Data = data.GetData(); }
  229. SapDataRGB &operator=(const SapData &data) { m_Type = SapFormatTypeRGB; m_Data = data.GetData(); return *this; }
  230. // Data access methods
  231. int Red() { return m_Data.rgb.red; }
  232. int Green() { return m_Data.rgb.green; }
  233. int Blue() { return m_Data.rgb.blue; }
  234. void Set(int red, int green, int blue) { m_Data.rgb.red = red; m_Data.rgb.green = green; m_Data.rgb.blue = blue; }
  235. };
  236. class SAPCLASSBASIC_CLASS SapDataYUV : public SapData
  237. {
  238. public:
  239. // Constructors
  240. SapDataYUV()
  241. { m_Type = SapFormatTypeYUV; }
  242. SapDataYUV(int y, int u, int v)
  243. { m_Type = SapFormatTypeYUV; m_Data.yuv.y = y; m_Data.yuv.u = u; m_Data.yuv.v = v; }
  244. SapDataYUV(const SapData &data)
  245. { m_Type = SapFormatTypeYUV; m_Data = data.GetData(); }
  246. // Data access methods
  247. int Y() { return m_Data.yuv.y; }
  248. int U() { return m_Data.yuv.u; }
  249. int V() { return m_Data.yuv.v; }
  250. void Clear() { SapData::Clear(); m_Data.yuv.u = 0x80; m_Data.yuv.v = 0x80; }
  251. void Set(int y, int u, int v) { m_Data.yuv.y = y; m_Data.yuv.u = u; m_Data.yuv.v = v; }
  252. };
  253. class SAPCLASSBASIC_CLASS SapDataHSI : public SapData
  254. {
  255. public:
  256. // Constructors
  257. SapDataHSI()
  258. { m_Type = SapFormatTypeHSI; }
  259. SapDataHSI(int h, int s, int i)
  260. { m_Type = SapFormatTypeHSI; m_Data.hsi.h = h; m_Data.hsi.s = s; m_Data.hsi.i = i; }
  261. SapDataHSI(const SapData &data)
  262. { m_Type = SapFormatTypeHSI; m_Data = data.GetData(); }
  263. // Data access methods
  264. int H() { return m_Data.hsi.h; }
  265. int S() { return m_Data.hsi.s; }
  266. int I() { return m_Data.hsi.i; }
  267. void Set(int h, int s, int i) { m_Data.hsi.h = h; m_Data.hsi.s = s; m_Data.hsi.i = i; }
  268. };
  269. class SAPCLASSBASIC_CLASS SapDataLAB : public SapData
  270. {
  271. public:
  272. // Constructors
  273. SapDataLAB()
  274. { m_Type = SapFormatTypeLAB; }
  275. SapDataLAB(int l, int a, int b)
  276. { m_Type = SapFormatTypeLAB; m_Data.lab.l = l; m_Data.lab.a = a; m_Data.lab.b = b; }
  277. SapDataLAB(const SapData &data)
  278. { m_Type = SapFormatTypeLAB; m_Data = data.GetData(); }
  279. // Data access methods
  280. int L() { return m_Data.lab.l; }
  281. int A() { return m_Data.lab.a; }
  282. int B() { return m_Data.lab.b; }
  283. void Set(int l, int a, int b) { m_Data.lab.l = l; m_Data.lab.a = a; m_Data.lab.b = b; }
  284. };
  285. class SAPCLASSBASIC_CLASS SapDataLABA : public SapData
  286. {
  287. public:
  288. // Constructors
  289. SapDataLABA()
  290. { m_Type = SapFormatTypeLABA; }
  291. SapDataLABA(int l, int a, int b, int alpha)
  292. { m_Type = SapFormatTypeLABA; m_Data.laba.l = (UINT16)l; m_Data.laba.a = (UINT16)a; m_Data.laba.b = (UINT16)b; m_Data.laba.alpha = (UINT16)alpha; }
  293. SapDataLABA(const SapData &data)
  294. { m_Type = SapFormatTypeLABA; m_Data = data.GetData(); }
  295. // Data access methods
  296. int L() { return m_Data.laba.l; }
  297. int A() { return m_Data.laba.a; }
  298. int B() { return m_Data.laba.b; }
  299. int Alpha() { return m_Data.laba.alpha; }
  300. void Set(int l, int a, int b, int alpha) { m_Data.laba.l = (UINT16)l; m_Data.laba.a = (UINT16)a; m_Data.laba.b = (UINT16)b; m_Data.laba.alpha = (UINT16)alpha; }
  301. };
  302. class SAPCLASSBASIC_CLASS SapDataHSV : public SapData
  303. {
  304. public:
  305. // Constructors
  306. SapDataHSV()
  307. { m_Type = SapFormatTypeHSV; }
  308. SapDataHSV(int h, int s, int v)
  309. { m_Type = SapFormatTypeHSV; m_Data.hsv.h = h; m_Data.hsv.s = s; m_Data.hsv.v = v; }
  310. SapDataHSV(const SapData &data)
  311. { m_Type = SapFormatTypeHSV; m_Data = data.GetData(); }
  312. // Data access methods
  313. int H() { return m_Data.hsv.h; }
  314. int S() { return m_Data.hsv.s; }
  315. int V() { return m_Data.hsv.v; }
  316. void Set(int h, int s, int v) { m_Data.hsv.h = h; m_Data.hsv.s = s; m_Data.hsv.v = v; }
  317. };
  318. class SAPCLASSBASIC_CLASS SapDataFloat : public SapData
  319. {
  320. public:
  321. // Constructors
  322. SapDataFloat()
  323. { m_Type = SapFormatTypeFloat; }
  324. SapDataFloat(float flt)
  325. { m_Type = SapFormatTypeFloat; m_Data.flt = flt; }
  326. SapDataFloat(const SapData &data)
  327. { m_Type = SapFormatTypeFloat; m_Data = data.GetData(); }
  328. // Data access methods
  329. float Float() { return m_Data.flt; }
  330. void Clear() { SapData::Clear(); m_Data.flt = 0.0; }
  331. void Set(float flt) { m_Data.flt = flt; }
  332. };
  333. class SAPCLASSBASIC_CLASS SapDataPoint : public SapData
  334. {
  335. public:
  336. // Constructors
  337. SapDataPoint()
  338. { m_Type = SapFormatTypePoint; }
  339. SapDataPoint(int x, int y)
  340. { m_Type = SapFormatTypePoint; m_Data.point.x = x; m_Data.point.y = y; }
  341. SapDataPoint(const SapData &data)
  342. { m_Type = SapFormatTypePoint; m_Data = data.GetData(); }
  343. // Data access methods
  344. int X() { return m_Data.point.x; }
  345. int Y() { return m_Data.point.y; }
  346. void Set(int x, int y) { m_Data.point.x = x; m_Data.point.y = y; }
  347. };
  348. class SAPCLASSBASIC_CLASS SapDataFPoint : public SapData
  349. {
  350. public:
  351. // Constructors
  352. SapDataFPoint()
  353. { m_Type = SapFormatTypeFPoint; }
  354. SapDataFPoint(float x, float y)
  355. { m_Type = SapFormatTypeFPoint; m_Data.fpoint.x = x; m_Data.fpoint.y = y; }
  356. SapDataFPoint(const SapData &data)
  357. { m_Type = SapFormatTypeFPoint; m_Data = data.GetData(); }
  358. // Data access methods
  359. float X() { return m_Data.fpoint.x; }
  360. float Y() { return m_Data.fpoint.y; }
  361. void Clear() { SapData::Clear(); m_Data.fpoint.x = 0.0; m_Data.fpoint.y = 0.0; }
  362. void Set(float x, float y) { m_Data.fpoint.x = x; m_Data.fpoint.y = y; }
  363. };
  364. class SAPCLASSBASIC_CLASS SapDataFRGB : public SapData
  365. {
  366. public:
  367. // Constructors
  368. SapDataFRGB()
  369. { m_Type = SapFormatTypeFRGB; }
  370. SapDataFRGB(float red, float green, float blue)
  371. { m_Type = SapFormatTypeFRGB; m_Data.frgb.red = red; m_Data.frgb.green = green; m_Data.frgb.blue = blue; }
  372. SapDataFRGB(const SapData &data)
  373. { m_Type = SapFormatTypeFRGB; m_Data = data.GetData(); }
  374. // Data access methods
  375. float Red() { return m_Data.frgb.red; }
  376. float Green() { return m_Data.frgb.green; }
  377. float Blue() { return m_Data.frgb.blue; }
  378. void Clear() { SapData::Clear(); m_Data.frgb.red = 0.0; m_Data.frgb.green = 0.0; m_Data.frgb.blue = 0.0; }
  379. void Set(float red, float green, float blue) { m_Data.frgb.red = red; m_Data.frgb.green = green; m_Data.frgb.blue = blue; }
  380. };
  381. #endif // _SAPDATA_H_