aboutsummaryrefslogtreecommitdiffstats
path: root/Test.java
blob: ad8c607f90a77804637b0cf31778958018bbca3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* See LICENSE file for copyright and license details. */
import libgamma.*;


/**
 * jlibgamma interactive test class
 */
public class Test
{
	public static void p(boolean text)  { System.out.println(text); }
	public static void p(byte    text)  { System.out.println(text); }
	public static void p(short   text)  { System.out.println(text); }
	public static void p(int     text)  { System.out.println(text); }
	public static void p(long    text)  { System.out.println(text); }
	public static void p(char    text)  { System.out.println(text); }
	public static void p(String  text)  { System.out.println(text); }
	public static void p(Object  text)  { System.out.println(text); }
	public static void p()              { System.out.println();     }

	public static void P(boolean text)  { System.out.print(text + " "); }
	public static void P(byte    text)  { System.out.print(text + " "); }
	public static void P(short   text)  { System.out.print(text + " "); }
	public static void P(int     text)  { System.out.print(text + " "); }
	public static void P(long    text)  { System.out.print(text + " "); }
	public static void P(char    text)  { System.out.print(text + " "); }
	public static void P(String  text)  { System.out.print(text + " "); }
	public static void P(Object  text)  { System.out.print(text + " "); }


	/**
	 * Main test function
	 * 
	 * @param  args  Command line arguments, excluding $0
	 */
	public static void main(String[] args) throws LibgammaException
	{
		p(LibgammaException.name_of_error(-3));
		p(LibgammaException.value_of_error("LIBGAMMA_NO_SUCH_SITE"));
		p();

		LibgammaException err = new LibgammaException(LibgammaException.LIBGAMMA_DEVICE_REQUIRE_GROUP);
		p(err.error_code);
		p(err.group_gid);
		p(err.group_name);
		p(err.string);
		err = new LibgammaException(5);
		p(err.string);
		p(err);
		p();

		for (AdjustmentMethod method : AdjustmentMethod.list_methods(0))  P(method.value);  p();
		for (AdjustmentMethod method : AdjustmentMethod.list_methods(1))  P(method.value);  p();
		for (AdjustmentMethod method : AdjustmentMethod.list_methods(2))  P(method.value);  p();
		for (AdjustmentMethod method : AdjustmentMethod.list_methods(3))  P(method.value);  p();
		for (AdjustmentMethod method : AdjustmentMethod.list_methods(4))  P(method.value);  p();
		p();

		AdjustmentMethod method = AdjustmentMethod.list_methods(0)[0];
		p(method);
		p(SubpixelOrder.HORIZONTAL_RGB);
		p(ConnectorType.VGA);
		p();

		p(AdjustmentMethod.X_RANDR.is_available());
		p(AdjustmentMethod.X_RANDR.get_default_site());
		p(AdjustmentMethod.X_RANDR.get_default_site_variable());
		p();

		for (byte b : CRTCInformation.unhex("0123456789abcdef"))
			P(b & 255);
		p();
		p(CRTCInformation.behex(CRTCInformation.unhex("0123456789abcdef")));
		p();

		Site site = new Site(method, ":0");
		p(site.partitions_available);
		p(site);
		Partition partition = new Partition(site, 0);
		p(partition.crtcs_available);
		p(partition);
		CRTC crtc = new CRTC(partition, 0);
		p(crtc);
		p();

		CRTCInformation info = crtc.get_information(~0);
		p(info);
		p();

		AdjustmentMethodCapabilities caps = method.get_capabilities();
		p(caps);
		p();

		GammaRamps<Ramp16> ramps = new GammaRamps<Ramp16>(info.red_gamma_size,
		                                                  info.green_gamma_size,
		                                                  info.blue_gamma_size,
		                                                  16);

		int[] saved_red = new int[ramps.red.size];
		int[] saved_green = new int[ramps.green.size];
		int[] saved_blue = new int[ramps.blue.size];

		crtc.get_gamma(ramps);

		for (int i = 0; i < ramps.red.size; i++) {
			P(ramps.red.get(i));
			ramps.red.set(i, (saved_red[i] = ramps.red.get(i)) / 2);
		}
		p();
		p();
		for (int i = 0; i < ramps.green.size; i++) {
			P(ramps.green.get(i));
			ramps.green.set(i, (saved_green[i] = ramps.green.get(i)) / 2);
		}
		p();
		p();
		for (int i = 0; i < ramps.blue.size; i++) {
			P(ramps.blue.get(i));
			ramps.blue.set(i, (saved_blue[i] = ramps.blue.get(i)) / 2);
		}
		p();
		p();

		crtc.set_gamma(ramps);

		try {
			Thread.sleep(1000);
		} catch (InterruptedException _error) {
			/* ignore. */
		}

		for (int i = 0; i < ramps.red.  size; i++)  ramps.red.  set(i, saved_red[i]);
		for (int i = 0; i < ramps.green.size; i++)  ramps.green.set(i, saved_green[i]);
		for (int i = 0; i < ramps.blue. size; i++)  ramps.blue. set(i, saved_blue[i]);

		crtc.set_gamma(ramps);

		ramps.close();
		crtc.close();
		partition.close();
		site.close();

		try {
			throw new LibgammaException(0);
		} catch (LibgammaException error) {
			p(error);
		}
	}
}