void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) { // TODO: Support ramp sizes other than 256 int i; int size = GLFW_GAMMA_RAMP_SIZE; CGGammaValue red[GLFW_GAMMA_RAMP_SIZE]; CGGammaValue green[GLFW_GAMMA_RAMP_SIZE]; CGGammaValue blue[GLFW_GAMMA_RAMP_SIZE]; if (CGDisplayGammaTableCapacity(monitor->ns.displayID) != GLFW_GAMMA_RAMP_SIZE) { _glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Only gamma ramps of size 256 supported"); return; } // Convert to float & take the difference of the original gamma and // the linear function. for (i = 0; i < size; i++) { red[i] = ramp->red[i] / 65535.f; green[i] = ramp->green[i] / 65535.f; blue[i] = ramp->blue[i] / 65535.f; } CGSetDisplayTransferByTable(monitor->ns.displayID, GLFW_GAMMA_RAMP_SIZE, red, green, blue); }
int GGI_quartz_setgammamap(struct ggi_visual *vis, int start, int len, const ggi_color *colormap) { int i; ggi_quartz_priv *priv; /* Note: If the compiler breaks here, * then it is not ANSI C99 conform. */ const CGTableCount tableSize = len; CGGammaValue redTable[tableSize]; CGGammaValue greenTable[tableSize]; CGGammaValue blueTable[tableSize]; priv = QUARTZ_PRIV(vis); if (colormap == NULL) return GGI_EARGINVAL; if (start < 0 || start >= vis->gamma->len) return GGI_ENOSPACE; if (len > (vis->gamma->len - start)) return GGI_ENOSPACE; /* Extract gamma values into separate tables, * convert to floats between 0.0 and 1.0 */ #if 0 i = 0; do { if ((start + i) < priv->gamma.maxwrite_r) { priv->gammamap[start + i].red = colormap[i].r; } /* if */ if ((start + i) < priv->gamma.maxwrite_g) { priv->gammamap[start + i].green = colormap[i].g; } /* if */ if ((start + i) < priv->gamma.maxwrite_b) { priv->gammamap[start + i].blue = colormap[i].b; } /* if */ } while (i++ < len); #endif i = 0; do { redTable[i] = (uint16_t)(colormap[i].r / 65535.0); greenTable[i] = (uint16_t)(colormap[i].g / 65535.0); blueTable[i] = (uint16_t)(colormap[i].b / 65535.0); } while (i++ < len); if ( CGDisplayNoErr != CGSetDisplayTransferByTable (priv->display_id, tableSize, redTable, greenTable, blueTable) ) { return -1; } /* if */ return 0; } /* GGI_quartz_setgammamap */
/*********************************************************************** * SetDeviceGammaRamp (MACDRV.@) */ BOOL macdrv_SetDeviceGammaRamp(PHYSDEV dev, LPVOID ramp) { DDGAMMARAMP *r = ramp; struct macdrv_display *displays; int num_displays; int win_entries = sizeof(r->red) / sizeof(r->red[0]); CGGammaValue *red, *green, *blue; int i; CGError err = kCGErrorFailure; TRACE("dev %p ramp %p\n", dev, ramp); if (!allow_set_gamma) { TRACE("disallowed by registry setting\n"); return FALSE; } if (macdrv_get_displays(&displays, &num_displays)) { WARN("failed to get Mac displays\n"); return FALSE; } red = HeapAlloc(GetProcessHeap(), 0, win_entries * sizeof(red[0]) * 3); if (!red) goto done; green = red + win_entries; blue = green + win_entries; for (i = 0; i < win_entries; i++) { red[i] = r->red[i] / 65535.0; green[i] = r->green[i] / 65535.0; blue[i] = r->blue[i] / 65535.0; } err = CGSetDisplayTransferByTable(displays[0].displayID, win_entries, red, green, blue); if (err != kCGErrorSuccess) WARN("failed to set display gamma table: %d\n", err); done: HeapFree(GetProcessHeap(), 0, red); macdrv_free_displays(displays); return (err == kCGErrorSuccess); }
static void quartz_set_temperature_for_display(quartz_state_t *state, int display, const color_setting_t *setting) { uint32_t ramp_size = state->displays[display].ramp_size; /* Create new gamma ramps */ float *gamma_ramps = malloc(3*ramp_size*sizeof(float)); if (gamma_ramps == NULL) { perror("malloc"); return; } float *gamma_r = &gamma_ramps[0*ramp_size]; float *gamma_g = &gamma_ramps[1*ramp_size]; float *gamma_b = &gamma_ramps[2*ramp_size]; if (state->preserve) { /* Initialize gamma ramps from saved state */ memcpy(gamma_ramps, state->displays[display].saved_ramps, 3*ramp_size*sizeof(float)); } else { /* Initialize gamma ramps to pure state */ for (int i = 0; i < ramp_size; i++) { float value = (double)i/ramp_size; gamma_r[i] = value; gamma_g[i] = value; gamma_b[i] = value; } } colorramp_fill_float(gamma_r, gamma_g, gamma_b, ramp_size, setting); CGError error = CGSetDisplayTransferByTable(display, ramp_size, gamma_r, gamma_g, gamma_b); if (error != kCGErrorSuccess) { free(gamma_ramps); return; } free(gamma_ramps); }
int main(int argc, char *argv[]) { CGTableCount sampleCount; CGDisplayErr cgErr; Initialize(); MakeWindow(); MakeMenu(); // Grab original gamma settings cgErr = CGGetDisplayTransferByTable( 0, 256, gOriginalRedTable, gOriginalGreenTable, gOriginalBlueTable, &sampleCount); InstallTimer(); EventLoop(); // Restore original gamma settings cgErr = CGSetDisplayTransferByTable( 0, 256, gOriginalRedTable, gOriginalGreenTable, gOriginalBlueTable); return 0; }
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) { int i; CGGammaValue* values = (CGGammaValue*) malloc(ramp->size * 3 * sizeof(CGGammaValue)); for (i = 0; i < ramp->size; i++) { values[i] = ramp->red[i] / 65535.f; values[i + ramp->size] = ramp->green[i] / 65535.f; values[i + ramp->size * 2] = ramp->blue[i] / 65535.f; } CGSetDisplayTransferByTable(monitor->ns.displayID, ramp->size, values, values + ramp->size, values + ramp->size * 2); free(values); }
void MyTimerProc ( EventLoopTimerRef inTimer, void *inUserData ) { CGGammaValue redTable[ 256 ]; CGGammaValue greenTable[ 256 ]; CGGammaValue blueTable[ 256 ]; CGTableCount sampleCount; CGDisplayErr cgErr; short i, j; static int firstTime = 1; if ( firstTime == 1 ) { for (j = 0; j < 3; j++) { x [j] = (TickCount () + j * 120) % 256; y [j] = 255; } firstTime = 0; } for (i = 0; i < 256 ; i++) { redTable[ i ] = gOriginalRedTable[ i ] * (y[ 0 ] % 256) / 256; greenTable[ i ] = gOriginalGreenTable[ i ] * (y[ 1 ] % 256) / 256; blueTable[ i ] = gOriginalBlueTable[ i ] * (y[ 2 ] % 256) / 256; } cgErr = CGSetDisplayTransferByTable( 0, 256, redTable, greenTable, blueTable); for (j = 0; j < 3; j++) { (x [j] > y [j]) ? y [j]++ : y [j]--; if (x [j] == y [j]) x [j] = ((TickCount () % (1457 * j)) + j * 97) % 256; } }
int VID_SetGamma(unsigned short *ramps, int rampsize) { CGGammaValue table_red [GAMMA_TABLE_SIZE]; CGGammaValue table_green [GAMMA_TABLE_SIZE]; CGGammaValue table_blue [GAMMA_TABLE_SIZE]; int i; // Convert the unsigned short table into 3 float tables for (i = 0; i < rampsize; i++) table_red[i] = (float)ramps[i] / 65535.0f; for (i = 0; i < rampsize; i++) table_green[i] = (float)ramps[i + rampsize] / 65535.0f; for (i = 0; i < rampsize; i++) table_blue[i] = (float)ramps[i + 2 * rampsize] / 65535.0f; if (CGSetDisplayTransferByTable(CGMainDisplayID(), rampsize, table_red, table_green, table_blue) != CGDisplayNoErr) { Con_Print("VID_SetGamma: ERROR: CGSetDisplayTransferByTable failed!\n"); return false; } return true; }