23#ifndef VCL_IO_IMAGE_STB_SAVE_H
24#define VCL_IO_IMAGE_STB_SAVE_H
26#include <vclib/io/exceptions.h>
27#include <vclib/io/file_info.h>
31#pragma clang diagnostic push
32#pragma clang diagnostic ignored "-Wdeprecated-declarations"
35#include <stb_image_write.h>
38#pragma clang diagnostic pop
46inline std::set<FileFormat> saveImageFormats()
49 FileFormat(
"png",
"Portable Network Graphics"),
50 FileFormat(
"bmp",
"Bitmap"),
51 FileFormat(
"tga",
"Truevision TGA"),
53 std::vector<std::string> {
"jpg",
"jpeg"},
54 "Joint Photographic Experts Group"),
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:260