~ubuntu-branches/ubuntu/saucy/darktable/saucy

« back to all changes in this revision

Viewing changes to src/rawspeed/RawSpeed/BitPumpMSB.cpp

  • Committer: Bazaar Package Importer
  • Author(s): David Bremner
  • Date: 2011-08-02 21:32:31 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110802213231-r9v63trgyk1e822j
Tags: 0.9.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "StdAfx.h"
2
 
#include "BitPumpMSB.h"
3
 
/*
4
 
    RawSpeed - RAW file decoder.
5
 
 
6
 
    Copyright (C) 2009 Klaus Post
7
 
 
8
 
    This library is free software; you can redistribute it and/or
9
 
    modify it under the terms of the GNU Lesser General Public
10
 
    License as published by the Free Software Foundation; either
11
 
    version 2 of the License, or (at your option) any later version.
12
 
 
13
 
    This library is distributed in the hope that it will be useful,
14
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
    Lesser General Public License for more details.
17
 
 
18
 
    You should have received a copy of the GNU Lesser General Public
19
 
    License along with this library; if not, write to the Free Software
20
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 
 
22
 
    http://www.klauspost.com
23
 
*/
24
 
 
25
 
namespace RawSpeed {
26
 
 
27
 
/*** Used for entropy encoded sections ***/
28
 
 
29
 
 
30
 
BitPumpMSB::BitPumpMSB(ByteStream *s):
31
 
    buffer(s->getData()), size(s->getRemainSize() + sizeof(uint32)), mLeft(0), mCurr(0), off(0) {
32
 
  init();
33
 
}
34
 
 
35
 
BitPumpMSB::BitPumpMSB(const uchar8* _buffer, uint32 _size) :
36
 
    buffer(_buffer), size(_size + sizeof(uint32)), mLeft(0), mCurr(0), off(0) {
37
 
  init();
38
 
}
39
 
 
40
 
__inline void BitPumpMSB::init() {
41
 
  fill();
42
 
}
43
 
 
44
 
uint32 BitPumpMSB::getBitSafe() {
45
 
  if (!mLeft) {
46
 
    fill();
47
 
    checkPos();
48
 
  }
49
 
 
50
 
  return (mCurr >> (--mLeft)) & 1;
51
 
}
52
 
 
53
 
uint32 BitPumpMSB::getBitsSafe(unsigned int nbits) {
54
 
  if (nbits > MIN_GET_BITS)
55
 
    throw IOException("Too many bits requested");
56
 
 
57
 
  if (mLeft < nbits) {
58
 
    fill();
59
 
    checkPos();
60
 
  }
61
 
 
62
 
  return ((mCurr >> (mLeft -= (nbits)))) & ((1 << nbits) - 1);
63
 
}
64
 
 
65
 
 
66
 
uchar8 BitPumpMSB::getByteSafe() {
67
 
  if (mLeft < 8) {
68
 
    fill();
69
 
    checkPos();
70
 
  }
71
 
 
72
 
  return ((mCurr >> (mLeft -= 8))) & 0xff;
73
 
}
74
 
 
75
 
void BitPumpMSB::setAbsoluteOffset(unsigned int offset) {
76
 
  if (offset >= size)
77
 
    throw IOException("Offset set out of buffer");
78
 
 
79
 
  mLeft = 0;
80
 
  mCurr = 0;
81
 
  off = offset;
82
 
  fill();
83
 
}
84
 
 
85
 
 
86
 
 
87
 
BitPumpMSB::~BitPumpMSB(void) {
88
 
}
89
 
 
90
 
} // namespace RawSpeed