From c2c145cf3cbfacff58b3a4e8017ce9eace35ac93 Mon Sep 17 00:00:00 2001 From: Andreas Schenk <andreas_schenk@hms.harvard.edu> Date: Fri, 14 Sep 2012 16:45:06 -0400 Subject: [PATCH] cleaned up chaos done by automatic replacements in tiff io --- modules/io/src/img/map_io_tiff_handler.cc | 44 +++++++++++------------ modules/io/src/img/tiff_util.cc | 34 +++++++++--------- modules/io/src/img/tiff_util.hh | 42 ++++++++-------------- 3 files changed, 52 insertions(+), 68 deletions(-) diff --git a/modules/io/src/img/map_io_tiff_handler.cc b/modules/io/src/img/map_io_tiff_handler.cc index e6144315b..4be8a815e 100644 --- a/modules/io/src/img/map_io_tiff_handler.cc +++ b/modules/io/src/img/map_io_tiff_handler.cc @@ -301,12 +301,12 @@ void MapIOTiffHandler::do_export(const img::MapHandle& image,TIFF* tfile,TIF& fo img::image_state::ComplexSpatialImageState *isc = NULL; img::image_state::WordSpatialImageState *isw = NULL; - boost::function<void (TIFF *,img::image_state::RealSpatialImageState*,UINTNN_T,UINTNN_T,UINTNN_T,UINTNN_T,const img::NormalizerPtr& )> fsr; - boost::function<void (TIFF *,img::image_state::ComplexSpatialImageState*,UINTNN_T,UINTNN_T,UINTNN_T,UINTNN_T,const img::NormalizerPtr&)> fsc; - boost::function<void (TIFF *,img::image_state::WordSpatialImageState*,UINTNN_T,UINTNN_T,UINTNN_T,UINTNN_T,const img::NormalizerPtr&)> fsw; + boost::function<void (TIFF *,img::image_state::RealSpatialImageState*,unsigned int,unsigned int,unsigned int,unsigned int,const img::NormalizerPtr& )> fsr; + boost::function<void (TIFF *,img::image_state::ComplexSpatialImageState*,unsigned int,unsigned int,unsigned int,unsigned int,const img::NormalizerPtr&)> fsc; + boost::function<void (TIFF *,img::image_state::WordSpatialImageState*,unsigned int,unsigned int,unsigned int,unsigned int,const img::NormalizerPtr&)> fsw; - UINTNN_T width=image.GetSize().GetWidth(); - UINTNN_T height=image.GetSize().GetHeight(); + unsigned int width=image.GetSize().GetWidth(); + unsigned int height=image.GetSize().GetHeight(); uint16 spp=1; uint16 fmt =0; uint16 bpp =0 ; @@ -344,7 +344,7 @@ void MapIOTiffHandler::do_export(const img::MapHandle& image,TIFF* tfile,TIF& fo case OST_BIT32_FORMAT: fmt=SAMPLEFORMAT_INT; bpp=32; - fsr=detail::do_tiff_write<Real,INTNN_T,img::image_state::RealSpatialImageState>; + fsr=detail::do_tiff_write<Real,int32,img::image_state::RealSpatialImageState>; break; case OST_FLOAT_FORMAT: fmt=SAMPLEFORMAT_IEEEFP; @@ -377,7 +377,7 @@ void MapIOTiffHandler::do_export(const img::MapHandle& image,TIFF* tfile,TIF& fo case OST_BIT32_FORMAT: fmt=SAMPLEFORMAT_UINT; bpp=32; - fsr=detail::do_tiff_write<Real,UINTNN_T,img::image_state::RealSpatialImageState>; + fsr=detail::do_tiff_write<Real,uint32,img::image_state::RealSpatialImageState>; break; case OST_FLOAT_FORMAT: fmt=SAMPLEFORMAT_IEEEFP; @@ -412,7 +412,7 @@ void MapIOTiffHandler::do_export(const img::MapHandle& image,TIFF* tfile,TIF& fo case OST_BIT32_FORMAT: fmt=SAMPLEFORMAT_COMPLEXINT; bpp=64; - fsc=detail::do_tiff_write<Complex,std::complex<INTNN_T>,img::image_state::ComplexSpatialImageState>; + fsc=detail::do_tiff_write<Complex,std::complex<int32>,img::image_state::ComplexSpatialImageState>; break; case OST_FLOAT_FORMAT: fmt=SAMPLEFORMAT_COMPLEXIEEEFP; @@ -438,7 +438,7 @@ void MapIOTiffHandler::do_export(const img::MapHandle& image,TIFF* tfile,TIF& fo } TIFFSetField(tfile,TIFFTAG_BITSPERSAMPLE,bpp); - UINTNN_T rowsperstrip=std::max<int>(1,8192/(width*bpp/8)); //ca. 8 kb per strip (adobe tiff specs recomendation) + unsigned int rowsperstrip=std::max<int>(1,8192/(width*bpp/8)); //ca. 8 kb per strip (adobe tiff specs recomendation) TIFFSetField(tfile,TIFFTAG_ROWSPERSTRIP,rowsperstrip); TIFFSetField(tfile,TIFFTAG_SAMPLEFORMAT,fmt); unsigned int stripcount=static_cast<int>(ceil( height/static_cast<Real>(rowsperstrip))); @@ -551,9 +551,8 @@ TIFF* MapIOTiffHandler::open_subimage_stream(std::istream& location,const TIF& f void MapIOTiffHandler::load_image_data(TIFF* tfile, img::ImageHandle& image, const TIF& formattif) { - UINTNN_T width,height,rps; + unsigned int width,height,rps; uint16 bpp,spp,plc,ori,reso=RESUNIT_NONE,fmt=SAMPLEFORMAT_UINT; - UINTNN_T* sbc; float xpos=0.0,ypos=0.0; float xreso=1.0,yreso=1.0; @@ -563,7 +562,6 @@ void MapIOTiffHandler::load_image_data(TIFF* tfile, img::ImageHandle& image, co if(!TIFFGetField(tfile,TIFFTAG_SAMPLESPERPIXEL,&spp)) { spp=0; } - TIFFGetField(tfile,TIFFTAG_STRIPBYTECOUNTS, &sbc); TIFFGetField(tfile,TIFFTAG_PLANARCONFIG,&plc); if(!TIFFGetField(tfile,TIFFTAG_ORIENTATION,&ori)) { ori=0; @@ -639,7 +637,7 @@ void MapIOTiffHandler::load_image_data(TIFF* tfile, img::ImageHandle& image, co throw IOException("unexpected failure of dynamic_cast in tiff io"); } - int current_row = 0; + unsigned int current_row = 0; LOG_VERBOSE("I/O Tiff: " << "importing data"); img::Progress::Instance().Register(this,stripcount,100); @@ -647,14 +645,14 @@ void MapIOTiffHandler::load_image_data(TIFF* tfile, img::ImageHandle& image, co int cread=TIFFReadEncodedStrip(tfile, strip, buf, (tsize_t) -1); if(bpp==8) { - int rowcount = cread/(width*spp); - detail::do_tiff_read<uchar,short,img::image_state::WordSpatialImageState>(buf,rowcount,width,is,current_row,spp); + int rowcount = cread/(width*spp); + detail::do_tiff_read<uchar,short,img::image_state::WordSpatialImageState>(buf,rowcount,width,is,current_row,spp); } else if(bpp==16) { - uint rowcount = cread/(width*2*spp); - detail::do_tiff_read<uint16,short,img::image_state::WordSpatialImageState>(buf,rowcount,width,is,current_row,spp); + uint rowcount = cread/(width*2*spp); + detail::do_tiff_read<uint16,short,img::image_state::WordSpatialImageState>(buf,rowcount,width,is,current_row,spp); } else if(bpp==32) { - uint rowcount = cread/(width*4*spp); - detail::do_tiff_read<UINTNN_T,short,img::image_state::WordSpatialImageState>(buf,rowcount,width,is,current_row,spp); + uint rowcount = cread/(width*4*spp); + detail::do_tiff_read<uint32,short,img::image_state::WordSpatialImageState>(buf,rowcount,width,is,current_row,spp); } img::Progress::Instance().AdvanceProgress(this); } @@ -694,7 +692,7 @@ void MapIOTiffHandler::load_image_data(TIFF* tfile, img::ImageHandle& image, co } - int current_row = 0; + unsigned int current_row = 0; LOG_VERBOSE("I/O Tiff: " << "importing data"); img::Progress::Instance().Register(this,stripcount,100); @@ -728,9 +726,9 @@ void MapIOTiffHandler::load_image_data(TIFF* tfile, img::ImageHandle& image, co } else if(bpp==32) { uint rowcount = cread/(width*4*spp); if(fmt==SAMPLEFORMAT_INT){ - detail::do_tiff_read<INTNN_T,Real,img::image_state::RealSpatialImageState>(buf,rowcount,width,isr,current_row,spp); + detail::do_tiff_read<int32,Real,img::image_state::RealSpatialImageState>(buf,rowcount,width,isr,current_row,spp); }else if(fmt==SAMPLEFORMAT_UINT){ - detail::do_tiff_read<UINTNN_T,Real,img::image_state::RealSpatialImageState>(buf,rowcount,width,isr,current_row,spp); + detail::do_tiff_read<uint32,Real,img::image_state::RealSpatialImageState>(buf,rowcount,width,isr,current_row,spp); }else if(fmt==SAMPLEFORMAT_IEEEFP){ detail::do_tiff_read<float,Real,img::image_state::RealSpatialImageState>(buf,rowcount,width,isr,current_row,spp); }else if(fmt==SAMPLEFORMAT_COMPLEXINT){ @@ -745,7 +743,7 @@ void MapIOTiffHandler::load_image_data(TIFF* tfile, img::ImageHandle& image, co if(fmt==SAMPLEFORMAT_IEEEFP){ detail::do_tiff_read<Real,Real,img::image_state::RealSpatialImageState>(buf,rowcount,width,isr,current_row,spp); }else if(fmt==SAMPLEFORMAT_COMPLEXINT){ - detail::do_tiff_read<detail::COMPLEXINTNN_T,Complex,img::image_state::ComplexSpatialImageState>(buf,rowcount,width,isc,current_row,spp); + detail::do_tiff_read<detail::complexint32,Complex,img::image_state::ComplexSpatialImageState>(buf,rowcount,width,isc,current_row,spp); }else if(fmt==SAMPLEFORMAT_COMPLEXIEEEFP){ detail::do_tiff_read<std::complex<float>,Complex,img::image_state::ComplexSpatialImageState>(buf,rowcount,width,isc,current_row,spp); }else{ diff --git a/modules/io/src/img/tiff_util.cc b/modules/io/src/img/tiff_util.cc index 105ebf73b..053f17976 100644 --- a/modules/io/src/img/tiff_util.cc +++ b/modules/io/src/img/tiff_util.cc @@ -41,7 +41,7 @@ void tiff_warning_handler(const char *mod, const char* fmt, va_list ap) LOG_INFO(mod << ": " << message); } -INTNN_T CustomTIFFReadProcIStream(void* thandle, void* tdata, INTNN_T tsize) +tsize_t CustomTIFFReadProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize) { std::istream* file= reinterpret_cast<std::istream*>(thandle); char* data= reinterpret_cast<char*>(tdata); @@ -49,29 +49,29 @@ INTNN_T CustomTIFFReadProcIStream(void* thandle, void* tdata, INTNN_T tsize) return file->gcount(); } -INTNN_T CustomTIFFReadProcOStream(void* thandle, void* tdata, INTNN_T tsize) +tsize_t CustomTIFFReadProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize) { assert(false); return -1; } -INTNN_T CustomTIFFWriteProcIStream(void* thandle, void* tdata, INTNN_T tsize) +tsize_t CustomTIFFWriteProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize) { assert(false); return -1; } -INTNN_T CustomTIFFWriteProcOStream(void* thandle, void* tdata, INTNN_T tsize) +tsize_t CustomTIFFWriteProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize) { std::ostream* file= reinterpret_cast<std::ostream*>(thandle); char* data= reinterpret_cast<char*>(tdata); - INTNN_T before = file->tellp(); + tsize_t before = file->tellp(); file->write(data,tsize); - INTNN_T after = file->tellp(); + tsize_t after = file->tellp(); return after-before; } -UINTNN_T CustomTIFFSeekProcIStream(void* thandle, UINTNN_T toff, int dir) +toff_t CustomTIFFSeekProcIStream(thandle_t thandle, toff_t toff, int dir) { std::istream* stream= reinterpret_cast<std::istream*>(thandle); @@ -89,7 +89,7 @@ UINTNN_T CustomTIFFSeekProcIStream(void* thandle, UINTNN_T toff, int dir) return stream->rdstate(); } -UINTNN_T CustomTIFFSeekProcOStream(void* thandle, UINTNN_T toff, int dir) +toff_t CustomTIFFSeekProcOStream(thandle_t thandle, toff_t toff, int dir) { std::ostream* stream= reinterpret_cast<std::ostream*>(thandle); @@ -106,38 +106,38 @@ UINTNN_T CustomTIFFSeekProcOStream(void* thandle, UINTNN_T toff, int dir) return stream->rdstate(); } -int CustomTIFFCloseProc(void* thandle) +int CustomTIFFCloseProc(thandle_t thandle) { return 0; } -UINTNN_T CustomTIFFSizeProcIStream(void* thandle) +toff_t CustomTIFFSizeProcIStream(thandle_t thandle) { std::istream* stream= reinterpret_cast<std::istream*>(thandle); - UINTNN_T curr_pos = stream->tellg(); + toff_t curr_pos = stream->tellg(); stream->seekg(0,std::ios::end); - UINTNN_T size = stream->tellg(); + toff_t size = stream->tellg(); stream->seekg(curr_pos,std::ios::beg); return size; } -UINTNN_T CustomTIFFSizeProcOStream(void* thandle) +toff_t CustomTIFFSizeProcOStream(thandle_t thandle) { std::ostream* stream= reinterpret_cast<std::ostream*>(thandle); - UINTNN_T curr_pos = stream->tellp(); + toff_t curr_pos = stream->tellp(); stream->seekp(0,std::ios::end); - UINTNN_T size = stream->tellp(); + toff_t size = stream->tellp(); stream->seekp(curr_pos,std::ios::beg); return size; } -int CustomTIFFMapFileProc(void* thandle, void** tdata, UINTNN* toff) +int CustomTIFFMapFileProc(thandle_t thandle, tdata_t* tdata, toff_t* toff) { assert(false); return(0); } -void CustomTIFFUnmapFileProc(void* thandle, void* tdata, UINTNN toff) +void CustomTIFFUnmapFileProc(thandle_t thandle, tdata_t tdata, toff_t toff) { assert(false); } diff --git a/modules/io/src/img/tiff_util.hh b/modules/io/src/img/tiff_util.hh index b2aca3386..76de383f7 100644 --- a/modules/io/src/img/tiff_util.hh +++ b/modules/io/src/img/tiff_util.hh @@ -27,18 +27,6 @@ #include <ost/img/alg/normalizer_factory.hh> #include <ost/io/img/image_format.hh> -#if defined(TIFFLIB_VERSION) && TIFFLIB_VERSION >= 20111221 -# define INTNN_T int64_t -# define UINTNN uint64 -# define UINTNN_T uint64_t -# define COMPLEXINTNN_T complexint64_t -#else -# define INTNN_T int32_t -# define UINTNN uint32 -# define UINTNN_T uint32_t -# define COMPLEXINTNN_T complexint32_t -#endif - namespace ost { namespace io { namespace detail { /// \internal typedef void (*TIFFWarningHandler)(const char*, const char*, va_list); @@ -60,7 +48,7 @@ struct tiff_warning_handler_wrapper { }; /// \internal -class COMPLEXINTNN_T:public std::complex<INTNN_T>{ +class complexint32:public std::complex<int32>{ public: operator std::complex<Real>() @@ -90,33 +78,31 @@ public: }; /// \internal -INTNN_T CustomTIFFReadProcIStream(void* thandle, void* tdata, INTNN_T tsize); -/// \internal -INTNN_T CustomTIFFReadProcIStream(void* thandle, void* tdata, INTNN_T tsize); +tsize_t CustomTIFFReadProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize); /// \internal -INTNN_T CustomTIFFReadProcOStream(void* thandle, void* tdata, INTNN_T tsize); +tsize_t CustomTIFFReadProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize); /// \internal -INTNN_T CustomTIFFWriteProcIStream(void* thandle, void* tdata, INTNN_T tsize); +tsize_t CustomTIFFWriteProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize); /// \internal -INTNN_T CustomTIFFWriteProcOStream(void* thandle, void* tdata, INTNN_T tsize); +tsize_t CustomTIFFWriteProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize); /// \internal -UINTNN_T CustomTIFFSeekProcIStream(void* thandle, UINTNN_T toff, int dir); +toff_t CustomTIFFSeekProcIStream(thandle_t thandle, toff_t toff, int dir); /// \internal -UINTNN_T CustomTIFFSeekProcOStream(void* thandle, UINTNN_T toff, int dir); +toff_t CustomTIFFSeekProcOStream(thandle_t thandle, toff_t toff, int dir); /// \internal -int CustomTIFFCloseProc(void* thandle); +int CustomTIFFCloseProc(thandle_t thandle); /// \internal -UINTNN_T CustomTIFFSizeProcIStream(void* thandle); +toff_t CustomTIFFSizeProcIStream(thandle_t thandle); /// \internal -UINTNN_T CustomTIFFSizeProcOStream(void* thandle); +toff_t CustomTIFFSizeProcOStream(thandle_t thandle); /// \internal -int CustomTIFFMapFileProc(void* thandle, void** tdata, UINTNN* toff); +int CustomTIFFMapFileProc(thandle_t thandle, tdata_t* tdata, toff_t* toff); /// \internal -void CustomTIFFUnmapFileProc(void* thandle, void* tdata, UINTNN toff); +void CustomTIFFUnmapFileProc(thandle_t thandle, tdata_t tdata, toff_t toff); /// \internal template<typename IN_TYPE,typename OUT_TYPE, class IST> -void do_tiff_read(tdata_t buf,uint16 rps, UINTNN_T width, IST* is,int& current_row, int spp) +void do_tiff_read(tdata_t buf,unsigned int rps, unsigned int width, IST* is,unsigned int& current_row, uint16 spp) { IN_TYPE* dp = static_cast<IN_TYPE*>(buf); for(uint r=0;r<rps;r++) { @@ -129,7 +115,7 @@ void do_tiff_read(tdata_t buf,uint16 rps, UINTNN_T width, IST* is,int& current_r /// \internal template<typename IN_TYPE,typename OUT_TYPE, class IST> -void do_tiff_write(TIFF *tif, IST* is,UINTNN_T rowsperstrip,UINTNN_T width,UINTNN_T height, UINTNN_T strip,const img::NormalizerPtr& nptr) +void do_tiff_write(TIFF *tif, IST* is,unsigned int rowsperstrip,unsigned int width, unsigned int height, unsigned int strip,const img::NormalizerPtr& nptr) { uint datalength=rowsperstrip*width; if((strip+1)*rowsperstrip>height){ -- GitLab