bioformats  5.1.8
OMETIFFWriter.h
1 /*
2  * #%L
3  * OME-BIOFORMATS C++ library for image IO.
4  * Copyright © 2006 - 2016 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_BIOFORMATS_OUT_OMETIFFWRITER_H
39 #define OME_BIOFORMATS_OUT_OMETIFFWRITER_H
40 
41 #include <ome/bioformats/detail/FormatWriter.h>
42 #include <ome/bioformats/detail/OMETIFF.h>
43 
44 #include <ome/common/filesystem.h>
45 #include <ome/common/log.h>
46 
47 #include <ome/xml/meta/OMEXMLMetadata.h>
48 
49 namespace ome
50 {
51  namespace bioformats
52  {
53  namespace tiff
54  {
55 
56  class TIFF;
57  class IFD;
58 
59  }
60 
61  namespace out
62  {
63 
68  {
69  protected:
72 
74  typedef std::map<boost::filesystem::path, std::string> file_uuid_map;
75 
76  // In the Java reader, this is uuids + ifdCounts
78  struct TIFFState
79  {
81  std::string uuid;
83  ome::compat::shared_ptr<ome::bioformats::tiff::TIFF> tiff;
86 
92  TIFFState(ome::compat::shared_ptr<ome::bioformats::tiff::TIFF>& tiff);
93 
95  ~TIFFState();
96  };
97 
99  typedef std::map<boost::filesystem::path, TIFFState> tiff_map;
100 
101  // In the Java reader, this is imageLocations.
103  struct SeriesState
104  {
106  std::vector<detail::OMETIFFPlane> planes;
107  };
108 
110  typedef std::vector<SeriesState> series_list;
111 
113  boost::filesystem::path baseDir;
114 
116  file_uuid_map files;
117 
118  // Mutable to allow opening TIFFs when const.
120  mutable tiff_map tiffs;
121 
123  tiff_map::iterator currentTIFF;
124 
126  std::string flags;
127 
129  series_list seriesState;
130 
140  ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve> originalMetadataRetrieve;
141 
143  ome::compat::shared_ptr<ome::xml::meta::OMEXMLMetadata> omeMeta;
144 
145  private:
147  boost::optional<bool> bigTIFF;
148 
149  public:
151  OMETIFFWriter();
152 
154  virtual
155  ~OMETIFFWriter();
156 
157  // Documented in superclass.
158  void
159  setId(const boost::filesystem::path& id);
160 
161  // Documented in superclass.
162  void
163  close(bool fileOnly = false);
164 
166 
167  // Documented in superclass.
168  void
170 
171  // Documented in superclass.
172  void
174 
175  protected:
177  void
178  nextIFD() const;
179 
181  void
182  setupIFD() const;
183 
184  public:
185  // Documented in superclass.
186  void
188  VariantPixelBuffer& buf,
193 
194  private:
200  void
201  fillMetadata();
202 
209  std::string
210  getOMEXML(const boost::filesystem::path& id);
211 
218  void
219  saveComment(const boost::filesystem::path& id,
220  const std::string& xml);
221 
222  // Java getUUID unimplemented; see uuid member of TIFFState.
223 
224  // Java planeCount() unimplemented; use getImageCount()
225  // instead. Note the java implementation special-cases
226  // certain behaviour such as interleaving for certain pixel
227  // types; here the caller can specify exactly what they want.
228 
229  public:
233  void
234  setBigTIFF(boost::optional<bool> big = true);
235 
239  boost::optional<bool>
240  getBigTIFF() const;
241  };
242 
243  }
244  }
245 }
246 
247 #endif // OME_BIOFORMATS_OUT_OMETIFFWRITER_H
248 
249 /*
250  * Local Variables:
251  * mode:C++
252  * End:
253  */
void setPlane(dimension_size_type plane) const
Set the active plane.
Definition: OMETIFFWriter.cpp:615
logging::sources::severity_logger_mt< logging::trivial::severity_level > Logger
Message logger.
Definition: log.h:98
TIFFState(ome::compat::shared_ptr< ome::bioformats::tiff::TIFF > &tiff)
Constructor.
Definition: OMETIFFWriter.cpp:411
tiff_map tiffs
Open TIFF files.
Definition: OMETIFFWriter.h:120
ome::compat::shared_ptr< ome::xml::meta::OMEXMLMetadata > omeMeta
OME-XML metadata for embedding in the TIFF.
Definition: OMETIFFWriter.h:143
ome::common::Logger logger
Message logger.
Definition: OMETIFFWriter.h:71
ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve > originalMetadataRetrieve
Original MetadataRetrieve.
Definition: OMETIFFWriter.h:140
void close(bool fileOnly=false)
Close the currently open file.
Definition: OMETIFFWriter.cpp:544
void saveComment(const boost::filesystem::path &id, const std::string &xml)
Save OME-XML text in the first IFD of the specified TIFF file.
Definition: OMETIFFWriter.cpp:798
Current state of an image series.
Definition: OMETIFFWriter.h:103
void saveBytes(dimension_size_type plane, VariantPixelBuffer &buf, dimension_size_type x, dimension_size_type y, dimension_size_type w, dimension_size_type h)
Save an image plane.
Definition: OMETIFFWriter.cpp:675
void fillMetadata()
Fill MetadataStore with cached metadata.
Definition: OMETIFFWriter.cpp:702
std::string flags
TIFF flags.
Definition: OMETIFFWriter.h:126
Interface for all biological file format writers (default behaviour).
Definition: FormatWriter.h:108
std::map< boost::filesystem::path, TIFFState > tiff_map
Map filename to TIFF state.
Definition: OMETIFFWriter.h:99
dimension_size_type series
Current series.
Definition: FormatWriter.h:122
boost::optional< bool > getBigTIFF() const
Query use of BigTIFF support.
Definition: OMETIFFWriter.cpp:912
boost::optional< bool > bigTIFF
Write a Big TIFF.
Definition: OMETIFFWriter.h:147
void setSeries(dimension_size_type series) const
Set the active series.
Definition: OMETIFFWriter.cpp:602
virtual ~OMETIFFWriter()
Destructor.
Definition: OMETIFFWriter.cpp:436
State of TIFF file.
Definition: OMETIFFWriter.h:78
Boost.Filesystem compatibility.
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
TIFF writer with support for OME-XML metadata.
Definition: OMETIFFWriter.h:67
void nextIFD() const
Flush current IFD and create new IFD.
Definition: OMETIFFWriter.cpp:628
std::map< boost::filesystem::path, std::string > file_uuid_map
Map filename to UUID.
Definition: OMETIFFWriter.h:74
virtual void saveBytes(dimension_size_type plane, VariantPixelBuffer &buf)=0
Save an image plane.
std::string uuid
UUID of file.
Definition: OMETIFFWriter.h:81
void setId(const boost::filesystem::path &id)
Set the current file name.
Definition: OMETIFFWriter.cpp:448
series_list seriesState
State of each series.
Definition: OMETIFFWriter.h:129
std::string getOMEXML(const boost::filesystem::path &id)
Get OME-XML for embedding into the specified TIFF file.
Definition: OMETIFFWriter.cpp:777
dimension_size_type ifdCount
Number of IFDs written.
Definition: OMETIFFWriter.h:85
~TIFFState()
Destructor.
Definition: OMETIFFWriter.cpp:418
dimension_size_type plane
Current plane.
Definition: FormatWriter.h:125
tiff_map::iterator currentTIFF
Current TIFF file.
Definition: OMETIFFWriter.h:123
boost::filesystem::path baseDir
Base path for computing relative paths in the OME-XML.
Definition: OMETIFFWriter.h:113
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:75
file_uuid_map files
UUID to filename mapping.
Definition: OMETIFFWriter.h:116
void setupIFD() const
Set IFD parameters for the current series.
Definition: OMETIFFWriter.cpp:635
void setBigTIFF(boost::optional< bool > big=true)
Set use of BigTIFF support.
Definition: OMETIFFWriter.cpp:906
Boost.Log compatibility.
std::vector< SeriesState > series_list
Vector of SeriesState objects.
Definition: OMETIFFWriter.h:110
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:59
OMETIFFWriter()
Constructor.
Definition: OMETIFFWriter.cpp:422
std::vector< detail::OMETIFFPlane > planes
Current state of each plane in an image series.
Definition: OMETIFFWriter.h:106
Xerces-C modern C++ wrapper.
Definition: Base.h:53
ome::compat::shared_ptr< ome::bioformats::tiff::TIFF > tiff
TIFF file handle.
Definition: OMETIFFWriter.h:83