4 #ifndef CHARLS_PROCESSLINE
5 #define CHARLS_PROCESSLINE
22 virtual void NewLineDecoded(
const void* pSrc,
int pixelCount,
int bytesperline) = 0;
23 virtual void NewLineRequested(
void* pSrc,
int pixelCount,
int bytesperline) = 0;
31 _pbyteOutput((BYTE*)pbyteOutput),
32 _bytesPerPixel(bytesPerPixel),
33 _bytesPerLine(info.bytesperline)
37 void NewLineRequested(
void* pDst,
int pixelCount,
int )
40 _pbyteOutput += _bytesPerLine;
43 void NewLineDecoded(
const void* pSrc,
int pixelCount,
int )
46 _pbyteOutput += _bytesPerLine;
56 template<
class TRANSFORM,
class SAMPLE>
57 void TransformLineToQuad(
const SAMPLE* ptypeInput, LONG pixelStrideIn,
Quad<SAMPLE>* pbyteBuffer, LONG pixelStride, TRANSFORM& transform)
59 int cpixel = MIN(pixelStride, pixelStrideIn);
62 for (
int x = 0; x < cpixel; ++x)
64 Quad<SAMPLE> pixel(transform(ptypeInput[x], ptypeInput[x + pixelStrideIn], ptypeInput[x + 2*pixelStrideIn]),ptypeInput[x + 3*pixelStrideIn]) ;
66 ptypeBuffer[x] = pixel;
71 template<
class TRANSFORM,
class SAMPLE>
72 void TransformQuadToLine(
const Quad<SAMPLE>* pbyteInput, LONG pixelStrideIn, SAMPLE* ptypeBuffer, LONG pixelStride, TRANSFORM& transform)
74 int cpixel = MIN(pixelStride, pixelStrideIn);
77 for (
int x = 0; x < cpixel; ++x)
80 Quad<SAMPLE> colorTranformed(transform(color.v1, color.v2, color.v3), color.v4);
82 ptypeBuffer[x] = colorTranformed.v1;
83 ptypeBuffer[x + pixelStride] = colorTranformed.v2;
84 ptypeBuffer[x + 2 *pixelStride] = colorTranformed.v3;
85 ptypeBuffer[x + 3 *pixelStride] = colorTranformed.v4;
90 template<
class SAMPLE>
91 void TransformRgbToBgr(SAMPLE* pDest,
int samplesPerPixel,
int pixelCount)
93 for (
int i = 0; i < pixelCount; ++i)
95 SAMPLE tmp = pDest[0];
98 pDest += samplesPerPixel;
103 template<
class TRANSFORM,
class SAMPLE>
106 for (
int i = 0; i < pixelCount; ++i)
108 pDest[i] = transform(pSrc[i].v1, pSrc[i].v2, pSrc[i].v3);
113 template<
class TRANSFORM,
class SAMPLE>
114 void TransformLineToTriplet(
const SAMPLE* ptypeInput, LONG pixelStrideIn,
Triplet<SAMPLE>* pbyteBuffer, LONG pixelStride, TRANSFORM& transform)
116 int cpixel = MIN(pixelStride, pixelStrideIn);
119 for (
int x = 0; x < cpixel; ++x)
121 ptypeBuffer[x] = transform(ptypeInput[x], ptypeInput[x + pixelStrideIn], ptypeInput[x + 2*pixelStrideIn]);
126 template<
class TRANSFORM,
class SAMPLE>
127 void TransformTripletToLine(
const Triplet<SAMPLE>* pbyteInput, LONG pixelStrideIn, SAMPLE* ptypeBuffer, LONG pixelStride, TRANSFORM& transform)
129 int cpixel = MIN(pixelStride, pixelStrideIn);
132 for (
int x = 0; x < cpixel; ++x)
135 Triplet<SAMPLE> colorTranformed = transform(color.v1, color.v2, color.v3);
137 ptypeBuffer[x] = colorTranformed.v1;
138 ptypeBuffer[x + pixelStride] = colorTranformed.v2;
139 ptypeBuffer[x + 2 *pixelStride] = colorTranformed.v3;
144 template<
class TRANSFORM>
147 typedef typename TRANSFORM::SAMPLE SAMPLE;
152 _pbyteOutput((BYTE*)pbyteOutput),
154 _templine(info.width * info.components),
155 _transform(transform),
156 _inverseTransform(transform)
162 void NewLineRequested(
void* pDst,
int pixelCount,
int stride)
164 SAMPLE* pLine = (SAMPLE*)_pbyteOutput;
167 pLine = &_templine[0];
169 TransformRgbToBgr(pLine, _info.components, pixelCount);
172 if (_info.components == 3)
174 if (_info.ilv == ILV_SAMPLE)
180 TransformTripletToLine((
const Triplet<SAMPLE>*)pLine, pixelCount, (SAMPLE*)pDst, stride, _transform);
183 else if (_info.components == 4 && _info.ilv == ILV_LINE)
185 TransformQuadToLine((
const Quad<SAMPLE>*)pLine, pixelCount, (SAMPLE*)pDst, stride, _transform);
187 _pbyteOutput += _info.bytesperline;
191 void NewLineDecoded(
const void* pSrc,
int pixelCount,
int byteStride)
193 if (_info.components == 3)
195 if (_info.ilv == ILV_SAMPLE)
201 TransformLineToTriplet((
const SAMPLE*)pSrc, byteStride, (
Triplet<SAMPLE>*)_pbyteOutput, pixelCount, _inverseTransform);
204 else if (_info.components == 4 && _info.ilv == ILV_LINE)
206 TransformLineToQuad((
const SAMPLE*)pSrc, byteStride, (
Quad<SAMPLE>*)_pbyteOutput, pixelCount, _inverseTransform);
211 TransformRgbToBgr(_pbyteOutput, _info.components, pixelCount);
213 _pbyteOutput += _info.bytesperline;
221 TRANSFORM _transform;
222 typename TRANSFORM::INVERSE _inverseTransform;