[Rawstudio-commit] rawspeed r166 - RawSpeed
Klaus Post
klauspost at gmail.com
Tue Nov 3 17:59:56 CET 2009
Author: post
Date: 2009-11-03 17:59:55 +0100 (Tue, 03 Nov 2009)
New Revision: 166
Modified:
RawSpeed/BitPumpMSB.cpp
RawSpeed/BitPumpMSB.h
Log:
GCC Friendly inlining.
Modified: RawSpeed/BitPumpMSB.cpp
===================================================================
--- RawSpeed/BitPumpMSB.cpp 2009-11-03 16:52:46 UTC (rev 165)
+++ RawSpeed/BitPumpMSB.cpp 2009-11-03 16:59:55 UTC (rev 166)
@@ -26,10 +26,7 @@
/*** Used for entropy encoded sections ***/
-#define BITS_PER_LONG (8*sizeof(guint))
-#define MIN_GET_BITS (BITS_PER_LONG-7) /* max value for long getBuffer */
-
BitPumpMSB::BitPumpMSB(ByteStream *s):
buffer(s->getData()), size(s->getRemainSize() + sizeof(guint)), mLeft(0), mCurr(0), off(0) {
init();
@@ -48,18 +45,6 @@
fill();
}
-__inline void BitPumpMSB::fill() {
- guchar c;
-
- while (mLeft < MIN_GET_BITS) {
- _ASSERTE(off < size);
- c = buffer[off++];
- mCurr = (mCurr << 8) | c;
- mLeft += 8;
- }
-}
-
-
guint BitPumpMSB::getBitSafe() {
if (!mLeft) {
fill();
Modified: RawSpeed/BitPumpMSB.h
===================================================================
--- RawSpeed/BitPumpMSB.h 2009-11-03 16:52:46 UTC (rev 165)
+++ RawSpeed/BitPumpMSB.h 2009-11-03 16:59:55 UTC (rev 166)
@@ -22,6 +22,9 @@
#pragma once
#include "ByteStream.h"
+#define BITS_PER_LONG (8*sizeof(guint))
+#define MIN_GET_BITS (BITS_PER_LONG-7) /* max value for long getBuffer */
+
namespace RawSpeed {
// Note: Allocated buffer MUST be at least size+sizeof(guint) large.
@@ -41,15 +44,26 @@
__inline guint peekByteNoFill() {return ((mCurr >> (mLeft-8))) & 0xff; }
__inline guint getBitsNoFill(guint nbits) {return ((mCurr >> (mLeft -= (nbits)))) & masks[nbits];}
__inline guint peekBitsNoFill(guint nbits) {return ((mCurr >> (mLeft-nbits))) &masks[nbits]; }
- __inline void fill(); // Fill the buffer with at least 24 bits
- __inline guint BitPumpMSB::getBit() {
+ // Fill the buffer with at least 24 bits
+ __inline void fill() {
+ guchar c;
+
+ while (mLeft < MIN_GET_BITS) {
+ _ASSERTE(off < size);
+ c = buffer[off++];
+ mCurr = (mCurr << 8) | c;
+ mLeft += 8;
+ }
+ }
+
+ __inline guint getBit() {
if (!mLeft) fill();
return (mCurr >> (--mLeft)) & 1;
}
- __inline guint BitPumpMSB::getBits(guint nbits) {
+ __inline guint getBits(guint nbits) {
if (mLeft < nbits) {
if (nbits>24)
throw IOException("Invalid data, attempting to read more than 24 bits.");
@@ -60,13 +74,13 @@
return ((mCurr >> (mLeft -= (nbits)))) & masks[nbits];
}
- __inline guint BitPumpMSB::peekBit() {
+ __inline guint peekBit() {
if (!mLeft) fill();
return (mCurr >> (mLeft - 1)) & 1;
}
- __inline guint BitPumpMSB::peekBits(guint nbits) {
+ __inline guint peekBits(guint nbits) {
if (mLeft < nbits) {
if (nbits>24)
throw IOException("Invalid data, attempting to read more than 24 bits.");
@@ -77,7 +91,7 @@
return ((mCurr >> (mLeft - nbits))) & masks[nbits];
}
- __inline guint BitPumpMSB::peekByte() {
+ __inline guint peekByte() {
if (mLeft < 8) {
fill();
}
@@ -88,7 +102,7 @@
return ((mCurr >> (mLeft - 8))) & 0xff;
}
- __inline void BitPumpMSB::skipBits(unsigned int nbits) {
+ __inline void skipBits(unsigned int nbits) {
if (mLeft < nbits) {
fill();
@@ -99,11 +113,11 @@
mLeft -= nbits;
}
- __inline void BitPumpMSB::skipBitsNoFill(unsigned int nbits) {
+ __inline void skipBitsNoFill(unsigned int nbits) {
mLeft -= nbits;
}
- __inline unsigned char BitPumpMSB::getByte() {
+ __inline unsigned char getByte() {
if (mLeft < 8) {
fill();
}
More information about the Rawstudio-commit
mailing list