netatmo-algo/src/png.cpp

29 lines
545 B
C++
Raw Normal View History

2022-02-12 00:28:54 +01:00
#include "png.h"
#include <cstring>
#include <iostream>
#include "stb_image.h"
2022-02-17 23:15:45 +01:00
namespace freling {
2022-02-12 00:28:54 +01:00
std::optional<Frame> load_png(const std::filesystem::path& in) {
int x = 0;
int y = 0;
int channels = 0;
const int desired_channels = 3;
unsigned char* data =
stbi_load(in.c_str(), &x, &y, &channels, desired_channels);
if (data == NULL) {
return {};
}
Frame f(x, y);
std::memcpy(f.data, data, x * y * desired_channels);
stbi_image_free(data);
return f;
}
2022-02-17 23:15:45 +01:00
} // namespace freling