// from Lut R + Lut G + Lut B
unsigned char * newDest = (unsigned char *)malloc(lgrTotale);
- unsigned char * a = (unsigned char *)destination;
-
+ unsigned char * a = (unsigned char *)destination;
unsigned char * lutRGBA = (unsigned char *)GetLUTRGBA();
-
if (lutRGBA) {
int l = lgrTotale/3;
memmove(newDest, destination, l);// move Gray pixels to temp area
*a++ = lutRGBA[j+2];
}
free(newDest);
+
+ // now, it's an RGB image
+ // Lets's write it in the Header
+
+ // CreateOrReplaceIfExist ?
+
+ std::string spp = "3"; // Samples Per Pixel
+ gdcmHeader::SetPubElValByNumber(spp,0x0028,0x0002);
+ std::string rgb= "RGB "; // Photometric Interpretation
+ gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);
+ std::string planConfig = "0"; // Planar Configuration
+ gdcmHeader::SetPubElValByNumber(planConfig,0x0028,0x0006);
+
} else {
// need to make RGB Pixels (?)
// No idea how to manage it
// It seems that *no Dicom Viewer* has any idea :-(
// Segmented xxx Palette Color are *more* than 65535 long ?!?
+
+ std::string rgb= "MONOCHROME1 "; // Photometric Interpretation
+ gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);
+
}
-
- // now, it's an RGB image
- // Lets's write it in the Header
-
- // CreateOrReplaceIfExist ?
-
- std::string spp = "3"; // Samples Per Pixel
- gdcmHeader::SetPubElValByNumber(spp,0x0028,0x0002);
- std::string rgb="RGB "; // Photometric Interpretation
- gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);
- std::string planConfig = "0"; // Planar Configuration
- gdcmHeader::SetPubElValByNumber(planConfig,0x0028,0x0006);
-
+
// TODO : Drop Palette Color out of the Header?
return lgrTotale;
-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.106 2003/10/31 11:29:59 malaterre Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.107 2003/11/03 10:49:31 jpr Exp $
#include "gdcmHeader.h"
/**
* \ingroup gdcmHeader
* \brief Retrieve the number of Samples Per Pixel
- * (1 : gray level, 3 : RGB)
+ * (1 : gray level, 3 : RGB -1 or 3 Planes-)
*
* @return The encountered number of Samples Per Pixel, 1 by default.
*/
* - 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 gdcmHeader::GetPixelType(void) {
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) {
if (Signed == "0")
Signed = std::string("U");
else
+
+std::cout << "GetPixelType : " << BitsAlloc + Signed << std::endl;
Signed = std::string("S");
return( BitsAlloc + Signed);
/**
* \ingroup gdcmHeader
* \brief tells us if LUT are used
+ * \warning Right now, Segmented xxx Palette Color Lookup Table Data
+ * \ are NOT considered as LUT, since nobody knows
+ *\ how to deal with them
* @return int acts as a Boolean
*/
int gdcmHeader::HasLUT(void) {
- // Just hope checking the presence of the LUT Descriptors is enough
+ // Check the presence of the LUT Descriptors
if (GetPubElValByNumber(0x0028,0x1101) == GDCM_UNFOUND)
return 0;
// LutDescriptorGreen
return 0;
// LutDescriptorBlue
if (GetPubElValByNumber(0x0028,0x1103) == GDCM_UNFOUND)
+ return 0;
+ // It is not enough
+ // we check also
+ if (GetPubElValByNumber(0x0028,0x1201) == GDCM_UNFOUND)
return 0;
+ if (GetPubElValByNumber(0x0028,0x1202) == GDCM_UNFOUND)
+ return 0;
+ if (GetPubElValByNumber(0x0028,0x1203) == GDCM_UNFOUND)
+ return 0;
return 1;
}
// if it works, we shall have to check the 3 Palettes
// to see which byte is ==0 (first one, or second one)
// and fix the code
- // We give up the checking to avoid some overhead
+ // We give up the checking to avoid some overhead
+
char *a;
int i;
a= LUTRGBA+0;
*a = 1; // Alpha component
a+=4;
}
-
-// WHY does it seg fault ?!?
-//free(LutR); free(LutB); free(LutG); printf ("libere\n");
+
+//How to free the now useless LUTs?
+//
+//free(LutR); free(LutB); free(LutG);
return(LUTRGBA);
}
-// $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.15 2003/11/03 10:49:31 jpr Exp $
#include "gdcmHeaderHelper.h"
*
*/
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) {
-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.h,v 1.4 2003/10/03 14:26:11 jpr Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.h,v 1.5 2003/11/03 10:49:31 jpr Exp $
#ifndef GDCMHEADERHELPER_H
#define GDCMHEADERHELPER_H
float GetZSpacing();
int GetNumberOfScalarComponents();
+ int GetNumberOfScalarComponentsRaw();
std::string GetStudyUID();
std::string GetSeriesUID();