#include "stdafx.h" #include "stddef.h" #include "string.h" #include "PortabilityLayer.h" /// Implementation of a logging function. See 'SetLoggingCallback' function. void Logit(String it) { printf("%s\n", it); } void Usage(_TCHAR* arg0) { printf("Purpose: Downloads 1+ images to image frame buffer memory\n"); printf("%s file1 [file2 | ...]\n", arg0); printf("Usage:\n"); printf(" Input one or more filenames to download to the DLP LightCommander\n"); printf(" image frame buffer memory.\n"); printf(" All input files must be DBI-formatted files. These files are created\n"); printf(" by the Application SW written by LOGIC. See documentation for further details.\n"); } // DBI image utility function int ReadDbiImageHdr_NBPP(const char* filename); int _tmain(int argc, _TCHAR* argv[]) { Byte loglvl = 0; Boolean stopOnError = 1; Status rc; int i; unsigned char imgcnt = 4; int nbpp = -1; Double intensityPerCent; int j; #define MAX_IMAGES 64 char file[MAX_IMAGES][256]; // fyi: 64 is just a convenient limit for this driver UInt16 imgOrderLUT[MAX_IMAGES]; for(i=0; i < MAX_IMAGES; i++) { file[i][0] = '\0'; // add NULL terminator imgOrderLUT[i] = 0; } strcpy(file[0],"C:\\Documents and Settings\\Dragon\\My Documents\\LightCommander Control\\CodingTest\\Solutions\\Test Batchfile for Coding\\Images\\duijiao.dbi"); strcpy(file[1],"C:\\Documents and Settings\\Dragon\\My Documents\\LightCommander Control\\CodingTest\\Solutions\\Test Batchfile for Coding\\Images\\dxctest1.dbi"); strcpy(file[2],"C:\\Documents and Settings\\Dragon\\My Documents\\LightCommander Control\\newgreen\\Solutions\\12\\Images\\12NO.1.dbi"); strcpy(file[3],"C:\\Documents and Settings\\Dragon\\My Documents\\LightCommander Control\\newgreen\\Solutions\\12\\Images\\12NO.2.dbi"); // REQUIRED INITIALIZATION... if((rc = InitPortabilityLayer(loglvl+1, loglvl, Logit)) != STAT_OK) { printf("ERROR running InitPortabilityLayer (ret code = %d)\n", (int)rc); return(1); } printf("%45s: ret code = OK\n","InitPortabilityLayer"); // 1. Program image order LUT... nbpp = ReadDbiImageHdr_NBPP(file[0]); for(i=0; i < imgcnt; i++) imgOrderLUT[i] = i; // maintain the same image order as was passed into this app... if((rc = DLP_RegIO_WriteImageOrderLut((Byte)nbpp, imgOrderLUT, (UInt16)imgcnt)) != STAT_OK) { printf("ERROR running WriteImageOrderTable (ret code = %d)\n", (int)rc); return(1); } // 2. Download images... for(i=0; i < imgcnt; i++) { printf("Downloading image# %3d: %s ...\n", i, file[i]); if((rc = WriteExternalImage(file[i], i)) != STAT_OK) { printf("ERROR running WriteExternalImage (ret code = %d)\n", (int)rc); return(1); } } if((rc = DLP_Display_DisplayPatternAutoStepForSinglePass()) != 0) { printf("ERROR running DisplayPatternAutoStepForSinglePass (ret code = %d)\n", (int)rc); return(1); } return 0; } // *Temporary* function used to read the NBPP field from the header of a DBI Image file. // This function has no guarantees of working in the future and should be used // at your own risk. It exists here since a similar function is not available as an // exported function in the portability DLL. int ReadDbiImageHdr_NBPP(const char* filename) { unsigned char bpp=0; FILE* pFile = NULL; int nBytesToRead = 0; int nBytesInFile = 0; int nBytesRead = 0; typedef struct { char signature[4]; UInt32 cbSize; UInt32 rows; UInt32 cols; UInt32 bpp; UInt16 data[1]; } dbiImage; dbiImage dbi; nBytesToRead = offsetof(dbiImage,bpp); // get byte offset to start of "bpp" nBytesToRead += sizeof(UInt32); if((pFile = fopen(filename, "rb")) == NULL) { printf("File open error on %s\n", filename); printf("Hint: check spelling or path\n"); return -1; } fseek(pFile, 0, SEEK_END); nBytesInFile = ftell(pFile); //printf("#bytes in file = %d\n", nBytesInFile); if(nBytesInFile < nBytesToRead) { printf("Insufficent data in file to read BPP parameter; must be at least %d bytes\n", nBytesToRead); return -1; } fseek(pFile, 0, SEEK_SET); nBytesRead = (long)fread((void*)&dbi, 1, nBytesToRead, pFile); if(nBytesRead != nBytesToRead) { printf("Error: did not read %d bytes...only read % bytes\n", nBytesToRead, nBytesRead); return -1; } return (int)dbi.bpp; }