bioformats  5.1.0
PixelProperties.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_PIXELPROPERTIES_H
39 #define OME_BIOFORMATS_PIXELPROPERTIES_H
40 
41 #include <complex>
42 
43 #include <ome/common/boolean.h>
44 #include <ome/common/endian.h>
45 
46 #include <ome/compat/cstdint.h>
47 
48 #include <ome/bioformats/Types.h>
49 
50 #include <ome/xml/model/enums/PixelType.h>
51 
52 namespace ome
53 {
54  namespace bioformats
55  {
56 
60  template<int>
62 
76  template<class P>
78  {
83  static pixel_size_type
85  {
86  return sizeof(typename P::std_type);
87  }
88 
93  static pixel_size_type
95  {
96  return pixel_byte_size() * 8;
97  }
98  };
99 
101  template<>
103  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::INT8> >
104  {
106  typedef int8_t std_type;
107 
109  typedef boost::endian::big_int8_t big_type;
111  typedef boost::endian::little_int8_t little_type;
113  typedef boost::endian::native_int8_t native_type;
114 
116  static const bool is_signed = true;
118  static const bool is_integer = true;
120  static const bool is_complex = false;
121  };
122 
124  template<>
126  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::INT16> >
127  {
129  typedef int16_t std_type;
130 
132  typedef boost::endian::big_int16_t big_type;
134  typedef boost::endian::little_int16_t little_type;
136  typedef boost::endian::native_int16_t native_type;
137 
139  static const bool is_signed = true;
141  static const bool is_integer = true;
143  static const bool is_complex = false;
144  };
145 
147  template<>
149  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::INT32> >
150  {
152  typedef int32_t std_type;
153 
155  typedef boost::endian::big_int32_t big_type;
157  typedef boost::endian::little_int32_t little_type;
159  typedef boost::endian::native_int32_t native_type;
160 
162  static const bool is_signed = true;
164  static const bool is_integer = true;
166  static const bool is_complex = false;
167  };
168 
170  template<>
172  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::UINT8> >
173  {
175  typedef uint8_t std_type;
176 
178  typedef boost::endian::big_uint8_t big_type;
180  typedef boost::endian::little_uint8_t little_type;
182  typedef boost::endian::native_uint8_t native_type;
183 
185  static const bool is_signed = false;
187  static const bool is_integer = true;
189  static const bool is_complex = false;
190  };
191 
193  template<>
195  public PixelPropertiesBase<struct PixelProperties< ::ome::xml::model::enums::PixelType::UINT16> >
196  {
198  typedef uint16_t std_type;
199 
201  typedef boost::endian::big_uint16_t big_type;
203  typedef boost::endian::little_uint16_t little_type;
205  typedef boost::endian::native_uint16_t native_type;
206 
208  static const bool is_signed = false;
210  static const bool is_integer = true;
212  static const bool is_complex = false;
213  };
214 
216  template<>
218  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::UINT32> >
219  {
221  typedef uint32_t std_type;
222 
224  typedef boost::endian::big_uint32_t big_type;
226  typedef boost::endian::little_uint32_t little_type;
228  typedef boost::endian::native_uint32_t native_type;
229 
231  static const bool is_signed = false;
233  static const bool is_integer = true;
235  static const bool is_complex = false;
236  };
237 
239  template<>
241  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::FLOAT> >
242  {
244  typedef float std_type;
245 
247  typedef boost::endian::big_float32_t big_type;
249  typedef boost::endian::little_float32_t little_type;
251  typedef boost::endian::native_float32_t native_type;
252 
254  static const bool is_signed = true;
256  static const bool is_integer = false;
258  static const bool is_complex = false;
259  };
260 
262  template<>
264  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::DOUBLE> >
265  {
267  typedef double std_type;
268 
270  typedef boost::endian::big_float64_t big_type;
272  typedef boost::endian::little_float64_t little_type;
274  typedef boost::endian::native_float64_t native_type;
275 
277  static const bool is_signed = true;
279  static const bool is_integer = false;
281  static const bool is_complex = false;
282  };
283 
285  template<>
287  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::BIT> >
288  {
290  typedef bool std_type;
291 
298 
300  static const bool is_signed = false;
302  static const bool is_integer = true;
304  static const bool is_complex = false;
305  };
306 
308  template<>
310  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::COMPLEX> >
311  {
313  typedef std::complex<float> std_type;
314 
316  typedef std::complex<boost::endian::big_float32_t> big_type;
318  typedef std::complex<boost::endian::little_float32_t> little_type;
320  typedef std::complex<boost::endian::native_float32_t> native_type;
321 
323  static const bool is_signed = true;
325  static const bool is_integer = false;
327  static const bool is_complex = true;
328  };
329 
331  template<>
333  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::DOUBLECOMPLEX> >
334  {
336  typedef std::complex<double> std_type;
337 
339  typedef std::complex<boost::endian::big_float64_t> big_type;
341  typedef std::complex<boost::endian::little_float64_t> little_type;
343  typedef std::complex<boost::endian::native_float64_t> native_type;
344 
346  static const bool is_signed = true;
348  static const bool is_integer = false;
350  static const bool is_complex = true;
351  };
352 
355  {
359  };
360 
365  template<int, int>
367 
369  template<int P>
371  {
374  };
375 
377  template<int P>
379  {
382  };
383 
385  template<int P>
387  {
390  };
391 
401 
411 
419  bool
421 
429  bool
431 
441  bool
443 
451  bool
453 
470  bool is_signed = false,
471  bool is_integer = true,
472  bool is_complex = false);
473 
490  bool is_signed = false,
491  bool is_integer = true,
492  bool is_complex = false);
493 
499  template<typename T>
500  inline void
501  byteswap(T& value)
502  {
503  boost::endian::reverse(value);
504  }
505 
511  template<>
512  inline void
513  byteswap(std::complex<float>& value)
514  {
515  // For pre-C++11 compatibility, it's not possible to byteswap in
516  // place.
517  value = std::complex<float>(reverse_value(value.real()),
518  reverse_value(value.imag()));
519  }
520 
526  template<>
527  inline void
528  byteswap(std::complex<double>& value)
529  {
530  // For pre-C++11 compatibility, it's not possible to byteswap in
531  // place.
532  value = std::complex<double>(reverse_value(value.real()),
533  reverse_value(value.imag()));
534  }
535 
536  }
537 }
538 
539 #endif // OME_BIOFORMATS_PIXELPROPERTIES_H
540 
541 /*
542  * Local Variables:
543  * mode:C++
544  * End:
545  */
uint32
Definition: PixelType.h:87
boost::endian::little_int32_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:157
uint8
Definition: PixelType.h:83
boost::endian::native_int8_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:113
EndianType
Endianness.
Definition: PixelProperties.h:354
::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:352
Big endian.
Definition: PixelProperties.h:356
uint8_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:175
int32_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:152
bit
Definition: PixelType.h:91
Properties common to all pixel types.
Definition: PixelProperties.h:77
uint16_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:198
PixelProperties< P >::native_type type
Pixel type (native endian).
Definition: PixelProperties.h:389
uint32_t pixel_size_type
Size type for pixel bit depths.
Definition: Types.h:62
boost::endian::native_uint16_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:205
Map a given PixelPropertiesType enum to the corresponding language types.
Definition: PixelProperties.h:61
int8
Definition: PixelType.h:77
bool std_type
Pixel type (standard language type).
Definition: PixelProperties.h:290
uint32_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:221
Native endian.
Definition: PixelProperties.h:358
boost::endian::native_float32_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:251
bool isInteger(::ome::xml::model::enums::PixelType pixeltype)
Check whether a PixelType is integer.
Definition: PixelProperties.cpp:191
double std_type
Pixel type (standard language type).
Definition: PixelProperties.h:267
bool isComplex(::ome::xml::model::enums::PixelType pixeltype)
Check whether a PixelType is complex.
Definition: PixelProperties.cpp:242
std::complex< boost::endian::big_float32_t > big_type
Pixel type (big endian).
Definition: PixelProperties.h:316
boost::endian::native_uint8_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:182
Boolean type with guaranteed size, alignment and storage values.
Definition: boolean.h:73
boost::endian::native_uint32_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:228
int16
Definition: PixelType.h:79
float std_type
Pixel type (standard language type).
Definition: PixelProperties.h:244
uint16
Definition: PixelType.h:85
std::complex< double > std_type
Pixel type (standard language type).
Definition: PixelProperties.h:336
std::complex< boost::endian::native_float32_t > native_type
Pixel type (native endian).
Definition: PixelProperties.h:320
ome::common::boolean big_type
Pixel type (big endian).
Definition: PixelProperties.h:293
static pixel_size_type pixel_bit_size()
Get size of pixel type, in bits.
Definition: PixelProperties.h:94
std::complex< boost::endian::little_float32_t > little_type
Pixel type (little endian).
Definition: PixelProperties.h:318
std::complex< boost::endian::big_float64_t > big_type
Pixel type (big endian).
Definition: PixelProperties.h:339
boost::endian::big_float32_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:247
boost::endian::native_int16_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:136
Endian-specific integer types.
boost::endian::native_int32_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:159
boost::endian::native_float64_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:274
float
Definition: PixelType.h:89
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
boost::endian::little_uint16_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:203
boost::endian::little_uint8_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:180
pixel_size_type bitsPerPixel(::ome::xml::model::enums::PixelType pixeltype)
Get the size of a PixelType, in bits.
Definition: PixelProperties.cpp:101
boost::endian::big_uint32_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:224
bool isFloatingPoint(::ome::xml::model::enums::PixelType pixeltype)
Check whether a PixelType is floating point.
Definition: PixelProperties.cpp:236
bool isSigned(::ome::xml::model::enums::PixelType pixeltype)
Check whether a PixelType is signed.
Definition: PixelProperties.cpp:146
Little endian.
Definition: PixelProperties.h:357
complex
Definition: PixelType.h:95
PixelProperties< P >::little_type type
Pixel type (little endian).
Definition: PixelProperties.h:381
boost::endian::big_int8_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:109
void byteswap(T &value)
Byteswap value to switch endianness.
Definition: PixelProperties.h:501
::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:291
boost::endian::little_int16_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:134
boost::endian::little_int8_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:111
std::complex< float > std_type
Pixel type (standard language type).
Definition: PixelProperties.h:313
Map the given PixelPropertiesType and Endian enums to the corresponding endian-specific language type...
Definition: PixelProperties.h:366
boost::endian::big_int32_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:155
int8_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:106
boost::endian::little_float64_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:272
double
Definition: PixelType.h:93
pixel_size_type bytesPerPixel(::ome::xml::model::enums::PixelType pixeltype)
Get the size of a PixelType, in bytes.
Definition: PixelProperties.cpp:56
PixelType enumeration.
Definition: PixelType.h:70
Standard integer types.
boost::endian::big_uint16_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:201
int16_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:129
boost::endian::little_uint32_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:226
boost::endian::big_int16_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:132
static pixel_size_type pixel_byte_size()
Get size of pixel type, in bytes.
Definition: PixelProperties.h:84
boost::endian::little_float32_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:249
boost::endian::big_uint8_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:178
ome::common::boolean little_type
Pixel type (little endian).
Definition: PixelProperties.h:295
ome::common::boolean native_type
Pixel type (native endian).
Definition: PixelProperties.h:297
int32
Definition: PixelType.h:81
std::complex< boost::endian::native_float64_t > native_type
Pixel type (native endian).
Definition: PixelProperties.h:343
boost::endian::big_float64_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:270
PixelProperties< P >::big_type type
Pixel type (big endian).
Definition: PixelProperties.h:373
double-complex
Definition: PixelType.h:97
std::complex< boost::endian::little_float64_t > little_type
Pixel type (little endian).
Definition: PixelProperties.h:341