]> Creatis software - gdcm.git/blobdiff - src/gdcmJpeg.cxx
2005-01-18 Jean-Pierre Roux <jpr@creatis.univ-lyon1.fr>
[gdcm.git] / src / gdcmJpeg.cxx
index d7579773fdd75064f7a3f18d0de57a48b4cafd6b..28f58b3f7e0d9f27f0db32c690f265374d41f7e7 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJpeg.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/12/12 17:21:08 $
-  Version:   $Revision: 1.29 $
+  Date:      $Date: 2005/01/18 08:01:41 $
+  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
@@ -127,7 +127,6 @@ namespace gdcm
  */
 
  /**
- * \ingroup File
  * \brief   routine for JPEG decompression 
  * @param fp pointer to an already open file descriptor 
  *                      8 significant bits per pixel
@@ -542,7 +541,15 @@ bool gdcm_read_JPEG_file ( std::ifstream* fp, void* image_buffer )
 
      //printf( "scanlines: %d\n",cinfo.output_scanline);
       (void) jpeg_read_scanlines(&cinfo, buffer, 1);
-      memcpy( pimage, *buffer,rowsize); 
+// The ijg has no notion of big endian, therefore always swap the jpeg stream
+#if defined(GDCM_WORDS_BIGENDIAN) && (CMAKE_BITS_IN_JSAMPLE != 8)
+      uint16_t *buffer16 = (uint16_t*)*buffer;
+      uint16_t *pimage16 = (uint16_t*)pimage;
+      for(int i=0;i<rowsize/2;i++)
+        pimage16[i] = (buffer16[i] >> 8) | (buffer16[i] << 8 );
+#else
+      memcpy( pimage, *buffer,rowsize);
+#endif //GDCM_WORDS_BIGENDIAN
       pimage+=rowsize;
    }
 
@@ -814,7 +821,14 @@ bool gdcm_read_JPEG_memory ( const JOCTET* input_buffer, const size_t buflen,
 
      //printf( "scanlines: %d\n",cinfo.output_scanline);
      (void) jpeg_read_scanlines(&cinfo, buffer, 1);
-     memcpy( pimage, *buffer,rowsize); 
+#if defined(GDCM_WORDS_BIGENDIAN) && (CMAKE_BITS_IN_JSAMPLE != 8)
+      uint16_t *buffer16 = (uint16_t*)*buffer;
+      uint16_t *pimage16 = (uint16_t*)pimage;
+      for(int i=0;i<rowsize/2;i++)
+        pimage16[i] = (buffer16[i] >> 8) | (buffer16[i] << 8 );
+#else
+      memcpy( pimage, *buffer,rowsize);
+#endif //GDCM_WORDS_BIGENDIAN
      pimage+=rowsize;
   }