diff --exclude='stamp-*' --exclude=po --exclude=.deps --exclude='*.o' --exclude='config.*' --exclude='*~' --exclude=config.h --exclude=autom4te.cache --exclude=Makefile --exclude=configure --exclude='*.m4' --exclude='*.in' -Nur orig/redshift-1.7/configure.ac redshift-1.7/configure.ac --- orig/redshift-1.7/configure.ac 2011-07-04 05:58:09.000000000 -0700 +++ redshift-1.7/configure.ac 2013-09-14 15:28:08.000000000 -0700 @@ -16,6 +16,9 @@ AM_GNU_GETTEXT_VERSION([0.17]) AM_GNU_GETTEXT([external]) +m4_ifndef([PKG_CHECK_MODULES], + AC_DEFUN([PKG_CHECK_MODULES], [$4])) + PKG_CHECK_MODULES([X11], [x11], [have_x11=yes], [have_x11=no]) PKG_CHECK_MODULES([XF86VM], [xxf86vm], [have_xf86vm=yes], [have_xf86vm=no]) PKG_CHECK_MODULES([XCB], [xcb], [have_xcb=yes], [have_xcb=no]) @@ -28,6 +31,8 @@ AC_CHECK_HEADER([windows.h], [have_windows_h=yes], [have_windows_h=no]) +AC_CHECK_HEADER([CoreGraphics/CGDirectDisplay.h], [have_coregraphics=yes], [have_coregraphics=no]) + # Check for Python AM_PATH_PYTHON([2.6], [have_python=yes], [have_python=no]) @@ -103,9 +108,32 @@ ]) AM_CONDITIONAL([ENABLE_WINGDI], [test "x$enable_wingdi" = xyes]) +AC_MSG_CHECKING([whether to enable Quartz Display Services method]) +AC_ARG_ENABLE([quartz], [AC_HELP_STRING([--enable-quartz], + [enable Quartz Display Services method])], + [enable_quartz=$enableval],[enable_quartz=maybe]) +AS_IF([test "x$enable_quartz" != xno], [ + AS_IF([test $have_coregraphics = yes], [ + AC_DEFINE([ENABLE_QUARTZ], 1, + [Define to 1 to enable Quartz Display Services method]) + AC_MSG_RESULT([yes]) + enable_quartz=yes + ], [ + AC_MSG_RESULT([missing dependencies]) + AS_IF([test "x$enable_quartz" = xyes], [ + AC_MSG_ERROR([missing CoreGraphics framework for Quartz Display Services method]) + ]) + enable_quartz=no + ]) +], [ + AC_MSG_RESULT([no]) + enable_quartz=no +]) +AM_CONDITIONAL([ENABLE_QUARTZ], [test "x$enable_quartz" = xyes]) + # Check that at least one method is enabled -AS_IF([test "x$enable_randr" = xno -a "x$enable_vidmode" = xno -a "x$enable_wingdi" = xno], [ - AC_MSG_ERROR([either RANDR, VidMode or WinGDI must be enabled]) +AS_IF([test "x$enable_randr" = xno -a "x$enable_vidmode" = xno -a "x$enable_wingdi" = xno -a "x$enable_quartz" = xno], [ + AC_MSG_ERROR([either RANDR, VidMode, WinGDI, or Quartz must be enabled]) ]) # Check GNOME Clock location provider @@ -221,6 +249,7 @@ RANDR: ${enable_randr} VidMode: ${enable_vidmode} WinGDI: ${enable_wingdi} + Quartz: ${enable_quartz} Location providers: GNOME Clock: ${enable_gnome_clock} diff --exclude='stamp-*' --exclude=po --exclude=.deps --exclude='*.o' --exclude='config.*' --exclude='*~' --exclude=config.h --exclude=autom4te.cache --exclude=Makefile --exclude=configure --exclude='*.m4' --exclude='*.in' -Nur orig/redshift-1.7/src/Makefile.am redshift-1.7/src/Makefile.am --- orig/redshift-1.7/src/Makefile.am 2011-03-27 14:57:36.000000000 -0700 +++ redshift-1.7/src/Makefile.am 2013-09-14 16:26:57.000000000 -0700 @@ -26,6 +26,7 @@ AM_CFLAGS = redshift_LDADD = @LIBINTL@ EXTRA_DIST = +redshift_LDFLAGS = if ENABLE_RANDR redshift_SOURCES += gamma-randr.c gamma-randr.h @@ -48,6 +49,11 @@ redshift_LDADD += -lgdi32 endif +if ENABLE_QUARTZ +redshift_SOURCES += gamma-quartz.c gamma-quartz.h +redshift_LDFLAGS += -framework CoreGraphics +endif + if ENABLE_GNOME_CLOCK redshift_SOURCES += location-gnome-clock.c location-gnome-clock.h AM_CFLAGS += $(GLIB_CFLAGS) $(GCONF_CFLAGS) diff --exclude='stamp-*' --exclude=po --exclude=.deps --exclude='*.o' --exclude='config.*' --exclude='*~' --exclude=config.h --exclude=autom4te.cache --exclude=Makefile --exclude=configure --exclude='*.m4' --exclude='*.in' -Nur orig/redshift-1.7/src/colorramp.c redshift-1.7/src/colorramp.c --- orig/redshift-1.7/src/colorramp.c 2011-04-20 14:46:05.000000000 -0700 +++ redshift-1.7/src/colorramp.c 2013-09-14 16:27:42.000000000 -0700 @@ -127,8 +127,7 @@ } void -colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b, - int size, int temp, float brightness, float gamma[3]) +get_coefficient(float coeff[3], int temp, float brightness) { /* Approximate white point */ float white_point[3]; @@ -137,12 +136,24 @@ interpolate_color(alpha, &blackbody_color[temp_index], &blackbody_color[temp_index+3], white_point); + coeff[0] = brightness * white_point[0]; + coeff[1] = brightness * white_point[1]; + coeff[2] = brightness * white_point[2]; +} + +void +colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b, + int size, int temp, float brightness, float gamma[3]) +{ + float coeff[3]; + get_coefficient(coeff, temp, brightness); + for (int i = 0; i < size; i++) { gamma_r[i] = pow((float)i/size, 1.0/gamma[0]) * - UINT16_MAX * brightness * white_point[0]; + UINT16_MAX * coeff[0]; gamma_g[i] = pow((float)i/size, 1.0/gamma[1]) * - UINT16_MAX * brightness * white_point[1]; + UINT16_MAX * coeff[1]; gamma_b[i] = pow((float)i/size, 1.0/gamma[2]) * - UINT16_MAX * brightness * white_point[2]; + UINT16_MAX * coeff[2]; } } diff --exclude='stamp-*' --exclude=po --exclude=.deps --exclude='*.o' --exclude='config.*' --exclude='*~' --exclude=config.h --exclude=autom4te.cache --exclude=Makefile --exclude=configure --exclude='*.m4' --exclude='*.in' -Nur orig/redshift-1.7/src/colorramp.h redshift-1.7/src/colorramp.h --- orig/redshift-1.7/src/colorramp.h 2011-04-20 14:46:21.000000000 -0700 +++ redshift-1.7/src/colorramp.h 2013-09-14 16:16:38.000000000 -0700 @@ -22,6 +22,8 @@ #include +void get_coefficient(float coeff[3], int temp, float brightness); + void colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b, int size, int temp, float brightness, float gamma[3]); diff --exclude='stamp-*' --exclude=po --exclude=.deps --exclude='*.o' --exclude='config.*' --exclude='*~' --exclude=config.h --exclude=autom4te.cache --exclude=Makefile --exclude=configure --exclude='*.m4' --exclude='*.in' -Nur orig/redshift-1.7/src/gamma-quartz.c redshift-1.7/src/gamma-quartz.c --- orig/redshift-1.7/src/gamma-quartz.c 1969-12-31 16:00:00.000000000 -0800 +++ redshift-1.7/src/gamma-quartz.c 2013-09-14 17:07:57.000000000 -0700 @@ -0,0 +1,125 @@ +/* gamma-quartz.c -- Quartz Display Services gamma adjustment source + This file is part of Redshift. + + Redshift is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Redshift is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Redshift. If not, see . + + Copyright (c) 2013 Geoffrey Thomas +*/ + +#include +#include + +#include + +#ifdef ENABLE_NLS +# include +# define _(s) gettext(s) +#else +# define _(s) s +#endif + +#include "gamma-quartz.h" +#include "colorramp.h" + +#define GAMMA_RAMP_SIZE 256 + + +int +quartz_init(quartz_state_t *state) +{ + return 0; +} + +int +quartz_start(quartz_state_t *state) +{ + state->display = kCGDirectMainDisplay; + state->capacity = CGDisplayGammaTableCapacity(state->display); + state->savedRedTable = malloc(sizeof(CGGammaValue) * state->capacity); + state->savedGreenTable = malloc(sizeof(CGGammaValue) * state->capacity); + state->savedBlueTable = malloc(sizeof(CGGammaValue) * state->capacity); + uint32_t sampleCount; + CGGetDisplayTransferByTable(state->display, + state->capacity, + state->savedRedTable, + state->savedGreenTable, + state->savedBlueTable, + &sampleCount); + return 0; +} + +void +quartz_free(quartz_state_t *state) +{ + free(state->savedRedTable); + free(state->savedGreenTable); + free(state->savedBlueTable); +} + + +void +quartz_print_help(FILE *f) +{ + fputs(_("Adjust gamma ramps with Quartz Display Services.\n"), f); + fputs("\n", f); +} + +int +quartz_set_option(quartz_state_t *state, const char *key, const char *value) +{ + return -1; +} + +void +quartz_restore(quartz_state_t *state) +{ + CGSetDisplayTransferByTable(state->display, + state->capacity, + state->savedRedTable, + state->savedGreenTable, + state->savedBlueTable); +} + +int +quartz_set_temperature(quartz_state_t *state, int temp, float brightness, + float gamma[3]) +{ + float coeff[3]; + + CGGammaValue * redTable = malloc(sizeof(CGGammaValue) * state->capacity); + CGGammaValue * greenTable = malloc(sizeof(CGGammaValue) * state->capacity); + CGGammaValue * blueTable = malloc(sizeof(CGGammaValue) * state->capacity); + + get_coefficient(coeff, temp, brightness); + + for (int i = 0; i < state->capacity; i++) { + redTable[i] = state->savedRedTable[i] * coeff[0]; + greenTable[i] = state->savedGreenTable[i] * coeff[1]; + blueTable[i] = state->savedBlueTable[i] * coeff[2]; + } + + CGSetDisplayTransferByTable(state->display, + state->capacity, + redTable, + greenTable, + blueTable); + /* + CGSetDisplayTransferByFormula(state->display, + 0, coeff[0], 1./gamma[0], + 0, coeff[1], 1./gamma[1], + 0, coeff[2], 1./gamma[2]); + */ + + return 0; +} diff --exclude='stamp-*' --exclude=po --exclude=.deps --exclude='*.o' --exclude='config.*' --exclude='*~' --exclude=config.h --exclude=autom4te.cache --exclude=Makefile --exclude=configure --exclude='*.m4' --exclude='*.in' -Nur orig/redshift-1.7/src/gamma-quartz.h redshift-1.7/src/gamma-quartz.h --- orig/redshift-1.7/src/gamma-quartz.h 1969-12-31 16:00:00.000000000 -0800 +++ redshift-1.7/src/gamma-quartz.h 2013-09-14 15:45:26.000000000 -0700 @@ -0,0 +1,47 @@ +/* gamma-quartz.h -- Quartz Display Services adjustment header + This file is part of Redshift. + + Redshift is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Redshift is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Redshift. If not, see . + + Copyright (c) 2013 Geoffrey Thomas +*/ + +#ifndef _REDSHIFT_GAMMA_QUARTZ_H +#define _REDSHIFT_GAMMA_QUARTZ_H + +#include + +typedef struct { + CGDirectDisplayID display; + uint32_t capacity; + CGGammaValue *savedRedTable; + CGGammaValue *savedGreenTable; + CGGammaValue *savedBlueTable; +} quartz_state_t; + + +int quartz_init(quartz_state_t *state); +int quartz_start(quartz_state_t *state); +void quartz_free(quartz_state_t *state); + +void quartz_print_help(FILE *f); +int quartz_set_option(quartz_state_t *state, const char *key, + const char *value); + +void quartz_restore(quartz_state_t *state); +int quartz_set_temperature(quartz_state_t *state, int temp, float brightness, + float gamma[3]); + + +#endif /* ! _REDSHIFT_GAMMA_QUARTZ_H */ Binary files orig/redshift-1.7/src/redshift and redshift-1.7/src/redshift differ diff --exclude='stamp-*' --exclude=po --exclude=.deps --exclude='*.o' --exclude='config.*' --exclude='*~' --exclude=config.h --exclude=autom4te.cache --exclude=Makefile --exclude=configure --exclude='*.m4' --exclude='*.in' -Nur orig/redshift-1.7/src/redshift.c redshift-1.7/src/redshift.c --- orig/redshift-1.7/src/redshift.c 2011-07-04 06:09:01.000000000 -0700 +++ redshift-1.7/src/redshift.c 2013-09-14 15:34:07.000000000 -0700 @@ -53,8 +53,9 @@ #if !(defined(ENABLE_RANDR) || \ defined(ENABLE_VIDMODE) || \ - defined(ENABLE_WINGDI)) -# error "At least one of RANDR, VidMode or WinGDI must be enabled." + defined(ENABLE_WINGDI) || \ + defined(ENABLE_QUARTZ)) +# error "At least one of RANDR, VidMode, WinGDI, or Quartz must be enabled." #endif #ifdef ENABLE_RANDR @@ -69,6 +70,10 @@ # include "gamma-w32gdi.h" #endif +#ifdef ENABLE_QUARTZ +# include "gamma-quartz.h" +#endif + #include "location-manual.h" @@ -92,6 +97,9 @@ #ifdef ENABLE_WINGDI w32gdi_state_t w32gdi; #endif +#ifdef ENABLE_QUARTZ + quartz_state_t quartz; +#endif } gamma_state_t; @@ -133,6 +141,18 @@ (gamma_method_set_temperature_func *)w32gdi_set_temperature }, #endif +#ifdef ENABLE_QUARTZ + { + "quartz", + (gamma_method_init_func *)quartz_init, + (gamma_method_start_func *)quartz_start, + (gamma_method_free_func *)quartz_free, + (gamma_method_print_help_func *)quartz_print_help, + (gamma_method_set_option_func *)quartz_set_option, + (gamma_method_restore_func *)quartz_restore, + (gamma_method_set_temperature_func *)quartz_set_temperature + }, +#endif { NULL } }; diff --exclude='stamp-*' --exclude=po --exclude=.deps --exclude='*.o' --exclude='config.*' --exclude='*~' --exclude=config.h --exclude=autom4te.cache --exclude=Makefile --exclude=configure --exclude='*.m4' --exclude='*.in' -Nur orig/redshift-1.7/src/systemtime.c redshift-1.7/src/systemtime.c --- orig/redshift-1.7/src/systemtime.c 2010-05-06 15:03:01.000000000 -0700 +++ redshift-1.7/src/systemtime.c 2013-09-14 16:36:03.000000000 -0700 @@ -20,7 +20,11 @@ #include #ifndef _WIN32 -# include +# ifndef HAVE_CLOCK_GETTIME +# include +# else +# include +# endif #endif #include "systemtime.h" @@ -29,6 +33,7 @@ systemtime_get_time(double *t) { #ifndef _WIN32 +# ifdef HAVE_CLOCK_GETTIME struct timespec now; int r = clock_gettime(CLOCK_REALTIME, &now); if (r < 0) { @@ -37,6 +42,16 @@ } *t = now.tv_sec + (now.tv_nsec / 1000000000.0); +# else + struct timeval now; + int r = gettimeofday(&now, NULL); + if (r < 0) { + perror("gettimeofday"); + return -1; + } + + *t = now.tv_sec + (now.tv_usec / 1000000.0); +# endif #else /* _WIN32 */ FILETIME now; ULARGE_INTEGER i;