~ubuntu-branches/ubuntu/vivid/rawstudio/vivid

« back to all changes in this revision

Viewing changes to plugins/load-rawspeed/rawspeed/BitPumpJPEG.h

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2011-07-28 17:36:32 UTC
  • mfrom: (2.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20110728173632-5czluz9ye3c83zc5
Tags: 2.0-1
* [3750b2cf] Merge commit 'upstream/2.0'
* [63637468] Removing Patch, not necessary anymore.
* [2fb580dc] Add new build-dependencies.
* [c57d953b] Run dh_autoreconf due to patches in configure.in
* [13febe39] Add patch to remove the libssl requirement.
* [5ae773fe] Replace libjpeg62-dev by libjpeg8-dev :)
* [1969d755] Don't build static libraries.
* [7cfe0a2e] Add a patch to fix the plugin directory path.
  As plugins are shared libraries, they need to go into /usr/lib,
  not into /usr/share.
  Thanks to Andrew McMillan
* [c1d0d9dd] Don't install .la files for all plugins and libraries.

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_JPEG_H
 
23
#define BIT_PUMP_JPEG_H
 
24
 
 
25
#include "ByteStream.h"
 
26
#include "IOException.h"
 
27
 
 
28
namespace RawSpeed {
 
29
 
 
30
// Note: Allocated buffer MUST be at least size+sizeof(uint32) large.
 
31
 
 
32
class BitPumpJPEG
 
33
{
 
34
public:
 
35
  BitPumpJPEG(ByteStream *s);
 
36
  BitPumpJPEG(const uchar8* _buffer, uint32 _size );
 
37
        uint32 getBits(uint32 nbits);
 
38
        uint32 getBit();
 
39
        uint32 getBitsSafe(uint32 nbits);
 
40
        uint32 getBitSafe();
 
41
        uint32 peekBits(uint32 nbits);
 
42
        uint32 peekBit();
 
43
  uint32 peekByte();
 
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
 
47
        uchar8 getByte();
 
48
        uchar8 getByteSafe();
 
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);}
 
55
 
 
56
#define TEST_IF_FF(VAL) if (VAL == 0xFF) {\
 
57
  if (buffer[off] == 0)\
 
58
  off++;\
 
59
  else  {\
 
60
  VAL = 0;off--;stuffed++;\
 
61
  }\
 
62
  }
 
63
 
 
64
 
 
65
  // Fill the buffer with at least 24 bits
 
66
  __inline void fill() {
 
67
    uchar8 c, c2, c3;
 
68
 
 
69
    int m = mLeft >> 3;
 
70
 
 
71
    if (mLeft > 23)
 
72
      return;
 
73
 
 
74
    if (m == 2)
 
75
    {
 
76
      // 16 to 23 bits left, we can add 1 byte
 
77
      c = buffer[off++];
 
78
      TEST_IF_FF(c);
 
79
      mCurr = (mCurr << 8) | c;
 
80
      mLeft += 8;
 
81
      return;
 
82
    }
 
83
 
 
84
    if (m == 1)
 
85
    {
 
86
      // 8 to 15 bits left, we can add 2 bytes
 
87
      c = buffer[off++];
 
88
      TEST_IF_FF(c);
 
89
      c2 = buffer[off++];
 
90
      TEST_IF_FF(c2);
 
91
      mCurr = (mCurr << 16) | (c<<8) | c2;
 
92
      mLeft += 16;
 
93
      return;
 
94
    }
 
95
 
 
96
    // 0 to 7 bits left, we can add 3 bytes
 
97
    c = buffer[off++];
 
98
    TEST_IF_FF(c);
 
99
    c2 = buffer[off++];
 
100
    TEST_IF_FF(c2);
 
101
    c3 = buffer[off++];
 
102
    TEST_IF_FF(c3);
 
103
    mCurr = (mCurr << 24) | (c<<16) | (c2<<8) | c3;
 
104
    mLeft += 24;
 
105
  }
 
106
 
 
107
#undef TEST_IF_FF
 
108
 
 
109
  virtual ~BitPumpJPEG(void);
 
110
protected:
 
111
  void __inline init();
 
112
  const uchar8* buffer;
 
113
  const uint32 size;            // This if the end of buffer.
 
114
  uint32 mLeft;
 
115
  uint32 mCurr;
 
116
  uint32 off;                  // Offset in bytes
 
117
  uint32 stuffed;              // How many bytes has been stuffed?
 
118
private:
 
119
};
 
120
 
 
121
} // namespace RawSpeed
 
122
 
 
123
#endif