/usr/include/CharLS/defaulttraits.h is in libcharls-dev 1.1.0+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | //
// (C) Jan de Vaan 2007-2010, all rights reserved. See the accompanying "License.txt" for licensed use.
//
#ifndef CHARLS_DEFAULTTRAITS
#define CHARLS_DEFAULTTRAITS
// Default traits that support all JPEG LS parameters: custom limit, near, maxval (not power of 2)
// This traits class is used to initialize a coder/decoder.
// The coder/decoder also delegates some functions to the traits class.
// This is to allow the traits class to replace the default implementation here with optimized specific implementations.
// This is done for lossless coding/decoding: see losslesstraits.h
#include <cstdlib>
template <class sample, class pixel>
struct DefaultTraitsT
{
public:
typedef sample SAMPLE;
typedef pixel PIXEL;
LONG MAXVAL;
LONG RANGE;
LONG NEAR;
LONG qbpp;
LONG bpp;
LONG LIMIT;
LONG RESET;
DefaultTraitsT(const DefaultTraitsT& src) :
MAXVAL(src.MAXVAL),
RANGE(src.RANGE),
NEAR(src.NEAR),
qbpp(src.qbpp),
bpp(src.bpp),
LIMIT(src.LIMIT),
RESET(src.RESET)
{
}
DefaultTraitsT(LONG max, LONG jls_near)
{
NEAR = jls_near;
MAXVAL = max;
RANGE = (MAXVAL + 2 * NEAR )/(2 * NEAR + 1) + 1;
bpp = log_2(max);
LIMIT = 2 * (bpp + MAX(8,bpp));
qbpp = log_2(RANGE);
RESET = BASIC_RESET;
}
inlinehint LONG ComputeErrVal(LONG e) const
{
return ModRange(Quantize(e));
}
inlinehint SAMPLE ComputeReconstructedSample(LONG Px, LONG ErrVal)
{
return FixReconstructedValue(Px + DeQuantize(ErrVal));
}
inlinehint bool IsNear(LONG lhs, LONG rhs) const
{ return std::abs(lhs-rhs) <=NEAR; }
bool IsNear(Triplet<SAMPLE> lhs, Triplet<SAMPLE> rhs) const
{
return std::abs(lhs.v1 - rhs.v1) <= NEAR &&
std::abs(lhs.v2 - rhs.v2) <= NEAR &&
std::abs(lhs.v3 - rhs.v3) <= NEAR;
}
inlinehint LONG CorrectPrediction(LONG Pxc) const
{
if ((Pxc & MAXVAL) == Pxc)
return Pxc;
return (~(Pxc >> (LONG_BITCOUNT-1))) & MAXVAL;
}
inlinehint LONG ModRange(LONG Errval) const
{
ASSERT(std::abs(Errval) <= RANGE);
if (Errval < 0)
Errval = Errval + RANGE;
if (Errval >= ((RANGE + 1) / 2))
Errval = Errval - RANGE;
ASSERT(std::abs(Errval) <= RANGE/2);
return Errval;
}
private:
LONG Quantize(LONG Errval) const
{
if (Errval > 0)
return (Errval + NEAR) / (2 * NEAR + 1);
else
return - (NEAR - Errval) / (2 * NEAR + 1);
}
inlinehint LONG DeQuantize(LONG Errval) const
{
return Errval * (2 * NEAR + 1);
}
inlinehint SAMPLE FixReconstructedValue(LONG val) const
{
if (val < -NEAR)
val = val + RANGE*(2*NEAR+1);
else if (val > MAXVAL + NEAR)
val = val - RANGE*(2*NEAR+1);
return SAMPLE(CorrectPrediction(val));
}
};
#endif
|