Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
BBitmapStream Class Reference

Provides for the conversion of a Translation Kit bitmap object to a BBitmap. More...

Inherits BPositionIO.

Public Member Functions

 BBitmapStream (BBitmap *bitmap=NULL)
 Initializes this object to either use the BBitmap passed to it as the object to read/write to or to create a BBitmap when data is written to this object.
 
virtual ~BBitmapStream ()
 Destroys the object and the BBitmap object if attached.
 
status_t DetachBitmap (BBitmap **_bitmap)
 Sets _bitmap to point to the internal bitmap object.
 
virtual off_t Position () const
 Gets the current stream position.
 
virtual ssize_t ReadAt (off_t offset, void *buffer, size_t size)
 Reads data from the stream into buffer at a specific position and size.
 
virtual off_t Seek (off_t position, uint32 seekMode)
 Changes the current stream position.
 
virtual status_t SetSize (off_t size)
 Sets the size of the data.
 
virtual off_t Size () const
 Gets the current stream size.
 
virtual ssize_t WriteAt (off_t offset, const void *buffer, size_t size)
 Writes data to the bitmap starting at a specific position and size.
 
- Public Member Functions inherited from BPositionIO
 BPositionIO ()
 This constructor does nothing.
 
virtual ~BPositionIO ()
 This destructor does nothing.
 
virtual status_t GetSize (off_t *size) const
 Get the size of the object or data.
 
virtual off_t Position () const =0
 Pure virtual to return the current position of the cursor.
 
virtual ssize_t Read (void *buffer, size_t size)
 Read data from current position.
 
virtual ssize_t ReadAt (off_t position, void *buffer, size_t size)=0
 Pure virtual to read data from a certain position.
 
status_t ReadAtExactly (off_t position, void *buffer, size_t size, size_t *_bytesRead=NULL)
 Reads an exact amount of data from the object at the specified position into a buffer.
 
virtual off_t Seek (off_t position, uint32 seekMode)=0
 Pure virtual to move the cursor to a certain position.
 
virtual status_t SetSize (off_t size)
 Set the size of the object or data.
 
virtual ssize_t Write (const void *buffer, size_t size)
 Write data to the current position.
 
virtual ssize_t WriteAt (off_t position, const void *buffer, size_t size)=0
 Pure virtual to write data to a certain position.
 
status_t WriteAtExactly (off_t position, const void *buffer, size_t size, size_t *_bytesWritten=NULL)
 Writes an exact amount of data from a buffer to the object at the specified position.
 
- Public Member Functions inherited from BDataIO
 BDataIO ()
 This constructor does nothing.
 
virtual ~BDataIO ()
 This destructor does nothing.
 
virtual status_t Flush ()
 Writes pending data to underlying storage.
 
virtual ssize_t Read (void *buffer, size_t size)
 Reads data from the object into a buffer.
 
status_t ReadExactly (void *buffer, size_t size, size_t *_bytesRead=NULL)
 Reads an exact amount of data from the object into a buffer.
 
virtual ssize_t Write (const void *buffer, size_t size)
 Writes data from a buffer to the object.
 
status_t WriteExactly (const void *buffer, size_t size, size_t *_bytesWritten=NULL)
 Writes an exact amount of data from a buffer to the object.
 

Protected Member Functions

void SwapHeader (const TranslatorBitmap *source, TranslatorBitmap *destination)
 Swaps the byte order of source, no matter the byte order, and copies the result to destination.
 

Detailed Description

Provides for the conversion of a Translation Kit bitmap object to a BBitmap.

BBitmapStream is limited subclass of BPositionIO that is good at reading and writing Translation Kit bitmaps. The DetachBitmap() method is the main method of this class as it returns the contents of the Translation Kit bitmap object into a BBitmap.

In most cases you shouldn't have to use this class directly as BTranslationUtils contains methods to load images from files and resources.

Constructor & Destructor Documentation

◆ BBitmapStream()

BBitmapStream::BBitmapStream ( BBitmap bitmap = NULL)

Initializes this object to either use the BBitmap passed to it as the object to read/write to or to create a BBitmap when data is written to this object.

If bitmap is NULL, a new BBitmap object is created when this object is written to.

Parameters
bitmapThe bitmap object to read from/write to.

Member Function Documentation

◆ DetachBitmap()

status_t BBitmapStream::DetachBitmap ( BBitmap **  _bitmap)

Sets _bitmap to point to the internal bitmap object.

The bitmap is not deleted when the BBitmapStream is deleted. After the bitmap has been detached it is still used by the stream, but it is never deleted by the stream.

Once you have called DetachBitmap() no further operations should be performed on the BBitmapStream except to destroy the object.

Parameters
_bitmapA BBitmap pointer that will be set to point to the internal bitmap object.
Returns
A status code, B_OK on success or an error code.
Return values
B_OKThe bitmap was detached.
B_BAD_VALUE_bitmap is NULL.
B_ERRORThe internal bitmap object is NULL or has already been detached.

◆ Position()

off_t BBitmapStream::Position ( ) const
virtual

Gets the current stream position.

Returns
The current stream position.

Implements BPositionIO.

◆ ReadAt()

ssize_t BBitmapStream::ReadAt ( off_t  pos,
void *  buffer,
size_t  size 
)
virtual

Reads data from the stream into buffer at a specific position and size.

The first sizeof(TranslatorBitmap) bytes are the bitmap header. The header is always written out and read in as big endian byte order.

Parameters
posThe position in the stream to read from.
bufferWhere the data will be read into
sizeThe amount of data to be read.
Returns
The amount of data written if the result is >= 0 or an error code.
Return values
B_BAD_VALUEbuffer is NULL or pos is invalid or the amount read if the result >= 0
B_NO_INITThere is no bitmap stored by the stream.

Implements BPositionIO.

◆ Seek()

off_t BBitmapStream::Seek ( off_t  position,
uint32  seekMode 
)
virtual

Changes the current stream position.

Parameters
positionThe position offset.
seekModeDecides how the position offset is used:
  • SEEK_CUR Position is added to current stream position.
  • SEEK_END Position is added to the end stream position.
  • SEEK_SET The stream position is set to position.
Returns
The new position offset if the result >= 0.
Return values
B_BAD_VALUEposition was bad.

Implements BPositionIO.

◆ SetSize()

status_t BBitmapStream::SetSize ( off_t  size)
virtual

Sets the size of the data.

Parameters
sizeThe size to set the stream size to.
Returns
A status code, B_NO_ERROR on success or an error code.
Return values
B_NO_ERROR(or B_OK) Size is a valid value.
B_BAD_VALUEsize is NOT a valid value.

Reimplemented from BPositionIO.

◆ Size()

off_t BBitmapStream::Size ( ) const
virtual

Gets the current stream size.

Returns
The current stream size.

◆ SwapHeader()

void BBitmapStream::SwapHeader ( const TranslatorBitmap *  source,
TranslatorBitmap *  destination 
)
protected

Swaps the byte order of source, no matter the byte order, and copies the result to destination.

Parameters
sourceData to be swapped.
destinationWhere the swapped data will be copied to.

◆ WriteAt()

ssize_t BBitmapStream::WriteAt ( off_t  pos,
const void *  data,
size_t  size 
)
virtual

Writes data to the bitmap starting at a specific position and size.

The first sizeof(TranslatorBitmap) bytes of data must be the TranslatorBitmap header in big endian byte order or the data will not be written.

Parameters
posThe position in the stream to write to data.
dataThe data to write to the stream.
sizeThe size of the data to write to the stream.
Returns
The amount of data written if the result is >= 0 or an error code.
Return values
B_BAD_VALUESize is bad or data is NULL or pos is invalid.
B_MISMATCHED_VALUESThe bitmap header is bad.
B_ERRORError allocating memory or setting up big endian header,

Implements BPositionIO.