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