Skip to content

pylon/ResultImage.h#

Low Level API: Contains an adapter adapting a grab result to Pylon::IImage.

Namespaces#

Name
Pylon
Contains definitions of pylon types.

Classes#

Name
class Pylon::CGrabResultImageT
Low Level API: Adapts grab result to Pylon::IImage.

Source code#

//-----------------------------------------------------------------------------
//  Basler pylon SDK
//  Copyright (c) 2010-2022 Basler AG
//  http://www.baslerweb.com
//  Author:  Andreas Gau
//-----------------------------------------------------------------------------
#pragma once

#ifndef INCLUDED_RESULTIMAGE_H_0326044
#define INCLUDED_RESULTIMAGE_H_0326044

#include <pylon/Image.h>

namespace Pylon
{
    template <typename GrabResultT>
    class CGrabResultImageT : public IImage
    {
    public:
        CGrabResultImageT( GrabResultT grabResult, bool isUnique )
            : m_grabResult( grabResult )
            , m_isUnique( isUnique )
        {
        }

        virtual ~CGrabResultImageT()
        {
        }

        // Implements Pylon::IImage.
        virtual bool IsValid() const
        {
            return IsValidImpl();
        }

        // Implements Pylon::IImage.
        virtual EPixelType GetPixelType() const
        {
            return IsValidImpl() ? m_grabResult.GetPixelType() : PixelType_Undefined;
        }

        // Implements Pylon::IImage.
        virtual uint32_t GetWidth() const
        {
            return IsValidImpl() ? static_cast<uint32_t>(m_grabResult.GetSizeX()) : 0;
        }

        // Implements Pylon::IImage.
        virtual uint32_t GetHeight() const
        {
            return IsValidImpl() ? static_cast<uint32_t>(m_grabResult.GetSizeY()) : 0;
        }

        // Implements Pylon::IImage.
        virtual size_t GetPaddingX() const
        {
            return IsValidImpl() ? m_grabResult.GetPaddingX() : 0;
        }

        // Implements Pylon::IImage.
        virtual EImageOrientation GetOrientation() const
        {
            return ImageOrientation_TopDown;
        }

        // Implements Pylon::IImage.
        virtual void* GetBuffer()
        {
            return IsValidImpl() ? m_grabResult.Buffer() : NULL;
        }

        // Implements Pylon::IImage.
        virtual const void* GetBuffer() const
        {
            return IsValidImpl() ? m_grabResult.Buffer() : NULL;
        }

        // Implements Pylon::IImage.
        virtual size_t GetImageSize() const
        {
            return IsValidImpl() ? ComputeBufferSize( m_grabResult.GetPixelType(), static_cast<uint32_t>(m_grabResult.GetSizeX()), static_cast<uint32_t>(m_grabResult.GetSizeY()), m_grabResult.GetPaddingX() ) : 0;
        }

        // Implements Pylon::IImage.
        virtual bool IsUnique() const
        {
            return m_isUnique;
        }

        // Implements Pylon::IImage.
        virtual bool GetStride( size_t& strideBytes ) const
        {
            return IsValidImpl() ? ComputeStride( strideBytes, m_grabResult.GetPixelType(), static_cast<uint32_t>(m_grabResult.GetSizeX()), m_grabResult.GetPaddingX() ) : false;
        }

    protected:
        // Check whether the grab result is valid.
        bool IsValidImpl() const
        {
            return
                m_grabResult.Succeeded()
                && m_grabResult.GetPixelType() != PixelType_Undefined
                && m_grabResult.GetSizeX() >= 0
                && m_grabResult.GetSizeY() >= 0
                && m_grabResult.GetPaddingX() >= 0;
        }

        GrabResultT m_grabResult; 
        bool m_isUnique; 
    };
} // namespace Pylon

#endif /* INCLUDED_RESULTIMAGE_H_0326044 */

Updated on 27 July 2022 at 19:03:47