OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
tiff_util.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 // Copyright (C) 2003-2010 by the IPLT authors
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 3.0 of the License, or (at your option)
10 // any later version.
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //------------------------------------------------------------------------------
20 #ifndef OST_IMG_IO_TIFF_HH
21 #define OST_IMG_IO_TIFF_HH
22 
23 #include <ost/stdint.hh>
24 #include <tiff.h>
25 #include <tiffio.h>
26 #include <boost/filesystem.hpp>
29 
30 
31 namespace ost { namespace io { namespace detail {
33 typedef void (*TIFFWarningHandler)(const char*, const char*, va_list);
34 
36 void tiff_warning_handler(const char *mod, const char* fmt, va_list ap);
37 
39 struct tiff_warning_handler_wrapper {
41  handler_ = TIFFSetWarningHandler(tiff_warning_handler);
42  }
43 
45  TIFFSetWarningHandler(handler_);
46  }
47 
49 };
50 
52 class complexint32:public std::complex<int32_t>{
53 public:
54 
55  operator std::complex<Real>()
56  {
57  return std::complex<Real>(real(),imag());
58  }
59 };
60 
62 class complexint16:public std::complex<int16_t>{
63 public:
64 
65  operator std::complex<Real>()
66  {
67  return std::complex<Real>(real(),imag());
68  }
69 };
70 
72 class complexint8:public std::complex<int8_t>{
73 public:
74 
75  operator std::complex<Real>()
76  {
77  return std::complex<Real>(real(),imag());
78  }
79 };
80 
82 tsize_t CustomTIFFReadProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
84 tsize_t CustomTIFFReadProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
86 tsize_t CustomTIFFWriteProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
88 tsize_t CustomTIFFWriteProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
90 toff_t CustomTIFFSeekProcIStream(thandle_t thandle, toff_t toff, int dir);
92 toff_t CustomTIFFSeekProcOStream(thandle_t thandle, toff_t toff, int dir);
94 int CustomTIFFCloseProc(thandle_t thandle);
96 toff_t CustomTIFFSizeProcIStream(thandle_t thandle);
98 toff_t CustomTIFFSizeProcOStream(thandle_t thandle);
100 int CustomTIFFMapFileProc(thandle_t thandle, tdata_t* tdata, toff_t* toff);
102 void CustomTIFFUnmapFileProc(thandle_t thandle, tdata_t tdata, toff_t toff);
103 
105 template<typename IN_TYPE,typename OUT_TYPE, class IST>
106 void do_tiff_read(tdata_t buf,unsigned int rps, unsigned int width, IST* is,unsigned int& current_row, uint16_t spp)
107 {
108  IN_TYPE* dp = static_cast<IN_TYPE*>(buf);
109  for(uint r=0;r<rps;r++) {
110  for(uint c=0;c<width;c++) {
111  is->Value(img::Point(c,current_row))=static_cast<OUT_TYPE>(dp[(r*width+c)*spp]);
112  }
113  current_row++;
114  }
115 }
116 
118 template<typename IN_TYPE,typename OUT_TYPE, class IST>
119 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 {
121  uint datalength=rowsperstrip*width;
122  if((strip+1)*rowsperstrip>height){
123  datalength=(height-strip*rowsperstrip)*width;
124  }
125  OUT_TYPE* buf=new OUT_TYPE[datalength];
126  img::Point start = is->GetExtent().GetStart();
127 
128  uint i=0;
129  for(uint r=strip*rowsperstrip;r<(strip+1)*rowsperstrip && r<height;r++) {
130  for(uint c=0;c<width;c++) {
131  buf[i] = static_cast<OUT_TYPE>(nptr->Convert(is->Value(img::Point(c,r)+start)));
132  ++i;
133  }
134  }
135  TIFFWriteEncodedStrip(tif,strip,buf, sizeof(OUT_TYPE)*datalength);
136  delete[] buf;
137 }
138 
139 }}} // ns
140 
141 #endif // TIFF_HH
boost::shared_ptr< NormalizerImpl > NormalizerPtr
void(* TIFFWarningHandler)(const char *, const char *, va_list)
Definition: tiff_util.hh:33
void do_tiff_read(tdata_t buf, unsigned int rps, unsigned int width, IST *is, unsigned int &current_row, uint16_t spp)
Definition: tiff_util.hh:106
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)
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)
unsigned short uint16_t
Definition: stdint_msc.hh:79
void do_tiff_write(TIFF *tif, IST *is, unsigned int rowsperstrip, unsigned int width, unsigned int height, unsigned int strip, const img::NormalizerPtr &nptr)
Definition: tiff_util.hh:119
tsize_t CustomTIFFWriteProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize)
class encapsulating 1D to 3D point
Definition: point.hh:43
int CustomTIFFCloseProc(thandle_t thandle)
unsigned int uint
Definition: base.hh:29
void CustomTIFFUnmapFileProc(thandle_t thandle, tdata_t tdata, toff_t toff)
toff_t CustomTIFFSizeProcOStream(thandle_t thandle)