Coverage Report

Created: 2026-11-12 07:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dcmtk/dcmjpls/libcharls/lltraits.h
Line
Count
Source
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
#include "header.h"
11
12
//
13
// optimized trait classes for lossless compression of 8 bit color and 8/16 bit monochrome images.
14
// This class is assumes MAXVAL correspond to a whole number of bits, and no custom RESET value is set when encoding.
15
// The point of this is to have the most optimized code for the most common and most demanding scenario. 
16
17
template <class sample, LONG bitsperpixel>
18
struct LosslessTraitsImplT 
19
{
20
  typedef sample SAMPLE;
21
  enum { 
22
    NEAR  = 0,
23
    bpp   = bitsperpixel,
24
    qbpp  = bitsperpixel,
25
    RANGE = (1 << bpp),
26
    MAXVAL= (1 << bpp) - 1,
27
    LIMIT = 2 * (bitsperpixel + MAX(8,bitsperpixel)),
28
    RESET = BASIC_RESET
29
  };
30
31
  static inlinehint LONG ComputeErrVal(LONG d)
32
0
  { return ModRange(d); }
Unexecuted instantiation: LosslessTraitsImplT<unsigned char, 8l>::ComputeErrVal(long)
Unexecuted instantiation: LosslessTraitsImplT<unsigned short, 12l>::ComputeErrVal(long)
33
    
34
  static inlinehint bool IsNear(LONG lhs, LONG rhs) 
35
0
    { return lhs == rhs; }
Unexecuted instantiation: LosslessTraitsImplT<unsigned char, 8l>::IsNear(long, long)
Unexecuted instantiation: LosslessTraitsImplT<unsigned short, 12l>::IsNear(long, long)
Unexecuted instantiation: LosslessTraitsImplT<unsigned short, 16l>::IsNear(long, long)
36
37
  static inlinehint LONG ModRange(LONG Errval) 
38
0
  {
39
0
    return LONG(Errval << (LONG_BITCOUNT  - bpp)) >> (LONG_BITCOUNT  - bpp); 
40
0
  }
Unexecuted instantiation: LosslessTraitsImplT<unsigned char, 8l>::ModRange(long)
Unexecuted instantiation: LosslessTraitsImplT<unsigned short, 12l>::ModRange(long)
41
  
42
  static inlinehint SAMPLE ComputeReconstructedSample(LONG Px, LONG ErrVal)
43
0
  {
44
0
    return SAMPLE(MAXVAL & (Px + ErrVal)); 
45
0
  }
46
47
  static inlinehint LONG CorrectPrediction(LONG Pxc) 
48
0
  {
49
0
    if ((Pxc & MAXVAL) == Pxc)
50
0
      return Pxc;
51
    
52
0
    return (~(Pxc >> (LONG_BITCOUNT-1))) & MAXVAL;   
53
0
  }
Unexecuted instantiation: LosslessTraitsImplT<unsigned char, 8l>::CorrectPrediction(long)
Unexecuted instantiation: LosslessTraitsImplT<unsigned short, 12l>::CorrectPrediction(long)
Unexecuted instantiation: LosslessTraitsImplT<unsigned short, 16l>::CorrectPrediction(long)
54
55
};
56
57
// xlC (compiler on AIX) tries to instantiate Triple<Triple<char> > which
58
// causes compiler errors and is wrong (other compilers don't instantiate it).
59
#ifdef __xlC__
60
#define DISABLE_SPECIALIZATIONS
61
#else
62
63
template <class SAMPLE, LONG bpp>
64
struct LosslessTraitsT : public LosslessTraitsImplT<SAMPLE, bpp> 
65
{
66
  typedef SAMPLE PIXEL;
67
};
68
69
70
71
template<>
72
struct LosslessTraitsT<BYTE,8> : public LosslessTraitsImplT<BYTE, 8> 
73
{
74
  typedef SAMPLE PIXEL;
75
76
  static inlinehint signed char ModRange(LONG Errval) 
77
0
    { return (signed char)Errval; }
78
79
  static inlinehint LONG ComputeErrVal(LONG d)
80
0
  { return (signed char)(d); }
81
82
  static inlinehint BYTE ComputeReconstructedSample(LONG Px, LONG ErrVal)
83
0
    { return BYTE(Px + ErrVal);  }
84
  
85
};
86
87
88
89
template<>
90
struct LosslessTraitsT<USHORT,16> : public LosslessTraitsImplT<USHORT,16> 
91
{
92
  typedef SAMPLE PIXEL;
93
94
  static inlinehint short ModRange(LONG Errval) 
95
0
    { return short(Errval); }
96
97
  static inlinehint LONG ComputeErrVal(LONG d)
98
0
  { return short(d); }
99
100
  static inlinehint SAMPLE ComputeReconstructedSample(LONG Px, LONG ErrVal)
101
0
    { return SAMPLE(Px + ErrVal);  }
102
103
};
104
105
106
107
108
template<class SAMPLE, LONG bpp>
109
struct LosslessTraitsT<Triplet<SAMPLE>,bpp> : public LosslessTraitsImplT<SAMPLE,bpp>
110
{
111
  typedef Triplet<SAMPLE> PIXEL;
112
113
  static inlinehint bool IsNear(LONG lhs, LONG rhs) 
114
    { return lhs == rhs; }
115
116
  static inlinehint bool IsNear(PIXEL lhs, PIXEL rhs) 
117
0
    { return lhs == rhs; }
118
119
120
  static inlinehint SAMPLE ComputeReconstructedSample(LONG Px, LONG ErrVal)
121
0
    { return SAMPLE(Px + ErrVal);  }
122
123
124
};
125
#endif
126
127
#endif