Updated on 2022-03-13 GMT+08:00

AIImageBuffer

Defines the general buffer of images. This class is defined in ai_tensor.h.

    class AIImageBuffer : public AISimpleTensor
    {
    public:
        AIImageBuffer()
        {
            format_ = JPEG;
            width_  = 0;
            height_ = 0;
        };

        /*
       * @brief   Obtain the type name.
        */
        const char* const GetTypeName();

        /*
       @brief  Obtain the byte size.
        */
        uint32_t ByteSizeLong();

        /*
       @brief Initialization
        @param [in] tensor_desc  Tensor description
        */
        bool Init(const AITensorDescription &tensor_desc);

#if defined( __ANDROID__) || defined(ANDROID)
        /*
        * @brief   Serialize data to the buffer for cross-process data interaction.
        * @param [in] buffer   Address of the buffer to which the data is serialized, allocated by the caller
        * @param [in] size   Size of the buffer to which the data is output
        * @return SUCCESS   Success
        *         FAILED: failure. If the tensor does not support cross-process, this API does not need to be implemented and a failure message is returned.
        */
        AIStatus SerializeTo(void* buffer, uint32_t size_);

        /*
        * @brief   Deserialize data from the buffer to a tensor for cross-process data interaction.
        * @param [in] buffer  Size of the buffer to which the data is input
        * @param [in] size   Size of the buffer to which the data is input
        * @return SUCCESS   Success
        *         FAILED: failure. If the tensor does not support cross-process, this API does not need to be implemented and a failure message is returned.
        */
        AIStatus DeserializeFrom(const void* buffer, uint32_t size_);
#endif
        /*
        * @brief  Obtain the description.
        */
        static AITensorDescription GetDescription(
            const std::string &size = "0",const std::string &height="0",
            const std::string &width="0", const std::string format="JPEG");

        /*
       @brief Create a tensor.
        */
        static std::shared_ptr<IAITensor> CreateTensor(const AITensorDescription& tensor_desc);

        /*
        @brief Obtain the image format.
        */
        ImageFormat GetFormat();
        /*
        @brief  Set the image format.
        */
        void SetFormat(ImageFormat format);

        /*
       @brief  Obtain the height.
        */
        int32_t GetHeight();

        /*
       @brief  Set the height.
        */
        void SetHeight(int32_t height);

        /*
       @brief  Obtain the width.
        */
        int32_t GetWidth();

        /*
       @brief  Set the width.
        */
        void SetWidth(int32_t width);
    private:
        ImageFormat format_;
        int32_t width_;
        int32_t height_;
    };