bioformats  5.1.8
PixelProperties.h
1 /*
2  * #%L
3  * OME-BIOFORMATS C++ library for image IO.
4  * Copyright © 2006 - 2016 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  {
84  static pixel_size_type
86  {
87  return sizeof(typename P::std_type);
88  }
89 
95  static pixel_size_type
97  {
98  return pixel_byte_size() * 8;
99  }
100 
107  static pixel_size_type
109  {
110  return pixel_bit_size();
111  }
112  };
113 
115  template<>
117  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::INT8> >
118  {
120  typedef int8_t std_type;
121 
123  typedef boost::endian::big_int8_t big_type;
125  typedef boost::endian::little_int8_t little_type;
127  typedef boost::endian::native_int8_t native_type;
128 
130  static const bool is_signed = true;
132  static const bool is_integer = true;
134  static const bool is_complex = false;
135  };
136 
138  template<>
140  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::INT16> >
141  {
143  typedef int16_t std_type;
144 
146  typedef boost::endian::big_int16_t big_type;
148  typedef boost::endian::little_int16_t little_type;
150  typedef boost::endian::native_int16_t native_type;
151 
153  static const bool is_signed = true;
155  static const bool is_integer = true;
157  static const bool is_complex = false;
158  };
159 
161  template<>
163  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::INT32> >
164  {
166  typedef int32_t std_type;
167 
169  typedef boost::endian::big_int32_t big_type;
171  typedef boost::endian::little_int32_t little_type;
173  typedef boost::endian::native_int32_t native_type;
174 
176  static const bool is_signed = true;
178  static const bool is_integer = true;
180  static const bool is_complex = false;
181  };
182 
184  template<>
186  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::UINT8> >
187  {
189  typedef uint8_t std_type;
190 
192  typedef boost::endian::big_uint8_t big_type;
194  typedef boost::endian::little_uint8_t little_type;
196  typedef boost::endian::native_uint8_t native_type;
197 
199  static const bool is_signed = false;
201  static const bool is_integer = true;
203  static const bool is_complex = false;
204  };
205 
207  template<>
209  public PixelPropertiesBase<struct PixelProperties< ::ome::xml::model::enums::PixelType::UINT16> >
210  {
212  typedef uint16_t std_type;
213 
215  typedef boost::endian::big_uint16_t big_type;
217  typedef boost::endian::little_uint16_t little_type;
219  typedef boost::endian::native_uint16_t native_type;
220 
222  static const bool is_signed = false;
224  static const bool is_integer = true;
226  static const bool is_complex = false;
227  };
228 
230  template<>
232  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::UINT32> >
233  {
235  typedef uint32_t std_type;
236 
238  typedef boost::endian::big_uint32_t big_type;
240  typedef boost::endian::little_uint32_t little_type;
242  typedef boost::endian::native_uint32_t native_type;
243 
245  static const bool is_signed = false;
247  static const bool is_integer = true;
249  static const bool is_complex = false;
250  };
251 
253  template<>
255  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::FLOAT> >
256  {
258  typedef float std_type;
259 
261  typedef boost::endian::big_float32_t big_type;
263  typedef boost::endian::little_float32_t little_type;
265  typedef boost::endian::native_float32_t native_type;
266 
268  static const bool is_signed = true;
270  static const bool is_integer = false;
272  static const bool is_complex = false;
273  };
274 
276  template<>
278  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::DOUBLE> >
279  {
281  typedef double std_type;
282 
284  typedef boost::endian::big_float64_t big_type;
286  typedef boost::endian::little_float64_t little_type;
288  typedef boost::endian::native_float64_t native_type;
289 
291  static const bool is_signed = true;
293  static const bool is_integer = false;
295  static const bool is_complex = false;
296  };
297 
299  template<>
301  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::BIT> >
302  {
304  typedef bool std_type;
305 
312 
314  static const bool is_signed = false;
316  static const bool is_integer = true;
318  static const bool is_complex = false;
319 
326  static pixel_size_type
328  {
329  return 1;
330  }
331  };
332 
334  template<>
336  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::COMPLEX> >
337  {
339  typedef std::complex<float> std_type;
340 
342  typedef std::complex<boost::endian::big_float32_t> big_type;
344  typedef std::complex<boost::endian::little_float32_t> little_type;
346  typedef std::complex<boost::endian::native_float32_t> native_type;
347 
349  static const bool is_signed = true;
351  static const bool is_integer = false;
353  static const bool is_complex = true;
354  };
355 
357  template<>
359  public PixelPropertiesBase<PixelProperties< ::ome::xml::model::enums::PixelType::DOUBLECOMPLEX> >
360  {
362  typedef std::complex<double> std_type;
363 
365  typedef std::complex<boost::endian::big_float64_t> big_type;
367  typedef std::complex<boost::endian::little_float64_t> little_type;
369  typedef std::complex<boost::endian::native_float64_t> native_type;
370 
372  static const bool is_signed = true;
374  static const bool is_integer = false;
376  static const bool is_complex = true;
377  };
378 
383  template<int, int>
385 
387  template<int P>
389  {
392  };
393 
395  template<int P>
397  {
400  };
401 
403  template<int P>
405  {
408  };
409 
419 
429 
440 
448  bool
450 
458  bool
460 
470  bool
472 
480  bool
482 
499  bool is_signed = false,
500  bool is_integer = true,
501  bool is_complex = false);
502 
519  bool is_signed = false,
520  bool is_integer = true,
521  bool is_complex = false);
522 
528  template<typename T>
529  inline void
530  byteswap(T& value)
531  {
532  boost::endian::reverse(value);
533  }
534 
540  template<>
541  inline void
542  byteswap(std::complex<float>& value)
543  {
544  // For pre-C++11 compatibility, it's not possible to byteswap in
545  // place.
546  value = std::complex<float>(reverse_value(value.real()),
547  reverse_value(value.imag()));
548  }
549 
555  template<>
556  inline void
557  byteswap(std::complex<double>& value)
558  {
559  // For pre-C++11 compatibility, it's not possible to byteswap in
560  // place.
561  value = std::complex<double>(reverse_value(value.real()),
562  reverse_value(value.imag()));
563  }
564 
565  }
566 }
567 
568 #endif // OME_BIOFORMATS_PIXELPROPERTIES_H
569 
570 /*
571  * Local Variables:
572  * mode:C++
573  * End:
574  */
uint32
Definition: PixelType.h:86
boost::endian::little_int32_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:171
uint8
Definition: PixelType.h:82
boost::endian::native_int8_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:127
::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:397
Big endian.
Definition: Types.h:70
uint8_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:189
int32_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:166
bit
Definition: PixelType.h:90
Properties common to all pixel types.
Definition: PixelProperties.h:77
uint16_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:212
PixelProperties< P >::native_type type
Pixel type (native endian).
Definition: PixelProperties.h:407
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:219
Map a given PixelPropertiesType enum to the corresponding language types.
Definition: PixelProperties.h:61
int8
Definition: PixelType.h:76
bool std_type
Pixel type (standard language type).
Definition: PixelProperties.h:304
uint32_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:235
Native endian.
Definition: Types.h:72
boost::endian::native_float32_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:265
bool isInteger(::ome::xml::model::enums::PixelType pixeltype)
Check whether a PixelType is integer.
Definition: PixelProperties.cpp:236
double std_type
Pixel type (standard language type).
Definition: PixelProperties.h:281
bool isComplex(::ome::xml::model::enums::PixelType pixeltype)
Check whether a PixelType is complex.
Definition: PixelProperties.cpp:287
std::complex< boost::endian::big_float32_t > big_type
Pixel type (big endian).
Definition: PixelProperties.h:342
boost::endian::native_uint8_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:196
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:242
int16
Definition: PixelType.h:78
float std_type
Pixel type (standard language type).
Definition: PixelProperties.h:258
uint16
Definition: PixelType.h:84
std::complex< double > std_type
Pixel type (standard language type).
Definition: PixelProperties.h:362
std::complex< boost::endian::native_float32_t > native_type
Pixel type (native endian).
Definition: PixelProperties.h:346
ome::common::boolean big_type
Pixel type (big endian).
Definition: PixelProperties.h:307
static pixel_size_type pixel_bit_size()
Get size of pixel type, in bits.
Definition: PixelProperties.h:96
std::complex< boost::endian::little_float32_t > little_type
Pixel type (little endian).
Definition: PixelProperties.h:344
std::complex< boost::endian::big_float64_t > big_type
Pixel type (big endian).
Definition: PixelProperties.h:365
boost::endian::big_float32_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:261
boost::endian::native_int16_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:150
Endian-specific integer types.
boost::endian::native_int32_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:173
boost::endian::native_float64_t native_type
Pixel type (native endian).
Definition: PixelProperties.h:288
float
Definition: PixelType.h:88
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
boost::endian::little_uint16_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:217
boost::endian::little_uint8_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:194
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:238
bool isFloatingPoint(::ome::xml::model::enums::PixelType pixeltype)
Check whether a PixelType is floating point.
Definition: PixelProperties.cpp:281
bool isSigned(::ome::xml::model::enums::PixelType pixeltype)
Check whether a PixelType is signed.
Definition: PixelProperties.cpp:191
Little endian.
Definition: Types.h:71
complex
Definition: PixelType.h:94
static pixel_size_type pixel_significant_bit_size()
Get significant (maximum bits used) size of pixel type, in bits.
Definition: PixelProperties.h:108
PixelProperties< P >::little_type type
Pixel type (little endian).
Definition: PixelProperties.h:399
boost::endian::big_int8_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:123
void byteswap(T &value)
Byteswap value to switch endianness.
Definition: PixelProperties.h:530
::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:336
boost::endian::little_int16_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:148
boost::endian::little_int8_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:125
std::complex< float > std_type
Pixel type (standard language type).
Definition: PixelProperties.h:339
Map the given PixelPropertiesType and Endian enums to the corresponding endian-specific language type...
Definition: PixelProperties.h:384
boost::endian::big_int32_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:169
static pixel_size_type pixel_significant_bit_size()
Get significant (maximum bits used) size of pixel type, in bits.
Definition: PixelProperties.h:327
int8_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:120
boost::endian::little_float64_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:286
double
Definition: PixelType.h:92
pixel_size_type bytesPerPixel(::ome::xml::model::enums::PixelType pixeltype)
Get the size of a PixelType, in bytes.
Definition: PixelProperties.cpp:56
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:146
PixelType enumeration.
Definition: PixelType.h:69
Standard integer types.
boost::endian::big_uint16_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:215
int16_t std_type
Pixel type (standard language type).
Definition: PixelProperties.h:143
boost::endian::little_uint32_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:240
boost::endian::big_int16_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:146
static pixel_size_type pixel_byte_size()
Get size of pixel type, in bytes.
Definition: PixelProperties.h:85
boost::endian::little_float32_t little_type
Pixel type (little endian).
Definition: PixelProperties.h:263
boost::endian::big_uint8_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:192
ome::common::boolean little_type
Pixel type (little endian).
Definition: PixelProperties.h:309
ome::common::boolean native_type
Pixel type (native endian).
Definition: PixelProperties.h:311
int32
Definition: PixelType.h:80
std::complex< boost::endian::native_float64_t > native_type
Pixel type (native endian).
Definition: PixelProperties.h:369
boost::endian::big_float64_t big_type
Pixel type (big endian).
Definition: PixelProperties.h:284
PixelProperties< P >::big_type type
Pixel type (big endian).
Definition: PixelProperties.h:391
double-complex
Definition: PixelType.h:96
std::complex< boost::endian::little_float64_t > little_type
Pixel type (little endian).
Definition: PixelProperties.h:367