PylonImageUserBufferEventHandler.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2021-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: JS
  6. //-----------------------------------------------------------------------------
  7. /**
  8. \file
  9. \brief Contains the pylon image event handler base class.
  10. */
  11. #pragma once
  12. #ifndef INCLUDED_PYLONIMAGEUSERBUFFEREVENTHANDLER_H_
  13. #define INCLUDED_PYLONIMAGEUSERBUFFEREVENTHANDLER_H_
  14. #include <pylon/stdinclude.h>
  15. #pragma pack(push, PYLON_PACKING)
  16. namespace Pylon
  17. {
  18. /** \addtogroup Pylon_ImageHandlingSupport
  19. * @{
  20. */
  21. /**
  22. \class CPylonImageUserBufferEventHandler
  23. \brief The CPylonImage user buffer event handler base class.
  24. You can optionally pass an object derived from this class when calling CPylonImage::AttachUserBuffer().
  25. When the CPylonImage doesn't need the user buffer anymore, it will call the CPylonImageUserBufferEventHandler::OnPylonImageUserBufferDetached()
  26. method. You can override this function to execute your custom code when the user buffer has been detached implicitly.
  27. The user is responsible for ensuring the object is valid until CPylonImageUserBufferEventHandler::OnPylonImageUserBufferDetached() has been called.
  28. */
  29. class CPylonImageUserBufferEventHandler
  30. {
  31. public:
  32. /**
  33. \brief This method is called after the image class has released its user buffer.
  34. This method is called after the image class releases its image buffer.
  35. In case a user buffer has been attached using CPylonImage::AttachUserBuffer() you can use this to free
  36. your user buffer.
  37. In case you created the event handler on the heap using \c new, you can call <tt>delete this</tt> at the end of the function.
  38. \code{.cpp}
  39. // Sample handler to show how to delete the handler when allocating the handler on the heap.
  40. class MyHandler : public CPylonImageUserBufferEventHandler {
  41. OnPylonImageUserBufferDetached( void* pUserBuffer, size_t bufferSizeBytes ) override {
  42. // Use our custom memory allocator to free the user buffer.
  43. MyCustomFreeMemory( pUserBuffer );
  44. // Delete the handler.
  45. delete this;
  46. }
  47. };
  48. // Use our custom memory allocator for pixel data.
  49. void* pUserBuffer = MyCustomAllocateMemory( 640 * 480 );
  50. // Attach user buffer using a heap-allocated event handler.
  51. CPylonImage image;
  52. image.AttachUserBuffer(pUserBuffer, (640 * 480), PixelType_Mono8, 640, 480, 0, ImageOrientation_TopDown, new MyHandler() );
  53. \endcode
  54. The default implementation does nothing. You can override this function to execute custom code.
  55. \param[in] pUserBuffer Pointer to the user buffer passed when the user buffer was attached using CPylonImage::AttachUserBuffer().
  56. \param[in] bufferSizeBytes Size of the user buffer passed when the user buffer was attached using CPylonImage::AttachUserBuffer().
  57. \error
  58. This function must not throw any exceptions.
  59. */
  60. virtual void OnPylonImageUserBufferDetached( void* pUserBuffer, size_t bufferSizeBytes )
  61. {
  62. PYLON_UNUSED( pUserBuffer );
  63. PYLON_UNUSED( bufferSizeBytes );
  64. }
  65. };
  66. /**
  67. * @}
  68. */
  69. }
  70. #pragma pack(pop)
  71. #endif /* INCLUDED_PYLONIMAGEUSERBUFFEREVENTHANDLER_H_ */