OFFIS DCMTK  Version 3.6.0
ctxtrmod.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_CONTEXTRUNMODE
7 #define CHARLS_CONTEXTRUNMODE
8 
9 // Implements statistical modelling for the run mode context.
10 // Computes model dependent parameters like the golomb code lengths
11 
13 {
14  CContextRunMode(LONG a, LONG nRItype, LONG nReset) :
15  A(a),
16  N(1),
17  Nn(0),
18  _nRItype(nRItype),
19  _nReset((BYTE)nReset)
20  {
21  }
22 
23  LONG A;
24  BYTE N;
25  BYTE Nn;
26  LONG _nRItype;
27  BYTE _nReset;
28 
30  {}
31 
32 
33  inlinehint LONG GetGolomb() const
34  {
35  LONG Ntest = N;
36  LONG TEMP = A + (N >> 1) * _nRItype;
37  LONG k = 0;
38  for(; Ntest < TEMP; k++)
39  {
40  Ntest <<= 1;
41  ASSERT(k <= 32);
42  };
43  return k;
44  }
45 
46 
47  void UpdateVariables(LONG Errval, LONG EMErrval)
48  {
49  if (Errval < 0)
50  {
51  Nn = Nn + 1;
52  }
53  A = A + ((EMErrval + 1 - _nRItype) >> 1);
54  if (N == _nReset)
55  {
56  A = A >> 1;
57  N = N >> 1;
58  Nn = Nn >> 1;
59  }
60  N = N + 1;
61  }
62 
63  inlinehint LONG ComputeErrVal(LONG temp, LONG k)
64  {
65  bool map = temp & 1;
66 
67  LONG errvalabs = (temp + map) / 2;
68 
69  if ((k != 0 || (2 * Nn >= N)) == map)
70  {
71  ASSERT(map == ComputeMap(-errvalabs, k));
72  return -errvalabs;
73  }
74 
75  ASSERT(map == ComputeMap(errvalabs, k));
76  return errvalabs;
77  }
78 
79 
80  bool ComputeMap(LONG Errval, LONG k) const
81  {
82  if ((k == 0) && (Errval > 0) && (2 * Nn < N))
83  return 1;
84 
85  else if ((Errval < 0) && (2 * Nn >= N))
86  return 1;
87 
88  else if ((Errval < 0) && (k != 0))
89  return 1;
90 
91  return 0;
92  }
93 
94 
95  inlinehint LONG ComputeMapNegativeE(LONG k) const
96  {
97  return k != 0 || (2 * Nn >= N );
98  }
99 };
100 
101 #endif


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