+/**
+ * \brief Retrieve the high bit position.
+ * \warning The method defaults to 0 when information is missing.
+ * The responsability of checking this value is left to the caller.
+ * @return The high bit position when present. 0 when missing.
+ */
+int File::GetHighBitPosition()
+{
+ std::string strSize = GetEntryValue( 0x0028, 0x0102 );
+ if ( strSize == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "(0028,0102) is supposed to be mandatory");
+ return 0;
+ }
+ return atoi( strSize.c_str() );
+}
+
+/**
+ * \brief Retrieve the number of Samples Per Pixel
+ * (1 : gray level, 3 : RGB/YBR -1 or 3 Planes-)
+ * @return The encountered number of Samples Per Pixel, 1 by default.
+ * (we assume Gray level Pixels)
+ */
+int File::GetSamplesPerPixel()
+{
+ const std::string &strSize = GetEntryValue(0x0028,0x0002);
+ if ( strSize == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "(0028,0002) is supposed to be mandatory");
+ return 1; // Well, it's supposed to be mandatory ...
+ // but sometimes it's missing : *we* assume Gray pixels
+ }
+ return atoi( strSize.c_str() );
+}
+
+/**
+ * \brief Retrieve the Planar Configuration for RGB images
+ * (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane)
+ * @return The encountered Planar Configuration, 0 by default.
+ */
+int File::GetPlanarConfiguration()
+{
+ std::string strSize = GetEntryValue(0x0028,0x0006);
+ if ( strSize == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Not found : Planar Configuration (0028,0006)");
+ return 0;
+ }
+ return atoi( strSize.c_str() );
+}
+
+/**
+ * \brief Return the size (in bytes) of a single pixel of data.
+ * @return The size in bytes of a single pixel of data; 0 by default
+ * 0 means the file is NOT USABLE; the caller will have to check
+ */
+int File::GetPixelSize()
+{
+ // 0028 0100 US IMG Bits Allocated
+ // (in order no to be messed up by old ACR-NEMA RGB images)
+ // if (File::GetEntryValue(0x0028,0x0100) == "24")
+ // return 3;
+
+ std::string pixelType = GetPixelType();
+ if ( pixelType == "8U" || pixelType == "8S" )
+ {
+ return 1;
+ }
+ if ( pixelType == "16U" || pixelType == "16S")
+ {
+ return 2;
+ }
+ if ( pixelType == "32U" || pixelType == "32S")
+ {
+ return 4;
+ }
+ if ( pixelType == "FD" )
+ {
+ return 8;
+ }
+ gdcmWarningMacro( "Unknown pixel type");
+ return 0;
+}
+
+/**
+ * \brief Build the Pixel Type of the image.
+ * Possible values are:
+ * - 8U unsigned 8 bit,
+ * - 8S signed 8 bit,
+ * - 16U unsigned 16 bit,
+ * - 16S signed 16 bit,
+ * - 32U unsigned 32 bit,
+ * - 32S signed 32 bit,
+ * - FD floating double 64 bits (Not kosher DICOM, but so usefull!)
+ * \warning 12 bit images appear as 16 bit.
+ * 24 bit images appear as 8 bit + photochromatic interp ="RGB "
+ * + Planar Configuration = 0
+ * @return 0S if nothing found. NOT USABLE file. The caller has to check
+ */
+std::string File::GetPixelType()
+{
+ std::string bitsAlloc = GetEntryValue(0x0028, 0x0100); // Bits Allocated
+ if ( bitsAlloc == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Missing Bits Allocated (0028,0100)");
+ bitsAlloc = "16"; // default and arbitrary value, not to polute the output
+ }
+
+ if ( bitsAlloc == "64" )
+ {
+ return "FD";
+ }
+ else if ( bitsAlloc == "12" )
+ {
+ // It will be unpacked
+ bitsAlloc = "16";
+ }
+ else if ( bitsAlloc == "24" )
+ {
+ // (in order no to be messed up by old RGB images)
+ bitsAlloc = "8";
+ }
+
+ std::string sign = GetEntryValue(0x0028, 0x0103);//"Pixel Representation"
+
+ if (sign == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Missing Pixel Representation (0028,0103)");
+ sign = "U"; // default and arbitrary value, not to polute the output
+ }
+ else if ( sign == "0" )
+ {
+ sign = "U";
+ }
+ else
+ {
+ sign = "S";
+ }
+ return bitsAlloc + sign;
+}
+
+/**
+ * \brief Check whether the pixels are signed (1) or UNsigned (0) data.
+ * \warning The method defaults to false (UNsigned) when tag 0028|0103
+ * is missing.
+ * The responsability of checking this value is left to the caller
+ * (NO transformation is performed on the pixels to make then >0)
+ * @return True when signed, false when UNsigned
+ */
+bool File::IsSignedPixelData()
+{
+ std::string strSign = GetEntryValue( 0x0028, 0x0103 );
+ if ( strSign == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "(0028,0103) is supposed to be mandatory");
+ return false;
+ }
+ int sign = atoi( strSign.c_str() );
+ if ( sign == 0 )
+ {
+ return false;
+ }
+ return true;
+}
+
+/**
+ * \brief Check whether this a monochrome picture (gray levels) or not,
+ * using "Photometric Interpretation" tag (0x0028,0x0004).
+ * @return true when "MONOCHROME1" or "MONOCHROME2". False otherwise.
+ */
+bool File::IsMonochrome()
+{
+ const std::string &PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
+ if ( Util::DicomStringEqual(PhotometricInterp, "MONOCHROME1")
+ || Util::DicomStringEqual(PhotometricInterp, "MONOCHROME2") )
+ {
+ return true;
+ }
+ if ( PhotometricInterp == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Not found : Photometric Interpretation (0028,0004)");
+ }
+ return false;
+}
+
+/**
+ * \brief Check whether this a MONOCHROME1 picture (high values = dark)
+ * or not using "Photometric Interpretation" tag (0x0028,0x0004).
+ * @return true when "MONOCHROME1" . False otherwise.
+ */
+bool File::IsMonochrome1()
+{
+ const std::string &PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
+ if ( Util::DicomStringEqual(PhotometricInterp, "MONOCHROME1") )
+ {
+ return true;
+ }
+ if ( PhotometricInterp == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Not found : Photometric Interpretation (0028,0004)");
+ }
+ return false;
+}
+
+/**
+ * \brief Check whether this a "PALETTE COLOR" picture or not by accessing
+ * the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
+ * @return true when "PALETTE COLOR". False otherwise.
+ */
+bool File::IsPaletteColor()
+{
+ std::string PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
+ if ( PhotometricInterp == "PALETTE COLOR " )
+ {
+ return true;
+ }
+ if ( PhotometricInterp == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Not found : Palette color (0028,0004)");
+ }
+ return false;
+}
+
+/**
+ * \brief Check whether this a "YBR_FULL" color picture or not by accessing
+ * the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
+ * @return true when "YBR_FULL". False otherwise.
+ */
+bool File::IsYBRFull()
+{
+ std::string PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
+ if ( PhotometricInterp == "YBR_FULL" )
+ {
+ return true;
+ }
+ if ( PhotometricInterp == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Not found : YBR Full (0028,0004)");
+ }
+ return false;
+}
+
+/**
+ * \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
+ * Please warn me if you know sbdy that *does* know ... jprx
+ * @return true if LUT Descriptors and LUT Tables were found
+ */
+bool File::HasLUT()
+{
+ // Check the presence of the LUT Descriptors, and LUT Tables
+ // LutDescriptorRed
+ if ( !GetDocEntry(0x0028,0x1101) )
+ {
+ return false;
+ }
+ // LutDescriptorGreen
+ if ( !GetDocEntry(0x0028,0x1102) )
+ {
+ return false;
+ }
+ // LutDescriptorBlue
+ if ( !GetDocEntry(0x0028,0x1103) )
+ {
+ return false;
+ }
+ // Red Palette Color Lookup Table Data
+ if ( !GetDocEntry(0x0028,0x1201) )
+ {
+ return false;
+ }
+ // Green Palette Color Lookup Table Data
+ if ( !GetDocEntry(0x0028,0x1202) )
+ {
+ return false;
+ }
+ // Blue Palette Color Lookup Table Data
+ if ( !GetDocEntry(0x0028,0x1203) )
+ {
+ return false;
+ }
+
+ // FIXME : (0x0028,0x3006) : LUT Data (CTX dependent)
+ // NOT taken into account, but we don't know how to use it ...
+ return true;
+}
+
+/**
+ * \brief gets the info from 0028,1101 : Lookup Table Desc-Red
+ * else 0
+ * @return Lookup Table number of Bits , 0 by default
+ * when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
+ * @ return bit number of each LUT item
+ */
+int File::GetLUTNbits()
+{
+ std::vector<std::string> tokens;
+ int lutNbits;
+
+ //Just hope Lookup Table Desc-Red = Lookup Table Desc-Red
+ // = Lookup Table Desc-Blue
+ // Consistency already checked in GetLUTLength
+ std::string lutDescription = GetEntryValue(0x0028,0x1101);
+ if ( lutDescription == GDCM_UNFOUND )
+ {
+ return 0;
+ }
+
+ tokens.clear(); // clean any previous value
+ Util::Tokenize ( lutDescription, tokens, "\\" );
+ //LutLength=atoi(tokens[0].c_str());
+ //LutDepth=atoi(tokens[1].c_str());
+
+ lutNbits = atoi( tokens[2].c_str() );
+ tokens.clear();
+
+ return lutNbits;
+}
+
+/**
+ *\brief gets the info from 0028,1052 : Rescale Intercept
+ * @return Rescale Intercept
+ */
+float File::GetRescaleIntercept()
+{
+ float resInter = 0.;
+ /// 0028 1052 DS IMG Rescale Intercept
+ const std::string &strRescInter = GetEntryValue(0x0028,0x1052);
+ if ( strRescInter != GDCM_UNFOUND )
+ {
+ if ( sscanf( strRescInter.c_str(), "%f ", &resInter) != 1 )
+ {
+ // bug in the element 0x0028,0x1052
+ gdcmWarningMacro( "Rescale Intercept (0028,1052) is empty." );
+ }
+ }
+
+ return resInter;
+}
+
+/**
+ *\brief gets the info from 0028,1053 : Rescale Slope
+ * @return Rescale Slope
+ */
+float File::GetRescaleSlope()
+{
+ float resSlope = 1.;
+ //0028 1053 DS IMG Rescale Slope
+ std::string strRescSlope = GetEntryValue(0x0028,0x1053);
+ if ( strRescSlope != GDCM_UNFOUND )
+ {
+ if ( sscanf( strRescSlope.c_str(), "%f ", &resSlope) != 1 )
+ {
+ // bug in the element 0x0028,0x1053
+ gdcmWarningMacro( "Rescale Slope (0028,1053) is empty.");