Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libjni-gdal / src-test / SidToTif.java @ 1188

History | View | Annotate | Download (3.95 KB)

1
/**********************************************************************
2
* $Id: SidToTif.java 1188 2005-01-25 13:15:10Z igbrotru $
3
*
4
* Name:     SidToTif.java
5
* Project:  
6
* Purpose:  Convierte una im?gen MrSID en Tiff utilizando para la lectura
7
*                          el wrapper jni-mrsid y para la escritura jni-gdal. Para el 
8
*                          funcionamiento de este ejemplo es necesaria tambien la libreria
9
*                          jmrsid.dll/libjmrsid.so.x.x.x as? como las librerias de mrsid. 
10
* Author:   Nacho Brodin, brodin_ign@gva.es
11
*
12
**********************************************************************/
13

    
14
/*Copyright (C) 2004  Nacho Brodin <brodin_ign@gva.es>
15

16
This program is free software; you can redistribute it and/or
17
modify it under the terms of the GNU General Public License
18
as published by the Free Software Foundation; either version 2
19
of the License, or (at your option) any later version.
20

21
This program is distributed in the hope that it will be useful,
22
but WITHOUT ANY WARRANTY; without even the implied warranty of
23
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
GNU General Public License for more details.
25

26
You should have received a copy of the GNU General Public License
27
along with this program; if not, write to the Free Software
28
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
29
*/
30

    
31
import es.gva.cit.jmrsid.*;
32
import es.gva.cit.jgdal.*;
33

    
34

    
35
public class SidToTif {
36
        public static void main(String[] args){
37
 
38
           Gdal dset_dstno;
39
           GdalRasterBand rband=null;
40
           Gdal migdal=new Gdal();
41
           
42
           LTIImageReader img;
43
           LTIPixel pixel;
44
           int eColorSpace, nBands, eSampleType;
45
                     
46
           int tamx=Integer.parseInt(args[1]);
47
           int tamy=Integer.parseInt(args[2]);
48
           int siz = tamx * tamy * 1;
49
           
50
           
51
           try{
52
                   
53
                           img = new MrSIDImageReader(args[0]);
54
                           img.initialize();
55
                           
56
                           int overviews=((MrSIDImageReader)img).getNumLevels()-1;
57
                           System.out.println("Overviews="+overviews);
58
                           System.out.println("Width="+img.getWidth());
59
                           System.out.println("Height="+img.getHeight());
60
                           System.out.println("Stripsheigth="+img.getStripHeight());
61
                           nBands=img.getNumBands();
62
                           System.out.println("NumBands="+nBands);
63
                           eColorSpace=img.getColorSpace();
64
                           System.out.println("ColorSpace="+eColorSpace);
65
                           eSampleType=img.getDataType();
66
                           System.out.println("DataType="+eSampleType);
67
                           pixel=new LTIPixel(eColorSpace, nBands, eSampleType);
68
                           int[] dimsAtMag=img.getDimsAtMag(0.5);
69
                           System.out.println("Dims At Mag 0,5="+dimsAtMag[0]+" "+dimsAtMag[1]);
70
                                              
71
                           
72
                           //Acceso a la informaci?n de georeferenciaci?n
73
                           
74
                           LTIGeoCoord geoc = img.getGeoCoord();
75
                       System.out.println("X="+geoc.getX());
76
                       System.out.println("Y="+geoc.getY());
77
                       System.out.println("XRes="+geoc.getXRes());
78
                       System.out.println("YRes="+geoc.getYRes());
79
                       System.out.println("XRot="+geoc.getXRot());
80
                       System.out.println("YRot="+geoc.getYRot());
81
                           
82
                       //Fin de acceso a la informaci?n de georeferenciaci?n
83
                       
84
                       System.out.println("************************************");
85
                           
86
                           LTIScene scene=new LTIScene(0,0,tamx,tamy,1.0);
87
                           LTISceneBuffer buffer=new LTISceneBuffer(pixel,tamx,tamy,1);
88
                           ((LTIImageStage)img).read(scene,buffer);
89
                           
90
                                                    
91
                        GdalDriver drv=Gdal.getDriverByName("GTiff");
92
                          String[] params={"TILED=YES","PHOTOMETRIC=RGB","TFW=WORLDFILE"};
93
                          dset_dstno=drv.create("SiToTif.tif",tamx,tamy,3,Gdal.GDT_Byte,null);
94
                          
95
                          GdalBuffer b=new GdalBuffer();
96
                          b.buffByte=buffer.buf1;
97
                          
98
                          rband=dset_dstno.getRasterBand(1);
99
                          rband.writeRaster(0,0, tamx, tamy, b,Gdal.GDT_Byte);
100
                          
101
                          b.buffByte=buffer.buf2;
102
                          
103
                          rband=dset_dstno.getRasterBand(2);
104
                          rband.writeRaster(0,0, tamx, tamy, b,Gdal.GDT_Byte);
105
                          
106
                          b.buffByte=buffer.buf3;
107
                          
108
                          rband=dset_dstno.getRasterBand(3);
109
                          rband.writeRaster(0,0, tamx, tamy, b,Gdal.GDT_Byte);
110
                          
111
                          dset_dstno.close();
112
                           
113
                                             
114
                        
115
                           
116
           }catch(Exception e){
117
                           e.printStackTrace();
118
         
119
           }
120
           
121
          
122
          
123
        }  
124
}