ome-files 0.1.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

TIFF.h
1 /*
2 * #%L
3 * OME-FILES C++ library for image IO.
4 * Copyright © 2006 - 2015 Open Microscopy Environment:
5 * - Massachusetts Institute of Technology
6 * - National Institutes of Health
7 * - University of Dundee
8 * - Board of Regents of the University of Wisconsin-Madison
9 * - Glencoe Software, Inc.
10 * %%
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 * The views and conclusions contained in the software and documentation are
33 * those of the authors and should not be interpreted as representing official
34 * policies, either expressed or implied, of any organization.
35 * #L%
36 */
37
38 #ifndef OME_FILES_TIFF_TIFF_H
39 #define OME_FILES_TIFF_TIFF_H
40
41 #include <string>
42
43 #include <boost/iterator/iterator_facade.hpp>
44
45 #include <ome/files/tiff/Types.h>
46
47 #include <ome/common/filesystem.h>
48
49 #include <ome/compat/cstdint.h>
50 #include <ome/compat/memory.h>
51
52 namespace ome
53 {
54 namespace files
55 {
59 namespace tiff
60 {
61
62 class IFD;
63
67 template<typename Value>
68 class IFDIterator : public boost::iterator_facade<IFDIterator<Value>,
69 ome::compat::shared_ptr<Value>,
70 boost::forward_traversal_tag>
71 {
72 public:
78 IFDIterator():
79 pos()
80 {}
81
89 IFDIterator(ome::compat::shared_ptr<IFD>& ifd):
90 pos(ifd)
91 {}
92
98 template <class OtherValue>
99 IFDIterator(const IFDIterator<OtherValue>& rhs)
100 : pos(rhs.pos) {}
101
102 private:
109 mutable ome::compat::shared_ptr<Value> pos;
110
111 friend class boost::iterator_core_access;
112 template <class> friend class IFDIterator;
113
121 void
122 increment();
123
130 bool
131 equal(IFDIterator const& rhs) const
132 {
133 return this->pos == rhs.pos;
134 }
135
141 ome::compat::shared_ptr<Value>&
142 dereference() const
143 {
144 return pos;
145 }
146 };
147
156 class TIFF : public ome::compat::enable_shared_from_this<TIFF>
157 {
158 private:
159 class Impl;
160 class wrapped_type;
162 ome::compat::shared_ptr<Impl> impl;
163
164 protected:
166 TIFF(const boost::filesystem::path& filename,
167 const std::string& mode);
168
169 private:
171 TIFF (const TIFF&);
172
174 TIFF&
175 operator= (const TIFF&);
176
177 public:
179 ~TIFF();
180
193 static ome::compat::shared_ptr<TIFF>
194 open(const boost::filesystem::path& filename,
195 const std::string& mode);
196
204 void
205 close();
206
213 operator bool ();
214
220 directory_index_type
221 directoryCount() const;
222
231 ome::compat::shared_ptr<IFD>
232 getDirectoryByIndex(directory_index_type index) const;
233
242 ome::compat::shared_ptr<IFD>
243 getDirectoryByOffset(offset_type offset) const;
244
251 ome::compat::shared_ptr<IFD>
252 getCurrentDirectory() const;
253
262 void
263 writeCurrentDirectory();
264
284 wrapped_type *
285 getWrapped() const;
286
287 friend class IFD;
288
290 typedef IFDIterator<IFD> iterator;
292 typedef IFDIterator<const IFD> const_iterator;
293
299 iterator
300 begin();
301
307 const_iterator
308 begin() const;
309
315 iterator
316 end();
317
323 const_iterator
324 end() const;
325
326 private:
328 void
329 registerImageJTags();
330 };
331
332 }
333 }
334 }
335
336 #endif // OME_FILES_TIFF_TIFF_H
337
338 /*
339 * Local Variables:
340 * mode:C++
341 * End:
342 */
ome::files::tiff::TIFF::getDirectoryByIndex
ome::compat::shared_ptr< IFD > getDirectoryByIndex(directory_index_type index) const
Get an IFD by its index.
Definition: TIFF.cpp:252
memory.h
ome::files::tiff::TIFF::Impl
Internal implementation details of TIFF.
Definition: TIFF.cpp:108
ome::files::tiff::TIFF
Tagged Image File Format (TIFF).
Definition: TIFF.h:156
ome::files::tiff::IFDIterator::IFDIterator
IFDIterator()
Default constructor.
Definition: TIFF.h:78
ome::files::tiff::TIFF::iterator
IFDIterator< IFD > iterator
IFD iterator.
Definition: TIFF.h:290
ome::files::tiff::IFDIterator::increment
void increment()
Increment the iterator by one position.
ome::files::tiff::IFDIterator::pos
ome::compat::shared_ptr< Value > pos
The current position.
Definition: TIFF.h:109
ome::files::tiff::TIFF::~TIFF
~TIFF()
Destructor.
Definition: TIFF.cpp:198
ome::files::tiff::TIFF::getWrapped
wrapped_type * getWrapped() const
Get the underlying libtiff ::TIFF instance.
Definition: TIFF.cpp:203
ome::files::tiff::TIFF::begin
iterator begin()
Get the first image file directory.
Definition: TIFF.cpp:300
ome::files::tiff::TIFF::directoryCount
directory_index_type directoryCount() const
Get the total number of IFDs.
Definition: TIFF.cpp:238
ome::files::tiff::offset_type
uint64_t offset_type
IFD offset.
Definition: Types.h:56
filesystem.h
ome::files::tiff::IFDIterator
Iterator for IFDs contained within a TIFF.
Definition: TIFF.h:68
ome
ome::files::tiff::TIFF::writeCurrentDirectory
void writeCurrentDirectory()
Write the currently active IFD.
Definition: TIFF.cpp:288
ome::files::tiff::TIFF::getCurrentDirectory
ome::compat::shared_ptr< IFD > getCurrentDirectory() const
Get the currently active IFD.
Definition: TIFF.cpp:281
ome::files::tiff::TIFF::registerImageJTags
void registerImageJTags()
Register ImageJ tags with libtiff for this image.
Definition: TIFF.cpp:326
ome::files::tiff::TIFF::open
static ome::compat::shared_ptr< TIFF > open(const boost::filesystem::path &filename, const std::string &mode)
Open a TIFF file for reading or writing.
Definition: TIFF.cpp:209
ome::files::tiff::TIFF::end
iterator end()
Get the last+1 image file directory.
Definition: TIFF.cpp:314
ome::files::tiff::IFDIterator::IFDIterator
IFDIterator(const IFDIterator< OtherValue > &rhs)
Construct from an existing iterator.
Definition: TIFF.h:99
ome::files::tiff::IFDIterator::equal
bool equal(IFDIterator const &rhs) const
Check for equality.
Definition: TIFF.h:131
ome::files::tiff::IFDIterator::dereference
ome::compat::shared_ptr< Value > & dereference() const
Dereference the iterator.
Definition: TIFF.h:142
ome::files::tiff::TIFF::impl
ome::compat::shared_ptr< Impl > impl
Private implementation details.
Definition: TIFF.h:160
cstdint.h
ome::files::tiff::TIFF::close
void close()
Close the TIFF file.
Definition: TIFF.cpp:227
ome::files::tiff::TIFF::operator=
TIFF & operator=(const TIFF &)
Assignment operator (deleted).
ome::files::tiff::TIFF::const_iterator
IFDIterator< const IFD > const_iterator
const IFD iterator.
Definition: TIFF.h:292
ome::files::tiff::directory_index_type
uint16_t directory_index_type
IFD index.
Definition: Types.h:53
ome::files::tiff::IFD
Image File Directory (IFD).
Definition: IFD.h:71
ome::files::tiff::TIFF::getDirectoryByOffset
ome::compat::shared_ptr< IFD > getDirectoryByOffset(offset_type offset) const
Get an IFD by its offset in the file.
Definition: TIFF.cpp:264
ome::files::tiff::IFDIterator::IFDIterator
IFDIterator(ome::compat::shared_ptr< IFD > &ifd)
Construct with an initial starting position.
Definition: TIFF.h:89
ome::files::tiff::TIFF::TIFF
TIFF(const boost::filesystem::path &filename, const std::string &mode)
Constructor (non-public).
Definition: TIFF.cpp:191