//---------------------------------------------------------------------------- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE, LPSTR acArgument, int) { Command* pkCommand = NULL; if ( acArgument && strlen(acArgument) > 0 ) { char* acProcessed = ProcessCommand(acArgument); pkCommand = new Command(acProcessed); assert( pkCommand ); delete[] acProcessed; } else { // command line was not specified return -1; } float fMagnify; if ( !pkCommand->Inf(0.0f).Float("m",fMagnify) ) { // magnification factor was not specified return -2; } char* acInputFile; pkCommand->Filename(acInputFile); if ( !acInputFile ) { // input.bmp was not specified return -3; } char* acOutputFile; pkCommand->Filename(acOutputFile); if ( !acOutputFile ) { // output.bmp was not specified delete[] acInputFile; return -4; } HBITMAP hImage = (HBITMAP) LoadImage(NULL,acInputFile,IMAGE_BITMAP,0,0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); if ( !hImage ) { // input.bmp could not be loaded return -5; } DIBSECTION dibSection; GetObject(hImage,sizeof(DIBSECTION),&dibSection); int iWidth = dibSection.dsBm.bmWidth; int iHeight = dibSection.dsBm.bmHeight; int iQuantity = dibSection.dsBm.bmWidth*dibSection.dsBm.bmHeight; if ( dibSection.dsBm.bmBitsPixel != 24 ) { // input.bmp was not 24-bit color return -6; } // split into separate channels and interpolate each channel separately float** aafB; Interp2DBicubic::Allocate(iWidth,iHeight,aafB); float** aafG; Interp2DBicubic::Allocate(iWidth,iHeight,aafG); float** aafR; Interp2DBicubic::Allocate(iWidth,iHeight,aafR); unsigned char* pucSrc = (unsigned char*) dibSection.dsBm.bmBits; int iX, iY; for (iY = 0; iY < iHeight; iY++) { for (iX = 0; iX < iWidth; iX++) { aafB[iY][iX] = *pucSrc++; aafG[iY][iX] = *pucSrc++; aafR[iY][iX] = *pucSrc++; } } Interp2DBicubic kB(iWidth,iHeight,0.0f,1.0f,0.0f,1.0f,aafB); Interp2DBicubic kG(iWidth,iHeight,0.0f,1.0f,0.0f,1.0f,aafG); Interp2DBicubic kR(iWidth,iHeight,0.0f,1.0f,0.0f,1.0f,aafR); // Compute width of output image. Make sure it is a multiple of 4 to // handle the BMP requirement of row-byte-count being a multiple of 4. int iOutWidth = (int)(fMagnify*iWidth); int iRemainder = iOutWidth % 4; if ( iRemainder > 0 ) iOutWidth += 4 - iRemainder; int iOutHeight = (int)(fMagnify*iHeight); int iOutQuantity = iOutWidth*iOutHeight; float fXRatio = (iWidth-1.0f)/(iOutWidth-1.0f); float fYRatio = (iHeight-1.0f)/(iOutHeight-1.0f); unsigned char* aucDst = new unsigned char[3*iOutQuantity]; pucSrc = (unsigned char*) dibSection.dsBm.bmBits; int i; for (iY = 0, i = 0; iY < iOutHeight; iY++) { float fY = fYRatio*iY; for (iX = 0; iX < iOutWidth; iX++) { float fX = fXRatio*iX; float fValue = kB(fX,fY); if ( fValue >= 0.0f ) { if ( fValue <= 255.0f ) aucDst[i++] = (unsigned char)fValue; else aucDst[i++] = 255; } else { aucDst[i++] = 0; } fValue = kG(fX,fY); if ( fValue >= 0.0f ) { if ( fValue <= 255.0f ) aucDst[i++] = (unsigned char)fValue; else aucDst[i++] = 255; } else { aucDst[i++] = 0; } fValue = kR(fX,fY); if ( fValue >= 0.0f ) { if ( fValue <= 255.0f ) aucDst[i++] = (unsigned char)fValue; else aucDst[i++] = 255; } else { aucDst[i++] = 0; } } } SaveImage(acOutputFile,iOutWidth,iOutHeight,aucDst); Interp2DBicubic::Deallocate(aafB); Interp2DBicubic::Deallocate(aafG); Interp2DBicubic::Deallocate(aafR); DeleteObject(hImage); delete[] acInputFile; delete[] acOutputFile; return 0; }