23#ifndef VCL_IO_IMAGE_SAVE_H
24#define VCL_IO_IMAGE_SAVE_H
36#include <vclib/base.h>
37#include <vclib/mesh.h>
38#include <vclib/space/core.h>
52inline std::set<FileFormat> saveImageFormats()
54 std::set<FileFormat> ff;
57 auto fqt = qt::saveImageFormats();
58 ff.insert(fqt.begin(), fqt.end());
62 auto fstb = stb::saveImageFormats();
63 ff.insert(fstb.begin(), fstb.end());
68inline void saveImageData(
69 const std::string& filename,
72 const unsigned char* data,
78 if (qt::saveImageFormats().contains(ff)) {
79 return qt::saveImageData(filename, w, h, data, quality);
83#ifdef VCLIB_WITH_TINYGLTF
84 if (stb::saveImageFormats().contains(ff)) {
85 return stb::saveImageData(filename, w, h, data, quality);
88 if (ff == FileFormat(
"bmp")) {
90 return saveImageToBmp(filename, w, h, data);
92 throw UnknownFileFormatException(ff.extensions().front());
95inline void saveImage(
const Image& image,
const std::string& filename)
97 saveImageData(filename, image.width(), image.height(), image.data());
114template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
115void saveTextureImages(
116 const MeshType& mesh,
117 const std::string& basePath,
119 LogType& log =
nullLogger)
requires HasMaterials<MeshType>
122 std::set<std::string> savedImages;
124 for (
const Material& mat : mesh.materials()) {
126 const uint N_TEXTURE_TYPES = toUnderlying(COUNT);
127 for (uint i = 0; i < N_TEXTURE_TYPES; ++i) {
129 if (textureTypesToSave[i]) {
130 const TextureDescriptor& t = mat.textureDescriptor(i);
131 if (!savedImages.contains(t.path())) {
132 const Image& img = mesh.textureImage(t.path());
133 if (img.isNull() || t.isNull()) {
135 "Cannot save empty texture " + t.path(),
136 LogType::WARNING_LOG);
139 saveImage(img, basePath + t.path());
140 savedImages.insert(t.path());
static constexpr BitSet< T > ALL()
Returns a BitSet with all the bits set to true.
Definition bit_set.h:366
static FileFormat fileFormat(const std::string &filename)
Get the file format of a file from its filename.
Definition file_info.h:280
TextureType
Defines the types of textures used in the PBR material model.
Definition material.h:62
NullLogger nullLogger
The nullLogger object is an object of type NullLogger that is used as default argument in the functio...
Definition null_logger.h:123
BitSet< char > BitSet8
BitSet8 is a BitSet of 8 bits.
Definition bit_set.h:401