]> Creatis software - gdcm.git/commitdiff
ENH: Getting real close to having JPEG support in gdcm... jpeg offset table still...
authormalaterre <malaterre>
Tue, 18 Oct 2005 19:54:25 +0000 (19:54 +0000)
committermalaterre <malaterre>
Tue, 18 Oct 2005 19:54:25 +0000 (19:54 +0000)
Example/WriteDicomAsJPEG.cxx
src/gdcmDocEntry.cxx
src/gdcmDocument.cxx
src/gdcmFile.cxx
src/gdcmFileHelper.cxx
src/gdcmFileHelper.h

index 934542a67f45155a51fe12aceaade1c2086fcdc0..5e40401ca86788c144521966ff3356f9e7da4eb6 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: WriteDicomAsJPEG.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 19:06:28 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2005/10/18 19:54:25 $
+  Version:   $Revision: 1.3 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -210,12 +210,6 @@ int main(int argc, char *argv[])
    }
    std::streambuf* sb = of->rdbuf();
    (void)sb;
-   //of->close();
-   std::ofstream out("/tmp/jpeg2.jpg");
-   //out.write( of->str(), of
-   out << of->str(); //faster than going through str()
-   //out.rdbuf( *sb );
-   out.close();
 
 
 
@@ -265,10 +259,6 @@ int main(int argc, char *argv[])
    str << samplesPerPixel; //img.components;
    fileToBuild->InsertEntryString(str.str(),0x0028,0x0002); // Samples per Pixel
 
-   str.str("");
-   str << "1.2.840.10008.1.2.4.50";
-   fileToBuild->InsertEntryString(str.str(),0x0002,0x0010); // Transfer Syntax UID
-
 // Step 2 : Create the output image
 //   std::cout << "2...";
 //   if( img.componentSize%8 > 0 )
@@ -278,14 +268,16 @@ int main(int argc, char *argv[])
    size_t size = xsize * ysize * 1 /*Z*/ 
                * samplesPerPixel /* * img.componentSize / 8*/;
 
-   //uint8_t *imageData = new uint8_t[size];
+   uint8_t *imageData = new uint8_t[size];
    gdcm::FileHelper *fileH = new gdcm::FileHelper(fileToBuild);
    //fileH->SetImageData(imageData,size);
    assert( size == testedDataSize );
    size = of->str().size();
    //size = sb->in_avail();
    std::cerr << "Size JPEG:" << size << std::endl;
-   fileH->SetImageData((uint8_t*)of->str().c_str(), size);
+   //fileH->SetImageData((uint8_t*)of->str().c_str(), size);
+   memcpy(imageData, of->str().c_str(), size);
+   fileH->SetImageData(imageData, size);
    //str::string *s = of->str();
    //fileH->SetWriteTypeToDcmExplVR();
    fileH->SetWriteTypeToJPEG(  );
@@ -294,6 +286,15 @@ int main(int argc, char *argv[])
      {
      std::cerr << "Badddd" << std::endl;
      }
+   //of->close();
+   std::ofstream out("/tmp/jpeg2.jpg");
+   //out.write( of->str(), of
+   //out << of->str(); //rdbuf is faster than going through str()
+   out.write( (char*)imageData, size);
+   std::cerr << "JPEG marker is: " << imageData[6] << imageData[7] << 
+     imageData[8] << imageData[9] << std::endl;
+   //out.rdbuf( *sb );
+   out.close();
 
    delete of;
    delete f;
index 8c117fb0a714cd921c2392d95bef24df95d96ea7..a4011aa731b0fef048e8ec408ef6087f498088b4 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 12:58:28 $
-  Version:   $Revision: 1.71 $
+  Date:      $Date: 2005/10/18 19:54:26 $
+  Version:   $Revision: 1.72 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -76,7 +76,7 @@ void DocEntry::WriteContent(std::ofstream *fp, FileType filetype)
    binary_write( *fp, el);    //element number
 
    // Dicom V3 group 0x0002 is *always* Explicit VR !
-   if ( filetype == ExplicitVR || group == 0x0002 )
+   if ( filetype == ExplicitVR || filetype == JPEG || group == 0x0002 )
    {
       // Special case of delimiters:
       if (group == 0xfffe)
index 958dfc887a4e22b39c273b836c79c9cc465ca709..6de517611e6ae675c4ae9f2712b9e7bee9ed69ba 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 14:37:18 $
-  Version:   $Revision: 1.295 $
+  Date:      $Date: 2005/10/18 19:54:26 $
+  Version:   $Revision: 1.296 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -604,7 +604,8 @@ void Document::WriteContent(std::ofstream *fp, FileType filetype)
 {
    // Skip if user wants to write an ACR-NEMA file
 
-   if ( filetype == ImplicitVR || filetype == ExplicitVR )
+   if ( filetype == ImplicitVR || filetype == ExplicitVR ||
+     filetype == JPEG )
    {
       // writing Dicom File Preamble
       char filePreamble[128];
index fe54402e1fddbfd7358d8603e2c873d0032decce..95d4867b0a324af0f097824b0e5e2e896df49349 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 12:58:28 $
-  Version:   $Revision: 1.277 $
+  Date:      $Date: 2005/10/18 19:54:26 $
+  Version:   $Revision: 1.278 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -1761,14 +1761,18 @@ bool File::Write(std::string fileName, FileType writetype)
       e0000->SetString(sLen.str());
    }
 
-   int i_lgPix = GetEntryLength(GrPixel, NumPixel);
-   if (i_lgPix != -2)
-   {
-      // no (GrPixel, NumPixel) element
-      std::string s_lgPix = Util::Format("%d", i_lgPix+12);
-      s_lgPix = Util::DicomString( s_lgPix.c_str() );
-      InsertEntryString(s_lgPix,GrPixel, 0x0000);
-   }
+   // Derma?.dcm does not have it...let's remove it  FIXME FIXME
+   if( writetype != JPEG )
+     {
+     int i_lgPix = GetEntryLength(GrPixel, NumPixel);
+     if (i_lgPix != -2)
+       {
+       // no (GrPixel, NumPixel) element
+       std::string s_lgPix = Util::Format("%d", i_lgPix+12);
+       s_lgPix = Util::DicomString( s_lgPix.c_str() );
+       InsertEntryString(s_lgPix,GrPixel, 0x0000);
+       }
+     }
 
    Document::WriteContent(fp, writetype);
 
index c4435ba4b2759d590b88da7f117446f2d58b9fad..98f023df9f98097b075170d37146428e1761a141 100644 (file)
@@ -4,8 +4,8 @@
   Module:    $RCSfile: gdcmFileHelper.cxx,v $
   Language:  C++
 
-  Date:      $Date: 2005/10/18 18:39:49 $
-  Version:   $Revision: 1.63 $
+  Date:      $Date: 2005/10/18 19:54:27 $
+  Version:   $Revision: 1.64 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -709,6 +709,7 @@ bool FileHelper::Write(std::string const &fileName)
         // SetWriteFileTypeToImplicitVR(); // ACR IS implicit VR !
          break;
       case JPEG:
+         SetWriteFileTypeToJPEG();
          std::cerr << "Writting as JPEG" << std::endl;
          break;
    }
@@ -1015,6 +1016,17 @@ void FileHelper::SetWriteFileTypeToACR()
 /**
  * \brief Sets in the File the TransferSyntax to 'Explicit VR Little Endian"   
  */ 
+void FileHelper::SetWriteFileTypeToJPEG()
+{
+   std::string ts = Util::DicomString( 
+      Global::GetTS()->GetSpecialTransferSyntax(TS::JPEGBaselineProcess1) );
+
+   DataEntry *tss = CopyDataEntry(0x0002,0x0010);
+   tss->SetString(ts);
+
+   Archive->Push(tss);
+}
+
 void FileHelper::SetWriteFileTypeToExplicitVR()
 {
    std::string ts = Util::DicomString( 
index 9c7e2d659b63e0189c2518d6e3bc049cbc7562d7..acd8b0139b90762ba822ff2e49ecfb22f46ae67f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFileHelper.h,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 18:39:49 $
-  Version:   $Revision: 1.25 $
+  Date:      $Date: 2005/10/18 19:54:27 $
+  Version:   $Revision: 1.26 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -155,6 +155,7 @@ protected:
    void RestoreWrite();
 
    void SetWriteFileTypeToACR();
+   void SetWriteFileTypeToJPEG();
    void SetWriteFileTypeToExplicitVR();
    void SetWriteFileTypeToImplicitVR();
    void RestoreWriteFileType();