X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0b72db08a78016b2cf89a454b307fb71942e8704..8708a10fa67501ab9fbf8f6160b89c26f1c59cbd:/src/common/imagtiff.cpp?ds=sidebyside diff --git a/src/common/imagtiff.cpp b/src/common/imagtiff.cpp index 1ca0a0d0f7..ab692dec26 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(); @@ -128,10 +128,20 @@ bool wxTIFFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos if (!tif) { if (verbose) - wxLogError( _("Error loading TIFF image.") ); + wxLogError( _("TIFF: Error loading image.") ); 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; @@ -147,7 +157,7 @@ bool wxTIFFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos if (!raster) { if (verbose) - wxLogError( _("Not enough memory for loading TIFF image.") ); + wxLogError( _("TIFF: Couldn't allocate memory.") ); return FALSE; } @@ -156,7 +166,7 @@ bool wxTIFFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos if (!image->Ok()) { if (verbose) - wxLogError( _("Not enough memory for loading TIFF image.") ); + wxLogError( _("TIFF: Couldn't allocate memory.") ); _TIFFfree( raster ); @@ -166,7 +176,7 @@ bool wxTIFFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos if (!TIFFReadRGBAImage( tif, w, h, raster, 0 )) { if (verbose) - wxLogError( _("Error reading TIFF image.") ); + wxLogError( _("TIFF: Error reading image.") ); _TIFFfree( raster ); image->Destroy(); @@ -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; }