PylonBitmapImage.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 Contains a bitmap image class for displaying images.
  10. */
  11. #ifndef INCLUDED_PYLONBITMAPIMAGE_H_7767407
  12. #define INCLUDED_PYLONBITMAPIMAGE_H_7767407
  13. #include <pylon/Platform.h>
  14. #ifdef _MSC_VER
  15. # pragma pack(push, PYLON_PACKING)
  16. #endif /* _MSC_VER */
  17. #include <pylon/stdinclude.h>
  18. #include <pylon/PylonUtility.h>
  19. #include <pylon/PylonImageBase.h>
  20. namespace Pylon
  21. {
  22. /** \addtogroup Pylon_ImageHandlingSupport
  23. * @{
  24. */
  25. /*!
  26. \class CPylonBitmapImage
  27. \brief This class can be used to easily create Windows bitmaps for displaying images.
  28. <ul>
  29. <li> Automatically handles the bitmap creation and lifetime.
  30. <li> Provides methods for loading and saving an image in different file formats.
  31. <li> Serves as target format for the \c CImageFormatConverter image format converter.
  32. </ul>
  33. \par Buffer Handling:
  34. The bitmap buffer that is automatically created by the CPylonBitmapImage class.
  35. The Release() method can be used to release a bitmap.
  36. \threading
  37. The CPylonBitmapImage class is not thread-safe.
  38. */
  39. class PYLONUTILITY_API CPylonBitmapImage : public CPylonImageBase
  40. {
  41. public:
  42. /*!
  43. \brief Creates an invalid image.
  44. See Pylon::IImage on how the properties of an invalid image are returned.
  45. \error
  46. Does not throw C++ exceptions.
  47. */
  48. CPylonBitmapImage();
  49. /*!
  50. \brief Copies the image properties and creates a reference to the bitmap of the source image.
  51. \param[in] source The source image.
  52. \post
  53. <ul>
  54. <li> Another reference to the source bitmap is created.
  55. <li> Creates an invalid image if the source image is invalid.
  56. </ul>
  57. \error
  58. Does not throw C++ exceptions.
  59. */
  60. CPylonBitmapImage( const CPylonBitmapImage& source );
  61. /*!
  62. \brief Destroys a pylon image object.
  63. \attention The bitmap handle must not be currently selected into a DC. Otherwise the bitmap is not freed.
  64. \error
  65. Does not throw C++ exceptions.
  66. */
  67. virtual ~CPylonBitmapImage();
  68. /*!
  69. \brief Copies the image properties and creates a reference to the bitmap of the source image.
  70. \param[in] source The source image.
  71. \post
  72. <ul>
  73. <li> Another reference to the source bitmap is created.
  74. <li> Creates an invalid image if the source image is invalid.
  75. </ul>
  76. \error
  77. Does not throw C++ exceptions.
  78. */
  79. virtual CPylonBitmapImage& operator= ( const CPylonBitmapImage& source );
  80. /*!
  81. \brief Creates an image and a Windows bitmap for it.
  82. \param[in] pixelType The pixel type of the new image.
  83. \param[in] width The number of pixels in a row in the new image.
  84. \param[in] height The number of rows in the new image.
  85. \param[in] orientation The vertical orientation of the image in the image buffer.
  86. \pre
  87. <ul>
  88. <li> The pixel type must be supported, see IsSupportedPixelType().
  89. <li> The \c width value must be > 0 and < _I32_MAX.
  90. <li> The \c height value must be > 0 and < _I32_MAX.
  91. </ul>
  92. \error
  93. Throws an exception when the parameters are invalid.
  94. Throws an exception when the bitmap could not be created.
  95. */
  96. static CPylonBitmapImage Create( EPixelType pixelType, uint32_t width, uint32_t height, EImageOrientation orientation = ImageOrientation_BottomUp );
  97. /*!
  98. \brief Copies the image data from a different image.
  99. The input image is automatically converted if needed to PixelType_Mono8
  100. if Pylon::IsMonoImage( pixelTypeSource) is true,
  101. otherwise it is converted to PixelType_BGR8packed.
  102. The orientation of the image is changed to bottom up.
  103. If more control over the conversion is required, the CImageFormatConverter class
  104. can be used to convert other images with a CPylonBitmapImage object as target.
  105. \param[in] image The source image, e.g. a CPylonImage, CPylonBitmapImage, or Grab Result Smart Pointer object.
  106. \pre
  107. The preconditions of the Reset() method must be met.
  108. \post
  109. <ul>
  110. <li> The source image is automatically converted.
  111. <li> Creates an invalid image if the source image is invalid.
  112. </ul>
  113. \error
  114. Throws an exception when the bitmap could not be created.
  115. Throws an exception when the preconditions of the Reset() method are not met.
  116. */
  117. virtual void CopyImage( const IImage& image );
  118. /*!
  119. \brief Sets an image from a user buffer.
  120. \param[in] pBuffer The pointer to the buffer of the source image.
  121. \param[in] bufferSizeBytes The size of the buffer of the source image.
  122. \param[in] pixelType The pixel type of the source image.
  123. \param[in] width The number of pixels in a row in the source image.
  124. \param[in] height The number of rows in the source image.
  125. \param[in] paddingX The number of extra data bytes at the end of each row.
  126. \param[in] orientation The vertical orientation of the image in the image buffer.
  127. \pre
  128. <ul>
  129. <li> The pixel type must be valid.
  130. <li> The \c width value must be >= 0 and < _I32_MAX.
  131. <li> The \c height value must be >= 0 and < _I32_MAX.
  132. <li> The pointer to the source buffer must not be NULL.
  133. <li> The source buffer must be large enough to hold the image described by the parameters.
  134. <li> The preconditions of the Reset() method must be met.
  135. </ul>
  136. \post
  137. The source image is automatically converted. See CopyImage().
  138. \error
  139. Throws an exception when when the bitmap could not be created.
  140. Throws an exception when the preconditions of the Reset() method are not met.
  141. */
  142. virtual void CopyImage(
  143. const void* pBuffer,
  144. size_t bufferSizeBytes,
  145. EPixelType pixelType,
  146. uint32_t width,
  147. uint32_t height,
  148. size_t paddingX,
  149. EImageOrientation orientation );
  150. // Implements Pylon::IImage.
  151. virtual bool IsValid() const;
  152. // Implements Pylon::IImage.
  153. virtual EPixelType GetPixelType() const;
  154. // Implements Pylon::IImage.
  155. virtual uint32_t GetWidth() const;
  156. // Implements Pylon::IImage.
  157. virtual uint32_t GetHeight() const;
  158. // Implements Pylon::IImage.
  159. virtual size_t GetPaddingX() const;
  160. // Implements Pylon::IImage.
  161. virtual EImageOrientation GetOrientation() const;
  162. // Implements Pylon::IImage.
  163. virtual void* GetBuffer();
  164. // Implements Pylon::IImage.
  165. virtual const void* GetBuffer() const;
  166. // Implements Pylon::IImage.
  167. virtual size_t GetImageSize() const;
  168. // Implements Pylon::IImage.
  169. virtual bool IsUnique() const;
  170. // Implements Pylon::IImage.
  171. virtual bool GetStride( size_t& strideBytes ) const;
  172. // Implements Pylon::IReusableImage.
  173. virtual bool IsSupportedPixelType( EPixelType pixelType ) const;
  174. // Implements Pylon::IReusableImage, always returns true.
  175. virtual bool IsAdditionalPaddingSupported() const;
  176. //Implements Pylon::IReusableImage
  177. /*!
  178. \brief Resets the image properties and creates a new Windows bitmap if required.
  179. \param[in] pixelType The pixel type of the new image.
  180. \param[in] width The number of pixels in a row in the new image.
  181. \param[in] height The number of rows in the new image.
  182. \param[in] orientation The vertical orientation of the image in the image buffer.
  183. \pre
  184. <ul>
  185. <li> The \c width value must be > 0 and < _I32_MAX.
  186. <li> The \c height value must be > 0 and < _I32_MAX.
  187. </ul>
  188. \post
  189. <ul>
  190. <li> If the previously referenced bitmap is also referenced by another pylon bitmap image, a new Windows bitmap is created.
  191. <li> If the previously referenced bitmap is able to hold an image with the given properties, a new Windows bitmap is created.
  192. <li> If no bitmap has been created before, a new Windows bitmap is created.
  193. </ul>
  194. \error
  195. Throws an exception when the preconditions are not met.
  196. Throws an exception when no buffer with the required size could be allocated.
  197. */
  198. virtual void Reset( EPixelType pixelType, uint32_t width, uint32_t height, EImageOrientation orientation = ImageOrientation_BottomUp );
  199. // Implements Pylon::IReusableImage.
  200. // attention: The bitmap handle must not be currently selected into a DC. Otherwise, the bitmap is not freed.
  201. virtual void Release();
  202. /*!
  203. \brief Get the handle of the windows bitmap.
  204. \attention The handle must not be freed using DeleteObject().
  205. The handle is invalid after calling Release().
  206. The handle may be invalid after calling Reset().
  207. \return Returns the handle of the windows bitmap or NULL if the image is invalid.
  208. \error
  209. Does not throw C++ exceptions.
  210. */
  211. virtual operator HBITMAP() const;
  212. /*!
  213. \brief Detach the windows bitmap.
  214. \return Returns the handle of the windows bitmap or NULL if the image is invalid.
  215. \pre
  216. IsUnique() must return true. No other image must reference the bitmap.
  217. \post
  218. <ul>
  219. <li> The image is invalid.
  220. <li> The ownership of the bitmap goes to the caller who is responsible for deleting it.
  221. </ul>
  222. \error
  223. Does not throw C++ exceptions.
  224. */
  225. virtual HBITMAP Detach();
  226. private:
  227. /// Not supported.
  228. virtual void Reset( EPixelType pixelType, uint32_t width, uint32_t height, size_t paddingX, EImageOrientation orientation );
  229. // Internal use only.
  230. class CPylonBitmapImageImpl;
  231. CPylonBitmapImageImpl* m_pImpl;
  232. };
  233. /**
  234. * @}
  235. */
  236. }
  237. #ifdef _MSC_VER
  238. # pragma pack(pop)
  239. #endif /* _MSC_VER */
  240. #endif /* INCLUDED_PYLONBITMAPIMAGE_H_7767407 */