]> Creatis software - gdcm.git/blobdiff - src/gdcmFileHelper.cxx
English mistakes
[gdcm.git] / src / gdcmFileHelper.cxx
index c47cee38c268513bdc23be7cf36d5d8f03e94164..70034af2efb06763e4c44b8e6ca5952325c0e5a9 100644 (file)
@@ -4,8 +4,8 @@
   Module:    $RCSfile: gdcmFileHelper.cxx,v $
   Language:  C++
 
-  Date:      $Date: 2006/07/04 07:58:51 $
-  Version:   $Revision: 1.106 $
+  Date:      $Date: 2007/04/12 13:22:49 $
+  Version:   $Revision: 1.111 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -230,8 +230,8 @@ bool FileHelper::Load()
 }
 
 /**
- * \brief   Accesses an existing DataEntry through it's (group, element) 
- *          and modifies it's content with the given value.
+ * \brief   Accesses an existing DataEntry through its (group, element) 
+ *          and modifies its content with the given value.
  * @param   content new value (string) to substitute with
  * @param   group  group number of the Dicom Element to modify
  * @param   elem element number of the Dicom Element to modify
@@ -245,8 +245,8 @@ bool FileHelper::SetEntryString(std::string const &content,
 
 
 /**
- * \brief   Accesses an existing DataEntry through it's (group, element) 
- *          and modifies it's content with the given value.
+ * \brief   Accesses an existing DataEntry through its (group, element) 
+ *          and modifies its content with the given value.
  * @param   content new value (void*  -> uint8_t*) to substitute with
  * @param   lgth new value length
  * @param   group  group number of the Dicom Element to modify
@@ -729,8 +729,12 @@ bool FileHelper::Write(std::string const &fileName)
       case JPEG:
          SetWriteFileTypeToJPEG();
          break;
+
+       case JPEG2000:
+         SetWriteFileTypeToJPEG2000();
+         break;
    }
+
    // --------------------------------------------------------------
    // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
    //
@@ -761,7 +765,7 @@ bool FileHelper::Write(std::string const &fileName)
    }
 
    bool check = CheckWriteIntegrity(); // verifies length
-   if (WriteType == JPEG ) check = true;
+   if (WriteType == JPEG || WriteType == JPEG2000) check = true;
    if (check)
    {
       check = FileInternal->Write(fileName,WriteType);
@@ -875,7 +879,7 @@ void FileHelper::SetWriteToRaw()
       if ( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files 
          vr = "OB";
        // For non RAW data. Mainly JPEG
-      if( WriteType == JPEG )
+      if( WriteType == JPEG || WriteType == JPEG2000)
       {
          vr = "OW";
       }
@@ -1050,6 +1054,21 @@ void FileHelper::SetWriteFileTypeToACR()
    Archive->Push(0x0002,0x0102);
 }
 
+ /**
+  * \brief Sets in the File the TransferSyntax to 'JPEG2000'
+  */
+void FileHelper::SetWriteFileTypeToJPEG2000()
+{
+   std::string ts = Util::DicomString(
+   Global::GetTS()->GetSpecialTransferSyntax(TS::JPEG2000Lossless) );
+   
+   DataEntry *tss = CopyDataEntry(0x0002,0x0010,"UI");
+   tss->SetString(ts);
+
+   Archive->Push(tss);
+   tss->Delete();   
+}
+
 /**
  * \brief Sets in the File the TransferSyntax to 'JPEG'
  */ 
@@ -1396,6 +1415,11 @@ void FileHelper::CheckMandatoryElements()
    //0002 0016 AE 1 Source Application Entity Title
    //0002 0100 UI 1 Private Information Creator
    //0002 0102 OB 1 Private Information
+   // Push out 'ACR-NEMA-special' entries, if any
+      Archive->Push(0x0008,0x0001); // Length to End
+      Archive->Push(0x0008,0x0010); // Recognition Code
+      Archive->Push(0x0028,0x0005); // Image Dimension  
   
    // Create them if not found
    // Always modify the value
@@ -1529,7 +1553,8 @@ void FileHelper::CheckMandatoryElements()
    std::ostringstream s;
    // check 'Bits Allocated' vs decent values
    int nbBitsAllocated = FileInternal->GetBitsAllocated();
-   if ( nbBitsAllocated == 0 || nbBitsAllocated > 32)
+   if ( nbBitsAllocated == 0 || nbBitsAllocated > 32 
+      || ( nbBitsAllocated > 8 && nbBitsAllocated <16) )
    {
       CopyMandatoryEntry(0x0028,0x0100,"16","US");
       gdcmWarningMacro("(0028,0100) changed from "
@@ -1562,6 +1587,24 @@ void FileHelper::CheckMandatoryElements()
                        << " for consistency purpose");
    }
 
+   // check Pixel Representation (default it as 0 -unsigned-)
+   
+   DataEntry *e_0028_0103 = FileInternal->GetDataEntry(0x0028, 0x0103);
+   if ( !e_0028_0103 )
+   {
+      gdcmWarningMacro("PixelRepresentation (0028,0103) is supposed to be mandatory");
+      CopyMandatoryEntry(0x0028, 0x0103,"0","US"); 
+   }
+   else
+   {
+      int sign = (int)e_0028_0103->GetValue(0);
+      if (sign !=1 && sign !=0)
+      {
+         gdcmWarningMacro("PixelRepresentation (0028,0103) is supposed to be =1 or =0");
+         CopyMandatoryEntry(0x0028, 0x0103,"0","US");
+      }
+   }
+
    std::string pixelSpacing = FileInternal->GetEntryString(0x0028,0x0030);
    if ( pixelSpacing == GDCM_UNFOUND )
    {