PICCANTE  0.4
The hottest HDR imaging library!
stb.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_IO_STB_HPP
19 #define PIC_IO_STB_HPP
20 
21 #include <stdio.h>
22 #include <string>
23 
24 #include "../base.hpp"
25 
26 
27 #ifndef PIC_DISABLE_STB
28  #define PIC_STB
29 
30  #define STBIWDEF inline
31  #define STB_IMAGE_STATIC
32  #define STB_IMAGE_WRITE_STATIC
33  #define STB_IMAGE_WRITE_IMPLEMENTATION
34  #define STB_IMAGE_IMPLEMENTATION
35 
36 #ifndef PIC_DISABLE_STB_LOCAL
37  #include "../../stb/stb_image_write.h"
38  #include "../../stb/stb_image.h"
39 #else
40  #include <stb/stb_image_write.h>
41  #include <stb/stb_image.h>
42 #endif
43 
44 #endif
45 
46 
47 namespace pic {
48 
57 PIC_INLINE unsigned char *ReadSTB(std::string nameFile, int &width,
58  int &height, int &channels)
59 {
60  unsigned char *data = NULL;
61 
62 #ifndef PIC_DISABLE_STB
63  int w, h, c;
64  stbi_info(nameFile.c_str(), &w, &h, &c);
65  data = stbi_load(nameFile.c_str(), &width, &height, &channels, c);
66 #endif
67 
68  return data;
69 }
70 
80 PIC_INLINE bool WriteSTB(std::string nameFile, unsigned char *data, int width, int height,
81  int channels = 3)
82 {
83  int tmp = 0;
84 
85  #ifndef PIC_DISABLE_STB
86  tmp = stbi_write_png(nameFile.c_str(), width, height, channels, (void*) data, 0);
87  #endif
88 
89  return (tmp == 1);
90 }
91 
92 } // end namespace pic
93 
94 #endif /* PIC_IO_STB_HPP */
95 
PIC_INLINE unsigned char * ReadSTB(std::string nameFile, int &width, int &height, int &channels)
ReadSTB.
Definition: stb.hpp:57
#define PIC_INLINE
Definition: base.hpp:33
Definition: bilateral_separation.hpp:25
PIC_INLINE bool WriteSTB(std::string nameFile, unsigned char *data, int width, int height, int channels=3)
WriteSTB.
Definition: stb.hpp:80