App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

Filter.java
Go to the documentation of this file.
1 package mhr.appcore.filters;
2
3 import android.location.Address;
4 import android.nfc.NfcAdapter.CreateBeamUrisCallback;
5 import mhr.appcore.bitmap.BitmapInfo;
6 import mhr.appcore.bitmap.ChannelCount;
7 import mhr.appcore.bitmap.NBitmap;
8 import mhr.appcore.exceptions.AlreadyDisposedException;
9 import mhr.appcore.utils.NotImplementedException;
10 import mhr.appcore.utils.Rect;
11
15 public class Filter {
16
17 //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
18 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
19 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
20
21 //===== FIELDS ==============================================================================================================================//
22 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
23 protected long adress = 0x0;
24 protected int extraMargin;
25 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
26 public static final double opacityAsFul = 0.9999;
27 public static final double opacityAsNone = 0.0001;
28
29 //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
30 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
31
32 @Override
33 protected void finalize() throws Throwable {
34 dispose();
35 super.finalize();
36 }
37
38
39 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
43 public Filter() {
44 extraMargin = 0;
45 }
46
54 public synchronized int makeGaussianBlurFilter(double xSigma, double ySigma) throws FilterAllocationException {
55 if (adress != 0) {
56 disposeFilter(adress);
57 adress = 0;
58 extraMargin = 0;
59 }
60 adress = createGaussianBlurFilter(xSigma, ySigma);
61
62 if (adress == 0) {
63 throw new FilterAllocationException("Could not allocate filter");
64 }
65 extraMargin = Math.max((int)(3 * xSigma), (int)(3 * ySigma));
66 return 0;
67 }
68
75 public synchronized int makeLaplaceSharpenFilter(double force) throws FilterAllocationException {
76 if (adress != 0) {
77 disposeFilter(adress);
78 adress = 0;
79 extraMargin = 0;
80 }
81 adress = createLaplaceSharpenFilter(force);
82
83 if (adress == 0) {
84 throw new FilterAllocationException("Could not allocate filter");
85 }
86 extraMargin = 3;
87 return 0;
88 }
89
97 public synchronized int makeGaussianSharpenFilter(double sigma, double force) throws FilterAllocationException {
98 if (adress != 0) {
99 disposeFilter(adress);
100 adress = 0;
101 extraMargin = 0;
102 }
103 adress = createGaussianSharpenFilter(sigma, force);
104
105 if (adress == 0) {
106 throw new FilterAllocationException("Could not allocate filter");
107 }
108 extraMargin = (int)(3 * sigma);
109 return 0;
110 }
111
120 public synchronized int makeLaplacianOfGaussianSharpenFilter(double sigma, double force, boolean area) throws FilterAllocationException {
121 if (adress != 0) {
122 disposeFilter(adress);
123 adress = 0;
124 extraMargin = 0;
125 }
126 adress = createLaplacianOfGaussianSharpenFilter(sigma, force, area);
127
128 if (adress == 0) {
129 throw new FilterAllocationException("Could not allocate filter");
130 }
131 extraMargin = (int)(3 * sigma);
132 return 0;
133 }
134
144 public synchronized int makeDifferenceOfGaussianSharpenFilter(double sigma, double k, double force, boolean area) throws FilterAllocationException {
145 if (adress != 0) {
146 disposeFilter(adress);
147 adress = 0;
148 extraMargin = 0;
149 }
150 adress = createDifferenceOfGaussianSharpenFilter(sigma, k, force, area);
151
152 if (adress == 0) {
153 throw new FilterAllocationException("Could not allocate filter");
154 }
155 extraMargin = (int)(3 * sigma);
156 return 0;
157 }
158
162 public synchronized void dispose() {
163 if (adress != 0) {
164 disposeFilter(adress);
165 adress = 0;
166 extraMargin = 0;
167 }
168 }
169
170 //===== METHODS =============================================================================================================================//
171 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
172 protected static native int disposeFilter(long adress);
173
174 protected static native long createGaussianBlurFilter(double xSigma, double ySigma);
175 protected static native long createLaplaceSharpenFilter(double force);
176 protected static native long createGaussianSharpenFilter(double sigma, double force);
177 protected static native long createLaplacianOfGaussianSharpenFilter(double sigma, double force, boolean area);
178 protected static native long createDifferenceOfGaussianSharpenFilter(double sigma, double k, double force, boolean area);
179
180 protected static native int applyTo(long filterAdress, long dstAdress, int dstTlx, int dstTly, int dstBrX, int dstBrY);
181 protected static native int applyTo(long filterAdress, long dstAdress, int dstTlx, int dstTly, int dstBrX, int dstBrY, double alpha);
182 protected static native int applyTo(long filterAdress, long dstAdress, long mskAdress, int mskTlx, int mskTly, int mskBrx, int mskBry, int mskOrigX, int mskOrigY);
183 protected static native int applyTo(long filterAdress, long dstAdress, long mskAdress, int mskTlx, int mskTly, int mskBrx, int mskBry, int mskOrigX, int mskOrigY, double alpha);
184 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
185
190 public synchronized int getExtraMargin() {
191 return extraMargin;
192 }
193
202 public synchronized int applyTo(NBitmap dst, Rect dstRect, double opacity) throws IllegalArgumentException {
203 if (opacity < opacityAsNone) {
204 return 0;
205 }
206 if (adress == 0) {
207 return 1000;
208 }
209 BitmapInfo dstInfo = dst.getInfo();
210 if (dstInfo.channelCount == ChannelCount.FOUR_CHANNEL) {
211 if (opacity < opacityAsFul) {
212 return applyTo(adress, dst.getAdress(), dstRect.tlx, dstRect.tly, dstRect.brx, dstRect.bry, opacity);
213 } else {
214 return applyTo(adress, dst.getAdress(), dstRect.tlx, dstRect.tly, dstRect.brx, dstRect.bry);
215 }
216 } else {
217 throw new IllegalArgumentException("Operation is not applicable to supplied bitmap.");
218 }
219 }
220
232 public synchronized int applyTo(NBitmap dst, NBitmap msk, Rect mskRect, int mskOrigX, int mskOrigY, double opacity) throws IllegalArgumentException {
233 if (opacity < opacityAsNone) {
234 return 0;
235 }
236 if (adress == 0) {
237 return 1000;
238 }
239 BitmapInfo dstInfo = dst.getInfo();
240 BitmapInfo mskInfo = msk.getInfo();
241 if (dstInfo.channelCount == ChannelCount.FOUR_CHANNEL && mskInfo.channelCount == ChannelCount.SINGLE_CHANNEL) {
242 if (opacity < opacityAsFul) {
243 return applyTo(adress, dst.getAdress(), msk.getAdress(), mskRect.tlx, mskRect.tly, mskRect.brx, mskRect.bry, mskOrigX, mskOrigY, opacity);
244 } else {
245 return applyTo(adress, dst.getAdress(), msk.getAdress(), mskRect.tlx, mskRect.tly, mskRect.brx, mskRect.bry, mskOrigX, mskOrigY);
246 }
247 } else {
248 throw new IllegalArgumentException("Operation is not applicable to supplied bitmap.");
249 }
250 }
251
252 //===== CALLBACKS ===========================================================================================================================//
253
254
255
256 }