Commit 5d5ce39a33a4782557b6ad61e4c393654d6b36e0
1 parent
2ad0ce4f
Ziqi convert the T * functions to boolean ones
Showing
1 changed file
with
16 additions
and
33 deletions
Show diff stats
envi/binary.h
@@ -79,55 +79,38 @@ public: | @@ -79,55 +79,38 @@ public: | ||
79 | return test_file_size(); | 79 | return test_file_size(); |
80 | } | 80 | } |
81 | 81 | ||
82 | - //DAVE: pass destination pointer as a parameter, make this a boolean function | ||
83 | - T * saveZ(unsigned int page){ | 82 | + //save one band of the file into the memory, and return the pointer |
83 | + bool saveZ( T * p, unsigned int page){ | ||
84 | 84 | ||
85 | - T * p; | ||
86 | - | ||
87 | - if (page > R[2]){ //make sure the bank number is right | 85 | + if (page >= R[2]){ //make sure the bank number is right |
88 | std::cout<<"ERROR: page out of range"<<std::endl; | 86 | std::cout<<"ERROR: page out of range"<<std::endl; |
89 | - return NULL; | 87 | + return false; |
90 | } | 88 | } |
91 | 89 | ||
92 | - //DAVE: don't allocate memory here, do it in main() | ||
93 | - p=(T *)malloc(R[0]*R[1]*sizeof(T)); //memory allocation | ||
94 | - if (p==NULL) | ||
95 | - cout<<"memory allocation failure"; | ||
96 | - | ||
97 | - file.seekg(R[1] * R[0] * page * sizeof(T),ios::beg); //write into memory from the binary file | 90 | + file.seekg(R[1] * R[0] * page * sizeof(T), ios::beg); //write into memory from the binary file |
98 | file.read((char *)p, R[0] * R[1] * sizeof(T)); | 91 | file.read((char *)p, R[0] * R[1] * sizeof(T)); |
99 | 92 | ||
100 | - return p; | 93 | + return true; |
101 | } | 94 | } |
102 | 95 | ||
103 | - //DAVE: same here | ||
104 | - T * saveXY(unsigned x, unsigned y){ | 96 | + //save one pixel of the file into the memory, and return the pointer |
97 | + bool saveXY(T * p, unsigned x, unsigned y){ | ||
105 | 98 | ||
106 | - T * px; | ||
107 | unsigned int i; | 99 | unsigned int i; |
108 | 100 | ||
109 | - if (x<1||x>R[0]||y<1||y>R[1]){ //make sure the sample and line number is right | ||
110 | - cout<<"wrong page"; | ||
111 | - getchar(); | ||
112 | - return NULL; | 101 | + if ( x >= R[0] || y >= R[1]){ //make sure the sample and line number is right |
102 | + std::cout<<"ERROR: sample or line out of range"<<std::endl; | ||
103 | + return false; | ||
113 | } | 104 | } |
114 | 105 | ||
115 | - px=(T *)malloc(R[2]*sizeof(T)); //memory allocation | ||
116 | - if (px==NULL) | ||
117 | - cout<<"memory allocation failure"; | ||
118 | - | ||
119 | - x=x-1; | ||
120 | - y=y-1; | ||
121 | - | ||
122 | - file.seekg((x+y*R[0])*sizeof(T),ios::beg); //point to the certain sample and line | ||
123 | - for (i=0;i<R[2];i++) | 106 | + file.seekg((x + y * R[0]) * sizeof(T), ios::beg); //point to the certain sample and line |
107 | + for (i = 0; i < R[2]; i++) | ||
124 | { | 108 | { |
125 | - file.read((char *)(px+i), sizeof(T)); | ||
126 | - file.seekg((R[1]*R[0]-1)*sizeof(T),ios::cur); //go to the next band | 109 | + file.read((char *)(p + i), sizeof(T)); |
110 | + file.seekg((R[1] * R[0] - 1) * sizeof(T), ios::cur); //go to the next band | ||
127 | } | 111 | } |
128 | 112 | ||
129 | - return px; | ||
130 | - | 113 | + return true; |
131 | } | 114 | } |
132 | 115 | ||
133 | /*bool open(std::string filename, unsigned int X, unsigned int h = 0){ | 116 | /*bool open(std::string filename, unsigned int X, unsigned int h = 0){ |