#include "cvd/internal/io/fits.h" #include "cvd/image_io.h" #include "cvd_src/config_internal.h" #include #include #include #include #include using namespace CVD; using namespace CVD::FITS; using namespace CVD::Exceptions::Image_IO; using namespace std; //////////////////////////////////////////////////////////////////////////////// // // Private implementation of FITS reading // //////////////////////////////////////////////////////////////////////////////// // // Useful string manipulation functions // //Trim off whitespace on the right hand side static string rtrim(string str) { string ws(" \t\f\v\n\r"); size_t pos; pos = str.find_last_not_of(ws); if(pos != string::npos) str.erase(pos + 1); else str.clear(); return str; } //Trim off whitespace on the left hand side static string ltrim(const string& str) { string ws(" \t\f\v\n\r"); size_t pos; pos = str.find_first_not_of(ws); if(pos != string::npos) return string(str.begin() + pos, str.end()); else return ""; } static int get_int(const string& s) { int i; istringstream is(s); is >> i; if(s.size() == 0 || is.bad()) throw(Exceptions::Image_IO::MalformedImage("Invalid integer: `" + s + "'")); return i; } static int get_uint(const string& s) { unsigned int i; istringstream is(s); is >> i; if(s.size() == 0 || is.bad()) throw(Exceptions::Image_IO::MalformedImage("Invalid unsigned integer: `" + s + "'")); return i; } static double get_double(const string& s) { double i; istringstream is(s); is >> i; if(s.size() == 0 || is.bad()) throw(Exceptions::Image_IO::MalformedImage("Invalid double: `" + s + "'")); return i; } //////////////////////////////////////////////////////////////////////////////// // // Private implementation of FITS reading // class CVD::FITS::ReadPimpl { public: ReadPimpl(istream&); ~ReadPimpl(); ImageRef size(); string datatype(); template void get_raw_pixel_line(C* data); template void convert_raw_pixel_line(unsigned char*, C* data); template