App

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

- File List
- File Members

LUT.java
Go to the documentation of this file.
1 package mhr.appcore.pointops;
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
12 public class LUT {
13
14 //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
15 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
16 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
17
18 //===== FIELDS ==============================================================================================================================//
19 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
20 protected long adress = 0x0;
21 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
22 public static final double opacityAsFul = 0.9999;
23 public static final double opacityAsNone = 0.0001;
24
25 //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
26 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
27
28 @Override
29 protected void finalize() throws Throwable {
30 dispose();
31 super.finalize();
32 }
33
34 protected LUT() {
35
36 }
37
38 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
39
40 public static LUT createEmptyLut() {
41 LUT retVal = new LUT();
42 retVal.adress = createLut();
43 if (retVal.adress == 0) {
44 throw new LUTAllocationException("Could not allocate LUT");
45 }
46 return retVal;
47 }
48
49 public static LUT getBrightnessLut(double bias) throws LUTAllocationException {
50 LUT retVal = new LUT();
51 retVal.adress = createBrightnessLut(bias);
52 if (retVal.adress == 0) {
53 throw new LUTAllocationException("Could not allocate LUT");
54 }
55 return retVal;
56 }
57
58 public static LUT getContrastLut(double bias) throws LUTAllocationException {
59 LUT retVal = new LUT();
60 retVal.adress = createContrastLut(bias);
61 if (retVal.adress == 0) {
62 throw new LUTAllocationException("Could not allocate LUT");
63 }
64 return retVal;
65 }
66
67 public static LUT getGammaLut(double gamma) throws LUTAllocationException {
68 LUT retVal = new LUT();
69 retVal.adress = createGammaLut(gamma);
70 if (retVal.adress == 0) {
71 throw new LUTAllocationException("Could not allocate LUT");
72 }
73 return retVal;
74 }
75
76 public static LUT getCurvesLut(float[][] M, float[][]R, float[][]G, float[][]B, float[][]A ) throws LUTAllocationException {
77 LUT retVal = new LUT();
78 double[][] MM = toDoubleArray(M);
79 double[][] RR = toDoubleArray(R);
80 double[][] GG = toDoubleArray(G);
81 double[][] BB = toDoubleArray(B);
82 double[][] AA = toDoubleArray(A);
83 retVal.adress = createCurvesLut(
84 MM[0], MM[1], MM[0].length,
85 RR[0], RR[1], RR[0].length,
86 GG[0], GG[1], GG[0].length,
87 BB[0], BB[1], BB[0].length,
88 AA[0], AA[1], AA[0].length);
89 if (retVal.adress == 0) {
90 throw new LUTAllocationException("Could not allocate LUT");
91 }
92 return retVal;
93 }
94
95
96 public void dispose() {
97 if (adress != 0) {
98 disposeLut(adress);
99 adress = 0;
100 }
101 }
102
103 //===== METHODS =============================================================================================================================//
104 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
105 protected static double[][] toDoubleArray(float[][] a) {
106 double[][] r = new double[2][a[0].length];
107 for (int i = 0; i < a[0].length; i++) {
108 r[0][i] = a[0][i];
109 r[1][i] = a[1][i];
110 }
111 return r;
112 }
113
114 protected static native long createLut();
115 protected static native int disposeLut(long adress);
116
117 protected static native long createBrightnessLut(double bias);
118 protected static native long createContrastLut(double bias);
119 protected static native long createGammaLut(double gamma);
120 protected static native long createCurvesLut( double[] xM, double[] yM, int cM,
121 double[] xR, double[] yR, int cR,
122 double[] xG, double[] yG, int cG,
123 double[] xB, double[] yB, int cB,
124 double[] xA, double[] yA, int cA);
125
126 protected static native int fillBrightnessLut(long lutAdress, double bias);
127 protected static native int fillContrastLut(long lutAdress, double bias);
128 protected static native int fillGammaLut(long lutAdress, double gamma);
129 protected static native int fillCurvesLut( long lutAdress,
130 double[] xM, double[] yM, int cM,
131 double[] xR, double[] yR, int cR,
132 double[] xG, double[] yG, int cG,
133 double[] xB, double[] yB, int cB,
134 double[] xA, double[] yA, int cA);
135
136
137 protected static native int applyTo(long lutAdress, long dstAdress, int dstTlx, int dstTly, int dstBrX, int dstBrY);
138 protected static native int applyTo(long lutAdress, long dstAdress, int dstTlx, int dstTly, int dstBrX, int dstBrY, double alpha);
139 protected static native int applyTo(long lutAdress, long dstAdress, long mskAdress, int mskTlx, int mskTly, int mskBrx, int mskBry, int mskOrigX, int mskOrigY);
140 protected static native int applyTo(long lutAdress, long dstAdress, long mskAdress, int mskTlx, int mskTly, int mskBrx, int mskBry, int mskOrigX, int mskOrigY, double alpha);
141 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
142
143 public long getAdress() {
144 return adress;
145 }
146
147
148 public int fillBrightnessLut(double bias) throws AlreadyDisposedException {
149 if (adress == 0) {
150 throw new AlreadyDisposedException("LUT was already disposed");
151 }
152 return fillBrightnessLut(adress, bias);
153 }
154
155 public int fillContrastLut(double bias) throws AlreadyDisposedException {
156 if (adress == 0) {
157 throw new AlreadyDisposedException("LUT was already disposed");
158 }
159 return fillContrastLut(adress, bias);
160 }
161 public int fillGammaLut(double gamma) throws AlreadyDisposedException {
162 if (adress == 0) {
163 throw new AlreadyDisposedException("LUT was already disposed");
164 }
165 return fillGammaLut(adress, gamma);
166 }
167
168 public int fillCurvesLut(float[][] M, float[][]R, float[][]G, float[][]B, float[][]A ) throws AlreadyDisposedException {
169 if (adress == 0) {
170 throw new AlreadyDisposedException("LUT was already disposed");
171 }
172 double[][] MM = toDoubleArray(M);
173 double[][] RR = toDoubleArray(R);
174 double[][] GG = toDoubleArray(G);
175 double[][] BB = toDoubleArray(B);
176 double[][] AA = toDoubleArray(A);
177 return fillCurvesLut( adress,
178 MM[0], MM[1], MM[0].length,
179 RR[0], RR[1], RR[0].length,
180 GG[0], GG[1], GG[0].length,
181 BB[0], BB[1], BB[0].length,
182 AA[0], AA[1], AA[0].length);
183 }
184
185
186 public int applyTo(NBitmap dst, Rect dstRect, double opacity) throws IllegalArgumentException, AlreadyDisposedException {
187 if (opacity < opacityAsNone) {
188 return 0;
189 }
190 if (adress == 0) {
191 throw new AlreadyDisposedException("LUT was already disposed");
192 }
193 BitmapInfo dstInfo = dst.getInfo();
194 if (dstInfo.channelCount == ChannelCount.FOUR_CHANNEL) {
195 if (opacity < opacityAsFul) {
196 return applyTo(adress, dst.getAdress(), dstRect.tlx, dstRect.tly, dstRect.brx, dstRect.bry, opacity);
197 } else {
198 return applyTo(adress, dst.getAdress(), dstRect.tlx, dstRect.tly, dstRect.brx, dstRect.bry);
199 }
200 } else {
201 throw new IllegalArgumentException("Operation is not applicable to supplied bitmap.");
202 }
203 }
204
205 public int applyTo(NBitmap dst, NBitmap msk, Rect mskRect, int mskOrigX, int mskOrigY, double opacity) throws IllegalArgumentException, AlreadyDisposedException {
206 if (opacity < opacityAsNone) {
207 return 0;
208 }
209 if (adress == 0) {
210 throw new AlreadyDisposedException("LUT was already disposed");
211 }
212 BitmapInfo dstInfo = dst.getInfo();
213 BitmapInfo mskInfo = msk.getInfo();
214 if (dstInfo.channelCount == ChannelCount.FOUR_CHANNEL && mskInfo.channelCount == ChannelCount.SINGLE_CHANNEL) {
215 if (opacity < opacityAsFul) {
216 return applyTo(adress, dst.getAdress(), msk.getAdress(), mskRect.tlx, mskRect.tly, mskRect.brx, mskRect.bry, mskOrigX, mskOrigY, opacity);
217 } else {
218 return applyTo(adress, dst.getAdress(), msk.getAdress(), mskRect.tlx, mskRect.tly, mskRect.brx, mskRect.bry, mskOrigX, mskOrigY);
219 }
220 } else {
221 throw new IllegalArgumentException("Operation is not applicable to supplied bitmap.");
222 }
223 }
224
225 //===== CALLBACKS ===========================================================================================================================//
226
227
228
229 }