1 | /** |
---|
2 | * libcaca Java bindings for libcaca |
---|
3 | * Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org> |
---|
4 | * |
---|
5 | * $Id$ |
---|
6 | * |
---|
7 | * This library is free software. It comes without any warranty, to |
---|
8 | * the extent permitted by applicable law. You can redistribute it |
---|
9 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
10 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
11 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
12 | */ |
---|
13 | |
---|
14 | #include "org_zoy_caca_Dither.h" |
---|
15 | #include "caca_java_common.h" |
---|
16 | |
---|
17 | #include "caca.h" |
---|
18 | |
---|
19 | JNIEXPORT jlong JNICALL |
---|
20 | Java_org_zoy_caca_Dither_createDither(JNIEnv *env, jclass cls, jint bpp, jint w, jint h, |
---|
21 | jint pitch, jint rmask, jint gmask, jint bmask, jint amask) |
---|
22 | { |
---|
23 | caca_dither_t *dither = caca_create_dither(bpp, w, h, pitch, rmask, gmask, bmask, amask); |
---|
24 | |
---|
25 | if(dither == NULL) { |
---|
26 | THROW_EX("Cannot create a new Dither"); |
---|
27 | return 0; |
---|
28 | } |
---|
29 | |
---|
30 | return (jlong)dither; |
---|
31 | } |
---|
32 | |
---|
33 | JNIEXPORT void JNICALL |
---|
34 | Java_org_zoy_caca_Dither_setDitherPalette(JNIEnv *env, jclass vls, jlong ptr, jintArray red, |
---|
35 | jintArray green, jintArray blue, jintArray alpha) |
---|
36 | { |
---|
37 | jint *relems, *gelems, *belems, *aelems; |
---|
38 | |
---|
39 | relems = (*env)->GetIntArrayElements(env, red, 0); |
---|
40 | gelems = (*env)->GetIntArrayElements(env, green, 0); |
---|
41 | belems = (*env)->GetIntArrayElements(env, blue, 0); |
---|
42 | aelems = (*env)->GetIntArrayElements(env, alpha, 0); |
---|
43 | caca_set_dither_palette((caca_dither_t *)ptr, relems, gelems, belems, aelems); |
---|
44 | (*env)->ReleaseIntArrayElements(env, red, relems, 0); |
---|
45 | (*env)->ReleaseIntArrayElements(env, green, gelems, 0); |
---|
46 | (*env)->ReleaseIntArrayElements(env, blue, belems, 0); |
---|
47 | (*env)->ReleaseIntArrayElements(env, alpha, aelems, 0); |
---|
48 | } |
---|
49 | |
---|
50 | JNIEXPORT void JNICALL |
---|
51 | Java_org_zoy_caca_Dither_setDitherBrightness(JNIEnv *env, jclass cls, jlong ptr, jfloat v) |
---|
52 | { |
---|
53 | caca_set_dither_brightness((caca_dither_t *)ptr, v); |
---|
54 | } |
---|
55 | |
---|
56 | JNIEXPORT jfloat JNICALL |
---|
57 | Java_org_zoy_caca_Dither_getDitherBrightness(JNIEnv *env, jclass cls, jlong ptr) |
---|
58 | { |
---|
59 | return caca_get_dither_brightness((caca_dither_t *)ptr); |
---|
60 | } |
---|
61 | |
---|
62 | JNIEXPORT void JNICALL |
---|
63 | Java_org_zoy_caca_Dither_setDitherGamma(JNIEnv *env, jclass cls, jlong ptr, jfloat v) |
---|
64 | { |
---|
65 | caca_set_dither_gamma((caca_dither_t *)ptr, v); |
---|
66 | } |
---|
67 | |
---|
68 | JNIEXPORT jfloat JNICALL |
---|
69 | Java_org_zoy_caca_Dither_getDitherGamma(JNIEnv *env, jclass cls, jlong ptr) |
---|
70 | { |
---|
71 | return caca_get_dither_gamma((caca_dither_t *)ptr); |
---|
72 | } |
---|
73 | |
---|
74 | JNIEXPORT void JNICALL |
---|
75 | Java_org_zoy_caca_Dither_setDitherContrast(JNIEnv *env, jclass cls, jlong ptr, jfloat v) |
---|
76 | { |
---|
77 | caca_set_dither_contrast((caca_dither_t *)ptr, v); |
---|
78 | } |
---|
79 | |
---|
80 | JNIEXPORT jfloat JNICALL |
---|
81 | Java_org_zoy_caca_Dither_getDitherContrast(JNIEnv *env, jclass cls, jlong ptr) |
---|
82 | { |
---|
83 | return caca_get_dither_contrast((caca_dither_t *)ptr); |
---|
84 | } |
---|
85 | |
---|
86 | JNIEXPORT jobjectArray JNICALL |
---|
87 | Java_org_zoy_caca_Dither_getDitherAntiAliasingList(JNIEnv *env, jclass cls, jlong ptr) |
---|
88 | { |
---|
89 | const char *const *antialias_list = caca_get_dither_antialias_list((caca_dither_t *)ptr); |
---|
90 | return caca_java_to_string_array(env, antialias_list); |
---|
91 | } |
---|
92 | |
---|
93 | JNIEXPORT void JNICALL |
---|
94 | Java_org_zoy_caca_Dither_setDitherAntiAliasing(JNIEnv *env, jclass cls, jlong ptr, jstring aa) |
---|
95 | { |
---|
96 | const char *aa_chars = (*env)->GetStringUTFChars(env, aa, 0); |
---|
97 | caca_set_dither_antialias((caca_dither_t *)ptr, aa_chars); |
---|
98 | (*env)->ReleaseStringUTFChars(env, aa, aa_chars); |
---|
99 | } |
---|
100 | |
---|
101 | JNIEXPORT jstring JNICALL |
---|
102 | Java_org_zoy_caca_Dither_getDitherAntiAliasing(JNIEnv *env, jclass cls, jlong ptr) |
---|
103 | { |
---|
104 | return (*env)->NewStringUTF(env, caca_get_dither_antialias((caca_dither_t *)ptr)); |
---|
105 | } |
---|
106 | |
---|
107 | JNIEXPORT jobjectArray |
---|
108 | JNICALL Java_org_zoy_caca_Dither_getDitherColorList(JNIEnv *env, jclass cls, jlong ptr) |
---|
109 | { |
---|
110 | const char *const *color_list = caca_get_dither_color_list((caca_dither_t *)ptr); |
---|
111 | return caca_java_to_string_array(env, color_list); |
---|
112 | } |
---|
113 | |
---|
114 | JNIEXPORT void JNICALL |
---|
115 | Java_org_zoy_caca_Dither_setDitherColor(JNIEnv *env, jclass cls, jlong ptr, jstring color) |
---|
116 | { |
---|
117 | const char *color_chars = (*env)->GetStringUTFChars(env, color, 0); |
---|
118 | caca_set_dither_color((caca_dither_t *)ptr, color_chars); |
---|
119 | (*env)->ReleaseStringUTFChars(env, color, color_chars); |
---|
120 | } |
---|
121 | |
---|
122 | JNIEXPORT jstring JNICALL |
---|
123 | Java_org_zoy_caca_Dither_getDitherColor(JNIEnv *env, jclass cls, jlong ptr) |
---|
124 | { |
---|
125 | return (*env)->NewStringUTF(env, caca_get_dither_color((caca_dither_t *)ptr)); |
---|
126 | } |
---|
127 | |
---|
128 | JNIEXPORT jobjectArray JNICALL |
---|
129 | Java_org_zoy_caca_Dither_getDitherCharsetList(JNIEnv *env, jclass cls, jlong ptr) |
---|
130 | { |
---|
131 | const char *const *color_list = caca_get_dither_color_list((caca_dither_t *)ptr); |
---|
132 | return caca_java_to_string_array(env, color_list); |
---|
133 | } |
---|
134 | |
---|
135 | JNIEXPORT void JNICALL |
---|
136 | Java_org_zoy_caca_Dither_setDitherCharset(JNIEnv *env, jclass cls, jlong ptr, jstring charset) |
---|
137 | { |
---|
138 | const char *charset_chars = (*env)->GetStringUTFChars(env, charset, 0); |
---|
139 | caca_set_dither_charset((caca_dither_t *)ptr, charset_chars); |
---|
140 | (*env)->ReleaseStringUTFChars(env, charset, charset_chars); |
---|
141 | } |
---|
142 | |
---|
143 | JNIEXPORT jstring JNICALL |
---|
144 | Java_org_zoy_caca_Dither_getDitherCharset(JNIEnv *env, jclass cls, jlong ptr) |
---|
145 | { |
---|
146 | return (*env)->NewStringUTF(env, caca_get_dither_charset((caca_dither_t *)ptr)); |
---|
147 | } |
---|
148 | |
---|
149 | JNIEXPORT jobjectArray JNICALL |
---|
150 | Java_org_zoy_caca_Dither_getDitherAlgorithmList(JNIEnv *env, jclass cls, jlong ptr) |
---|
151 | { |
---|
152 | const char *const *algorithm_list = caca_get_dither_algorithm_list((caca_dither_t *)ptr); |
---|
153 | return caca_java_to_string_array(env, algorithm_list); |
---|
154 | } |
---|
155 | |
---|
156 | JNIEXPORT void JNICALL |
---|
157 | Java_org_zoy_caca_Dither_setDitherAlgorithm(JNIEnv *env, jclass cls, jlong ptr, jstring algorithm) |
---|
158 | { |
---|
159 | const char *algorithm_chars = (*env)->GetStringUTFChars(env, algorithm, 0); |
---|
160 | caca_set_dither_algorithm((caca_dither_t *)ptr, algorithm_chars); |
---|
161 | (*env)->ReleaseStringUTFChars(env, algorithm, algorithm_chars); |
---|
162 | } |
---|
163 | |
---|
164 | JNIEXPORT jstring JNICALL |
---|
165 | Java_org_zoy_caca_Dither_getDitherAlgorithm(JNIEnv *env, jclass cls, jlong ptr) |
---|
166 | { |
---|
167 | return (*env)->NewStringUTF(env, caca_get_dither_algorithm((caca_dither_t *)ptr)); |
---|
168 | } |
---|
169 | |
---|
170 | JNIEXPORT void JNICALL |
---|
171 | Java_org_zoy_caca_Dither_freeDither(JNIEnv *env, jclass cls, jlong ptr) |
---|
172 | { |
---|
173 | caca_free_dither((caca_dither_t *)ptr); |
---|
174 | } |
---|
175 | |
---|