From 700ec4546cfa7a89b3bca0a4eb5b6ee9d43ac17a Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 30 Nov 1999 17:24:14 +0000 Subject: [PATCH] Compile fix for GIF decoder, Added image index to loadfile. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4774 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/image.h | 19 +++++++++++-------- src/common/gifdecod.cpp | 2 +- src/common/imagbmp.cpp | 2 +- src/common/image.cpp | 12 ++++++------ src/common/imaggif.cpp | 2 +- src/common/imagjpeg.cpp | 2 +- src/common/imagpcx.cpp | 2 +- src/common/imagpng.cpp | 2 +- src/common/imagpnm.cpp | 2 +- src/common/imagtiff.cpp | 29 +++++++++++++++++++++++++++-- 10 files changed, 51 insertions(+), 23 deletions(-) diff --git a/include/wx/image.h b/include/wx/image.h index cded61d096..cbff996d75 100644 --- a/include/wx/image.h +++ b/include/wx/image.h @@ -62,8 +62,10 @@ public: wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; } #if wxUSE_STREAMS - virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); + virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 ); virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); + + virtual int GetImageCount( wxInputStream& stream ); bool CanRead( wxInputStream& stream ) { return DoCanRead(stream); } bool CanRead( const wxString& name ); @@ -108,7 +110,7 @@ public: }; #if wxUSE_STREAMS - virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); + virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 ); virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); virtual bool DoCanRead( wxInputStream& stream ); #endif @@ -135,7 +137,7 @@ public: }; #if wxUSE_STREAMS - virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); + virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 ); virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); virtual bool DoCanRead( wxInputStream& stream ); #endif @@ -162,9 +164,10 @@ public: }; #if wxUSE_STREAMS - virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); + virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 ); virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); virtual bool DoCanRead( wxInputStream& stream ); + virtual int GetImageCount( wxInputStream& stream ); #endif }; #endif @@ -188,7 +191,7 @@ public: }; #if wxUSE_STREAMS - virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); + virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 ); virtual bool DoCanRead( wxInputStream& stream ); #endif }; @@ -214,7 +217,7 @@ public: }; #if wxUSE_STREAMS - virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); + virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 ); virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); virtual bool DoCanRead( wxInputStream& stream ); #endif @@ -241,7 +244,7 @@ public: }; #if wxUSE_STREAMS - virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); + virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 ); virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); virtual bool DoCanRead( wxInputStream& stream ); #endif @@ -268,7 +271,7 @@ public: }; #if wxUSE_STREAMS - virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); + virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 ); virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); virtual bool DoCanRead( wxInputStream& stream ); #endif // wxUSE_STREAMS diff --git a/src/common/gifdecod.cpp b/src/common/gifdecod.cpp index 3345366d7b..0a8a6f525b 100644 --- a/src/common/gifdecod.cpp +++ b/src/common/gifdecod.cpp @@ -446,7 +446,7 @@ bool wxGIFDecoder::CanRead() unsigned char buf[3]; m_f->Read(buf, 3); - stream.SeekI(-3, wxFromCurrent); + m_f->SeekI(-3, wxFromCurrent); return (memcmp(buf, "GIF", 3) == 0); } diff --git a/src/common/imagbmp.cpp b/src/common/imagbmp.cpp index 52dade70e4..baec6a1d48 100644 --- a/src/common/imagbmp.cpp +++ b/src/common/imagbmp.cpp @@ -64,7 +64,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxBMPHandler,wxImageHandler) #define poffset (line * width * 3 + column * 3) -bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSED(verbose) ) +bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSED(verbose), int WXUNUSED(index) ) { int rshift = 0, gshift = 0, bshift = 0; wxUint8 aByte; diff --git a/src/common/image.cpp b/src/common/image.cpp index 96d3c58d8a..c714ea6b5b 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -656,7 +656,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxImageHandler,wxObject) #endif #if wxUSE_STREAMS -bool wxImageHandler::LoadFile( wxImage *WXUNUSED(image), wxInputStream& WXUNUSED(stream), bool WXUNUSED(verbose) ) +bool wxImageHandler::LoadFile( wxImage *WXUNUSED(image), wxInputStream& WXUNUSED(stream), bool WXUNUSED(verbose), int WXUNUSED(index) ) { return FALSE; } @@ -666,9 +666,13 @@ bool wxImageHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSE return FALSE; } +int wxImageHandler::GetImageCount( wxInputStream& WXUNUSED(stream) ) +{ + return 1; +} + bool wxImageHandler::CanRead( const wxString& name ) { -#if wxUSE_STREAMS if (wxFileExists(name)) { wxFileInputStream stream(name); @@ -680,13 +684,9 @@ bool wxImageHandler::CanRead( const wxString& name ) return FALSE; } -#else // !wxUSE_STREAMS return FALSE; -#endif // wxUSE_STREAMS } - - #endif // wxUSE_STREAMS //----------------------------------------------------------------------------- diff --git a/src/common/imaggif.cpp b/src/common/imaggif.cpp index b15fff887e..41211855a5 100644 --- a/src/common/imaggif.cpp +++ b/src/common/imaggif.cpp @@ -40,7 +40,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler,wxImageHandler) #if wxUSE_STREAMS -bool wxGIFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose ) +bool wxGIFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose, int WXUNUSED(index) ) { wxGIFDecoder *decod; int error; diff --git a/src/common/imagjpeg.cpp b/src/common/imagjpeg.cpp index a4fc184bed..6676597e79 100644 --- a/src/common/imagjpeg.cpp +++ b/src/common/imagjpeg.cpp @@ -150,7 +150,7 @@ my_error_exit (j_common_ptr cinfo) -bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose ) +bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose, int WXUNUSED(index) ) { struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; diff --git a/src/common/imagpcx.cpp b/src/common/imagpcx.cpp index 4f5ecbb328..0ba41da2f2 100644 --- a/src/common/imagpcx.cpp +++ b/src/common/imagpcx.cpp @@ -222,7 +222,7 @@ int ReadPCX(wxImage *image, wxInputStream& stream) IMPLEMENT_DYNAMIC_CLASS(wxPCXHandler,wxImageHandler) #endif -bool wxPCXHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose ) +bool wxPCXHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose, int WXUNUSED(index) ) { int error; diff --git a/src/common/imagpng.cpp b/src/common/imagpng.cpp index 132655980c..e8d9f42c7e 100644 --- a/src/common/imagpng.cpp +++ b/src/common/imagpng.cpp @@ -96,7 +96,7 @@ LINKAGEMODE png_silent_warning(png_structp WXUNUSED(png_ptr), png_const_charp WX { } -bool wxPNGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose) +bool wxPNGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose, int WXUNUSED(index) ) { // VZ: as this function uses setjmp() the only fool proof error handling // method is to use goto (setjmp is not really C++ dtors friendly...) diff --git a/src/common/imagpnm.cpp b/src/common/imagpnm.cpp index c2ed7bf13c..ec9edd90b1 100644 --- a/src/common/imagpnm.cpp +++ b/src/common/imagpnm.cpp @@ -50,7 +50,7 @@ void Skip_Comment(wxInputStream &stream) } } -bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSED(verbose) ) +bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSED(verbose), int WXUNUSED(index) ) { wxUint32 width, height; wxUint16 maxval; diff --git a/src/common/imagtiff.cpp b/src/common/imagtiff.cpp index 1ca0a0d0f7..b182648068 100644 --- a/src/common/imagtiff.cpp +++ b/src/common/imagtiff.cpp @@ -119,7 +119,7 @@ TIFFwxOpen(wxInputStream &stream, const char* name, const char* mode) } -bool wxTIFFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose ) +bool wxTIFFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose, int index ) { image->Destroy(); @@ -132,6 +132,16 @@ bool wxTIFFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos return FALSE; } + + if (!TIFFSetDirectory( tif, (tdir_t)index )) + { + if (verbose) + wxLogError( _("Invalid TIFF image index.") ); + + TIFFClose( tif ); + + return FALSE; + } uint32 w, h; size_t npixels; @@ -216,9 +226,24 @@ bool wxTIFFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos return TRUE; } +int wxTIFFHandler::GetImageCount( wxInputStream& stream ) +{ + TIFF *tif = TIFFwxOpen( stream, "image", "r" ); + + if (!tif) + return 0; + int dircount = 0; // according to the libtiff docs, dircount should be set to 1 here??? + do { + dircount++; + } while (TIFFReadDirectory(tif)); + + TIFFClose( tif ); + + return dircount; +} -bool wxTIFFHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbose ) +bool wxTIFFHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSED(stream), bool WXUNUSED(verbose) ) { return FALSE; } -- 2.45.2