OpenStructure
Loading...
Searching...
No Matches
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
31namespace ost { namespace io { namespace detail {
33typedef void (*TIFFWarningHandler)(const char*, const char*, va_list);
34
36void tiff_warning_handler(const char *mod, const char* fmt, va_list ap);
37
50
52class complexint32:public std::complex<int32_t>{
53public:
54
55 operator std::complex<Real>()
56 {
57 return std::complex<Real>(real(),imag());
58 }
59};
60
62class complexint16:public std::complex<int16_t>{
63public:
64
65 operator std::complex<Real>()
66 {
67 return std::complex<Real>(real(),imag());
68 }
69};
70
72class complexint8:public std::complex<int8_t>{
73public:
74
75 operator std::complex<Real>()
76 {
77 return std::complex<Real>(real(),imag());
78 }
79};
80
82tsize_t CustomTIFFReadProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
84tsize_t CustomTIFFReadProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
86tsize_t CustomTIFFWriteProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
88tsize_t CustomTIFFWriteProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize);
90toff_t CustomTIFFSeekProcIStream(thandle_t thandle, toff_t toff, int dir);
92toff_t CustomTIFFSeekProcOStream(thandle_t thandle, toff_t toff, int dir);
94int CustomTIFFCloseProc(thandle_t thandle);
96toff_t CustomTIFFSizeProcIStream(thandle_t thandle);
98toff_t CustomTIFFSizeProcOStream(thandle_t thandle);
100int CustomTIFFMapFileProc(thandle_t thandle, tdata_t* tdata, toff_t* toff);
102void CustomTIFFUnmapFileProc(thandle_t thandle, tdata_t tdata, toff_t toff);
103
105template<typename IN_TYPE,typename OUT_TYPE, class IST>
106void 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
118template<typename IN_TYPE,typename OUT_TYPE, class IST>
119void 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
class encapsulating 1D to 3D point
Definition point.hh:47
unsigned int uint
Definition base.hh:29
boost::shared_ptr< NormalizerImpl > NormalizerPtr
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
void(* TIFFWarningHandler)(const char *, const char *, va_list)
Definition tiff_util.hh:33
tsize_t CustomTIFFReadProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize)
int CustomTIFFMapFileProc(thandle_t thandle, tdata_t *tdata, toff_t *toff)
void tiff_warning_handler(const char *mod, const char *fmt, va_list ap)
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
int CustomTIFFCloseProc(thandle_t thandle)
tsize_t CustomTIFFWriteProcIStream(thandle_t thandle, tdata_t tdata, tsize_t tsize)
toff_t CustomTIFFSizeProcOStream(thandle_t thandle)
tsize_t CustomTIFFReadProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize)
void CustomTIFFUnmapFileProc(thandle_t thandle, tdata_t tdata, toff_t toff)
tsize_t CustomTIFFWriteProcOStream(thandle_t thandle, tdata_t tdata, tsize_t tsize)
toff_t CustomTIFFSeekProcOStream(thandle_t thandle, toff_t toff, int dir)
toff_t CustomTIFFSizeProcIStream(thandle_t thandle)
toff_t CustomTIFFSeekProcIStream(thandle_t thandle, toff_t toff, int dir)
Definition base.dox:1
unsigned short uint16_t
Definition stdint_msc.hh:79