OFFIS DCMTK  Version 3.6.0
context.h
1 //
2 // (C) Jan de Vaan 2007-2010, all rights reserved. See the accompanying "License.txt" for licensed use.
3 //
4 
5 
6 #ifndef CHARLS_CONTEXT
7 #define CHARLS_CONTEXT
8 
9 
10 //
11 // JlsContext: a JPEG-LS context with it's current statistics.
12 //
13 struct JlsContext
14 {
15 public:
16  JlsContext()
17  {}
18 
19  JlsContext(LONG a) :
20  A(a),
21  B(0),
22  C(0),
23  N(1)
24  {
25  }
26 
27  LONG A;
28  LONG B;
29  short C;
30  short N;
31 
32  inlinehint LONG GetErrorCorrection(LONG k) const
33  {
34  if (k != 0)
35  return 0;
36 
37  return BitWiseSign(2 * B + N - 1);
38  }
39 
40 
41  inlinehint void UpdateVariables(LONG errorValue, LONG NEAR, LONG NRESET)
42  {
43  ASSERT(N != 0);
44 
45  // For performance work on copies of A,B,N (compiler will use registers).
46  int b = B + errorValue * (2 * NEAR + 1);
47  int a = A + ABS(errorValue);
48  int n = N;
49 
50  ASSERT(a < 65536 * 256);
51  ASSERT(ABS(b) < 65536 * 256);
52 
53  if (n == NRESET)
54  {
55  a = a >> 1;
56  b = b >> 1;
57  n = n >> 1;
58  }
59 
60  n = n + 1;
61 
62  if (b + n <= 0)
63  {
64  b = b + n;
65  if (b <= -n)
66  {
67  b = -n + 1;
68  }
69  C = _tableC[C - 1];
70  }
71  else if (b > 0)
72  {
73  b = b - n;
74  if (b > 0)
75  {
76  b = 0;
77  }
78  C = _tableC[C + 1];
79  }
80  A = a;
81  B = b;
82  N = (short)n;
83  ASSERT(N != 0);
84  }
85 
86 
87 
88  inlinehint LONG GetGolomb() const
89  {
90  LONG Ntest = N;
91  LONG Atest = A;
92  LONG k = 0;
93  for(; (Ntest << k) < Atest; k++)
94  {
95  ASSERT(k <= 32);
96  };
97  return k;
98  }
99 
100  static signed char* CreateTableC()
101  {
102  static OFVector<signed char> rgtableC;
103 
104  rgtableC.reserve(256 + 2);
105 
106  rgtableC.push_back(-128);
107  for (int i = -128; i < 128; i++)
108  {
109  rgtableC.push_back(char(i));
110  }
111  rgtableC.push_back(127);
112 
113  signed char* pZero = &rgtableC[128 + 1];
114  ASSERT(pZero[0] == 0);
115  return pZero;
116  }
117 private:
118 
119  static signed char* _tableC;
120 };
121 
122 #endif


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2