Code:
// at the top:
unsigned char UnchangedData[14]; // image header data that never changes
BITMAPINFO MainImageHeader; // used for eventual scaling
BITMAPINFOHEADER ImageHeader; // size, bit count, etc. of image
LPBITMAPINFOHEADER ImageHeaderPointer; // pointer to image header
HBITMAP ImageHeaderHandle; // handle for eventual scaling
HDC HDCBitmap; // DC for handling the source image
unsigned char ImageDataOrig[75202560]; // the main image pixel data (sized for a 4096x6120 image)
// for ground layer automation
HDC HDCResults; // the contents for the resulting output
HBITMAP HBMPResults;
BITMAPINFOHEADER ResultsInfo;
LPBITMAPINFOHEADER ResultsInfoPointer;
LPVOID ResultsPointer;
unsigned char Results[33792]; // the results, for writing the output (1024x11 max size, as per the 30-channel system)
// the related functions
void WriteScaledOutput(const int OutputImageHeight, const char Scaling[11])
{
const unsigned char FileNameBase[200] = "C:\\My Documents\\My programs\\Platform Masters\\Platform Masters temp\\Automation results\\";
unsigned char FileNameMain[256];
const int OutputDataSize = 3072*OutputImageHeight; // always 1024 pixels wide
sprintf(FileNameMain, "%sGeneralBGGroundGrass%s.bmp", FileNameBase, Scaling); // write the output
FileHandle = fopen(FileNameMain, "wb");
fwrite(UnchangedData, 1, 14, FileHandle); // this data never changes - 0x00 to 0x0D
fwrite(&ResultsInfo.biSize, 4, 1, FileHandle); // 0x0E to 0x11
fwrite(&ResultsInfo.biWidth, 4, 1, FileHandle); // 0x12 to 0x15
fwrite(&OutputImageHeight, 4, 1, FileHandle); // 0x16 to 0x19
fwrite(&ResultsInfo.biPlanes, 2, 1, FileHandle); // 0x1A and 0x1B
fwrite(&ResultsInfo.biBitCount, 2, 1, FileHandle); // 0x1C and 0x1D
fwrite(&ResultsInfo.biCompression, 4, 1, FileHandle); // 0x1E to 0x21
fwrite(&ResultsInfo.biSizeImage, 4, 1, FileHandle); // 0x22 to 0x25
fwrite(&ResultsInfo.biXPelsPerMeter, 4, 1, FileHandle); // 0x26 to 0x29
fwrite(&ResultsInfo.biYPelsPerMeter, 4, 1, FileHandle); // 0x2A to 0x2D
fwrite(&ResultsInfo.biClrUsed, 4, 1, FileHandle); // 0x2E to 0x31
fwrite(&ResultsInfo.biClrImportant, 4, 1, FileHandle); // 0x32 to 0x35
fwrite(Results, 1, OutputDataSize, FileHandle); // write the resulting scaled image
fclose(FileHandle);
}
void ProcessGroundForPM(const int TextureScale)
{
const unsigned char FileNameBase[200] = "C:\\My Documents\\My programs\\Platform Masters\\Platform Masters temp\\Automation results\\";
unsigned char FileNameMain[256];
unsigned int LoopCount = 0;
// stage 1: load the base textures
sprintf(FileNameMain, "%sGeneralBGGroundGrass.bmp", FileNameBase); // the 1x texture
FileHandle = fopen(FileNameMain, "rb");
if (FileHandle == 0) // not found
{
printf("\nError: the file couldn't be found:\n%s\n\n", FileNameMain);
return; // can't do anything - terminate
}
// stage 2: setup the output buffers
else
{
HDCResults = GetDC(NULL); // set the DC, using the entire screen (since a command prompt window is used)
ResultsInfo.biSize = 40; // the size of the struct, always 40 in my case (due to true color being used)
ResultsInfo.biWidth = 1024; // the maximum possible output size used
ResultsInfo.biHeight = 11; // variable in the output, but this is the maximum
ResultsInfo.biPlanes = 1; // always 1
ResultsInfo.biBitCount = 24; // number of bits per pixel, the output image is in true color without alpha
ResultsInfo.biCompression = BI_RGB; // no compression used
ResultsInfo.biSizeImage = ResultsInfo.biWidth*ResultsInfo.biHeight*3; // "Width*Height*BitCount/8" gives the image data size
ResultsInfo.biXPelsPerMeter = 11811; // resolution in pixels per meter - this is unimportant
ResultsInfo.biYPelsPerMeter = 11811;
ResultsInfo.biClrUsed = 0; // always 0 in my case
ResultsInfo.biClrImportant = 0; // same here
ResultsInfoPointer = &ResultsInfo; // set the pointers
ResultsPointer = &Results;
// HDCResults = CreateCompatibleDC(HDCScreen); // create a compatible DC, of which is to be used for drawing into the results
HBMPResults = CreateCompatibleBitmap(HDCResults, 1024, 11); // create compatible bitmap, used for drawing into, but not on screen
HDCBitmap = CreateCompatibleDC(HDCResults); // for AlphaBlend
SelectObject(HDCResults, HBMPResults); // select the created bitmap
if (TextureScale == 1)
{
// stage 3: load the base texture
fread(UnchangedData, 1, 14, FileHandle); // this data never changes
fread(&ImageHeader.biSize, 4, 1, FileHandle); // see above for byte locations
fread(&ImageHeader.biWidth, 4, 1, FileHandle);
fread(&ImageHeader.biHeight, 4, 1, FileHandle);
fread(&ImageHeader.biPlanes, 2, 1, FileHandle);
fread(&ImageHeader.biBitCount, 2, 1, FileHandle);
fread(&ImageHeader.biCompression, 4, 1, FileHandle);
fread(&ImageHeader.biSizeImage, 4, 1, FileHandle);
fread(&ImageHeader.biXPelsPerMeter, 4, 1, FileHandle);
fread(&ImageHeader.biYPelsPerMeter, 4, 1, FileHandle);
fread(&ImageHeader.biClrUsed, 4, 1, FileHandle);
fread(&ImageHeader.biClrImportant, 4, 1, FileHandle);
fread(ImageDataOrig, 1, ImageHeader.biSizeImage, FileHandle); // read the main image data // in BGR format
fclose(FileHandle);
// stage 4: scale the output and write this to disk
SetStretchBltMode(HDCResults, HALFTONE); // a must to blend pixel colors (for smoothing)
SelectObject(HDCBitmap, HBMPResults); // the results
for (LoopCount = 0; LoopCount < 8; LoopCount++) // cover the entire span of 1024 pixels
{
StretchBlt(HDCResults, 0, 0, 128, 11, HDCBitmap, 0, 1999, 2304, 576, SRCCOPY); // resize the image
WriteScaledOutput(11, "0018");
}
}
}
ReleaseDC(WindowHandle, HDCResults); // free the DC handles
DeleteDC(HDCResults);
DeleteDC(HDCBitmap);
DeleteObject(HBMPBack); // free the memory
}
Is there any way I can have the output get written?