ome-files  0.1.1
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:
79  pos()
80  {}
81 
89  IFDIterator(ome::compat::shared_ptr<IFD>& ifd):
90  pos(ifd)
91  {}
92 
98  template <class OtherValue>
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 
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 
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  */
Internal implementation details of TIFF.
Definition: TIFF.cpp:108
Tagged Image File Format (TIFF).
Definition: TIFF.h:156
IFDIterator()
Default constructor.
Definition: TIFF.h:78
IFDIterator< IFD > iterator
IFD iterator.
Definition: TIFF.h:290
void increment()
Increment the iterator by one position.
ome::compat::shared_ptr< Value > pos
The current position.
Definition: TIFF.h:109
uint64_t offset_type
IFD offset.
Definition: Types.h:56
Iterator for IFDs contained within a TIFF.
Definition: TIFF.h:68
IFDIterator(const IFDIterator< OtherValue > &rhs)
Construct from an existing iterator.
Definition: TIFF.h:99
bool equal(IFDIterator const &rhs) const
Check for equality.
Definition: TIFF.h:131
ome::compat::shared_ptr< Value > & dereference() const
Dereference the iterator.
Definition: TIFF.h:142
ome::compat::shared_ptr< Impl > impl
Private implementation details.
Definition: TIFF.h:160
IFDIterator< const IFD > const_iterator
const IFD iterator.
Definition: TIFF.h:292
uint16_t directory_index_type
IFD index.
Definition: Types.h:53
Image File Directory (IFD).
Definition: IFD.h:71
IFDIterator(ome::compat::shared_ptr< IFD > &ifd)
Construct with an initial starting position.
Definition: TIFF.h:89