netatmo-algo/src/png.cpp

26 lines
532 B
C++

#include "png.h"
#include <cstring>
#include <iostream>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
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;
}