diff --git a/modules/io/pymod/export_map_io.cc b/modules/io/pymod/export_map_io.cc index 4d49dad7f6f2e08de62a1fa39a65146d8cecd7bd..ab195ef2dc25f8323f27f08de82e31b4f8363980 100644 --- a/modules/io/pymod/export_map_io.cc +++ b/modules/io/pymod/export_map_io.cc @@ -112,8 +112,10 @@ void export_map_io() .def("GetEndianessOnSave", &Spider::GetEndianessOnSave) ; - class_<MRC, bases<ImageFormatBase> >("MRC", init<bool,Subformat,Endianess> - ((arg("normalize_on_save") = false,arg("subformat")=MRC_AUTO_FORMAT,arg("endianess_on_save")=OST_LOCAL_ENDIAN))) + class_<MRC, bases<ImageFormatBase> >("MRC", init<bool,Subformat,Endianess,Format> + ((arg("normalize_on_save") = false,arg("subformat")=MRC_AUTO_FORMAT,arg("endianess_on_save")=OST_LOCAL_ENDIAN,arg("format")=OST_DEFAULT_FORMAT))) + .def("SetBitDepth", &MRC::SetBitDepth) + .def("GetBitDepth", &MRC::GetBitDepth) .def("SetNormalizeOnSave", &MRC::SetNormalizeOnSave) .def("GetNormalizeOnSave", &MRC::GetNormalizeOnSave) .def("SetSubformat", &MRC::SetSubformat) @@ -122,8 +124,8 @@ void export_map_io() .def("GetEndianessOnSave", &MRC::GetEndianessOnSave) ; - class_<CCP4, bases<MRC> >("CCP4", init<bool,Endianess> - ((arg("normalize_on_save") = false,arg("endianess_on_save")=OST_LOCAL_ENDIAN))) + class_<CCP4, bases<MRC> >("CCP4", init<bool,Endianess,Format> + ((arg("normalize_on_save") = false,arg("endianess_on_save")=OST_LOCAL_ENDIAN,arg("format")=OST_DEFAULT_FORMAT))) ; class_<DM3, bases<ImageFormatBase> >("DM3", init<>()) diff --git a/modules/io/src/img/map_io_mrc_handler.cc b/modules/io/src/img/map_io_mrc_handler.cc index c80ec39aba853070679aefdfd7b890cd5b876de0..3273a94e4452e00cef82f445951de33222e6c931 100644 --- a/modules/io/src/img/map_io_mrc_handler.cc +++ b/modules/io/src/img/map_io_mrc_handler.cc @@ -94,13 +94,24 @@ namespace ost { namespace io { String MRC::FORMAT_STRING = "defined_mrc"; -MRC::MRC(bool normalize_on_save, Subformat subformat,Endianess endianess_on_save): +MRC::MRC(bool normalize_on_save, Subformat subformat,Endianess endianess_on_save, Format bit_depth): ImageFormatBase(FORMAT_STRING), subformat_(subformat), normalize_on_save_(normalize_on_save), - endianess_on_save_(endianess_on_save) + endianess_on_save_(endianess_on_save), + bit_depth_(bit_depth) { } +Format MRC::GetBitDepth() const +{ + return bit_depth_; +} + +void MRC::SetBitDepth (Format bitdepth) +{ + bit_depth_ = bitdepth; +} + Endianess MRC::GetEndianessOnSave() const { @@ -132,8 +143,8 @@ void MRC::SetNormalizeOnSave(bool normalize_on_save) normalize_on_save_ = normalize_on_save; } -CCP4::CCP4(bool normalize_on_save, Endianess endianess_on_save): - MRC(normalize_on_save,MRC_NEW_FORMAT,endianess_on_save) +CCP4::CCP4(bool normalize_on_save, Endianess endianess_on_save, Format bit_depth): + MRC(normalize_on_save,MRC_NEW_FORMAT,endianess_on_save,bit_depth) {} @@ -223,7 +234,7 @@ public: label[i]=' '; } } - header_base(const img::ConstImageHandle& im): + header_base(const img::ConstImageHandle& im, Format bit_depth): nc(), nr(static_cast<int>(im.GetExtent().GetSize().GetHeight())), ns(static_cast<int>(im.GetExtent().GetSize().GetDepth())), @@ -247,13 +258,38 @@ public: { if(im.GetType()==img::REAL){ nc=static_cast<int>(im.GetExtent().GetSize().GetWidth()); - mode=2; + switch(bit_depth){ + case OST_BIT8_FORMAT: + mode=0; + break; + case OST_BIT16_FORMAT: + mode=1; + break; + case OST_FLOAT_FORMAT: + case OST_DEFAULT_FORMAT: + mode=2; + break; + default: + throw(IOException("MRC/CCP4 export: Bit depth not supported.")); + break; + } x=im.GetExtent().GetSize().GetWidth()*im.GetSpatialSampling()[0]; y=im.GetExtent().GetSize().GetHeight()*im.GetSpatialSampling()[1]; z=im.GetExtent().GetSize().GetDepth()*im.GetSpatialSampling()[2]; }else{ nc=static_cast<int>(im.GetExtent().GetSize().GetWidth()/2 +1); - mode=4; + switch(bit_depth){ + case OST_BIT16_FORMAT: + mode=3; + break; + case OST_FLOAT_FORMAT: + case OST_DEFAULT_FORMAT: + mode=4; + break; + default: + throw(IOException("MRC/CCP4 export: Bit depth not supported.")); + break; + } x=1.0; y=1.0; z=1.0; @@ -342,8 +378,8 @@ public: yorigin(0.0) { } - mrc_header(const img::ConstImageHandle& im): - header_base(im), + mrc_header(const img::ConstImageHandle& im, Format bit_depth): + header_base(im,bit_depth), xorigin(0.0), // todo determine origin yorigin(0.0) { @@ -435,8 +471,8 @@ public: arms() { } - ccp4_header(const img::ConstImageHandle& im): - header_base(im), + ccp4_header(const img::ConstImageHandle& im, Format bit_depth): + header_base(im,bit_depth), lskflag(), skwmat(), skwtrn(), @@ -857,14 +893,39 @@ void export_helper(const img::MapHandle& image, const MRC& formatmrc) { BinaryOStream<CONVERSIONTYPE> f(out); - HEADER header(image); + HEADER header(image,formatmrc.GetBitDepth()); f << header; if(image.GetType()==img::REAL) { - detail::real_dumper<float,CONVERSIONTYPE>(f,header,image,formatmrc); + switch(formatmrc.GetBitDepth()){ + case OST_BIT8_FORMAT: + detail::real_dumper<int8_t,CONVERSIONTYPE>(f,header,image,formatmrc); + break; + case OST_BIT16_FORMAT: + detail::real_dumper<int16_t,CONVERSIONTYPE>(f,header,image,formatmrc); + break; + case OST_FLOAT_FORMAT: + case OST_DEFAULT_FORMAT: + detail::real_dumper<float,CONVERSIONTYPE>(f,header,image,formatmrc); + break; + default: + throw(IOException("MRC/CCP4 export: Bit depth not supported.")); + break; + } } else { if(image.GetDomain()==img::HALF_FREQUENCY){ - detail::complex_dumper<float,CONVERSIONTYPE>(f,header,image,formatmrc); + switch(formatmrc.GetBitDepth()){ + case OST_BIT16_FORMAT: + detail::complex_dumper<int16_t,CONVERSIONTYPE>(f,header,image,formatmrc); + break; + case OST_FLOAT_FORMAT: + case OST_DEFAULT_FORMAT: + detail::complex_dumper<float,CONVERSIONTYPE>(f,header,image,formatmrc); + break; + default: + throw(IOException("MRC/CCP4 export: Bit depth not supported.")); + break; + } } else { throw(IOException("MRC/CCP4 export: full complex export not supported.")); } diff --git a/modules/io/src/img/map_io_mrc_handler.hh b/modules/io/src/img/map_io_mrc_handler.hh index c12096b68ff711366e597118aea85f5e0550fc21..d8e2e9710dfa15eb688bd8594fb055923e3d1c11 100644 --- a/modules/io/src/img/map_io_mrc_handler.hh +++ b/modules/io/src/img/map_io_mrc_handler.hh @@ -28,7 +28,10 @@ class DLLEXPORT_OST_IO MRC: public ImageFormatBase { public: - MRC(bool normalize_on_save = false, Subformat subformat = MRC_AUTO_FORMAT ,Endianess endianness_on_save = OST_LOCAL_ENDIAN); + MRC(bool normalize_on_save = false, Subformat subformat = MRC_AUTO_FORMAT ,Endianess endianness_on_save = OST_LOCAL_ENDIAN, Format bit_depth = OST_DEFAULT_FORMAT); + + Format GetBitDepth() const; + void SetBitDepth ( Format bitdepth); Endianess GetEndianessOnSave() const; void SetEndianessOnSave(Endianess end); @@ -46,12 +49,13 @@ class DLLEXPORT_OST_IO MRC: public ImageFormatBase Subformat subformat_; bool normalize_on_save_; Endianess endianess_on_save_; + Format bit_depth_; }; class DLLEXPORT_OST_IO CCP4: public MRC { public: - CCP4(bool normalize_on_save = false, Endianess endianness_on_save = OST_LOCAL_ENDIAN); + CCP4(bool normalize_on_save = false, Endianess endianness_on_save = OST_LOCAL_ENDIAN, Format bit_depth = OST_DEFAULT_FORMAT); }; typedef CCP4 MAP;