bioformats  5.1.2
FormatWriter.h
1 /*
2  * #%L
3  * OME-BIOFORMATS 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_BIOFORMATS_DETAIL_FORMATWRITER_H
39 #define OME_BIOFORMATS_DETAIL_FORMATWRITER_H
40 
41 #include <ome/bioformats/FormatWriter.h>
42 #include <ome/bioformats/FormatHandler.h>
43 
44 #include <map>
45 
46 namespace ome
47 {
48  namespace bioformats
49  {
50  namespace detail
51  {
52 
57  {
59  typedef std::map<std::string,
60  std::set<ome::xml::model::enums::PixelType> > codec_pixel_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  codec_pixel_type_map codec_pixel_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  codec_pixel_types(),
91  stacks()
92  {
93  compression_suffixes.push_back(boost::filesystem::path(""));
94  }
95  };
96 
109  virtual public ::ome::bioformats::FormatHandler
110  {
111  protected:
114 
116  boost::optional<boost::filesystem::path> currentId;
117 
119  ome::compat::shared_ptr<std::ostream> out;
120 
123 
126 
128  boost::optional<std::string> compression;
129 
131  boost::optional<bool> interleaved;
132 
135 
138 
143  ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve> metadataRetrieve;
144 
145  protected:
148 
149  private:
151  FormatWriter (const FormatWriter&);
152 
154  FormatWriter&
155  operator= (const FormatWriter&);
156 
157  public:
159  virtual
160  ~FormatWriter();
161 
162  // Documented in superclass.
163  bool
164  isThisType(const boost::filesystem::path& name,
165  bool open = true) const;
166 
175  virtual
177  getSeriesCount() const;
178 
179  // Documented in superclass.
180  void
182  const VariantPixelBuffer& buf);
183 
185 
186  // Documented in superclass.
187  void
189  VariantPixelBuffer& buf);
190 
191  // Documented in superclass.
192  void
193  setSeries(dimension_size_type series) const;
194 
195  // Documented in superclass.
197  getSeries() const;
198 
207  virtual void
208  setPlane(dimension_size_type plane) const;
209 
215  virtual dimension_size_type
216  getPlane() const;
217 
218  // Documented in superclass.
219  bool
220  canDoStacks() const;
221 
222  // Documented in superclass.
223  void
224  setMetadataRetrieve(ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve>& retrieve);
225 
226  // Documented in superclass.
227  const ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve>&
228  getMetadataRetrieve() const;
229 
230  // Documented in superclass.
231  ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve>&
233 
239  virtual
241  getImageCount() const;
242 
253  virtual
254  bool
255  isRGB(dimension_size_type channel) const;
256 
262  virtual
264  getSizeX() const;
265 
271  virtual
273  getSizeY() const;
274 
280  virtual
282  getSizeZ() const;
283 
289  virtual
291  getSizeT() const;
292 
298  virtual
300  getSizeC() const;
301 
307  virtual
309  getPixelType() const;
310 
320  virtual
322  getBitsPerPixel() const;
323 
335  virtual
337  getEffectiveSizeC() const;
338 
350  virtual
353 
357  virtual
358  const std::string&
359  getDimensionOrder() const;
360 
364  virtual
368  dimension_size_type t) const;
369 
373  virtual
374  ome::compat::array<dimension_size_type, 3>
375  getZCTCoords(dimension_size_type index) const;
376 
377  // Documented in superclass.
378  void
380 
381  // Documented in superclass.
383  getFramesPerSecond() const;
384 
385  // Documented in superclass.
386  const std::set<ome::xml::model::enums::PixelType>&
387  getPixelTypes() const;
388 
389  // Documented in superclass.
390  const std::set<ome::xml::model::enums::PixelType>&
391  getPixelTypes(const std::string& codec) const;
392 
393  // Documented in superclass.
394  bool
396 
397  // Documented in superclass.
398  bool
400  const std::string& codec) const;
401 
402  // Documented in superclass.
403  const std::set<std::string>&
404  getCompressionTypes() const ;
405 
406  // Documented in superclass.
407  void
408  setCompression(const std::string& compression);
409 
410  // Documented in superclass.
411  const boost::optional<std::string>&
412  getCompression() const;
413 
414  // Documented in superclass.
415  void
416  setInterleaved(bool interleaved);
417 
418  // Documented in superclass.
419  const boost::optional<bool>&
420  getInterleaved() const;
421 
422  // Documented in superclass.
423  void
424  changeOutputFile(const boost::filesystem::path& id);
425 
426  // Documented in superclass.
427  void
428  setWriteSequentially(bool sequential = true);
429 
430  // Documented in superclass.
431  bool
432  getWriteSequentially() const;
433 
434  // Documented in superclass.
435  void
436  setId(const boost::filesystem::path& id);
437 
438  // Documented in superclass.
439  void
440  close(bool fileOnly = false);
441 
442  // Documented in superclass.
443  const std::string&
444  getFormat() const;
445 
446  // Documented in superclass.
447  const std::string&
448  getFormatDescription() const;
449 
450  // Documented in superclass.
451  const std::vector<boost::filesystem::path>&
452  getSuffixes() const;
453 
454  // Documented in superclass.
455  const std::vector<boost::filesystem::path>&
456  getCompressionSuffixes() const;
457  };
458 
459  }
460  }
461 }
462 
463 #endif // OME_BIOFORMATS_DETAIL_FORMATWRITER_H
464 
465 /*
466  * Local Variables:
467  * mode:C++
468  * End:
469  */
void setSeries(dimension_size_type series) const
Set the active series.
Definition: FormatWriter.cpp:181
bool getWriteSequentially() const
Check if planes are written sequentially.
Definition: FormatWriter.cpp:335
void setLookupTable(dimension_size_type plane, const VariantPixelBuffer &buf)
Set the color lookup table associated with the current series.
Definition: FormatWriter.cpp:161
virtual ~FormatWriter()
Destructor.
Definition: FormatWriter.cpp:95
codec_pixel_type_map codec_pixel_types
Supported pixel types.
Definition: FormatWriter.h:73
uint32_t pixel_size_type
Size type for pixel bit depths.
Definition: Types.h:62
WriterProperties(const std::string &name, const std::string &description)
Constructor.
Definition: FormatWriter.h:83
const std::set< ome::xml::model::enums::PixelType > & getPixelTypes() const
Get supported pixel types.
Definition: FormatWriter.cpp:257
Interface for all biological file format readers and writers.
Definition: FormatHandler.h:64
virtual pixel_size_type getBitsPerPixel() const
Get the number of valid bits per pixel.
Definition: FormatWriter.cpp:433
boost::optional< bool > interleaved
Subchannel interleaving enabled.
Definition: FormatWriter.h:131
virtual dimension_size_type getImageCount() const
Determine the number of image planes in the current series.
Definition: FormatWriter.cpp:364
virtual dimension_size_type getSizeZ() const
Get the size of the Z dimension.
Definition: FormatWriter.cpp:396
bool sequential
Planes are written sequentially.
Definition: FormatWriter.h:134
const std::vector< boost::filesystem::path > & getCompressionSuffixes() const
Get the default compression suffixes for this file format.
Definition: FormatWriter.cpp:517
virtual dimension_size_type getPlane() const
Get the active plane.
Definition: FormatWriter.cpp:238
const WriterProperties & writerProperties
Writer properties specific to the derived file format.
Definition: FormatWriter.h:113
virtual dimension_size_type getIndex(dimension_size_type z, dimension_size_type c, dimension_size_type t) const
Get the linear index of a Z, C and T coordinate.
Definition: FormatWriter.cpp:473
virtual dimension_size_type getSizeC() const
Get the size of the C dimension.
Definition: FormatWriter.cpp:416
const boost::optional< bool > & getInterleaved() const
Set subchannel interleaving.
Definition: FormatWriter.cpp:315
const std::vector< boost::filesystem::path > & getSuffixes() const
Get the default file suffixes for this file format.
Definition: FormatWriter.cpp:511
std::vector< boost::filesystem::path > compression_suffixes
Filename compression suffixes this format can handle.
Definition: FormatWriter.h:69
void saveBytes(dimension_size_type plane, VariantPixelBuffer &buf)
Save an image plane.
Definition: FormatWriter.cpp:170
Interface for all biological file format writers (default behaviour).
Definition: FormatWriter.h:108
uint16_t frame_rate_type
Frame rate type.
Definition: FormatWriter.h:86
Interface for all biological file format writers.
Definition: FormatWriter.h:82
virtual dimension_size_type getSizeT() const
Get the size of the T dimension.
Definition: FormatWriter.cpp:406
dimension_size_type series
Current series.
Definition: FormatWriter.h:122
bool isThisType(const boost::filesystem::path &name, bool open=true) const
Check if the given file is a valid instance of this file format.
Definition: FormatWriter.cpp:146
FormatWriter & operator=(const FormatWriter &)
Assignment operator (deleted).
std::set< std::string > compression_types
Supported compression types.
Definition: FormatWriter.h:71
void setFramesPerSecond(frame_rate_type rate)
Set the frame rate to use when writing.
Definition: FormatWriter.cpp:245
virtual dimension_size_type getEffectiveSizeC() const
Get the effective size of the C dimension.
Definition: FormatWriter.cpp:440
virtual ome::compat::array< dimension_size_type, 3 > getZCTCoords(dimension_size_type index) const
Get the Z, C and T coordinate of a linear index.
Definition: FormatWriter.cpp:487
virtual bool isRGB(dimension_size_type channel) const
Does a channel contain subchannels?
Definition: FormatWriter.cpp:370
virtual dimension_size_type getRGBChannelCount(dimension_size_type channel) const
Get the number of channels required for a call to saveBytes().
Definition: FormatWriter.cpp:447
std::vector< boost::filesystem::path > suffixes
Filename suffixes this format can handle.
Definition: FormatWriter.h:67
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
virtual const std::string & getDimensionOrder() const
Get the dimension order.
Definition: FormatWriter.cpp:466
void close(bool fileOnly=false)
Close the currently open file.
Definition: FormatWriter.cpp:129
virtual void saveBytes(dimension_size_type plane, VariantPixelBuffer &buf)=0
Save an image plane.
bool stacks
Stacks are supported.
Definition: FormatWriter.h:75
void changeOutputFile(const boost::filesystem::path &id)
Switch the output file for the current dataset.
Definition: FormatWriter.cpp:321
bool canDoStacks() const
Get whether or not the writer can save multiple images in a single file.
Definition: FormatWriter.cpp:529
const std::set< std::string > & getCompressionTypes() const
Get supported compression types.
Definition: FormatWriter.cpp:523
virtual dimension_size_type getSeriesCount() const
Get the number of image series in this file.
Definition: FormatWriter.cpp:155
void setMetadataRetrieve(ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve > &retrieve)
Set the default metadata store for this writer.
Definition: FormatWriter.cpp:341
dimension_size_type getSeries() const
Get the active series.
Definition: FormatWriter.cpp:206
std::string description
Format description.
Definition: FormatWriter.h:65
frame_rate_type getFramesPerSecond() const
Get the frame rate to use when writing.
Definition: FormatWriter.cpp:251
const std::string & getFormat() const
Get the name of this file format.
Definition: FormatWriter.cpp:499
PixelType enumeration.
Definition: PixelType.h:70
virtual void setPlane(dimension_size_type plane) const
Set the active plane.
Definition: FormatWriter.cpp:214
const ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve > & getMetadataRetrieve() const
Get the current metadata store for this writer.
Definition: FormatWriter.cpp:352
dimension_size_type plane
Current plane.
Definition: FormatWriter.h:125
frame_rate_type framesPerSecond
The frames per second to use when writing.
Definition: FormatWriter.h:137
virtual ome::xml::model::enums::PixelType getPixelType() const
Get the pixel type.
Definition: FormatWriter.cpp:426
const std::string & getFormatDescription() const
Get the description of this file format.
Definition: FormatWriter.cpp:505
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:72
void setId(const boost::filesystem::path &id)
Set the current file name.
Definition: FormatWriter.cpp:107
boost::optional< std::string > compression
The compression type to use.
Definition: FormatWriter.h:128
FormatWriter()
Constructor.
Definition: FormatWriter.h:90
std::map< std::string, std::set< ome::xml::model::enums::PixelType > > codec_pixel_type_map
Map of codec to pixel types.
Definition: FormatWriter.h:60
std::string name
Format name.
Definition: FormatWriter.h:63
void setCompression(const std::string &compression)
Set the compression type to use when writing.
Definition: FormatWriter.cpp:289
boost::optional< boost::filesystem::path > currentId
The identifier (path) of the currently open file.
Definition: FormatWriter.h:116
virtual dimension_size_type getSizeY() const
Get the size of the Y dimension.
Definition: FormatWriter.cpp:386
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:59
bool isSupportedType(ome::xml::model::enums::PixelType type) const
Check if the pixel type is supported.
Definition: FormatWriter.cpp:274
ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve > metadataRetrieve
Current metadata store.
Definition: FormatWriter.h:143
Properties specific to a particular writer.
Definition: FormatWriter.h:56
const boost::optional< std::string > & getCompression() const
Get the compression type to use when writing.
Definition: FormatWriter.cpp:303
virtual dimension_size_type getSizeX() const
Get the size of the X dimension.
Definition: FormatWriter.cpp:376
void setWriteSequentially(bool sequential=true)
Write planes sequentially.
Definition: FormatWriter.cpp:329
void setInterleaved(bool interleaved)
Set subchannel interleaving.
Definition: FormatWriter.cpp:309
ome::compat::shared_ptr< std::ostream > out
Current output.
Definition: FormatWriter.h:119