10#ifndef MVE_IMAGE_BASE_HEADER
11#define MVE_IMAGE_BASE_HEADER
55 typedef std::shared_ptr<ImageBase>
Ptr;
56 typedef std::shared_ptr<ImageBase const>
ConstPtr;
67 int64_t width (
void)
const;
69 int64_t height (
void)
const;
71 int64_t channels (
void)
const;
74 bool valid (
void)
const;
80 bool reinterpret (int64_t new_w, int64_t new_h, int64_t new_c);
83 virtual std::size_t get_byte_size (
void)
const;
85 virtual char const* get_byte_pointer (
void)
const;
87 virtual char* get_byte_pointer (
void);
91 virtual char const* get_type_string (
void)
const;
94 static ImageType get_type_for_string (std::string
const& type_string);
115 typedef std::shared_ptr<TypedImageBase<T> >
Ptr;
116 typedef std::shared_ptr<TypedImageBase<T>
const>
ConstPtr;
132 void allocate (int64_t width, int64_t height, int64_t chans);
141 void resize (int64_t width, int64_t height, int64_t chans);
144 virtual void clear (
void);
147 void fill (T
const& value);
155 char const* get_type_string (
void)
const;
163 T
const* get_data_pointer (
void)
const;
165 T* get_data_pointer (
void);
170 T
const* begin (
void)
const;
174 T
const* end (
void)
const;
177 int64_t get_pixel_amount (
void)
const;
179 int64_t get_value_amount (
void)
const;
182 std::size_t get_byte_size (
void)
const;
184 char const* get_byte_pointer (
void)
const;
186 char* get_byte_pointer (
void);
195ImageBase::duplicate_base (
void)
const
201ImageBase::width (
void)
const
207ImageBase::height (
void)
const
213ImageBase::channels (
void)
const
219ImageBase::valid (
void)
const
221 return this->w > 0 && this->h > 0 && this->c > 0;
225ImageBase::reinterpret (int64_t new_w, int64_t new_h, int64_t new_c)
227 if (new_w * new_h * new_c != this->w * this->h * this->c)
237ImageBase::get_byte_size (
void)
const
243ImageBase::get_byte_pointer (
void)
const
249ImageBase::get_byte_pointer (
void)
255ImageBase::get_type (
void)
const
261ImageBase::get_type_string (
void)
const
267ImageBase::get_type_for_string (std::string
const& type_string)
269 if (type_string ==
"sint8")
271 else if (type_string ==
"sint16")
273 else if (type_string ==
"sint32")
275 else if (type_string ==
"sint64")
277 else if (type_string ==
"uint8")
279 else if (type_string ==
"uint16")
281 else if (type_string ==
"uint32")
283 else if (type_string ==
"uint64")
285 else if (type_string ==
"float")
287 else if (type_string ==
"double")
390 return util::string::for_type<T>();
398 this->resize(width, height, chans);
408 this->data.resize(width * height * chans);
425 std::fill(this->data.begin(), this->data.end(), value);
456 if (this->data.empty())
458 return &this->data[0];
465 if (this->data.empty())
467 return &this->data[0];
474 return this->data.empty() ? nullptr : &this->data[0];
481 return this->data.empty() ? nullptr : &this->data[0];
488 return this->data.empty() ? nullptr : this->begin() + this->data.size();
495 return this->data.empty() ? nullptr : this->begin() + this->data.size();
502 return this->w * this->h;
509 return this->get_pixel_amount() * this->c;
516 return this->data.size() *
sizeof(T);
523 return reinterpret_cast<char const*
>(this->get_data_pointer());
530 return reinterpret_cast<char*
>(this->get_data_pointer());
Base class for images without type information.
virtual ~ImageBase(void)=default
std::shared_ptr< ImageBase const > ConstPtr
std::shared_ptr< ImageBase > Ptr
ImageBase(void)=default
Initializes members with 0.
Base class for images of arbitrary type.
void swap(TypedImageBase< T > &other)
Swaps the contents of the images.
ImageData const & get_data(void) const
Returns the data vector for the image.
int64_t get_pixel_amount(void) const
Returns the amount of pixels in the image (w * h).
int64_t get_value_amount(void) const
Returns the amount of values in the image (w * h * c).
std::size_t get_byte_size(void) const
Returns the size of the image in bytes (w * h * c * BPV).
void fill(T const &value)
Fills the data with a constant value.
void resize(int64_t width, int64_t height, int64_t chans)
Resizes the underlying image data vector.
virtual ImageType get_type(void) const
Value type information by template specialization.
T * begin(void)
Returns data pointer to beginning.
virtual void clear(void)
Clears the image data from memory.
std::shared_ptr< TypedImageBase< T > const > ConstPtr
T * end(void)
Returns data pointer to end.
char const * get_type_string(void) const
Returns a string representation of the image data type.
std::shared_ptr< TypedImageBase< T > > Ptr
T const * get_data_pointer(void) const
Returns the data pointer.
std::vector< T > ImageData
virtual ImageBase::Ptr duplicate_base(void) const
Duplicates the image.
char const * get_byte_pointer(void) const
Returns the char pointer to the data.
void allocate(int64_t width, int64_t height, int64_t chans)
Allocates new image space, clearing previous content.
virtual ~TypedImageBase(void)=default
TypedImageBase(void)=default
Default constructor creates an empty image.
#define MVE_NAMESPACE_BEGIN
#define STD_NAMESPACE_END
#define MVE_NAMESPACE_END
#define STD_NAMESPACE_BEGIN
ImageType
Identifiers for image types.
void swap(mve::Image< T > &a, mve::Image< T > &b)
Specialization of std::swap for efficient image swapping.