ome-files  0.5.0
FormatWriter.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_DETAIL_FORMATWRITER_H
39 #define OME_FILES_DETAIL_FORMATWRITER_H
40 
41 #include <ome/files/FormatWriter.h>
42 #include <ome/files/FormatHandler.h>
43 
44 #include <map>
45 
46 namespace ome
47 {
48  namespace files
49  {
50  namespace detail
51  {
52 
57  {
59  typedef std::map<ome::xml::model::enums::PixelType,
60  std::set<std::string>> pixel_compression_type_map;
61 
63  std::string name;
65  std::string description;
67  std::vector<boost::filesystem::path> suffixes;
69  std::vector<boost::filesystem::path> compression_suffixes;
71  std::set<std::string> compression_types;
73  pixel_compression_type_map pixel_compression_types;
75  bool stacks;
76 
83  WriterProperties(const std::string& name,
84  const std::string& description):
85  name(name),
86  description(description),
87  suffixes(),
88  compression_suffixes(),
89  compression_types(),
90  pixel_compression_types(),
91  stacks()
92  {
93  compression_suffixes.push_back(boost::filesystem::path(""));
94  }
95  };
96 
109  virtual public ::ome::files::FormatHandler
110  {
111  protected:
114 
116  boost::optional<boost::filesystem::path> currentId;
117 
119  std::shared_ptr<std::ostream> out;
120 
123 
126 
128  boost::optional<std::string> compression;
129 
131  boost::optional<bool> interleaved;
132 
135 
138 
140  boost::optional<dimension_size_type> tile_size_x;
141 
143  boost::optional<dimension_size_type> tile_size_y;
144 
149  std::shared_ptr<::ome::xml::meta::MetadataRetrieve> metadataRetrieve;
150 
153 
155  FormatWriter (const FormatWriter&) = delete;
156 
157  FormatWriter&
158  operator= (const FormatWriter&) = delete;
160 
161  public:
163  virtual
164  ~FormatWriter();
165 
166  // Documented in superclass.
167  bool
168  isThisType(const boost::filesystem::path& name,
169  bool open = true) const;
170 
179  virtual
181  getSeriesCount() const;
182 
183  // Documented in superclass.
184  void
185  setLookupTable(dimension_size_type plane,
186  const VariantPixelBuffer& buf);
187 
189 
190  // Documented in superclass.
191  void
192  saveBytes(dimension_size_type plane,
193  VariantPixelBuffer& buf);
194 
195  // Documented in superclass.
196  void
197  setSeries(dimension_size_type series) const;
198 
199  // Documented in superclass.
201  getSeries() const;
202 
203  // Documented in superclass.
204  void
205  setPlane(dimension_size_type plane) const;
206 
207  // Documented in superclass.
209  getPlane() const;
210 
211  // Documented in superclass.
212  bool
213  canDoStacks() const;
214 
215  // Documented in superclass.
216  void
217  setMetadataRetrieve(std::shared_ptr<::ome::xml::meta::MetadataRetrieve>& retrieve);
218 
219  // Documented in superclass.
220  const std::shared_ptr<::ome::xml::meta::MetadataRetrieve>&
221  getMetadataRetrieve() const;
222 
223  // Documented in superclass.
224  std::shared_ptr<::ome::xml::meta::MetadataRetrieve>&
225  getMetadataRetrieve();
226 
232  virtual
234  getImageCount() const;
235 
246  virtual
247  bool
248  isRGB(dimension_size_type channel) const;
249 
255  virtual
257  getSizeX() const;
258 
264  virtual
266  getSizeY() const;
267 
273  virtual
275  getSizeZ() const;
276 
282  virtual
284  getSizeT() const;
285 
291  virtual
293  getSizeC() const;
294 
300  virtual
302  getPixelType() const;
303 
313  virtual
315  getBitsPerPixel() const;
316 
328  virtual
330  getEffectiveSizeC() const;
331 
343  virtual
345  getRGBChannelCount(dimension_size_type channel) const;
346 
350  virtual
351  const std::string&
352  getDimensionOrder() const;
353 
357  virtual
361  dimension_size_type t) const;
362 
366  virtual
367  std::array<dimension_size_type, 3>
368  getZCTCoords(dimension_size_type index) const;
369 
370  // Documented in superclass.
371  void
372  setFramesPerSecond(frame_rate_type rate);
373 
374  // Documented in superclass.
376  getFramesPerSecond() const;
377 
378  // Documented in superclass.
379  const std::set<ome::xml::model::enums::PixelType>
380  getPixelTypes() const;
381 
382  // Documented in superclass.
383  const std::set<ome::xml::model::enums::PixelType>
384  getPixelTypes(const std::string& codec) const;
385 
386  // Documented in superclass.
387  bool
388  isSupportedType(ome::xml::model::enums::PixelType type) const;
389 
390  // Documented in superclass.
391  bool
392  isSupportedType(ome::xml::model::enums::PixelType type,
393  const std::string& codec) const;
394 
395  // Documented in superclass.
396  const std::set<std::string>&
397  getCompressionTypes() const;
398 
399  const std::set<std::string>&
400  getCompressionTypes(ome::xml::model::enums::PixelType type) const;
401 
402  // Documented in superclass.
403  void
404  setCompression(const std::string& compression);
405 
406  // Documented in superclass.
407  const boost::optional<std::string>&
408  getCompression() const;
409 
410  // Documented in superclass.
411  void
412  setInterleaved(bool interleaved);
413 
414  // Documented in superclass.
415  const boost::optional<bool>&
416  getInterleaved() const;
417 
418  // Documented in superclass.
419  void
420  changeOutputFile(const boost::filesystem::path& id);
421 
422  // Documented in superclass.
423  void
424  setWriteSequentially(bool sequential = true);
425 
426  // Documented in superclass.
427  bool
428  getWriteSequentially() const;
429 
430  // Documented in superclass.
431  void
432  setId(const boost::filesystem::path& id);
433 
434  // Documented in superclass.
435  void
436  close(bool fileOnly = false);
437 
438  // Documented in superclass.
439  const std::string&
440  getFormat() const;
441 
442  // Documented in superclass.
443  const std::string&
444  getFormatDescription() const;
445 
446  // Documented in superclass.
447  const std::vector<boost::filesystem::path>&
448  getSuffixes() const;
449 
450  // Documented in superclass.
451  const std::vector<boost::filesystem::path>&
452  getCompressionSuffixes() const;
453 
454  // Documented in superclass.
456  setTileSizeX(boost::optional<dimension_size_type> size);
457 
458  // Documented in superclass.
460  getTileSizeX() const;
461 
462  // Documented in superclass.
464  setTileSizeY(boost::optional<dimension_size_type> size);
465 
466  // Documented in superclass.
468  getTileSizeY() const;
469  };
470 
471  }
472  }
473 }
474 
475 #endif // OME_FILES_DETAIL_FORMATWRITER_H
476 
477 /*
478  * Local Variables:
479  * mode:C++
480  * End:
481  */
const WriterProperties & writerProperties
Writer properties specific to the derived file format.
Definition: FormatWriter.h:113
pixel_compression_type_map pixel_compression_types
Supported compression codecs types for each pixel type.
Definition: FormatWriter.h:73
Interface for all biological file format writers.
Definition: FormatWriter.h:82
bool sequential
Planes are written sequentially.
Definition: FormatWriter.h:134
std::shared_ptr<::ome::xml::meta::MetadataRetrieve > metadataRetrieve
Current metadata store.
Definition: FormatWriter.h:149
uint32_t pixel_size_type
Size type for pixel bit depths.
Definition: Types.h:61
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:58
std::map< ome::xml::model::enums::PixelType, std::set< std::string > > pixel_compression_type_map
Map of codec to pixel types.
Definition: FormatWriter.h:60
std::shared_ptr< std::ostream > out
Current output.
Definition: FormatWriter.h:119
WriterProperties(const std::string &name, const std::string &description)
Constructor.
Definition: FormatWriter.h:83
dimension_size_type getIndex(const std::string &order, dimension_size_type zSize, dimension_size_type cSize, dimension_size_type tSize, dimension_size_type num, dimension_size_type z, dimension_size_type c, dimension_size_type t)
Get the rasterized index corresponding to the given Z, C and T coordinates (real sizes).
Definition: FormatTools.cpp:365
std::set< std::string > compression_types
Supported compression types.
Definition: FormatWriter.h:71
virtual void saveBytes(dimension_size_type plane, VariantPixelBuffer &buf)=0
Save an image plane.
boost::optional< boost::filesystem::path > currentId
The identifier (path) of the currently open file.
Definition: FormatWriter.h:116
Interface for all biological file format writers (default behaviour).
Definition: FormatWriter.h:108
boost::optional< dimension_size_type > tile_size_x
Tile size X.
Definition: FormatWriter.h:140
boost::optional< bool > interleaved
Subchannel interleaving enabled.
Definition: FormatWriter.h:131
dimension_size_type series
Current series.
Definition: FormatWriter.h:122
boost::optional< std::string > compression
The compression type to use.
Definition: FormatWriter.h:128
Properties specific to a particular writer.
Definition: FormatWriter.h:56
Open Microscopy Environment C++.
frame_rate_type framesPerSecond
The frames per second to use when writing.
Definition: FormatWriter.h:137
std::string name
Format name.
Definition: FormatWriter.h:63
std::vector< boost::filesystem::path > suffixes
Filename suffixes this format can handle.
Definition: FormatWriter.h:67
std::array< dimension_size_type, 3 > getZCTCoords(const std::string &order, dimension_size_type zSize, dimension_size_type cSize, dimension_size_type tSize, dimension_size_type num, dimension_size_type index)
Get the Z, C and T coordinates (real sizes) corresponding to the given rasterized index value...
Definition: FormatTools.cpp:422
dimension_size_type plane
Current plane.
Definition: FormatWriter.h:125
bool stacks
Stacks are supported.
Definition: FormatWriter.h:75
std::vector< boost::filesystem::path > compression_suffixes
Filename compression suffixes this format can handle.
Definition: FormatWriter.h:69
std::string description
Format description.
Definition: FormatWriter.h:65
uint16_t frame_rate_type
Frame rate type.
Definition: FormatWriter.h:86
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:78
boost::optional< dimension_size_type > tile_size_y
Tile size Y.
Definition: FormatWriter.h:143
Interface for all biological file format readers and writers.
Definition: FormatHandler.h:63