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 13 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 60 of file Image.h.

◆ iter

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

Definition at line 53 of file Image.h.

Constructor & Destructor Documentation

◆ Image() [1/2]

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

Definition at line 20 of file Image.h.

21 : width(0)
22 , height(0) {
23 }

◆ Image() [2/2]

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

Definition at line 24 of file Image.h.

25 : width(width)
26 , height(height)
27 , data(width * height, fill) {
28 }

Member Function Documentation

◆ begin() [1/2]

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

Definition at line 54 of file Image.h.

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

◆ begin() [2/2]

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

Definition at line 61 of file Image.h.

61 {
62 return data.begin();
63 }

◆ end() [1/2]

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

Definition at line 57 of file Image.h.

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

◆ end() [2/2]

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

Definition at line 64 of file Image.h.

64 {
65 return data.end();
66 }

◆ fill()

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

Definition at line 49 of file Image.h.

49 {
50 std::fill(data.begin(), data.end(), color);
51 }

◆ getData()

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

Definition at line 81 of file Image.h.

81 {
82 return data;
83 }

◆ getHeight()

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

Definition at line 71 of file Image.h.

71 {
72 return height;
73 }

◆ getPixel() [1/2]

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

Definition at line 88 of file Image.h.

88 {
89 return data[index(x, y)];
90 }

◆ getPixel() [2/2]

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

Definition at line 85 of file Image.h.

85 {
86 return data[index(x, y)];
87 }

◆ getPixelCount()

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

Definition at line 74 of file Image.h.

74 {
75 return width * height;
76 }

◆ getSize()

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

Definition at line 77 of file Image.h.

77 {
78 return getPixelCount();
79 }

◆ getWidth()

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

Definition at line 68 of file Image.h.

68 {
69 return width;
70 }

◆ index()

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

Definition at line 116 of file Image.h.

116 {
117 if (x < 0 || y < 0 || x >= width || y >= height)
118 throw std::out_of_range("Pixel coordinates out of bounds");
119 return y * width + x;
120 }

◆ 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 31 of file Image.h.

33 {
34 // converter.convert must return exactly PixelT
35 static_assert(
36 std::is_same_v<decltype(converter.convert((const uint8_t*)nullptr)), PixelT>,
37 "Converter return type must match PixelT"
38 );
39
40 this->width = width;
41 this->height = height;
42 const int pixelCount = getPixelCount();
43 data.resize(pixelCount);
44 for (int i = 0; i < pixelCount; ++i) {
45 data[i] = converter.convert(&buffer[i * converter.bytesPerPixel]);
46 }
47 }

◆ operator()() [1/2]

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

Definition at line 105 of file Image.h.

105 {
106 return data.at(index(x, y));
107 } // set

◆ operator()() [2/2]

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

Definition at line 108 of file Image.h.

108 {
109 return data.at(index(x, y));
110 } // get

◆ operator[]() [1/2]

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

Definition at line 97 of file Image.h.

97 {
98 return data.at(idx);
99 } // set

◆ operator[]() [2/2]

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

Definition at line 100 of file Image.h.

100 {
101 return data.at(idx);
102 } // get

◆ setPixel()

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

Definition at line 92 of file Image.h.

92 {
93 data[index(x, y)] = p;
94 }

Member Data Documentation

◆ data

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

Definition at line 113 of file Image.h.

◆ height

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

Definition at line 114 of file Image.h.

◆ width

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

Definition at line 114 of file Image.h.


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