document that CanRead() and GetImageCount() functions of wxImageHandlers do NOT modify the current stream position and that they require seekable streams; rename current GetImageCount() functions to DoGetImageCount() and put save-and-restore stream position logic in GetImageCount(); add comments in the various DoCanRead() and in DoGetImageCount() where the stream position is modified; remove unneeded SeekI(0) calls from DoCanRead() and DoGetImageCount() functions: they didn't allow to load images from non-seekable streams; implement forward-seeking in wxInputStream::SeekI() also for non-seekable streams

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2009-06-01 11:43:36 +00:00
parent 1f51673bb8
commit 8faef7ccbc
25 changed files with 236 additions and 93 deletions

View File

@@ -916,13 +916,48 @@ wxFileOffset wxInputStream::SeekI(wxFileOffset pos, wxSeekMode mode)
{
// RR: This code is duplicated in wxBufferedInputStream. This is
// not really a good design, but buffered stream are different
// from all other in that they handle two stream-related objects,
// from all others in that they handle two stream-related objects:
// the stream buffer and parent stream.
// I don't know whether it should be put as well in wxFileInputStream::OnSysSeek
if (m_lasterror==wxSTREAM_EOF)
m_lasterror=wxSTREAM_NO_ERROR;
// avoid unnecessary seek operations (optimization)
wxFileOffset currentPos = TellI(), size = GetLength();
if ((mode == wxFromStart && currentPos == pos) ||
(mode == wxFromCurrent && pos == 0) ||
(mode == wxFromEnd && size != wxInvalidOffset && currentPos == size-pos))
return currentPos;
if (!IsSeekable() && mode == wxFromCurrent && pos > 0)
{
// rather than seeking, we can just read data and discard it;
// this allows to forward-seek also non-seekable streams!
char buf[BUF_TEMP_SIZE];
size_t bytes_read;
// read chunks of BUF_TEMP_SIZE bytes until we reach the new position
for ( ; pos >= BUF_TEMP_SIZE; pos -= bytes_read)
{
bytes_read = Read(buf, WXSIZEOF(buf)).LastRead();
if ( m_lasterror != wxSTREAM_NO_ERROR )
return wxInvalidOffset;
wxASSERT(bytes_read == WXSIZEOF(buf));
}
// read the last 'pos' bytes
bytes_read = Read(buf, (size_t)pos).LastRead();
if ( m_lasterror != wxSTREAM_NO_ERROR )
return wxInvalidOffset;
wxASSERT(bytes_read == (size_t)pos);
// we should now have seeked to the right position...
return TellI();
}
/* RR: A call to SeekI() will automatically invalidate any previous
call to Ungetch(), otherwise it would be possible to SeekI() to
one position, unread some bytes there, SeekI() to another position