X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmJpeg.cxx;h=7cfee75fc209001b1a585f4611f27e012f92ca5a;hb=5b4a76f5a670626f5ae20714d265b3a50ffa2218;hp=2d79c5c8f8fdafc35dc27f96471a86ac593c487d;hpb=0e0403151bbff57175d2b974ee2d14b8195f9234;p=gdcm.git diff --git a/src/gdcmJpeg.cxx b/src/gdcmJpeg.cxx index 2d79c5c8..7cfee75f 100644 --- a/src/gdcmJpeg.cxx +++ b/src/gdcmJpeg.cxx @@ -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/10/18 19:06:30 $ + Version: $Revision: 1.51 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -56,11 +56,11 @@ namespace gdcm * @return 1 on success, 0 on error */ -bool gdcm_write_JPEG_file (std::ofstream* fp, void* im_buf, +bool gdcm_write_JPEG_file (std::ostream *fp, void *im_buf, int image_width, int image_height, int quality) { - JSAMPLE* image_buffer = (JSAMPLE*) im_buf; + JSAMPLE *image_buffer = (JSAMPLE*) im_buf; /* This struct contains the JPEG compression parameters and pointers to * working space (which is allocated as needed by the JPEG library). @@ -107,7 +107,9 @@ bool gdcm_write_JPEG_file (std::ofstream* fp, void* im_buf, // exit(1); // // } - jpeg_stdio_dest(&cinfo, fp); + assert( 0 ); + (void)fp; + //jpeg_stdio_dest(&cinfo, fp, 0, 0, image_width, image_height, quality); /* Step 3: set parameters for compression */ @@ -170,10 +172,9 @@ bool gdcm_write_JPEG_file (std::ofstream* fp, void* im_buf, /* And we're done! */ - return true; //??? + return true; } - //----------------------------------------------------------------------------- struct my_error_mgr { struct jpeg_error_mgr pub; /* "public" fields */ @@ -185,6 +186,7 @@ typedef struct my_error_mgr* my_error_ptr; /* * Here's the routine that will replace the standard error_exit method: */ +extern "C" { METHODDEF(void) my_error_exit (j_common_ptr cinfo) { /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */ my_error_ptr myerr = (my_error_ptr) cinfo->err; @@ -197,6 +199,18 @@ METHODDEF(void) my_error_exit (j_common_ptr cinfo) { 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 ); +//} + +} //----------------------------------------------------------------------------- /** @@ -204,10 +218,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 @@ -242,8 +257,11 @@ bool JPEGFragment::gdcm_read_JPEG_file (std::ifstream* fp, void* image_buffer , // 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)) { @@ -255,7 +273,7 @@ bool JPEGFragment::gdcm_read_JPEG_file (std::ifstream* fp, void* image_buffer , return 0; } // Now we can initialize the JPEG decompression object. - if( statesuspension == 0 ) + if ( statesuspension == 0 ) { jpeg_create_decompress(&cinfo); jpeg_stdio_src(&cinfo, fp, this, 1); @@ -266,17 +284,17 @@ bool JPEGFragment::gdcm_read_JPEG_file (std::ifstream* fp, void* image_buffer , } // Step 3: read file parameters with jpeg_read_header() - if( statesuspension < 2 ) + if ( statesuspension < 2 ) { - if( jpeg_read_header(&cinfo, TRUE) == JPEG_SUSPENDED ) + if ( jpeg_read_header(&cinfo, TRUE) == JPEG_SUSPENDED ) { // Suspension in jpeg_read_header statesuspension = 2; } - + // Step 4: set parameters for decompression // prevent the library from performing any color space conversion - if( cinfo.process == JPROC_LOSSLESS ) + if ( cinfo.process == JPROC_LOSSLESS ) { cinfo.jpeg_color_space = JCS_UNKNOWN; cinfo.out_color_space = JCS_UNKNOWN; @@ -284,9 +302,9 @@ bool JPEGFragment::gdcm_read_JPEG_file (std::ifstream* fp, void* image_buffer , } // Step 5: Start decompressor - if(statesuspension < 3 ) + if (statesuspension < 3 ) { - if( jpeg_start_decompress(&cinfo) == FALSE ) + if ( jpeg_start_decompress(&cinfo) == FALSE ) { // Suspension: jpeg_start_decompress statesuspension = 3; @@ -314,14 +332,14 @@ bool JPEGFragment::gdcm_read_JPEG_file (std::ifstream* fp, void* image_buffer , while (cinfo.output_scanline < cinfo.output_height) { - if( jpeg_read_scanlines(&cinfo, buffer, 1) == 0 ) + if ( jpeg_read_scanlines(&cinfo, buffer, 1) == 0 ) { // Suspension in jpeg_read_scanlines statesuspension = 3; return true; } // The ijg has no notion of big endian, therefore always swap the jpeg stream -#if defined(GDCM_WORDS_BIGENDIAN) && (CMAKE_BITS_IN_JSAMPLE != 8) +#if (defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION)) && (CMAKE_BITS_IN_JSAMPLE != 8) uint16_t *buffer16 = (uint16_t*)*buffer; uint16_t *pimage16 = (uint16_t*)pImage; for(unsigned int i=0;i