Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

176 wiersze
5.8 KiB

  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. #include "org_zoy_caca_Dither.h"
  14. #include "caca_java_common.h"
  15. #include "caca.h"
  16. JNIEXPORT jlong JNICALL
  17. Java_org_zoy_caca_Dither_createDither(JNIEnv *env, jclass cls, jint bpp, jint w, jint h,
  18. jint pitch, jint rmask, jint gmask, jint bmask, jint amask)
  19. {
  20. caca_dither_t *dither = caca_create_dither(bpp, w, h, pitch, rmask, gmask, bmask, amask);
  21. if(dither == NULL) {
  22. THROW_EX("Cannot create a new Dither");
  23. return 0;
  24. }
  25. return (jlong)dither;
  26. }
  27. JNIEXPORT void JNICALL
  28. Java_org_zoy_caca_Dither_setDitherPalette(JNIEnv *env, jclass vls, jlong ptr, jintArray red,
  29. jintArray green, jintArray blue, jintArray alpha)
  30. {
  31. jint *relems, *gelems, *belems, *aelems;
  32. relems = (*env)->GetIntArrayElements(env, red, 0);
  33. gelems = (*env)->GetIntArrayElements(env, green, 0);
  34. belems = (*env)->GetIntArrayElements(env, blue, 0);
  35. aelems = (*env)->GetIntArrayElements(env, alpha, 0);
  36. caca_set_dither_palette((caca_dither_t *)ptr, relems, gelems, belems, aelems);
  37. (*env)->ReleaseIntArrayElements(env, red, relems, 0);
  38. (*env)->ReleaseIntArrayElements(env, green, gelems, 0);
  39. (*env)->ReleaseIntArrayElements(env, blue, belems, 0);
  40. (*env)->ReleaseIntArrayElements(env, alpha, aelems, 0);
  41. }
  42. JNIEXPORT void JNICALL
  43. Java_org_zoy_caca_Dither_setDitherBrightness(JNIEnv *env, jclass cls, jlong ptr, jfloat v)
  44. {
  45. caca_set_dither_brightness((caca_dither_t *)ptr, v);
  46. }
  47. JNIEXPORT jfloat JNICALL
  48. Java_org_zoy_caca_Dither_getDitherBrightness(JNIEnv *env, jclass cls, jlong ptr)
  49. {
  50. return caca_get_dither_brightness((caca_dither_t *)ptr);
  51. }
  52. JNIEXPORT void JNICALL
  53. Java_org_zoy_caca_Dither_setDitherGamma(JNIEnv *env, jclass cls, jlong ptr, jfloat v)
  54. {
  55. caca_set_dither_gamma((caca_dither_t *)ptr, v);
  56. }
  57. JNIEXPORT jfloat JNICALL
  58. Java_org_zoy_caca_Dither_getDitherGamma(JNIEnv *env, jclass cls, jlong ptr)
  59. {
  60. return caca_get_dither_gamma((caca_dither_t *)ptr);
  61. }
  62. JNIEXPORT void JNICALL
  63. Java_org_zoy_caca_Dither_setDitherContrast(JNIEnv *env, jclass cls, jlong ptr, jfloat v)
  64. {
  65. caca_set_dither_contrast((caca_dither_t *)ptr, v);
  66. }
  67. JNIEXPORT jfloat JNICALL
  68. Java_org_zoy_caca_Dither_getDitherContrast(JNIEnv *env, jclass cls, jlong ptr)
  69. {
  70. return caca_get_dither_contrast((caca_dither_t *)ptr);
  71. }
  72. JNIEXPORT jobjectArray JNICALL
  73. Java_org_zoy_caca_Dither_getDitherAntiAliasingList(JNIEnv *env, jclass cls, jlong ptr)
  74. {
  75. const char *const *antialias_list = caca_get_dither_antialias_list((caca_dither_t *)ptr);
  76. return caca_java_to_string_array(env, antialias_list);
  77. }
  78. JNIEXPORT void JNICALL
  79. Java_org_zoy_caca_Dither_setDitherAntiAliasing(JNIEnv *env, jclass cls, jlong ptr, jstring aa)
  80. {
  81. const char *aa_chars = (*env)->GetStringUTFChars(env, aa, 0);
  82. caca_set_dither_antialias((caca_dither_t *)ptr, aa_chars);
  83. (*env)->ReleaseStringUTFChars(env, aa, aa_chars);
  84. }
  85. JNIEXPORT jstring JNICALL
  86. Java_org_zoy_caca_Dither_getDitherAntiAliasing(JNIEnv *env, jclass cls, jlong ptr)
  87. {
  88. return (*env)->NewStringUTF(env, caca_get_dither_antialias((caca_dither_t *)ptr));
  89. }
  90. JNIEXPORT jobjectArray
  91. JNICALL Java_org_zoy_caca_Dither_getDitherColorList(JNIEnv *env, jclass cls, jlong ptr)
  92. {
  93. const char *const *color_list = caca_get_dither_color_list((caca_dither_t *)ptr);
  94. return caca_java_to_string_array(env, color_list);
  95. }
  96. JNIEXPORT void JNICALL
  97. Java_org_zoy_caca_Dither_setDitherColor(JNIEnv *env, jclass cls, jlong ptr, jstring color)
  98. {
  99. const char *color_chars = (*env)->GetStringUTFChars(env, color, 0);
  100. caca_set_dither_color((caca_dither_t *)ptr, color_chars);
  101. (*env)->ReleaseStringUTFChars(env, color, color_chars);
  102. }
  103. JNIEXPORT jstring JNICALL
  104. Java_org_zoy_caca_Dither_getDitherColor(JNIEnv *env, jclass cls, jlong ptr)
  105. {
  106. return (*env)->NewStringUTF(env, caca_get_dither_color((caca_dither_t *)ptr));
  107. }
  108. JNIEXPORT jobjectArray JNICALL
  109. Java_org_zoy_caca_Dither_getDitherCharsetList(JNIEnv *env, jclass cls, jlong ptr)
  110. {
  111. const char *const *color_list = caca_get_dither_color_list((caca_dither_t *)ptr);
  112. return caca_java_to_string_array(env, color_list);
  113. }
  114. JNIEXPORT void JNICALL
  115. Java_org_zoy_caca_Dither_setDitherCharset(JNIEnv *env, jclass cls, jlong ptr, jstring charset)
  116. {
  117. const char *charset_chars = (*env)->GetStringUTFChars(env, charset, 0);
  118. caca_set_dither_charset((caca_dither_t *)ptr, charset_chars);
  119. (*env)->ReleaseStringUTFChars(env, charset, charset_chars);
  120. }
  121. JNIEXPORT jstring JNICALL
  122. Java_org_zoy_caca_Dither_getDitherCharset(JNIEnv *env, jclass cls, jlong ptr)
  123. {
  124. return (*env)->NewStringUTF(env, caca_get_dither_charset((caca_dither_t *)ptr));
  125. }
  126. JNIEXPORT jobjectArray JNICALL
  127. Java_org_zoy_caca_Dither_getDitherAlgorithmList(JNIEnv *env, jclass cls, jlong ptr)
  128. {
  129. const char *const *algorithm_list = caca_get_dither_algorithm_list((caca_dither_t *)ptr);
  130. return caca_java_to_string_array(env, algorithm_list);
  131. }
  132. JNIEXPORT void JNICALL
  133. Java_org_zoy_caca_Dither_setDitherAlgorithm(JNIEnv *env, jclass cls, jlong ptr, jstring algorithm)
  134. {
  135. const char *algorithm_chars = (*env)->GetStringUTFChars(env, algorithm, 0);
  136. caca_set_dither_algorithm((caca_dither_t *)ptr, algorithm_chars);
  137. (*env)->ReleaseStringUTFChars(env, algorithm, algorithm_chars);
  138. }
  139. JNIEXPORT jstring JNICALL
  140. Java_org_zoy_caca_Dither_getDitherAlgorithm(JNIEnv *env, jclass cls, jlong ptr)
  141. {
  142. return (*env)->NewStringUTF(env, caca_get_dither_algorithm((caca_dither_t *)ptr));
  143. }
  144. JNIEXPORT void JNICALL
  145. Java_org_zoy_caca_Dither_freeDither(JNIEnv *env, jclass cls, jlong ptr)
  146. {
  147. caca_free_dither((caca_dither_t *)ptr);
  148. }