/usr/include/CharLS/processline.h is in libcharls-dev 1.0-6.
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | //
// (C) Jan de Vaan 2007-2010, all rights reserved. See the accompanying "License.txt" for licensed use.
//
#ifndef CHARLS_PROCESSLINE
#define CHARLS_PROCESSLINE
#include "colortransform.h"
//
// This file defines the ProcessLine base class, its derivitives and helper functions.
// During coding/decoding, CharLS process one line at a time. The different Processline implementations
// convert the uncompressed format to and from the internal format for encoding.
// Conversions include color transforms, line interleaved vs sample interleaved, masking out unused bits,
// accounting for line padding etc.
// This mechanism could be used to encode/decode images as they are received.
//
class ProcessLine
{
public:
virtual ~ProcessLine() {}
virtual void NewLineDecoded(const void* pSrc, int pixelCount, int bytesperline) = 0;
virtual void NewLineRequested(void* pSrc, int pixelCount, int bytesperline) = 0;
};
class PostProcesSingleComponent : public ProcessLine
{
public:
PostProcesSingleComponent(void* pbyteOutput, const JlsParameters& info, int bytesPerPixel) :
_pbyteOutput((BYTE*)pbyteOutput),
_bytesPerPixel(bytesPerPixel),
_bytesPerLine(info.bytesperline)
{
}
void NewLineRequested(void* pDst, int pixelCount, int /*byteStride*/)
{
::memcpy(pDst, _pbyteOutput, pixelCount * _bytesPerPixel);
_pbyteOutput += _bytesPerLine;
}
void NewLineDecoded(const void* pSrc, int pixelCount, int /*byteStride*/)
{
::memcpy(_pbyteOutput, pSrc, pixelCount * _bytesPerPixel);
_pbyteOutput += _bytesPerLine;
}
private:
BYTE* _pbyteOutput;
int _bytesPerPixel;
int _bytesPerLine;
};
template<class TRANSFORM, class SAMPLE>
void TransformLineToQuad(const SAMPLE* ptypeInput, LONG pixelStrideIn, Quad<SAMPLE>* pbyteBuffer, LONG pixelStride, TRANSFORM& transform)
{
int cpixel = MIN(pixelStride, pixelStrideIn);
Quad<SAMPLE>* ptypeBuffer = (Quad<SAMPLE>*)pbyteBuffer;
for (int x = 0; x < cpixel; ++x)
{
Quad<SAMPLE> pixel(transform(ptypeInput[x], ptypeInput[x + pixelStrideIn], ptypeInput[x + 2*pixelStrideIn]),ptypeInput[x + 3*pixelStrideIn]) ;
ptypeBuffer[x] = pixel;
}
}
template<class TRANSFORM, class SAMPLE>
void TransformQuadToLine(const Quad<SAMPLE>* pbyteInput, LONG pixelStrideIn, SAMPLE* ptypeBuffer, LONG pixelStride, TRANSFORM& transform)
{
int cpixel = MIN(pixelStride, pixelStrideIn);
const Quad<SAMPLE>* ptypeBufferIn = (Quad<SAMPLE>*)pbyteInput;
for (int x = 0; x < cpixel; ++x)
{
Quad<SAMPLE> color = ptypeBufferIn[x];
Quad<SAMPLE> colorTranformed(transform(color.v1, color.v2, color.v3), color.v4);
ptypeBuffer[x] = colorTranformed.v1;
ptypeBuffer[x + pixelStride] = colorTranformed.v2;
ptypeBuffer[x + 2 *pixelStride] = colorTranformed.v3;
ptypeBuffer[x + 3 *pixelStride] = colorTranformed.v4;
}
}
template<class SAMPLE>
void TransformRgbToBgr(SAMPLE* pDest, int samplesPerPixel, int pixelCount)
{
for (int i = 0; i < pixelCount; ++i)
{
std::swap(pDest[0], pDest[2]);
pDest += samplesPerPixel;
}
}
template<class TRANSFORM, class SAMPLE>
void TransformLine(Triplet<SAMPLE>* pDest, const Triplet<SAMPLE>* pSrc, int pixelCount, TRANSFORM& transform)
{
for (int i = 0; i < pixelCount; ++i)
{
pDest[i] = transform(pSrc[i].v1, pSrc[i].v2, pSrc[i].v3);
}
}
template<class TRANSFORM, class SAMPLE>
void TransformLineToTriplet(const SAMPLE* ptypeInput, LONG pixelStrideIn, Triplet<SAMPLE>* pbyteBuffer, LONG pixelStride, TRANSFORM& transform)
{
int cpixel = MIN(pixelStride, pixelStrideIn);
Triplet<SAMPLE>* ptypeBuffer = (Triplet<SAMPLE>*)pbyteBuffer;
for (int x = 0; x < cpixel; ++x)
{
ptypeBuffer[x] = transform(ptypeInput[x], ptypeInput[x + pixelStrideIn], ptypeInput[x + 2*pixelStrideIn]);
}
}
template<class TRANSFORM, class SAMPLE>
void TransformTripletToLine(const Triplet<SAMPLE>* pbyteInput, LONG pixelStrideIn, SAMPLE* ptypeBuffer, LONG pixelStride, TRANSFORM& transform)
{
int cpixel = MIN(pixelStride, pixelStrideIn);
const Triplet<SAMPLE>* ptypeBufferIn = (Triplet<SAMPLE>*)pbyteInput;
for (int x = 0; x < cpixel; ++x)
{
Triplet<SAMPLE> color = ptypeBufferIn[x];
Triplet<SAMPLE> colorTranformed = transform(color.v1, color.v2, color.v3);
ptypeBuffer[x] = colorTranformed.v1;
ptypeBuffer[x + pixelStride] = colorTranformed.v2;
ptypeBuffer[x + 2 *pixelStride] = colorTranformed.v3;
}
}
template<class TRANSFORM>
class ProcessTransformed : public ProcessLine
{
typedef typename TRANSFORM::SAMPLE SAMPLE;
ProcessTransformed(const ProcessTransformed&);
public:
ProcessTransformed(void* pbyteOutput, const JlsParameters& info, TRANSFORM transform) :
_pbyteOutput((BYTE*)pbyteOutput),
_info(info),
_templine(info.width * info.components),
_transform(transform),
_inverseTransform(transform)
{
// ASSERT(_info.components == sizeof(TRIPLET)/sizeof(TRIPLET::SAMPLE));
}
void NewLineRequested(void* pDst, int pixelCount, int stride)
{
SAMPLE* pLine = (SAMPLE*)_pbyteOutput;
if (_info.outputBgr)
{
pLine = &_templine[0];
memcpy(pLine, _pbyteOutput, sizeof(Triplet<SAMPLE>)*pixelCount);
TransformRgbToBgr(pLine, _info.components, pixelCount);
}
if (_info.components == 3)
{
if (_info.ilv == ILV_SAMPLE)
{
TransformLine((Triplet<SAMPLE>*)pDst, (const Triplet<SAMPLE>*)pLine, pixelCount, _transform);
}
else
{
TransformTripletToLine((const Triplet<SAMPLE>*)pLine, pixelCount, (SAMPLE*)pDst, stride, _transform);
}
}
else if (_info.components == 4 && _info.ilv == ILV_LINE)
{
TransformQuadToLine((const Quad<SAMPLE>*)pLine, pixelCount, (SAMPLE*)pDst, stride, _transform);
}
_pbyteOutput += _info.bytesperline;
}
void NewLineDecoded(const void* pSrc, int pixelCount, int byteStride)
{
if (_info.components == 3)
{
if (_info.ilv == ILV_SAMPLE)
{
TransformLine((Triplet<SAMPLE>*)_pbyteOutput, (const Triplet<SAMPLE>*)pSrc, pixelCount, _inverseTransform);
}
else
{
TransformLineToTriplet((const SAMPLE*)pSrc, byteStride, (Triplet<SAMPLE>*)_pbyteOutput, pixelCount, _inverseTransform);
}
}
else if (_info.components == 4 && _info.ilv == ILV_LINE)
{
TransformLineToQuad((const SAMPLE*)pSrc, byteStride, (Quad<SAMPLE>*)_pbyteOutput, pixelCount, _inverseTransform);
}
if (_info.outputBgr)
{
TransformRgbToBgr(_pbyteOutput, _info.components, pixelCount);
}
_pbyteOutput += _info.bytesperline;
}
private:
BYTE* _pbyteOutput;
const JlsParameters& _info;
std::vector<SAMPLE> _templine;
TRANSFORM _transform;
typename TRANSFORM::INVERSE _inverseTransform;
};
#endif
|