Author: post Date: 2010-09-23 19:37:58 +0200 (Thu, 23 Sep 2010) New Revision: 277
Added: RawSpeed/BitPumpMSB32.cpp RawSpeed/BitPumpMSB32.h Modified: RawSpeed/Common.h RawSpeed/NefDecoder.cpp RawSpeed/RawSpeed.vcproj Log: Finally got a break on Nikon Coolpix. (rawstudio makefile update pending) Added: RawSpeed/BitPumpMSB32.cpp =================================================================== --- RawSpeed/BitPumpMSB32.cpp (rev 0) +++ RawSpeed/BitPumpMSB32.cpp 2010-09-23 17:37:58 UTC (rev 277) @@ -0,0 +1,87 @@ +#include "StdAfx.h" +#include "BitPumpMSB32.h" +/* + RawSpeed - RAW file decoder. + + Copyright (C) 2009 Klaus Post + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + http://www.klauspost.com +*/ + +namespace RawSpeed { + +/*** Used for entropy encoded sections, for now only Nikon Coolpix ***/ + + +BitPumpMSB32::BitPumpMSB32(ByteStream *s): + buffer(s->getData()), size(s->getRemainSize() + sizeof(uint32)), mLeft(0), mCurr(0), off(0) { + init(); +} + +BitPumpMSB32::BitPumpMSB32(const uchar8* _buffer, uint32 _size) : + buffer(_buffer), size(_size + sizeof(uint32)), mLeft(0), mCurr(0), off(0) { + init(); +} + +__inline void BitPumpMSB32::init() { + fill(); +} + +void BitPumpMSB32::fill() +{ + uint32 c, c2, c3, c4; + + if (mLeft >= MIN_GET_BITS) + return; + + c = buffer[off++]; + c2 = buffer[off++]; + c3 = buffer[off++]; + c4 = buffer[off++]; + mCurr <<= 32; + mCurr |= (c4 << 24) | (c3<<16) | (c2<<8) | c; + mLeft += 32; +} + +uint32 BitPumpMSB32::getBitsSafe(unsigned int nbits) { + if (nbits > MIN_GET_BITS) + throw IOException("Too many bits requested"); + + if (mLeft < nbits) { + fill(); + checkPos(); + } + + return (uint32)((mCurr >> (mLeft -= (nbits))) & ((1 << nbits) - 1)); +} + + +void BitPumpMSB32::setAbsoluteOffset(unsigned int offset) { + if (offset >= size) + throw IOException("Offset set out of buffer"); + + mLeft = 0; + mCurr = 0; + off = offset; + fill(); +} + +BitPumpMSB32::~BitPumpMSB32(void) { +} + + +} // namespace RawSpeed Added: RawSpeed/BitPumpMSB32.h =================================================================== --- RawSpeed/BitPumpMSB32.h (rev 0) +++ RawSpeed/BitPumpMSB32.h 2010-09-23 17:37:58 UTC (rev 277) @@ -0,0 +1,76 @@ +/* + RawSpeed - RAW file decoder. + + Copyright (C) 2009 Klaus Post + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + http://www.klauspost.com +*/ +#pragma once +#include "ByteStream.h" + +#ifdef MIN_GET_BITS +#undef MIN_GET_BITS +#endif + +#define BITS_PER_LONG_LONG (8*sizeof(uint64)) +#define MIN_GET_BITS (BITS_PER_LONG_LONG-33) /* max value for long getBuffer */ + +namespace RawSpeed { + +// Note: Allocated buffer MUST be at least size+sizeof(uint32) large. + +class BitPumpMSB32 +{ +public: + BitPumpMSB32(ByteStream *s); + BitPumpMSB32(const uchar8* _buffer, uint32 _size ); + uint32 getBitsSafe(uint32 nbits); + uint32 getBitSafe(); + uchar8 getByteSafe(); + void setAbsoluteOffset(uint32 offset); // Set offset in bytes + __inline uint32 getOffset() { return off-(mLeft>>3);} + __inline void checkPos() { if (off>size) throw IOException("Out of buffer read");}; // Check if we have a valid position + + // Fill the buffer with at least 24 bits +void fill(); + + __inline uint32 getBit() { + if (!mLeft) fill(); + + return (uint32)((mCurr >> (--mLeft)) & 1); + } + + __inline uint32 getBits(uint32 nbits) { + if (mLeft < nbits) { + fill(); + } + + return (uint32)((mCurr >> (mLeft -= (nbits))) & ((1 << nbits) - 1)); + } + + virtual ~BitPumpMSB32(void); +protected: + void __inline init(); + const uchar8* buffer; + const uint32 size; // This if the end of buffer. + uint32 mLeft; + uint64 mCurr; + uint32 off; // Offset in bytes +private: +}; + +} // namespace RawSpeed Modified: RawSpeed/Common.h =================================================================== --- RawSpeed/Common.h 2010-09-22 18:48:28 UTC (rev 276) +++ RawSpeed/Common.h 2010-09-23 17:37:58 UTC (rev 277) @@ -26,6 +26,7 @@ #pragma intrinsic(_ReturnAddress) #define MIN(a,b) min(a,b) #define MAX(a,b) max(a,b) +typedef unsigned __int64 uint64; #else // On linux #define _ASSERTE(a) void(a) #define _RPT0(a,b) @@ -39,7 +40,8 @@ #define _aligned_free(a) do { free(a); } while (0) #ifndef MIN #define MIN(a, b) lmin(a,b) -#endif +typedef unsigned long long uint64; +#endif // end On linux #ifndef MAX #define MAX(a, b) lmin(a,b) #endif Modified: RawSpeed/NefDecoder.cpp =================================================================== --- RawSpeed/NefDecoder.cpp 2010-09-22 18:48:28 UTC (rev 276) +++ RawSpeed/NefDecoder.cpp 2010-09-23 17:37:58 UTC (rev 277) @@ -1,6 +1,7 @@ #include "StdAfx.h" #include "NefDecoder.h" #include "ByteStreamSwap.h" +#include "BitpumpMSB32.h" /* RawSpeed - RAW file decoder. @@ -228,50 +229,11 @@ uint32 y = offset.y; h = MIN(h + (uint32)offset.y, (uint32)mRaw->dim.y); w *= cpp; - BitPumpMSB *in = new BitPumpMSB(&input); + BitPumpMSB32 *in = new BitPumpMSB32(&input); for (; y < h; y++) { ushort16* dest = (ushort16*) & data[offset.x*sizeof(ushort16)*cpp+y*outPitch]; - int val; - int val2; for (uint32 x = 0 ; x < w; x++) { - switch (x&7) { - case 0: - val = in->getBits(12); - break; - case 2: - case 5: - val2 = in->getBits(12); - val = dest[x-2]; // Swap this and pixel two to the left - dest[x-2] = val2; - break; - case 1: - val = in->getBits(12); - val = ((val&0xf)<<8) | (((val>>4)&0xf)<<4) | (((val>>8)&0xf)); - break; - case 3: - val = in->getBits(4) << 8; - val2 = in->getBits(8) << 4; - val |= in->getBits(8); - val2 |= in->getBits(4); - dest[x] = val; - x++; - val= val2; - break; - case 6: - val = in->getBits(4); - val2 = in->getBits(4) << 8; - val |= in->getBits(8) << 4; - val2 |= in->getBits(4) <<4; - val2 |= in->getBits(4); - dest[x] = val; - x++; - val = val2; - break; - default: - val = 4096; - in->skipBits(12); - } - dest[x] = val; + dest[x] = in->getBits(12); } } } Modified: RawSpeed/RawSpeed.vcproj =================================================================== --- RawSpeed/RawSpeed.vcproj 2010-09-22 18:48:28 UTC (rev 276) +++ RawSpeed/RawSpeed.vcproj 2010-09-23 17:37:58 UTC (rev 277) @@ -289,6 +289,10 @@ > </File> <File + RelativePath=".\BitPumpMSB32.cpp" + > + </File> + <File RelativePath=".\BitPumpPlain.cpp" > </File> @@ -411,6 +415,10 @@ > </File> <File + RelativePath=".\BitPumpMSB32.h" + > + </File> + <File RelativePath=".\BitPumpPlain.h" > </File> _______________________________________________ Rawstudio-commit mailing list [email protected] http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit
