]> Creatis software - gdcm.git/blobdiff - Example/WriteDicomAsJPEG.cxx
Allow wrapping of DirList
[gdcm.git] / Example / WriteDicomAsJPEG.cxx
index 97611a2a190ef42a40036b87d7e1deab14048e01..1681047023b12e10a8bd6bdb41668dcbe3d7c3e5 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: WriteDicomAsJPEG.cxx,v $
   Language:  C++
-  Date:      $Date: 2006/01/27 10:03:23 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2006/08/18 16:08:16 $
+  Version:   $Revision: 1.13 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -107,8 +107,9 @@ void UpdateBasicOffsetTable(std::ostream *fp, JpegVector const &v, size_t pos)
     {
     const JpegPair &jp = *i;
     if(i == v.begin() ){ assert( jp.first - first.first == 0); }
-    gdcm::binary_write(*fp, jp.first - first.first);
-    std::cerr << "Updating Table:" << jp.first - first.first << std::endl;
+    uint32_t offset = jp.first - first.first;
+    gdcm::binary_write(*fp, offset);
+    //std::cerr << "Updating Table:" << jp.first - first.first << std::endl;
     }
 }
 
@@ -119,8 +120,9 @@ void UpdateJpegFragmentSize(std::ostream *fp, JpegVector const &v)
     {
     const JpegPair &jp = *i;
     fp->seekp( jp.first );
-    gdcm::binary_write(*fp, jp.second );
-    std::cerr << "Updating:" << jp.first << "," << jp.second << std::endl;
+    uint32_t length = jp.second;
+    gdcm::binary_write(*fp, length );
+    //std::cerr << "Updating:" << jp.first << "," << jp.second << std::endl;
     }
 }
 
@@ -236,6 +238,7 @@ bool InitializeJpeg(std::ostream *fp, int fragment_size, int image_width, int im
    */
   if (sample_pixel == 3)
     {
+    assert( sample_pixel == 1 );
     row_stride = image_width * 3;/* JSAMPLEs per row in image_buffer */
     }
   else
@@ -326,7 +329,15 @@ bool CreateOneFrame (std::ostream *fp, void *input_buffer, int fragment_size,
     static int i = 0;
     JpegPair &jp = v[i];
     jp.second = end-beg;
-    std::cerr << "DIFF: " << i <<" -> " << end-beg << std::endl;
+    
+    if( ((end-beg) % 2) )
+    {
+       fp->put( '\0' );
+       jp.second += 1;
+    }
+    assert( !(jp.second % 2) );
+    std::cerr << "DIFF: " << i <<" -> " << jp.second << std::endl;    
+       
     ++i;
 
   //JpegPair &jp = v[0];
@@ -394,6 +405,7 @@ int main(int argc, char *argv[])
      WriteDICOMItems(of, JpegFragmentSize);
      CreateOneFrame(of, pImageData, fragment_size, xsize, ysize, zsize, 
        samplesPerPixel, quality, JpegFragmentSize);
+     assert( !(fragment_size % 2) );  
      pImageData += fragment_size;
      }
    CloseJpeg(of, JpegFragmentSize);
@@ -433,40 +445,40 @@ int main(int argc, char *argv[])
    // Set the image size
    str.str("");
    str << xsize;
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0011); // Columns
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0011,"US"); // Columns
    str.str("");
    str << ysize;
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0010); // Rows
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0010,"US"); // Rows
 
    if(zsize>1)
    {
       str.str("");
       str << zsize;
-      fileToBuild->InsertEntryString(str.str(),0x0028,0x0008); // Number of Frames
+      fileToBuild->InsertEntryString(str.str(),0x0028,0x0008,"IS"); // Number of Frames
    }
 
    // Set the pixel type
    str.str("");
    str << 8; //img.componentSize;
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0100); // Bits Allocated
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0100,"US"); // Bits Allocated
 
    str.str("");
    str << 8; //img.componentUse;
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0101); // Bits Stored
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0101,"US"); // Bits Stored
 
    str.str("");
    str << 7; //( img.componentSize - 1 );
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0102); // High Bit
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0102,"US"); // High Bit
 
    // Set the pixel representation
    str.str("");
    str << 0; //img.sign;
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0103); // Pixel Representation
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0103,"US"); // Pixel Representation
 
    // Set the samples per pixel
    str.str("");
    str << samplesPerPixel; //img.components;
-   fileToBuild->InsertEntryString(str.str(),0x0028,0x0002); // Samples per Pixel
+   fileToBuild->InsertEntryString(str.str(),0x0028,0x0002,"US"); // Samples per Pixel
 
 // Step 2 : Create the output image
 //   std::cout << "2...";