~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to extra/libkdcraw/libraw/RawSpeed/BitPumpMSB.h

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-11-26 18:24:20 UTC
  • mfrom: (1.9.1) (3.1.23 experimental)
  • Revision ID: package-import@ubuntu.com-20121126182420-qoy6z0nx4ai0wzcl
Tags: 4:3.0.0~beta3-0ubuntu1
* New upstream release
  - Add build-deps :  libhupnp-dev, libqtgstreamer-dev, libmagickcore-dev
* Merge from debian, remaining changes:
  - Make sure libqt4-opengl-dev, libgl1-mesa-dev and libglu1-mesa-dev only
    install on i386,amd64 and powerpc
  - Depend on libtiff-dev instead of libtiff4-dev
  - Drop digikam breaks/replaces kipi-plugins-common since we're past the
    LTS release now
  - digikam to recommend mplayerthumbs | ffmpegthumbs. We currently only
    have latter in the archives, even though former is also supposed to
    be part of kdemultimedia. (LP: #890059)
  - kipi-plugins to recommend www-browser rather than konqueror directly
    since 2.8 no direct usage of konqueror is present in the flickr
    plugin anymore (LP: #1011211)
  - Keep kubuntu_mysqld_executable_name.diff
  - Don't install libkipi translations
  - Keep deps on libcv-dev, libcvaux-dev
  - Keep split packaging of libraries
  - Replace icons from KDE 3 time in debian/xpm.d/*.xpm with the new
    versions (LP: #658047)
* Update debian/not-installed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
    RawSpeed - RAW file decoder.
 
3
 
 
4
    Copyright (C) 2009 Klaus Post
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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
 
19
 
 
20
    http://www.klauspost.com
 
21
*/
 
22
#ifndef BIT_PUMP_MSB_H
 
23
#define BIT_PUMP_MSB_H
 
24
 
 
25
#include "ByteStream.h"
 
26
 
 
27
#define BITS_PER_LONG (8*sizeof(uint32))
 
28
#define MIN_GET_BITS  (BITS_PER_LONG-7)    /* max value for long getBuffer */
 
29
 
 
30
namespace RawSpeed {
 
31
 
 
32
// Note: Allocated buffer MUST be at least size+sizeof(uint32) large.
 
33
 
 
34
class BitPumpMSB
 
35
{
 
36
public:
 
37
  BitPumpMSB(ByteStream *s);
 
38
  BitPumpMSB(const uchar8* _buffer, uint32 _size );
 
39
        uint32 getBitsSafe(uint32 nbits);
 
40
        uint32 getBitSafe();
 
41
        uchar8 getByteSafe();
 
42
        void setAbsoluteOffset(uint32 offset);     // Set offset in bytes
 
43
  __inline uint32 getOffset() { return off-(mLeft>>3);}
 
44
  __inline void checkPos()  { if (off>size+12) throw IOException("Out of buffer read");};        // Check if we have a valid position
 
45
 
 
46
  // Fill the buffer with at least 24 bits
 
47
 void fill();
 
48
 __inline uint32 peekBitsNoFill( uint32 nbits )
 
49
 {
 
50
   int shift = mLeft-nbits;
 
51
   uint32 ret = *(uint32*)&current_buffer[shift>>3];
 
52
   ret >>= shift & 7;
 
53
   return ret & ((1 << nbits) - 1);
 
54
 }
 
55
 
 
56
 
 
57
__inline uint32 getBit() {
 
58
  if (!mLeft) fill();
 
59
  mLeft--;
 
60
  uint32 _byte = mLeft >> 3;
 
61
  return (current_buffer[_byte] >> (mLeft & 0x7)) & 1;
 
62
}
 
63
 
 
64
__inline uint32 getBitsNoFill(uint32 nbits) {
 
65
        uint32 ret = peekBitsNoFill(nbits);
 
66
        mLeft -= nbits;
 
67
        return ret;
 
68
}
 
69
__inline uint32 getBits(uint32 nbits) {
 
70
        fill();
 
71
        return getBitsNoFill(nbits);
 
72
}
 
73
 
 
74
__inline uint32 peekBit() {
 
75
  if (!mLeft) fill();
 
76
  return (current_buffer[(mLeft-1) >> 3] >> ((mLeft-1) & 0x7)) & 1;
 
77
}
 
78
__inline uint32 getBitNoFill() {
 
79
  mLeft--;
 
80
  uint32 ret = (current_buffer[mLeft >> 3] >> (mLeft & 0x7)) & 1;
 
81
  return ret;
 
82
}
 
83
 
 
84
__inline uint32 peekByteNoFill() {
 
85
  int shift = mLeft-8;
 
86
  uint32 ret = *(uint32*)&current_buffer[shift>>3];
 
87
  ret >>= shift & 7;
 
88
  return ret & 0xff;
 
89
}
 
90
 
 
91
__inline uint32 peekBits(uint32 nbits) {
 
92
  fill();
 
93
  return peekBitsNoFill(nbits);
 
94
}
 
95
 
 
96
__inline uint32 peekByte() {
 
97
   fill();
 
98
 
 
99
  if (off > size)
 
100
    throw IOException("Out of buffer read");
 
101
 
 
102
  return peekByteNoFill();
 
103
 
104
 
 
105
  __inline void skipBits(unsigned int nbits) {
 
106
    while (nbits) {
 
107
      fill();
 
108
      checkPos();
 
109
      int n = MIN(nbits, mLeft);
 
110
      mLeft -= n;
 
111
      nbits -= n;
 
112
    }
 
113
  }
 
114
 
 
115
  __inline void skipBitsNoFill(unsigned int nbits) {
 
116
    mLeft -= nbits;
 
117
  }
 
118
 
 
119
  __inline unsigned char getByte() {
 
120
    fill();
 
121
    mLeft-=8;
 
122
    int shift = mLeft;
 
123
    uint32 ret = *(uint32*)&current_buffer[shift>>3];
 
124
    ret >>= shift & 7;
 
125
    return ret & 0xff;
 
126
  }
 
127
 
 
128
  virtual ~BitPumpMSB(void);
 
129
protected:
 
130
  void __inline init();
 
131
  const uchar8* buffer;
 
132
  uchar8* current_buffer;
 
133
  const uint32 size;            // This if the end of buffer.
 
134
  uint32 mLeft;
 
135
  uint32 off;                  // Offset in bytes
 
136
private:
 
137
};
 
138
 
 
139
} // namespace RawSpeed
 
140
 
 
141
#endif//BIT_PUMP_MSB_H