File: Dither.java

package info (click to toggle)
libcaca 0.99.beta18-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,936 kB
  • sloc: ansic: 22,177; python: 2,316; cs: 1,213; cpp: 1,107; java: 916; objc: 836; makefile: 636; sh: 381; ruby: 193; asm: 65
file content (236 lines) | stat: -rw-r--r-- 6,788 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/**
 *  libcaca       Java bindings for libcaca
 *  Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org>
 *
 *  This library is free software. It comes without any warranty, to
 *  the extent permitted by applicable law. You can redistribute it
 *  and/or modify it under the terms of the Do What The Fuck You Want
 *  To Public License, Version 2, as published by Sam Hocevar. See
 *  http://sam.zoy.org/wtfpl/COPYING for more details.
 */

package org.zoy.caca;

public class Dither extends NativeObject {

  static {
    Caca.load();
  }

  private native static long createDither(int bitmapDepth, int weight, int height,
      int pitch, int redMask, int greenMask, int blueMask, int alphaMask);

  public Dither(int bitmapDepth, int weight, int height, int pitch, int redMask,
                int greenMask, int blueMask, int alphaMask) {
    this.ptr = createDither(bitmapDepth, weight, height, pitch, redMask, greenMask,
                            blueMask, alphaMask);
  }

  private static native void setDitherPalette(long ditherPtr, int[] red, int[] green,
                                              int[] blue, int[] alpha);

  public void setPalette(int[] red, int[] green, int[] blue, int[] alpha) {
    if (red.length != 256 ||
        green.length != 256 ||
        blue.length != 256 ||
        alpha.length !=256) {
      throw new IllegalArgumentException("Palette components must have 256 elements");
    }
    setDitherPalette(ptr, red, green, blue, alpha);
  }

  private static native void setDitherBrightness(long ditherPtr, float brightness);

  public void setBrightness(float brightness) {
    setDitherBrightness(ptr, brightness);
  }

  private static native float getDitherBrightness(long ditherPtr);

  public float getBrightness() {
    return getDitherBrightness(ptr);
  }

  private static native void setDitherGamma(long ditherPtr, float gama);

  public void setGamma(float gama) {
    setDitherGamma(ptr, gama);
  }

  private static native float getDitherGamma(long ditherPtr);

  public float getGamma() {
    return getDitherGamma(ptr);
  }

  private static native void setDitherContrast(long ditherPtr, float contrast);

  public void setContrast(float contrast) {
    setDitherContrast(ptr, contrast);
  }

  private static native float getDitherContrast(long ditherPtr);

  public float getContrast() {
    return getDitherContrast(ptr);
  }

  public static class AntiAliasing extends CacaObject {
    public AntiAliasing(String code, String desc) {
      super(code, desc);
    }

    public static AntiAliasing forCode(Dither dither, String code) {
      for (AntiAliasing aa : dither.getAntiAliasingList()) {
        if (aa.code.equals(code)) {
          return aa;
        }
      }
      return null;
    }
  }

  private static native String[] getDitherAntiAliasingList(long ditherPtr);

  public AntiAliasing[] getAntiAliasingList() {
    String[] tmp = getDitherAntiAliasingList(ptr);
    AntiAliasing[] aas;
    aas = new AntiAliasing[tmp.length / 2];
    for (int i = 0; 2*i < tmp.length; i++) {
      aas[i] = new AntiAliasing(tmp[2*i], tmp[2*i+1]);
    }
    return aas;
  }

  private static native void setDitherAntiAliasing(long ditherPtr, String antiAliasing);

  public void setAntiAliasing(AntiAliasing antiAliasing) {
    setDitherAntiAliasing(ptr, antiAliasing.code);
  }

  private static native String getDitherAntiAliasing(long ditherPtr);

  public AntiAliasing getAntiAliasing() {
    return AntiAliasing.forCode(this, getDitherAntiAliasing(ptr));
  }

  public static class Color extends CacaObject {
    public Color(String code, String desc) {
      super(code, desc);
    }
    public static Color forCode(Dither dither, String code) {
      for (Color color : dither.getColorList()) {
        if (color.code.equals(code)) {
          return color;
        }
      }
      return null;
    }
  }

  private static native String[] getDitherColorList(long ditherPtr);

  public Color[] getColorList() {
    String[] tmp = getDitherColorList(ptr);
    Color[] colors = new Color[tmp.length / 2];
    for (int i = 0; 2*i < tmp.length; i++) {
      colors[i] = new Color(tmp[2*i], tmp[2*i+1]);
    }
    return colors;
  }

  private static native void setDitherColor(long ditherPtr, String color);

  public void setColor(Color color) {
    setDitherColor(ptr, color.code);
  }

  private static native String getDitherColor(long ditherPtr);

  public Color getColor() {
    return Color.forCode(this, getDitherColor(ptr));
  }

  public static class Charset extends CacaObject {
    public Charset(String code, String desc) {
      super(code, desc);
    }
    public static Charset forCode(Dither dither, String code) {
      for (Charset charset : dither.getCharsetList()) {
        if (charset.code.equals(code)) {
          return charset;
        }
      }
      return null;
    }
  }

  private static native String[] getDitherCharsetList(long charsetPtr);

  public Charset[] getCharsetList() {
    String[] tmp = getDitherCharsetList(ptr);
    Charset[] charsets = new Charset[tmp.length / 2];
    for (int i = 0; 2*i < tmp.length; i++) {
      charsets[i] = new Charset(tmp[2*i], tmp[2*i+1]);
    }
    return charsets;
  }

  private static native void setDitherCharset(long ditherPtr, String charset);

  public void setCharset(Charset charset) {
    setDitherCharset(ptr, charset.code);
  }

  private static native String getDitherCharset(long ditherPtr);

  public Charset getCharset() {
    return Charset.forCode(this, getDitherCharset(ptr));
  }

  public static class Algorithm extends CacaObject {
    public Algorithm(String code, String desc) {
      super(code, desc);
    }
    public static Algorithm forCode(Dither dither, String code) {
      for (Algorithm algorithm : dither.getAlgorithmList()) {
        if (algorithm.code.equals(code)) {
          return algorithm;
        }
      }
      return null;
    }
  }

  private static native String[] getDitherAlgorithmList(long ditherPtr);

  public Algorithm[] getAlgorithmList() {
    String[] tmp = getDitherAlgorithmList(ptr);
    Algorithm[] result = new Algorithm[tmp.length / 2];
    for (int i = 0; 2*i < tmp.length; i++) {
      result[i] = new Algorithm(tmp[2*i], tmp[2*i+1]);
    }
    return result;
  }

  private static native void setDitherAlgorithm(long ditherPtr, String algorithm);

  public void setAlgorithm(Algorithm algorithm) {
    setDitherAlgorithm(ptr, algorithm.code);
  }

  private static native String getDitherAlgorithm(long ditherPtr);

  public Algorithm getAlgorithm() {
    return Algorithm.forCode(this, getDitherAlgorithm(ptr));
  }

  private static native void freeDither(long ditherPtr);

  @Override
  public void finalize() throws Throwable {
    freeDither(ptr);
    super.finalize();
  }

}