]> Creatis software - gdcm.git/commitdiff
* ENH - Comment out Mathieu's (dangerous) Super Hack
authorjpr <jpr>
Fri, 14 Jan 2005 15:06:36 +0000 (15:06 +0000)
committerjpr <jpr>
Fri, 14 Jan 2005 15:06:36 +0000 (15:06 +0000)
      for dealing with BIGENDIAN processors
- Move equivalent stuff to BinEntry::WriteContent
When necessary, 16 Bits Pixels are swapped in a small buffer
and then written. This avoid allocating a huge buffer, in
PixelWriteConveror, and avoid modifying the Pixel Area.
Note :
      Probabely, the same operation will have to be done when we want
      to write image with Big Endian Transfert Syntax,
      and we are working onj Little Endian Processor

ChangeLog
src/gdcmBinEntry.cxx
src/gdcmHeader.cxx
src/gdcmPixelReadConvert.cxx

index 2d27c58a165eb7dc599426f70c908d7d83d51143..48e58c3d588598eb359af9b97faeb076b3c0f744 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2005-01-13 Jean-Pierre Roux <jpr@creatis.univ-lyon1.fr>
+   * ENH - Comment out Mathieu's (dangerous) Super Hack 
+             for dealing with BIGENDIAN processors
+                       - Move equivalent stuff to BinEntry::WriteContent
+                       When necessary, 16 Bits Pixels are swapped in a small buffer
+                       and then written. This avoid allocating a huge buffer, in
+                       PixelWriteConveror, and avoid modifying the Pixel Area.
+                       Note :
+             Probabely, the same operation will have to be done when we want 
+             to write image with Big Endian Transfert Syntax, 
+             and we are working onj Little Endian Processor
+                                               
 2005-01-14 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
    * src/gdcmDocument.[h|cxx] : comment all methods concerning a flat hash
      table.
index e54c1a76259bc8451adf13187d14284df7a753a8..dd5c79719a62229c918ab9434f865d659d82a1bb 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmBinEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/11 20:49:44 $
-  Version:   $Revision: 1.46 $
+  Date:      $Date: 2005/01/14 15:06:37 $
+  Version:   $Revision: 1.47 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -110,14 +110,63 @@ void BinEntry::Print(std::ostream &os)
  * @param filetype type of the file to be written
 */
 void BinEntry::WriteContent(std::ofstream *fp, FileType filetype)
-{
+{ 
+#define BUFFER_SIZE 4096
    DocEntry::WriteContent(fp, filetype);
    void* binArea = GetBinArea();
    int lgr = GetLength();
-   if (binArea)
+   if (binArea) // the binArea was *actually* loaded
    {
-      // there is a 'non string' LUT, overlay, etc
+
+   // TODO FIME
+   // Probabely, the same operation will have to be done when we want 
+   // to write image with Big Endian Transfert Syntax, 
+   //   and we are working onj Little Endian Processor
+
+#ifdef GDCM_WORDS_BIGENDIAN
+      // Be carefull with *any* 16 bits words 'binEntries !'
+      // if ( GetVR() == "OW") // to be used later
+
+      // TODO FIXME Right now, we only care of Pixels element
+
+      // 8 Bits Pixels *are* OB, 16 Bits Pixels *are* OW
+      // -value forced while Reading process-
+      if (GetGroup == 0x7fe0 && GetVR() == "OW")
+      {     
+         unit16_t *currPosition = (uint16_t *)binArea;
+
+         // TODO FIXME : Maybe we should allocate somewhere a static buffer,
+         // in order not to have to alloc/delete for almost every BinEntry ...
+         unit16_t *buffer = new uint16[BUFFER_SIZE];
+
+         // how many BUFFER_SIZE long pieces in binArea ?
+         int nbPieces = lgr/BUFFER_SIZE/2; //(16 bits = 2 Bytes)
+         for (int j=0;j<nbPieces;j++)
+         {
+            for (int i = 0; i < BUFFER_SIZE/2; i++)
+            {
+               buffer[i] =   (uint16_t *)binArea[i] >> 8 
+                           | (uint16_t *)binArea[i] << 8;  
+            }
+            fp->write ( (char*)currPosition, BUFFER_SIZE );
+            currPosition += BUFFER_SIZE/2;
+         }
+         int remainingSize = lgr%BUFFER_SIZE;
+         if ( remainingSize != 0)
+         {
+            fp->write ( (char*)currPosition, remainingSize );   
+         } 
+         delete buffer; 
+      }
+      else
+      { 
+         // For any other VR, BinEntry is re-written as-is
+         fp->write ( (char*)binArea, lgr );
+      }
+#else
       fp->write ( (char*)binArea, lgr ); // Elem value
+#endif //GDCM_WORDS_BIGENDIAN
+
    }
    else
    {
index b5b3b07afc4f050ee386c8d8a574ed27e313d6a6..cab302f3e8423f5ca5cdd296225cd9f2d3165958 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmHeader.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/11 23:06:35 $
-  Version:   $Revision: 1.231 $
+  Date:      $Date: 2005/01/14 15:06:37 $
+  Version:   $Revision: 1.232 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -196,11 +196,12 @@ bool Header::Write(std::string fileName, FileType filetype)
       }
    }
 
+/*
 #ifdef GDCM_WORDS_BIGENDIAN
-   // Super Duper hack that will make gdcm a BOMB ! but should
+   // Super Super hack that will make gdcm a BOMB ! but should
    // Fix temporarily the dashboard
-   BinEntry *b = GetBinEntry(0x7fe0,0x0010);
-   if ( GetEntry(0x0028,0x0100) ==  "16")
+   BinEntry *b = GetBinEntry(GrPixel,NumPixel);
+   if ( GetPixelSize() ==  16 )
    {
       uint16_t *im16 = (uint16_t*)b->GetBinArea();
       int lgr = b->GetLength();
@@ -210,12 +211,14 @@ bool Header::Write(std::string fileName, FileType filetype)
       }
    }
 #endif //GDCM_WORDS_BIGENDIAN
+*/
 
    Document::WriteContent(fp,filetype);
 
+/*
 #ifdef GDCM_WORDS_BIGENDIAN
    // Flip back the pixel ... I told you this is a hack
-   if ( GetEntry(0x0028,0x0100) ==  "16")
+   if ( GetPixelSize() ==  16 )
    {
       uint16_t *im16 = (uint16_t*)b->GetBinArea();
       int lgr = b->GetLength();
@@ -225,6 +228,7 @@ bool Header::Write(std::string fileName, FileType filetype)
       }
    }
 #endif //GDCM_WORDS_BIGENDIAN
+*/
 
    fp->close();
    delete fp;
index 53c636b4037c1925eb369de293b31ecec48836d1..3cddb493b164d9839283df1ad8d2a06111f56a3d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmPixelReadConvert.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/13 09:24:08 $
-  Version:   $Revision: 1.26 $
+  Date:      $Date: 2005/01/14 15:06:37 $
+  Version:   $Revision: 1.27 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -411,7 +411,7 @@ void PixelReadConvert::ConvertReorderEndianity()
 
 /**
  * \brief     Reads from disk the Pixel Data of JPEG Dicom encapsulated
- *            file and decompress it. This funciton assumes that each
+ *            file and decompress it. This function assumes that each
  *            jpeg fragment contains a whole frame (jpeg file).
  * @param     fp File Pointer
  * @return    Boolean
@@ -543,7 +543,7 @@ ReadAndDecompressJPEGSingleFrameFragmentsFromFile( std::ifstream *fp )
    else
    {
       // other JPEG lossy not supported
-      gdcmErrorMacro( "Unknown jpeg lossy compression ");
+      gdcmErrorMacro( "Unsupported jpeg lossy compression ");
       delete [] buffer;
       return false;
    }      
@@ -641,7 +641,7 @@ ReadAndDecompressJPEGFragmentedFramesFromFile( std::ifstream *fp )
       else
       {
          // other JPEG lossy not supported
-         gdcmErrorMacro( "Unknown jpeg lossy compression ");
+         gdcmErrorMacro( "Unsupported jpeg lossy compression ");
          delete [] buffer;
          return false;
       }
@@ -1070,7 +1070,7 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header )
       // [Bin|Val]Entry occurence migth have been hindered (read simply NOT
       // loaded). Hence, we first try to obtain the LUTs data from the header
       // and when this fails we read the LUTs data directely from disk.
-      /// \todo Reading a [Bin|Val]Entry directly from disk is a kludge.
+      /// \TODO Reading a [Bin|Val]Entry directly from disk is a kludge.
       ///       We should NOT bypass the [Bin|Val]Entry class. Instead
       ///       an access to an UNLOADED content of a [Bin|Val]Entry occurence
       ///       (e.g. BinEntry::GetBinArea()) should force disk access from
@@ -1083,7 +1083,7 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header )
       LutRedData = (uint8_t*)header->GetEntryBinArea( 0x0028, 0x1201 );
       if ( ! LutRedData )
       {
-         gdcmVerboseMacro( "Unable to read red LUT data" );
+         gdcmVerboseMacro( "Unable to read Red LUT data" );
       }
 
       ////// Green round:
@@ -1091,7 +1091,7 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header )
       LutGreenData = (uint8_t*)header->GetEntryBinArea(0x0028, 0x1202 );
       if ( ! LutGreenData)
       {
-         gdcmVerboseMacro( "Unable to read green LUT data" );
+         gdcmVerboseMacro( "Unable to read Green LUT data" );
       }
 
       ////// Blue round:
@@ -1099,7 +1099,7 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header )
       LutBlueData = (uint8_t*)header->GetEntryBinArea( 0x0028, 0x1203 );
       if ( ! LutBlueData )
       {
-         gdcmVerboseMacro( "Unable to read blue LUT data" );
+         gdcmVerboseMacro( "Unable to read Blue LUT data" );
       }
    }
 
@@ -1152,7 +1152,7 @@ void PixelReadConvert::BuildLUTRGBA()
                         &lengthR, &debR, &nbitsR );
    if( nbRead != 3 )
    {
-      gdcmVerboseMacro( "Wrong red LUT descriptor" );
+      gdcmVerboseMacro( "Wrong Red LUT descriptor" );
    }
                                                                                 
    int lengthG;  // Green LUT length in Bytes
@@ -1163,7 +1163,7 @@ void PixelReadConvert::BuildLUTRGBA()
                     &lengthG, &debG, &nbitsG );
    if( nbRead != 3 )
    {
-      gdcmVerboseMacro( "Wrong green LUT descriptor" );
+      gdcmVerboseMacro( "Wrong Green LUT descriptor" );
    }
                                                                                 
    int lengthB;  // Blue LUT length in Bytes
@@ -1174,7 +1174,7 @@ void PixelReadConvert::BuildLUTRGBA()
                     &lengthB, &debB, &nbitsB );
    if( nbRead != 3 )
    {
-      gdcmVerboseMacro( "Wrong blue LUT descriptor" );
+      gdcmVerboseMacro( "Wrong Blue LUT descriptor" );
    }
                                                                                 
    ////////////////////////////////////////////////////////
@@ -1209,7 +1209,7 @@ void PixelReadConvert::BuildLUTRGBA()
    // if it works, we shall have to check the 3 Palettes
    // to see which byte is ==0 (first one, or second one)
    // and fix the code
-   // We give up the checking to avoid some (useless ?)overhead
+   // We give up the checking to avoid some (useless ?) overhead
    // (optimistic asumption)
    int i;
    uint8_t* a = LutRGBA + 0;