]> Creatis software - gdcm.git/commitdiff
POur traiter certaines (?) images Philips pour lesquelles le File Preamble
authorjpr <jpr>
Wed, 12 Mar 2003 13:09:00 +0000 (13:09 +0000)
committerjpr <jpr>
Wed, 12 Mar 2003 13:09:00 +0000 (13:09 +0000)
est suivi de l'elem (0002,0001) et non pas de l'elem (0002,0000)
-pas d'autre possibilité envisageable ...-
Peut-etre

src/Makefile.am
src/gdcmHeader.cxx
src/gdcmHeader.h

index c5506f186876a59277010ef355e49f04192dcdb4..ec064d88d81dc160a580f9f0f5af244495483a71 100644 (file)
@@ -26,7 +26,8 @@ libgdcm_la_SOURCES=           \
        gdcmDictSet.cxx   \
        gdcmElValSet.cxx  \
        gdcmHeaderIdo.cxx \
-       gdcmFile.cxx
+       gdcmFile.cxx    \
+       gdcmJpeg.cxx
 
 libgdcmincludedir = $(includedir)
 libgdcminclude_HEADERS =       \
@@ -34,4 +35,5 @@ libgdcminclude_HEADERS =      \
        gdcm.h          \
        gdcmException.h \
        gdcmIdo.h       \
-       gdcmUtil.h
+       gdcmUtil.h      \
+       iddcmjpeg.h
index 231b5bc4196a4af75b51695e5de8329c3c56a965..37b2e1ecbb4b57c88f20e7555ac2def7829a1263 100644 (file)
@@ -13,6 +13,8 @@
 #include "gdcmUtil.h"
 #include "gdcmHeader.h"
 
+#include <iddcmjpeg.h>
+
 // Refer to gdcmHeader::CheckSwap()
 #define HEADER_LENGTH_TO_READ       256
 // Refer to gdcmHeader::SetMaxSizeLoadElementValue()
@@ -128,8 +130,9 @@ void gdcmHeader::CheckSwap()
 
    if(filetype == TrueDicom) {
       // Next, determine the value representation (VR). Let's skip to the
-      // first element (0002, 0000) and check there if we find "UL", in
-      // which case we (almost) know it is explicit VR.
+      // first element (0002, 0000) and check there if we find "UL" 
+      // - or "OB" if the 1st one is (0002,0001) -,
+      // in which case we (almost) know it is explicit VR.
       // WARNING: if it happens to be implicit VR then what we will read
       // is the length of the group. If this ascii representation of this
       // length happens to be "UL" then we shall believe it is explicit VR.
@@ -139,10 +142,12 @@ void gdcmHeader::CheckSwap()
       // We need to skip :
       // * the 128 bytes of File Preamble (often padded with zeroes),
       // * the 4 bytes of "DICM" string,
-      // * the 4 bytes of the first tag (0002, 0000),
+      // * the 4 bytes of the first tag (0002, 0000),or (0002, 0001)
       // i.e. a total of  136 bytes.
       entCur = deb + 136;
-      if(memcmp(entCur, "UL", (size_t)2) == 0) {
+      if(  (memcmp(entCur, "UL", (size_t)2) == 0) ||
+          (memcmp(entCur, "OB", (size_t)2) == 0) )
+       {
          filetype = ExplicitVR;
          dbg.Verbose(1, "gdcmHeader::CheckSwap:",
                      "explicit Value Representation");
@@ -241,7 +246,11 @@ void gdcmHeader::GetPixels(size_t lgrTotale, void* _Pixels) {
    size_t pixelsOffset; 
    pixelsOffset = GetPixelOffset();
    fseek(fp, pixelsOffset, SEEK_SET);
-   fread(_Pixels, 1, lgrTotale, fp);
+   if (IsJPEGLossless()) {
+       _Pixels=_IdDcmJpegRead(fp);  
+   } else {
+       fread(_Pixels, 1, lgrTotale, fp);
+   }
 }
 
 
@@ -286,7 +295,7 @@ void gdcmHeader::FindVR( ElValue *ElVal) {
    // PostPone this test in an optional integrity check at the end
    // of parsing or only in debug mode.
    if ( RealExplicit && !dicom_vr->count(vr) )
-      RealExplicit = false;
+      RealExplicit= false;
 
    if ( RealExplicit ) {
       if ( ElVal->IsVrUnknown() ) {
@@ -393,7 +402,7 @@ bool gdcmHeader::IsExplicitVRBigEndianTransferSyntax(void) {
       return false;
    LoadElementValueSafe(Element);
    string Transfer = Element->GetValue();
-   if ( Transfer == "1.2.840.10008.1.2.2" )
+   if ( Transfer == "1.2.840.10008.1.2.2" )  //1.2.2 ??? A verifier !
       return true;
    return false;
 }
@@ -416,6 +425,20 @@ bool gdcmHeader::IsJPEGBaseLineProcess1TransferSyntax(void) {
    return false;
 }
 
+// faire qq chose d'intelligent a la place de ça
+
+bool gdcmHeader::IsJPEGLossless(void) {
+   ElValue* Element = PubElVals.GetElementByNumber(0x0002, 0x0010);
+   if ( !Element )
+      return false;
+   LoadElementValueSafe(Element);
+   const char * Transfert = Element->GetValue().c_str();
+   if ( memcmp(Transfert+strlen(Transfert)-2 ,"70",2)==0) return true;
+   if ( memcmp(Transfert+strlen(Transfert)-2 ,"55",2)==0) return true;
+   return false;
+}
+
+
 /**
  * \ingroup gdcmHeader
  * \brief   Determines if the Transfer Syntax was allready encountered
index 02c58ef6a9a3fafcb3b42cef66a7020a712eb909..fa33ebc8d039e96605688aedf330fcac8b02088b 100644 (file)
@@ -105,6 +105,8 @@ private:
    bool IsJPEGExtendedProcess2_4TransferSyntax(void); 
    bool IsJPEGExtendedProcess3_5TransferSyntax(void);
    bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void); 
+   
+   bool IsJPEGLossless(void); 
       
 protected:
    // FIXME: is this enum still necessary ??