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-2011 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 namespace ost { namespace io { namespace detail {
32 typedef void (*TIFFWarningHandler)(const char*, const char*, va_list);
33 
35 void tiff_warning_handler(const char *mod, const char* fmt, va_list ap);
36 
38 struct tiff_warning_handler_wrapper {
40  handler_ = TIFFSetWarningHandler(tiff_warning_handler);
41  }
42 
44  TIFFSetWarningHandler(handler_);
45  }
46 
48 };
49 
51 class complexint32:public std::complex<int32>{
52 public:
53 
54  operator std::complex<Real>()
55  {
56  return std::complex<Real>(real(),imag());
57  }
58 };
59 
61 class complexint16:public std::complex<int16>{
62 public:
63 
64  operator std::complex<Real>()
65  {
66  return std::complex<Real>(real(),imag());
67  }
68 };
69 
71 class complexint8:public std::complex<int8>{
72 public:
73 
74  operator std::complex<Real>()
75  {
76  return std::complex<Real>(real(),imag());
77  }
78 };
79 
81 tsize_t CustomTIFFReadProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
83 tsize_t CustomTIFFReadProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
85 tsize_t CustomTIFFWriteProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
87 tsize_t CustomTIFFWriteProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
89 toff_t CustomTIFFSeekProcIStream(thandle_t thandle, toff_t toff, int dir);
91 toff_t CustomTIFFSeekProcOStream(thandle_t thandle, toff_t toff, int dir);
93 int CustomTIFFCloseProc(thandle_t thandle);
95 toff_t CustomTIFFSizeProcIStream(thandle_t thandle);
97 toff_t CustomTIFFSizeProcOStream(thandle_t thandle);
99 int CustomTIFFMapFileProc(thandle_t thandle, tdata_t* tdata, toff_t* toff);
101 void CustomTIFFUnmapFileProc(thandle_t thandle, tdata_t tdata, toff_t toff);
102 
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)
106 {
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]);
111  }
112  current_row++;
113  }
114 }
115 
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)
119 {
120  uint datalength=rowsperstrip*width;
121  if((strip+1)*rowsperstrip>height){
122  datalength=(height-strip*rowsperstrip)*width;
123  }
124  OUT_TYPE* buf=new OUT_TYPE[datalength];
125  img::Point start = is->GetExtent().GetStart();
126 
127  uint i=0;
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)));
131  ++i;
132  }
133  }
134  TIFFWriteEncodedStrip(tif,strip,buf, sizeof(OUT_TYPE)*datalength);
135  delete[] buf;
136 }
137 
138 }}} // ns
139 
140 #endif // TIFF_HH
boost::shared_ptr< NormalizerImpl > NormalizerPtr
void do_tiff_read(tdata_t buf, unsigned int rps, unsigned int width, IST *is, unsigned int &current_row, uint16 spp)
Definition: tiff_util.hh:105
void(* TIFFWarningHandler)(const char *, const char *, va_list)
Definition: tiff_util.hh:32
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)
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:118
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)