updated StreamBuffer with features used by TIFFTranslator, updated TGATranslator to use new version of this class
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3058 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
// read from a BPositionIO object.
|
// read from a BPositionIO object.
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Copyright (c) 2002 OpenBeOS Project
|
// Copyright (c) 2003 OpenBeOS Project
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "StreamBuffer.h"
|
#include "StreamBuffer.h"
|
||||||
|
|
||||||
@@ -55,7 +56,8 @@
|
|||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
StreamBuffer::StreamBuffer(BPositionIO *pstream, size_t nbuffersize)
|
StreamBuffer::StreamBuffer(BPositionIO *pstream, size_t nbuffersize,
|
||||||
|
bool binitialread)
|
||||||
{
|
{
|
||||||
fpStream = pstream;
|
fpStream = pstream;
|
||||||
fpBuffer = NULL;
|
fpBuffer = NULL;
|
||||||
@@ -68,7 +70,7 @@ StreamBuffer::StreamBuffer(BPositionIO *pstream, size_t nbuffersize)
|
|||||||
|
|
||||||
fnBufferSize = max(nbuffersize, MIN_BUFFER_SIZE);
|
fnBufferSize = max(nbuffersize, MIN_BUFFER_SIZE);
|
||||||
fpBuffer = new uint8[fnBufferSize];
|
fpBuffer = new uint8[fnBufferSize];
|
||||||
if (fpBuffer)
|
if (fpBuffer && binitialread)
|
||||||
ReadStream();
|
ReadStream();
|
||||||
// Fill the buffer with data so that
|
// Fill the buffer with data so that
|
||||||
// object is prepared for first call to
|
// object is prepared for first call to
|
||||||
@@ -113,7 +115,8 @@ StreamBuffer::~StreamBuffer()
|
|||||||
// Returns: B_OK if object has been initialized successfully,
|
// Returns: B_OK if object has been initialized successfully,
|
||||||
// B_ERROR if not
|
// B_ERROR if not
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
status_t StreamBuffer::InitCheck()
|
status_t
|
||||||
|
StreamBuffer::InitCheck()
|
||||||
{
|
{
|
||||||
if (fpStream && fpBuffer)
|
if (fpStream && fpBuffer)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -138,7 +141,8 @@ status_t StreamBuffer::InitCheck()
|
|||||||
// Returns: the number of bytes successfully read or an
|
// Returns: the number of bytes successfully read or an
|
||||||
// error code returned by BPositionIO::Read()
|
// error code returned by BPositionIO::Read()
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
ssize_t StreamBuffer::Read(uint8 *pinto, size_t nbytes)
|
ssize_t
|
||||||
|
StreamBuffer::Read(uint8 *pinto, size_t nbytes)
|
||||||
{
|
{
|
||||||
ssize_t result = B_ERROR;
|
ssize_t result = B_ERROR;
|
||||||
size_t rd1 = 0, rd2 = 0;
|
size_t rd1 = 0, rd2 = 0;
|
||||||
@@ -162,6 +166,37 @@ ssize_t StreamBuffer::Read(uint8 *pinto, size_t nbytes)
|
|||||||
return rd1 + rd2;
|
return rd1 + rd2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
// Seek
|
||||||
|
//
|
||||||
|
// Seeks the stream to the given position and refreshes the
|
||||||
|
// read buffer. If the seek operation fails, the read buffer
|
||||||
|
// will be reset.
|
||||||
|
//
|
||||||
|
// Preconditions: fpBuffer must be allocated and fnBufferSize
|
||||||
|
// must be valid
|
||||||
|
//
|
||||||
|
// Parameters:
|
||||||
|
//
|
||||||
|
// Postconditions:
|
||||||
|
//
|
||||||
|
// Returns: true if the seek was successful,
|
||||||
|
// false if the seek operation failed
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
bool
|
||||||
|
StreamBuffer::Seek(off_t position)
|
||||||
|
{
|
||||||
|
fnLen = 0;
|
||||||
|
fnPos = 0;
|
||||||
|
|
||||||
|
if (fpStream->Seek(position, SEEK_SET) == position) {
|
||||||
|
ReadStream();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// ReadStream
|
// ReadStream
|
||||||
//
|
//
|
||||||
@@ -177,7 +212,8 @@ ssize_t StreamBuffer::Read(uint8 *pinto, size_t nbytes)
|
|||||||
// Returns: the number of bytes successfully read or an
|
// Returns: the number of bytes successfully read or an
|
||||||
// error code returned by BPositionIO::Read()
|
// error code returned by BPositionIO::Read()
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
ssize_t StreamBuffer::ReadStream()
|
ssize_t
|
||||||
|
StreamBuffer::ReadStream()
|
||||||
{
|
{
|
||||||
ssize_t rd;
|
ssize_t rd;
|
||||||
rd = fpStream->Read(fpBuffer, fnBufferSize);
|
rd = fpStream->Read(fpBuffer, fnBufferSize);
|
||||||
@@ -187,5 +223,3 @@ ssize_t StreamBuffer::ReadStream()
|
|||||||
}
|
}
|
||||||
return rd;
|
return rd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
// read from a BPositionIO object.
|
// read from a BPositionIO object.
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Copyright (c) 2002 OpenBeOS Project
|
// Copyright (c) 2003 OpenBeOS Project
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
class StreamBuffer {
|
class StreamBuffer {
|
||||||
public:
|
public:
|
||||||
StreamBuffer(BPositionIO *pstream, size_t nbuffersize);
|
StreamBuffer(BPositionIO *pstream, size_t nbuffersize, bool binitialread);
|
||||||
~StreamBuffer();
|
~StreamBuffer();
|
||||||
|
|
||||||
status_t InitCheck();
|
status_t InitCheck();
|
||||||
@@ -48,6 +48,9 @@ public:
|
|||||||
ssize_t Read(uint8 *pinto, size_t nbytes);
|
ssize_t Read(uint8 *pinto, size_t nbytes);
|
||||||
// copy nbytes from the stream into pinto
|
// copy nbytes from the stream into pinto
|
||||||
|
|
||||||
|
bool Seek(off_t position);
|
||||||
|
// seek the stream to the given position
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ssize_t ReadStream();
|
ssize_t ReadStream();
|
||||||
// Load the stream buffer from the stream
|
// Load the stream buffer from the stream
|
||||||
|
|||||||
@@ -1887,7 +1887,7 @@ translate_from_tganmrle_to_bits(BPositionIO *inSource,
|
|||||||
memset(bitsRowData, 0xff, bitsRowBytes);
|
memset(bitsRowData, 0xff, bitsRowBytes);
|
||||||
uint8 *pbitspixel = bitsRowData;
|
uint8 *pbitspixel = bitsRowData;
|
||||||
uint8 packethead;
|
uint8 packethead;
|
||||||
StreamBuffer sbuf(inSource, TGA_STREAM_BUFFER_SIZE);
|
StreamBuffer sbuf(inSource, TGA_STREAM_BUFFER_SIZE, true);
|
||||||
ssize_t rd = 0;
|
ssize_t rd = 0;
|
||||||
if (sbuf.InitCheck() == B_OK)
|
if (sbuf.InitCheck() == B_OK)
|
||||||
rd = sbuf.Read(&packethead, 1);
|
rd = sbuf.Read(&packethead, 1);
|
||||||
@@ -2198,7 +2198,7 @@ translate_from_tgamrle_to_bits(BPositionIO *inSource,
|
|||||||
memset(bitsRowData, 0xff, bitsRowBytes);
|
memset(bitsRowData, 0xff, bitsRowBytes);
|
||||||
uint8 *pbitspixel = bitsRowData;
|
uint8 *pbitspixel = bitsRowData;
|
||||||
uint8 packethead;
|
uint8 packethead;
|
||||||
StreamBuffer sbuf(inSource, TGA_STREAM_BUFFER_SIZE);
|
StreamBuffer sbuf(inSource, TGA_STREAM_BUFFER_SIZE, true);
|
||||||
ssize_t rd = 0;
|
ssize_t rd = 0;
|
||||||
if (sbuf.InitCheck() == B_OK)
|
if (sbuf.InitCheck() == B_OK)
|
||||||
rd = sbuf.Read(&packethead, 1);
|
rd = sbuf.Read(&packethead, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user