/* getwinlut.c -- Reads the hardware gamma ramps (look-up tables) on MS Windows systems, and saves * them to OUTPUTFILE. It then reads new gamma ramps from INPUTFILE and writes them * to the hardware (i.e. the video card). * * Only works on MS Windows systems with a video card capable of writable gamma tables (most are). * * Compiled with MinGW (www.mingw.org) on Win98SE/XP using: * * windres -i getwinlut.rc -ogetwinrc.o * gcc -mwindows getwinlut.c -o getwinlut.exe getwinrc.o * * Not tested with other compilers or on other systems. * * Dirk Beer (rdbeer@ucsd.edu) 1 November 2002 * */ #include #include #include #define INPUTFILE "inputluttable.txt" #define OUTPUTFILE "oldluttable.txt" #define RED 0 #define GREEN 1 #define BLUE 2 // function to make an error message and exit void error(char *messagestr) { char str[256]; strcpy(str, messagestr); MessageBox(NULL, strcat(str, " Exiting ..."), "Error", MB_OK); exit(EXIT_FAILURE); } int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HDC hDC; HANDLE hStdout; FILE * outfp, * infp; char str[256]; WORD oldgam[3][256], newgam[3][256]; int i, good; // create a hardware device context for the default display hDC = CreateDC("DISPLAY", NULL, NULL, NULL); // get the gamma ramps if(!GetDeviceGammaRamp(hDC, oldgam)) error("GetDeviceGammaRamp failed."); // write the current gamma ramps to the output file if((outfp = fopen(OUTPUTFILE, "w")) == NULL) error("Could not open output file"); for(i=0; i<256; i++) { sprintf(str, "%d\t%d\t%d\n", oldgam[RED][i], oldgam[GREEN][i], oldgam[BLUE][i]); fprintf(outfp, str); } fclose(outfp); MessageBox(NULL, "Current gamma ramps written to output file." , "", MB_OK); // get the new gamma ramps from the input file if((infp = fopen(INPUTFILE, "r")) == NULL) error("Could not open input file."); for(i=0; i<256; i++) { fscanf(infp, "%d\t%d\t%d\n", &newgam[RED][i], &newgam[GREEN][i], &newgam[BLUE][i]); } fclose(infp); MessageBox(NULL, "New gamma ramps read from input file." , "", MB_OK); // set the hardware to the new gamma ramps if(!SetDeviceGammaRamp(hDC, newgam)) error("SetDeviceGammaRamp failed."); MessageBox(NULL, "New gamma ramps written to hardware." , "", MB_OK); return (EXIT_SUCCESS); }