18 #ifndef PIC_IO_PFM_HPP 19 #define PIC_IO_PFM_HPP 24 #include "../base.hpp" 39 unsigned char *c_v = (
unsigned char*) &value;
40 unsigned char *c_r = (
unsigned char*) &ret;
60 int &height,
int &channel)
62 FILE *file = fopen(nameFile.c_str(),
"rb");
98 fscanf(file,
"%d %d%c", &width, &height, &flagc);
99 fscanf(file,
"%f%c", &flag, &flagc);
102 data =
new float[width * height * channel];
108 for(
int i = height - 1; i > -1; i--) {
111 for(
int j = 0; j < width; j++) {
112 int tmpInd = (ind + j) * channel;
114 fread(&data[tmpInd],
sizeof(
float), channel, file);
120 for(
int i = height - 1; i > -1; i--) {
123 for(
int j = 0; j < width; j++) {
124 int tmpInd = (ind + j) * channel;
126 fread(&data[tmpInd],
sizeof(
float), channel, file);
128 for(
int k = 0; k < channel; k++) {
149 int height,
int channels = 3)
151 if((data == NULL) || (height < 1) || (width < 1) || (channels < 1)) {
155 FILE *file = fopen(nameFile.c_str(),
"wb");
173 fprintf(file,
"%d %d", width, height);
177 fprintf(file,
"%f", -1.0f);
189 for(
int i = height - 1; i > -1; i--) {
192 for(
int j = 0; j < width; j++) {
193 int tmpInd = (ind + j) * channels;
195 fwrite(&data[tmpInd],
sizeof(
float), 1, file);
198 fwrite(&data[tmpInd + ind1],
sizeof(
float), 1, file);
199 fwrite(&data[tmpInd + ind2],
sizeof(
float), 1, file);
PIC_INLINE float convertFloatEndianess(float value)
convertFloatEndianess converts a float from little-endian to big-endian or viceversa.
Definition: pfm.hpp:35
#define PIC_INLINE
Definition: base.hpp:33
PIC_INLINE bool WritePFM(std::string nameFile, float *data, int width, int height, int channels=3)
WritePFM writes an HDR image in the portable float map format into a file.
Definition: pfm.hpp:148
PIC_INLINE float * ReadPFM(std::string nameFile, float *data, int &width, int &height, int &channel)
ReadPFM loads a portable float map from a file.
Definition: pfm.hpp:59
Definition: bilateral_separation.hpp:25