/***
  This file is part of monadjust.

  Copyright 2008 Pierre Ossman <drzeus@drzeus.cx>

  Monadjust is free software; you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  Monadjust 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 Lesser General Public License
  along with PulseAudio; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA.
***/

#include <stdio.h>
#include <errno.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/xf86vmode.h>
#include <ctype.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
	Display *dpy;
	/* one LUT for each output colour channel */
	unsigned short lut[256];
	unsigned short red[256], green[256], blue[256];
	int k;
	int screen;

	if (argc != 257) {
		fprintf(stderr, "invalid syntax\n");
		return -1;
	}
	
	dpy = XOpenDisplay(NULL);
	screen = DefaultScreen(dpy);

	for (k = 0;k < 256;k++)
		lut[k] = atoi(argv[k + 1]) * 256;

	XF86VidModeSetGammaRamp(dpy, screen, 256, lut, lut, lut);

	XCloseDisplay(dpy);

	return 0;
}

