#include <mil.h>
void Upsample(MIL_ID MilSystem, MIL_ID MilDisplay, MIL_CONST_TEXT_PTR ImageFile);
#define MIL_IMAGE_TEXT M_IMAGE_PATH MIL_TEXT("Preprocessing/PrintedText.mim")
void PrintHeader()
{
MosPrintf(MIL_TEXT("[EXAMPLE NAME]\n")
MIL_TEXT("Image Upscaling Modes\n\n")
MIL_TEXT("[SYNOPSIS]\n")
MIL_TEXT("This program demonstrates how the resize operation increases\n")
MIL_TEXT("the size of an image using various interpolation modes.\n\n")
MIL_TEXT("[MODULES USED]\n")
MIL_TEXT("Modules used: application, system, display, buffer,\n")
MIL_TEXT(" graphics, image processing.\n\n"));
}
int MosMain()
{
PrintHeader();
MIL_ID MilApplication,
MilSystem,
MilDisplay;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);
Upsample(MilSystem, MilDisplay, MIL_IMAGE_TEXT);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL);
return 0;
}
void Upsample(MIL_ID MilSystem, MIL_ID MilDisplay, MIL_CONST_TEXT_PTR ImageFile)
{
MIL_ID MilImage,
MilOriginalImage,
MilZoneOfInterest,
MilSubImage0,
MilSubImage1,
MilSubImage2;
MIL_INT Type, SizeX, SizeY;
MosPrintf(MIL_TEXT("An image is loaded and resized using various modes.\n"));
MbufDiskInquire(ImageFile, M_SIZE_X, &SizeX);
MbufDiskInquire(ImageFile, M_SIZE_Y, &SizeY);
MbufDiskInquire(ImageFile, M_TYPE, &Type);
MIL_INT ZOI_SizeX = SizeX / 16;
MIL_INT ZOI_SizeY = SizeY / 16;
MIL_INT ZOI_OffsetX = 185;
MIL_INT ZOI_OffsetY = 90;
MIL_DOUBLE DisplayScaleFactor = 1 / 3.0;
MIL_INT ReducedSizeX = (MIL_INT) ((MIL_DOUBLE)SizeX * DisplayScaleFactor);
MIL_INT ReducedSizeY = (MIL_INT) ((MIL_DOUBLE)SizeY * DisplayScaleFactor);
MIL_INT CanvasSizeY = (SizeY >= 3 * ReducedSizeY) ? SizeY : 3 * ReducedSizeY;
MIL_INT CanvasSizeX = SizeX + ReducedSizeX;
MbufAlloc2d(MilSystem, CanvasSizeX, CanvasSizeY, Type, M_IMAGE | M_DISP | M_PROC, &MilImage);
MbufChild2d(MilImage, 0, 0, SizeX, SizeY, &MilOriginalImage);
MbufChild2d(MilOriginalImage, ZOI_OffsetX, ZOI_OffsetY, ZOI_SizeX, ZOI_SizeY, &MilZoneOfInterest);
MbufChild2d(MilImage, SizeX, 0, ReducedSizeX, ReducedSizeY, &MilSubImage0);
MbufChild2d(MilImage, SizeX, ReducedSizeY, ReducedSizeX, ReducedSizeY, &MilSubImage1);
MbufChild2d(MilImage, SizeX, 2 * ReducedSizeY, ReducedSizeX, SizeY - (2 * ReducedSizeY), &MilSubImage2);
MbufLoad(ImageFile, MilOriginalImage);
MimResize(MilZoneOfInterest, MilSubImage0, M_FILL_DESTINATION, M_FILL_DESTINATION, M_NEAREST_NEIGHBOR);
MimResize(MilZoneOfInterest, MilSubImage1, M_FILL_DESTINATION, M_FILL_DESTINATION, M_BILINEAR);
MimResize(MilZoneOfInterest, MilSubImage2, M_FILL_DESTINATION, M_FILL_DESTINATION, M_BICUBIC);
MgraColor(M_DEFAULT, 255);
MgraRect(M_DEFAULT,
MilOriginalImage,
ZOI_OffsetX,
ZOI_OffsetY,
ZOI_OffsetX + ZOI_SizeX,
ZOI_OffsetY + ZOI_SizeY);
MdispSelect(MilDisplay, MilImage);
MgraText(M_DEFAULT, MilOriginalImage, 0, 0, MIL_TEXT("Source image"));
MgraText(M_DEFAULT, MilSubImage0, 0, 0, MIL_TEXT("Nearest Neighbor"));
MgraText(M_DEFAULT, MilSubImage1, 0, 0, MIL_TEXT("Bilinear"));
MgraText(M_DEFAULT, MilSubImage2, 0, 0, MIL_TEXT("Bicubic"));
MosPrintf(MIL_TEXT("\nPress <Enter> to end.\n\n"));
MosGetch();
MbufFree(MilZoneOfInterest);
MbufFree(MilSubImage2);
MbufFree(MilSubImage1);
MbufFree(MilSubImage0);
MbufFree(MilOriginalImage);
MbufFree(MilImage);
}