20 #ifndef OST_IMG_IO_TIFF_HH
21 #define OST_IMG_IO_TIFF_HH
26 #include <boost/filesystem.hpp>
30 namespace ost {
namespace io {
namespace detail {
38 struct tiff_warning_handler_wrapper {
51 class complexint32:
public std::complex<int32>{
54 operator std::complex<Real>()
56 return std::complex<Real>(real(),imag());
61 class complexint16:
public std::complex<int16>{
64 operator std::complex<Real>()
66 return std::complex<Real>(real(),imag());
71 class complexint8:
public std::complex<int8>{
74 operator std::complex<Real>()
76 return std::complex<Real>(real(),imag());
104 template<
typename IN_TYPE,
typename OUT_TYPE,
class IST>
105 void do_tiff_read(tdata_t buf,
unsigned int rps,
unsigned int width, IST* is,
unsigned int& current_row, uint16 spp)
107 IN_TYPE* dp =
static_cast<IN_TYPE*
>(buf);
108 for(
uint r=0;r<rps;r++) {
109 for(
uint c=0;c<width;c++) {
110 is->Value(
img::Point(c,current_row))=
static_cast<OUT_TYPE
>(dp[(r*width+c)*spp]);
117 template<
typename IN_TYPE,
typename OUT_TYPE,
class IST>
118 void do_tiff_write(TIFF *tif, IST* is,
unsigned int rowsperstrip,
unsigned int width,
unsigned int height,
unsigned int strip,
const img::NormalizerPtr& nptr)
120 uint datalength=rowsperstrip*width;
121 if((strip+1)*rowsperstrip>height){
122 datalength=(height-strip*rowsperstrip)*width;
124 OUT_TYPE* buf=
new OUT_TYPE[datalength];
125 img::Point start = is->GetExtent().GetStart();
128 for(
uint r=strip*rowsperstrip;r<(strip+1)*rowsperstrip && r<height;r++) {
129 for(
uint c=0;c<width;c++) {
130 buf[i] =
static_cast<OUT_TYPE
>(nptr->Convert(is->Value(img::Point(c,r)+start)));
134 TIFFWriteEncodedStrip(tif,strip,buf,
sizeof(OUT_TYPE)*datalength);
~tiff_warning_handler_wrapper()
boost::shared_ptr< NormalizerImpl > NormalizerPtr
TIFFWarningHandler handler_
void do_tiff_read(tdata_t buf, unsigned int rps, unsigned int width, IST *is, unsigned int ¤t_row, uint16 spp)
void(* TIFFWarningHandler)(const char *, const char *, va_list)
tsize_t CustomTIFFWriteProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize)
int CustomTIFFMapFileProc(thandle_t thandle, tdata_t *tdata, toff_t *toff)
tsize_t CustomTIFFReadProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize)
tiff_warning_handler_wrapper()
toff_t CustomTIFFSizeProcIStream(thandle_t thandle)
tsize_t CustomTIFFReadProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize)
toff_t CustomTIFFSeekProcOStream(thandle_t thandle, toff_t toff, int dir)
void tiff_warning_handler(const char *mod, const char *fmt, va_list ap)
toff_t CustomTIFFSeekProcIStream(thandle_t thandle, toff_t toff, int dir)
void do_tiff_write(TIFF *tif, IST *is, unsigned int rowsperstrip, unsigned int width, unsigned int height, unsigned int strip, const img::NormalizerPtr &nptr)
tsize_t CustomTIFFWriteProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize)
class encapsulating 1D to 3D point
int CustomTIFFCloseProc(thandle_t thandle)
void CustomTIFFUnmapFileProc(thandle_t thandle, tdata_t tdata, toff_t toff)
toff_t CustomTIFFSizeProcOStream(thandle_t thandle)