import es.gva.cit.jecwcompress.*; import es.gva.cit.jgdal.*; public class TestCompressEcw{ public static void Uso(){ System.out.println("Uso 1: Comprime una ventana de la imagen."); System.out.println(" java TifToEcw file-src file-dst compresión ulX ulY sizeX sizeY"); System.out.println("Uso 2: Comprime a tamaño completo de la imágen."); System.out.println(" java TifToEcw file-src file-dst compresión"); } public static void main(String[] args){ Gdal migdal=new Gdal(); NCSEcwCompressClient client; Read lectura=null; if(args.length != 3 && args.length != 7){ TestCompressEcw.Uso(); return; } try{ migdal.open(args[0],Gdal.GA_ReadOnly); }catch(Exception ge){ ge.printStackTrace(); //........... } GdalRasterBand mirasterband=null; String st; int nxsize=0; int nysize=0; int ulX=0; int ulY=0; int widthcompress = 0; int heightcompress = 0; int rastercount=0; String rasterband; GeoTransform gt=null; try{ rastercount=migdal.getRasterCount(); nxsize = migdal.getRasterXSize(); nysize = migdal.getRasterYSize(); System.out.println("N BANDAS="+rastercount+" SIZEX="+nxsize+" SIZEY="+nysize); System.out.println(migdal.getProjectionRef()); }catch(GdalException ge){ ge.printStackTrace(); //........... } if(args.length == 7){ ulX = Integer.parseInt(args[3]); ulY = Integer.parseInt(args[4]); widthcompress = Integer.parseInt(args[5]); heightcompress = Integer.parseInt(args[6]); if(ulX<0 || ulY<0 || (ulX+widthcompress)>nxsize || (ulY+heightcompress)>nysize){ System.out.println("Error en los límites de la ventana solicitada"); return; } }else{ widthcompress = nxsize; heightcompress = nysize; } try{ gt=migdal.getGeoTransform(); System.out.println("Origins = ("+gt.adfgeotransform[0]+","+gt.adfgeotransform[3]+")"); System.out.println("Pixel Size = ("+gt.adfgeotransform[1]+","+gt.adfgeotransform[5]+")"); }catch(GdalException e){ System.out.println("No puedo obtener el array geoTransform."); e.printStackTrace(); //........... } try{ client = new NCSEcwCompressClient(); client.setOutputFilename(args[1]); client.setInputFilename(args[0]); client.setTargetCompress(Double.parseDouble(args[2])); client.setInOutSizeX(widthcompress); client.setInOutSizeY(heightcompress); client.setInputBands(rastercount); if(rastercount == 1) { client.setCompressFormat(CompressFormat.COMPRESS_UINT8); } else if(rastercount == 3) { client.setCompressFormat(CompressFormat.COMPRESS_RGB); } else { client.setCompressFormat(CompressFormat.COMPRESS_MULTI); } //client.setDatum("UTM Zona 31N"); client.setProjection("WGS84"); client.setCellIncrementX(gt.adfgeotransform[1]); client.setCellIncrementY(gt.adfgeotransform[5]); client.setOriginX(gt.adfgeotransform[0]); client.setOriginY(gt.adfgeotransform[3]); client.setCellSizeUnits(1); System.out.println(Double.parseDouble(args[2])); lectura = new Read(migdal, client, ulX, ulY, widthcompress, heightcompress); client.NCSEcwCompressOpen(false); client.NCSEcwCompress(lectura); client.NCSEcwCompressClose(); }catch(EcwException e){ e.printStackTrace(); //........... } try{ migdal.close(); }catch(GdalException e){ e.printStackTrace(); } } } /** * * Para la lectura hay que hacer una clase que extienda de JniObject e implemente ReadCallBack * . Esto obliga a crear un método loadBuffer. En el hay que meter la funcionalidad para que * llene el buffer. El buffer esta en la clase cliente y tendrá una longitud de * ancho de una línea * número de bandas */ class Read extends JniObject implements ReadCallBack { private GdalBuffer buf=null; private GdalRasterBand mirasterband=null; private Gdal migdal=null; private NCSEcwCompressClient client=null; private int width, height; private int ulX, ulY; public Read(Gdal g, NCSEcwCompressClient client,int ulx, int uly, int width, int height){ migdal = g; this.client = client; this.width = width; this.height = height; this.ulX = ulx; this.ulY = uly; } public void loadBuffer(){ try{ for(int iBand=0;iBand