ome-files 0.1.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

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
56 struct WriterProperties
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
108 class FormatWriter : public ::ome::files::FormatWriter,
109 virtual public ::ome::files::FormatHandler
110 {
111 protected:
113 const WriterProperties& writerProperties;
114
116 boost::optional<boost::filesystem::path> currentId;
117
119 ome::compat::shared_ptr<std::ostream> out;
120
122 mutable dimension_size_type series;
123
125 mutable dimension_size_type plane;
126
128 boost::optional<std::string> compression;
129
131 boost::optional<bool> interleaved;
132
134 bool sequential;
135
137 frame_rate_type framesPerSecond;
138
143 ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve> metadataRetrieve;
144
145 protected:
147 FormatWriter(const WriterProperties&);
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
176 dimension_size_type
177 getSeriesCount() const;
178
179 // Documented in superclass.
180 void
181 setLookupTable(dimension_size_type plane,
182 const VariantPixelBuffer& buf);
183
184 using files::FormatWriter::saveBytes;
185
186 // Documented in superclass.
187 void
188 saveBytes(dimension_size_type plane,
189 VariantPixelBuffer& buf);
190
191 // Documented in superclass.
192 void
193 setSeries(dimension_size_type series) const;
194
195 // Documented in superclass.
196 dimension_size_type
197 getSeries() const;
198
199 // Documented in superclass.
200 void
201 setPlane(dimension_size_type plane) const;
202
203 // Documented in superclass.
204 dimension_size_type
205 getPlane() const;
206
207 // Documented in superclass.
208 bool
209 canDoStacks() const;
210
211 // Documented in superclass.
212 void
213 setMetadataRetrieve(ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve>& retrieve);
214
215 // Documented in superclass.
216 const ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve>&
217 getMetadataRetrieve() const;
218
219 // Documented in superclass.
220 ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve>&
221 getMetadataRetrieve();
222
228 virtual
229 dimension_size_type
230 getImageCount() const;
231
242 virtual
243 bool
244 isRGB(dimension_size_type channel) const;
245
251 virtual
252 dimension_size_type
253 getSizeX() const;
254
260 virtual
261 dimension_size_type
262 getSizeY() const;
263
269 virtual
270 dimension_size_type
271 getSizeZ() const;
272
278 virtual
279 dimension_size_type
280 getSizeT() const;
281
287 virtual
288 dimension_size_type
289 getSizeC() const;
290
296 virtual
297 ome::xml::model::enums::PixelType
298 getPixelType() const;
299
309 virtual
310 pixel_size_type
311 getBitsPerPixel() const;
312
324 virtual
325 dimension_size_type
326 getEffectiveSizeC() const;
327
339 virtual
340 dimension_size_type
341 getRGBChannelCount(dimension_size_type channel) const;
342
346 virtual
347 const std::string&
348 getDimensionOrder() const;
349
353 virtual
354 dimension_size_type
355 getIndex(dimension_size_type z,
356 dimension_size_type c,
357 dimension_size_type t) const;
358
362 virtual
363 ome::compat::array<dimension_size_type, 3>
364 getZCTCoords(dimension_size_type index) const;
365
366 // Documented in superclass.
367 void
368 setFramesPerSecond(frame_rate_type rate);
369
370 // Documented in superclass.
371 frame_rate_type
372 getFramesPerSecond() const;
373
374 // Documented in superclass.
375 const std::set<ome::xml::model::enums::PixelType>&
376 getPixelTypes() const;
377
378 // Documented in superclass.
379 const std::set<ome::xml::model::enums::PixelType>&
380 getPixelTypes(const std::string& codec) const;
381
382 // Documented in superclass.
383 bool
384 isSupportedType(ome::xml::model::enums::PixelType type) const;
385
386 // Documented in superclass.
387 bool
388 isSupportedType(ome::xml::model::enums::PixelType type,
389 const std::string& codec) const;
390
391 // Documented in superclass.
392 const std::set<std::string>&
393 getCompressionTypes() const ;
394
395 // Documented in superclass.
396 void
397 setCompression(const std::string& compression);
398
399 // Documented in superclass.
400 const boost::optional<std::string>&
401 getCompression() const;
402
403 // Documented in superclass.
404 void
405 setInterleaved(bool interleaved);
406
407 // Documented in superclass.
408 const boost::optional<bool>&
409 getInterleaved() const;
410
411 // Documented in superclass.
412 void
413 changeOutputFile(const boost::filesystem::path& id);
414
415 // Documented in superclass.
416 void
417 setWriteSequentially(bool sequential = true);
418
419 // Documented in superclass.
420 bool
421 getWriteSequentially() const;
422
423 // Documented in superclass.
424 void
425 setId(const boost::filesystem::path& id);
426
427 // Documented in superclass.
428 void
429 close(bool fileOnly = false);
430
431 // Documented in superclass.
432 const std::string&
433 getFormat() const;
434
435 // Documented in superclass.
436 const std::string&
437 getFormatDescription() const;
438
439 // Documented in superclass.
440 const std::vector<boost::filesystem::path>&
441 getSuffixes() const;
442
443 // Documented in superclass.
444 const std::vector<boost::filesystem::path>&
445 getCompressionSuffixes() const;
446 };
447
448 }
449 }
450 }
451
452 #endif // OME_FILES_DETAIL_FORMATWRITER_H
453
454 /*
455 * Local Variables:
456 * mode:C++
457 * End:
458 */
ome::files::detail::FormatWriter::writerProperties
const WriterProperties & writerProperties
Writer properties specific to the derived file format.
Definition: FormatWriter.h:113
ome::files::detail::FormatWriter::setPlane
void setPlane(dimension_size_type plane) const
Set the active plane.
Definition: FormatWriter.cpp:210
ome::files::FormatWriter
Interface for all biological file format writers.
Definition: FormatWriter.h:82
ome::files::detail::FormatWriter::sequential
bool sequential
Planes are written sequentially.
Definition: FormatWriter.h:134
ome::files::detail::FormatWriter::getImageCount
virtual dimension_size_type getImageCount() const
Determine the number of image planes in the current series.
Definition: FormatWriter.cpp:361
ome::files::detail::FormatWriter::getFormatDescription
const std::string & getFormatDescription() const
Get the description of this file format.
Definition: FormatWriter.cpp:502
ome::files::pixel_size_type
uint32_t pixel_size_type
Size type for pixel bit depths.
Definition: Types.h:62
ome::files::detail::FormatWriter::getMetadataRetrieve
const ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve > & getMetadataRetrieve() const
Get the current metadata store for this writer.
Definition: FormatWriter.cpp:349
ome::files::detail::FormatWriter::getPixelTypes
const std::set< ome::xml::model::enums::PixelType > & getPixelTypes() const
Get supported pixel types.
Definition: FormatWriter.cpp:254
ome::files::detail::FormatWriter::getPixelType
virtual ome::xml::model::enums::PixelType getPixelType() const
Get the pixel type.
Definition: FormatWriter.cpp:423
ome::files::dimension_size_type
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:59
ome::files::detail::FormatWriter::getCompression
const boost::optional< std::string > & getCompression() const
Get the compression type to use when writing.
Definition: FormatWriter.cpp:300
ome::files::FormatWriter::FormatWriter
FormatWriter()
Constructor.
Definition: FormatWriter.h:90
ome::files::detail::FormatWriter::getSuffixes
const std::vector< boost::filesystem::path > & getSuffixes() const
Get the default file suffixes for this file format.
Definition: FormatWriter.cpp:508
ome::files::detail::FormatWriter::getCompressionSuffixes
const std::vector< boost::filesystem::path > & getCompressionSuffixes() const
Get the default compression suffixes for this file format.
Definition: FormatWriter.cpp:514
ome::files::detail::FormatWriter::isSupportedType
bool isSupportedType(ome::xml::model::enums::PixelType type) const
Check if the pixel type is supported.
Definition: FormatWriter.cpp:271
ome::files::detail::WriterProperties::WriterProperties
WriterProperties(const std::string &name, const std::string &description)
Constructor.
Definition: FormatWriter.h:83
ome::files::detail::FormatWriter::setLookupTable
void setLookupTable(dimension_size_type plane, const VariantPixelBuffer &buf)
Set the color lookup table associated with the current series.
Definition: FormatWriter.cpp:157
ome::files::detail::FormatWriter::changeOutputFile
void changeOutputFile(const boost::filesystem::path &id)
Switch the output file for the current dataset.
Definition: FormatWriter.cpp:318
ome::files::detail::FormatWriter::saveBytes
void saveBytes(dimension_size_type plane, VariantPixelBuffer &buf)
Save an image plane.
Definition: FormatWriter.cpp:166
ome::files::detail::FormatWriter::setMetadataRetrieve
void setMetadataRetrieve(ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve > &retrieve)
Set the default metadata store for this writer.
Definition: FormatWriter.cpp:338
ome::files::detail::WriterProperties::compression_types
std::set< std::string > compression_types
Supported compression types.
Definition: FormatWriter.h:71
ome::files::FormatWriter::saveBytes
virtual void saveBytes(dimension_size_type plane, VariantPixelBuffer &buf)=0
Save an image plane.
ome::files::detail::FormatWriter::getDimensionOrder
virtual const std::string & getDimensionOrder() const
Get the dimension order.
Definition: FormatWriter.cpp:463
ome::files::detail::FormatWriter::setWriteSequentially
void setWriteSequentially(bool sequential=true)
Write planes sequentially.
Definition: FormatWriter.cpp:326
ome::files::detail::FormatWriter::currentId
boost::optional< boost::filesystem::path > currentId
The identifier (path) of the currently open file.
Definition: FormatWriter.h:116
ome::files::detail::FormatWriter::getSizeY
virtual dimension_size_type getSizeY() const
Get the size of the Y dimension.
Definition: FormatWriter.cpp:383
ome::files::detail::FormatWriter::getRGBChannelCount
virtual dimension_size_type getRGBChannelCount(dimension_size_type channel) const
Get the number of channels required for a call to saveBytes().
Definition: FormatWriter.cpp:444
ome::files::detail::FormatWriter
Interface for all biological file format writers (default behaviour).
Definition: FormatWriter.h:108
ome::files::detail::FormatWriter::getEffectiveSizeC
virtual dimension_size_type getEffectiveSizeC() const
Get the effective size of the C dimension.
Definition: FormatWriter.cpp:437
ome::files::detail::FormatWriter::out
ome::compat::shared_ptr< std::ostream > out
Current output.
Definition: FormatWriter.h:119
ome::files::detail::FormatWriter::getInterleaved
const boost::optional< bool > & getInterleaved() const
Set subchannel interleaving.
Definition: FormatWriter.cpp:312
ome::files::detail::FormatWriter::interleaved
boost::optional< bool > interleaved
Subchannel interleaving enabled.
Definition: FormatWriter.h:131
ome::files::detail::WriterProperties::codec_pixel_type_map
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
ome::files::detail::FormatWriter::series
dimension_size_type series
Current series.
Definition: FormatWriter.h:122
ome::files::detail::FormatWriter::compression
boost::optional< std::string > compression
The compression type to use.
Definition: FormatWriter.h:128
ome::files::detail::WriterProperties
Properties specific to a particular writer.
Definition: FormatWriter.h:56
ome::files::detail::FormatWriter::getZCTCoords
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:484
ome::files::detail::FormatWriter::setCompression
void setCompression(const std::string &compression)
Set the compression type to use when writing.
Definition: FormatWriter.cpp:286
ome::files::detail::FormatWriter::canDoStacks
bool canDoStacks() const
Get whether or not the writer can save multiple images in a single file.
Definition: FormatWriter.cpp:526
ome
ome::files::detail::FormatWriter::framesPerSecond
frame_rate_type framesPerSecond
The frames per second to use when writing.
Definition: FormatWriter.h:137
ome::files::detail::FormatWriter::isThisType
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:142
ome::files::detail::FormatWriter::operator=
FormatWriter & operator=(const FormatWriter &)
Assignment operator (deleted).
ome::files::detail::FormatWriter::getFormat
const std::string & getFormat() const
Get the name of this file format.
Definition: FormatWriter.cpp:496
ome::files::detail::FormatWriter::setSeries
void setSeries(dimension_size_type series) const
Set the active series.
Definition: FormatWriter.cpp:177
ome::files::detail::FormatWriter::getIndex
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:470
ome::files::detail::WriterProperties::codec_pixel_types
codec_pixel_type_map codec_pixel_types
Supported pixel types.
Definition: FormatWriter.h:73
ome::files::detail::FormatWriter::metadataRetrieve
ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve > metadataRetrieve
Current metadata store.
Definition: FormatWriter.h:143
ome::files::detail::WriterProperties::name
std::string name
Format name.
Definition: FormatWriter.h:63
ome::files::detail::WriterProperties::suffixes
std::vector< boost::filesystem::path > suffixes
Filename suffixes this format can handle.
Definition: FormatWriter.h:67
ome::files::detail::FormatWriter::setInterleaved
void setInterleaved(bool interleaved)
Set subchannel interleaving.
Definition: FormatWriter.cpp:306
ome::xml::model::enums::PixelType
ome::files::detail::FormatWriter::setFramesPerSecond
void setFramesPerSecond(frame_rate_type rate)
Set the frame rate to use when writing.
Definition: FormatWriter.cpp:242
ome::files::detail::FormatWriter::getPlane
dimension_size_type getPlane() const
Get the active plane.
Definition: FormatWriter.cpp:234
ome::files::detail::FormatWriter::getSizeX
virtual dimension_size_type getSizeX() const
Get the size of the X dimension.
Definition: FormatWriter.cpp:373
ome::files::detail::FormatWriter::getSizeZ
virtual dimension_size_type getSizeZ() const
Get the size of the Z dimension.
Definition: FormatWriter.cpp:393
ome::files::detail::FormatWriter::plane
dimension_size_type plane
Current plane.
Definition: FormatWriter.h:125
ome::files::detail::FormatWriter::getCompressionTypes
const std::set< std::string > & getCompressionTypes() const
Get supported compression types.
Definition: FormatWriter.cpp:520
ome::files::detail::FormatWriter::isRGB
virtual bool isRGB(dimension_size_type channel) const
Does a channel contain subchannels?
Definition: FormatWriter.cpp:367
ome::files::detail::FormatWriter::getBitsPerPixel
virtual pixel_size_type getBitsPerPixel() const
Get the number of valid bits per pixel.
Definition: FormatWriter.cpp:430
ome::files::detail::WriterProperties::stacks
bool stacks
Stacks are supported.
Definition: FormatWriter.h:75
ome::files::detail::WriterProperties::compression_suffixes
std::vector< boost::filesystem::path > compression_suffixes
Filename compression suffixes this format can handle.
Definition: FormatWriter.h:69
ome::files::detail::FormatWriter::getSeries
dimension_size_type getSeries() const
Get the active series.
Definition: FormatWriter.cpp:202
ome::files::detail::WriterProperties::description
std::string description
Format description.
Definition: FormatWriter.h:65
ome::files::detail::FormatWriter::getSizeT
virtual dimension_size_type getSizeT() const
Get the size of the T dimension.
Definition: FormatWriter.cpp:403
ome::files::detail::FormatWriter::close
void close(bool fileOnly=false)
Close the currently open file.
Definition: FormatWriter.cpp:129
ome::files::FormatWriter::frame_rate_type
uint16_t frame_rate_type
Frame rate type.
Definition: FormatWriter.h:86
ome::files::detail::FormatWriter::getSizeC
virtual dimension_size_type getSizeC() const
Get the size of the C dimension.
Definition: FormatWriter.cpp:413
ome::files::VariantPixelBuffer
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:75
ome::files::detail::FormatWriter::setId
void setId(const boost::filesystem::path &id)
Set the current file name.
Definition: FormatWriter.cpp:107
ome::files::FormatHandler
Interface for all biological file format readers and writers.
Definition: FormatHandler.h:64
ome::files::detail::FormatWriter::getFramesPerSecond
frame_rate_type getFramesPerSecond() const
Get the frame rate to use when writing.
Definition: FormatWriter.cpp:248
ome::files::detail::FormatWriter::getWriteSequentially
bool getWriteSequentially() const
Check if planes are written sequentially.
Definition: FormatWriter.cpp:332
ome::files::detail::FormatWriter::getSeriesCount
virtual dimension_size_type getSeriesCount() const
Get the number of image series in this file.
Definition: FormatWriter.cpp:151
ome::files::detail::FormatWriter::~FormatWriter
virtual ~FormatWriter()
Destructor.
Definition: FormatWriter.cpp:95