PixelData.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //------------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2012-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: Andreas Gau
  6. //------------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Contains a data structure describing the data of one pixel.
  10. */
  11. #ifndef INCLUDED_PIXELDATA_H_9714014
  12. #define INCLUDED_PIXELDATA_H_9714014
  13. #include <pylon/Platform.h>
  14. #ifdef _MSC_VER
  15. # pragma pack(push, PYLON_PACKING)
  16. #endif /* _MSC_VER */
  17. #include <pylon/PylonBase.h>
  18. namespace Pylon
  19. {
  20. /** \addtogroup Pylon_ImageHandlingSupport
  21. * @{
  22. */
  23. /*!
  24. \class SPixelData
  25. \brief Describes the data of one pixel.
  26. */
  27. struct SPixelData
  28. {
  29. /// Construct and clear.
  30. SPixelData()
  31. : PixelDataType( PixelDataType_Unknown )
  32. , BitDepth( 0 )
  33. {
  34. Data.RGBA.R =
  35. Data.RGBA.G =
  36. Data.RGBA.B =
  37. Data.RGBA.A = 0;
  38. }
  39. ~SPixelData()
  40. {
  41. }
  42. /// Lists the possible pixel data types.
  43. /// Do not confound this enumeration with the Pylon::PixelType enumeration that lists all pixel formats.
  44. enum EPixelDataType
  45. {
  46. PixelDataType_Unknown,//!< Will be returned, if the pixel data cannot be determined.
  47. PixelDataType_Mono, //!< Pixel data of monochrome images.
  48. PixelDataType_YUV, //!< Pixel data of YUV images.
  49. PixelDataType_RGB, //!< Pixel data of RGB or BGR images.
  50. PixelDataType_RGBA, //!< Pixel data of RGB or BGR images with alpha channel.
  51. PixelDataType_BayerR, //!< Pixel data of a red pixel of bayer images.
  52. PixelDataType_BayerG, //!< Pixel data of a green pixel of bayer images.
  53. PixelDataType_BayerB //!< Pixel data of a blue pixel of bayer images.
  54. };
  55. EPixelDataType PixelDataType; ///< The type of pixel data held.
  56. uint32_t BitDepth; ///< The bit depth of the data held.
  57. union
  58. {
  59. int Mono; ///< Pixel data of monochrome images.
  60. int BayerR; ///< Pixel data of a red pixel of bayer images.
  61. int BayerG; ///< Pixel data of a green pixel of bayer images.
  62. int BayerB; ///< Pixel data of a blue pixel of bayer images.
  63. struct
  64. {
  65. int Y; ///< Brightness.
  66. int U; ///< Chroma U.
  67. int V; ///< Chroma V.
  68. }
  69. YUV; ///< Pixel data of YUV images.
  70. struct
  71. {
  72. int R; ///< Red.
  73. int G; ///< Green.
  74. int B; ///< Blue.
  75. }
  76. RGB; ///< Pixel data of RGB or BGR images.
  77. struct
  78. {
  79. int R; ///< Red.
  80. int G; ///< Green.
  81. int B; ///< Blue.
  82. int A; ///< Transparency.
  83. }
  84. RGBA; ///< Pixel data of RGB or BGR images with an alpha channel.
  85. }
  86. Data; ///< Holds all types of pixel data.
  87. /// Compares pixel data.
  88. bool operator==( const SPixelData& rhs )
  89. {
  90. if (PixelDataType != rhs.PixelDataType) return false;
  91. if (BitDepth != rhs.BitDepth) return false;
  92. switch (PixelDataType)
  93. {
  94. case PixelDataType_Unknown:
  95. return true;
  96. case PixelDataType_Mono:
  97. return Data.Mono == rhs.Data.Mono;
  98. case PixelDataType_YUV:
  99. return Data.YUV.Y == rhs.Data.YUV.Y && Data.YUV.U == rhs.Data.YUV.U && Data.YUV.V == rhs.Data.YUV.V;
  100. case PixelDataType_RGB:
  101. return Data.RGB.R == rhs.Data.RGB.R && Data.RGB.G == rhs.Data.RGB.G && Data.RGB.B == rhs.Data.RGB.B;
  102. case PixelDataType_RGBA:
  103. return Data.RGB.R == rhs.Data.RGBA.R && Data.RGBA.G == rhs.Data.RGBA.G && Data.RGBA.B == rhs.Data.RGBA.B && Data.RGBA.A == rhs.Data.RGBA.A;
  104. case PixelDataType_BayerR:
  105. return Data.BayerR == rhs.Data.BayerR;
  106. case PixelDataType_BayerG:
  107. return Data.BayerG == rhs.Data.BayerG;
  108. case PixelDataType_BayerB:
  109. return Data.BayerB == rhs.Data.BayerB;
  110. default:
  111. PYLON_ASSERT2( false, "Cannot compare SPixelDataStructure. It contains unexpected data." );
  112. }
  113. return false;
  114. }
  115. /// Compares pixel data.
  116. bool operator!=( const SPixelData& rhs )
  117. {
  118. return !((*this) == rhs);
  119. }
  120. };
  121. /**
  122. * @}
  123. */
  124. }
  125. #ifdef _MSC_VER
  126. # pragma pack(pop)
  127. #endif /* _MSC_VER */
  128. #endif /* INCLUDED_PIXELDATA_H_9714014 */