]> Creatis software - gdcm.git/blobdiff - src/gdcmHeader.cxx
* src/*.[h] all occurences of stl classes are now prefixed with
[gdcm.git] / src / gdcmHeader.cxx
index d98074f56aea75c3da92ba280bee6fb97edce8ef..48ebc838cdc147dde91f50c9acb648e5ebe91f52 100644 (file)
@@ -1,4 +1,4 @@
-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.62 2003/05/06 15:52:13 jpr Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.66 2003/05/21 14:42:46 frog Exp $
 
 #include <stdio.h>
 #include <cerrno>
@@ -12,6 +12,7 @@
 #include <sstream>
 #include "gdcmUtil.h"
 #include "gdcmHeader.h"
+using namespace std;
 
 // Refer to gdcmHeader::CheckSwap()
 #define HEADER_LENGTH_TO_READ       256
@@ -29,7 +30,8 @@ gdcmHeader::gdcmHeader(const char *InFilename, bool exception_on_error) {
   SetMaxSizeLoadElementValue(_MaxSizeLoadElementValue_);
   filename = InFilename;
   Initialise();
-  OpenFile(exception_on_error);
+  if ( !OpenFile(exception_on_error))
+     return;
   ParseHeader();
   LoadElements();
   CloseFile();
@@ -42,10 +44,9 @@ bool gdcmHeader::OpenFile(bool exception_on_error)
     if(!fp)
       throw gdcmFileError("gdcmHeader::gdcmHeader(const char *, bool)");
   }
-  else
-    dbg.Error(!fp, "gdcmHeader::gdcmHeader cannot open file", filename.c_str());
   if ( fp )
      return true;
+  dbg.Verbose(0, "gdcmHeader::gdcmHeader cannot open file", filename.c_str());
   return false;
 }
 
@@ -1440,18 +1441,36 @@ int gdcmHeader::GetZSize(void) {
    return 1;
 }
 
+/**
+ * \ingroup gdcmHeader
+ * \brief   Return the size (in bytes) of a single pixel of data.
+ * @return  The size in bytes of a single pixel of data.
+ *
+ */
+int gdcmHeader::GetPixelSize(void) {
+   string PixelType = GetPixelType();
+   if (PixelType == "8U" || PixelType == "8S")
+      return 1;
+   if (PixelType == "16U" || PixelType == "16S")
+      return 2;
+   if (PixelType == "32U" || PixelType == "32S")
+      return 4;
+   dbg.Verbose(0, "gdcmHeader::GetPixelSize: Unknown pixel type");
+   return 0;
+}
+
 /**
  * \ingroup gdcmHeader
  * \brief   Build the Pixel Type of the image.
  *          Possible values are:
- *          - U8  unsigned  8 bit,
- *          - S8    signed  8 bit,
- *          - U16 unsigned 16 bit,
- *          - S16   signed 16 bit,
- *          - U32 unsigned 32 bit,
- *          - S32   signed 32 bit,
+ *          - 8U  unsigned  8 bit,
+ *          - 8S    signed  8 bit,
+ *          - 16U unsigned 16 bit,
+ *          - 16S   signed 16 bit,
+ *          - 32U unsigned 32 bit,
+ *          - 32S   signed 32 bit,
  * \warning 12 bit images appear as 16 bit.
- * @return 
+ * @return  
  */
 string gdcmHeader::GetPixelType(void) {
    string BitsAlloc;