Author: post
Date: 2010-03-21 17:39:41 +0100 (Sun, 21 Mar 2010)
New Revision: 210
Modified:
RawSpeed/BitPumpJPEG.cpp
RawSpeed/BitPumpJPEG.h
Log:
Slightly faster LJPEG decoding
Modified: RawSpeed/BitPumpJPEG.cpp
===================================================================
--- RawSpeed/BitPumpJPEG.cpp 2010-03-21 15:16:34 UTC (rev 209)
+++ RawSpeed/BitPumpJPEG.cpp 2010-03-21 16:39:41 UTC (rev 210)
@@ -50,37 +50,53 @@
fill();
}
+#define TEST_IF_FF(VAL) if (VAL == 0xFF) {\
+ if (buffer[off] == 0)\
+ off++;\
+ else {\
+ VAL = 0;off--;stuffed++;\
+ }\
+}
void BitPumpJPEG::fill() {
- guchar c, c2;
+ guchar c, c2, c3;
- while (mLeft < MIN_GET_BITS) {
- _ASSERTE(off < size);
- c = buffer[off++];
+ int m = mLeft >> 3;
- /*
- * If it's 0xFF, check and discard stuffed zero byte
- */
+ if (mLeft > 23)
+ return;
- if (c == 0xFF) {
- c2 = buffer[off];
-
- if (c2 == 0) { // Increment, if not a stuffed ff
- off++;
- } else {
- c = 0;
- off--; // Don't return more bytes, rewind, so this will be hit next
- stuffed++;
- }
- }
-
- /*
- * OK, load c into mCurr
- */
+ if (m == 2)
+ {
+ // 16 to 23 bits left, we can add 1 byte
+ c = buffer[off++];
+ TEST_IF_FF(c);
mCurr = (mCurr << 8) | c;
-
mLeft += 8;
+ return;
}
+
+ if (m == 1)
+ {
+ // 8 to 15 bits left, we can add 2 bytes
+ c = buffer[off++];
+ TEST_IF_FF(c);
+ c2 = buffer[off++];
+ TEST_IF_FF(c2);
+ mCurr = (mCurr << 16) | (c<<8) | c2;
+ mLeft += 16;
+ return;
+ }
+
+ // 0 to 7 bits left, we can add 3 bytes
+ c = buffer[off++];
+ TEST_IF_FF(c);
+ c2 = buffer[off++];
+ TEST_IF_FF(c2);
+ c3 = buffer[off++];
+ TEST_IF_FF(c3);
+ mCurr = (mCurr << 24) | (c<<16) | (c2<<8) | c3;
+ mLeft += 24;
}
guint BitPumpJPEG::getBit() {
@@ -189,7 +205,6 @@
}
-
BitPumpJPEG::~BitPumpJPEG(void) {
}
Modified: RawSpeed/BitPumpJPEG.h
===================================================================
--- RawSpeed/BitPumpJPEG.h 2010-03-21 15:16:34 UTC (rev 209)
+++ RawSpeed/BitPumpJPEG.h 2010-03-21 16:39:41 UTC (rev 210)
@@ -57,11 +57,11 @@
protected:
void __inline init();
const guchar* buffer;
- const guint size; // This if the end of buffer.
guint mLeft;
+ guint off; // Offset in bytes
guint mCurr;
- guint off; // Offset in bytes
guint stuffed; // How many bytes has been stuffed?
+ const guint size; // This if the end of buffer.
private:
};
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit