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);