gvsig-raster / org.gvsig.raster.ermapper / trunk / org.gvsig.raster.ermapper / org.gvsig.raster.ermapper.jni / src / main / java / com / ermapper / ecw / JNCSFile.java @ 2449
History | View | Annotate | Download (13 KB)
1 |
// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
|
---|---|
2 |
// Jad home page: http://www.kpdus.com/jad.html
|
3 |
// Decompiler options: packimports(3)
|
4 |
// Source File Name: JNCSFile.java
|
5 |
// [01] 01-Oct-2005 nbt New call to JNI function ECWOpenArray to convert name string to char array.
|
6 |
|
7 |
package com.ermapper.ecw; |
8 |
|
9 |
import com.ermapper.util.JNCSDatasetPoint; |
10 |
import com.ermapper.util.JNCSWorldPoint; |
11 |
import java.io.FileInputStream; |
12 |
import java.io.PrintStream; |
13 |
import java.lang.reflect.Field; |
14 |
import java.lang.reflect.Method; |
15 |
import java.util.Properties; |
16 |
|
17 |
// Referenced classes of package com.ermapper.ecw:
|
18 |
// JNCSNativeLibraryException, JNCSFileOpenFailedException, JNCSInvalidSetViewException, JNCSException,
|
19 |
// JNCSFileNotOpenException, JNCSProgressiveUpdate
|
20 |
|
21 |
/**
|
22 |
* Clase que representa a un fichero Ecw
|
23 |
*/
|
24 |
|
25 |
public class JNCSFile |
26 |
implements JNCSProgressiveUpdate
|
27 |
{ |
28 |
|
29 |
private native int ECWOpen(String s, boolean flag); |
30 |
|
31 |
private native int ECWOpenArray(String s, boolean flag, byte[] b); |
32 |
|
33 |
private native void ECWClose(boolean flag); |
34 |
|
35 |
private native int ECWSetView(int i, int ai[], int j, int k, int l, int i1, double d, double d1, double d2, double d3, |
36 |
int j1, int k1); |
37 |
|
38 |
private native int ECWReadLineRGBA(int ai[]); |
39 |
|
40 |
private native int ECWReadImageRGBA(int ai[], int i, int j); |
41 |
|
42 |
private native short ECWGetPercentComplete(); |
43 |
|
44 |
private static native String ECWGetErrorString(int i); |
45 |
|
46 |
private static native int NCSJNIInit(); |
47 |
|
48 |
private static native String ECWGetLibVersion(); |
49 |
|
50 |
/**
|
51 |
* Carga la libreria libecw.so que contiene el wrapper y llama a la
|
52 |
* funci�n de inicializaci�n
|
53 |
* @throws JNCSNativeLibraryException
|
54 |
*/
|
55 |
|
56 |
static void initClass() |
57 |
throws JNCSNativeLibraryException
|
58 |
{ |
59 |
boolean flag = false; |
60 |
boolean flag1 = false; |
61 |
|
62 |
|
63 |
try
|
64 |
{ |
65 |
System.loadLibrary("jecw2.0.0"); |
66 |
bUseNativeMethods = true;
|
67 |
bUnsatisfiedLink = false;
|
68 |
int i = NCSJNIInit();
|
69 |
if(i != 0) |
70 |
{ |
71 |
System.err.println("JNCSFile classes found on PATH failed to initialize correctly. Attempting to locate other libecw.so...."); |
72 |
} |
73 |
} |
74 |
catch(Exception e) |
75 |
{ |
76 |
e.printStackTrace(); |
77 |
} |
78 |
} |
79 |
|
80 |
/**
|
81 |
* Constructor
|
82 |
* @throws JNCSException
|
83 |
*/
|
84 |
|
85 |
public JNCSFile()
|
86 |
throws JNCSException
|
87 |
{ |
88 |
bSetViewIsWorld = false;
|
89 |
progImageClient = null;
|
90 |
initClass(); |
91 |
cellSizeUnits = 0;
|
92 |
bIsOpen = false;
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Constructor con open del fichero.
|
97 |
* @throws JNCSException
|
98 |
*/
|
99 |
|
100 |
public JNCSFile(String s, boolean flag) |
101 |
throws JNCSException
|
102 |
{ |
103 |
bSetViewIsWorld = false;
|
104 |
progImageClient = null;
|
105 |
initClass(); |
106 |
open(s, flag); |
107 |
} |
108 |
|
109 |
/**
|
110 |
* Llama al close del ecw para liberar la memoria de C.
|
111 |
* @throws Throwable
|
112 |
*/
|
113 |
|
114 |
protected void finalize() |
115 |
throws Throwable |
116 |
{ |
117 |
if(bIsOpen)
|
118 |
ECWClose(false);
|
119 |
super.finalize();
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* Abre el fichero de imagen.
|
124 |
* @throws JNCSFileOpenFailedException
|
125 |
*/
|
126 |
|
127 |
public int open(String s, boolean flag) |
128 |
throws JNCSFileOpenFailedException
|
129 |
{ |
130 |
if(s == null) |
131 |
throw new IllegalArgumentException(); |
132 |
|
133 |
//int i = ECWOpen(s, flag);
|
134 |
int i = ECWOpenArray(s, flag, s.getBytes());
|
135 |
|
136 |
if(i != 0) |
137 |
{ |
138 |
bIsOpen = false;
|
139 |
String s1 = JNCSError.getError(i);
|
140 |
throw new JNCSFileOpenFailedException(s1); |
141 |
} else
|
142 |
{ |
143 |
bIsOpen = true;
|
144 |
progressive = flag; |
145 |
return 0; |
146 |
} |
147 |
} |
148 |
|
149 |
/**
|
150 |
* Cierra el fichero de imagen.
|
151 |
* @param flag par�metro para la funci�n NCScbmCloseFileViewEx
|
152 |
*/
|
153 |
|
154 |
public void close(boolean flag) |
155 |
{ |
156 |
ECWClose(flag); |
157 |
if(!flag);
|
158 |
} |
159 |
|
160 |
public void addProgressiveUpdateListener(JNCSProgressiveUpdate jncsprogressiveupdate) |
161 |
{ |
162 |
progImageClient = jncsprogressiveupdate; |
163 |
} |
164 |
|
165 |
public void refreshUpdate(int i, int j, double d, double d1, double d2, double d3) |
166 |
{ |
167 |
if(progImageClient != null) |
168 |
progImageClient.refreshUpdate(i, j, d, d1, d2, d3); |
169 |
} |
170 |
|
171 |
public void refreshUpdate(int i, int j, int k, int l, int i1, int j1) |
172 |
{ |
173 |
if(progImageClient != null) |
174 |
progImageClient.refreshUpdate(i, j, k, l, i1, j1); |
175 |
} |
176 |
|
177 |
/**
|
178 |
* Crea una vista en un fichero ecw abierto dando las coordenadas de la vista
|
179 |
* @param nBands N�mero de bandas en bandList
|
180 |
* @param bandList Array de �ndices de bandas
|
181 |
* @param width ancho de la vista en pixels
|
182 |
* @param height alto de la vista en pixels
|
183 |
* @param tlx coordenada X arriba-izquierda de la vista
|
184 |
* @param tly coordenada Y arriba-izquierda de la vista
|
185 |
* @param brx coordenada X abajo-derecha de la vista
|
186 |
* @param bry coordenada Y abajo-derecha de la vista
|
187 |
* @throws JNCSFileNotOpenException, JNCSInvalidSetViewException
|
188 |
*/
|
189 |
|
190 |
public int setView(int i, int ai[], int j, int k, int l, int i1, int j1, |
191 |
int k1)
|
192 |
throws JNCSFileNotOpenException, JNCSInvalidSetViewException
|
193 |
{ |
194 |
if(!bIsOpen)
|
195 |
throw new JNCSFileNotOpenException("File not open"); |
196 |
|
197 |
if (ai == null) |
198 |
throw new JNCSInvalidSetViewException("Wrong parameter value"); |
199 |
|
200 |
|
201 |
int l1 = ECWSetView(i, ai, j, k, l, i1, 0.0D, 0.0D, 0.0D, 0.0D, j1, k1); |
202 |
if(l1 != 0) |
203 |
{ |
204 |
//String s = ECWGetErrorString(l1);
|
205 |
String s = JNCSError.getError(l1);
|
206 |
throw new JNCSInvalidSetViewException(s); |
207 |
} else
|
208 |
{ |
209 |
bSetViewIsWorld = false;
|
210 |
return 0; |
211 |
} |
212 |
} |
213 |
|
214 |
/**
|
215 |
* Asigna la vista pasando por par�metros los pixeles de inicio y fin y coordenadas de georreferenciaci�n solicitadas-
|
216 |
* El cliente de esta funci�n tendr� que convertir las coordenadas reales en pixeles.
|
217 |
*/
|
218 |
public int setView(int nBands, int posBands[], int iniX, int iniY, int endX, int endY, double tlX, double tlY, double brX, double brY, |
219 |
int bufW, int bufH)throws JNCSFileNotOpenException, JNCSInvalidSetViewException{ |
220 |
|
221 |
if(!bIsOpen)
|
222 |
throw new JNCSFileNotOpenException("File not open"); |
223 |
|
224 |
if (posBands == null) |
225 |
throw new JNCSInvalidSetViewException("Wrong parameter value"); |
226 |
|
227 |
int l = ECWSetView(nBands, posBands, iniX, iniY, endX, endY, tlX, tlY, brX, brY, bufW, bufH);
|
228 |
if(l != 0){ |
229 |
String s = JNCSError.getError(l);
|
230 |
throw new JNCSInvalidSetViewException(s); |
231 |
}else{
|
232 |
bSetViewIsWorld = true;
|
233 |
return 0; |
234 |
} |
235 |
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* Crea una vista en un fichero ecw abierto.
|
240 |
*
|
241 |
* @param nBands N�mero de bandas en bandList
|
242 |
* @param bandList Array de �ndices de bandas
|
243 |
* @param width ancho de la vista en pixels
|
244 |
* @param height alto de la vista en pixels
|
245 |
* @param dWorldTLX coordenada X arriba-izquierda)
|
246 |
* @param dWorldTLY coordenada Y arriba-izquierda
|
247 |
* @param dWorldBRX coordenada X abajo-derecha)
|
248 |
* @param dWorldBRY coordenada Y abajo-derecha
|
249 |
* @throws JNCSFileNotOpenException, JNCSInvalidSetViewException
|
250 |
*/
|
251 |
|
252 |
public int setView(int i, int ai[], double d, double d1, double d2, double d3, int j, int k) |
253 |
throws JNCSFileNotOpenException, JNCSInvalidSetViewException
|
254 |
{ |
255 |
if(!bIsOpen)
|
256 |
throw new JNCSFileNotOpenException("File not open"); |
257 |
|
258 |
if (ai == null) |
259 |
throw new JNCSInvalidSetViewException("Wrong parameter value"); |
260 |
JNCSDatasetPoint jncsdatasetpoint = convertWorldToDataset(d, d1); |
261 |
JNCSDatasetPoint jncsdatasetpoint1 = convertWorldToDataset(d2, d3); |
262 |
int l = ECWSetView(i, ai, jncsdatasetpoint.x, jncsdatasetpoint.y, jncsdatasetpoint1.x - 1, jncsdatasetpoint1.y - 1, d, d1, d2, d3, j, k); |
263 |
if(l != 0) |
264 |
{ |
265 |
//String s = ECWGetErrorString(l);
|
266 |
String s = JNCSError.getError(l);
|
267 |
throw new JNCSInvalidSetViewException(s); |
268 |
} else
|
269 |
{ |
270 |
bSetViewIsWorld = true;
|
271 |
return 0; |
272 |
} |
273 |
} |
274 |
|
275 |
/**
|
276 |
* Lee una l�nea del fichero Ecw
|
277 |
* @param buffer Buffer donde se almacenan los datos de la l�nea
|
278 |
* @throws JNCSException
|
279 |
*/
|
280 |
|
281 |
public int readLineRGBA(int ai[]) |
282 |
throws JNCSException
|
283 |
{ |
284 |
if(!bIsOpen)
|
285 |
throw new JNCSFileNotOpenException("File not open"); |
286 |
int i = ECWReadLineRGBA(ai);
|
287 |
if(i != 0) |
288 |
{ |
289 |
String s = JNCSError.getError(i);
|
290 |
throw new JNCSException(s); |
291 |
} else
|
292 |
{ |
293 |
return 0; |
294 |
} |
295 |
} |
296 |
|
297 |
public int readLineBGRA(int ai[]) |
298 |
throws JNCSException
|
299 |
{ |
300 |
throw new JNCSException("Not Yet Implemented!"); |
301 |
} |
302 |
|
303 |
public int readLineBIL(int ai[]) |
304 |
throws JNCSException
|
305 |
{ |
306 |
throw new JNCSException("Not Yet Implemented!"); |
307 |
} |
308 |
|
309 |
public int readLineBIL(double ad[]) |
310 |
throws JNCSException
|
311 |
{ |
312 |
throw new JNCSException("Not Yet Implemented!"); |
313 |
} |
314 |
|
315 |
public int readImageRGBA(int ai[], int i, int j) |
316 |
throws JNCSException
|
317 |
{ |
318 |
if(!bIsOpen)
|
319 |
throw new JNCSFileNotOpenException("File not open"); |
320 |
int k = ECWReadImageRGBA(ai, i, j);
|
321 |
if(k != 0) |
322 |
{ |
323 |
String s = JNCSError.getError(k);
|
324 |
throw new JNCSException(s); |
325 |
} else
|
326 |
{ |
327 |
return 0; |
328 |
} |
329 |
} |
330 |
|
331 |
/**
|
332 |
* Obtiene una cadena que corresponde a un error a trav�s del entero que lo representa
|
333 |
* @return String Cadena de error
|
334 |
* @param error Entero que representa el error
|
335 |
*/
|
336 |
|
337 |
public String getLastErrorText(int i) |
338 |
{ |
339 |
return JNCSError.getError(i);
|
340 |
} |
341 |
|
342 |
/**
|
343 |
* Convierte una coordenada del mundo real a coordenadas de la vista
|
344 |
* @return JNCSDatasetPoint Clase que representa a un punto en la imagen
|
345 |
* @param x Coordenada X del mundo real
|
346 |
* @param y Coordenada Y del mundo real
|
347 |
* @throws JNCSFileNotOpenException
|
348 |
*/
|
349 |
|
350 |
public JNCSDatasetPoint convertWorldToDataset(double d, double d1) |
351 |
throws JNCSFileNotOpenException
|
352 |
{ |
353 |
int i;
|
354 |
int j;
|
355 |
if(bIsOpen)
|
356 |
{ |
357 |
i = (int)Math.round((d - originX) / cellIncrementX); |
358 |
j = (int)Math.round((d1 - originY) / cellIncrementY); |
359 |
} else
|
360 |
{ |
361 |
throw new JNCSFileNotOpenException(); |
362 |
} |
363 |
return new JNCSDatasetPoint(i, j); |
364 |
} |
365 |
|
366 |
/**
|
367 |
* Convierte una coordenada de la vista a coordenadas del mundo real
|
368 |
* @return JNCSWorldPoint Clase que representa una coordenada del mundo real
|
369 |
* @param x Coordenada X de la imagen
|
370 |
* @param y Coordenada Y de la imagen
|
371 |
* @throws JNCSFileNotOpenException
|
372 |
*/
|
373 |
|
374 |
public JNCSWorldPoint convertDatasetToWorld(int i, int j) |
375 |
throws JNCSFileNotOpenException
|
376 |
{ |
377 |
double d;
|
378 |
double d1;
|
379 |
if(bIsOpen)
|
380 |
{ |
381 |
d = originX + (double)i * cellIncrementX;
|
382 |
d1 = originY + (double)j * cellIncrementY;
|
383 |
} else
|
384 |
{ |
385 |
throw new JNCSFileNotOpenException(); |
386 |
} |
387 |
return new JNCSWorldPoint(d, d1); |
388 |
} |
389 |
|
390 |
public short getPercentComplete() |
391 |
{ |
392 |
return ECWGetPercentComplete();
|
393 |
} |
394 |
|
395 |
/**
|
396 |
* Obtiene una cadena con la versi�n de la libreria
|
397 |
* @return versi�n
|
398 |
*/
|
399 |
|
400 |
public static String getLibVersion() |
401 |
{ |
402 |
return ECWGetLibVersion();
|
403 |
} |
404 |
|
405 |
private static void debug(String s) |
406 |
{ |
407 |
if(debug)
|
408 |
System.out.println(s);
|
409 |
} |
410 |
|
411 |
private static boolean bUseNativeMethods = false; |
412 |
private static boolean bSecurityError = false; |
413 |
private static boolean bUnsatisfiedLink = false; |
414 |
static boolean bHaveClassInit = false; |
415 |
static boolean debug = false; |
416 |
public static final int ECW_CELL_UNITS_INVALID = 0; |
417 |
public static final int ECW_CELL_UNITS_METERS = 1; |
418 |
public static final int ECW_CELL_UNITS_DEGREES = 2; |
419 |
public static final int ECW_CELL_UNITS_FEET = 3; |
420 |
public int numBands; |
421 |
public int width; |
422 |
public int height; |
423 |
public double originX; |
424 |
public double originY; |
425 |
public double cellIncrementX; |
426 |
public double cellIncrementY; |
427 |
public int cellSizeUnits; |
428 |
public double compressionRate; |
429 |
public boolean progressive; |
430 |
public String fileName; |
431 |
public String datum; |
432 |
public String projection; |
433 |
public boolean bIsOpen; |
434 |
private long nativeDataPointer; |
435 |
private static final boolean doGarbageCollectionOnClose = false; |
436 |
private static final int ECW_OK = 0; |
437 |
private int nFileSetViewDatasetTLX; |
438 |
private int nFileSetViewDatasetTLY; |
439 |
private int nFileSetViewDatasetBRX; |
440 |
private int nFileSetViewDatasetBRY; |
441 |
private int nFileSetViewWidth; |
442 |
private int nFileSetViewHeight; |
443 |
private double dFileSetViewWorldTLX; |
444 |
private double dFileSetViewWorldTLY; |
445 |
private double dFileSetViewWorldBRX; |
446 |
private double dFileSetViewWorldBRY; |
447 |
private boolean bSetViewIsWorld; |
448 |
protected JNCSProgressiveUpdate progImageClient;
|
449 |
|
450 |
} |