PeriDyno 1.0.0
Loading...
Searching...
No Matches
ImageLoader.cpp
Go to the documentation of this file.
1#define STB_IMAGE_IMPLEMENTATION
2#define STB_IMAGE_WRITE_IMPLEMENTATION
3
4#include "ImageLoader.h"
5
6namespace dyno {
7
8 bool ImageLoader::loadImage(const char* path, CArray2D<Vec4f>& img) {
9 int x, y, comp;
10 stbi_set_flip_vertically_on_load(true);
11
12 float* data = stbi_loadf(path, &x, &y, &comp, STBI_default);
13
14 if (data) {
15 img.resize(x, y);
16 for (int x0 = 0; x0 < x; x0++) {
17 for (int y0 = 0; y0 < y; y0++) {
18 int idx = (y0 * x + x0) * comp;
19 for (int c0 = 0; c0 < comp; c0++) {
20 img(x0, y0)[c0] = data[idx + c0];
21 }
22 }
23 }
24 STBI_FREE(data);
25 }
26
27 return data != nullptr;
28 }
29
30} // namespace dyno
bool loadImage(const char *path, CArray2D< Vec4f > &img)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array2D< T, DeviceType::CPU > CArray2D
Definition Array2D.h:131