sculpto
Public Member Functions | List of all members
scl::image Class Reference

#include <image.h>

Public Member Functions

int GetWidth () const
 
int GetHeight () const
 
int GetComponentsCount () const
 
const u8GetRawData () const
 
bool IsEmpty () const
 
 image ()=default
 
 image (const image &Other)
 
imageoperator= (const image &Other)
 
 image (int Width, int Height, int ComponentsCount, bool AllocateMemory=true)
 
 image (int Width, int Height, int ComponentsCount, void *Data)
 
 image (const std::string &FileName)
 
 ~image ()
 
void Allocate ()
 
void Free ()
 
bool Load (const std::string &FileName)
 
void FlipHorizontaly ()
 

Detailed Description

Image container class.

Definition at line 18 of file image.h.

Constructor & Destructor Documentation

◆ image() [1/5]

scl::image::image ( )
default

Imaeg default constructor.

◆ image() [2/5]

scl::image::image ( const image Other)
inline

Image copy constructor.

Definition at line 48 of file image.h.

49 {
50 if (Other.Data == nullptr) return;
51
52 Width = Other.Width;
53 Height = Other.Height;
54 ComponentsCount = Other.ComponentsCount;
55
56 size_t size = (size_t)Width * Height * ComponentsCount;
57 Data = new u8[size];
58 memcpy(Data, Other.Data, size);
59 }
uint8_t u8
Definition: math_common.h:17

◆ image() [3/5]

scl::image::image ( int  Width,
int  Height,
int  ComponentsCount,
bool  AllocateMemory = true 
)
inline
  • Empty image specified size constructor.
Parameters
Width- width of creating image.
Height- height of creating image.
ComponentsCount- dimentions (components per pixel) count.
AllocateMemory- flag, showing weather allocate mrmory for data buffer or not.

Definition at line 85 of file image.h.

85 :
86 Width(Width), Height(Height), ComponentsCount(ComponentsCount)
87 {
88 if (AllocateMemory) Allocate();
89 }
void Allocate()
Definition: image.h:129

◆ image() [4/5]

scl::image::image ( int  Width,
int  Height,
int  ComponentsCount,
void *  Data 
)
inline
  • Image by pixels array constructor.
Parameters
Width- width of creating image.
Height- height of creating image.
ComponentsCount- dimentions (components per pixel) count.
Data- image pixel array pointer with byte size [Width * Height * ComponentsCount].

Definition at line 99 of file image.h.

99 :
100 Width(Width), Height(Height), ComponentsCount(ComponentsCount)
101 {
102 size_t size = (size_t)Width * Height * ComponentsCount;
103 this->Data = new u8[size];
104 memcpy(this->Data, Data, size);
105 }

◆ image() [5/5]

scl::image::image ( const std::string &  FileName)
inline
  • Image constructor loading data from file.
Parameters
FileName- image file name.

Definition at line 112 of file image.h.

113 {
114 this->Load(FileName);
115 }
bool Load(const std::string &FileName)
Definition: image.h:153

◆ ~image()

scl::image::~image ( )
inline

Image default destructor.

Definition at line 118 of file image.h.

119 {
120 Free();
121 }
void Free()
Definition: image.h:140

Member Function Documentation

◆ Allocate()

void scl::image::Allocate ( )
inline
  • Allocate memory for image data buffer (of current image size).
Parameters
None.
Returns
None.

Definition at line 129 of file image.h.

130 {
131 Data = new u8[(u64)Width * Height * ComponentsCount];
132 }
uint64_t u64
Definition: math_common.h:23

◆ FlipHorizontaly()

void scl::image::FlipHorizontaly ( )
inline
  • Flip image along X axis function.
Parameters
None.
Returns
None.

Definition at line 180 of file image.h.

181 {
182 u32 row_size = Width * ComponentsCount;
183 u8 *tmp = new u8[row_size];
184 for (u64 i = 0; i < Height / 2; ++i)
185 {
186 std::memmove(tmp, &Data[i * row_size], row_size);
187 std::memmove(&Data[i * row_size], &Data[(Height - i - 1) * row_size], row_size);
188 std::memmove(&Data[(Height - i - 1) * row_size], tmp, row_size);
189 }
190 delete[] tmp;
191 }
uint32_t u32
Definition: math_common.h:21

◆ Free()

void scl::image::Free ( )
inline
  • Free memory of image data buffer.
Parameters
None.
Returns
None.

Definition at line 140 of file image.h.

141 {
142 Width = Height = ComponentsCount = 0;
143 if (Data != nullptr) stbi_image_free(Data);
144 Data = nullptr;
145 }

◆ GetComponentsCount()

int scl::image::GetComponentsCount ( ) const
inline

Image dimentions (components per pixel) count getter function.

Definition at line 31 of file image.h.

31{ return ComponentsCount; }

◆ GetHeight()

int scl::image::GetHeight ( ) const
inline

Image height getter function.

Definition at line 29 of file image.h.

29{ return Height; }

◆ GetRawData()

const u8 * scl::image::GetRawData ( ) const
inline

Image raw data pointer getter function.

Definition at line 33 of file image.h.

33{ return Data; }

◆ GetWidth()

int scl::image::GetWidth ( ) const
inline

Image getter/setter functions.

Image width getter function.

Definition at line 27 of file image.h.

27{ return Width; }

◆ IsEmpty()

bool scl::image::IsEmpty ( ) const
inline
  • Check if image container filled with pixels function.
Parameters
None.
Returns
is image empty flag.

Definition at line 41 of file image.h.

41{ return Data == nullptr; }

◆ Load()

bool scl::image::Load ( const std::string &  FileName)
inline
  • Image load from file function.
Parameters
FileName- file name to load image from.
Returns
success flag.

Definition at line 153 of file image.h.

154 {
155 // За каждым малоком должен быть free.... (CGSG FOREVER!!!)
156 if (Data != nullptr) delete[] Data;
157
158 // Load image, check if successful
159 int w, h, c;
160 Data = stbi_load(FileName.c_str(), &w, &h, &c, 0);
161 if (Data == nullptr)
162 {
163 SCL_CORE_ERROR("Error during loading image from file \"{}\"!", FileName);
164 Width = Height = ComponentsCount = 0;
165 if (Data) stbi_image_free(Data);
166 return false;
167 }
168
169 // If image loaded successful, set image data
170 Width = w, Height = h, ComponentsCount = c;
171 return true;
172 }
#define SCL_CORE_ERROR(...)
Definition: log.h:44

◆ operator=()

image & scl::image::operator= ( const image Other)
inline

Image copy assigment operator.

Definition at line 62 of file image.h.

63 {
64 if (this == &Other || Other.Data == nullptr) return *this;
65 if (Data != nullptr) delete[] Data;
66
67 Width = Other.Width;
68 Height = Other.Height;
69 ComponentsCount = Other.ComponentsCount;
70
71 size_t size = (size_t)Width * Height * ComponentsCount;
72 Data = new u8[size];
73 memcpy(Data, Other.Data, size);
74 return *this;
75 }

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