From 421219bac35aed6feeb971ebd9b5238acafce6c1 Mon Sep 17 00:00:00 2001 From: heziqi Date: Sat, 27 Sep 2014 06:28:37 +0800 Subject: [PATCH] Ziqi added bip.h and bsq2bip function --- envi/bsq.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+), 0 deletions(-) diff --git a/envi/bsq.h b/envi/bsq.h index 05018b3..39032f0 100644 --- a/envi/bsq.h +++ b/envi/bsq.h @@ -249,6 +249,33 @@ public: return true; } + //convert BSQ file to BIP file and save it + bool bip(std::string outname) + { + unsigned int L = header.bands * sizeof(T); //calculate the number of bytes in a spectrum + + std::ofstream target(outname.c_str(), std::ios::binary); + std::string headername = outname + ".hdr"; + + T * p; //pointer to the current spectrum + p = (T*)malloc(L); + + for ( unsigned i = 0; i < header.lines; i++) + { + for ( unsigned j = 0; j < header.samples; j++ ) + { + getSpectrum(p, j, i); + target.write(reinterpret_cast(p), L); //write spectrum data into target file + } + } + header.interleave = rts::envi::interleaveType::BIP; //change the type of file in header file + header.save(headername); + + free(p); + target.close(); + return true; + } + }; } -- libgit2 0.21.4