diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-09-05 04:51:49 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-09-05 04:51:49 +0200 |
commit | 237bedc5e228e6b06f53762c65c638789c2d29e7 (patch) | |
tree | ff93f936ff9d34110c4f778c49443d2cb08fb86a | |
parent | m (diff) | |
download | jlibgamma-237bedc5e228e6b06f53762c65c638789c2d29e7.tar.gz jlibgamma-237bedc5e228e6b06f53762c65c638789c2d29e7.tar.bz2 jlibgamma-237bedc5e228e6b06f53762c65c638789c2d29e7.tar.xz |
add test and fix some small errors
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r-- | src/Test.java | 131 | ||||
-rw-r--r-- | src/libgamma/CRTC.java | 4 | ||||
-rw-r--r-- | src/libgamma/GammaRamps.java | 15 |
3 files changed, 146 insertions, 4 deletions
diff --git a/src/Test.java b/src/Test.java index 6002543..e42971f 100644 --- a/src/Test.java +++ b/src/Test.java @@ -23,14 +23,141 @@ import libgamma.*; */ 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) + public static void main(String[] args) throws LibgammaException { - System.out.println(AdjustmentMethod.X_RANDR.is_available()); + 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); + } } } diff --git a/src/libgamma/CRTC.java b/src/libgamma/CRTC.java index 15a0672..5bbb445 100644 --- a/src/libgamma/CRTC.java +++ b/src/libgamma/CRTC.java @@ -109,7 +109,7 @@ public class CRTC * * @param output The gamma ramp structure to fill. */ - public void get_gamma(GammaRamps<Ramp> output) throws LibgammaException + public <T extends Ramp> void get_gamma(GammaRamps<T> output) throws LibgammaException { int r = 0; if (output.depth == 8) r = libgamma_crtc_get_gamma_ramps8(this.address, output.address); @@ -127,7 +127,7 @@ public class CRTC * * @param values The gamma ramps to apply. */ - public void set_gamma(GammaRamps<Ramp> values) throws LibgammaException + public <T extends Ramp> void set_gamma(GammaRamps<T> values) throws LibgammaException { int r = 0; if (values.depth == 8) r = libgamma_crtc_set_gamma_ramps8(this.address, values.address); diff --git a/src/libgamma/GammaRamps.java b/src/libgamma/GammaRamps.java index 35f9d4b..61352e2 100644 --- a/src/libgamma/GammaRamps.java +++ b/src/libgamma/GammaRamps.java @@ -54,6 +54,21 @@ public class GammaRamps<T extends Ramp> * -1 for single precision floating point, and -2 for * double precision floating point. */ + public GammaRamps(int red_size, int green_size, int blue_size, int depth) throws LibgammaException + { + this(red_size, green_size, blue_size, (short)depth); + } + + /** + * Constructor. + * + * @param red_size The size of the encoding axis of the red gamma ramp. + * @param green_size The size of the encoding axis of the green gamma ramp. + * @param blue_size The size of the encoding axis of the blue gamma ramp. + * @param depth The bit-depth of the value axes of gamma ramps, + * -1 for single precision floating point, and -2 for + * double precision floating point. + */ @SuppressWarnings("unchecked") public GammaRamps(int red_size, int green_size, int blue_size, short depth) throws LibgammaException { |