]> Creatis software - gdcm.git/blobdiff - src/gdcmPixelReadConvert.cxx
Autogenerated misstyping after system crash ?!???
[gdcm.git] / src / gdcmPixelReadConvert.cxx
index a80e759c4ebf81c7fac2147e4510bb720933e4dd..b31cfa9c307f8efaf71c137ac86aef793bc66154 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmPixelReadConvert.cxx,v $
   Language:  C++
-  Date:      $Date: 2006/08/29 15:17:51 $
-  Version:   $Revision: 1.113 $
+  Date:      $Date: 2007/09/04 13:42:57 $
+  Version:   $Revision: 1.120 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -32,7 +32,7 @@
    #include <mem.h> // for memset
 #endif 
 
-namespace gdcm
+namespace GDCM_NAME_SPACE
 {
 
 //bool ReadMPEGFile (std::ifstream *fp, char *inputdata, size_t lenght); 
@@ -97,11 +97,11 @@ void PixelReadConvert::GrabInformationsFromFile( File *file,
    {
       BitsAllocated = 16;
    }
-   else if (BitsAllocated > 8 && BitsAllocated < 16)
+
+   else if (BitsAllocated > 8 && BitsAllocated < 16 && BitsAllocated != 12)
    {
       BitsAllocated = 16;
    }   
-
    // Number of "Bits Stored", defaulted to number of "Bits Allocated"
    // when absent from the file.
    BitsStored = file->GetBitsStored();
@@ -170,7 +170,7 @@ void PixelReadConvert::GrabInformationsFromFile( File *file,
             if( IsJPEG2000      = Global::GetTS()->IsJPEG2000(ts) )     break;
             if( IsMPEG          = Global::GetTS()->IsMPEG(ts) )         break;
             if( IsJPEGLS        = Global::GetTS()->IsJPEGLS(ts) )       break;
-            // DeflatedExplicitVRLittleEndian is considered as 'Unexpected' (we don't know yet haow to process !)
+            // DeflatedExplicitVRLittleEndian is considered as 'Unexpected' (we don't know yet how to process !)
             gdcmWarningMacro("Unexpected Transfer Syntax :[" << ts << "]");
             break;
          } 
@@ -594,8 +594,15 @@ bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream *fp )
      // Precompute the offset localRaw will be shifted with
      int length = XSize * YSize * ZSize * SamplesPerPixel;
      int numberBytes = BitsAllocated / 8;
-
-     JPEGInfo->DecompressFromFile(fp, Raw, BitsStored, numberBytes, length );
+      
+      // to avoid major troubles when BitsStored == 8 && BitsAllocated==16 !
+     int dummy;
+     if (BitsStored == 8 && BitsAllocated==16)
+        dummy = 16;
+     else
+        dummy = BitsStored;
+     
+     JPEGInfo->DecompressFromFile(fp, Raw, /*BitsStored*/ dummy , numberBytes, length );
      return true;
    }
 }
@@ -1065,20 +1072,26 @@ bool PixelReadConvert::ConvertReArrangeBits() throw ( FormatError )
       {
          // pmask : to mask the 'unused bits' (may contain overlays)
          uint16_t pmask = 0xffff;
-         pmask = pmask >> ( BitsAllocated - BitsStored );
+         // It's up to the user to remove overlays if any),
+         // not to gdcm, witout asking !
+         //pmask = pmask >> ( BitsAllocated - BitsStored );
 
          uint16_t *deb = (uint16_t*)Raw;
 
          if ( !PixelSign )  // Pixels are unsigned
          {
             for(int i = 0; i<l; i++)
-            {   
-               *deb = (*deb >> (BitsStored - HighBitPosition - 1)) & pmask;
+            {  
+              //                                                save CPU time
+               *deb = (*deb >> (BitsStored - HighBitPosition - 1))/* & pmask */;
                deb++;
             }
          }
          else // Pixels are signed
          {
+            // Hope there is never A
             // smask : to check the 'sign' when BitsStored != BitsAllocated
             uint16_t smask = 0x0001;
             smask = smask << ( 16 - (BitsAllocated - BitsStored + 1) );
@@ -1101,12 +1114,21 @@ bool PixelReadConvert::ConvertReArrangeBits() throw ( FormatError )
             }
          }
       }
+      /*
       else if ( BitsAllocated == 32 )
       {
+               }
+               deb++;
+            }
+         }
+      }
+      */
+      else if ( BitsAllocated == 32 )
+      { 
          // pmask : to mask the 'unused bits' (may contain overlays)
          uint32_t pmask = 0xffffffff;
          pmask = pmask >> ( BitsAllocated - BitsStored );
-
          uint32_t *deb = (uint32_t*)Raw;
 
          if ( !PixelSign )
@@ -1131,8 +1153,8 @@ bool PixelReadConvert::ConvertReArrangeBits() throw ( FormatError )
                *deb = *deb >> (BitsStored - HighBitPosition - 1);
                if ( *deb & smask )
                   *deb = *deb | nmask;
-               else
-                  *deb = *deb & pmask;
+               else                
+                 *deb = *deb & pmask; 
                deb++;
             }
          }
@@ -1351,7 +1373,10 @@ void PixelReadConvert::ComputeRawAndRGBSizes()
    else
    {
       RGBSize = RawSize;
+      
    }
+   RawSize += RawSize%2;
+   RGBSize += RGBSize%2;
 }
 
 /// Allocates room for RGB Pixels
@@ -1522,13 +1547,6 @@ of 12 for the third value and a max of 0xfff).
 
 Since almost every vendor that I have encountered that encodes LUTs
 makes this mistake, perhaps it is time to amend the standard to warn
-implementor's of receivers and/or sanction this bad behavior. We have
-talked about this in the past in WG 6 but so far everyone has been
-reluctant to write into the standard such a comment. Maybe it is time
-to try again, since if one is not aware of this problem, one cannot
-effectively implement display using VOI LUTs, and there is a vast
-installed base to contend with.
-
 I did not check presentation states, in which VOI LUTs could also be
 encountered, for the prevalence of this mistake, nor did I look at the
 encoding of Modality LUT's, which are unusual. Nor did I check digital