]> Creatis software - gdcm.git/commitdiff
ENH: Adding jpeg error handling. As quoted we could be more fancy and throw an except...
authormalaterre <malaterre>
Fri, 4 Feb 2005 23:45:22 +0000 (23:45 +0000)
committermalaterre <malaterre>
Fri, 4 Feb 2005 23:45:22 +0000 (23:45 +0000)
src/gdcmJpeg.cxx

index 90498140367f1ebd3a52daf0449a03ee6839c75a..ae4c268510be8414f3e1bd653bf9798e2908c836 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJpeg.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/04 23:36:26 $
-  Version:   $Revision: 1.42 $
+  Date:      $Date: 2005/02/04 23:45:22 $
+  Version:   $Revision: 1.43 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -196,6 +196,18 @@ METHODDEF(void) my_error_exit (j_common_ptr cinfo) {
    /* Return control to the setjmp point */
    longjmp(myerr->setjmp_buffer, 1);
 }
+
+METHODDEF(void) my_output_message (j_common_ptr cinfo)
+{
+   char buffer[JMSG_LENGTH_MAX];
+   /* Create the message */
+   (*cinfo->err->format_message) (cinfo, buffer);
+
+   // Custom display message, we could be more fancy and throw an exception:
+   gdcmErrorMacro( buffer );
+}
+
 }
 //-----------------------------------------------------------------------------
  
@@ -243,7 +255,10 @@ bool JPEGFragment::ReadJPEGFile (std::ifstream *fp, void *image_buffer, int &sta
   // We set up the normal JPEG error routines, then override error_exit.
   
   cinfo.err = jpeg_std_error(&jerr.pub);
+  // for any jpeg error call my_error_exit
   jerr.pub.error_exit = my_error_exit;
+  // for any output message call my_output_message
+  jerr.pub.output_message = my_output_message;
   
   // Establish the setjmp return context for my_error_exit to use.
   if (setjmp(jerr.setjmp_buffer))