Img2Num C++ (Internal Developer Docs) dev
API Documentation
Loading...
Searching...
No Matches
ImageLib::Image< PixelT > Class Template Reference
+ Collaboration diagram for ImageLib::Image< PixelT >:

Public Types

using iter = typename std::vector< PixelT >::iterator
 
using const_iter = typename std::vector< PixelT >::const_iterator
 

Public Member Functions

 Image (int width, int height, PixelT fill=PixelT())
 
template<typename ConverterT >
void loadFromBuffer (const uint8_t *buffer, int width, int height, PixelConverter< ConverterT > converter)
 
void fill (const PixelT &color)
 
iter begin ()
 
iter end ()
 
const_iter begin () const
 
const_iter end () const
 
int getWidth () const
 
int getHeight () const
 
int getPixelCount () const
 
int getSize () const
 
const std::vector< PixelT > & getData () const
 
const PixelT & getPixel (int x, int y) const
 
PixelT & getPixel (int x, int y)
 
void setPixel (int x, int y, const PixelT &p)
 
PixelT & operator[] (int idx)
 
const PixelT & operator[] (int idx) const
 
PixelT & operator() (int x, int y)
 
const PixelT & operator() (int x, int y) const
 

Private Member Functions

int index (int x, int y) const
 

Private Attributes

std::vector< PixelT > data
 
int width
 
int height
 

Detailed Description

template<typename PixelT>
class ImageLib::Image< PixelT >

Definition at line 14 of file Image.h.

Member Typedef Documentation

◆ const_iter

template<typename PixelT >
using ImageLib::Image< PixelT >::const_iter = typename std::vector<PixelT>::const_iterator

Definition at line 52 of file Image.h.

◆ iter

template<typename PixelT >
using ImageLib::Image< PixelT >::iter = typename std::vector<PixelT>::iterator

Definition at line 45 of file Image.h.

Constructor & Destructor Documentation

◆ Image() [1/2]

template<typename PixelT >
ImageLib::Image< PixelT >::Image ( )
inline

Definition at line 19 of file Image.h.

19 : width(0), height(0) {
20 }

◆ Image() [2/2]

template<typename PixelT >
ImageLib::Image< PixelT >::Image ( int  width,
int  height,
PixelT  fill = PixelT() 
)
inline

Definition at line 21 of file Image.h.

22 : width(width), height(height), data(width * height, fill) {
23 }

Member Function Documentation

◆ begin() [1/2]

template<typename PixelT >
iter ImageLib::Image< PixelT >::begin ( )
inline

Definition at line 46 of file Image.h.

46 {
47 return data.begin();
48 }

◆ begin() [2/2]

template<typename PixelT >
const_iter ImageLib::Image< PixelT >::begin ( ) const
inline

Definition at line 53 of file Image.h.

53 {
54 return data.begin();
55 }

◆ end() [1/2]

template<typename PixelT >
iter ImageLib::Image< PixelT >::end ( )
inline

Definition at line 49 of file Image.h.

49 {
50 return data.end();
51 }

◆ end() [2/2]

template<typename PixelT >
const_iter ImageLib::Image< PixelT >::end ( ) const
inline

Definition at line 56 of file Image.h.

56 {
57 return data.end();
58 }

◆ fill()

template<typename PixelT >
void ImageLib::Image< PixelT >::fill ( const PixelT &  color)
inline

Definition at line 41 of file Image.h.

41 {
42 std::fill(data.begin(), data.end(), color);
43 }

◆ getData()

template<typename PixelT >
const std::vector< PixelT > & ImageLib::Image< PixelT >::getData ( ) const
inline

Definition at line 73 of file Image.h.

73 {
74 return data;
75 }

◆ getHeight()

template<typename PixelT >
int ImageLib::Image< PixelT >::getHeight ( ) const
inline

Definition at line 63 of file Image.h.

63 {
64 return height;
65 }

◆ getPixel() [1/2]

template<typename PixelT >
PixelT & ImageLib::Image< PixelT >::getPixel ( int  x,
int  y 
)
inline

Definition at line 80 of file Image.h.

80 {
81 return data[index(x, y)];
82 }

◆ getPixel() [2/2]

template<typename PixelT >
const PixelT & ImageLib::Image< PixelT >::getPixel ( int  x,
int  y 
) const
inline

Definition at line 77 of file Image.h.

77 {
78 return data[index(x, y)];
79 }

◆ getPixelCount()

template<typename PixelT >
int ImageLib::Image< PixelT >::getPixelCount ( ) const
inline

Definition at line 66 of file Image.h.

66 {
67 return width * height;
68 }

◆ getSize()

template<typename PixelT >
int ImageLib::Image< PixelT >::getSize ( ) const
inline

Definition at line 69 of file Image.h.

69 {
70 return getPixelCount();
71 }

◆ getWidth()

template<typename PixelT >
int ImageLib::Image< PixelT >::getWidth ( ) const
inline

Definition at line 60 of file Image.h.

60 {
61 return width;
62 }

◆ index()

template<typename PixelT >
int ImageLib::Image< PixelT >::index ( int  x,
int  y 
) const
inlineprivate

Definition at line 108 of file Image.h.

108 {
109 if (x < 0 || y < 0 || x >= width || y >= height)
110 throw std::out_of_range("Pixel coordinates out of bounds");
111 return y * width + x;
112 }

◆ loadFromBuffer()

template<typename PixelT >
template<typename ConverterT >
void ImageLib::Image< PixelT >::loadFromBuffer ( const uint8_t *  buffer,
int  width,
int  height,
PixelConverter< ConverterT >  converter 
)
inline

Definition at line 26 of file Image.h.

27 {
28 // converter.convert must return exactly PixelT
29 static_assert(std::is_same_v<decltype(converter.convert((const uint8_t *)nullptr)), PixelT>,
30 "Converter return type must match PixelT");
31
32 this->width = width;
33 this->height = height;
34 const int pixelCount = getPixelCount();
35 data.resize(pixelCount);
36 for (int i = 0; i < pixelCount; ++i) {
37 data[i] = converter.convert(&buffer[i * converter.bytesPerPixel]);
38 }
39 }

◆ operator()() [1/2]

template<typename PixelT >
PixelT & ImageLib::Image< PixelT >::operator() ( int  x,
int  y 
)
inline

Definition at line 97 of file Image.h.

97 {
98 return data.at(index(x, y));
99 } // set

◆ operator()() [2/2]

template<typename PixelT >
const PixelT & ImageLib::Image< PixelT >::operator() ( int  x,
int  y 
) const
inline

Definition at line 100 of file Image.h.

100 {
101 return data.at(index(x, y));
102 } // get

◆ operator[]() [1/2]

template<typename PixelT >
PixelT & ImageLib::Image< PixelT >::operator[] ( int  idx)
inline

Definition at line 89 of file Image.h.

89 {
90 return data.at(idx);
91 } // set

◆ operator[]() [2/2]

template<typename PixelT >
const PixelT & ImageLib::Image< PixelT >::operator[] ( int  idx) const
inline

Definition at line 92 of file Image.h.

92 {
93 return data.at(idx);
94 } // get

◆ setPixel()

template<typename PixelT >
void ImageLib::Image< PixelT >::setPixel ( int  x,
int  y,
const PixelT &  p 
)
inline

Definition at line 84 of file Image.h.

84 {
85 data[index(x, y)] = p;
86 }

Member Data Documentation

◆ data

template<typename PixelT >
std::vector<PixelT> ImageLib::Image< PixelT >::data
private

Definition at line 105 of file Image.h.

◆ height

template<typename PixelT >
int ImageLib::Image< PixelT >::height
private

Definition at line 106 of file Image.h.

◆ width

template<typename PixelT >
int ImageLib::Image< PixelT >::width
private

Definition at line 106 of file Image.h.


The documentation for this class was generated from the following file: