#include <mil.h>
void MFTYPE CustomRemap(MIL_ID SrcImage, MIL_ID DstImage, MIL_UINT Option);
#define IMAGE_FILE M_IMAGE_PATH MIL_TEXT("Wafer.mim")
#define SLAVE_SYSTEM_DESCRIPTOR M_SYSTEM_DEFAULT
#define SLAVE_DLL_NAME MIL_TEXT("dmilremapslave")
#if M_MIL_USE_WINDOWS
#define SLAVE_DLL_TARGET_NAME M_USER_DLL_DIR SLAVE_DLL_NAME MIL_TEXT(".dll")
#elif M_MIL_USE_LINUX
#define SLAVE_DLL_TARGET_NAME M_USER_DLL_DIR MIL_TEXT("lib") SLAVE_DLL_NAME MIL_TEXT(".so")
#endif
#define DISPLAY_FORMAT MIL_TEXT("M_DEFAULT")
static bool SetupDMILExample(MIL_ID MilSystem);
int MosMain(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilImage;
MappAlloc(M_NULL, M_DEFAULT, &MilApplication);
MsysAlloc(M_DEFAULT, SLAVE_SYSTEM_DESCRIPTOR, M_DEFAULT, M_DEFAULT, &MilSystem);
if (!SetupDMILExample(MilSystem))
{
MsysFree(MilSystem);
MappFree(MilApplication);
return -1;
}
MdispAlloc(MilSystem, M_DEFAULT, DISPLAY_FORMAT, M_DEFAULT, &MilDisplay);
MbufRestore(IMAGE_FILE, MilSystem, &MilImage);
MdispSelect(MilDisplay, MilImage);
MosPrintf(MIL_TEXT("\nMIL DTK:\n"));
MosPrintf(MIL_TEXT("--------\n\n"));
MosPrintf(MIL_TEXT("Custom asynchronous processing function:\n\n"));
MosPrintf(MIL_TEXT("This example creates a custom MIL function "));
MosPrintf(MIL_TEXT("that maximize the contrast.\n"));
MosPrintf(MIL_TEXT("Press a key to continue.\n\n"));
MosGetch();
CustomRemap(MilImage, MilImage, M_DEFAULT);
MosPrintf(MIL_TEXT("A smart image remapping was done on the image using "));
MosPrintf(MIL_TEXT("a user made MIL function.\n"));
MosPrintf(MIL_TEXT("Press a key to terminate.\n\n"));
MosGetch();
MbufFree(MilImage);
MdispFree(MilDisplay);
MsysFree(MilSystem);
MappFree(MilApplication);
return 0;
}
#define FUNCTION_OPCODE_REMAP (M_USER_FUNCTION+1)
#define FUNCTION_NB_PARAM 3
#define SLAVE_FUNC_NAME MIL_TEXT("SlaveCustomRemap")
void MFTYPE CustomRemap(MIL_ID SrcImage, MIL_ID DstImage, MIL_UINT Option)
{
MIL_ID Func;
MfuncAlloc(MIL_TEXT("CustomRemap"),
FUNCTION_NB_PARAM,
M_NULL, SLAVE_DLL_NAME, SLAVE_FUNC_NAME,
FUNCTION_OPCODE_REMAP,
M_ASYNCHRONOUS_FUNCTION,
&Func);
MfuncParamMilId (Func, 1, SrcImage, M_IMAGE, M_IN + M_PROC);
MfuncParamMilId (Func, 2, DstImage, M_IMAGE, M_OUT + M_PROC);
MfuncParamMilUint(Func, 3, Option);
MfuncCall(Func);
MfuncFree(Func);
}
bool SetupDMILExample(MIL_ID MilSystem)
{
MIL_ID MilSystemOwnerApplication;
bool CheckExistence = false;
if (MsysInquire(MilSystem, M_LOCATION, M_NULL) != M_REMOTE)
{
MosPrintf(MIL_TEXT("This example requires the default system to be a remote system.\n"));
MosPrintf(MIL_TEXT("Please select a remote system as the default.\n"));
MosPrintf(MIL_TEXT("If no remote systems are registered "));
MosPrintf(MIL_TEXT("please go to the DistributedMIL->Connections page, "));
MosPrintf(MIL_TEXT("register a remote system, "));
MosPrintf(MIL_TEXT("and then select it as the default system.\n"));
MosGetch();
return false;
}
MsysInquire(MilSystem, M_OWNER_APPLICATION, &MilSystemOwnerApplication);
if ((MappInquire(M_DEFAULT, M_PLATFORM_BITNESS, M_NULL) ==
MappInquire(MilSystemOwnerApplication, M_PLATFORM_BITNESS, M_NULL)) &&
(MappInquire(M_DEFAULT, M_PLATFORM_OS_TYPE, M_NULL) == M_OS_WINDOWS) &&
(MappInquire(MilSystemOwnerApplication, M_PLATFORM_OS_TYPE, M_NULL) == M_OS_WINDOWS) &&
(MsysInquire(MilSystem, M_DISTRIBUTED_MIL_TYPE, M_NULL) == M_DMIL_REMOTE))
{
MappControl(M_DEFAULT, M_ERROR, M_PRINT_DISABLE);
MappFileOperation(M_DEFAULT, SLAVE_DLL_TARGET_NAME, MilSystemOwnerApplication, M_NULL,
M_FILE_COPY_MIL_USER_DLL, M_DEFAULT, M_NULL);
if (0 != MappGetError(M_DEFAULT, M_CURRENT, M_NULL))
{
MosPrintf(MIL_TEXT("There was an error while copying the slave library.\n"));
MosPrintf(MIL_TEXT("Checking if one is present on the remote system.\n"));
CheckExistence = true;
}
MappControl(M_DEFAULT, M_ERROR, M_PRINT_ENABLE);
}
else
CheckExistence = true;
if (CheckExistence)
{
MIL_INT DllExists = M_NO;
MappFileOperation(MilSystemOwnerApplication, SLAVE_DLL_NAME, M_NULL, M_NULL,
M_FILE_EXISTS_MIL_USER_DLL, M_DEFAULT, &DllExists);
if (DllExists != M_YES)
{
MosPrintf(MIL_TEXT("The slave library was NOT copied to the remote system.\n"));
MosPrintf(MIL_TEXT("Make sure it is present for the example to work properly.\n"));
MosPrintf(MIL_TEXT("See DistributedMILExamples.txt in the DistributedMIL examples "));
MosPrintf(MIL_TEXT("folder\nfor more information.\n"));
MosPrintf(MIL_TEXT("Press a key to terminate.\n\n"));
MosGetch();
return false;
}
}
return true;
}