26#include <vclib/io/file_info.h>
27#include <vclib/misc/string.h>
29#if __has_include(<stb/stb_image.h>)
30#include <stb/stb_image.h>
31#include <stb/stb_image_write.h>
35#define STB_IMAGE_STATIC
36#define STB_IMAGE_IMPLEMENTATION
37#include "../../../external/stb-master/stb/stb_image.h"
38#define STB_IMAGE_WRITE_STATIC
39#define STB_IMAGE_WRITE_IMPLEMENTATION
40#include "../../../external/stb-master/stb/stb_image_write.h"
48inline std::shared_ptr<unsigned char> loadImageData(
49 const std::string& filename,
53 std::shared_ptr<unsigned char> ptr(
54 stbi_load(filename.c_str(), &w, &h,
nullptr, 4), stbi_image_free);
58inline void saveImageData(
59 const std::string& filename,
62 const unsigned char* data,
69 ret = stbi_write_png(filename.c_str(), w, h, 4, data, 0);
71 else if (ext ==
".bmp") {
72 ret = stbi_write_bmp(filename.c_str(), w, h, 4, data);
74 else if (ext ==
".tga") {
75 ret = stbi_write_tga(filename.c_str(), w, h, 4, data);
77 else if (ext ==
".jpg" || ext ==
".jpeg") {
78 ret = stbi_write_jpg(filename.c_str(), w, h, 4, data, quality);
81 throw UnknownFileFormatException(ext);
85 throw CannotOpenFileException(filename);
static std::string extension(const std::string &filename)
Get the extension of a file.
Definition file_info.h:257