File header
IBRraw.xdr
@@FileBaseName = orange_05_1
@@FileID = IBRraw
@@ImageDim = 2
@@ImageSize = 128 200
@@buffer-channels-0 = 3
@@buffer-primtype-0 = float
@@buffer-type-0 = color
---end-of-header---
Following the header is the image data.
Sample code for reading an IBRraw file
void read_IBRraw_float(const char *filename, int *width, int *height, float **buf) {
FILE *f=fopen(filename, "rb");
if(f==NULL){
perror("Error opening file");
}
string line;
// read signature "IBRraw"
line = GetLine(f);
assert(line.substr(0,6) == "IBRraw");
bool use_xdr = (line.substr(0,10) == "IBRraw.xdr");
// read all parameters until end-of-header marker
bool end_of_header=false;
do {
line = GetLine(f);
end_of_header = line.substr(0,IBR_FFRAW_EOH.size()) == IBR_FFRAW_EOH;
if(!end_of_header) {
if(line.substr(2, IBR_FFRAW_SIZE.size()) == IBR_FFRAW_SIZE){
sscanf(line.c_str(), "%d %d",&width, &height);
}
}
} while(!feof(f) && !end_of_header);
//allocate space
int w=(*width);
int h=(*height);
(*buf) = new float[w*h*3];
//read data
fread((*buf),sizeof(float),w*h*3,f);
if(use_xdr) {
ntohl_buf(w*h*3, (uint32 *)(*buf) );
}
fclose(f);
}
No comments:
Post a Comment