Enchance ReadStream and MemoryReadStream with 24bits operations as well
as tell() and rewind() methods, as needed by SAGA engine. svn-id: r13772
This commit is contained in:
parent
5de55d2dfa
commit
b9ebd68022
2 changed files with 71 additions and 1 deletions
|
@ -34,12 +34,24 @@ byte ReadStream::readByte() {
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int8 ReadStream::readSByte() {
|
||||||
|
int8 b = 0;
|
||||||
|
read(&b, 1);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
uint16 ReadStream::readUint16LE() {
|
uint16 ReadStream::readUint16LE() {
|
||||||
uint16 a = readByte();
|
uint16 a = readByte();
|
||||||
uint16 b = readByte();
|
uint16 b = readByte();
|
||||||
return a | (b << 8);
|
return a | (b << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 ReadStream::readUint24LE() {
|
||||||
|
uint32 a = readUint16LE();
|
||||||
|
uint32 b = readByte();
|
||||||
|
return (b << 16) | a;
|
||||||
|
}
|
||||||
|
|
||||||
uint32 ReadStream::readUint32LE() {
|
uint32 ReadStream::readUint32LE() {
|
||||||
uint32 a = readUint16LE();
|
uint32 a = readUint16LE();
|
||||||
uint32 b = readUint16LE();
|
uint32 b = readUint16LE();
|
||||||
|
@ -52,6 +64,12 @@ uint16 ReadStream::readUint16BE() {
|
||||||
return a | (b << 8);
|
return a | (b << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 ReadStream::readUint24BE() {
|
||||||
|
uint32 b = readByte();
|
||||||
|
uint32 a = readUint16BE();
|
||||||
|
return (b << 16) | a;
|
||||||
|
}
|
||||||
|
|
||||||
uint32 ReadStream::readUint32BE() {
|
uint32 ReadStream::readUint32BE() {
|
||||||
uint32 b = readUint16BE();
|
uint32 b = readUint16BE();
|
||||||
uint32 a = readUint16BE();
|
uint32 a = readUint16BE();
|
||||||
|
@ -63,6 +81,10 @@ int16 ReadStream::readSint16LE() {
|
||||||
return (int16)readUint16LE();
|
return (int16)readUint16LE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 ReadStream::readSint24LE() {
|
||||||
|
return (int32)readUint24LE();
|
||||||
|
}
|
||||||
|
|
||||||
int32 ReadStream::readSint32LE() {
|
int32 ReadStream::readSint32LE() {
|
||||||
return (int32)readUint32LE();
|
return (int32)readUint32LE();
|
||||||
}
|
}
|
||||||
|
@ -71,6 +93,10 @@ int16 ReadStream::readSint16BE() {
|
||||||
return (int16)readUint16BE();
|
return (int16)readUint16BE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 ReadStream::readSint24BE() {
|
||||||
|
return (int32)readUint24BE();
|
||||||
|
}
|
||||||
|
|
||||||
int32 ReadStream::readSint32BE() {
|
int32 ReadStream::readSint32BE() {
|
||||||
return (int32)readUint32BE();
|
return (int32)readUint32BE();
|
||||||
}
|
}
|
||||||
|
@ -81,11 +107,20 @@ void WriteStream::writeByte(byte value) {
|
||||||
write(&value, 1);
|
write(&value, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WriteStream::writeSByte(int8 value) {
|
||||||
|
write(&value, 1);
|
||||||
|
}
|
||||||
|
|
||||||
void WriteStream::writeUint16LE(uint16 value) {
|
void WriteStream::writeUint16LE(uint16 value) {
|
||||||
writeByte((byte)(value & 0xff));
|
writeByte((byte)(value & 0xff));
|
||||||
writeByte((byte)(value >> 8));
|
writeByte((byte)(value >> 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WriteStream::writeUint24LE(uint32 value) {
|
||||||
|
writeUint16LE((uint16)(value & 0xffff));
|
||||||
|
writeByte((byte)(value >> 16));
|
||||||
|
}
|
||||||
|
|
||||||
void WriteStream::writeUint32LE(uint32 value) {
|
void WriteStream::writeUint32LE(uint32 value) {
|
||||||
writeUint16LE((uint16)(value & 0xffff));
|
writeUint16LE((uint16)(value & 0xffff));
|
||||||
writeUint16LE((uint16)(value >> 16));
|
writeUint16LE((uint16)(value >> 16));
|
||||||
|
@ -96,6 +131,11 @@ void WriteStream::writeUint16BE(uint16 value) {
|
||||||
writeByte((byte)(value & 0xff));
|
writeByte((byte)(value & 0xff));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WriteStream::writeUint24BE(uint32 value) {
|
||||||
|
writeByte((byte)(value >> 16));
|
||||||
|
writeUint16BE((uint16)(value & 0xffff));
|
||||||
|
}
|
||||||
|
|
||||||
void WriteStream::writeUint32BE(uint32 value) {
|
void WriteStream::writeUint32BE(uint32 value) {
|
||||||
writeUint16BE((uint16)(value >> 16));
|
writeUint16BE((uint16)(value >> 16));
|
||||||
writeUint16BE((uint16)(value & 0xffff));
|
writeUint16BE((uint16)(value & 0xffff));
|
||||||
|
@ -106,6 +146,10 @@ void WriteStream::writeSint16LE(int16 value) {
|
||||||
writeUint16LE((uint16)value);
|
writeUint16LE((uint16)value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WriteStream::writeSint24LE(int32 value) {
|
||||||
|
writeUint24LE((uint32)value);
|
||||||
|
}
|
||||||
|
|
||||||
void WriteStream::writeSint32LE(int32 value) {
|
void WriteStream::writeSint32LE(int32 value) {
|
||||||
writeUint32LE((uint32)value);
|
writeUint32LE((uint32)value);
|
||||||
}
|
}
|
||||||
|
@ -114,6 +158,10 @@ void WriteStream::writeSint16BE(int16 value) {
|
||||||
writeUint16BE((uint16)value);
|
writeUint16BE((uint16)value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WriteStream::writeSint24BE(int32 value) {
|
||||||
|
writeUint24BE((uint32)value);
|
||||||
|
}
|
||||||
|
|
||||||
void WriteStream::writeSint32BE(int32 value) {
|
void WriteStream::writeSint32BE(int32 value) {
|
||||||
writeUint32BE((uint32)value);
|
writeUint32BE((uint32)value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,17 +36,22 @@ public:
|
||||||
// The remaining methods all have default implementations
|
// The remaining methods all have default implementations
|
||||||
|
|
||||||
void writeByte(byte value);
|
void writeByte(byte value);
|
||||||
|
void writeSByte(int8 value);
|
||||||
|
|
||||||
void writeUint16LE(uint16 value);
|
void writeUint16LE(uint16 value);
|
||||||
|
void writeUint24LE(uint32 value);
|
||||||
void writeUint32LE(uint32 value);
|
void writeUint32LE(uint32 value);
|
||||||
|
|
||||||
void writeUint16BE(uint16 value);
|
void writeUint16BE(uint16 value);
|
||||||
|
void writeUint24BE(uint32 value);
|
||||||
void writeUint32BE(uint32 value);
|
void writeUint32BE(uint32 value);
|
||||||
|
|
||||||
void writeSint16LE(int16 value);
|
void writeSint16LE(int16 value);
|
||||||
|
void writeSint24LE(int32 value);
|
||||||
void writeSint32LE(int32 value);
|
void writeSint32LE(int32 value);
|
||||||
|
|
||||||
void writeSint16BE(int16 value);
|
void writeSint16BE(int16 value);
|
||||||
|
void writeSint24BE(int32 value);
|
||||||
void writeSint32BE(int32 value);
|
void writeSint32BE(int32 value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,17 +63,22 @@ public:
|
||||||
// The remaining methods all have default implementations
|
// The remaining methods all have default implementations
|
||||||
|
|
||||||
byte readByte();
|
byte readByte();
|
||||||
|
int8 readSByte();
|
||||||
|
|
||||||
uint16 readUint16LE();
|
uint16 readUint16LE();
|
||||||
|
uint32 readUint24LE();
|
||||||
uint32 readUint32LE();
|
uint32 readUint32LE();
|
||||||
|
|
||||||
uint16 readUint16BE();
|
uint16 readUint16BE();
|
||||||
|
uint32 readUint24BE();
|
||||||
uint32 readUint32BE();
|
uint32 readUint32BE();
|
||||||
|
|
||||||
int16 readSint16LE();
|
int16 readSint16LE();
|
||||||
|
int32 readSint24LE();
|
||||||
int32 readSint32LE();
|
int32 readSint32LE();
|
||||||
|
|
||||||
int16 readSint16BE();
|
int16 readSint16BE();
|
||||||
|
int32 readSint24BE();
|
||||||
int32 readSint32BE();
|
int32 readSint32BE();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -109,9 +119,12 @@ public:
|
||||||
class MemoryReadStream : public ReadStream {
|
class MemoryReadStream : public ReadStream {
|
||||||
private:
|
private:
|
||||||
const byte *_ptr;
|
const byte *_ptr;
|
||||||
|
const byte *_ptrOrig;
|
||||||
uint32 _size;
|
uint32 _size;
|
||||||
|
uint32 _sizeOrig;
|
||||||
|
uint32 _pos;
|
||||||
public:
|
public:
|
||||||
MemoryReadStream(const byte *ptr, uint32 size) : _ptr(ptr), _size(size) {}
|
MemoryReadStream(const byte *ptr, uint32 size) : _ptr(ptr), _ptrOrig(ptr), _size(size), _sizeOrig(size), _pos(0) {}
|
||||||
|
|
||||||
uint32 read(void *ptr, uint32 size) {
|
uint32 read(void *ptr, uint32 size) {
|
||||||
if (size > _size)
|
if (size > _size)
|
||||||
|
@ -119,8 +132,17 @@ public:
|
||||||
memcpy(ptr, _ptr, size);
|
memcpy(ptr, _ptr, size);
|
||||||
_size -= size;
|
_size -= size;
|
||||||
_ptr += size;
|
_ptr += size;
|
||||||
|
_pos += size;
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 tell() { return _pos; }
|
||||||
|
|
||||||
|
void rewind() {
|
||||||
|
_ptr = _ptrOrig;
|
||||||
|
_size = _sizeOrig;
|
||||||
|
_pos = 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Common
|
} // End of namespace Common
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue