-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpfmLoader.cpp
More file actions
81 lines (60 loc) · 1.65 KB
/
pfmLoader.cpp
File metadata and controls
81 lines (60 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <cstdio>
#include <string.h>
#include "pfmLoader.h"
void HDRImage::setSize(int x, int y)
{
if(mSizeX==x && mSizeY==y)
return;
mSizeX = x;
mSizeY = y;
//if (data)
//delete[] data;
data = new COLOR[mSizeX* mSizeY];
}
void HDRImage::loadPfm(const char * filename)
{
char strPF[3];
unsigned int SizeX;
unsigned int SizeY;
float dummy;
int dummyC;
FILE * file = fopen(filename, "rb");
if (file == NULL) {
printf("PFM-File not found!\n");
return;
}
fscanf(file, "%s\n%u %u\n", strPF, &SizeX, &SizeY);
dummyC = fgetc(file);
fscanf(file, "\n%f\n", &dummy);
//DEBUG Ausgabe
printf("Keyword: %s\n",strPF);
printf("Size X: %d\n", SizeX);
printf("Size Y: %d\n", SizeY);
printf("dummy: %f\n", dummy);
// ENDE Debug Ausgabe
this->setSize(SizeX, SizeY);
int result;
int lSize;
lSize = mSizeX*3;
for(int y=mSizeY-1; y>=0; y--)
{
result = fread(data+1+mSizeX*y, sizeof(float), lSize, file);
if (result != lSize) {
printf("Error reading PFM-File. %d Bytes read.\n", result);
}
}
fclose(file);
}
void HDRImage::writePfm(const char * filename)
{
char sizes[256];
FILE * file = fopen(filename, "wb");
fwrite("PF\n",sizeof(char), 3, file);
sprintf(sizes, "%d %d\n", mSizeX, mSizeY);
fwrite(sizes,sizeof(char), strlen(sizes)+1, file);
fwrite("\n",sizeof(char),1, file);
fwrite("-1.000000\n",sizeof(char),10, file);
for(int y=mSizeY-1; y>=0; y--)
fwrite(data+1+mSizeX*y, sizeof(float), mSizeX*3, file);
fclose(file);
}