]> Creatis software - gdcm.git/commitdiff
Taking into account the difference between MONOCHROME1 (low values = bright)
authorjpr <jpr>
Tue, 15 Feb 2005 18:12:34 +0000 (18:12 +0000)
committerjpr <jpr>
Tue, 15 Feb 2005 18:12:34 +0000 (18:12 +0000)
 and MONOCHROME2 (low values = dark)

src/gdcmFile.cxx
src/gdcmFile.h
src/gdcmPixelReadConvert.cxx
src/gdcmPixelReadConvert.h

index 94f5ca5b22b4895807937ffae513695655a7fc4c..a9638f57544a49e2797cba6bae3ab88df2e042cb 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/10 20:53:23 $
-  Version:   $Revision: 1.223 $
+  Date:      $Date: 2005/02/15 18:12:34 $
+  Version:   $Revision: 1.224 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -847,8 +847,8 @@ bool File::IsSignedPixelData()
 }
 
 /**
- * \brief   Check whether this a monochrome picture or not by accessing
- *          the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
+ * \brief   Check whether this a monochrome picture (gray levels) or not,
+ *          using "Photometric Interpretation" tag (0x0028,0x0004).
  * @return  true when "MONOCHROME1" or "MONOCHROME2". False otherwise.
  */
 bool File::IsMonochrome()
@@ -866,6 +866,25 @@ bool File::IsMonochrome()
    return false;
 }
 
+/**
+ * \brief   Check whether this a MONOCHROME1 picture (high values = dark)
+ *            or not using "Photometric Interpretation" tag (0x0028,0x0004).
+ * @return  true when "MONOCHROME1" . False otherwise.
+ */
+bool File::IsMonochrome1()
+{
+   const std::string &PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
+   if (  Util::DicomStringEqual(PhotometricInterp, "MONOCHROME1") )
+   {
+      return true;
+   }
+   if ( PhotometricInterp == GDCM_UNFOUND )
+   {
+      gdcmWarningMacro( "Not found : Photometric Interpretation (0028,0004)");
+   }
+   return false;
+}
+
 /**
  * \brief   Check whether this a "PALETTE COLOR" picture or not by accessing
  *          the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
index dd48d1c53a419deba2f89bc83ae78d6a2afb4e67..b0dabaf9d467dced021089c6deaf54388d707504 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.h,v $
   Language:  C++
-  Date:      $Date: 2005/02/06 14:39:35 $
-  Version:   $Revision: 1.103 $
+  Date:      $Date: 2005/02/15 18:12:35 $
+  Version:   $Revision: 1.104 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -129,6 +129,7 @@ public:
    std::string GetPixelType();
    bool IsSignedPixelData();
    bool IsMonochrome();
+   bool IsMonochrome1();
    bool IsPaletteColor();
    bool IsYBRFull();
 
index 78075ab2a940da5e70cb2ff968c48d7e95d2e5b9..1d59ff9a31c53ca78e8fb095f3b23e21899b0f8f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmPixelReadConvert.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/05 01:37:09 $
-  Version:   $Revision: 1.49 $
+  Date:      $Date: 2005/02/15 18:12:35 $
+  Version:   $Revision: 1.50 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -123,13 +123,15 @@ void PixelReadConvert::GrabInformationsFromFile( File *file )
 
    PixelOffset     = file->GetPixelOffset();
    PixelDataLength = file->GetPixelAreaLength();
-   RLEInfo  = file->GetRLEInfo();
-   JPEGInfo = file->GetJPEGInfo();
+   RLEInfo         = file->GetRLEInfo();
+   JPEGInfo        = file->GetJPEGInfo();
+
+   IsMonochrome    = file->IsMonochrome();
+   IsMonochrome1   = file->IsMonochrome1();
+   IsPaletteColor  = file->IsPaletteColor();
+   IsYBRFull       = file->IsYBRFull();
 
    PlanarConfiguration = file->GetPlanarConfiguration();
-   IsMonochrome = file->IsMonochrome();
-   IsPaletteColor = file->IsPaletteColor();
-   IsYBRFull = file->IsYBRFull();
 
    /////////////////////////////////////////////////////////////////
    // LUT section:
@@ -262,6 +264,7 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp )
    //// Third stage: twigle the bytes and bits.
    ConvertReorderEndianity();
    ConvertReArrangeBits();
+   ConvertFixGreyLevels();
    ConvertHandleColor();
 
    return true;
@@ -641,6 +644,49 @@ void PixelReadConvert::ConvertReorderEndianity()
    }
 }
 
+
+
+/**
+ * \brief Deal with Grey levels i.e. re-arange them
+ *        to have low values = dark, high values = bright
+ */
+void PixelReadConvert::ConvertFixGreyLevels()
+{
+   if (!IsMonochrome1)
+      return;
+
+   int i; // to please M$VC6
+   if ( BitsAllocated == 8 )
+   {
+      uint8_t *deb = (uint8_t *)Raw;
+      for (i=0; i<RawSize; i++)      
+      {
+         *deb = 255 - *deb;
+         deb++;
+      }
+      return;
+   }
+
+   if ( BitsAllocated == 16 )
+   {
+      uint16_t mask =1;
+      int bitStored = 12;   
+      for (i=0; i<BitsStored-1; i++)
+      {
+         mask = (mask << 1) +1; // will be fff when BitStored=12
+      }
+
+      uint16_t *deb = (uint16_t *)Raw;
+      for (i=0; i<RawSize/2; i++)      
+      {
+         *deb = mask - *deb;
+         deb++;
+      }
+      return;
+   }
+}
+
+
 /**
  * \brief  Re-arrange the bits within the bytes.
  * @return Boolean
index 29a5b12dd4f6c8be3e83b6232377900cb5b0dae4..6a329ff1b2012e2698b6058c304158768601c3f3 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmPixelReadConvert.h,v $
   Language:  C++
-  Date:      $Date: 2005/02/03 10:03:07 $
-  Version:   $Revision: 1.18 $
+  Date:      $Date: 2005/02/15 18:12:35 $
+  Version:   $Revision: 1.19 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -70,6 +70,7 @@ private:
    void ConvertSwapZone();
    void ConvertReorderEndianity();
    bool ConvertReArrangeBits() throw ( FormatError );
+   void ConvertFixGreyLevels();
    void ConvertRGBPlanesToRGBPixels();
    void ConvertYcBcRPlanesToRGBPixels();
    void ConvertHandleColor();
@@ -118,6 +119,7 @@ private:
    // For handling color stage
    int PlanarConfiguration;
    bool IsMonochrome;
+   bool IsMonochrome1;
    bool IsPaletteColor;
    bool IsYBRFull;
    bool HasLUT;