X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b59ff3c9c8d59c2c4e0291b964d349c9df839894..9841339c74917270e36def49a00a0415efe3683e:/src/common/imagjpeg.cpp?ds=sidebyside diff --git a/src/common/imagjpeg.cpp b/src/common/imagjpeg.cpp index b8f642502f..b2e4447a02 100644 --- a/src/common/imagjpeg.cpp +++ b/src/common/imagjpeg.cpp @@ -10,10 +10,6 @@ /* We don't put pragma implement in this file because it is already present in src/common/image.cpp - -#ifdef __GNUG__ -#pragma implementation "image.h" -#endif */ // For compilers that support precompilation, includes "wx.h". @@ -23,16 +19,18 @@ #pragma hdrstop #endif +#include "wx/defs.h" + +#if wxUSE_LIBJPEG + #include "wx/image.h" #include "wx/bitmap.h" #include "wx/debug.h" #include "wx/log.h" #include "wx/app.h" -#if wxUSE_LIBJPEG -extern "C" { -#include +extern "C" { +#include "jpeglib.h" } -#endif #include "wx/filefn.h" #include "wx/wfstream.h" #include "wx/intl.h" @@ -57,15 +55,12 @@ extern "C" { // wxJPEGHandler //----------------------------------------------------------------------------- -#if wxUSE_LIBJPEG - #if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxJPEGHandler,wxImageHandler) #endif #if wxUSE_STREAMS - //------------- JPEG Data Source Manager typedef struct { @@ -76,11 +71,11 @@ typedef struct { typedef my_source_mgr * my_src_ptr; -METHODDEF(void) my_init_source ( j_decompress_ptr cinfo ) +METHODDEF(void) my_init_source ( j_decompress_ptr WXUNUSED(cinfo) ) { } -METHODDEF(boolean) my_fill_input_buffer ( j_decompress_ptr cinfo ) +METHODDEF(boolean) my_fill_input_buffer ( j_decompress_ptr WXUNUSED(cinfo) ) { return TRUE; } @@ -111,10 +106,10 @@ void jpeg_wxio_src( j_decompress_ptr cinfo, wxInputStream& infile ) src = (my_src_ptr) cinfo->src; } src = (my_src_ptr) cinfo->src; - src->pub.bytes_in_buffer = infile.StreamSize(); /* forces fill_input_buffer on first read */ - src->buffer = (JOCTET *) malloc (infile.StreamSize()); + src->pub.bytes_in_buffer = infile.GetSize(); /* forces fill_input_buffer on first read */ + src->buffer = (JOCTET *) malloc (infile.GetSize()); src->pub.next_input_byte = src->buffer; /* until buffer loaded */ - infile.Read(src->buffer, infile.StreamSize()); + infile.Read(src->buffer, infile.GetSize()); src->pub.init_source = my_init_source; src->pub.fill_input_buffer = my_fill_input_buffer; @@ -146,7 +141,7 @@ my_error_exit (j_common_ptr cinfo) /* Always display the message. */ /* We could postpone this until after returning, if we chose. */ - (*cinfo->err->output_message) (cinfo); + if (cinfo->err->output_message) (*cinfo->err->output_message) (cinfo); /* Return control to the setjmp point */ longjmp(myerr->setjmp_buffer, 1); @@ -154,7 +149,7 @@ my_error_exit (j_common_ptr cinfo) -bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream ) +bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose ) { struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; @@ -166,12 +161,14 @@ bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream ) cinfo.err = jpeg_std_error( &jerr.pub ); jerr.pub.error_exit = my_error_exit; + if (!verbose) cinfo.err->output_message=NULL; + /* Establish the setjmp return context for my_error_exit to use. */ if (setjmp(jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. * We need to clean up the JPEG object, close the input file, and return. */ - wxLogError(_("Couldn't load a JPEG image - probably file is corrupted.")); + if (verbose) wxLogError(_("Couldn't load a JPEG image - probably file is corrupted.")); jpeg_destroy_decompress(&cinfo); if (image->Ok()) image->Destroy(); return FALSE; @@ -268,7 +265,7 @@ GLOBAL(void) jpeg_wxio_dest (j_compress_ptr cinfo, wxOutputStream& outfile) dest->stream = &outfile; } -bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream ) +bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbose ) { struct jpeg_compress_struct cinfo; struct my_error_mgr jerr; @@ -279,12 +276,14 @@ bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream ) cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; + if (!verbose) cinfo.err->output_message=NULL; + /* Establish the setjmp return context for my_error_exit to use. */ if (setjmp(jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. * We need to clean up the JPEG object, close the input file, and return. */ - wxLogError(_("Couldn't save a JPEG image - probably file is corrupted.")); + if (verbose) wxLogError(_("Couldn't save a JPEG image - probably file is corrupted.")); jpeg_destroy_compress(&cinfo); return FALSE; } @@ -310,12 +309,20 @@ bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream ) return TRUE; } -#endif // wxUSE_STREAMS -#endif -// wxUSE_LIBJPEG +bool wxJPEGHandler::CanRead( wxInputStream& stream ) +{ + unsigned char hdr[2]; + + stream.Read(&hdr, 2); + stream.SeekI(-2, wxFromCurrent); + return (hdr[0] == 0xFF && hdr[1] == 0xD8); +} + +#endif // wxUSE_STREAMS +#endif // wxUSE_LIBJPEG