]> Creatis software - gdcm.git/commitdiff
ENH: Pass 2 at cleaning the JPEG mess. Still some work to do, but things are getting...
authormalaterre <malaterre>
Mon, 31 Jan 2005 04:00:04 +0000 (04:00 +0000)
committermalaterre <malaterre>
Mon, 31 Jan 2005 04:00:04 +0000 (04:00 +0000)
src/gdcmJPEGFragment.cxx
src/gdcmJPEGFragment.h
src/gdcmJPEGFragmentsInfo.cxx
src/gdcmJPEGFragmentsInfo.h
src/gdcmJpeg.cxx
src/gdcmJpeg12.cxx
src/gdcmJpeg16.cxx
src/gdcmJpeg8.cxx
src/gdcmPixelReadConvert.cxx
src/gdcmjpeg/jmemsrc.c [deleted file]

index 65b9e3934194c56ba32ba301bef8559ba4f53116..e3569967180264d0184d685be5bddf91c9556228 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJPEGFragment.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/31 03:22:25 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2005/01/31 04:00:04 $
+  Version:   $Revision: 1.11 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -38,8 +38,6 @@ JPEGFragment::JPEGFragment()
    Offset = 0;
    Length = 0;
 
-//   StateSuspension = 0;
-//   void *SampBuffer;
    pImage = 0;
 
 }
@@ -73,27 +71,18 @@ void JPEGFragment::DecompressJPEGFramesFromFile(std::ifstream *fp,
 
    if ( nBits == 8 )
    {
-      // JPEG Lossy : call to IJG 6b
-      if ( ! this->gdcm_read_JPEG_file8( fp, buffer, statesuspension) )
-      {
-         //return false;
-      }
+      // JPEG Lossy : call to IJG 6b - 8 bits
+      ReadJPEGFile8( fp, buffer, statesuspension);
    }
    else if ( nBits <= 12 )
    {
-      // Reading Fragment pixels
-      if ( ! this->gdcm_read_JPEG_file12 ( fp, buffer, statesuspension) )
-      {
-         //return false;
-      }
+      // JPEG Lossy : call to IJG 6b - 8 bits
+      ReadJPEGFile12 ( fp, buffer, statesuspension);
    }
    else if ( nBits <= 16 )
    {
-      // Reading Fragment pixels
-      if ( ! this->gdcm_read_JPEG_file16 ( fp, buffer, statesuspension) )
-      {
-         //return false;
-      }
+      // JPEG Lossy : call to IJG 6b - 8 bits
+      ReadJPEGFile16 ( fp, buffer, statesuspension);
       //gdcmAssertMacro( IsJPEGLossless );
    }
    else
@@ -103,9 +92,7 @@ void JPEGFragment::DecompressJPEGFramesFromFile(std::ifstream *fp,
 
       // other JPEG lossy not supported
       gdcmErrorMacro( "Unknown jpeg lossy compression ");
-      //return false;
    }
-
 }
 
 } // end namespace gdcm
index b3e0cc3ab4f920edd7a53e8ab71bd37cccd025b4..e6d74eb8d408fc8954c890a3a2a7da4fe438d8f5 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJPEGFragment.h,v $
   Language:  C++
-  Date:      $Date: 2005/01/31 03:22:25 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2005/01/31 04:00:04 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -27,8 +27,6 @@
 
 namespace gdcm 
 {
-#define JOCTET uint8_t
-
 /**
  * \brief Utility class for summerizing the informations of a JPEG
  *        fragment of an "Encapsulated JPEG Compressed Image".
@@ -47,9 +45,9 @@ public:
    void Print( std::ostream &os = std::cout, std::string indent = "" );
    void DecompressJPEGFramesFromFile(std::ifstream *fp, uint8_t *buffer, int nBits, int & statesuspension);
 
-   bool gdcm_read_JPEG_file8 (std::ifstream* fp, void* image_buffer, int & statesuspension );
-   bool gdcm_read_JPEG_file12 (std::ifstream* fp, void* image_buffer, int & statesuspension );
-   bool gdcm_read_JPEG_file16 (std::ifstream* fp, void* image_buffer, int & statesuspension );
+   bool ReadJPEGFile8 (std::ifstream* fp, void* image_buffer, int & statesuspension );
+   bool ReadJPEGFile12 (std::ifstream* fp, void* image_buffer, int & statesuspension );
+   bool ReadJPEGFile16 (std::ifstream* fp, void* image_buffer, int & statesuspension );
 
    void SetLength(uint32_t length) { Length = length; };
    uint32_t GetLength() { return Length;};
index 489ab2fe1a82c33f81c301089ced9d73dc45a800..4e038ce18cdf19ac332aee59bf2b0e3635521e12 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJPEGFragmentsInfo.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/31 03:22:25 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2005/01/31 04:00:04 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -87,27 +87,6 @@ size_t JPEGFragmentsInfo::GetFragmentsLength()
    return totalLength;
 }
 
-/**
- * \brief Read the all the JPEG Fragment into the input buffer
- */
-void JPEGFragmentsInfo::ReadAllFragments(std::ifstream *fp, JOCTET *buffer )
-{
-   JOCTET *p = buffer;
-
-   // Loop on the fragment[s]
-   JPEGFragmentsList::const_iterator it;
-   for( it  = Fragments.begin();
-        it != Fragments.end();
-        ++it )
-   {
-      fp->seekg( (*it)->GetOffset(), std::ios::beg);
-      size_t len = (*it)->GetLength();
-      fp->read((char *)p,len);
-      p += len;
-   }
-
-}
-
 // to avoid warnings
 void JPEGFragmentsInfo::DecompressJPEGFramesFromFile(std::ifstream *fp, uint8_t *buffer, int nBits, int , int )
 {
index da248099637d809279777affa9dd74cc4679eff7..8aac16936c68f912238c38aa3467969ddf55af8d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJPEGFragmentsInfo.h,v $
   Language:  C++
-  Date:      $Date: 2005/01/30 17:30:57 $
-  Version:   $Revision: 1.16 $
+  Date:      $Date: 2005/01/31 04:00:04 $
+  Version:   $Revision: 1.17 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -44,7 +44,6 @@ public:
    ~JPEGFragmentsInfo();
    void Print( std::ostream &os = std::cout, std::string const & indent = "" );
    size_t GetFragmentsLength();
-   void ReadAllFragments(std::ifstream *fp, JOCTET *buffer );
 
    void DecompressJPEGFramesFromFile(std::ifstream *fp, uint8_t *buffer, int nBits, int numBytes, int length);
 
index 2d79c5c8f8fdafc35dc27f96471a86ac593c487d..66a6dca66289224b3200d18e7242790fef72588b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJpeg.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/31 03:22:25 $
-  Version:   $Revision: 1.38 $
+  Date:      $Date: 2005/01/31 04:00:04 $
+  Version:   $Revision: 1.39 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -204,10 +204,11 @@ METHODDEF(void) my_error_exit (j_common_ptr cinfo) {
  * @param fp pointer to an already open file descriptor 
  *                      8 significant bits per pixel
  * @param image_buffer to receive uncompressed pixels
+ * @param statesuspension Suspension State basically it should be 3 otherwise more complex to handle
  * @return 1 on success, 0 on error
  */
 void *SampBuffer; 
-bool JPEGFragment::gdcm_read_JPEG_file (std::ifstream* fp, void* image_buffer , int& statesuspension)
+bool JPEGFragment::ReadJPEGFile (std::ifstream* fp, void* image_buffer , int& statesuspension)
 {
    pImage = (uint8_t*)image_buffer;
    // This struct contains the JPEG decompression parameters and pointers to
index 03d25b8438e8f65ee795b726ce9e80473f8b4b68..b89b86d979361abde1fbf5eaf926dd220bedd074 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJpeg12.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/31 03:22:26 $
-  Version:   $Revision: 1.31 $
+  Date:      $Date: 2005/01/31 04:00:04 $
+  Version:   $Revision: 1.32 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -26,7 +26,7 @@ extern "C" {
 }
 
 #define gdcm_write_JPEG_file  gdcm_write_JPEG_file12
-#define gdcm_read_JPEG_file   gdcm_read_JPEG_file12
+#define ReadJPEGFile   ReadJPEGFile12
 #define SampBuffer SampBuffer12
 
 #include "gdcmJpeg.cxx"
index 4adfddbb277cb8aab6b5cce29f405fc7fe5b54ef..8911708fce44506ace68aa70631dd09f3ed98dbf 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJpeg16.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/31 03:22:26 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2005/01/31 04:00:05 $
+  Version:   $Revision: 1.11 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -26,7 +26,7 @@ extern "C" {
 }
 
 #define gdcm_write_JPEG_file  gdcm_write_JPEG_file16
-#define gdcm_read_JPEG_file   gdcm_read_JPEG_file16
+#define ReadJPEGFile   ReadJPEGFile16
 #define SampBuffer SampBuffer16
 
 #include "gdcmJpeg.cxx"
index 42ab8130e27ce8b7f4e76ae99f231d2df226b38d..aef7ca8f84277e743f841befec0002771e642228 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJpeg8.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/31 03:22:26 $
-  Version:   $Revision: 1.16 $
+  Date:      $Date: 2005/01/31 04:00:05 $
+  Version:   $Revision: 1.17 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -26,7 +26,7 @@ extern "C" {
 }
 
 #define gdcm_write_JPEG_file  gdcm_write_JPEG_file8
-#define gdcm_read_JPEG_file   gdcm_read_JPEG_file8
+#define ReadJPEGFile   ReadJPEGFile8
 #define SampBuffer SampBuffer8
 
 #include "gdcmJpeg.cxx"
index 8c8bd2db17eb8562e3f25e371f6932419538095d..9338248a130141a5161773f0c6c32536862062c6 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmPixelReadConvert.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/31 03:22:26 $
-  Version:   $Revision: 1.38 $
+  Date:      $Date: 2005/01/31 04:00:05 $
+  Version:   $Revision: 1.39 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -96,21 +96,21 @@ void PixelReadConvert::ReadAndDecompress12BitsTo16Bits( std::ifstream *fp )
       uint8_t b0, b1, b2;
 
       fp->read( (char*)&b0, 1);
-      if ( fp->fail() || fp->eof() )//Fp->gcount() == 1
+      if ( fp->fail() || fp->eof() )
       {
          throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()",
                                 "Unfound first block" );
       }
 
       fp->read( (char*)&b1, 1 );
-      if ( fp->fail() || fp->eof())//Fp->gcount() == 1
+      if ( fp->fail() || fp->eof())
       {
          throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()",
                                 "Unfound second block" );
       }
 
       fp->read( (char*)&b2, 1 );
-      if ( fp->fail() || fp->eof())//Fp->gcount() == 1
+      if ( fp->fail() || fp->eof())
       {
          throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()",
                                 "Unfound second block" );
diff --git a/src/gdcmjpeg/jmemsrc.c b/src/gdcmjpeg/jmemsrc.c
deleted file mode 100644 (file)
index b208fbc..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-/*\r
- * jmemsrc.c\r
- *\r
- * Copyright (C) 1994-1996, Thomas G. Lane.\r
- * This file is part of the Independent JPEG Group's software.\r
- * For conditions of distribution and use, see the accompanying README file.\r
- *\r
- * This file contains decompression data source routines for the case of\r
- * reading JPEG data from a memory buffer that is preloaded with the entire\r
- * JPEG file.  This would not seem especially useful at first sight, but\r
- * a number of people have asked for it.\r
- * This is really just a stripped-down version of jdatasrc.c.  Comparison\r
- * of this code with jdatasrc.c may be helpful in seeing how to make\r
- * custom source managers for other purposes.\r
- */\r
-\r
-/* this is not a core library module, so it doesn't define JPEG_INTERNALS */\r
-#include "jinclude.h"\r
-#include "jpeglib.h"\r
-#include "jerror.h"\r
-\r
-\r
-/* Expanded data source object for memory input */\r
-\r
-/**\r
- * \brief very low level C 'structure', used to decode jpeg file\r
- * Should not appear in the Doxygen supplied documentation\r
- */\r
-typedef struct {\r
-  struct jpeg_source_mgr pub; /* public fields */\r
-  JOCTET eoi_buffer[2];       /* a place to put a dummy EOI */\r
-} my_source_mgr;\r
-\r
-typedef my_source_mgr * my_src_ptr;\r
-\r
-\r
-/*\r
- * Initialize source --- called by jpeg_read_header\r
- * before any data is actually read.\r
- */\r
-\r
-METHODDEF(void)\r
-init_source (j_decompress_ptr cinfo)\r
-{\r
-  /* No work, since jpeg_memory_src set up the buffer pointer and count.\r
-   * Indeed, if we want to read multiple JPEG images from one buffer,\r
-   * this *must* not do anything to the pointer.\r
-   */\r
-  (void)cinfo;\r
-}\r
-\r
-\r
-/*\r
- * Fill the input buffer --- called whenever buffer is emptied.\r
- *\r
- * In this application, this routine should never be called; if it is called,\r
- * the decompressor has overrun the end of the input buffer, implying we\r
- * supplied an incomplete or corrupt JPEG datastream.  A simple error exit\r
- * might be the most appropriate response.\r
- *\r
- * But what we choose to do in this code is to supply dummy EOI markers\r
- * in order to force the decompressor to finish processing and supply\r
- * some sort of output image, no matter how corrupted.\r
- */\r
-\r
-METHODDEF(boolean)\r
-fill_input_buffer (j_decompress_ptr cinfo)\r
-{\r
-  my_src_ptr src = (my_src_ptr) cinfo->src;\r
-\r
-  WARNMS(cinfo, JWRN_JPEG_EOF);\r
-\r
-  /* Create a fake EOI marker */\r
-  src->eoi_buffer[0] = (JOCTET) 0xFF;\r
-  src->eoi_buffer[1] = (JOCTET) JPEG_EOI;\r
-  src->pub.next_input_byte = src->eoi_buffer;\r
-  src->pub.bytes_in_buffer = 2;\r
-\r
-  return TRUE;\r
-}\r
-\r
-\r
-/*\r
- * Skip data --- used to skip over a potentially large amount of\r
- * uninteresting data (such as an APPn marker).\r
- *\r
- * If we overrun the end of the buffer, we let fill_input_buffer deal with\r
- * it.  An extremely large skip could cause some time-wasting here, but\r
- * it really isn't supposed to happen ... and the decompressor will never\r
- * skip more than 64K anyway.\r
- */\r
-\r
-METHODDEF(void)\r
-skip_input_data (j_decompress_ptr cinfo, long num_bytes)\r
-{\r
-  my_src_ptr src = (my_src_ptr) cinfo->src;\r
-\r
-  if (num_bytes > 0) {\r
-    while (num_bytes > (long) src->pub.bytes_in_buffer) {\r
-      num_bytes -= (long) src->pub.bytes_in_buffer;\r
-      (void) fill_input_buffer(cinfo);\r
-      /* note we assume that fill_input_buffer will never return FALSE,\r
-       * so suspension need not be handled.\r
-       */\r
-    }\r
-    src->pub.next_input_byte += (size_t) num_bytes;\r
-    src->pub.bytes_in_buffer -= (size_t) num_bytes;\r
-  }\r
-}\r
-\r
-\r
-/*\r
- * An additional method that can be provided by data source modules is the\r
- * resync_to_restart method for error recovery in the presence of RST markers.\r
- * For the moment, this source module just uses the default resync method\r
- * provided by the JPEG library.  That method assumes that no backtracking\r
- * is possible.\r
- */\r
-\r
-\r
-/*\r
- * Terminate source --- called by jpeg_finish_decompress\r
- * after all data has been read.  Often a no-op.\r
- *\r
- * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding\r
- * application must deal with any cleanup that should happen even\r
- * for error exit.\r
- */\r
-\r
-METHODDEF(void)\r
-term_source (j_decompress_ptr cinfo)\r
-{\r
-  /* no work necessary here */\r
-  (void)cinfo;\r
-}\r
-\r
-\r
-/*\r
- * Prepare for input from a memory buffer.\r
- */\r
-\r
-GLOBAL(void)\r
-jpeg_memory_src (j_decompress_ptr cinfo, const JOCTET * buffer, size_t bufsize)\r
-{\r
-  my_src_ptr src;\r
-\r
-  /* The source object is made permanent so that a series of JPEG images\r
-   * can be read from a single buffer by calling jpeg_memory_src\r
-   * only before the first one.\r
-   * This makes it unsafe to use this manager and a different source\r
-   * manager serially with the same JPEG object.  Caveat programmer.\r
-   */\r
-  if (cinfo->src == NULL) { /* first time for this JPEG object? */\r
-    cinfo->src = (struct jpeg_source_mgr *)\r
-      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,\r
-        SIZEOF(my_source_mgr));\r
-  }\r
-\r
-  src = (my_src_ptr) cinfo->src;\r
-  src->pub.init_source = init_source;\r
-  src->pub.fill_input_buffer = fill_input_buffer;\r
-  src->pub.skip_input_data = skip_input_data;\r
-  src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */\r
-  src->pub.term_source = term_source;\r
-\r
-  src->pub.next_input_byte = buffer;\r
-  src->pub.bytes_in_buffer = bufsize;\r
-}\r
-\r
-\r