ome-files  0.3.0
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 <cstdint>
42 #include <memory>
43 #include <string>
44 
45 #include <boost/filesystem/path.hpp>
46 #include <boost/iterator/iterator_facade.hpp>
47 
48 #include <ome/files/tiff/Types.h>
49 
50 namespace ome
51 {
52  namespace files
53  {
57  namespace tiff
58  {
59 
60  class IFD;
61 
65  template<typename Value>
66  class IFDIterator : public boost::iterator_facade<IFDIterator<Value>,
67  std::shared_ptr<Value>,
68  boost::forward_traversal_tag>
69  {
70  public:
77  pos()
78  {}
79 
87  IFDIterator(std::shared_ptr<IFD>& ifd):
88  pos(ifd)
89  {}
90 
96  template <class OtherValue>
98  : pos(rhs.pos) {}
99 
100  private:
107  mutable std::shared_ptr<Value> pos;
108 
109  friend class boost::iterator_core_access;
110  template <class> friend class IFDIterator;
111 
119  void
120  increment();
121 
128  bool
129  equal(IFDIterator const& rhs) const
130  {
131  return this->pos == rhs.pos;
132  }
133 
139  std::shared_ptr<Value>&
140  dereference() const
141  {
142  return pos;
143  }
144  };
145 
154  class TIFF : public std::enable_shared_from_this<TIFF>
155  {
156  private:
157  class Impl;
158  class wrapped_type;
160  std::shared_ptr<Impl> impl;
161 
162  protected:
164  TIFF(const boost::filesystem::path& filename,
165  const std::string& mode);
166 
167  private:
169  TIFF (const TIFF&);
170 
172  TIFF&
173  operator= (const TIFF&);
174 
175  public:
177  ~TIFF();
178 
191  static std::shared_ptr<TIFF>
192  open(const boost::filesystem::path& filename,
193  const std::string& mode);
194 
202  void
203  close();
204 
211  operator bool ();
212 
219  directoryCount() const;
220 
229  std::shared_ptr<IFD>
230  getDirectoryByIndex(directory_index_type index) const;
231 
240  std::shared_ptr<IFD>
241  getDirectoryByOffset(offset_type offset) const;
242 
249  std::shared_ptr<IFD>
250  getCurrentDirectory() const;
251 
260  void
261  writeCurrentDirectory();
262 
282  wrapped_type *
283  getWrapped() const;
284 
285  friend class IFD;
286 
291 
297  iterator
298  begin();
299 
305  const_iterator
306  begin() const;
307 
313  iterator
314  end();
315 
321  const_iterator
322  end() const;
323 
324  private:
326  void
327  registerImageJTags();
328  };
329 
330  }
331  }
332 }
333 
334 #endif // OME_FILES_TIFF_TIFF_H
335 
336 /*
337  * Local Variables:
338  * mode:C++
339  * End:
340  */
std::shared_ptr< Value > & dereference() const
Dereference the iterator.
Definition: TIFF.h:140
Internal implementation details of TIFF.
Definition: TIFF.cpp:113
Tagged Image File Format (TIFF).
Definition: TIFF.h:154
std::shared_ptr< Value > pos
The current position.
Definition: TIFF.h:107
IFDIterator()
Default constructor.
Definition: TIFF.h:76
IFDIterator< IFD > iterator
IFD iterator.
Definition: TIFF.h:288
void increment()
Increment the iterator by one position.
uint64_t offset_type
IFD offset.
Definition: Types.h:65
Iterator for IFDs contained within a TIFF.
Definition: TIFF.h:66
Open Microscopy Environment C++.
IFDIterator(std::shared_ptr< IFD > &ifd)
Construct with an initial starting position.
Definition: TIFF.h:87
IFDIterator(const IFDIterator< OtherValue > &rhs)
Construct from an existing iterator.
Definition: TIFF.h:97
std::shared_ptr< Impl > impl
Private implementation details.
Definition: TIFF.h:158
bool equal(IFDIterator const &rhs) const
Check for equality.
Definition: TIFF.h:129
IFDIterator< const IFD > const_iterator
const IFD iterator.
Definition: TIFF.h:290
uint16_t directory_index_type
IFD index.
Definition: Types.h:62
Image File Directory (IFD).
Definition: IFD.h:70