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
00031 namespace ost { namespace io { namespace detail {
00033 typedef void (*TIFFWarningHandler)(const char*, const char*, va_list);
00034
00036 void tiff_warning_handler(const char *mod, const char* fmt, va_list ap);
00037
00039 struct tiff_warning_handler_wrapper {
00040 tiff_warning_handler_wrapper() {
00041 handler_ = TIFFSetWarningHandler(tiff_warning_handler);
00042 }
00043
00044 ~tiff_warning_handler_wrapper() {
00045 TIFFSetWarningHandler(handler_);
00046 }
00047
00048 TIFFWarningHandler handler_;
00049 };
00050
00052 class complexint32_t:public std::complex<int32_t>{
00053 public:
00054
00055 operator std::complex<Real>()
00056 {
00057 return std::complex<Real>(real(),imag());
00058 }
00059 };
00060
00062 class complexint16:public std::complex<int16>{
00063 public:
00064
00065 operator std::complex<Real>()
00066 {
00067 return std::complex<Real>(real(),imag());
00068 }
00069 };
00070
00072 class complexint8:public std::complex<int8>{
00073 public:
00074
00075 operator std::complex<Real>()
00076 {
00077 return std::complex<Real>(real(),imag());
00078 }
00079 };
00080
00082 int32_t CustomTIFFReadProcIStream(void* thandle, void* tdata, int32_t tsize);
00084 int32_t CustomTIFFReadProcIStream(void* thandle, void* tdata, int32_t tsize);
00086 int32_t CustomTIFFReadProcOStream(void* thandle, void* tdata, int32_t tsize);
00088 int32_t CustomTIFFWriteProcIStream(void* thandle, void* tdata, int32_t tsize);
00090 int32_t CustomTIFFWriteProcOStream(void* thandle, void* tdata, int32_t tsize);
00092 uint32_t CustomTIFFSeekProcIStream(void* thandle, uint32_t toff, int dir);
00094 uint32_t CustomTIFFSeekProcOStream(void* thandle, uint32_t toff, int dir);
00096 int CustomTIFFCloseProc(void* thandle);
00098 uint32_t CustomTIFFSizeProcIStream(void* thandle);
00100 uint32_t CustomTIFFSizeProcOStream(void* thandle);
00102 int CustomTIFFMapFileProc(void* thandle, void** tdata, uint32* toff);
00104 void CustomTIFFUnmapFileProc(void* thandle, void* tdata, uint32 toff);
00105
00107 template<typename IN_TYPE,typename OUT_TYPE, class IST>
00108 void do_tiff_read(tdata_t buf,uint16 rps, uint32_t width, IST* is,int& current_row, int spp)
00109 {
00110 IN_TYPE* dp = static_cast<IN_TYPE*>(buf);
00111 for(uint r=0;r<rps;r++) {
00112 for(uint c=0;c<width;c++) {
00113 is->Value(img::Point(c,current_row))=static_cast<OUT_TYPE>(dp[(r*width+c)*spp]);
00114 }
00115 current_row++;
00116 }
00117 }
00118
00120 template<typename IN_TYPE,typename OUT_TYPE, class IST>
00121 void do_tiff_write(TIFF *tif, IST* is,uint32_t rowsperstrip,uint32_t width,uint32_t height, uint32_t strip,const img::NormalizerPtr& nptr)
00122 {
00123 uint datalength=rowsperstrip*width;
00124 if((strip+1)*rowsperstrip>height){
00125 datalength=(height-strip*rowsperstrip)*width;
00126 }
00127 OUT_TYPE* buf=new OUT_TYPE[datalength];
00128 img::Point start = is->GetExtent().GetStart();
00129
00130 uint i=0;
00131 for(uint r=strip*rowsperstrip;r<(strip+1)*rowsperstrip && r<height;r++) {
00132 for(uint c=0;c<width;c++) {
00133 buf[i] = static_cast<OUT_TYPE>(nptr->Convert(is->Value(img::Point(c,r)+start)));
00134 ++i;
00135 }
00136 }
00137 TIFFWriteEncodedStrip(tif,strip,buf, sizeof(OUT_TYPE)*datalength);
00138 delete[] buf;
00139 }
00140
00141 }}}
00142
00143 #endif // TIFF_HH