root / tags / v1_0_1_RELEASE / libraries / libjni-mrsid / src / es / gva / cit / jmrsid / MrSIDImageReader.java @ 9531
History | View | Annotate | Download (3.4 KB)
1 | 662 | igbrotru | /**********************************************************************
|
---|---|---|---|
2 | * $Id$
|
||
3 | *
|
||
4 | * Name: MrSIDImageReader.java
|
||
5 | * Project: JMRSID. Interfaz java to MrSID (Lizardtech).
|
||
6 | * Purpose:
|
||
7 | * Author: Nacho Brodin, brodin_ign@gva.es
|
||
8 | *
|
||
9 | **********************************************************************/
|
||
10 | /*Copyright (C) 2004 Nacho Brodin <brodin_ign@gva.es>
|
||
11 | |||
12 | This program is free software; you can redistribute it and/or
|
||
13 | modify it under the terms of the GNU General Public License
|
||
14 | as published by the Free Software Foundation; either version 2
|
||
15 | of the License, or (at your option) any later version.
|
||
16 | |||
17 | This program is distributed in the hope that it will be useful,
|
||
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
20 | GNU General Public License for more details.
|
||
21 | |||
22 | You should have received a copy of the GNU General Public License
|
||
23 | along with this program; if not, write to the Free Software
|
||
24 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||
25 | 3539 | nacho | |
26 | |||
27 | [01] 01-Oct-2005 nbt New call to JNI function MrSIDImageReaderArrayNat to convert name string to char array.
|
||
28 | |||
29 | 662 | igbrotru | */
|
30 | |||
31 | 2214 | igbrotru | package es.gva.cit.jmrsid; |
32 | 662 | igbrotru | |
33 | 3539 | nacho | import java.io.File; |
34 | import java.io.IOException; |
||
35 | 2214 | igbrotru | |
36 | |||
37 | 662 | igbrotru | /**
|
38 | 2214 | igbrotru | *
|
39 | 662 | igbrotru | * @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
|
40 | * @version 0.0
|
||
41 | * @link http://www.gvsig.gva.es
|
||
42 | */
|
||
43 | public class MrSIDImageReader extends MrSIDImageReaderBase{ |
||
44 | |||
45 | private native long MrSIDImageReaderNat(String pszFilename); |
||
46 | 3090 | nacho | private native long MrSIDImageReaderArrayNat(byte[] b); |
47 | 1124 | igbrotru | private native void FreeMrSIDImageReaderNat(long cPtr); |
48 | |||
49 | public MrSIDImageReader(){}
|
||
50 | |||
51 | /**
|
||
52 | * Constructor
|
||
53 | * @param cPtr direcci?n de memoria al objeto MrSIDImageReader de C.
|
||
54 | */
|
||
55 | |||
56 | public MrSIDImageReader(long cPtr){ |
||
57 | this.cPtr=cPtr;
|
||
58 | } |
||
59 | |||
60 | /**
|
||
61 | * Destructor
|
||
62 | */
|
||
63 | |||
64 | protected void finalize(){ |
||
65 | 3539 | nacho | this.close();
|
66 | } |
||
67 | |||
68 | /**
|
||
69 | * Cierra el MrSIDImageReader
|
||
70 | *
|
||
71 | */
|
||
72 | public void close(){ |
||
73 | if(cPtr > 0){ |
||
74 | 1124 | igbrotru | FreeMrSIDImageReaderNat(cPtr); |
75 | 3539 | nacho | cPtr = -1;
|
76 | } |
||
77 | 1124 | igbrotru | } |
78 | 662 | igbrotru | |
79 | /**
|
||
80 | 840 | igbrotru | * Constructor
|
81 | 662 | igbrotru | *
|
82 | 840 | igbrotru | * @param pszFilename Nombre del fichero
|
83 | * @throws MrSIDException, IOException
|
||
84 | 662 | igbrotru | */
|
85 | |||
86 | public MrSIDImageReader(String pszFilename)throws MrSIDException, IOException{ |
||
87 | |||
88 | File f = new File( pszFilename ); |
||
89 | if(!f.exists())
|
||
90 | throw new IOException("The file "+pszFilename+" don't exists"); |
||
91 | |||
92 | if(!f.canRead())
|
||
93 | throw new IOException("I can't read the file"); |
||
94 | |||
95 | 3539 | nacho | cPtr=MrSIDImageReaderArrayNat(pszFilename.getBytes()); |
96 | 662 | igbrotru | |
97 | if(cPtr<0) |
||
98 | throw new MrSIDException("Error in MrDID Open"); |
||
99 | |||
100 | } |
||
101 | |||
102 | /**
|
||
103 | 2214 | igbrotru | * Obtiene el n?mero de niveles
|
104 | 662 | igbrotru | */
|
105 | public int getNumLevels()throws MrSIDException{ |
||
106 | 8765 | jjdelcerro | String os = System.getProperty("os.name").toLowerCase(); |
107 | if(os.startsWith("mac os x")){ |
||
108 | return getNumLevelsFromMinMagnification();
|
||
109 | }else{
|
||
110 | String msg1="Error en getNumLevels. No se ha obtenido un puntero valido a LTIImage"; |
||
111 | String msg2="La llamada nativa a getNumLevels ha devuelto un c?digo de error"; |
||
112 | return baseSimpleFunction(2,msg1,msg2); |
||
113 | } |
||
114 | 662 | igbrotru | |
115 | 8765 | jjdelcerro | } |
116 | |||
117 | /**
|
||
118 | * Obtiene el n?mero de niveles s partir de getMinMagnification.
|
||
119 | * (Funcion creada para Mac sobre Power PC por los problemas con getNumLevels)
|
||
120 | */
|
||
121 | public int getNumLevelsFromMinMagnification()throws MrSIDException{ |
||
122 | 662 | igbrotru | |
123 | 8765 | jjdelcerro | double mag = getMinMagnification();
|
124 | |||
125 | double aux = getWidth() * mag;
|
||
126 | int cont = 0; |
||
127 | while(aux < getWidth()){
|
||
128 | aux *= 2;
|
||
129 | cont ++; |
||
130 | } |
||
131 | return cont;
|
||
132 | 662 | igbrotru | } |
133 | 2214 | igbrotru | |
134 | 662 | igbrotru | } |