23#ifndef VCL_IO_IMAGE_LOAD_H
24#define VCL_IO_IMAGE_LOAD_H
34#include <vclib/io/file_format.h>
35#include <vclib/io/file_info.h>
37#include <vclib/mesh.h>
38#include <vclib/space/core.h>
54inline std::set<FileFormat> loadImageFormats()
56 std::set<FileFormat> ff;
59 auto fqt = qt::loadImageFormats();
60 ff.insert(fqt.begin(), fqt.end());
64 auto fstb = stb::loadImageFormats();
65 ff.insert(fstb.begin(), fstb.end());
70inline std::shared_ptr<unsigned char> loadImageData(
71 const std::string& filename,
78 if (qt::loadImageFormats().contains(ff)) {
79 return qt::loadImageData(filename, w, h);
84 if (stb::loadImageFormats().contains(ff)) {
85 return stb::loadImageData(filename, w, h);
88 throw UnknownFileFormatException(ff.extensions().front());
91inline Image loadImage(
const std::string& filename)
94 auto data = loadImageData(filename, w, h);
98 return Image(data.get(), w, h);
116template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
117void loadTextureImages(
119 std::string basePath =
"",
121 LogType& log =
nullLogger)
requires HasMaterials<MeshType>
123 if (basePath.empty()) {
124 basePath = mesh.meshBasePath();
127 for (
const Material& mat : mesh.materials()) {
129 const uint N_TEXTURE_TYPES = toUnderlying(COUNT);
130 for (uint i = 0; i < N_TEXTURE_TYPES; ++i) {
133 if (textureTypesToLoad[i]) {
134 const TextureDescriptor& tex = mat.textureDescriptor(i);
137 if (mesh.textureImage(tex.path()).isNull()) {
138 Image img = loadImage(basePath + tex.path());
141 "Cannot load texture " + tex.path(),
142 LogType::WARNING_LOG);
147 mesh.pushTextureImage(tex.path(), std::move(img));
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
static Image::ColorSpace textureTypeToColorSpace(TextureType type)
Determines the appropriate color space for a given texture type.
Definition material.h:375
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