Statistics
| Revision:

gvsig-raster / org.gvsig.raster.lizardtech / trunk / org.gvsig.raster.lizardtech / org.gvsig.raster.lizardtech.jni / src / main / java / es / gva / cit / jmrsid / MrSIDImageReader.java @ 2452

History | View | Annotate | Download (3.6 KB)

1
/**********************************************************************
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
                if (cPtr != 0)
66
                        this.close();
67
        }
68

    
69
        /**
70
         * Cierra el MrSIDImageReader
71
         *
72
         */
73
        public void close(){
74
                if(cPtr != 0){
75
                        FreeMrSIDImageReaderNat(cPtr);
76
                        cPtr = 0;
77
                }
78
        }
79
                
80
        /**
81
         * Constructor
82
         *
83
         * @param pszFilename        Nombre del fichero
84
         * @throws MrSIDException, IOException
85
         */
86
        
87
        public MrSIDImageReader(String pszFilename)throws MrSIDException, IOException{
88
                
89
                /*if ((pszFilename == null) || (pszFilename.equals("")))
90
                        throw new MrSIDException("Nombre de fichero incorrecto");
91
                
92
                File f = new File( pszFilename );
93
                if(!f.exists())
94
                        throw new IOException("The file "+pszFilename+" don't exists");
95
          
96
                if(!f.canRead())
97
                        throw new IOException("I can't read the file");*/
98

    
99
                cPtr = MrSIDImageReaderArrayNat(pszFilename.getBytes());
100
    
101
                if(cPtr == 0)
102
                        throw new MrSIDException("Error in MrDID Open");
103
 
104
        }
105
        
106
        /**
107
         * Obtiene el n?mero de niveles
108
         */
109
        public int getNumLevels()throws MrSIDException{
110
                String os = System.getProperty("os.name").toLowerCase();
111
                if(os.startsWith("mac os x")){
112
                        return getNumLevelsFromMinMagnification();
113
                }else{
114
                        String msg1="Error en getNumLevels. No se ha obtenido un puntero valido a LTIImage";
115
                        String msg2="La llamada nativa a getNumLevels ha devuelto un c?digo de error";
116
                        return baseSimpleFunction(2,msg1,msg2);
117
                }
118
                
119
        }
120
        
121
        /**
122
         * Obtiene el n?mero de niveles s partir de getMinMagnification. 
123
         * (Funcion creada para Mac sobre Power PC por los problemas con getNumLevels)
124
         */
125
        public int getNumLevelsFromMinMagnification()throws MrSIDException{
126
                
127
                double mag = getMinMagnification();
128
                   
129
                   double aux = getWidth() * mag;
130
                   int cont = 0;
131
                   while(aux < getWidth()){
132
                           aux *= 2;
133
                           cont ++;
134
                   }
135
                return cont;
136
        }
137
                        
138
}