Commit 421219bac35aed6feeb971ebd9b5238acafce6c1
1 parent
089d9c81
Ziqi added bip.h and bsq2bip function
Showing
1 changed file
with
27 additions
and
0 deletions
Show diff stats
envi/bsq.h
... | ... | @@ -249,6 +249,33 @@ public: |
249 | 249 | return true; |
250 | 250 | } |
251 | 251 | |
252 | + //convert BSQ file to BIP file and save it | |
253 | + bool bip(std::string outname) | |
254 | + { | |
255 | + unsigned int L = header.bands * sizeof(T); //calculate the number of bytes in a spectrum | |
256 | + | |
257 | + std::ofstream target(outname.c_str(), std::ios::binary); | |
258 | + std::string headername = outname + ".hdr"; | |
259 | + | |
260 | + T * p; //pointer to the current spectrum | |
261 | + p = (T*)malloc(L); | |
262 | + | |
263 | + for ( unsigned i = 0; i < header.lines; i++) | |
264 | + { | |
265 | + for ( unsigned j = 0; j < header.samples; j++ ) | |
266 | + { | |
267 | + getSpectrum(p, j, i); | |
268 | + target.write(reinterpret_cast<const char*>(p), L); //write spectrum data into target file | |
269 | + } | |
270 | + } | |
271 | + header.interleave = rts::envi::interleaveType::BIP; //change the type of file in header file | |
272 | + header.save(headername); | |
273 | + | |
274 | + free(p); | |
275 | + target.close(); | |
276 | + return true; | |
277 | + } | |
278 | + | |
252 | 279 | |
253 | 280 | }; |
254 | 281 | } | ... | ... |