You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

174 lines
5.8 KiB

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