Author: post
Date: 2009-10-05 22:20:13 +0200 (Mon, 05 Oct 2009)
New Revision: 157
Modified:
RawSpeed/BitPumpMSB.cpp
RawSpeed/BitPumpMSB.h
RawSpeed/OrfDecoder.cpp
Log:
Minor optimization to ORF-reader.
Modified: RawSpeed/BitPumpMSB.cpp
===================================================================
--- RawSpeed/BitPumpMSB.cpp 2009-10-05 15:23:19 UTC (rev 156)
+++ RawSpeed/BitPumpMSB.cpp 2009-10-05 20:20:13 UTC (rev 157)
@@ -65,6 +65,9 @@
guint BitPumpMSB::getBits(guint nbits) {
if (mLeft < nbits) {
+ if (nbits>24)
+ throw IOException("Invalid data, attempting to read more than 24 bits.");
+
fill();
}
@@ -79,6 +82,9 @@
guint BitPumpMSB::peekBits(guint nbits) {
if (mLeft < nbits) {
+ if (nbits>24)
+ throw IOException("Invalid data, attempting to read more than 24 bits.");
+
fill();
}
@@ -132,6 +138,10 @@
mLeft -= nbits;
}
+void BitPumpMSB::skipBitsNoFill(unsigned int nbits) {
+ mLeft -= nbits;
+}
+
unsigned char BitPumpMSB::getByte() {
if (mLeft < 8) {
fill();
Modified: RawSpeed/BitPumpMSB.h
===================================================================
--- RawSpeed/BitPumpMSB.h 2009-10-05 15:23:19 UTC (rev 156)
+++ RawSpeed/BitPumpMSB.h 2009-10-05 20:20:13 UTC (rev 157)
@@ -38,6 +38,7 @@
guint peekBit();
guint peekByte();
void skipBits(guint nbits);
+ void skipBitsNoFill(guint nbits);
__inline void checkPos() { if (off>size) throw IOException("Out of buffer
read");}; // Check if we have a valid position
guchar getByte();
guchar getByteSafe();
Modified: RawSpeed/OrfDecoder.cpp
===================================================================
--- RawSpeed/OrfDecoder.cpp 2009-10-05 15:23:19 UTC (rev 156)
+++ RawSpeed/OrfDecoder.cpp 2009-10-05 20:20:13 UTC (rev 157)
@@ -102,6 +102,16 @@
guchar* data = mRaw->getData();
gint pitch = mRaw->pitch;
+ /* Build a table to quickly look up "high" value */
+ gchar bittable[4096];
+ for (i = 0; i < 4096; i++) {
+ int b = i;
+ for (high = 0; high < 12; high++)
+ if ((b>>(11-high))&1)
+ break;
+ bittable[i] = high;
+ }
+
s.skipBytes(7);
BitPumpMSB bits(&s);
@@ -114,10 +124,13 @@
carry = acarry[x & 1];
i = 2 * (carry[2] < 3);
for (nbits = 2 + i; (gushort) carry[0] >> (nbits + i); nbits++);
- sign = bits.getBitNoFill() * -1;
- low = bits.getBitsNoFill(2);
- for (high = 0; high < 12; high++)
- if (bits.getBitNoFill()) break;
+ int b = bits.peekBitsNoFill(15);
+ sign = (b >> 14) * -1;
+ low = (b >> 12) & 3;
+ high = bittable[b&4095];
+ // Skip bits used above.
+ bits.skipBitsNoFill(min(12+3, high + 1 + 3));
+
if (high == 12)
high = bits.getBits(16 - nbits) >> 1;
carry[0] = (high << nbits) | bits.getBits(nbits);
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit