Author: post
Date: 2013-09-11 21:06:00 +0200 (Wed, 11 Sep 2013)
New Revision: 576
Modified:
RawSpeed/ByteStream.cpp
RawSpeed/ByteStream.h
RawSpeed/ByteStreamSwap.cpp
RawSpeed/ByteStreamSwap.h
Log:
Add features to Bytestreams and make it more robust.
Modified: RawSpeed/ByteStream.cpp
===================================================================
--- RawSpeed/ByteStream.cpp 2013-09-11 18:58:27 UTC (rev 575)
+++ RawSpeed/ByteStream.cpp 2013-09-11 19:06:00 UTC (rev 576)
@@ -45,7 +45,7 @@
void ByteStream::skipBytes(uint32 nbytes) {
off += nbytes;
if (off > size)
- throw IOException("Skipped out of buffer");
+ ThrowIOE("Skipped out of buffer");
}
uchar8 ByteStream::getByte() {
@@ -56,22 +56,31 @@
}
ushort16 ByteStream::getShort() {
- if (off + 1 >= size)
- throw IOException("getShort: Out of buffer read");
+ if (off + 1 > size)
+ ThrowIOE("getShort: Out of buffer read");
off +=2;
- return *(ushort16*)&buffer[off-2];
+ return ((ushort16)buffer[off-1] << 8) | (ushort16)buffer[off-2];
}
+uint32 ByteStream::getUInt() {
+ if (off + 4 > size)
+ ThrowIOE("getInt:Out of buffer read");
+ uint32 r = (uint32)buffer[off+3] << 24 | (uint32)buffer[off+2] << 16 |
(uint32)buffer[off+1] << 8 | (uint32)buffer[off];
+ off+=4;
+ return r;
+}
+
int ByteStream::getInt() {
- if (off + 4 >= size)
- throw IOException("getInt:Out of buffer read");
+ if (off + 4 > size)
+ ThrowIOE("getInt:Out of buffer read");
+ int r = (int)buffer[off+3] << 24 | (int)buffer[off+2] << 16 |
(int)buffer[off+1] << 8 | (int)buffer[off];
off+=4;
- return *(int*)&buffer[off-4];
+ return r;
}
void ByteStream::setAbsoluteOffset(uint32 offset) {
if (offset >= size)
- throw IOException("setAbsoluteOffset:Offset set out of buffer");
+ ThrowIOE("setAbsoluteOffset:Offset set out of buffer");
off = offset;
}
@@ -81,9 +90,26 @@
off++;
c++;
if (off >= size)
- throw IOException("No marker found inside rest of buffer");
+ ThrowIOE("No marker found inside rest of buffer");
}
// _RPT1(0,"Skipped %u bytes.\n", c);
}
+float ByteStream::getFloat()
+{
+ uchar8 temp[4];
+ if (off + 4 > size)
+ ThrowIOE("getFloat: Out of buffer read");
+ for (int i = 0; i < 4; i++)
+ temp[i] = buffer[off+i];
+ return *(float*)temp;
+}
+
+void ByteStream::popOffset()
+{
+ if (offset_stack.empty())
+ ThrowIOE("Pop Offset: Stack empty");
+ off = offset_stack.top();
+ offset_stack.pop();
+}
} // namespace RawSpeed
Modified: RawSpeed/ByteStream.h
===================================================================
--- RawSpeed/ByteStream.h 2013-09-11 18:58:27 UTC (rev 575)
+++ RawSpeed/ByteStream.h 2013-09-11 19:06:00 UTC (rev 576)
@@ -23,6 +23,7 @@
#define BYTE_STREAM_H
#include "IOException.h"
+#include <stack>
namespace RawSpeed {
@@ -42,11 +43,15 @@
const uchar8* getData() {return &buffer[off];}
virtual ushort16 getShort();
virtual int getInt();
+ virtual uint32 getUInt();
+ virtual float getFloat();
+ void pushOffset() { offset_stack.push(off);}
+ void popOffset();
protected:
const uchar8* buffer;
const uint32 size; // This if the end of buffer.
uint32 off; // Offset in bytes (this is next byte to
deliver)
-
+ stack<uint32> offset_stack;
};
} // namespace RawSpeed
Modified: RawSpeed/ByteStreamSwap.cpp
===================================================================
--- RawSpeed/ByteStreamSwap.cpp 2013-09-11 18:58:27 UTC (rev 575)
+++ RawSpeed/ByteStreamSwap.cpp 2013-09-11 19:06:00 UTC (rev 576)
@@ -28,9 +28,16 @@
int ByteStreamSwap::getInt() {
if (off + 4 >= size)
throw IOException("getInt: Out of buffer read");
- int r = (int)buffer[off] << 24 | (int)buffer[off] << 16 | (int)buffer[off]
<< 8 | (int)buffer[off];
+ int r = (int)buffer[off] << 24 | (int)buffer[off+1] << 16 |
(int)buffer[off+2] << 8 | (int)buffer[off+3];
off+=4;
return r;
}
+uint32 ByteStreamSwap::getUInt() {
+ if (off + 4 >= size)
+ throw IOException("getUInt: Out of buffer read");
+ uint32 r = (uint32)buffer[off] << 24 | (uint32)buffer[off+1] << 16 |
(uint32)buffer[off+2] << 8 | (uint32)buffer[off+3];
+ off+=4;
+ return r;
+}
} // namespace RawSpeed
Modified: RawSpeed/ByteStreamSwap.h
===================================================================
--- RawSpeed/ByteStreamSwap.h 2013-09-11 18:58:27 UTC (rev 575)
+++ RawSpeed/ByteStreamSwap.h 2013-09-11 19:06:00 UTC (rev 576)
@@ -16,6 +16,7 @@
virtual ushort16 getShort();
virtual int getInt();
virtual ~ByteStreamSwap(void);
+ virtual uint32 getUInt();
};
} // namespace RawSpeed
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit