Commit 6ae44e0a authored by seb's avatar seb
Browse files

second version of MaxipixReconstruction


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@159 45c4679d-1946-429d-baad-37912b19538b
parent 022367b8
sub-dirs = common simulator frelon sub-dirs = common simulator frelon maxipix
include ../global.inc include ../global.inc
...@@ -12,9 +12,9 @@ namespace lima ...@@ -12,9 +12,9 @@ namespace lima
class MaxipixReconstruction : public LinkTask class MaxipixReconstruction : public LinkTask
{ {
public: public:
enum Type {ZERO,DISPATCH,MEAN}; enum Type {RAW,ZERO,DISPATCH,MEAN};
enum Model {M_4x4,M_5x1}; enum Model {M_2x2,M_5x1};
explicit MaxipixReconstruction(Model = M_5x1,Type = ZERO); explicit MaxipixReconstruction(Model = M_5x1,Type = RAW);
MaxipixReconstruction(const MaxipixReconstruction&); MaxipixReconstruction(const MaxipixReconstruction&);
~MaxipixReconstruction(); ~MaxipixReconstruction();
......
namespace Maxipix
{
class MaxipixReconstruction : LinkTask
{
%TypeHeaderCode
#include "MaxipixReconstruction.h"
using namespace lima;
%End
public:
enum Type {RAW,ZERO,DISPATCH,MEAN};
enum Model {M_4x4,M_5x1};
explicit MaxipixReconstruction(Model = M_5x1,
Type = RAW);
MaxipixReconstruction(const Maxipix::MaxipixReconstruction&);
~MaxipixReconstruction();
void setType(Type);
void setXnYGapSpace(int xSpace,int ySpace);
virtual Data process(Data &aData);
};
}; // namespace Maxipix
...@@ -4,7 +4,11 @@ using namespace lima::Maxipix; ...@@ -4,7 +4,11 @@ using namespace lima::Maxipix;
static const int MAXIPIX_LINE_SIZE = 256 * 2; static const int MAXIPIX_LINE_SIZE = 256 * 2;
static const int MAXIPIX_NB_LINE = 256; static const int MAXIPIX_NB_LINE = 256;
static const int MAXIPIX_NB_COLUMN = 256;
//----------------------------------------------------------------------------
// 5x1 copy function
//----------------------------------------------------------------------------
#define COPY_5x1 \ #define COPY_5x1 \
/* set aSrcPt to the last line of the 5th chip */ \ /* set aSrcPt to the last line of the 5th chip */ \
unsigned char *aSrcPt = ((unsigned char*)src.data()) + \ unsigned char *aSrcPt = ((unsigned char*)src.data()) + \
...@@ -14,23 +18,29 @@ static const int MAXIPIX_NB_LINE = 256; ...@@ -14,23 +18,29 @@ static const int MAXIPIX_NB_LINE = 256;
(MAXIPIX_LINE_SIZE * 4 * MAXIPIX_NB_LINE) + \ (MAXIPIX_LINE_SIZE * 4 * MAXIPIX_NB_LINE) + \
(xSpace * 2 * 4 * MAXIPIX_NB_LINE); \ (xSpace * 2 * 4 * MAXIPIX_NB_LINE); \
\ \
/*number of iteration == number of line * number of chip */ \ int aNbLine = MAXIPIX_NB_LINE; \
/* in case of inplace remove the last memcopy (first line of the first chip) */ \
int nbIter = (MAXIPIX_NB_LINE * 5) - int(inplace); \
do \ do \
{ \ { \
int MAXIPIX_LINE_SIZE_COPY = MAXIPIX_LINE_SIZE; \
\
int aNbChipCopyWithGap = 4; \
do \
{ \
memcpy(aDstPt,aSrcPt,MAXIPIX_LINE_SIZE_COPY); \
GAP_COPY_FUNCTION \
aDstPt -= MAXIPIX_LINE_SIZE + xSpace * 2; \
aSrcPt -= MAXIPIX_LINE_SIZE; \
} \
while(--aNbChipCopyWithGap); \
memcpy(aDstPt,aSrcPt,MAXIPIX_LINE_SIZE_COPY); \ memcpy(aDstPt,aSrcPt,MAXIPIX_LINE_SIZE_COPY); \
GAP_COPY_FUNCTION\ aDstPt -= MAXIPIX_LINE_SIZE; \
aDstPt -= MAXIPIX_LINE_SIZE + xSpace * 2; \
aSrcPt -= MAXIPIX_LINE_SIZE; \ aSrcPt -= MAXIPIX_LINE_SIZE; \
} \ } \
while(--nbIter); while(--aNbLine);
static inline void _raw_5x1(Data &src,Data &dst,
static inline void _zero_5x1(Data &src,Data &dst, int xSpace)
int xSpace,bool inplace)
{ {
int MAXIPIX_LINE_SIZE_COPY = MAXIPIX_LINE_SIZE;
#ifdef GAP_COPY_FUNCTION #ifdef GAP_COPY_FUNCTION
#undef GAP_COPY_FUNCTION #undef GAP_COPY_FUNCTION
#endif #endif
...@@ -41,10 +51,22 @@ static inline void _zero_5x1(Data &src,Data &dst, ...@@ -41,10 +51,22 @@ static inline void _zero_5x1(Data &src,Data &dst,
COPY_5x1 COPY_5x1
} }
static inline void _zero_5x1(Data &src,Data &dst,
int xSpace)
{
#ifdef GAP_COPY_FUNCTION
#undef GAP_COPY_FUNCTION
#endif
#define GAP_COPY_FUNCTION \
MAXIPIX_LINE_SIZE_COPY = MAXIPIX_LINE_SIZE - 2; \
unsigned short *aPixel = ((unsigned short*)aDstPt); \
for(int i = xSpace + 2;i;--i,--aPixel) \
*aPixel = 0;
COPY_5x1
}
static inline void _dispatch_5x1(Data &src,Data &dst, static inline void _dispatch_5x1(Data &src,Data &dst,
int xSpace,bool inplace) int xSpace)
{ {
int MAXIPIX_LINE_SIZE_COPY = MAXIPIX_LINE_SIZE;
int nbPixelDispatch = (xSpace >> 1) + 1; // (xSpace / 2) + 1 int nbPixelDispatch = (xSpace >> 1) + 1; // (xSpace / 2) + 1
#ifdef GAP_COPY_FUNCTION #ifdef GAP_COPY_FUNCTION
#undef GAP_COPY_FUNCTION #undef GAP_COPY_FUNCTION
...@@ -64,9 +86,8 @@ COPY_5x1 ...@@ -64,9 +86,8 @@ COPY_5x1
} }
static inline void _mean_5x1(Data &src,Data &dst, static inline void _mean_5x1(Data &src,Data &dst,
int xSpace,bool inplace) int xSpace)
{ {
int MAXIPIX_LINE_SIZE_COPY = MAXIPIX_LINE_SIZE;
int nbPixelMean = (xSpace >> 1) + 1; // (xSpace / 2) + 1 int nbPixelMean = (xSpace >> 1) + 1; // (xSpace / 2) + 1
#ifdef GAP_COPY_FUNCTION #ifdef GAP_COPY_FUNCTION
#undef GAP_COPY_FUNCTION #undef GAP_COPY_FUNCTION
...@@ -85,54 +106,237 @@ static inline void _mean_5x1(Data &src,Data &dst, ...@@ -85,54 +106,237 @@ static inline void _mean_5x1(Data &src,Data &dst,
*aPixel = (unsigned short)aPixelValue; *aPixel = (unsigned short)aPixelValue;
COPY_5x1 COPY_5x1
} }
//----------------------------------------------------------------------------
// 2x2 function
//----------------------------------------------------------------------------
static inline void copy_2x2(Data &src,Buffer *dst,int xSpace,int ySpace)
{
unsigned short *aSrcPt = (unsigned short*)src.data();
unsigned short *aDstPt = ((unsigned short*)dst->data) +
(((MAXIPIX_LINE_SIZE + xSpace) * (MAXIPIX_NB_LINE + (ySpace >> 1))) << 1) -
MAXIPIX_LINE_SIZE;
Data MaxipixReconstruction::process(Data &aData) int aJump2LeftChip = MAXIPIX_LINE_SIZE + xSpace - 1;
int aColumnIterNumber = MAXIPIX_NB_COLUMN;
do
{
// copy left chip
int chipNb = 2;
do
{
for(int i = MAXIPIX_NB_LINE;i;--i,aDstPt -= (MAXIPIX_LINE_SIZE + xSpace),++aSrcPt)
*aDstPt = *aSrcPt;
aDstPt -= (MAXIPIX_LINE_SIZE + xSpace) * ySpace;
}
while(--chipNb);
aDstPt += aJump2LeftChip;
//copy right chips
chipNb = 2;
do
{
for(int i = MAXIPIX_NB_LINE;i;--i,aDstPt += (MAXIPIX_LINE_SIZE + xSpace),++aSrcPt)
*aDstPt = *aSrcPt;
aDstPt += (MAXIPIX_LINE_SIZE + xSpace) * ySpace;
}
while(--chipNb);
--aJump2LeftChip;
aDstPt -= aJump2LeftChip;
}
while(--aColumnIterNumber);
}
static inline void _raw_2x2(Data &src,Buffer *dst,int xSpace,int ySpace)
{ {
Data aReturnData; unsigned short *aDstPt = ((unsigned short*)dst->data) + MAXIPIX_NB_COLUMN;
aReturnData = aData; for(int i = MAXIPIX_NB_LINE;i;--i,aDstPt += MAXIPIX_LINE_SIZE)
for(int k = 0;k < xSpace;++k)
aDstPt[k] = 0;
aDstPt += MAXIPIX_LINE_SIZE - MAXIPIX_NB_COLUMN;
int aGapSize = (MAXIPIX_LINE_SIZE + (xSpace << 1)) * ySpace;
memset(aDstPt,0,aGapSize);
aDstPt += aGapSize;
aDstPt += MAXIPIX_NB_COLUMN;
for(int i = MAXIPIX_NB_LINE;i;--i,aDstPt += MAXIPIX_LINE_SIZE)
for(int k = 0;k < xSpace;++k)
aDstPt[k] = 0;
copy_2x2(src,dst,xSpace,ySpace);
}
static inline void _zero_2x2(Data &src,Buffer *dst,int xSpace,int ySpace)
{
copy_2x2(src,dst,xSpace,ySpace);
unsigned short *aDstPt = ((unsigned short*)dst->data) + MAXIPIX_NB_COLUMN - 1;
for(int i = MAXIPIX_NB_LINE - 1;i;--i,aDstPt += MAXIPIX_LINE_SIZE)
for(int k = 0;k < xSpace + 2;++k)
aDstPt[k] = 0;
aDstPt += MAXIPIX_LINE_SIZE - (MAXIPIX_NB_COLUMN - 1);
int aGapSize = (MAXIPIX_LINE_SIZE + (xSpace << 1)) * (ySpace + 2);
memset(aDstPt,0,aGapSize);
aDstPt += aGapSize;
if(_processingInPlaceFlag) aDstPt += MAXIPIX_NB_COLUMN - 1;
for(int i = MAXIPIX_NB_LINE - 1;i;--i,aDstPt += MAXIPIX_LINE_SIZE)
for(int k = 0;k < xSpace + 2;++k)
aDstPt[k] = 0;
}
static inline void _dispatch_2x2(Data &src,Buffer *dst,int xSpace,int ySpace)
{
copy_2x2(src,dst,xSpace,ySpace);
unsigned short *aDstPt = ((unsigned short*)dst->data) + MAXIPIX_NB_COLUMN - 1;
int aNbPixel2Dispatch = (xSpace >> 1) + 1;
for(int lineId = MAXIPIX_LINE_SIZE - 1;lineId;--lineId)
{ {
if(mModel == M_5x1) unsigned short aPixelValue = *aDstPt / aNbPixel2Dispatch;
for(int i = aNbPixel2Dispatch;i;--i,++aDstPt)
*aDstPt = aPixelValue;
aPixelValue = aDstPt[aNbPixel2Dispatch - 1] / aNbPixel2Dispatch;
for(int i = aNbPixel2Dispatch;i;--i,++aDstPt)
*aDstPt = aPixelValue;
aDstPt += MAXIPIX_LINE_SIZE - 2;
}
aDstPt -= MAXIPIX_NB_COLUMN - 1;
int aNbPixel2DispatchInY = (ySpace >> 1) + 1;
int aLineSize = MAXIPIX_LINE_SIZE + xSpace;
int aPart = 2;
/* aPart == 2 => upper chip
aPart == 1 => bottom chip
*/
do
{
//Last line or first line of left chip (depend on aPart)
for(int columnIter = MAXIPIX_NB_COLUMN - 1;columnIter;--columnIter,++aDstPt)
{ {
switch(mType) unsigned short aPixelValue = *aDstPt / aNbPixel2DispatchInY;
{ for(int y = 0;y < aNbPixel2DispatchInY;++y)
case ZERO: aDstPt[aLineSize * y] = aPixelValue;
_zero_5x1(aData,aData,mXSpace,_processingInPlaceFlag);break;
case DISPATCH:
_dispatch_5x1(aData,aData,mXSpace,_processingInPlaceFlag);break;
case MEAN:
_mean_5x1(aData,aData,mXSpace,_processingInPlaceFlag);break;
default: // ERROR
break;
}
} }
else // Model 4x2
//Bottom or top right corner of left chip
unsigned short aPixelValue = *aDstPt / (aNbPixel2DispatchInY * aNbPixel2Dispatch);
for(int columnIter = aNbPixel2Dispatch;columnIter;--columnIter,++aDstPt)
{ {
for(int y = 0;y < aNbPixel2DispatchInY;++y)
aDstPt[aLineSize * y] = aPixelValue;
} }
//Bottom or top left corner of right chip
aPixelValue = aDstPt[aNbPixel2Dispatch - 1] / (aNbPixel2DispatchInY * aNbPixel2Dispatch);
for(int columnIter = aNbPixel2Dispatch;columnIter;--columnIter,++aDstPt)
{
for(int y = 0;y < aNbPixel2DispatchInY;++y)
aDstPt[aLineSize * y] = aPixelValue;
}
//Last or first line of right chip
for(int columnIter = MAXIPIX_NB_COLUMN - 1;columnIter;--columnIter,++aDstPt)
{
aPixelValue = *aDstPt / aNbPixel2DispatchInY;
for(int y = 0;y < aNbPixel2DispatchInY;++y)
aDstPt[aLineSize * y] = aPixelValue;
}
//Set Variable for second part iteration (bottom chip)
aLineSize = -aLineSize;
aDstPt += aLineSize * (ySpace >> 1);
}
while(--aPart);
aDstPt = ((unsigned short*)dst->data) + aLineSize * (MAXIPIX_NB_LINE + ySpace + 1) +
MAXIPIX_NB_COLUMN - 1;
for(int lineId = MAXIPIX_LINE_SIZE - 1;lineId;--lineId)
{
unsigned short aPixelValue = *aDstPt / aNbPixel2Dispatch;
for(int i = aNbPixel2Dispatch;i;--i,++aDstPt)
*aDstPt = aPixelValue;
aPixelValue = aDstPt[aNbPixel2Dispatch - 1] / aNbPixel2Dispatch;
for(int i = aNbPixel2Dispatch;i;--i,++aDstPt)
*aDstPt = aPixelValue;
aDstPt += MAXIPIX_LINE_SIZE - 2;
} }
else }
static inline void _mean_2x2(Data &src,Buffer *dst,int xSpace,int ySpace)
{
copy_2x2(src,dst,xSpace,ySpace);
}
Data MaxipixReconstruction::process(Data &aData)
{
Data aReturnData;
aReturnData = aData;
if(mModel == M_5x1)
{ {
if(mModel == M_5x1) if(!_processingInPlaceFlag)
{ {
Buffer *aNewBuffer = new Buffer((MAXIPIX_LINE_SIZE * 5 + (mXSpace << 1) * 4) * Buffer *aNewBuffer = new Buffer((MAXIPIX_LINE_SIZE * 5 + (mXSpace << 1) * 4) *
MAXIPIX_NB_LINE); MAXIPIX_NB_LINE);
aReturnData.setBuffer(aNewBuffer); aReturnData.setBuffer(aNewBuffer);
switch(mType)
{
case ZERO:
_zero_5x1(aData,aReturnData,mXSpace,_processingInPlaceFlag);break;
case DISPATCH:
_dispatch_5x1(aData,aReturnData,mXSpace,_processingInPlaceFlag);break;
case MEAN:
_mean_5x1(aData,aReturnData,mXSpace,_processingInPlaceFlag);break;
default: // ERROR
break;
}
} }
else // Model 4x2 switch(mType)
{ {
case RAW:
_raw_5x1(aData,aReturnData,mXSpace);break;
case ZERO:
_zero_5x1(aData,aReturnData,mXSpace);break;
case DISPATCH:
_dispatch_5x1(aData,aReturnData,mXSpace);break;
case MEAN:
_mean_5x1(aData,aReturnData,mXSpace);break;
default: // ERROR
break;
} }
} }
else // Model 2x2
{
int aBufferSize = ((MAXIPIX_LINE_SIZE + mXSpace) * 2) *
((MAXIPIX_NB_LINE + mYSpace) * 2);
Buffer *aNewBuffer = new Buffer(aBufferSize);
switch(mType)
{
case RAW:
_raw_2x2(aData,aNewBuffer,mXSpace,mYSpace);break;
case ZERO:
_zero_2x2(aData,aNewBuffer,mXSpace,mYSpace);break;
case DISPATCH:
_dispatch_2x2(aData,aNewBuffer,mXSpace,mYSpace);break;
case MEAN:
_mean_2x2(aData,aNewBuffer,mXSpace,mYSpace);break;
default: // ERROR
break;
}
if(_processingInPlaceFlag)
{
unsigned char *aSrcPt = (unsigned char*)aNewBuffer->data;
unsigned char *aDstPt = (unsigned char*)aData.data();
memcpy(aDstPt,aSrcPt,aBufferSize);
aNewBuffer->unref();
}
else
aReturnData.setBuffer(aNewBuffer);
}
return aReturnData; return aReturnData;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment