static int32_t osdcmd_cvar_set_baselayer(const osdfuncparm_t *parm) { int32_t r = osdcmd_cvar_set(parm); if (r != OSDCMD_OK) return r; /* if (!Bstrcasecmp(parm->name, "r_scrcaptureformat")) { const char *fmts[] = {"TGA", "PCX"}; if (showval) { OSD_Printf("r_scrcaptureformat is %s\n", fmts[captureformat]); } else { int32_t j; for (j=0; j<2; j++) if (!Bstrcasecmp(parm->parms[0], fmts[j])) break; if (j == 2) return OSDCMD_SHOWHELP; captureformat = j; } return OSDCMD_OK; } else */ if (!Bstrcasecmp(parm->name, "vid_gamma") || !Bstrcasecmp(parm->name, "vid_brightness") || !Bstrcasecmp(parm->name, "vid_contrast")) { setbrightness(GAMMA_CALC,palette,0); return r; } return r; }
void brightnessDown(void) { int c; c = current(); if(c > 0) { c--; setbrightness(c); } }
//Initialize the bees struct void initBees(){ //turn off contrast setbrightness(0); //paint it black stroke(0); for(int i=0; i < BEES_COUNT; i++){ mBees[i].x = 160; // =320/2 mBees[i].y = 120; } }
void brightnessUp(void) { int c, m; c = current(); m = maximum(); if(c < m) { c++; setbrightness(c); } }
VOID SetPaletteToVESA(char *pal) { /* char pal_buff[1024]; short i; for (i = 0; i < 256; i++) { pal_buff[i * 4 + NRED] = pal[i * 3 + ORED]; pal_buff[i * 4 + NGREEN] = pal[i * 3 + OGREEN]; pal_buff[i * 4 + NBLUE] = pal[i * 3 + OBLUE]; pal_buff[i * 4 + NRESERVED] = 0; } VBE_setPalette(0, 256, pal_buff); */ setbrightness(0,pal,4|2); // fprintf(stderr,"SetPaletteToVESA() called\n"); }
void playanm(short anim_num) { unsigned char *animbuf, *palptr; int i, j, k, length = 0, numframes = 0; int32 handle = -1; unsigned char ANIMvesapal[4*256]; unsigned char tempbuf[256]; unsigned char *palook_bak = palookup[0]; UserInput uinfo = { FALSE, FALSE, dir_None }; ANIMnum = anim_num; KB_FlushKeyboardQueue(); KB_ClearKeysDown(); DSPRINTF(ds,"PlayAnm"); MONO_PRINT(ds); DSPRINTF(ds,"PlayAnm"); MONO_PRINT(ds); animbuf = LoadAnm(anim_num); if (!animbuf) return; DSPRINTF(ds,"PlayAnm - Palette Stuff"); MONO_PRINT(ds); for (i = 0; i < 256; i++) tempbuf[i] = i; palookup[0] = tempbuf; ANIM_LoadAnim(animbuf); ANIMnumframes = ANIM_NumFrames(); numframes = ANIMnumframes; palptr = ANIM_GetPalette(); for (i = 0; i < 768; i++) ANIMvesapal[i] = palptr[i]>>2; tilesizx[ANIM_TILE(ANIMnum)] = 200; tilesizy[ANIM_TILE(ANIMnum)] = 320; clearview(0); setbrightness(gs.Brightness,ANIMvesapal,2); if (ANIMnum == 1) { // draw the first frame waloff[ANIM_TILE(ANIMnum)] = (intptr_t)ANIM_DrawFrame(1); invalidatetile(ANIM_TILE(ANIMnum), 0, 1<<4); rotatesprite(0 << 16, 0 << 16, 65536L, 512, ANIM_TILE(ANIMnum), 0, 0, 2 + 4 + 8 + 16 + 64, 0, 0, xdim - 1, ydim - 1); } SoundState = 0; //ototalclock = totalclock + 120*2; ototalclock = totalclock; for (i = 1; i < numframes; i++) { while (totalclock < ototalclock) { handleevents(); CONTROL_GetUserInput(&uinfo); CONTROL_ClearUserInput(&uinfo); switch (ANIMnum) { case ANIM_INTRO: if (KB_KeyWaiting() || uinfo.button0 || uinfo.button1 || quitevent) goto ENDOFANIMLOOP; break; case ANIM_SERP: if (KEY_PRESSED(KEYSC_ESC) || uinfo.button1 || quitevent) goto ENDOFANIMLOOP; break; } getpackets(); } switch (ANIMnum) { case ANIM_INTRO: AnimShareIntro(i,numframes); break; case ANIM_SERP: AnimSerp(i,numframes); break; case ANIM_SUMO: AnimSumo(i,numframes); break; case ANIM_ZILLA: AnimZilla(i,numframes); break; } waloff[ANIM_TILE(ANIMnum)] = (intptr_t)ANIM_DrawFrame(i); invalidatetile(ANIM_TILE(ANIMnum), 0, 1<<4); rotatesprite(0 << 16, 0 << 16, 65536L, 512, ANIM_TILE(ANIMnum), 0, 0, 2 + 4 + 8 + 16 + 64, 0, 0, xdim - 1, ydim - 1); nextpage(); } // pause on final frame while (totalclock < ototalclock) { handleevents(); getpackets(); } ENDOFANIMLOOP: clearview(0); nextpage(); palookup[0] = palook_bak; setbrightness(gs.Brightness, (unsigned char*)palette_data, 2); KB_FlushKeyboardQueue(); KB_ClearKeysDown(); ANIM_FreeAnim(); walock[ANIM_TILE(ANIMnum)] = 1; }
void playanm ( short anim_num ) { char *animbuf, *palptr; long i, j, k, numframes = 0; int32 handle = -1; char ANIMvesapal[4 * 256]; char tempbuf[256]; char *palook_bak = palookup[0]; ANIMnum = anim_num; KB_FlushKeyboardQueue(); KB_ClearKeysDown(); DSPRINTF ( ds, "PlayAnm" ); MONO_PRINT ( ds ); DSPRINTF ( ds, "PlayAnm" ); MONO_PRINT ( ds ); animbuf = LoadAnm ( anim_num ); if ( !animbuf ) { return; } DSPRINTF ( ds, "PlayAnm - Palette Stuff" ); MONO_PRINT ( ds ); for ( i = 0; i < 256; i++ ) { tempbuf[i] = i; } palookup[0] = tempbuf; ANIM_LoadAnim ( ( uint8_t * ) animbuf, length ); ANIMnumframes = ANIM_NumFrames(); numframes = ANIMnumframes; palptr = ( char * ) ANIM_GetPalette(); for ( i = 0; i < 768; i++ ) { ANIMvesapal[i] = palptr[i] >> 2; } tilesiz[TILE_ANIM].x = 200; tilesiz[TILE_ANIM].y = 320; setbasepal ( 0, ( const uint8_t * ) ANIMvesapal ); setbrightness ( gs.Brightness, 0, 2 ); if ( ANIMnum == 1 ) { // draw the first frame waloff[TILE_ANIM] = FP_OFF ( ANIM_DrawFrame ( 1 ) ); invalidatetile ( TILE_ANIM, 0, 1 << 4 ); rotatesprite ( 0 << 16, 0 << 16, 65536L, 512, TILE_ANIM, 0, 0, 2 + 4 + 8 + 16 + 64, 0, 0, xdim - 1, ydim - 1 ); } SoundState = 0; //ototalclock = totalclock + 120*2; ototalclock = totalclock; for ( i = 1; i < numframes; i++ ) { while ( totalclock < ototalclock ) { switch ( ANIMnum ) { case 0: if ( KB_KeyWaiting() ) { goto ENDOFANIMLOOP; } break; case 1: if ( KEY_PRESSED ( KEYSC_ESC ) ) { goto ENDOFANIMLOOP; } break; } getpackets(); } switch ( ANIMnum ) { case ANIM_INTRO: AnimShareIntro ( i, numframes ); break; case ANIM_SERP: AnimSerp ( i, numframes ); break; case ANIM_SUMO: AnimSumo ( i, numframes ); break; case ANIM_ZILLA: AnimZilla ( i, numframes ); break; } waloff[TILE_ANIM] = FP_OFF ( ANIM_DrawFrame ( i ) ); invalidatetile ( TILE_ANIM, 0, 1 << 4 ); rotatesprite ( 0 << 16, 0 << 16, 65536L, 512, TILE_ANIM, 0, 0, 2 + 4 + 8 + 16 + 64, 0, 0, xdim - 1, ydim - 1 ); nextpage(); } // pause on final frame while ( totalclock < ototalclock ) { getpackets(); } ENDOFANIMLOOP: clearview ( 0 ); nextpage(); palookup[0] = palook_bak; // setbrightness(gs.Brightness, (char*)palette_data, 2); setbasepal ( 0, ( const uint8_t * ) palette_data ); setbrightness ( gs.Brightness, 0, 2 ); KB_FlushKeyboardQueue(); KB_ClearKeysDown(); ANIM_FreeAnim(); walock[ANIM_TILE ( ANIMnum )] = 1; }
void chunk::setbrightness(int x, int y, int z, brightness tbrightness){ setbrightness((ubyte)x, (ubyte)y, (ubyte)z, tbrightness); }
/** * This is the mane entry point of the program * * @param argc The number of elements in `argv` * @parma argv Command line arguments, including the command * @return Exit value, zero on success */ int main(int argc, char** argv) { struct winsize win; struct termios saved_stty; struct termios stty; size_t i, ndevices = 0; pid_t pid = 0; char* set = NULL; int j, get = 0, help = 0, all = 0, cols = 80; char** devices = alloca((size_t)argc * sizeof(char*)); if (argc > 1) { char* arg; for (i = 1; i < (size_t)argc; i++) { #define T(S) (!strcmp(arg, S)) arg = *(argv + i); if (T("-h") || T("--help")) help = 1; else if (T("-a") || T("--all")) all = 1; else if (T("-c") || T("--copyright") || T("--copying")) { P("\n"); P("adjbacklight – Convenient method for adjusting the backlight on your portable computer"); P(""); P("Copyright © " _YEARS_ " Mattias Andrée ([email protected])"); P(""); P("This program is free software: you can redistribute it and/or modify"); P("it under the terms of the GNU General Public License as published by"); P("the Free Software Foundation, either version 3 of the License, or"); P("(at your option) any later version."); P(""); P("This program is distributed in the hope that it will be useful,"); P("but WITHOUT ANY WARRANTY; without even the implied warranty of"); P("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"); P("GNU General Public License for more details."); P(""); P("You should have received a copy of the GNU General Public License"); P("along with this program. If not, see <http://www.gnu.org/licenses/>."); P("\n"); return 0; } else if (T("-w") || T("--warranty")) { P("\n"); P("This program is distributed in the hope that it will be useful,"); P("but WITHOUT ANY WARRANTY; without even the implied warranty of"); P("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"); P("GNU General Public License for more details."); P("\n"); return 0; } else if (T("-s") || T("--set")) { char* tmp; if (i + 1 == (size_t)argc) fprintf(stderr, "%s: argument for option %s is missing, ignoring option\n", *argv, arg); else if (!isnumerical(tmp = *(argv + ++i))) fprintf(stderr, "%s: argument for option %s is malformated, ignoring option\n", *argv, arg); else { set = tmp; get = 0; } } else if (T("-g") || T("--get")) { get = 1; set = NULL; } else if (((*arg == '-') || (*arg == '+') || (*arg == '=')) && isnumerical(arg + 1)) { set = arg; get = 0; } else { if (*arg && (*arg != '-')) *(devices + ndevices++) = arg; else fprintf(stderr, "%s: ignoring unrecognised argument: %s\n", *argv, arg); } #undef T } fflush(stderr); if (help || (((size_t)all + ndevices + (size_t)get == 0) && !set)) { P("\n"); P("adjbacklight - Convenient method for adjusting the backlight on your portable computer"); P(""); P("USAGE: adjbacklight (-c | -w | [-g | -s LEVEL | LEVEL] [-a | DEVICE...])"); P(""); P("Run with options to adjust the backlight on your monitors."); P(""); P(""); P("OPTIONS:"); P(""); P("-c"); P("--copyright"); P("--copying Display copyright information"); P(""); P("-w"); P("--warranty Display warranty disclaimer"); P(""); P("-a"); P("--all Run for all devices, including ACPI devices"); P(""); P("-g"); P("--get Get average brightness on devices"); P(""); P("-s"); P("--set LEVEL[%] Set brightness on devices"); P(""); P("+LEVEL Increase brightness on devices by actual value"); P("-LEVEL Decrease brightness on devices by actual value"); P("=LEVEL Set brightness on devices by actual value"); P(""); P("+LEVEL% Increase brightness on devices by percentage-points"); P("-LEVEL% Decrease brightness on devices by percentage-points"); P("=LEVEL% Set brightness on devices by percentage-points"); P(""); P("+LEVEL%% Increase brightness on devices by percentage"); P("-LEVEL%% Decrease brightness on devices by percentage"); P("=LEVEL%% Set brightness on devices by percentage"); P(""); P(""); P("KEYBOARD:"); P(""); P("←"); P("↓ Darken the screen"); P(""); P("→"); P("↑ Brighten the screen"); P(""); P("q"); P("enter"); P("C-d Continue to next controller, or if at last, quit"); P(""); P(""); P(""); P("Copyright © " _YEARS_ " Mattias Andrée ([email protected])"); P(""); P("This program is free software: you can redistribute it and/or modify"); P("it under the terms of the GNU General Public License as published by"); P("the Free Software Foundation, either version 3 of the License, or"); P("(at your option) any later version."); P(""); return 0; } } /* Check permissions */ if (getuid()) /* Always accept root */ { struct group* video_grp = getgrnam("video"); if (video_grp) /* Accept everypony if the group ‘video’ does not exist */ { struct passwd* realuser = getpwuid(getuid()); char** mems; char* realname; int ok; if (!realuser) { P("You do not exist, go away!"); return 1; } mems = video_grp->gr_mem; realname = realuser->pw_name; ok = 0; for (; *mems; mems++) if (!strcmp(realname, *mems)) { ok = 1; break; } endgrent(); if (!ok) { P("Sorry, you need to be in the group 'video'."); return 1; } } endpwent(); } if (!get && !set) { P("\n"); P("If the program is abnormally aborted the may be some residual"); P("effects on the terminal. the following commands should reset it:"); P(""); P(" stty icanon echo"); P(" echo -en '\\e[?25h'"); P(""); P("\n\n\n"); } if (!get && !set) { /* Get the size of the terminal */ if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == -1) perror(*argv); else cols = win.ws_col; /* Hide cursor */ printf("%s", "\033[?25l"); fflush(stdout); /* stty -icanon -echo */ if (tcgetattr(STDIN_FILENO, &stty)) { perror(*argv); return 1; } saved_stty = stty; stty.c_lflag &= (tcflag_t)~(ICANON | ECHO); if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &stty)) { perror(*argv); return 1; } } /* Fork to diminish risk of unclean exit */ if (!get && !set) { pid = FORK(); if (pid == (pid_t)-1) { perror(*argv); pid = 0; } } if (pid) waitpid(pid, NULL, 0); else { float brightness = 0; int nbrightness = 0; if (!get && !set) { line = malloc((size_t)cols * 3 * sizeof(char)); space = malloc((size_t)cols * sizeof(char)); for (i = 0; i < (size_t)cols; i++) { *(line + i * 3 + 0) = (char)(0xE2); *(line + i * 3 + 1) = (char)(0x94); *(line + i * 3 + 2) = (char)(0x80); *(space + i) = ' '; } *(space + cols - 1) = 0; *(line + (cols - 2) * 3) = 0; } if (ndevices) { char* device; for (i = 0; i < ndevices; i++) { device = *(devices + i); for (j = 0; *(device + j); j++) if (*(device + j) == '/') { device += j + 1; j = -1; } if (get) { float value = getbrightness(device); if (value >= 0.f) { brightness += value; nbrightness++; } } else if (set) setbrightness(device, set); else adjust(cols, device); } } else { struct dirent* ent; DIR* dir = opendir(BACKLIGHT_DIR); if (dir) { char* device; while ((ent = readdir(dir))) { device = ent->d_name; if (all || (strstr(device, "acpi_video") != device)) if (*device && (*device != '.')) { if (get) { float value = getbrightness(device); if (value >= 0.f) { brightness += value; nbrightness++; } } else if (set) setbrightness(device, set); else adjust(cols, device); } } closedir(dir); } } if (!get && !set) { free(line); free(space); } else if (get) { if (nbrightness) { brightness *= 100.f; brightness /= (float)nbrightness; printf("%.2f%%\n", (double)brightness); fflush(stdout); } else { printf("%s\n", "100.00%"); fflush(stdout); } } } if (!get && !set) { /* `stty icanon echo` */ if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_stty)) { perror(*argv); return 1; } /* Show cursor */ printf("%s", "\033[?25h"); fflush(stdout); } return 0; }