bsq.h
1.59 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
#include "../envi/envi.h"
#include "../envi/binary.h"
namespace rts{
template <typename T>
class bsq: public binary<T> {
protected:
envi header;
public:
//open a file, given the file and its header's names
bool open(std::string filename, std::string headername){
if (header.load(headername)==false){
std::cout<<"ERROR: unable to load head file"<<std::endl;
return false;
}
binary::open(filename, (header.samples, header.lines, header.bands), header.header_offset);
return true;
}
//save one band of the file into the memory, and return the pointer
bool saveBand( T * p, unsigned int page){
if (page >= header.bands){ //make sure the bank number is right
std::cout<<"ERROR: page out of range"<<std::endl;
return false;
}
file.seekg(header.lines * header.samples * page * sizeof(T), ios::beg); //write into memory from the binary file
file.read((char *)p, header.lines * header.samples * sizeof(T));
return true;
}
//save one pixel of the file into the memory, and return the pointer
bool saveSpectrum(T * p, unsigned x, unsigned y){
unsigned int i;
if ( x >= header.samples || y >= header.lines){ //make sure the sample and line number is right
std::cout<<"ERROR: sample or line out of range"<<std::endl;
return false;
}
file.seekg((x + y * header.samples) * sizeof(T), ios::beg); //point to the certain sample and line
for (i = 0; i < header.bands; i++)
{
file.read((char *)(p + i), sizeof(T));
file.seekg((header.lines * header.samples - 1) * sizeof(T), ios::cur); //go to the next band
}
return true;
}
};
}