Visual Computing Library  devel
Loading...
Searching...
No Matches
load.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_IO_IMAGE_STB_LOAD_H
24#define VCL_IO_IMAGE_STB_LOAD_H
25
26#include <vclib/io/file_info.h>
27
28// disable deprecated warnings - just for stb
29#if defined(__clang__)
30#pragma clang diagnostic push
31#pragma clang diagnostic ignored "-Wdeprecated-declarations"
32#endif
33
34#include <stb_image.h>
35
36#if defined(__clang__)
37#pragma clang diagnostic pop
38#endif
39
40#include <memory>
41#include <set>
42#include <string>
43
44namespace vcl::stb {
45
46inline std::set<FileFormat> loadImageFormats()
47{
48 return {
49 FileFormat("png", "Portable Network Graphics"),
50 FileFormat("bmp", "Bitmap"),
51 FileFormat("tga", "Truevision TGA"),
52 FileFormat(
53 std::vector<std::string> {"jpg", "jpeg"},
54 "Joint Photographic Experts Group"),
55 };
56}
57
58inline std::shared_ptr<unsigned char> loadImageData(
59 const std::string& filename,
60 int& w,
61 int& h)
62{
63 std::shared_ptr<unsigned char> ptr(
64 stbi_load(filename.c_str(), &w, &h, nullptr, 4), stbi_image_free);
65 return ptr;
66}
67
68} // namespace vcl::stb
69
70#endif // VCL_IO_IMAGE_STB_LOAD_H