source: libcaca/trunk/java/org_zoy_caca_Dither.c @ 4197

Last change on this file since 4197 was 4197, checked in by Sam Hocevar, 10 years ago

Java bindings, courtesy of Adrien Grand <jpountz@dinauz.org>.

File size: 5.8 KB
Line 
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
19JNIEXPORT jlong JNICALL
20Java_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
33JNIEXPORT void JNICALL
34Java_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
50JNIEXPORT void JNICALL
51Java_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
56JNIEXPORT jfloat JNICALL
57Java_org_zoy_caca_Dither_getDitherBrightness(JNIEnv *env, jclass cls, jlong ptr)
58{
59  return caca_get_dither_brightness((caca_dither_t *)ptr);
60}
61
62JNIEXPORT void JNICALL
63Java_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
68JNIEXPORT jfloat JNICALL
69Java_org_zoy_caca_Dither_getDitherGamma(JNIEnv *env, jclass cls, jlong ptr)
70{
71  return caca_get_dither_gamma((caca_dither_t *)ptr);
72}
73
74JNIEXPORT void JNICALL
75Java_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
80JNIEXPORT jfloat JNICALL
81Java_org_zoy_caca_Dither_getDitherContrast(JNIEnv *env, jclass cls, jlong ptr)
82{
83  return caca_get_dither_contrast((caca_dither_t *)ptr);
84}
85
86JNIEXPORT jobjectArray JNICALL
87Java_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
93JNIEXPORT void JNICALL
94Java_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
101JNIEXPORT jstring JNICALL
102Java_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
107JNIEXPORT jobjectArray
108JNICALL 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
114JNIEXPORT void JNICALL
115Java_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
122JNIEXPORT jstring JNICALL
123Java_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
128JNIEXPORT jobjectArray JNICALL
129Java_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
135JNIEXPORT void JNICALL
136Java_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
143JNIEXPORT jstring JNICALL
144Java_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
149JNIEXPORT jobjectArray JNICALL
150Java_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
156JNIEXPORT void JNICALL
157Java_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
164JNIEXPORT jstring JNICALL
165Java_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
170JNIEXPORT void JNICALL
171Java_org_zoy_caca_Dither_freeDither(JNIEnv *env, jclass cls, jlong ptr)
172{
173  caca_free_dither((caca_dither_t *)ptr);
174}
175
Note: See TracBrowser for help on using the repository browser.