/* Write an ICC Profile from a file into the JPEG stream. */ static int write_profile_file( Write *write, const char *profile ) { if( !(write->profile_bytes = im__file_read_name( profile, VIPS_ICC_DIR, &write->profile_length )) ) return( -1 ); write_profile_data( &write->cinfo, (JOCTET *) write->profile_bytes, write->profile_length ); #ifdef DEBUG printf( "im_vips2jpeg: attached profile \"%s\"\n", profile ); #endif /*DEBUG*/ return( 0 ); }
/* load_configuration_data Load all module configuration data from the INI-file into the configuration_data structure, if not done already loaded. */ void load_configuration_data(void) { if(configuration_data_loaded == FALSE){ // data not loaded yet ULONG size; // get name of the saver module (stored as resource string) if(WinLoadString(hab, hmodDLL, IDS_MODULENAME, SAVER_NAME_MAXLEN, (PSZ)modulename) == 0){ // resource string not found. indicate error by // setting module name to empty string (the name // "" is interpreted as an error by SSDLL.DLL and // the module does not show up in the list box). strcpy(modulename, ""); return; } // load data from INI-file. the key name is the name of the // saver module size = query_profile_data(); if(size != sizeof(configuration_data) || configuration_data.version != MODULEVERSION || strncmp(modulename, configuration_data.modulename, sizeof(modulename)) != 0){ // if entry is not found or entry has invalid size or // entry has wrong version number, create a new entry // with default values and write it to the INI-file configuration_data.version = MODULEVERSION; configuration_data.enabled = TRUE; configuration_data.animation_speed = CONFIGURATION_DEFAULT_ANIMATIONSPEED; strncpy(configuration_data.modulename, modulename, sizeof(configuration_data.modulename)); /* $$$$$ insert code here $$$$$ If you have added data to the configuration_data structure, insert code here to set the default values for your data items. $$$$$ for example $$$$$ */ configuration_data.count = CONFIGURATION_DEFAULT_COUNT; configuration_data.colors = COLORS_DEFAULT; configuration_data.blank_screen = CONFIGURATION_DEFAULT_BLANKSCREEN; write_profile_data(); } configuration_data_loaded = TRUE; } }
static int write_profile_meta( Write *write ) { void *data; size_t data_length; if( im_meta_get_blob( write->in, IM_META_ICC_NAME, &data, &data_length ) ) return( -1 ); write_profile_data( &write->cinfo, data, data_length ); #ifdef DEBUG printf( "im_vips2jpeg: attached %zd byte profile from VIPS header\n", data_length ); #endif /*DEBUG*/ return( 0 ); }
/* load_configuration_data Load all module configuration data from the INI-file into the configuration_data structure, if not done already loaded. */ void load_configuration_data(void) { if(configuration_data_loaded == FALSE){ /* data not loaded yet */ ULONG size; /* get name of the saver module (stored as resource string) */ if(WinLoadString(hab, hmodDLL, IDS_MODULENAME, SAVER_NAME_MAXLEN, (PSZ)modulename) == 0){ /* resource string not found. indicate error by */ /* setting module name to empty string (the name */ /* "" is interpreted as an error by SSDLL.DLL and */ /* the module does not show up in the list box). */ strcpy(modulename, ""); return; } /* load data from INI-file. the key name is the name of the */ /* saver module */ size = query_profile_data(); if(size != sizeof(configuration_data) || configuration_data.version != MODULEVERSION){ /* if entry is not found or entry has invalid size or */ /* entry has wrong version number, create a new entry */ /* with default values and write it to the INI-file */ configuration_data.version = MODULEVERSION; configuration_data.enabled = TRUE; configuration_data.tracename = TRUE; configuration_data.show3d = TRUE; configuration_data.gravity = CONFIGURATION_DEFAULT_GRAVITY; configuration_data.whitestar_count = CONFIGURATION_DEFAULT_STARS; configuration_data.redstar_count = CONFIGURATION_DEFAULT_STARS; configuration_data.bluestar_count = CONFIGURATION_DEFAULT_STARS; configuration_data.yellowstar_count = CONFIGURATION_DEFAULT_STARS; write_profile_data(); } configuration_data_loaded = TRUE; } }
/* ConfigureDlgProc This is the dialog procedure for the module configuration dialog. The dialog contains a check box for enabling/disabling the module and two push buttons ("OK" and "Cancel") to close/cancel the dialog. Since version 1.2, it contains a slider to set the animation speed; if you don't want this slider, change the '#if 0' line in the WM_INITDLG part of this dialog procedure. This is enough for simple saver modules, but can easily be expanded for more saver modules that need more settings. */ MRESULT EXPENTRY ConfigureDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { char buf[sizeof(modulename)+20]; static HWND hwndEnabled; static HWND hwndSpeed; /* $$$$$ insert code here $$$$$ If you need additional data for dialog processing, insert it here. $$$$$ for example $$$$$ */ static HWND hwndCount; static HWND hwndColor; static HWND hwndBlankScreen; CHAR msgtext[256]; switch(msg){ case WM_INITDLG: // set titlebar of the dialog window // to "MODULENAME configuration" strcpy(buf, modulename); strcat(buf, " configuration"); WinSetWindowText(hwnd, (PSZ)buf); // get window handles of the dialog controls // and set initial state of the controls hwndEnabled = WinWindowFromID(hwnd, IDC_ENABLED); WinSendMsg(hwndEnabled, BM_SETCHECK, MPFROMLONG(configuration_data.enabled), MPVOID); hwndSpeed = WinWindowFromID(hwnd, IDC_SPEED); WinSendMsg(hwndSpeed, SLM_SETTICKSIZE, MPFROM2SHORT(SMA_SETALLTICKS, 3), MPVOID); WinSendMsg(hwndSpeed, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), MPFROMLONG(configuration_data.animation_speed)); WinSendMsg(hwndSpeed, SLM_SETSCALETEXT, MPFROMSHORT(0), MPFROMP("slow")); WinSendMsg(hwndSpeed, SLM_SETSCALETEXT, MPFROMSHORT(4), MPFROMP("fast")); /* $$$$$ insert code here $$$$$ Get window handles of your dialog controls. Set initial state of your controls. $$$$$ for example $$$$$ */ hwndCount = WinWindowFromID(hwnd, IDC_COUNT); WinSendMsg(hwndCount, SPBM_SETLIMITS, (MPARAM)CONFIGURATION_MAXIMUM_COUNT, (MPARAM)CONFIGURATION_MINIMUM_COUNT); WinSendMsg(hwndCount, SPBM_SETCURRENTVALUE, MPFROMLONG(configuration_data.count), MPVOID); /* set window that queries how many lines will have the same color */ hwndColor = WinWindowFromID(hwnd, IDC_COLOR); WinSendMsg(hwndColor, SPBM_SETLIMITS, (MPARAM)COLORS_MAXIMUM, (MPARAM)COLORS_MINIMUM); WinSendMsg(hwndColor, SPBM_SETCURRENTVALUE, MPFROMLONG(configuration_data.colors), MPVOID); hwndBlankScreen = WinWindowFromID(hwnd, IDC_BLANKSCREEN); WinSendMsg(hwndBlankScreen, BM_SETCHECK, MPFROMSHORT(configuration_data.blank_screen), MPVOID); // return FALSE since we did not change the focus return (MRESULT)FALSE; case WM_COMMAND: switch(SHORT1FROMMP(mp1)){ case IDC_OK: // OK button was pressed. query the control settings configuration_data.enabled = SHORT1FROMMR(WinSendMsg(hwndEnabled, BM_QUERYCHECK, MPVOID, MPVOID)); configuration_data.animation_speed = SHORT1FROMMR(WinSendMsg(hwndSpeed, SLM_QUERYSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), MPVOID)); /* $$$$$ insert code here $$$$$ Query control settings of your controls. $$$$$ for example $$$$$ */ WinSendMsg(hwndCount, SPBM_QUERYVALUE, MPFROMP(&configuration_data.count), MPFROM2SHORT(0, SPBQ_DONOTUPDATE)); WinSendMsg(hwndColor, SPBM_QUERYVALUE, MPFROMP(&configuration_data.colors), MPFROM2SHORT(0, SPBQ_DONOTUPDATE)); configuration_data.blank_screen = SHORT1FROMMR(WinSendMsg(hwndBlankScreen, BM_QUERYCHECK, MPVOID, MPVOID)); /* check if the values are in the allowed range */ if(CONFIGURATION_MINIMUM_COUNT > configuration_data.count || configuration_data.count > CONFIGURATION_MAXIMUM_COUNT){ sprintf( msgtext, "Sorry, but the number of lines displayed must be between %d and %d!", CONFIGURATION_MINIMUM_COUNT, CONFIGURATION_MAXIMUM_COUNT); WinMessageBox( HWND_DESKTOP, hwnd, (PSZ)msgtext, (PSZ)"Bouncing Line", 0, MB_OK | MB_INFORMATION | MB_MOVEABLE ); } else { if( COLORS_MINIMUM > configuration_data.colors || configuration_data.colors > COLORS_MAXIMUM ) { sprintf( msgtext, "Sorry, but the number of lines that are displayed in the same color must be between %d and %d!", COLORS_MINIMUM, COLORS_MAXIMUM ); WinMessageBox( HWND_DESKTOP, hwnd, (PSZ)msgtext, (PSZ)"Bouncing Line", 0, MB_OK | MB_INFORMATION | MB_MOVEABLE ); } else { /* everything is o.k. */ /* write all configuration data to INI-file */ write_profile_data(); // end dialog WinDismissDlg(hwnd, TRUE); } } return (MRESULT)0; case IDC_CANCEL: // dialog was cancelled; end it WinDismissDlg(hwnd, FALSE); return (MRESULT)0; default: return (MRESULT)0; } } return WinDefDlgProc(hwnd, msg, mp1, mp2); }
/* SAVER_PROC This is the entry point into the saver module that is called by the ScreenSaver program. There should be no reason to alter the code. Depending on the requested function, the following tasks are performed: * set the name of the INI file to store and query settings * call the configuration dialog of the saver module * copy the name of the saver module into the supplied buffer * tell if the saver module is enabled * set the "enabled" state of the saver module * start the saver * stop the saver Note that before any processing is done, module configuration data is loaded from the INI-files. */ void EXPENTRY SAVER_PROC(int function, HAB _hab, HWND hwndOwner, char *appname, void *buffer) { hab = _hab; application_name = appname; hwndApplication = hwndOwner; // load all configuration data from INI-file if(function != FUNCTION_SETINIFILENAME) load_configuration_data(); switch(function){ case FUNCTION_SETINIFILENAME: if(buffer != NULL) strcpy(ini_filename, (char *)buffer); else strcpy(ini_filename, ""); return; case FUNCTION_CONFIGURE: // call the configuration dialog WinDlgBox(HWND_DESKTOP, hwndOwner, ConfigureDlgProc, hmodDLL, IDD_CONFIGURE, application_name); return; case FUNCTION_STARTSAVER: // start the saver // get "low priority" state from supplied buffer (BOOL *) low_priority = *((BOOL *)buffer); // query size of screen screenSizeX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN); screenSizeY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN); // register window class for the saver window WinRegisterClass(hab, (PSZ)modulename, (PFNWP)SaverWindowProc, 0, 0); // create the saver window hwndSaver = WinCreateWindow(HWND_DESKTOP, (PSZ)modulename, (PSZ)NULL, WS_VISIBLE, 0, 0, screenSizeX, screenSizeY, HWND_DESKTOP, HWND_TOP, 0, NULL, NULL); return; case FUNCTION_STOPSAVER: // stop the saver if(low_priority){ stop_priority_thread = TRUE; DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, 0, tidPriority); DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, 0, tidDraw); DosWaitThread(&tidPriority, DCWW_WAIT); // DosKillThread(tidPriority); ***** kills thread 1 under OS/2 2.11 } // tell drawing-thread to stop stop_draw_thread = TRUE; if(DosWaitThread(&tidDraw, DCWW_NOWAIT) == ERROR_THREAD_NOT_TERMINATED){ // if priority of drawing-thread was set to idle time // priority, set it back to normal value DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, PRTYD_MAXIMUM, tidDraw); // wait until drawing-thread has ended DosWaitThread(&tidDraw, DCWW_WAIT); } if(hwndSaver != NULLHANDLE){ // move saver window to front WinSetWindowPos(hwndSaver, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER); // destroy saver window WinDestroyWindow(hwndSaver); hwndSaver = NULLHANDLE; } return; case FUNCTION_QUERYNAME: // copy module name to supplied buffer (CHAR *) strcpy(buffer, modulename); return; case FUNCTION_QUERYENABLED: // copy "enabled" state to supplied buffer (BOOL *) *((BOOL *)buffer) = configuration_data.enabled; return; case FUNCTION_SETENABLED: // get new "enabled" state from supplied buffer (BOOL *) configuration_data.enabled = *((BOOL *)buffer); write_profile_data(); return; } // illegal function request WinAlarm(HWND_DESKTOP, WA_ERROR); return; }
/* ConfigureDlgProc This is the dialog procedure for the module configuration dialog. The dialog contains a check box for enabling/disabling the module and two push buttons ("OK" and "Cancel") to close/cancel the dialog. Since version 1.2, it contains a slider to set the animation speed; if you don't want this slider, change the '#if 0' line in the WM_INITDLG part of this dialog procedure. This is enough for simple saver modules, but can easily be expanded for more saver modules that need more settings. */ MRESULT EXPENTRY ConfigureDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { char buf[sizeof(modulename)+20]; static HWND hwndEnabled; static HWND hwndGravity; static HWND hwndWhiteStars,hwndRedStars; static HWND hwndBlueStars,hwndYellowStars; static HWND hwndTraceName; static HWND hwndShow3d; switch(msg){ case WM_INITDLG: /* set titlebar of the dialog window */ /* to "MODULENAME configuration" */ strcpy(buf, modulename); strcat(buf, " configuration"); WinSetWindowText(hwnd, (PSZ)buf); /* get window handles of the dialog controls */ /* and set initial state of the controls */ hwndEnabled = WinWindowFromID(hwnd, IDC_ENABLED); WinSendMsg(hwndEnabled, BM_SETCHECK, MPFROMSHORT(configuration_data.enabled), MPVOID); hwndEnabled = WinWindowFromID(hwnd, IDC_ENABLED); WinSendMsg(hwndEnabled, BM_SETCHECK,MPFROMSHORT(configuration_data.enabled), MPVOID); hwndTraceName = WinWindowFromID(hwnd, IDC_TRACENAME); WinSendMsg(hwndTraceName, BM_SETCHECK,MPFROMSHORT(configuration_data.tracename), MPVOID); hwndShow3d = WinWindowFromID(hwnd, IDC_3D); WinSendMsg(hwndShow3d, BM_SETCHECK,MPFROMSHORT(configuration_data.show3d), MPVOID); hwndGravity = WinWindowFromID(hwnd, IDC_GRAVITY); WinSendMsg(hwndGravity, SPBM_SETLIMITS, (MPARAM)CONFIGURATION_MAXIMUM_GRAVITY, (MPARAM)CONFIGURATION_MINIMUM_GRAVITY); WinSendMsg(hwndGravity, SPBM_SETCURRENTVALUE, MPFROMSHORT(configuration_data.gravity), MPVOID); hwndWhiteStars = WinWindowFromID(hwnd, IDC_WHITESTARS); WinSendMsg(hwndWhiteStars, SPBM_SETLIMITS, (MPARAM)CONFIGURATION_MAXIMUM_STARS, (MPARAM)CONFIGURATION_MINIMUM_STARS); WinSendMsg(hwndWhiteStars, SPBM_SETCURRENTVALUE, MPFROMSHORT(configuration_data.whitestar_count), MPVOID); hwndRedStars = WinWindowFromID(hwnd, IDC_REDSTARS); WinSendMsg(hwndRedStars, SPBM_SETLIMITS, (MPARAM)CONFIGURATION_MAXIMUM_STARS, (MPARAM)CONFIGURATION_MINIMUM_STARS); WinSendMsg(hwndRedStars, SPBM_SETCURRENTVALUE, MPFROMSHORT(configuration_data.redstar_count), MPVOID); hwndBlueStars = WinWindowFromID(hwnd, IDC_BLUESTARS); WinSendMsg(hwndBlueStars, SPBM_SETLIMITS, (MPARAM)CONFIGURATION_MAXIMUM_STARS, (MPARAM)CONFIGURATION_MINIMUM_STARS); WinSendMsg(hwndBlueStars, SPBM_SETCURRENTVALUE, MPFROMSHORT(configuration_data.bluestar_count), MPVOID); hwndYellowStars = WinWindowFromID(hwnd, IDC_YELLOWSTARS); WinSendMsg(hwndYellowStars, SPBM_SETLIMITS, (MPARAM)CONFIGURATION_MAXIMUM_STARS, (MPARAM)CONFIGURATION_MINIMUM_STARS); WinSendMsg(hwndYellowStars, SPBM_SETCURRENTVALUE, MPFROMSHORT(configuration_data.yellowstar_count), MPVOID); /* return FALSE since we did not change the focus */ return (MRESULT)FALSE; case WM_COMMAND: switch(SHORT1FROMMP(mp1)){ case IDC_OK: /* OK button was pressed. query the control settings */ configuration_data.enabled = SHORT1FROMMR(WinSendMsg(hwndEnabled, BM_QUERYCHECK, MPVOID, MPVOID)); configuration_data.tracename = SHORT1FROMMR(WinSendMsg(hwndTraceName, BM_QUERYCHECK, MPVOID, MPVOID)); configuration_data.show3d = SHORT1FROMMR(WinSendMsg(hwndShow3d, BM_QUERYCHECK, MPVOID, MPVOID)); WinSendMsg(hwndGravity, SPBM_QUERYVALUE, MPFROMP(&configuration_data.gravity), MPFROM2SHORT(0, SPBQ_DONOTUPDATE)); WinSendMsg(hwndWhiteStars, SPBM_QUERYVALUE, MPFROMP(&configuration_data.whitestar_count), MPFROM2SHORT(0, SPBQ_DONOTUPDATE)); WinSendMsg(hwndRedStars, SPBM_QUERYVALUE, MPFROMP(&configuration_data.redstar_count), MPFROM2SHORT(0, SPBQ_DONOTUPDATE)); WinSendMsg(hwndBlueStars, SPBM_QUERYVALUE, MPFROMP(&configuration_data.bluestar_count), MPFROM2SHORT(0, SPBQ_DONOTUPDATE)); WinSendMsg(hwndYellowStars, SPBM_QUERYVALUE, MPFROMP(&configuration_data.yellowstar_count), MPFROM2SHORT(0, SPBQ_DONOTUPDATE)); /* write all configuration data to INI-file */ write_profile_data(); /* end dialog */ WinDismissDlg(hwnd, TRUE); return (MRESULT)0; case IDC_CANCEL: /* dialog was cancelled; end it */ WinDismissDlg(hwnd, FALSE); return (MRESULT)0; default: return (MRESULT)0; } } return WinDefDlgProc(hwnd, msg, mp1, mp2); }
/* ConfigureDlgProc This is the dialog procedure for the module configuration dialog. The dialog contains a check box for enabling/disabling the module and two push buttons ("OK" and "Cancel") to close/cancel the dialog. Since version 1.2, it contains a slider to set the animation speed; if you don't want this slider, change the '#if 0' line in the WM_INITDLG part of this dialog procedure. This is enough for simple saver modules, but can easily be expanded for more saver modules that need more settings. */ MRESULT EXPENTRY ConfigureDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { char buf[sizeof(modulename)+20]; static HWND hwndEnabled; static HWND hwndSpeed; /* $$$$$ insert code here $$$$$ If you need additional data for dialog processing, insert it here. $$$$$ for example $$$$$ */ static HWND hwndCount; switch(msg){ case WM_INITDLG: /* set titlebar of the dialog window */ /* to "MODULENAME configuration" */ strcpy(buf, modulename); strcat(buf, " configuration"); WinSetWindowText(hwnd, (PSZ)buf); /* get window handles of the dialog controls */ /* and set initial state of the controls */ hwndEnabled = WinWindowFromID(hwnd, IDC_ENABLED); WinSendMsg(hwndEnabled, BM_SETCHECK, MPFROMSHORT(configuration_data.enabled), MPVOID); hwndSpeed = WinWindowFromID(hwnd, IDC_SPEED); WinSendMsg(hwndSpeed, SLM_SETTICKSIZE, MPFROM2SHORT(SMA_SETALLTICKS, 3), MPVOID); WinSendMsg(hwndSpeed, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), MPFROMLONG(configuration_data.animation_speed)); WinSendMsg(hwndSpeed, SLM_SETSCALETEXT, MPFROMSHORT(0), MPFROMP("slow")); WinSendMsg(hwndSpeed, SLM_SETSCALETEXT, MPFROMSHORT(4), MPFROMP("fast")); /* $$$$$ insert code here $$$$$ Get window handles of your dialog controls. Set initial state of your controls. $$$$$ for example $$$$$ */ hwndCount = WinWindowFromID(hwnd, IDC_COUNT); WinSendMsg(hwndCount, SPBM_SETLIMITS, (MPARAM)CONFIGURATION_MAXIMUM_COUNT, (MPARAM)CONFIGURATION_MINIMUM_COUNT); WinSendMsg(hwndCount, SPBM_SETCURRENTVALUE, MPFROMLONG(configuration_data.count), MPVOID); /* return FALSE since we did not change the focus */ return (MRESULT)FALSE; case WM_COMMAND: switch(SHORT1FROMMP(mp1)){ case IDC_OK: /* OK button was pressed. query the control settings */ configuration_data.enabled = SHORT1FROMMR(WinSendMsg(hwndEnabled, BM_QUERYCHECK, MPVOID, MPVOID)); configuration_data.animation_speed = SHORT1FROMMR(WinSendMsg(hwndSpeed, SLM_QUERYSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), MPVOID)); /* $$$$$ insert code here $$$$$ Query control settings of your controls. $$$$$ for example $$$$$ */ WinSendMsg(hwndCount, SPBM_QUERYVALUE, MPFROMP(&configuration_data.count), MPFROM2SHORT(0, SPBQ_DONOTUPDATE)); /* write all configuration data to INI-file */ write_profile_data(); /* end dialog */ WinDismissDlg(hwnd, TRUE); return (MRESULT)0; case IDC_CANCEL: /* dialog was cancelled; end it */ WinDismissDlg(hwnd, FALSE); return (MRESULT)0; default: return (MRESULT)0; } } return WinDefDlgProc(hwnd, msg, mp1, mp2); }