LibraryLink Utilities  3.0.1
Modern C++ wrapper over LibraryLink and WSTP
Generic/Image.hpp
Go to the documentation of this file.
1 
5 #ifndef LLU_CONTAINERS_GENERIC_IMAGE_HPP
6 #define LLU_CONTAINERS_GENERIC_IMAGE_HPP
7 
10 
11 namespace LLU {
12 
13  template<>
14  class MContainer<MArgumentType::Image>;
15 
17  using GenericImage = MContainer<MArgumentType::Image>;
18 
22  template<>
23  class MContainer<MArgumentType::Image> : public ImageInterface, public MContainerBase<MArgumentType::Image> {
24  public:
27 
29  MContainer() = default;
30 
40  MContainer(mint width, mint height, mint channels, imagedata_t type, colorspace_t colorSpace, mbool interleaving)
41  : MContainer(0, width, height, channels, type, colorSpace, interleaving) {}
42 
53  MContainer(mint slices, mint width, mint height, mint channels, imagedata_t type, colorspace_t colorSpace, mbool interleaving);
54 
62  GenericImage convert(imagedata_t t, mbool interleavingQ) const;
63 
70  GenericImage convert(imagedata_t t) const {
71  return convert(t, static_cast<mbool>(interleavedQ()));
72  }
73 
79  MContainer clone() const {
80  return MContainer {cloneContainer(), Ownership::Library};
81  }
82 
84  colorspace_t colorspace() const override {
85  return LibraryData::ImageAPI()->MImage_getColorSpace(this->getContainer());
86  }
87 
89  mint rows() const override {
90  return LibraryData::ImageAPI()->MImage_getRowCount(this->getContainer());
91  }
92 
94  mint columns() const override {
95  return LibraryData::ImageAPI()->MImage_getColumnCount(this->getContainer());
96  }
97 
99  mint slices() const override {
100  return LibraryData::ImageAPI()->MImage_getSliceCount(this->getContainer());
101  }
102 
104  mint channels() const override {
105  return LibraryData::ImageAPI()->MImage_getChannels(this->getContainer());
106  }
107 
109  bool alphaChannelQ() const override {
110  return LibraryData::ImageAPI()->MImage_alphaChannelQ(this->getContainer()) != 0;
111  }
112 
114  bool interleavedQ() const override {
115  return LibraryData::ImageAPI()->MImage_interleavedQ(this->getContainer()) != 0;
116  }
117 
119  bool is3D() const override {
120  return LibraryData::ImageAPI()->MImage_getRank(this->getContainer()) == 3;
121  }
122 
124  mint getRank() const override {
125  return LibraryData::ImageAPI()->MImage_getRank(this->getContainer());
126  }
127 
129  mint getFlattenedLength() const override {
130  return LibraryData::ImageAPI()->MImage_getFlattenedLength(this->getContainer());
131  }
132 
134  imagedata_t type() const override {
135  return LibraryData::ImageAPI()->MImage_getDataType(this->getContainer());
136  }
137 
139  void* rawData() const override {
140  return LibraryData::ImageAPI()->MImage_getRawData(this->getContainer());
141  }
142  private:
143 
148  Container cloneImpl() const override;
149 
154  mint shareCountImpl() const noexcept override {
155  return LibraryData::ImageAPI()->MImage_shareCount(this->getContainer());
156  }
157 
159  void passImpl(MArgument& res) const noexcept override {
160  MArgument_setMImage(res, this->getContainer());
161  }
162  };
163 
164 } // namespace LLU
165 
166 #endif // LLU_CONTAINERS_GENERIC_IMAGE_HPP
LLU::MContainerBase
Template of the base class for all generic containers.
Definition: Base.hpp:35
LLU::MContainer< MArgumentType::Image >::MContainer
MContainer()=default
Default constructor, the MContainer does not manage any instance of MImage.
LLU
Main namespace of LibraryLink Utilities.
Definition: Queue.h:13
LLU::MContainer
MContainer is an abstract class template for generic containers. Only specializations shall be used.
Definition: Base.hpp:245
LLU::MContainer< MArgumentType::Image >::columns
mint columns() const override
Get number of columns.
Definition: Generic/Image.hpp:94
LLU::MContainer< MArgumentType::Image >::clone
MContainer clone() const
Clone this MContainer, performs a deep copy of the underlying MImage.
Definition: Generic/Image.hpp:79
LLU::MContainer< MArgumentType::Image >::is3D
bool is3D() const override
Check if the image is 3D.
Definition: Generic/Image.hpp:119
LLU::MContainer< MArgumentType::Image >::type
imagedata_t type() const override
Get the data type of the image.
Definition: Generic/Image.hpp:134
LLU::MContainer< MArgumentType::Image >::MContainer
MContainer(mint width, mint height, mint channels, imagedata_t type, colorspace_t colorSpace, mbool interleaving)
Create new 2D MImage based on given parameters.
Definition: Generic/Image.hpp:40
LLU::ImageInterface
Abstract class that defines a basic set of operations on an image.
Definition: Interfaces.h:17
LLU::MContainer< MArgumentType::Image >::getFlattenedLength
mint getFlattenedLength() const override
Get the total number of pixels in the image.
Definition: Generic/Image.hpp:129
LLU::MContainer< MArgumentType::Image >
MContainer specialization for MImage.
Definition: Generic/Image.hpp:23
LLU::MContainer< MArgumentType::Image >::getRank
mint getRank() const override
Get rank.
Definition: Generic/Image.hpp:124
LLU::Ownership::Library
@ Library
The library (LLU) is responsible for managing the container's memory. Used for Manual passing and con...
LLU::LibraryData::ImageAPI
static const st_WolframImageLibrary_Functions * ImageAPI()
Get a pointer to structure with function pointers to MImage API.
Definition: LibraryData.cpp:41
LLU::MContainer< MArgumentType::Image >::alphaChannelQ
bool alphaChannelQ() const override
Check if there is an alpha channel in the image.
Definition: Generic/Image.hpp:109
LLU::MContainer< MArgumentType::Image >::convert
GenericImage convert(imagedata_t t) const
Convert this object to a new GenericImage of given datatype.
Definition: Generic/Image.hpp:70
LLU::MContainer< MArgumentType::Image >::channels
mint channels() const override
Get number of channels.
Definition: Generic/Image.hpp:104
LLU::MContainer< MArgumentType::Image >::slices
mint slices() const override
Get number of slices.
Definition: Generic/Image.hpp:99
LLU::Argument::Typed::Image
MContainer< MArgumentType::Image > Image
Image stands for a GenericImage - type agnostic wrapper over MImage.
Definition: TypedMArgument.h:56
Base.hpp
Definitions of MContainerBase and MContainer class templates.
LLU::MArgumentType
MArgumentType
Strongly type enum with possible types of data stored in MArgument.
Definition: MArgument.h:22
LLU::MContainer< MArgumentType::Image >::rawData
void * rawData() const override
Get access to raw image data.
Definition: Generic/Image.hpp:139
LLU::MContainer< MArgumentType::Image >::interleavedQ
bool interleavedQ() const override
Check if the image is interleaved.
Definition: Generic/Image.hpp:114
LLU::MContainer< MArgumentType::Image >::colorspace
colorspace_t colorspace() const override
Get colorspace which describes how colors are represented as numbers.
Definition: Generic/Image.hpp:84
Interfaces.h
LLU::MContainer< MArgumentType::Image >::rows
mint rows() const override
Get number of rows.
Definition: Generic/Image.hpp:89