#include <mil.h>
void PrintHeader()
{
MosPrintf(MIL_TEXT("[EXAMPLE NAME]\n"));
MosPrintf(MIL_TEXT("DotSpacing\n\n"));
MosPrintf(MIL_TEXT("[SYNOPSIS]\n"));
MosPrintf(MIL_TEXT("This program illustrates the use of the dot spacing setting to read a \n"));
MosPrintf(MIL_TEXT("dot-printed DataMatrix code.\n\n"));
MosPrintf(MIL_TEXT("[MODULES USED]\n"));
MosPrintf(MIL_TEXT("Modules used: application, system, display, buffer, graphic, code.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to read the datamatrix in the target image, using \n"));
MosPrintf(MIL_TEXT("default settings.\n\n"));
MosGetch();
}
#define IMAGE_FILE M_IMAGE_PATH MIL_TEXT("CodeDotSpacing/DataMatrix_Matrox.mim")
void DotSpacing(MIL_ID MilSystem, MIL_ID MilSrcImage, MIL_ID MilDisplay, MIL_INT CodeType);
int MosMain(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay;
MappAlloc(M_NULL, M_DEFAULT, &MilApplication);
MsysAlloc(M_DEFAULT, M_SYSTEM_HOST, M_DEFAULT, M_DEFAULT, &MilSystem);
MdispAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_DEFAULT, &MilDisplay);
PrintHeader();
MIL_ID MilSrcImage;
MbufRestore(IMAGE_FILE, MilSystem, &MilSrcImage);
DotSpacing(MilSystem, MilSrcImage, MilDisplay, M_DATAMATRIX);
MbufFree(MilSrcImage);
MdispFree(MilDisplay);
MsysFree(MilSystem);
MappFree(MilApplication);
return 0;
}
void DotSpacing(MIL_ID MilSystem, MIL_ID MilSrcImage, MIL_ID MilDisplay, MIL_INT CodeType)
{
MIL_ID MilDisplayImage;
MbufAlloc2d(MilSystem,
MbufInquire(MilSrcImage, M_SIZE_X, M_NULL),
MbufInquire(MilSrcImage, M_SIZE_Y, M_NULL),
MbufInquire(MilSrcImage, M_TYPE, M_NULL),
M_IMAGE+M_DISP,
&MilDisplayImage);
MbufClear(MilDisplayImage, 0L);
MbufCopy(MilSrcImage, MilDisplayImage);
MdispSelect(MilDisplay, MilDisplayImage);
MIL_ID MilOverlayImage;
MdispControl(MilDisplay, M_OVERLAY, M_ENABLE);
MdispInquire(MilDisplay, M_OVERLAY_ID, &MilOverlayImage);
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
MIL_ID MilCodeContext;
McodeAlloc(MilSystem, M_DEFAULT, M_DEFAULT, &MilCodeContext);
McodeModel(MilCodeContext, M_ADD, CodeType, M_NULL, M_DEFAULT, M_NULL);
MIL_ID MilCodeResult;
McodeAllocResult(MilSystem, M_DEFAULT, &MilCodeResult);
MIL_INT Status = !M_STATUS_READ_OK;
for(MIL_INT ii = 0; ii < 2 && (Status != M_STATUS_READ_OK); ii++)
{
McodeRead(MilCodeContext, MilSrcImage, MilCodeResult);
McodeGetResult(MilCodeResult, M_STATUS+M_TYPE_MIL_INT, &Status);
if (Status == M_STATUS_READ_OK)
{
MgraColor(M_DEFAULT, M_COLOR_GREEN);
MgraBackColor(M_DEFAULT, M_COLOR_GRAY);
McodeDraw(M_DEFAULT, MilCodeResult, MilOverlayImage, M_DRAW_BOX, M_ALL, M_DEFAULT);
MIL_INT ResultStringSize;
McodeGetResult(MilCodeResult, M_STRING_SIZE+M_TYPE_MIL_INT, &ResultStringSize);
MIL_TEXT_CHAR* ResultString = new MIL_TEXT_CHAR[ResultStringSize+1];
McodeGetResult(MilCodeResult, M_STRING, ResultString);
for(MIL_INT n=0; n < ResultStringSize; n++)
{
if ((ResultString[n] < MIL_TEXT('!')) || (ResultString[n] > MIL_TEXT('~')))
ResultString[n] = MIL_TEXT(' ');
}
const MIL_TEXT_CHAR PrefixString[] = MIL_TEXT("Read string: ");
MIL_INT OutputStringSize = ResultStringSize + MosStrlen(PrefixString) + 1;
MIL_TEXT_CHAR* OutputString = new MIL_TEXT_CHAR[OutputStringSize];
MosSprintf(OutputString, OutputStringSize, MIL_TEXT("%s%s"), PrefixString, ResultString);
double BottomLeftX, BottomLeftY;
McodeGetResult(MilCodeResult, M_BOTTOM_LEFT_X, &BottomLeftX);
McodeGetResult(MilCodeResult, M_BOTTOM_LEFT_Y, &BottomLeftY);
MgraText(M_DEFAULT,
MilOverlayImage,
BottomLeftX,
BottomLeftY+20,
OutputString);
delete [] OutputString;
delete [] ResultString;
MosPrintf(MIL_TEXT("The decoding is successful and the string result ")
MIL_TEXT("is displayed under the code.\n"));
}
else
{
MosPrintf(MIL_TEXT("The code read operation fails!\n\n"));
if(ii == 0)
{
MosPrintf(MIL_TEXT("Press <Enter> to read the datamatrix using the dot-spacing setting.\n\n"));
MosGetch();
McodeControl(MilCodeContext, M_DOT_SPACING, 7);
}
}
}
MosPrintf(MIL_TEXT("Press <Enter> to end.\n\n"));
MosGetch();
MbufFree(MilDisplayImage);
McodeFree(MilCodeResult);
McodeFree(MilCodeContext);
}