]> Creatis software - gdcm.git/blobdiff - src/gdcmHeader.cxx
* When compiling with distutils (see setup.py) the C++ compiler is
[gdcm.git] / src / gdcmHeader.cxx
index d98074f56aea75c3da92ba280bee6fb97edce8ef..29955e13029d535e3746bba7de03d1aabe8dcc59 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.68 2003/05/28 19:36:21 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;
 }
 
@@ -713,7 +714,6 @@ void gdcmHeader::SetMaxSizeLoadElementValue(long NewSize) {
 void gdcmHeader::LoadElementValue(gdcmElValue * ElVal) {
    size_t item_read;
    guint16 group  = ElVal->GetGroup();
-   guint16 elem   = ElVal->GetElement();
    string  vr     = ElVal->GetVR();
    guint32 length = ElVal->GetLength();
    bool SkipLoad  = false;
@@ -1440,18 +1440,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;
@@ -1545,11 +1563,11 @@ void gdcmHeader::LoadElements(void) {
       }
 }
 
-void gdcmHeader::PrintPubElVal(ostream & os) {
+void gdcmHeader::PrintPubElVal(std::ostream & os) {
    PubElValSet.Print(os);
 }
 
-void gdcmHeader::PrintPubDict(ostream & os) {
+void gdcmHeader::PrintPubDict(std::ostream & os) {
    RefPubDict->Print(os);
 }