Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

239 строки
6.6 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. package org.zoy.caca;
  14. public class Dither extends NativeObject {
  15. static {
  16. Caca.load();
  17. }
  18. private native static long createDither(int bitmapDepth, int weight, int height,
  19. int pitch, int redMask, int greenMask, int blueMask, int alphaMask);
  20. public Dither(int bitmapDepth, int weight, int height, int pitch, int redMask,
  21. int greenMask, int blueMask, int alphaMask) {
  22. this.ptr = createDither(bitmapDepth, weight, height, pitch, redMask, greenMask,
  23. blueMask, alphaMask);
  24. }
  25. private static native void setDitherPalette(long ditherPtr, int[] red, int[] green,
  26. int[] blue, int[] alpha);
  27. public void setPalette(int[] red, int[] green, int[] blue, int[] alpha) {
  28. if (red.length != 256 ||
  29. green.length != 256 ||
  30. blue.length != 256 ||
  31. alpha.length !=256) {
  32. throw new IllegalArgumentException("Palette components must have 256 elements");
  33. }
  34. setDitherPalette(ptr, red, green, blue, alpha);
  35. }
  36. private static native void setDitherBrightness(long ditherPtr, float brightness);
  37. public void setBrightness(float brightness) {
  38. setDitherBrightness(ptr, brightness);
  39. }
  40. private static native float getDitherBrightness(long ditherPtr);
  41. public float getBrightness() {
  42. return getDitherBrightness(ptr);
  43. }
  44. private static native void setDitherGamma(long ditherPtr, float gama);
  45. public void setGamma(float gama) {
  46. setDitherGamma(ptr, gama);
  47. }
  48. private static native float getDitherGamma(long ditherPtr);
  49. public float getGamma() {
  50. return getDitherGamma(ptr);
  51. }
  52. private static native void setDitherContrast(long ditherPtr, float contrast);
  53. public void setContrast(float contrast) {
  54. setDitherContrast(ptr, contrast);
  55. }
  56. private static native float getDitherContrast(long ditherPtr);
  57. public float getContrast() {
  58. return getDitherContrast(ptr);
  59. }
  60. public static class AntiAliasing extends CacaObject {
  61. public AntiAliasing(String code, String desc) {
  62. super(code, desc);
  63. }
  64. public static AntiAliasing forCode(Dither dither, String code) {
  65. for (AntiAliasing aa : dither.getAntiAliasingList()) {
  66. if (aa.code.equals(code)) {
  67. return aa;
  68. }
  69. }
  70. return null;
  71. }
  72. }
  73. private static native String[] getDitherAntiAliasingList(long ditherPtr);
  74. public AntiAliasing[] getAntiAliasingList() {
  75. String[] tmp = getDitherAntiAliasingList(ptr);
  76. AntiAliasing[] aas;
  77. aas = new AntiAliasing[tmp.length / 2];
  78. for (int i = 0; 2*i < tmp.length; i++) {
  79. aas[i] = new AntiAliasing(tmp[2*i], tmp[2*i+1]);
  80. }
  81. return aas;
  82. }
  83. private static native void setDitherAntiAliasing(long ditherPtr, String antiAliasing);
  84. public void setAntiAliasing(AntiAliasing antiAliasing) {
  85. setDitherAntiAliasing(ptr, antiAliasing.code);
  86. }
  87. private static native String getDitherAntiAliasing(long ditherPtr);
  88. public AntiAliasing getAntiAliasing() {
  89. return AntiAliasing.forCode(this, getDitherAntiAliasing(ptr));
  90. }
  91. public static class Color extends CacaObject {
  92. public Color(String code, String desc) {
  93. super(code, desc);
  94. }
  95. public static Color forCode(Dither dither, String code) {
  96. for (Color color : dither.getColorList()) {
  97. if (color.code.equals(code)) {
  98. return color;
  99. }
  100. }
  101. return null;
  102. }
  103. }
  104. private static native String[] getDitherColorList(long ditherPtr);
  105. public Color[] getColorList() {
  106. String[] tmp = getDitherColorList(ptr);
  107. Color[] colors = new Color[tmp.length / 2];
  108. for (int i = 0; 2*i < tmp.length; i++) {
  109. colors[i] = new Color(tmp[2*i], tmp[2*i+1]);
  110. }
  111. return colors;
  112. }
  113. private static native void setDitherColor(long ditherPtr, String color);
  114. public void setColor(Color color) {
  115. setDitherColor(ptr, color.code);
  116. }
  117. private static native String getDitherColor(long ditherPtr);
  118. public Color getColor() {
  119. return Color.forCode(this, getDitherColor(ptr));
  120. }
  121. public static class Charset extends CacaObject {
  122. public Charset(String code, String desc) {
  123. super(code, desc);
  124. }
  125. public static Charset forCode(Dither dither, String code) {
  126. for (Charset charset : dither.getCharsetList()) {
  127. if (charset.code.equals(code)) {
  128. return charset;
  129. }
  130. }
  131. return null;
  132. }
  133. }
  134. private static native String[] getDitherCharsetList(long charsetPtr);
  135. public Charset[] getCharsetList() {
  136. String[] tmp = getDitherCharsetList(ptr);
  137. Charset[] charsets = new Charset[tmp.length / 2];
  138. for (int i = 0; 2*i < tmp.length; i++) {
  139. charsets[i] = new Charset(tmp[2*i], tmp[2*i+1]);
  140. }
  141. return charsets;
  142. }
  143. private static native void setDitherCharset(long ditherPtr, String charset);
  144. public void setCharset(Charset charset) {
  145. setDitherCharset(ptr, charset.code);
  146. }
  147. private static native String getDitherCharset(long ditherPtr);
  148. public Charset getCharset() {
  149. return Charset.forCode(this, getDitherCharset(ptr));
  150. }
  151. public static class Algorithm extends CacaObject {
  152. public Algorithm(String code, String desc) {
  153. super(code, desc);
  154. }
  155. public static Algorithm forCode(Dither dither, String code) {
  156. for (Algorithm algorithm : dither.getAlgorithmList()) {
  157. if (algorithm.code.equals(code)) {
  158. return algorithm;
  159. }
  160. }
  161. return null;
  162. }
  163. }
  164. private static native String[] getDitherAlgorithmList(long ditherPtr);
  165. public Algorithm[] getAlgorithmList() {
  166. String[] tmp = getDitherAlgorithmList(ptr);
  167. Algorithm[] result = new Algorithm[tmp.length / 2];
  168. for (int i = 0; 2*i < tmp.length; i++) {
  169. result[i] = new Algorithm(tmp[2*i], tmp[2*i+1]);
  170. }
  171. return result;
  172. }
  173. private static native void setDitherAlgorithm(long ditherPtr, String algorithm);
  174. public void setAlgorithm(Algorithm algorithm) {
  175. setDitherAlgorithm(ptr, algorithm.code);
  176. }
  177. private static native String getDitherAlgorithm(long ditherPtr);
  178. public Algorithm getAlgorithm() {
  179. return Algorithm.forCode(this, getDitherAlgorithm(ptr));
  180. }
  181. private static native void freeDither(long ditherPtr);
  182. @Override
  183. public void finalize() throws Throwable {
  184. freeDither(ptr);
  185. super.finalize();
  186. }
  187. }