OFFIS DCMTK  Version 3.6.0
lltraits.h
1 //
2 // (C) Jan de Vaan 2007-2010, all rights reserved. See the accompanying "License.txt" for licensed use.
3 //
4 
5 
6 
7 #ifndef CHARLS_LOSSLESSTRAITS
8 #define CHARLS_LOSSLESSTRAITS
9 
10 //
11 // optimized trait classes for lossless compression of 8 bit color and 8/16 bit monochrome images.
12 // This class is assumes MAXVAL correspond to a whole number of bits, and no custom RESET value is set when encoding.
13 // The point of this is to have the most optimized code for the most common and most demanding scenario.
14 
15 template <class sample, LONG bitsperpixel>
17 {
18  typedef sample SAMPLE;
19  enum {
20  NEAR = 0,
21  bpp = bitsperpixel,
22  qbpp = bitsperpixel,
23  RANGE = (1 << bpp),
24  MAXVAL= (1 << bpp) - 1,
25  LIMIT = 2 * (bitsperpixel + MAX(8,bitsperpixel)),
26  RESET = BASIC_RESET
27  };
28 
29  static inlinehint LONG ComputeErrVal(LONG d)
30  { return ModRange(d); }
31 
32  static inlinehint bool IsNear(LONG lhs, LONG rhs)
33  { return lhs == rhs; }
34 
35  static inlinehint LONG ModRange(LONG Errval)
36  {
37  return LONG(Errval << (LONG_BITCOUNT - bpp)) >> (LONG_BITCOUNT - bpp);
38  }
39 
40  static inlinehint SAMPLE ComputeReconstructedSample(LONG Px, LONG ErrVal)
41  {
42  return SAMPLE(MAXVAL & (Px + ErrVal));
43  }
44 
45  static inlinehint LONG CorrectPrediction(LONG Pxc)
46  {
47  if ((Pxc & MAXVAL) == Pxc)
48  return Pxc;
49 
50  return (~(Pxc >> (LONG_BITCOUNT-1))) & MAXVAL;
51  }
52 
53 };
54 
55 // For some weird reason MSVC6 doesn't like these templates
56 #if defined(_MSC_VER) && _MSC_VER <= 1200
57 # define DISABLE_SPECIALIZATIONS
58 #else
59 
60 template <class SAMPLE, LONG bpp>
61 struct LosslessTraitsT : public LosslessTraitsImplT<SAMPLE, bpp>
62 {
63  typedef SAMPLE PIXEL;
64 };
65 
66 
67 
68 template<>
69 struct LosslessTraitsT<BYTE,8> : public LosslessTraitsImplT<BYTE, 8>
70 {
71  typedef SAMPLE PIXEL;
72 
73  static inlinehint signed char ModRange(LONG Errval)
74  { return (signed char)Errval; }
75 
76  static inlinehint LONG ComputeErrVal(LONG d)
77  { return (signed char)(d); }
78 
79  static inlinehint BYTE ComputeReconstructedSample(LONG Px, LONG ErrVal)
80  { return BYTE(Px + ErrVal); }
81 
82 };
83 
84 
85 
86 template<>
87 struct LosslessTraitsT<USHORT,16> : public LosslessTraitsImplT<USHORT,16>
88 {
89  typedef SAMPLE PIXEL;
90 
91  static inlinehint short ModRange(LONG Errval)
92  { return short(Errval); }
93 
94  static inlinehint LONG ComputeErrVal(LONG d)
95  { return short(d); }
96 
97  static inlinehint SAMPLE ComputeReconstructedSample(LONG Px, LONG ErrVal)
98  { return SAMPLE(Px + ErrVal); }
99 
100 };
101 
102 
103 
104 
105 template<class SAMPLE, LONG bpp>
106 struct LosslessTraitsT<Triplet<SAMPLE>,bpp> : public LosslessTraitsImplT<SAMPLE,bpp>
107 {
108  typedef Triplet<SAMPLE> PIXEL;
109 
110  static inlinehint bool IsNear(LONG lhs, LONG rhs)
111  { return lhs == rhs; }
112 
113  static inlinehint bool IsNear(PIXEL lhs, PIXEL rhs)
114  { return lhs == rhs; }
115 
116 
117  static inlinehint SAMPLE ComputeReconstructedSample(LONG Px, LONG ErrVal)
118  { return SAMPLE(Px + ErrVal); }
119 
120 
121 };
122 #endif
123 
124 #endif


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