#include <mil.h>
#if M_MIL_USE_RT
#define MIL_SLAVE_EXPORT __declspec(dllexport)
#else
#define MIL_SLAVE_EXPORT
#endif
#ifdef __cplusplus
extern "C" {
#endif
MIL_SLAVE_EXPORT void MFTYPE SlaveAddConstantC(MIL_ID Func);
void MFTYPE TargetAddConstantC(MIL_ID SrcImage, MIL_ID DstImage, MIL_UINT Constant);
#ifdef __cplusplus
}
#endif
void MFTYPE SlaveAddConstantC(MIL_ID Func)
{
MIL_ID SrcImage, DstImage;
MIL_UINT Constant;
MfuncParamValue(Func, 1, &SrcImage);
MfuncParamValue(Func, 2, &DstImage);
MfuncParamValue(Func, 3, &Constant);
TargetAddConstantC(SrcImage, DstImage, Constant);
}
#define FUNCTION_SUPPORTED_IMAGE_DEPTH (8+M_UNSIGNED)
#define FUNCTION_PARAMETER_ERROR_CODE 1
void MFTYPE TargetAddConstantC(MIL_ID Src, MIL_ID Dst, MIL_UINT Constant)
{
unsigned char* pSrc, *pDst;
MIL_UINT PixelValue;
MIL_INT SizeX, SizeY, SrcPitch, DstPitch, x, y;
MbufInquire(Src, M_HOST_ADDRESS, &pSrc);
MbufInquire(Src, M_PITCH, &SrcPitch);
MbufInquire(Dst, M_HOST_ADDRESS, &pDst);
MbufInquire(Dst, M_SIZE_X, &SizeX);
MbufInquire(Dst, M_SIZE_Y, &SizeY);
MbufInquire(Dst, M_PITCH, &DstPitch);
MbufControl(Src, M_LOCK, M_DEFAULT);
MbufControl(Dst, M_LOCK, M_DEFAULT);
if((pSrc != M_NULL) && (pDst != M_NULL))
{
if ((MbufInquire(Src, M_TYPE, M_NULL) == FUNCTION_SUPPORTED_IMAGE_DEPTH) &&
(MbufInquire(Dst, M_TYPE, M_NULL) == FUNCTION_SUPPORTED_IMAGE_DEPTH) &&
(MbufInquire(Src, M_SIZE_X, M_NULL) == SizeX) &&
(MbufInquire(Src, M_SIZE_Y, M_NULL) == SizeY)
)
{
for(y = 0; y < SizeY; y++)
{
for(x = 0; x < SizeX; x++)
{
PixelValue = pSrc[x] + (unsigned char)Constant;
pDst[x] = (PixelValue < 255) ? (unsigned char)PixelValue : 255;
}
pSrc += SrcPitch;
pDst += DstPitch;
}
MbufControl(Dst, M_MODIFIED, M_DEFAULT);
}
else
{
MfuncErrorReport(M_DEFAULT, M_FUNC_ERROR + FUNCTION_PARAMETER_ERROR_CODE,
MIL_TEXT("Invalid parameter."),
MIL_TEXT("Images must have the same dimensions and must be 8-bit unsigned."),
M_NULL,
M_NULL
);
}
}
else
{
MfuncErrorReport(M_DEFAULT, M_FUNC_ERROR + FUNCTION_PARAMETER_ERROR_CODE,
MIL_TEXT("Invalid parameter."),
MIL_TEXT("One of the buffer has a NULL host address."),
M_NULL,
M_NULL
);
}
MbufControl(Src, M_UNLOCK, M_DEFAULT);
MbufControl(Dst, M_UNLOCK, M_DEFAULT);
}