2
RawSpeed - RAW file decoder.
4
Copyright (C) 2009 Klaus Post
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
http://www.klauspost.com
22
#ifndef BIT_PUMP_JPEG_H
23
#define BIT_PUMP_JPEG_H
25
#include "ByteStream.h"
26
#include "IOException.h"
30
// Note: Allocated buffer MUST be at least size+sizeof(uint32) large.
35
BitPumpJPEG(ByteStream *s);
36
BitPumpJPEG(const uchar8* _buffer, uint32 _size );
37
uint32 getBits(uint32 nbits);
39
uint32 getBitsSafe(uint32 nbits);
41
uint32 peekBits(uint32 nbits);
44
void skipBits(uint32 nbits);
45
__inline void skipBitsNoFill(uint32 nbits){ mLeft -= nbits; }
46
__inline void checkPos() { if (off>size) throw IOException("Out of buffer read");}; // Check if we have a valid position
49
void setAbsoluteOffset(uint32 offset); // Set offset in bytes
50
uint32 getOffset() { return off-(mLeft>>3)+stuffed;}
51
__inline uint32 getBitNoFill() {return (mCurr >> (--mLeft)) & 1;}
52
__inline uint32 peekByteNoFill() {return ((mCurr >> (mLeft-8))) & 0xff; }
53
__inline uint32 peekBitsNoFill(uint32 nbits) {return ((mCurr >> (mLeft-nbits))) & ((1 << nbits) - 1); }
54
__inline uint32 getBitsNoFill(uint32 nbits) { return ((mCurr >> (mLeft -= (nbits)))) & ((1 << nbits) - 1);}
56
#define TEST_IF_FF(VAL) if (VAL == 0xFF) {\
57
if (buffer[off] == 0)\
60
VAL = 0;off--;stuffed++;\
65
// Fill the buffer with at least 24 bits
66
__inline void fill() {
76
// 16 to 23 bits left, we can add 1 byte
79
mCurr = (mCurr << 8) | c;
86
// 8 to 15 bits left, we can add 2 bytes
91
mCurr = (mCurr << 16) | (c<<8) | c2;
96
// 0 to 7 bits left, we can add 3 bytes
103
mCurr = (mCurr << 24) | (c<<16) | (c2<<8) | c3;
109
virtual ~BitPumpJPEG(void);
111
void __inline init();
112
const uchar8* buffer;
113
const uint32 size; // This if the end of buffer.
116
uint32 off; // Offset in bytes
117
uint32 stuffed; // How many bytes has been stuffed?
121
} // namespace RawSpeed