ome-files  0.1.1
ImageJMetadata.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_IMAGEJMETADATA_H
39 #define OME_FILES_TIFF_IMAGEJMETADATA_H
40 
41 #include <map>
42 #include <vector>
43 #include <sstream>
44 #include <string>
45 
46 #include <ome/files/Types.h>
47 
48 namespace ome
49 {
50  namespace files
51  {
52  namespace tiff
53  {
54 
55  class IFD;
56 
61  {
63  std::map<std::string, std::string> map;
65  std::vector<uint32_t> counts;
67  std::vector<uint8_t> data;
77  std::string unit;
79  double spacing;
81  double finterval;
87  std::string mode;
89  bool loop;
90 
97  ImageJMetadata(const IFD& ifd);
98 
108  static
109  std::map<std::string,std::string>
110  parse_imagedescription(const std::string& description);
111 
112  protected:
120  static
121  void
122  parse_value_error(const std::string& key,
123  const std::string& value);
124 
135  template<typename T>
136  void
137  parse_value(const std::string& key,
138  T& value)
139  {
140  std::map<std::string,std::string>::const_iterator i = map.find(key);
141  if (i != map.end())
142  {
143  try
144  {
145  std::istringstream is(i->second);
146  is.imbue(std::locale::classic());
147  is.exceptions(std::ios::failbit);
148  is >> value;
149  }
150  catch (const std::ios_base::failure&)
151  {
152  parse_value_error(key, i->second);
153  }
154  }
155  }
156 
167  void
168  parse_value(const std::string& key,
169  bool& value);
170 
181  void
182  parse_value(const std::string& key,
183  std::string& value);
184 
185  };
186 
187  }
188  }
189 }
190 
191 #endif // OME_FILES_TIFF_IMAGEJMETADATA_H
192 
193 /*
194  * Local Variables:
195  * mode:C++
196  * End:
197  */
std::string unit
Length unit name.
Definition: ImageJMetadata.h:77
ImageJMetadata(const IFD &ifd)
Construct from an IFD.
Definition: ImageJMetadata.cpp:65
static std::map< std::string, std::string > parse_imagedescription(const std::string &description)
Parse the TIFF ImageDescription field content.
Definition: ImageJMetadata.cpp:87
std::map< std::string, std::string > map
Map of key-value pairs from ImageDescription field.
Definition: ImageJMetadata.h:63
bool loop
Loop animation(?).
Definition: ImageJMetadata.h:89
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:59
static void parse_value_error(const std::string &key, const std::string &value)
Throw an exception on failing to parse a particular key value.
Definition: ImageJMetadata.cpp:137
dimension_size_type xorigin
X origin.
Definition: ImageJMetadata.h:83
void parse_value(const std::string &key, T &value)
Parse a key&#39;s value into a given type.
Definition: ImageJMetadata.h:137
dimension_size_type slices
Slice count.
Definition: ImageJMetadata.h:71
dimension_size_type channels
Channel count.
Definition: ImageJMetadata.h:75
std::string mode
Color mode.
Definition: ImageJMetadata.h:87
double spacing
Z spacing distance.
Definition: ImageJMetadata.h:79
std::vector< uint8_t > data
Content of ImageJMetaData field.
Definition: ImageJMetadata.h:67
dimension_size_type images
Total number of images.
Definition: ImageJMetadata.h:69
dimension_size_type frames
Frame count.
Definition: ImageJMetadata.h:73
dimension_size_type yorigin
Y origin.
Definition: ImageJMetadata.h:85
double finterval
Frame interval time.
Definition: ImageJMetadata.h:81
Image File Directory (IFD).
Definition: IFD.h:71
ImageJ metadata from IFD tags.
Definition: ImageJMetadata.h:60
std::vector< uint32_t > counts
Content of ImageJMetaDataByteCounts field.
Definition: ImageJMetadata.h:65