ResultImage.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2010-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: Andreas Gau
  6. //-----------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Low Level API: Contains an adapter adapting a grab result to Pylon::IImage.
  10. */
  11. #pragma once
  12. #ifndef INCLUDED_RESULTIMAGE_H_0326044
  13. #define INCLUDED_RESULTIMAGE_H_0326044
  14. #include <pylon/Image.h>
  15. namespace Pylon
  16. {
  17. /*!
  18. \brief Low Level API: Adapts grab result to Pylon::IImage.
  19. \ingroup Pylon_LowLevelApi
  20. */
  21. template <typename GrabResultT>
  22. class CGrabResultImageT : public IImage
  23. {
  24. public:
  25. /*!
  26. \brief Creates a grab result image object.
  27. \param[in] grabResult A grab result.
  28. \param[in] isUnique User provided info whether the buffer is referenced only by this grab result.
  29. \error
  30. Does not throw C++ exceptions.
  31. */
  32. CGrabResultImageT( GrabResultT grabResult, bool isUnique )
  33. : m_grabResult( grabResult )
  34. , m_isUnique( isUnique )
  35. {
  36. }
  37. /// Destroys a grab result image object.
  38. virtual ~CGrabResultImageT()
  39. {
  40. }
  41. // Implements Pylon::IImage.
  42. virtual bool IsValid() const
  43. {
  44. return IsValidImpl();
  45. }
  46. // Implements Pylon::IImage.
  47. virtual EPixelType GetPixelType() const
  48. {
  49. return IsValidImpl() ? m_grabResult.GetPixelType() : PixelType_Undefined;
  50. }
  51. // Implements Pylon::IImage.
  52. virtual uint32_t GetWidth() const
  53. {
  54. return IsValidImpl() ? static_cast<uint32_t>(m_grabResult.GetSizeX()) : 0;
  55. }
  56. // Implements Pylon::IImage.
  57. virtual uint32_t GetHeight() const
  58. {
  59. return IsValidImpl() ? static_cast<uint32_t>(m_grabResult.GetSizeY()) : 0;
  60. }
  61. // Implements Pylon::IImage.
  62. virtual size_t GetPaddingX() const
  63. {
  64. return IsValidImpl() ? m_grabResult.GetPaddingX() : 0;
  65. }
  66. // Implements Pylon::IImage.
  67. virtual EImageOrientation GetOrientation() const
  68. {
  69. return ImageOrientation_TopDown;
  70. }
  71. // Implements Pylon::IImage.
  72. virtual void* GetBuffer()
  73. {
  74. return IsValidImpl() ? m_grabResult.Buffer() : NULL;
  75. }
  76. // Implements Pylon::IImage.
  77. virtual const void* GetBuffer() const
  78. {
  79. return IsValidImpl() ? m_grabResult.Buffer() : NULL;
  80. }
  81. // Implements Pylon::IImage.
  82. virtual size_t GetImageSize() const
  83. {
  84. return IsValidImpl() ? ComputeBufferSize( m_grabResult.GetPixelType(), static_cast<uint32_t>(m_grabResult.GetSizeX()), static_cast<uint32_t>(m_grabResult.GetSizeY()), m_grabResult.GetPaddingX() ) : 0;
  85. }
  86. // Implements Pylon::IImage.
  87. virtual bool IsUnique() const
  88. {
  89. return m_isUnique;
  90. }
  91. // Implements Pylon::IImage.
  92. virtual bool GetStride( size_t& strideBytes ) const
  93. {
  94. return IsValidImpl() ? ComputeStride( strideBytes, m_grabResult.GetPixelType(), static_cast<uint32_t>(m_grabResult.GetSizeX()), m_grabResult.GetPaddingX() ) : false;
  95. }
  96. protected:
  97. // Check whether the grab result is valid.
  98. bool IsValidImpl() const
  99. {
  100. return
  101. m_grabResult.Succeeded()
  102. && m_grabResult.GetPixelType() != PixelType_Undefined
  103. && m_grabResult.GetSizeX() >= 0
  104. && m_grabResult.GetSizeY() >= 0
  105. && m_grabResult.GetPaddingX() >= 0;
  106. }
  107. GrabResultT m_grabResult; ///< The grab result that is adapted to IImage.
  108. bool m_isUnique; ///< User provided info whether the buffer is referenced only by this adapter.
  109. };
  110. } // namespace Pylon
  111. #endif /* INCLUDED_RESULTIMAGE_H_0326044 */