-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.cxx,v 1.14 2003/10/27 14:01:12 jpr Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.cxx,v 1.17 2003/11/12 14:06:35 malaterre Exp $
#include "gdcmHeaderHelper.h"
#include "gdcmUtil.h" //for debug
#include <math.h>
#include <algorithm>
-#include <string.h> //for bzero
+//#include <string.h> //for bzero
//directory manipulation (os indep).
//cygwin ???? -> _WIN32 ??
*
*/
int gdcmHeaderHelper::GetPixelSize() {
+
+ // 0028 0100 US IMG Bits Allocated
+ // (in order no to be messed up by old RGB images)
+ if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24")
+ return 3;
+
std::string PixelType = GetPixelType();
if (PixelType == "8U" || PixelType == "8S")
return 1;
//----------------------------------------------------------------------------
/**
* \ingroup gdcmHeaderHelper
- * \brief gets the info from 0028,0004 : Photometric Interp
- * \ else 1.
- * @return 1 if Gray level, 3 if Color
+ * \brief This function is intended to user who doesn't whan
+ * \ to have to manage a LUT and expects to get an RBG Pixel image
+ * \ (or a monochrome one ...)
+ * \warning to be used with GetImagePixels()
+ * @return 1 if Gray level, 3 if Color (RGB, YBR or PALETTE COLOR)
*/
int gdcmHeaderHelper::GetNumberOfScalarComponents() {
- std::string PhotometricInterpretation =
- gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
-
-// The compiler will optimze, if it feels like !
-
- //beware of trailing space at end of string
- if (PhotometricInterpretation.find(GDCM_UNFOUND) < PhotometricInterpretation.length() ||
- PhotometricInterpretation.find("MONOCHROME1") < PhotometricInterpretation.length() ||
- PhotometricInterpretation.find("MONOCHROME2") < PhotometricInterpretation.length() ) return 1;
+ if (GetSamplesPerPixel() ==3)
+ return 3;
+
+ // 0028 0100 US IMG Bits Allocated
+ // (in order no to be messed up by old RGB images)
+ if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24")
+ return 3;
+
+ std::string PhotometricInterpretation =
+ gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
- // WARNING : quick and dirty trick to produce a single plane Grey image
- // See also gdcmFile::GetImageDataIntoVector()
- // if(GetPubElValVoidAreaByNumber(0x0028,0x1201)==NULL) return 1; // Lut Red
- // end of dirty trick
+ if ( ( PhotometricInterpretation == "PALETTE COLOR ") ) {
+ if (HasLUT()) // PALETTE COLOR is NOT enough
+ return 3;
+ else
+ return 1;
+ }
+
+ //beware of trailing space at end of string
+ if (PhotometricInterpretation.find(GDCM_UNFOUND) <
+ PhotometricInterpretation.length() ||
+ PhotometricInterpretation.find("MONOCHROME1") <
+ PhotometricInterpretation.length() ||
+ PhotometricInterpretation.find("MONOCHROME2") <
+ PhotometricInterpretation.length() )
+ return 1;
+ else
+ // we assume that *all* kinds of YBR are dealt with
+ return 3;
+}
+//----------------------------------------------------------------------------
+/**
+ * \ingroup gdcmHeaderHelper
+ * \brief This function is intended to user that DOESN'T want
+ * \to get RGB pixels image when it's stored as a PALETTE COLOR image
+ * \ - the (vtk) user is supposed to know how deal with LUTs -
+ * \warning to be used with GetImagePixelsRaw()
+ * @return 1 if Gray level, 3 if Color (RGB or YBR - NOT 'PALETTE COLOR' -)
+ */
+int gdcmHeaderHelper::GetNumberOfScalarComponentsRaw() {
+
+ // 0028 0100 US IMG Bits Allocated
+ // (in order no to be messed up by old RGB images)
+ if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24")
return 3;
+
+ // we assume that *all* kinds of YBR are dealt with
+ return GetSamplesPerPixel();
}
+
//----------------------------------------------------------------------------
/**
* \ingroup gdcmHeaderHelper
* - 32U unsigned 32 bit,
* - 32S signed 32 bit,
* \warning 12 bit images appear as 16 bit.
+ * \ 24 bit images appear as 8 bit
* @return
*/
std::string gdcmHeaderHelper::GetPixelType() {
dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
BitsAlloc = std::string("16");
}
- if (BitsAlloc == "12")
+ if (BitsAlloc == "12") // It will be unpacked
BitsAlloc = std::string("16");
-
+ else if (BitsAlloc == "24") // (in order no to be messed up
+ BitsAlloc = std::string("8"); // by old RGB images)
+
std::string Signed;
Signed = GetElValByName("Pixel Representation");
if (Signed == GDCM_UNFOUND) {
{
return GetPubElValByNumber(0x0008,0x0018); //0008 0018 UI ID SOP Instance UID
}
+//----------------------------------------------------------------------------
+float gdcmHeaderHelper::GetRescaleIntercept()
+{
+ float resInter = 0.;
+ std::string StrRescInter = GetPubElValByNumber(0x0028,0x1052); //0028 1052 DS IMG Rescale Intercept
+ if (StrRescInter != GDCM_UNFOUND) {
+ if( sscanf( StrRescInter.c_str(), "%f", &resInter) != 1) {
+ dbg.Verbose(0, "gdcmHeader::GetRescaleIntercept: Rescale Slope is empty");
+ // bug in the element 0x0028,0x1052
+ }
+ }
+ return resInter;
+}
+//----------------------------------------------------------------------------
+float gdcmHeaderHelper::GetRescaleSlope()
+{
+ float resSlope = 1.;
+ std::string StrRescSlope = GetPubElValByNumber(0x0028,0x1053); //0028 1053 DS IMG Rescale Slope
+ if (StrRescSlope != GDCM_UNFOUND) {
+ if( sscanf( StrRescSlope.c_str(), "%f", &resSlope) != 1) {
+ dbg.Verbose(0, "gdcmHeader::GetRescaleSlope: Rescale Slope is empty");
+ // bug in the element 0x0028,0x1053
+ }
+ }
+ return resSlope;
+}