#include <image.h>
Image container class.
Definition at line 18 of file image.h.
◆ image() [1/5]
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;
58 memcpy(Data, Other.Data, size);
59 }
◆ 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 {
89 }
◆ 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)
◆ ~image()
Image default destructor.
Definition at line 118 of file image.h.
◆ Allocate()
void scl::image::Allocate |
( |
| ) |
|
|
inline |
- Allocate memory for image data buffer (of current image size).
- Parameters
-
- Returns
- None.
Definition at line 129 of file image.h.
130 {
131 Data =
new u8[(
u64)Width * Height * ComponentsCount];
132 }
◆ FlipHorizontaly()
void scl::image::FlipHorizontaly |
( |
| ) |
|
|
inline |
- Flip image along X axis function.
- Parameters
-
- 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 }
◆ Free()
void scl::image::Free |
( |
| ) |
|
|
inline |
- Free memory of image data buffer.
- Parameters
-
- 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.
◆ GetRawData()
const u8 * scl::image::GetRawData |
( |
| ) |
const |
|
inline |
Image raw data pointer getter function.
Definition at line 33 of file image.h.
◆ GetWidth()
int scl::image::GetWidth |
( |
| ) |
const |
|
inline |
Image getter/setter functions.
Image width getter function.
Definition at line 27 of file image.h.
◆ IsEmpty()
bool scl::image::IsEmpty |
( |
| ) |
const |
|
inline |
- Check if image container filled with pixels function.
- Parameters
-
- 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
156 if (Data != nullptr) delete[] Data;
157
158
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
170 Width = w, Height = h, ComponentsCount = c;
171 return true;
172 }
#define SCL_CORE_ERROR(...)
◆ 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;
73 memcpy(Data, Other.Data, size);
74 return *this;
75 }
The documentation for this class was generated from the following file: