Author: post
Date: 2010-03-21 18:16:20 +0100 (Sun, 21 Mar 2010)
New Revision: 211
Modified:
RawSpeed/BitPumpJPEG.cpp
RawSpeed/BitPumpJPEG.h
RawSpeed/BitPumpMSB.cpp
RawSpeed/BitPumpMSB.h
Log:
Slightly faster decoding on most cameras.
Modified: RawSpeed/BitPumpJPEG.cpp
===================================================================
--- RawSpeed/BitPumpJPEG.cpp 2010-03-21 16:39:41 UTC (rev 210)
+++ RawSpeed/BitPumpJPEG.cpp 2010-03-21 17:16:20 UTC (rev 211)
@@ -50,55 +50,6 @@
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, c3;
-
- int m = mLeft >> 3;
-
- if (mLeft > 23)
- return;
-
- 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() {
if (!mLeft) fill();
Modified: RawSpeed/BitPumpJPEG.h
===================================================================
--- RawSpeed/BitPumpJPEG.h 2010-03-21 16:39:41 UTC (rev 210)
+++ RawSpeed/BitPumpJPEG.h 2010-03-21 17:16:20 UTC (rev 211)
@@ -50,9 +50,60 @@
__inline guint peekByteNoFill() {return ((mCurr >> (mLeft-8))) & 0xff; }
__inline guint peekBitsNoFill(guint nbits) {return ((mCurr >>
(mLeft-nbits))) & ((1 << nbits) - 1); }
__inline guint getBitsNoFill(guint nbits) { return ((mCurr >> (mLeft -=
(nbits)))) & ((1 << nbits) - 1);}
- void fill(); // Fill the buffer with at least 24 bits
+#define TEST_IF_FF(VAL) if (VAL == 0xFF) {\
+ if (buffer[off] == 0)\
+ off++;\
+ else {\
+ VAL = 0;off--;stuffed++;\
+ }\
+ }
+
+ // Fill the buffer with at least 24 bits
+ void __inline BitPumpJPEG::fill() {
+ guchar c, c2, c3;
+
+ int m = mLeft >> 3;
+
+ if (mLeft > 23)
+ return;
+
+ 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;
+ }
+
+#undef TEST_IF_FF
+
virtual ~BitPumpJPEG(void);
protected:
void __inline init();
Modified: RawSpeed/BitPumpMSB.cpp
===================================================================
--- RawSpeed/BitPumpMSB.cpp 2010-03-21 16:39:41 UTC (rev 210)
+++ RawSpeed/BitPumpMSB.cpp 2010-03-21 17:16:20 UTC (rev 211)
@@ -38,9 +38,6 @@
}
__inline void BitPumpMSB::init() {
- for (int i = 0; i < 31; i++) {
- masks[i] = (1 << i) - 1;
- }
fill();
}
Modified: RawSpeed/BitPumpMSB.h
===================================================================
--- RawSpeed/BitPumpMSB.h 2010-03-21 16:39:41 UTC (rev 210)
+++ RawSpeed/BitPumpMSB.h 2010-03-21 17:16:20 UTC (rev 211)
@@ -46,17 +46,37 @@
__inline guint peekBitsNoFill(guint nbits) {return ((mCurr >>
(mLeft-nbits))) & ((1 << nbits) - 1); }
// Fill the buffer with at least 24 bits
- __inline void fill() {
- guchar c;
+__inline void fill() {
+ int m = mLeft >> 3;
- while (mLeft < MIN_GET_BITS) {
- _ASSERTE(off < size);
- c = buffer[off++];
- mCurr = (mCurr << 8) | c;
- mLeft += 8;
- }
+ if (mLeft > 23)
+ return;
+
+ if (m == 2) {
+ // 16 to 23 bits left, we can add 1 byte
+ unsigned char c = buffer[off++];
+ mCurr = (mCurr << 8) | c;
+ mLeft += 8;
+ return;
}
+ if (m == 1) {
+ // 8 to 15 bits left, we can add 2 bytes
+ unsigned short c = *(unsigned short*)&buffer[off+1];
+ mCurr = (mCurr << 16) | c;
+ mLeft += 16;
+ off += 2;
+ return;
+ }
+
+ // 0 to 7 bits left, we can add 3 bytes
+ unsigned int c = *(unsigned int*)&buffer[off+2];
+ mCurr = (mCurr << 24) | c&0x00ffffff;
+ mLeft += 24;
+ off+=3;
+
+}
+
__inline guint getBit() {
if (!mLeft) fill();
@@ -123,7 +143,6 @@
void __inline init();
const guchar* buffer;
const guint size; // This if the end of buffer.
- guint masks[31];
guint mLeft;
guint mCurr;
guint off; // Offset in bytes
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit