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

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

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

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