From 45ff9decad4b874b12cf4d7e974b804ffdd67b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Fri, 22 Feb 2008 22:00:41 +0000 Subject: [PATCH] EXRTranslator now uses the StreamBuffer class added StreamBuffer::Position() git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24069 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../translators/exr/IStreamWrapper.cpp | 8 +++--- src/add-ons/translators/exr/IStreamWrapper.h | 4 ++- .../translators/shared/StreamBuffer.cpp | 27 +++++++++++++++++++ src/add-ons/translators/shared/StreamBuffer.h | 2 ++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/add-ons/translators/exr/IStreamWrapper.cpp b/src/add-ons/translators/exr/IStreamWrapper.cpp index 9c5bdbe503..157179c9c9 100644 --- a/src/add-ons/translators/exr/IStreamWrapper.cpp +++ b/src/add-ons/translators/exr/IStreamWrapper.cpp @@ -8,7 +8,7 @@ IStreamWrapper::IStreamWrapper(const char *filename, BPositionIO *stream) : IStream(filename), - fStream(stream) + fStream(stream, 2048) { } @@ -21,7 +21,7 @@ IStreamWrapper::~IStreamWrapper() bool IStreamWrapper::read(char c[/*n*/], int n) { - int actual = fStream->Read(c, n); + int actual = fStream.Read(c, n); if (actual < B_OK) { } @@ -32,12 +32,12 @@ IStreamWrapper::read(char c[/*n*/], int n) Int64 IStreamWrapper::tellg() { - return fStream->Position(); + return fStream.Position(); } void IStreamWrapper::seekg(Int64 pos) { - fStream->Seek(pos, SEEK_SET); + fStream.Seek(pos); } diff --git a/src/add-ons/translators/exr/IStreamWrapper.h b/src/add-ons/translators/exr/IStreamWrapper.h index 285cac68e1..be2abbda83 100644 --- a/src/add-ons/translators/exr/IStreamWrapper.h +++ b/src/add-ons/translators/exr/IStreamWrapper.h @@ -8,6 +8,8 @@ #include #include +#include "StreamBuffer.h" + using namespace Imf; class IStreamWrapper : public IStream { @@ -20,7 +22,7 @@ class IStreamWrapper : public IStream { virtual void seekg(Int64 pos); private: - BPositionIO *fStream; + StreamBuffer fStream; }; #endif /* ISTREAM_WRAPPER_H */ diff --git a/src/add-ons/translators/shared/StreamBuffer.cpp b/src/add-ons/translators/shared/StreamBuffer.cpp index 39b92e6349..3d710a3eb8 100644 --- a/src/add-ons/translators/shared/StreamBuffer.cpp +++ b/src/add-ons/translators/shared/StreamBuffer.cpp @@ -202,6 +202,33 @@ StreamBuffer::Seek(off_t position) return false; } + +// --------------------------------------------------------------- +// Position +// +// Returns the current position in the stream. +// +// Preconditions: fBuffer must be allocated and fBufferSize +// must be valid +// +// Parameters: +// +// Postconditions: +// +// Returns: the position +// --------------------------------------------------------------- +off_t +StreamBuffer::Position() +{ + off_t position = fStream->Position(); + if (fToRead) + position -= fPos; + else + position += fLen; + return position; +} + + // --------------------------------------------------------------- // _ReadStream // diff --git a/src/add-ons/translators/shared/StreamBuffer.h b/src/add-ons/translators/shared/StreamBuffer.h index 6b48c197cd..46611d9d2d 100644 --- a/src/add-ons/translators/shared/StreamBuffer.h +++ b/src/add-ons/translators/shared/StreamBuffer.h @@ -31,6 +31,8 @@ public: bool Seek(off_t position); // seek the stream to the given position + off_t Position(); + // return the actual position private: ssize_t _ReadStream(); // Load the stream buffer from the stream