gdcmPixelFormat.h
Go to the documentation of this file.
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef GDCMPIXELFORMAT_H
#define GDCMPIXELFORMAT_H
#include "gdcmTypes.h"
#include <iostream>
#include <assert.h>
namespace gdcm
{
class TransferSyntax;
class GDCM_EXPORT PixelFormat
{
friend class Bitmap;
friend std::ostream& operator<<(std::ostream &_os, const PixelFormat &pf);
public:
// When adding a type please add its dual type (its unsigned counterpart)
typedef enum {
UINT8,
INT8,
UINT12,
INT12,
UINT16,
INT16,
UINT32, // For some DICOM files (RT or SC)
INT32, // " "
UINT64, // Needed when input is 32bits + intercept/slope (incomplete support)
INT64, // " "
FLOAT16, // sure why not...
FLOAT32, // good ol' 'float'
FLOAT64, // aka 'double'
SINGLEBIT, // bool / monochrome
UNKNOWN // aka BitsAllocated == 0 && PixelRepresentation == 0
} ScalarType;
// default cstor:
PixelFormat () : PixelFormat(1, 8, 8, 7, 0) {}
explicit PixelFormat (
unsigned short samplesperpixel,
unsigned short bitsallocated = 8,
unsigned short bitsstored = 8,
unsigned short highbit = 7,
unsigned short pixelrepresentation = 0 ) :
SamplesPerPixel(samplesperpixel),
BitsAllocated(bitsallocated),
BitsStored(bitsstored),
HighBit(highbit),
PixelRepresentation(pixelrepresentation) {}
// helper, for the common case
PixelFormat(ScalarType st);
// For transparency of use
operator ScalarType() const { return GetScalarType(); }
unsigned short GetSamplesPerPixel() const;
void SetSamplesPerPixel(unsigned short spp)
{
gdcmAssertMacro( spp <= 4 );
SamplesPerPixel = spp;
assert( SamplesPerPixel == 1 || SamplesPerPixel == 3 || SamplesPerPixel == 4 );
}
unsigned short GetBitsAllocated() const
{
return BitsAllocated;
}
void SetBitsAllocated(unsigned short ba)
{
if( ba )
{
switch( ba )
{
/* some devices (FUJIFILM CR + MONO1) incorrectly set BitsAllocated/BitsStored
* as bitmask instead of value. Do what they mean instead of what they say.
*/
case 0xffff: ba = 16; break;
case 0x0fff: ba = 12; break;
case 0x00ff: ba = 8; break;
}
BitsAllocated = ba;
BitsStored = ba;
HighBit = (unsigned short)(ba - 1);
}
else // Make the PixelFormat as UNKNOWN
{
BitsAllocated = 0;
PixelRepresentation = 0;
}
}
unsigned short GetBitsStored() const
{
assert( BitsStored <= BitsAllocated );
return BitsStored;
}
void SetBitsStored(unsigned short bs)
{
switch( bs )
{
/* see SetBitsAllocated for explanation
*/
case 0xffff: bs = 16; break;
case 0x0fff: bs = 12; break;
case 0x00ff: bs = 8; break;
}
if( bs <= BitsAllocated && bs )
{
BitsStored = bs;
SetHighBit( (unsigned short) (bs - 1) );
}
}
unsigned short GetHighBit() const
{
assert( HighBit < BitsStored );
return HighBit;
}
void SetHighBit(unsigned short hb)
{
switch( hb )
{
/* broken implementations that use bitmask for BitsAllocated/Stored
* nonetheless use (BitsStored-1) for HighBit. correct for this here.
*/
case 0xfffe: hb = 15; break;
case 0x0ffe: hb = 11; break;
case 0x00fe: hb = 7; break;
}
if( hb < BitsStored )
HighBit = hb;
}
unsigned short GetPixelRepresentation() const
{
return (unsigned short)(PixelRepresentation ? 1 : 0);
}
void SetPixelRepresentation(unsigned short pr)
{
PixelRepresentation = (unsigned short)(pr ? 1 : 0);
}
ScalarType GetScalarType() const;
void SetScalarType(ScalarType st);
const char *GetScalarTypeAsString() const;
uint8_t GetPixelSize() const;
void Print(std::ostream &os) const;
int64_t GetMin() const;
int64_t GetMax() const;
bool IsValid() const;
bool operator==(ScalarType st) const
{
return GetScalarType() == st;
}
bool operator!=(ScalarType st) const
{
return GetScalarType() != st;
}
bool operator==(const PixelFormat &pf) const
{
return
SamplesPerPixel == pf.SamplesPerPixel &&
BitsAllocated == pf.BitsAllocated &&
BitsStored == pf.BitsStored &&
HighBit == pf.HighBit &&
PixelRepresentation == pf.PixelRepresentation;
}
bool operator!=(const PixelFormat &pf) const
{
return
SamplesPerPixel != pf.SamplesPerPixel ||
BitsAllocated != pf.BitsAllocated ||
BitsStored != pf.BitsStored ||
HighBit != pf.HighBit ||
PixelRepresentation != pf.PixelRepresentation;
}
bool IsCompatible(const TransferSyntax & ts ) const;
protected:
bool Validate();
private:
// D 0028|0002 [US] [Samples per Pixel] [1]
unsigned short SamplesPerPixel;
// D 0028|0100 [US] [Bits Allocated] [8]
unsigned short BitsAllocated;
// D 0028|0101 [US] [Bits Stored] [8]
unsigned short BitsStored;
// D 0028|0102 [US] [High Bit] [7]
unsigned short HighBit;
// D 0028|0103 [US] [Pixel Representation] [0]
unsigned short PixelRepresentation;
};
//-----------------------------------------------------------------------------
inline std::ostream& operator<<(std::ostream &os, const PixelFormat &pf)
{
pf.Print( os );
return os;
}
} // end namespace gdcm
#endif //GDCMPIXELFORMAT_H
gdcm::PixelFormat::IsCompatible
bool IsCompatible(const TransferSyntax &ts) const
gdcm::PixelFormat::Bitmap
friend class Bitmap
Definition gdcmPixelFormat.h:47
gdcm::PixelFormat::PixelFormat
PixelFormat(unsigned short samplesperpixel, unsigned short bitsallocated=8, unsigned short bitsstored=8, unsigned short highbit=7, unsigned short pixelrepresentation=0)
Definition gdcmPixelFormat.h:72
gdcm::PixelFormat::SetScalarType
void SetScalarType(ScalarType st)
gdcm::PixelFormat::operator!=
bool operator!=(ScalarType st) const
Definition gdcmPixelFormat.h:213
gdcm::PixelFormat::SetBitsStored
void SetBitsStored(unsigned short bs)
Definition gdcmPixelFormat.h:134
gdcm::PixelFormat::GetSamplesPerPixel
unsigned short GetSamplesPerPixel() const
gdcm::PixelFormat::GetPixelRepresentation
unsigned short GetPixelRepresentation() const
PixelRepresentation: 0 or 1, see Tag (0028,0103) US Pixel Representation.
Definition gdcmPixelFormat.h:173
gdcm::PixelFormat::SetSamplesPerPixel
void SetSamplesPerPixel(unsigned short spp)
Definition gdcmPixelFormat.h:92
gdcm::PixelFormat::GetPixelSize
uint8_t GetPixelSize() const
gdcm::PixelFormat::PixelFormat
PixelFormat(ScalarType st)
gdcm::PixelFormat::GetScalarTypeAsString
const char * GetScalarTypeAsString() const
gdcm::PixelFormat::SetHighBit
void SetHighBit(unsigned short hb)
Definition gdcmPixelFormat.h:157
gdcm::PixelFormat::SetBitsAllocated
void SetBitsAllocated(unsigned short ba)
Definition gdcmPixelFormat.h:104
gdcm::PixelFormat::operator!=
bool operator!=(const PixelFormat &pf) const
Definition gdcmPixelFormat.h:226
gdcm::PixelFormat::Print
void Print(std::ostream &os) const
Print.
gdcm::PixelFormat::Validate
bool Validate()
When image with 24/24/23 was read, need to validate.
gdcm::PixelFormat::GetMax
int64_t GetMax() const
return the max possible of the pixel
gdcm::PixelFormat::operator<<
friend std::ostream & operator<<(std::ostream &_os, const PixelFormat &pf)
Definition gdcmPixelFormat.h:254
gdcm::PixelFormat::PixelFormat
PixelFormat()
Definition gdcmPixelFormat.h:70
gdcm::PixelFormat::GetHighBit
unsigned short GetHighBit() const
HighBit see Tag (0028,0102) US High Bit.
Definition gdcmPixelFormat.h:152
gdcm::PixelFormat::GetBitsAllocated
unsigned short GetBitsAllocated() const
BitsAllocated see Tag (0028,0100) US Bits Allocated.
Definition gdcmPixelFormat.h:100
gdcm::PixelFormat::operator==
bool operator==(const PixelFormat &pf) const
Definition gdcmPixelFormat.h:217
gdcm::PixelFormat::operator==
bool operator==(ScalarType st) const
Definition gdcmPixelFormat.h:209
gdcm::PixelFormat::GetBitsStored
unsigned short GetBitsStored() const
BitsStored see Tag (0028,0101) US Bits Stored.
Definition gdcmPixelFormat.h:129
gdcm::PixelFormat::ScalarType
ScalarType
Definition gdcmPixelFormat.h:51
gdcm::PixelFormat::UINT32
@ UINT32
Definition gdcmPixelFormat.h:58
gdcm::PixelFormat::INT32
@ INT32
Definition gdcmPixelFormat.h:59
gdcm::PixelFormat::UNKNOWN
@ UNKNOWN
Definition gdcmPixelFormat.h:66
gdcm::PixelFormat::INT8
@ INT8
Definition gdcmPixelFormat.h:53
gdcm::PixelFormat::FLOAT32
@ FLOAT32
Definition gdcmPixelFormat.h:63
gdcm::PixelFormat::SINGLEBIT
@ SINGLEBIT
Definition gdcmPixelFormat.h:65
gdcm::PixelFormat::INT12
@ INT12
Definition gdcmPixelFormat.h:55
gdcm::PixelFormat::FLOAT64
@ FLOAT64
Definition gdcmPixelFormat.h:64
gdcm::PixelFormat::FLOAT16
@ FLOAT16
Definition gdcmPixelFormat.h:62
gdcm::PixelFormat::UINT8
@ UINT8
Definition gdcmPixelFormat.h:52
gdcm::PixelFormat::UINT12
@ UINT12
Definition gdcmPixelFormat.h:54
gdcm::PixelFormat::UINT64
@ UINT64
Definition gdcmPixelFormat.h:60
gdcm::PixelFormat::UINT16
@ UINT16
Definition gdcmPixelFormat.h:56
gdcm::PixelFormat::INT16
@ INT16
Definition gdcmPixelFormat.h:57
gdcm::PixelFormat::INT64
@ INT64
Definition gdcmPixelFormat.h:61
gdcm::PixelFormat::GetScalarType
ScalarType GetScalarType() const
ScalarType does not take into account the sample per pixel.
gdcm::PixelFormat::IsValid
bool IsValid() const
return IsValid
gdcm::PixelFormat::SetPixelRepresentation
void SetPixelRepresentation(unsigned short pr)
Definition gdcmPixelFormat.h:177
gdcm::PixelFormat::GetMin
int64_t GetMin() const
return the min possible of the pixel
gdcm::TransferSyntax
Class to manipulate Transfer Syntax.
Definition gdcmTransferSyntax.h:40
gdcmAssertMacro
#define gdcmAssertMacro(arg)
Assert.
Definition gdcmTrace.h:189
gdcmTypes.h
GDCM_EXPORT
#define GDCM_EXPORT
Definition gdcmWin32.h:34
gdcm
Definition gdcmASN1.h:21
gdcm::operator<<
std::ostream & operator<<(std::ostream &os, const Directory &d)
Definition gdcmDirectory.h:88