ome-files  0.5.0
PixelProperties.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_PIXELPROPERTIES_H
39 #define OME_FILES_PIXELPROPERTIES_H
40 
41 #include <cstdint>
42 #include <complex>
43 
44 #include <ome/common/boolean.h>
45 #include <ome/common/endian.h>
46 
47 #include <ome/files/Types.h>
48 
49 #include <ome/xml/model/enums/PixelType.h>
50 
51 namespace ome
52 {
53  namespace files
54  {
55 
59  template<int>
61 
75  template<class P>
77  {
83  static pixel_size_type
85  {
86  return sizeof(typename P::std_type);
87  }
88 
94  static pixel_size_type
96  {
97  return pixel_byte_size() * 8;
98  }
99 
106  static pixel_size_type
108  {
109  return pixel_bit_size();
110  }
111  };
112 
114  template<>
116  public PixelPropertiesBase<PixelProperties<::ome::xml::model::enums::PixelType::INT8>>
117  {
119  typedef int8_t std_type;
120 
122  typedef boost::endian::big_int8_t big_type;
124  typedef boost::endian::little_int8_t little_type;
126  typedef boost::endian::native_int8_t native_type;
127 
129  static const bool is_signed = true;
131  static const bool is_integer = true;
133  static const bool is_complex = false;
134  };
135 
137  template<>
139  public PixelPropertiesBase<PixelProperties<::ome::xml::model::enums::PixelType::INT16>>
140  {
142  typedef int16_t std_type;
143 
145  typedef boost::endian::big_int16_t big_type;
147  typedef boost::endian::little_int16_t little_type;
149  typedef boost::endian::native_int16_t native_type;
150 
152  static const bool is_signed = true;
154  static const bool is_integer = true;
156  static const bool is_complex = false;
157  };
158 
160  template<>
162  public PixelPropertiesBase<PixelProperties<::ome::xml::model::enums::PixelType::INT32>>
163  {
165  typedef int32_t std_type;
166 
168  typedef boost::endian::big_int32_t big_type;
170  typedef boost::endian::little_int32_t little_type;
172  typedef boost::endian::native_int32_t native_type;
173 
175  static const bool is_signed = true;
177  static const bool is_integer = true;
179  static const bool is_complex = false;
180  };
181 
183  template<>
185  public PixelPropertiesBase<PixelProperties<::ome::xml::model::enums::PixelType::UINT8>>
186  {
188  typedef uint8_t std_type;
189 
191  typedef boost::endian::big_uint8_t big_type;
193  typedef boost::endian::little_uint8_t little_type;
195  typedef boost::endian::native_uint8_t native_type;
196 
198  static const bool is_signed = false;
200  static const bool is_integer = true;
202  static const bool is_complex = false;
203  };
204 
206  template<>
208  public PixelPropertiesBase<struct PixelProperties<::ome::xml::model::enums::PixelType::UINT16>>
209  {
211  typedef uint16_t std_type;
212 
214  typedef boost::endian::big_uint16_t big_type;
216  typedef boost::endian::little_uint16_t little_type;
218  typedef boost::endian::native_uint16_t native_type;
219 
221  static const bool is_signed = false;
223  static const bool is_integer = true;
225  static const bool is_complex = false;
226  };
227 
229  template<>
231  public PixelPropertiesBase<PixelProperties<::ome::xml::model::enums::PixelType::UINT32>>
232  {
234  typedef uint32_t std_type;
235 
237  typedef boost::endian::big_uint32_t big_type;
239  typedef boost::endian::little_uint32_t little_type;
241  typedef boost::endian::native_uint32_t native_type;
242 
244  static const bool is_signed = false;
246  static const bool is_integer = true;
248  static const bool is_complex = false;
249  };
250 
252  template<>
254  public PixelPropertiesBase<PixelProperties<::ome::xml::model::enums::PixelType::FLOAT>>
255  {
257  typedef float std_type;
258 
260  typedef boost::endian::big_float32_t big_type;
262  typedef boost::endian::little_float32_t little_type;
264  typedef boost::endian::native_float32_t native_type;
265 
267  static const bool is_signed = true;
269  static const bool is_integer = false;
271  static const bool is_complex = false;
272  };
273 
275  template<>
277  public PixelPropertiesBase<PixelProperties<::ome::xml::model::enums::PixelType::DOUBLE>>
278  {
280  typedef double std_type;
281 
283  typedef boost::endian::big_float64_t big_type;
285  typedef boost::endian::little_float64_t little_type;
287  typedef boost::endian::native_float64_t native_type;
288 
290  static const bool is_signed = true;
292  static const bool is_integer = false;
294  static const bool is_complex = false;
295  };
296 
298  template<>
300  public PixelPropertiesBase<PixelProperties<::ome::xml::model::enums::PixelType::BIT>>
301  {
303  typedef bool std_type;
304 
311 
313  static const bool is_signed = false;
315  static const bool is_integer = true;
317  static const bool is_complex = false;
318 
325  static pixel_size_type
327  {
328  return 1;
329  }
330  };
331 
333  template<>
335  public PixelPropertiesBase<PixelProperties<::ome::xml::model::enums::PixelType::COMPLEXFLOAT>>
336  {
338  typedef std::complex<float> std_type;
339 
341  typedef std::complex<boost::endian::big_float32_t> big_type;
343  typedef std::complex<boost::endian::little_float32_t> little_type;
345  typedef std::complex<boost::endian::native_float32_t> native_type;
346 
348  static const bool is_signed = true;
350  static const bool is_integer = false;
352  static const bool is_complex = true;
353  };
354 
356  template<>
358  public PixelPropertiesBase<PixelProperties<::ome::xml::model::enums::PixelType::COMPLEXDOUBLE>>
359  {
361  typedef std::complex<double> std_type;
362 
364  typedef std::complex<boost::endian::big_float64_t> big_type;
366  typedef std::complex<boost::endian::little_float64_t> little_type;
368  typedef std::complex<boost::endian::native_float64_t> native_type;
369 
371  static const bool is_signed = true;
373  static const bool is_integer = false;
375  static const bool is_complex = true;
376  };
377 
382  template<int, int>
384 
386  template<int P>
388  {
391  };
392 
394  template<int P>
396  {
399  };
400 
402  template<int P>
404  {
407  };
408 
418 
428 
439 
447  bool
449 
457  bool
459 
469  bool
471 
479  bool
481 
498  bool is_signed = false,
499  bool is_integer = true,
500  bool is_complex = false);
501 
518  bool is_signed = false,
519  bool is_integer = true,
520  bool is_complex = false);
521 
527  template<typename T>
528  inline void
529  byteswap(T& value)
530  {
531  boost::endian::reverse(value);
532  }
533 
539  template<>
540  inline void
541  byteswap(std::complex<float>& value)
542  {
543  // For pre-C++11 compatibility, it's not possible to byteswap in
544  // place.
545  value = std::complex<float>(reverse_value(value.real()),
546  reverse_value(value.imag()));
547  }
548 
554  template<>
555  inline void
556  byteswap(std::complex<double>& value)
557  {
558  // For pre-C++11 compatibility, it's not possible to byteswap in
559  // place.
560  value = std::complex<double>(reverse_value(value.real()),
561  reverse_value(value.imag()));
562  }
563 
564  }
565 }
566 
567 #endif // OME_FILES_PIXELPROPERTIES_H
568 
569 /*
570  * Local Variables:
571  * mode:C++
572  * End:
573  */
pixel_size_type bytesPerPixel(::ome::xml::model::enums::PixelType pixeltype)
Get the size of a PixelType, in bytes.
Definition: PixelProperties.cpp:65
boost::endian::little_uint8_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:193
::ome::xml::model::enums::PixelType pixelTypeFromBytes(pixel_size_type size, bool is_signed, bool is_integer, bool is_complex)
Determine a likely pixel type from its the storage size in bytes.
Definition: PixelProperties.cpp:190
boost::endian::little_float64_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:285
double std_type
Pixel type (standard language type).
Definition: PixelProperties.h:280
::ome::xml::model::enums::PixelType pixelTypeFromBits(pixel_size_type size, bool is_signed, bool is_integer, bool is_complex)
Determine a likely pixel type from its the storage size in bits.
Definition: PixelProperties.cpp:251
Properties common to all pixel types.
Definition: PixelProperties.h:76
PixelProperties< P >::little_type type
Pixel type (little endian).
Definition: PixelProperties.h:398
ome::common::boolean big_type
Pixel type (big endian).
Definition: PixelProperties.h:306
uint32_t pixel_size_type
Size type for pixel bit depths.
Definition: Types.h:61
pixel_size_type significantBitsPerPixel(::ome::xml::model::enums::PixelType pixeltype)
Get the significant (maximum bits used) size of a PixelType, in bits.
Definition: PixelProperties.cpp:105
boost::endian::little_int8_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:124
static pixel_size_type pixel_byte_size()
Get size of pixel type, in bytes.
Definition: PixelProperties.h:84
std::complex< boost::endian::big_float64_t > big_type
Pixel type (big endian).
Definition: PixelProperties.h:364
Big endian.
Definition: Types.h:69
std::complex< boost::endian::native_float64_t > native_type
Pixel type (native endian).
Definition: PixelProperties.h:368
static pixel_size_type pixel_significant_bit_size()
Get significant (maximum bits used) size of pixel type, in bits.
Definition: PixelProperties.h:107
Map a given PixelPropertiesType enum to the corresponding language types.
Definition: PixelProperties.h:60
boost::endian::big_float32_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:260
std::complex< float > std_type
Pixel type (standard language type).
Definition: PixelProperties.h:338
std::complex< boost::endian::native_float32_t > native_type
Pixel type (native endian).
Definition: PixelProperties.h:345
boost::endian::little_uint32_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:239
boost::endian::native_uint8_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:195
bool isInteger(::ome::xml::model::enums::PixelType pixeltype)
Check whether a PixelType is integer.
Definition: PixelProperties.cpp:145
uint8_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:188
static pixel_size_type pixel_bit_size()
Get size of pixel type, in bits.
Definition: PixelProperties.h:95
int32_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:165
boost::endian::big_int16_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:145
uint16_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:211
boost::endian::little_float32_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:262
bool isComplex(::ome::xml::model::enums::PixelType pixeltype)
Check whether a PixelType is complex.
Definition: PixelProperties.cpp:171
boost::endian::big_uint32_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:237
std::complex< boost::endian::little_float32_t > little_type
Pixel type (little endian).
Definition: PixelProperties.h:343
float std_type
Pixel type (standard language type).
Definition: PixelProperties.h:257
Open Microscopy Environment C++.
boost::endian::native_int32_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:172
boost::endian::little_int16_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:147
Native endian.
Definition: Types.h:71
ome::common::boolean native_type
Pixel type (native endian).
Definition: PixelProperties.h:310
int16_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:142
boost::endian::native_float32_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:264
void byteswap(T &value)
Byteswap value to switch endianness.
Definition: PixelProperties.h:529
boost::endian::little_uint16_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:216
bool isFloatingPoint(::ome::xml::model::enums::PixelType pixeltype)
Check whether a PixelType is floating point.
Definition: PixelProperties.cpp:160
PixelProperties< P >::big_type type
Pixel type (big endian).
Definition: PixelProperties.h:390
bool isSigned(::ome::xml::model::enums::PixelType pixeltype)
Check whether a PixelType is signed.
Definition: PixelProperties.cpp:125
boost::endian::big_int8_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:122
boost::endian::big_uint8_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:191
PixelProperties< P >::native_type type
Pixel type (native endian).
Definition: PixelProperties.h:406
std::complex< boost::endian::little_float64_t > little_type
Pixel type (little endian).
Definition: PixelProperties.h:366
boost::endian::big_uint16_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:214
boost::endian::native_int16_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:149
Map the given PixelPropertiesType and Endian enums to the corresponding endian-specific language type...
Definition: PixelProperties.h:383
std::complex< double > std_type
Pixel type (standard language type).
Definition: PixelProperties.h:361
static pixel_size_type pixel_significant_bit_size()
Get significant (maximum bits used) size of pixel type, in bits.
Definition: PixelProperties.h:326
Little endian.
Definition: Types.h:70
boost::endian::native_int8_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:126
uint32_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:234
boost::endian::big_int32_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:168
boost::endian::little_int32_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:170
boost::endian::native_float64_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:287
ome::common::boolean little_type
Pixel type (little endian).
Definition: PixelProperties.h:308
std::complex< boost::endian::big_float32_t > big_type
Pixel type (big endian).
Definition: PixelProperties.h:341
bool std_type
Pixel type (standard language type).
Definition: PixelProperties.h:303
pixel_size_type bitsPerPixel(::ome::xml::model::enums::PixelType pixeltype)
Get the size of a PixelType, in bits.
Definition: PixelProperties.cpp:85
boost::endian::big_float64_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:283
boost::endian::native_uint16_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:218
boost::endian::native_uint32_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:241
int8_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:119