#include "mil.h"
int MosMain(void)
{
MosPrintf(MIL_TEXT("[EXAMPLE NAME]\nInteractiveBayer\n\n"));
MIL_ID MilApplication,
MilSystem,
MilDigitizer,
MilDisplay,
MilWBCoefficients,
MilImageDisp,
MilImageGrab;
float WBCoefficients[3];
MIL_INT ConversionType;
MIL_INT BayerConversion;
MIL_INT XSize;
MIL_INT YSize;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, &MilDigitizer, M_NULL);
if ((MdigInquire(MilDigitizer, M_EXTENDED_INIT_FLAG, M_NULL) & M_EMULATED) == M_EMULATED)
{
MosPrintf(MIL_TEXT("The example does not run with a digitizer in emulated mode.\n\n"));
MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, M_NULL);
MosPrintf(MIL_TEXT("Press <ENTER> to end\n"));
MosGetchar();
return 1;
}
MdigInquire(MilDigitizer, M_BAYER_PATTERN, &ConversionType);
MdigInquire(MilDigitizer, M_BAYER_CONVERSION, &BayerConversion);
if ((ConversionType==M_NULL) || (BayerConversion==M_ENABLE))
{
MosPrintf(MIL_TEXT("The example requires acquiring a raw Bayer image.\n\n"));
MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, M_NULL);
MosPrintf(MIL_TEXT("Press <ENTER> to end\n"));
MosGetchar();
return 1;
}
XSize = MdigInquire(MilDigitizer, M_SIZE_X, M_NULL);
YSize = MdigInquire(MilDigitizer, M_SIZE_Y, M_NULL);
MbufAllocColor(MilSystem, 3, XSize, YSize, 8L+M_UNSIGNED, M_PROC+M_IMAGE+M_DISP,&MilImageDisp);
MbufAllocColor(MilSystem, 1, XSize, YSize, 8L+M_UNSIGNED, M_IMAGE+M_DISP+M_GRAB+M_PROC, &MilImageGrab);
MbufAlloc1d(MilSystem, 3, 32+M_FLOAT, M_ARRAY, &MilWBCoefficients);
MbufClear(MilImageDisp, M_RGB888(0, 0, 0));
MdispSelect(MilDisplay, MilImageDisp);
MosPrintf(MIL_TEXT("Place a white reference in front of the\n"));
MosPrintf(MIL_TEXT("camera and press <ENTER> when ready.\n"));
do
{
MdigGrab(MilDigitizer, MilImageGrab);
MbufBayer(MilImageGrab, MilImageDisp, M_DEFAULT, ConversionType);
}
while (!MosKbhit());
MbufBayer(MilImageGrab, MilImageDisp, MilWBCoefficients,
ConversionType+M_WHITE_BALANCE_CALCULATE);
MbufGet(MilWBCoefficients, (void *) &WBCoefficients[0]);
MosPrintf(MIL_TEXT("\nWhite balance correction coefficients : %f, %f, %f\n\n"),
WBCoefficients[0], WBCoefficients[1], WBCoefficients[2]);
MosPrintf(MIL_TEXT("Press <ENTER> to grab white balanced images\n"));
MosGetchar();
do
{
MdigGrab(MilDigitizer, MilImageGrab);
MbufBayer(MilImageGrab, MilImageDisp, MilWBCoefficients, ConversionType);
}
while (!MosKbhit());
MosPrintf(MIL_TEXT("Press <ENTER> to end\n"));
MosGetchar();
MbufFree(MilImageGrab);
MbufFree(MilImageDisp);
MbufFree(MilWBCoefficients);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, M_NULL);
return 0;
}