#ifndef SP_IMAGE_H #define SP_IMAGE_H #include "core_v2/ndarray_helper.hpp" #include "core_v2/meta_helper.hpp" #include constexpr auto image_rank = 2; struct sp_image : ndarray_proxy, meta_proxy { std::type_index type = typeid(void); //@formatter:off using base_type = ndarray_proxy; base_type *array_base() { return this; } [[nodiscard]] cv::Size cv_size() const; [[nodiscard]] int cv_type() const; [[nodiscard]] cv::Mat cv_mat(void *ptr) const; [[nodiscard]] cv::cuda::GpuMat cv_gpu_mat(void *ptr) const; [[nodiscard]] sp_image sub_view(cv::Size size, cv::Size start = {}) const; //@formatter:on template static sp_image create(const cv::Size size, const size_t align = 1) { return create_impl(size, align, typeid(T)); } static sp_image create(const int cv_type, const cv::Size size, const size_t align = 1) { return create_impl(size, align, cv_type); } template static sp_image create(const cv::Size size, const void *ptr) { return create_impl(size, ptr, typeid(T)); } static sp_image create(const cv::Mat &mat); template [[nodiscard]] sp_image cast_view() const { return cast_view_impl(typeid(T)); } [[nodiscard]] sp_image cast_view(int cv_type) const; protected: //@formatter:off static sp_image create_impl(cv::Size size, size_t align, std::type_index type); static sp_image create_impl(cv::Size size, size_t align, int cv_type); static sp_image create_impl(cv::Size size, const void *ptr, std::type_index type); [[nodiscard]] sp_image cast_view_impl(std::type_index type) const; //@formatter:on }; void copy_sp_image(const sp_image &src, sp_image &dst, cudaMemcpyKind kind = cudaMemcpyDefault); template using image_ndarray = ndarray; #include "core/image_utility_v2.h" template image_type_v2 to_cuda_v2(image_ndarray img) { auto ret = image_type_v2(); ret.ptr = (T *) img.data; ret.width = img.width(); ret.height = img.height(); ret.pitch = img.pitch(); return ret; } image_mem_info to_mem_v1(const sp_image &img, void *ptr, memory_location loc = MEM_CUDA); #endif //SP_IMAGE_H