00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef OST_IMG_IO_TIFF_HH
00021 #define OST_IMG_IO_TIFF_HH
00022
00023 #include <ost/stdint.hh>
00024 #include <tiff.h>
00025 #include <tiffio.h>
00026 #include <boost/filesystem.hpp>
00027 #include <ost/img/alg/normalizer_factory.hh>
00028 #include <ost/io/img/image_format.hh>
00029
00030 namespace ost { namespace io { namespace detail {
00032 typedef void (*TIFFWarningHandler)(const char*, const char*, va_list);
00033
00035 void tiff_warning_handler(const char *mod, const char* fmt, va_list ap);
00036
00038 struct tiff_warning_handler_wrapper {
00039 tiff_warning_handler_wrapper() {
00040 handler_ = TIFFSetWarningHandler(tiff_warning_handler);
00041 }
00042
00043 ~tiff_warning_handler_wrapper() {
00044 TIFFSetWarningHandler(handler_);
00045 }
00046
00047 TIFFWarningHandler handler_;
00048 };
00049
00051 class complexint32:public std::complex<int32>{
00052 public:
00053
00054 operator std::complex<Real>()
00055 {
00056 return std::complex<Real>(real(),imag());
00057 }
00058 };
00059
00061 class complexint16:public std::complex<int16>{
00062 public:
00063
00064 operator std::complex<Real>()
00065 {
00066 return std::complex<Real>(real(),imag());
00067 }
00068 };
00069
00071 class complexint8:public std::complex<int8>{
00072 public:
00073
00074 operator std::complex<Real>()
00075 {
00076 return std::complex<Real>(real(),imag());
00077 }
00078 };
00079
00081 tsize_t CustomTIFFReadProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
00083 tsize_t CustomTIFFReadProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
00085 tsize_t CustomTIFFWriteProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
00087 tsize_t CustomTIFFWriteProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
00089 toff_t CustomTIFFSeekProcIStream(thandle_t thandle, toff_t toff, int dir);
00091 toff_t CustomTIFFSeekProcOStream(thandle_t thandle, toff_t toff, int dir);
00093 int CustomTIFFCloseProc(thandle_t thandle);
00095 toff_t CustomTIFFSizeProcIStream(thandle_t thandle);
00097 toff_t CustomTIFFSizeProcOStream(thandle_t thandle);
00099 int CustomTIFFMapFileProc(thandle_t thandle, tdata_t* tdata, toff_t* toff);
00101 void CustomTIFFUnmapFileProc(thandle_t thandle, tdata_t tdata, toff_t toff);
00102
00104 template<typename IN_TYPE,typename OUT_TYPE, class IST>
00105 void do_tiff_read(tdata_t buf,unsigned int rps, unsigned int width, IST* is,unsigned int& current_row, uint16 spp)
00106 {
00107 IN_TYPE* dp = static_cast<IN_TYPE*>(buf);
00108 for(uint r=0;r<rps;r++) {
00109 for(uint c=0;c<width;c++) {
00110 is->Value(img::Point(c,current_row))=static_cast<OUT_TYPE>(dp[(r*width+c)*spp]);
00111 }
00112 current_row++;
00113 }
00114 }
00115
00117 template<typename IN_TYPE,typename OUT_TYPE, class IST>
00118 void do_tiff_write(TIFF *tif, IST* is,unsigned int rowsperstrip,unsigned int width, unsigned int height, unsigned int strip,const img::NormalizerPtr& nptr)
00119 {
00120 uint datalength=rowsperstrip*width;
00121 if((strip+1)*rowsperstrip>height){
00122 datalength=(height-strip*rowsperstrip)*width;
00123 }
00124 OUT_TYPE* buf=new OUT_TYPE[datalength];
00125 img::Point start = is->GetExtent().GetStart();
00126
00127 uint i=0;
00128 for(uint r=strip*rowsperstrip;r<(strip+1)*rowsperstrip && r<height;r++) {
00129 for(uint c=0;c<width;c++) {
00130 buf[i] = static_cast<OUT_TYPE>(nptr->Convert(is->Value(img::Point(c,r)+start)));
00131 ++i;
00132 }
00133 }
00134 TIFFWriteEncodedStrip(tif,strip,buf, sizeof(OUT_TYPE)*datalength);
00135 delete[] buf;
00136 }
00137
00138 }}}
00139
00140 #endif // TIFF_HH