root / trunk / libraries / libjni-mrsid / src / main / java / es / gva / cit / jmrsid / MrSIDImageReader.java @ 20021
History | View | Annotate | Download (3.45 KB)
1 | 20021 | maquerol | /**********************************************************************
|
---|---|---|---|
2 | * $Id: MrSIDImageReader.java 8460 2006-10-31 16:26:34Z nacho $
|
||
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 | |||
26 | |||
27 | [01] 01-Oct-2005 nbt New call to JNI function MrSIDImageReaderArrayNat to convert name string to char array.
|
||
28 | |||
29 | */
|
||
30 | |||
31 | package es.gva.cit.jmrsid; |
||
32 | |||
33 | import java.io.File; |
||
34 | import java.io.IOException; |
||
35 | |||
36 | |||
37 | /**
|
||
38 | *
|
||
39 | * @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 | private native long MrSIDImageReaderArrayNat(byte[] b); |
||
47 | 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 | this.close();
|
||
66 | } |
||
67 | |||
68 | /**
|
||
69 | * Cierra el MrSIDImageReader
|
||
70 | *
|
||
71 | */
|
||
72 | public void close(){ |
||
73 | if(cPtr > 0){ |
||
74 | FreeMrSIDImageReaderNat(cPtr); |
||
75 | cPtr = -1;
|
||
76 | } |
||
77 | } |
||
78 | |||
79 | /**
|
||
80 | * Constructor
|
||
81 | *
|
||
82 | * @param pszFilename Nombre del fichero
|
||
83 | * @throws MrSIDException, IOException
|
||
84 | */
|
||
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 | cPtr=MrSIDImageReaderArrayNat(pszFilename.getBytes()); |
||
96 | |||
97 | if(cPtr<0) |
||
98 | throw new MrSIDException("Error in MrDID Open"); |
||
99 | |||
100 | } |
||
101 | |||
102 | /**
|
||
103 | * Obtiene el n?mero de niveles
|
||
104 | */
|
||
105 | public int getNumLevels()throws MrSIDException{ |
||
106 | 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 | |||
115 | } |
||
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 | |||
123 | 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 | } |
||
133 | |||
134 | } |