Revision 3578

View differences:

trunk/libraries/libCq CMS for java.old/src/org/cresques/io/raster/RasterFilterStack.java
24 24
package org.cresques.io.raster;
25 25

  
26 26
import java.awt.Image;
27

  
28 27
import java.util.Vector;
29 28

  
29
import org.cresques.geo.ViewPortData;
30
import org.cresques.px.Extent;
30 31

  
32

  
31 33
/**
32 34
 * Esta clase representa la pila de filtros que debe ser manejada desde el
33 35
 * RasterFilterStackManager.
......
35 37
 *
36 38
 */
37 39
public class RasterFilterStack {
38
    private Image image = null;
39
    private RasterBuf rasterBuf = null;
40
    private RasterFilter rasterFilter = null;
41
    private int[] order = null;
42
    private RasterStats stats = null;
43
    Vector stack = new Vector();
44
    private int typeFilter = -2;
40
    private Image 			image = null;
41
    private RasterBuf 		rasterBuf = null;
42
    private RasterFilter 	rasterFilter = null;
43
    private int[] 			order = null;
44
    private RasterStats 	stats = null;
45
    private Vector			stack = new Vector();
46
    private int 			typeFilter = -2;
47
    private ViewPortData	viewPortData = null;
48
    private Extent			extent = null;
45 49

  
46 50
    /**
47 51
     * Constructor
......
238 242
    public RasterFilter get(int i) {
239 243
        return ((Filter) stack.get(i)).filter;
240 244
    }
245
    
246
    /**
247
     * Obtiene el filtro apilado que corresponde con el tipo
248
     * @param type	Tipo de filtro
249
     * @return      Filtro
250
     */
251
    public RasterFilter getByType(int type) {
252
    	for(int i=0;i<lenght();i++){
253
    		if(((Filter) stack.get(i)).type == type)
254
    			return ((Filter) stack.get(i)).filter;
255
    	}
256
        return null;
257
    }
241 258

  
242 259
    /**
243 260
     * Obtiene el tipo del filtro de la pila de la posici?n i
......
343 360
            } else {
344 361
                filter.addParam("raster", rasterBuf);
345 362
            }
346

  
363
            
364
            filter.setExtent(extent);
365
            filter.setViewPortData(viewPortData);
347 366
            filter.execute();
348 367

  
349 368
            if (filter.getResult("stats") != null) {
......
381 400
        this.rasterBuf = rasterBuf;
382 401
        executeFilterByDataType(RasterBuf.TYPE_SHORT);
383 402
    }
384

  
403
	
385 404
    /**
386 405
     *Muestra el contenido de la pila de filtros para depuraci?n
387 406
     */
......
412 431
            this.type = type;
413 432
        }
414 433
    }
434
	
435
	/**
436
	 * @param viewPortData The viewPortData to set.
437
	 */
438
	public void setViewPortData(ViewPortData viewPortData) {
439
		this.viewPortData = viewPortData;
440
	}
441
	/**
442
	 * @param extent The extent to set.
443
	 */
444
	public void setExtent(Extent extent) {
445
		this.extent = extent;
446
	}
415 447
}
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/raster/ColorSpaceConversion.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 * 
4
 * Copyright (C) 2004-5. 
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 * 
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io.raster;
25

  
26

  
27

  
28
/**
29
 *  
30
 * @author Nacho Brodin (brodin_ign@gva.es)
31
 */
32

  
33
public class ColorSpaceConversion {
34
	public static int H = 0, R = 0;
35
	public static int S = 1, G = 1;
36
	public static int L = 2, B = 2;
37

  
38
	
39
	/**
40
	 * Convierte HSL a RGB
41
	 * @param h hue
42
	 * @param s saturation
43
	 * @param l ligthness
44
	 * @return
45
	 */
46
	public static int[] HSLtoRGB(int h, int s, int i){
47
		double   red;                   /* the red band output                       */
48
		double   red255;                /* the red band output                       */
49
		double   green;                 /* the green band output                     */
50
		double   green255;              /* the green band output                     */
51
		double   blue;                  /* the blue band output                      */
52
		double   blue255;               /* the blue band output                      */
53
		double   m1;                    /* value used for determining RGB            */
54
		double   m2;                    /* value used for determining RGB            */
55
		double   scalei;                /* intensity value                           */
56
		double   scales;                /* saturation value                          */
57
		double   hue;                   /* hue                                       */
58
		double   savehue;               /* save the hue for future processing        */
59
		int[]   res = new int[3];
60
		 
61
		if(h == s && h == 0){
62
			res[0] = res[1] = res[2] = i;
63
			return res;
64
		}
65
				
66
		red = green = blue = 0.0;
67
		scalei = (double) (i / 255.0);
68
		scales = (double) (s / 255.0);
69
		m2 = 0.0;
70
		
71
		if (scalei <= 0.50)
72
			m2 = scalei*(1.0 + scales);
73
		else if (scalei > 0.50)
74
		    m2 = scalei+scales-(scalei*scales);
75
		m1 = 2.0 * scalei - m2;
76
		 
77
		hue = (double) 360.0 * h / 255.0;
78
		 
79
		if (scales == 0.0){
80
		  if (hue == -1.0){
81
		    red = scalei;
82
		    green = scalei;
83
		    blue = scalei;
84
		  }
85
		}else{
86
		   savehue = hue + 120.0;
87
		   if (savehue > 360.0)
88
		      savehue -= 360.0;
89
		   if (savehue < 0.0)
90
		      savehue += 360.0;
91
		   if (savehue < 60.0)
92
		      red = m1 + (m2-m1) * savehue/60.0;
93
		   else if (savehue < 180.0)
94
		          red = m2;
95
		        else if (savehue < 240.0)
96
		          red = m1 + (m2-m1) * (240.0-savehue)/60.0;
97
		        else
98
		          red = m1;
99
		 
100
		   savehue = hue;
101
		   if (savehue > 360.0)
102
		     savehue -= 360.0;
103
		   if (savehue < 0.0)
104
		      savehue += 360.0;
105
		   if (savehue < 60.0)
106
		      green = m1 + (m2-m1) * savehue/60.0;
107
		   else if (savehue < 180.0)
108
		      green = m2;
109
		   else if (savehue < 240.0)
110
		      green = m1 + (m2-m1) * (240.0-savehue)/60.0;
111
		   else
112
		      green = m1;
113
		 
114
		   
115
		   savehue = hue - 120.0;
116
		   if (savehue > 360.0)
117
		      savehue -= 360.0;
118
		   if (savehue < 0.0)
119
		      savehue += 360.0;
120
		   if (savehue < 60.0)
121
		      blue = m1 + (m2-m1) * savehue/60.0;
122
		   else if (savehue < 180.0)
123
		      blue = m2;
124
		   else if (savehue < 240.0)
125
		      blue = m1 + (m2-m1) * (240.0-savehue)/60.0;
126
		   else
127
		      blue = m1;
128
		}
129
		 
130
		red255 = red*255.0;
131
		green255 = green*255.0;
132
		blue255 = blue*255.0;
133
		if (red255 > 255.0)
134
		   red = 255.0;
135
		else
136
		   red = red255;
137
		if (green255 > 255.0)
138
		   green = 255.0;
139
		else
140
		   green = green255;
141
		if (blue255 > 255.0)
142
		   blue = 255.0;
143
		else
144
		   blue = blue255;
145
		 
146
		if (red   > 254.5) red   = 254.5;
147
		if (red   <   0.0) red   =   0.0;
148
		if (green > 254.5) green = 254.5;
149
		if (green <   0.0) green =   0.0;
150
		if (blue  > 254.5) blue  = 254.5;
151
		if (blue  <   0.0) blue  =   0.0;
152
		 
153
		res[0] = (int) (red + 0.5);
154
		res[1] = (int) (green +0.5);
155
		res[2] = (int) (blue + 0.5);
156
		return res;
157
	}
158
	
159
	/**
160
	 * Convierte RGB a HSL
161
	 * @param r red
162
	 * @param g green
163
	 * @param b blue
164
	 * @return
165
	 */
166
	public static double[] RGBtoHSL(int rojo, int verde, int azul){
167
		double scaler, scaleg, scaleb;
168
		double sat;
169
		double red, green, blue;
170
		double low, high, intens;
171
		double   hue=0.0;
172
		double[] res1 = new double[3];
173
		
174
		scaler = (double) (rojo / 255.0);
175
	    scaleg = (double) (verde / 255.0);
176
	    scaleb = (double) (azul / 255.0);
177
	  	 
178
	    high = scaler;
179
	    
180
	    if (scaleg > high)
181
	    	high = scaleg;
182
	    if (scaleb > high)
183
	    	high = scaleb;
184
	    low = scaler;
185
	    if (scaleg < low)
186
	    	low = scaleg;
187
	    if (scaleb < low)
188
	    	low = scaleb;
189
	    
190
	    intens = ((high + low) / 2.0);
191
	    if (high == low){
192
		  sat = 0.0;
193
		  hue = 0.0;
194
		  res1[0] = (double) hue;
195
		  res1[2] = (double) intens;
196
		  res1[1] = (double) sat;
197
	    }else if (high != low){
198
		  if (intens <= 0.5)
199
		    sat = (high-low)/(high+low);
200
		  else
201
		    sat = (high-low)/(2 - high - low);
202
		   
203
			red = (high-scaler)/(high-low);
204
			green = (high-scaleg)/(high-low);
205
			blue =(high-scaleb)/(high-low);
206
						
207
			if (scaler == high)
208
			    hue = blue - green;
209
			else
210
			  if (scaleg == high)
211
			   hue = 2 + red - blue;
212
			  else
213
			    if (scaleb == high)
214
			    	hue = 4 + green - red;
215
			  
216
			hue *= 60.0;
217
			
218
			if (hue < 0.0)
219
			 hue += 360.0;
220
			 
221
			//res[0] = (byte)(255.0 * hue / 360.0 + 0.5);
222
			//res[1] = (byte) (intens*255. + 0.5);
223
			//res[2] = (byte) (sat*255. + 0.5);
224
			res1[0] = (double)(hue);
225
			res1[2] = (double) (intens);
226
			res1[1] = (double) (sat);
227
	    }
228
		return res1;
229
	}
230
}
0 231

  
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/raster/SharpeningFilter.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io.raster;
25

  
26
import java.awt.Image;
27

  
28
import org.cresques.io.GeoRasterFile;
29

  
30

  
31
/**
32
 * Clase base para los filtros de sharpening en sus diferentes tipos
33
 * de datos.
34
 * @author Nacho Brodin (brodin_ign@gva.es)
35
 *
36
 */
37
public abstract class SharpeningFilter extends RasterFilter {
38
    
39
	/**
40
	 * Posici?n en la lista de GeoRasterFiles de la imagen de refinado.
41
	 */
42
	protected int			 	posPancromatica = 0;
43
	
44
	/**
45
	 * Lista de GeoRasterFiles que componen los datos de entrada
46
	 */
47
	protected GeoRasterFile[]	files = null;
48
	
49
	/**
50
	 * Alto de la imagen pancrom?tica
51
	 */
52
	protected int 				heightPancr = 0;
53
	
54
	/**
55
	 * Ancho de la imagen pancrom?tica
56
	 */
57
	protected int 				widthPancr = 0;
58
	
59
	/**
60
	 * Alto de las bandas multiespectrales
61
	 */
62
	protected int 				heightMultiespec = 0;
63
	
64
	/**
65
	 * Ancho de las bandas multiespectrales
66
	 */
67
	protected int 				widthMultiespec = 0;
68
	
69
	/**
70
	 * Image que corresponde a la imagen de refinado
71
	 */
72
	protected Image 			imagePancr = null;
73
	
74
	/**
75
	 * Image que corresponde a la imagen de entrada
76
	 */
77
	protected Image 			imageMultiespec = null;
78
	
79
	/**
80
	 * N?mero de bandas de la operaci?n incluido la de refinado
81
	 */
82
	protected int				nBands = 0;
83
	
84
	/**
85
	 * Relaci?n entre la pancromatica y la multiespectral en X
86
	 */
87
	protected int				relX = 0;
88
	
89
	/**
90
	 * Relaci?n entre la pancromatica y la multiespectral en Y
91
	 */
92
	protected int				relY = 0;
93
	
94
	/**
95
	 * Vector de 3 elementos que corresponden a R, G y B respectivamente. El valor contenido
96
	 * en cada uno de ellos corresponde al n?mero de banda de fichero que se visualiza en R, G y B.
97
	 */
98
	protected int[]				bandOrder = null;
99
	
100
	/**
101
	 * Valor de alpha aplicado a toda la imagen
102
	 */
103
	protected int				alpha = 0;
104
	
105
	/**
106
	 * M?todo de calculo del refinado
107
	 */
108
	protected String			method = "ihs";
109
	
110
	/**
111
	 * Coeficiente
112
	 */
113
	protected double			coef = 0.15;
114
	
115
    /**
116
     * Constructor
117
     *
118
     */
119
    public SharpeningFilter() {
120
        super();
121
    }
122

  
123
    /**
124
     * 
125
     */
126
    public void pre() {
127
      
128
    }
129

  
130
}
0 131

  
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/raster/RasterFilter.java
24 24
package org.cresques.io.raster;
25 25

  
26 26
import java.awt.Image;
27

  
28 27
import java.util.Hashtable;
29 28

  
29
import org.cresques.geo.ViewPortData;
30
import org.cresques.px.Extent;
30 31

  
32

  
31 33
/**
32 34
 * Filtro para raster. Ancestro de todos los filtros.
33 35
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
34 36
 */
35 37
public abstract class RasterFilter implements IRasterFilter {
36
    protected RasterBuf raster = null;
37
    protected RasterStats stats = null;
38
    protected Image image = null;
39
    protected int[] px = new int[4];
40
    protected int height = 0;
41
    protected int width = 0;
42
    protected Hashtable params = new Hashtable();
43
    protected int incX = 1;
44
    protected int incY = 1;
45
    protected boolean exec = true; //Si est? a false no se ejecuta el  filtro
38
    protected RasterBuf 	raster = null;
39
    protected RasterStats 	stats = null;
40
    protected Image 		image = null;
41
    protected int[] 		px = new int[4];
42
    protected int 			height = 0;
43
    protected int 			width = 0;
44
    protected Hashtable 	params = new Hashtable();
45
    protected int 			incX = 1;
46
    protected int 			incY = 1;
47
    protected ViewPortData	viewPortData = null;
48
    protected Extent		extent = null;
49
    
50
    /**
51
     * Variable que control la aplicaci?n o no del filtro. Si est? a false aunque est? en 
52
     * la pila el filtro no se ejecutar?.
53
     */
54
    protected boolean 		exec = true; 
46 55

  
47 56
    /**
57
     * @author Nacho Brodin (brodin_ign@gva.es)
58
     */
59
    public static class Kernel{
60
    	public float[][] kernel = null;
61
    	public Kernel(float[][] k){
62
    		this.kernel = k;
63
    	}
64
    	
65
    	public float kernelOperation(Kernel k){
66
    		float res = 0;
67
    		for(int i=0;i<3;i++)
68
    			for(int j=0;j<3;j++)
69
    				res += kernel[i][j] *  k.kernel[i][j];
70
    		return res;
71
    	}
72
    	
73
    }
74

  
75
    /**
48 76
     * Constructor
49 77
     */
50 78
    public RasterFilter() {
......
78 106

  
79 107
    /**
80 108
     * A?ade un par?metro al filtro
109
     * @param name	Clave del par?metro
110
     * @param param Objeto pasado como par?metro
81 111
     */
82 112
    public void addParam(String name, Object param) {
83 113
        params.put(name, param);
84 114
    }
85 115

  
86 116
    /**
117
     * Elimina un par?metro del filtro
118
     * @param name Clave del par?metro a eliminar
119
     */
120
    public void removeParam(String name){
121
    	params.remove(name);
122
    }
123
    
124
    /**
125
     * Obtiene un par?metro a partir de la clave
126
     * @param name Par?metro
127
     * @return Par?metro
128
     */
129
    public Object getParam(String name){
130
    	return params.get(name);
131
    }
132
    
133
    /**
87 134
     * Funci?n que contiene el c?digo a ejecutar antes de aplicar el filtro
88 135
     */
89 136
    abstract public void pre();
......
118 165
     * @param name        clave para obtener un objeto resultado del filtro.
119 166
     */
120 167
    abstract public Object getResult(String name);
168

  
169
	/**
170
	 * @param viewPortData The viewPortData to set.
171
	 */
172
	public void setViewPortData(ViewPortData viewPortData) {
173
		this.viewPortData = viewPortData;
174
	}
175
	/**
176
	 * @param extent The extent to set.
177
	 */
178
	public void setExtent(Extent extent) {
179
		this.extent = extent;
180
	}
121 181
}
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/raster/SharpeningImageFilter.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io.raster;
25

  
26
import java.awt.Dimension;
27
import java.awt.Graphics2D;
28
import java.awt.Image;
29
import java.awt.image.BufferedImage;
30
import java.awt.image.PixelGrabber;
31

  
32
import org.cresques.geo.ViewPortData;
33
import org.cresques.io.GeoRasterFile;
34
import org.cresques.px.PxRaster;
35

  
36

  
37
/**
38
 * Filtro de sharpening que se aplica sobre la vista. Tiene como entradas el objeto Image
39
 * con las bandas del raster visualizadas en la Vista y la banda pancrom?tica. A partir de
40
 * estas entradas genera un Image de salida como la que hay pero de resoluci?n igual a la
41
 * de la pancrom?tica.  
42
 * @author Nacho Brodin (brodin_ign@gva.es)
43
 *
44
 */
45
public class SharpeningImageFilter extends SharpeningFilter {
46
	
47
	//Variable que dice para cada pixel de la imagen de entrada cuantos de salida hay.
48
	private int 			nOutputPixelsPerInputPixel;  
49
	//Vector con los desplazamientos de los pixeles de salida dentro del vector
50
	private int[] 			outKernel;
51
	//Kernel aplicado a la pancromatica 
52
	private Kernel			kernel = null; 
53
	private PixelGrabber 	pgAct = null, pgPrev = null, pgNext = null;
54
	int[]					bufferPrev = null, bufferAct = null, bufferNext = null;
55
	double					coef = 0.20;
56
	double					coefBrovey = 0;
57
	
58
    /**
59
     * Constructor
60
     *
61
     */
62
    public SharpeningImageFilter() {
63
        super();
64
    }
65

  
66
    /**
67
     *  Validamos que haya alguna otra banda adem?s de la pancrom?tica y que la pancrom?tica 
68
     *  sea de mayor resoluci?n que las dem?s.
69
     */
70
    private void checkInput(){
71
    	exec = true;
72
        if(heightMultiespec >= heightPancr || widthMultiespec >= widthPancr || heightMultiespec == 0 || widthMultiespec == 0)
73
			exec = false;
74
        for(int i=0;i<files.length;i++){
75
        	if(i != posPancromatica){
76
        		if(files[i].getHeight() != heightMultiespec || files[i].getWidth() != widthMultiespec){
77
        			exec = false;
78
        			break;
79
        		}   		
80
        	}
81
        }
82
    }
83
    
84
    /**
85
     * Carga los par?metros pasados al filtro en las variables de 
86
     * instancia que corresponde,
87
     */
88
    private void loadParam(){
89
    	//Carga de parametros
90
    	this.image = (Image) params.get("raster");
91
        posPancromatica = ((Integer) params.get("pancromatica")).intValue();
92
        files = (GeoRasterFile[]) params.get("files");
93
        bandOrder = (int[]) params.get("order");
94
        alpha = ((Integer) params.get("alpha")).intValue();
95
        method = (String) params.get("method");
96
        coef = ((Double) params.get("coef")).doubleValue();
97
        coefBrovey = ((Integer) params.get("coefBrovey")).intValue();
98
        
99
        //Asignamos el nombre de la banda pancrom?tica como par?metro para que cuando 
100
        //volvamos a abrir el dialogo pueda recuperarse y seleccionarse en el cuadro
101
        this.addParam("pancrName",files[posPancromatica].getName().substring(
102
        		files[posPancromatica].getName().lastIndexOf("/")+1, 
103
				files[posPancromatica].getName().length()));
104
       
105
        height = image.getHeight(null);
106
        width = image.getWidth(null);
107
        heightPancr = files[posPancromatica].getHeight();
108
        widthPancr = files[posPancromatica].getWidth();
109
        for(int i=0;i<files.length;i++){
110
        	if(i != posPancromatica){
111
        		heightMultiespec = files[i].getHeight(); 
112
        		widthMultiespec = files[i].getWidth();
113
        	}
114
        }
115
        
116
        relX = (int)widthPancr/widthMultiespec;
117
		relY = (int)heightPancr/heightMultiespec;
118
    }
119
    
120
    /* (non-Javadoc)
121
     * @see org.cresques.io.raster.IRasterFilter#pre()
122
     */
123
    public void pre() {
124
    	
125
    	loadParam();
126
    	checkInput();
127
    	
128
        //Creamos el buffer donde se pinta la pancromatica
129
        
130
    	imagePancr = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
131
        Graphics2D graphicsPancr = (Graphics2D)imagePancr.getGraphics();
132
		PxRaster rasterPancr = new PxRaster(files[posPancromatica], null, files[posPancromatica].getView());
133
						
134
		rasterPancr.setBand(GeoRasterFile.RED_BAND, 0);
135
		rasterPancr.setBand(GeoRasterFile.GREEN_BAND, 1);
136
		rasterPancr.setBand(GeoRasterFile.BLUE_BAND, 2);
137
		
138
		ViewPortData vp = (ViewPortData)viewPortData.clone();
139
		vp.zoom(extent);
140
		rasterPancr.draw(graphicsPancr, vp);
141
		rasterPancr = null;
142
		
143
		//Creamos el buffer donde se pinta la imagen de entrada
144
		
145
		imageMultiespec = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
146
	    Graphics2D graphicsMultiespec = (Graphics2D)imageMultiespec.getGraphics();
147
		PxRaster rasterMultiespec = null;
148
		boolean first = true;
149
		for(int i = 0;i<files.length;i++){	
150
		  if(first){
151
			rasterMultiespec = new PxRaster(files[i], null, files[posPancromatica].getView());
152
			first = false;
153
		  }else
154
		   	rasterMultiespec.addFile(files[i].getName());
155
		}
156
		
157
		rasterMultiespec.setBand(GeoRasterFile.RED_BAND, bandOrder[0]);
158
		rasterMultiespec.setBand(GeoRasterFile.GREEN_BAND, bandOrder[1]);
159
		rasterMultiespec.setBand(GeoRasterFile.BLUE_BAND, bandOrder[2]);
160
							
161
		rasterMultiespec.draw(graphicsMultiespec, vp);
162
		rasterMultiespec = null;
163
		
164
        super.pre();
165
    }
166

  
167
    /**
168
     * Aplica la operaci?n de refinamiento sobre el buffer Multiespectral que contiene 
169
     * el RGB que es pasado por par?metro utilizando la pancrom?tica.
170
     * @param bufferInput	Buffer rgb 
171
     * @param length		longitud del buffer de la pancromatica utilizado
172
     * @param iLine			l?nea leida de la imagen multiespectral
173
     * @return				buffer con el resultado de la operaci?n
174
     */
175
    private int[] processBrovey(int[] bufferInput, int iLine){    	
176
    	double[]		hsl;
177
    	int[]			rgb;    	
178
    	PixelGrabber 	pg = null;
179
    	
180
    	//Longitud del buffer de salida
181
    	int 			widthDst = width * relX;
182
    	//Buffer de salida
183
    	int[]			bufferPancr = new int[width];
184

  
185
    	pg = new PixelGrabber(imagePancr, 0, iLine, width, 1, bufferPancr , 0, width);
186

  
187
    	
188
    	try {
189
            pg.grabPixels();
190
        } catch (InterruptedException e) {
191
            e.printStackTrace();
192
        }
193
   
194
        for(int iElem=0; iElem<width; iElem++){
195
    		int r = ((bufferInput[iElem] >> 16) & 0xff);
196
			int g = ((bufferInput[iElem] >> 8) & 0xff);
197
			int b = (bufferInput[iElem] & 0xff);
198
			byte i = (byte)((bufferPancr[iElem] >> 16) & 0xff);
199
			double scale = (3.0*(i+coefBrovey))/(r+g+b+1.0);
200
			r *= scale;g *= scale;b *= scale;			
201
			bufferPancr[iElem] = ((alpha << 24) & 0xff000000) | 
202
								((r << 16) & 0x00ff0000)| 
203
								((g << 8) & 0x0000ff00) | 
204
								(b & 0x000000ff);
205
    	}
206
    	return bufferPancr;
207
    	
208
    }
209
    
210
    /**
211
     * Aplica la operaci?n de refinamiento sobre el buffer Multiespectral que contiene 
212
     * el RGB que es pasado por par?metro utilizando la pancrom?tica.
213
     * @param bufferInput	Buffer rgb 
214
     * @param length		longitud del buffer de la pancromatica utilizado
215
     * @param iLine			l?nea leida de la imagen multiespectral
216
     * @return				buffer con el resultado de la operaci?n
217
     */
218
    private int[] processKernel(int[] bufferInput, int iLine){    	
219
    	int[]			bufferDst = new int[width];
220
    	    	
221
    	if(iLine != 0){
222
    		bufferPrev = bufferAct;
223
    		bufferAct = bufferNext;
224
    	}else{
225
    		bufferPrev = null;
226
    		bufferAct = new int[width];
227
    		pgAct = new PixelGrabber(imagePancr, 0, iLine, width, 1, bufferAct , 0, width);
228
    		try {
229
                pgAct.grabPixels();
230
            } catch (InterruptedException e) {e.printStackTrace();}
231
    	}
232
    	    	
233
    	if(iLine != (height - 1)){
234
    		bufferNext = new int[width];
235
    		pgNext = new PixelGrabber(imagePancr, 0, iLine + 1, width, 1, bufferNext , 0, width);
236
    		try {
237
                pgNext.grabPixels();
238
            } catch (InterruptedException e) {e.printStackTrace();}
239
    	}else
240
    		bufferNext = null;
241
    	        
242

  
243
    	for(int iElem=0; iElem<width; iElem++){
244
    		int a = ((bufferInput[iElem] >> 24) & 0xff);
245
    		int r = ((bufferInput[iElem] >> 16) & 0xff);
246
			int g = ((bufferInput[iElem] >> 8) & 0xff);
247
			int b = (bufferInput[iElem] & 0xff);
248

  
249
			float[][] op = new float[3][3];
250
			if(bufferPrev != null){
251
				if(iElem != 0)op[0][0] = (bufferPrev[iElem - 1] & 0x000000ff);
252
				op[0][1] = (bufferPrev[iElem] & 0x000000ff);
253
				if(iElem != (width -1))op[0][2] = (bufferPrev[iElem + 1] & 0x000000ff);
254
			}
255
			if(iElem != 0)op[1][0] = (bufferAct[iElem - 1] & 0x000000ff);
256
			op[1][1] = (bufferAct[iElem] & 0x000000ff);
257
			if(iElem != (width -1))op[1][2] = (bufferAct[iElem + 1] & 0x000000ff);
258
			if(bufferNext != null){
259
				if(iElem != 0)op[2][0] = (bufferNext[iElem - 1] & 0x000000ff); 
260
				op[2][1] = (bufferNext[iElem] & 0x000000ff);
261
				if(iElem != (width -1))op[2][2] = (bufferNext[iElem + 1] & 0x000000ff);
262
			}
263
			Kernel operando = new Kernel(op);
264
			double i = kernel.kernelOperation(operando) * 0.15;
265
			r += i;
266
			g += i;
267
			b += i;
268
			bufferDst[iElem] = ((a << 24) & 0xff000000) | 
269
								((r << 16) & 0x00ff0000)| 
270
								((g << 8) & 0x0000ff00) | 
271
								(b & 0x000000ff);	
272
    	}
273
    	return bufferDst;
274
    	
275
    }
276
    
277
    /**
278
     * Aplica la operaci?n de refinamiento sobre el buffer Multiespectral que contiene 
279
     * el RGB que es pasado por par?metro utilizando la pancrom?tica.
280
     * @param bufferInput	Buffer rgb 
281
     * @param length		longitud del buffer de la pancromatica utilizado
282
     * @param iLine			l?nea leida de la imagen multiespectral
283
     * @return				buffer con el resultado de la operaci?n
284
     */
285
    private int[] processIHS(int[] bufferInput, int iLine){    	
286
    	double[]		hsl;
287
    	int[]			rgb;
288
    	PixelGrabber 	pg = null;
289

  
290
    	//Buffer de salida
291
    	int[]			bufferPancr = new int[width];
292

  
293
    	pg = new PixelGrabber(imagePancr, 0, iLine, width, 1, bufferPancr , 0, width);
294

  
295
    	try {
296
            pg.grabPixels();
297
        } catch (InterruptedException e) {
298
            e.printStackTrace();
299
        }
300

  
301
        int[] uvw , tmp = new int[3];
302
        double[] xyz;
303
    	for(int iElem=0; iElem<width; iElem++){
304
    		xyz = ColorSpaceConversion.RGBtoHSL( (bufferInput[iElem] >> 16) & 0x000000ff,
305
    											 (bufferInput[iElem] >> 8) & 0x000000ff,
306
    											 bufferInput[iElem] & 0x000000ff);
307

  
308
    		xyz[2] = ((bufferPancr[iElem] & 0x000000ff)/255.0) + coef;
309
    		
310
    		tmp[0] = (int)(255.0 * xyz[0] / 360.0 + 0.5);
311
			tmp[2] = (int) (xyz[2]*255. + 0.5);
312
			tmp[1] = (int) (xyz[1]*255. + 0.5);
313
			
314
    		uvw = ColorSpaceConversion.HSLtoRGB(tmp[ColorSpaceConversion.H],
315
    											tmp[ColorSpaceConversion.S],
316
    											tmp[ColorSpaceConversion.L]);
317
    		bufferPancr[iElem] = ((alpha << 24) & 0xff000000) |
318
								((uvw[0] << 16) & 0x00ff0000)|
319
								((uvw[1] << 8) & 0x0000ff00) |
320
								(uvw[2] & 0x000000ff);
321
    	}
322
    	return bufferPancr;
323
    	
324
    }
325
        
326
    /**
327
     * Aplica el filtro sobre el raster pasado pixel a pixel
328
     */
329
    public void execute() {
330
        pre();
331

  
332
        if (exec) {    		
333
        	int[] 			pRGBArrayMultiesp = new int[width];
334
        	int[] 			pRGBArrayPancr = null;
335
        	PixelGrabber	pg = null;
336
        	int 			widthDst = width * relX;
337
        	
338
        	//Para cada linea leemos los valores RGB del image. Aplicamos el algoritmo
339
        	//y escribimos el resultado.
340
        	
341
        	if(method.equals("hsl")){
342
        		float[][]	k = {{-1F, -1F, -1F},{-1F, 8F, -1F},{-1F, -1F, -1F}};
343
        		kernel = new Kernel(k);
344
        		for(int iLine=0;iLine<height ;iLine++){
345
		    		pg = new PixelGrabber(imageMultiespec, 0, iLine, width, 1, pRGBArrayMultiesp, 0, width);
346
		    		try {
347
		                pg.grabPixels();
348
		            } catch (InterruptedException e) {e.printStackTrace();}    
349
		            pRGBArrayPancr = processIHS(pRGBArrayMultiesp, iLine);	    		
350
		    		((BufferedImage)imagePancr).setRGB(0, iLine, width, 1, pRGBArrayPancr, 0, width);
351
		    	}
352
        	}else{
353
		    	for(int iLine=0;iLine<height ;iLine++){
354
		    		pg = new PixelGrabber(imageMultiespec, 0, iLine, width, 1, pRGBArrayMultiesp, 0, width);
355
		    		try {
356
		                pg.grabPixels();
357
		            } catch (InterruptedException e) {e.printStackTrace();}    
358
		            pRGBArrayPancr = processBrovey(pRGBArrayMultiesp, iLine);	    		
359
		    		((BufferedImage)imagePancr).setRGB(0, iLine, width, 1, pRGBArrayPancr, 0, width);
360
		    	}
361
        	}
362
        }
363
        
364
        post();
365
    }
366

  
367
    /* (non-Javadoc)
368
     * @see org.cresques.io.raster.IRasterFilter#process(int, int)
369
     */
370
    public void process(int x, int y) {
371

  
372
    }
373

  
374
    /* (non-Javadoc)
375
     * @see org.cresques.io.raster.IRasterFilter#getInRasterDataType()
376
     */
377
    public int getInRasterDataType() {
378
        return RasterBuf.TYPE_IMAGE;
379
    }
380

  
381
    /* (non-Javadoc)
382
     * @see org.cresques.io.raster.IRasterFilter#getOutRasterDataType()
383
     */
384
    public int getOutRasterDataType() {
385
        return RasterBuf.TYPE_IMAGE;
386
    }
387

  
388
    /* (non-Javadoc)
389
     * @see org.cresques.io.raster.IRasterFilter#getResult(java.lang.String)
390
     */
391
    public Object getResult(String name) {
392
        if (name.equals("raster")) {
393
            return (Object) this.imagePancr;
394
        } else {
395
            return null;
396
        }
397
    }
398

  
399
    /* (non-Javadoc)
400
     * @see org.cresques.io.raster.RasterFilter#processLine(int)
401
     */
402
    public void processLine(int y) {
403
    }
404

  
405
    /* (non-Javadoc)
406
     * @see org.cresques.io.raster.IRasterFilter#post()
407
     */
408
    public void post() {
409
    }
410
}
411

  
0 412

  
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/raster/RasterFilterStackManager.java
24 24
package org.cresques.io.raster;
25 25

  
26 26
import java.lang.reflect.Constructor;
27

  
28 27
import java.util.ArrayList;
29 28
import java.util.Hashtable;
30 29
import java.util.StringTokenizer;
31 30
import java.util.regex.Matcher;
32 31
import java.util.regex.Pattern;
33 32

  
33
import org.cresques.io.GeoRasterFile;
34 34

  
35

  
35 36
/**
36 37
 * Esta clase es de la parte cliente y es la encargada de la gesti?n
37 38
 * de la pila de filtros. Es la que conoce el orden en que se deben apilar
......
59 60
        typeFilters.put("computeminmax", new Integer(2));
60 61
        typeFilters.put("tail", new Integer(3));
61 62
        typeFilters.put("removebands", new Integer(4));
63
        typeFilters.put("sharpening", new Integer(5));
62 64
        init();
63 65
        this.filterStack.setOrder(order);
64 66
    }
......
77 79
     */
78 80
    protected void init() {
79 81
        order = new int[typeFilters.size()];
80
        order[0] = ((Integer) typeFilters.get("computeminmax")).intValue();
81
        order[1] = ((Integer) typeFilters.get("tail")).intValue();
82
        order[2] = ((Integer) typeFilters.get("enhanced")).intValue();
83
        order[3] = ((Integer) typeFilters.get("transparency")).intValue();
84
        order[4] = ((Integer) typeFilters.get("removebands")).intValue();
82
        order[0] = ((Integer) typeFilters.get("sharpening")).intValue();
83
        order[1] = ((Integer) typeFilters.get("computeminmax")).intValue();
84
        order[2] = ((Integer) typeFilters.get("tail")).intValue();
85
        order[3] = ((Integer) typeFilters.get("enhanced")).intValue();
86
        order[4] = ((Integer) typeFilters.get("transparency")).intValue();
87
        order[5] = ((Integer) typeFilters.get("removebands")).intValue();
85 88
    }
86 89

  
87 90
    /**
......
134 137
        switch (filterStack.getDataTypeInFilter(((Integer) typeFilters.get("transparency")).intValue())) {
135 138
        case RasterBuf.TYPE_IMAGE:
136 139
            filtro = new TransparencyImageFilter();
137

  
138 140
            break;
139

  
140 141
        case RasterBuf.TYPE_SHORT:
141 142
        case RasterBuf.TYPE_USHORT:
142 143
        case RasterBuf.TYPE_INT:
143 144
            filtro = new TransparencyShortFilter();
144

  
145 145
            break;
146 146
        }
147 147

  
......
250 250
        switch (filterStack.getDataTypeInFilter(((Integer) typeFilters.get("removebands")).intValue())) {
251 251
        case RasterBuf.TYPE_IMAGE:
252 252
            filtro = new RemoveBandsImageFilter();
253

  
254 253
            break;
255

  
256 254
        case RasterBuf.TYPE_SHORT:
257 255
        case RasterBuf.TYPE_USHORT:
258 256
        case RasterBuf.TYPE_INT:
259 257
            filtro = new RemoveBandsShortFilter();
260

  
261 258
            break;
262 259
        }
263 260

  
......
286 283
        switch (filterStack.getDataTypeInFilter(((Integer) typeFilters.get("tail")).intValue())) {
287 284
        case RasterBuf.TYPE_IMAGE:
288 285
            filtro = new PercentTailTrimImageFilter();
289

  
290 286
            break;
291

  
292 287
        case RasterBuf.TYPE_SHORT:
293 288
        case RasterBuf.TYPE_USHORT:
294 289
        case RasterBuf.TYPE_INT:
295 290
            filtro = new PercentTailTrimShortFilter();
296

  
297 291
            break;
298 292
        }
299 293

  
......
323 317
        switch (filterStack.getDataTypeInFilter(((Integer) typeFilters.get("enhanced")).intValue())) {
324 318
        case RasterBuf.TYPE_IMAGE:
325 319
            filtro = new LinearEnhancementImageFilter();
326

  
327 320
            break;
328

  
329 321
        case RasterBuf.TYPE_SHORT:
330 322
        case RasterBuf.TYPE_USHORT:
331 323
        case RasterBuf.TYPE_INT:
332 324
            filtro = new LinearEnhancementShortFilter();
333

  
334 325
            break;
335 326
        }
336 327

  
......
371 362
            switch (filterStack.getDataTypeInFilter(((Integer) typeFilters.get("computeminmax")).intValue())) {
372 363
            case RasterBuf.TYPE_IMAGE:
373 364
                filtro = new ComputeMinMaxImageFilter();
374

  
375 365
                break;
376

  
377 366
            case RasterBuf.TYPE_SHORT:
378 367
            case RasterBuf.TYPE_USHORT:
379 368
            case RasterBuf.TYPE_INT:
380 369
                filtro = new ComputeMinMaxShortFilter();
381

  
382 370
                break;
383 371
            }
384 372

  
......
391 379
    }
392 380

  
393 381
    /**
382
     * A?ade un filtro ComputeMinMax
383
     * @param files Ficheros que componen la imagen
384
     * @param i	Posici?n de la imagen de refinado dentro de la lista de GeoRasterFile
385
     * @param order	Orden de visualizado de las bandas RGB
386
     * @param alpha	Alpha aplicado a toda la imagen
387
     * @param method M?todo de calculo del refinado
388
     * @param coef	Coeficiente
389
     */
390
    public void addSharpeningFilter(GeoRasterFile[] files, int i, int[] order, int alpha, String method, double coef, int coefBrovey) {
391
    	//Si ya hay un filtro de sharpening nos lo cargamos
392
    	if (filterStack.isActive(((Integer) typeFilters.get("sharpening")).intValue())) {
393
            filterStack.removeFilter(((Integer) typeFilters.get("sharpening")).intValue());
394
        }
395

  
396
        RasterFilter filtro = null;
397

  
398
        switch (filterStack.getDataTypeInFilter(((Integer) typeFilters.get("sharpening")).intValue())) {
399
            case RasterBuf.TYPE_IMAGE:
400
                filtro = new SharpeningImageFilter();
401
                break;
402
            case RasterBuf.TYPE_SHORT:
403
            case RasterBuf.TYPE_USHORT:
404
            case RasterBuf.TYPE_INT:
405
                //filtro = new SharpeningShortFilter();
406
                break;
407
            }
408

  
409
        filtro.addParam("stats", filterStack.getStats());
410
        filtro.addParam("pancromatica", new Integer(i));
411
        filtro.addParam("files", files);
412
        filtro.addParam("order", order);
413
        filtro.addParam("alpha", new Integer(alpha));
414
        filtro.addParam("method", method);
415
        filtro.addParam("coef", new Double(coef));
416
        filtro.addParam("coefBrovey", new Integer(coefBrovey));
417
        filterStack.addFilter(((Integer) typeFilters.get("sharpening")).intValue(),filtro);
418
        
419
        this.controlTypes();
420
    }
421
    
422
    /**
423
     * Obtiene de la pila el primer filtro del tipo solicitado si existe sino devuelve null
424
     * @param type Tipo de filtro
425
     * @return Filtro
426
     */
427
    public RasterFilter getFilter(String type){
428
    	int intType = getTypeFilter(type);
429
    	return filterStack.getByType(intType);
430
    	
431
    }
432
    
433
    /**
394 434
     * Obtiene el tipo de filtro a partir del objeto RasterFilter
395 435
     * @param rasterFilter        Objeto RasterFilter del cual se quiere saber que tipo de filtro contiene
396 436
     * @return        Tipo de filtro seg?n las constantes contenidas en RasterFilterStackManager
......
431 471
            if ((i - 1) >= 0) {
432 472
                //Para el primer filtro comprobamos con el tipo de dato de entrada a la pila
433 473
                if (i == filterStack.lenght()) {
434
                    if (filterStack.getInitDataType() != filterStack.get(i - 1)
435
                                                                        .getInRasterDataType()) {
436
                        String oldClass = filterStack.get(i - 1).getClass()
437
                                                     .toString().substring(filterStack.get(i -
438
                                                                                           1)
439
                                                                                      .getClass()
440
                                                                                      .toString()
441
                                                                                      .lastIndexOf(".") +
442
                                                                           1,
443
                                                                           filterStack.get(i -
444
                                                                                           1)
445
                                                                                      .getClass()
446
                                                                                      .toString()
447
                                                                                      .length());
448
                        Pattern p = Pattern.compile(RasterBuf.typesToString(filterStack.get(i -
449
                                                                                            1)
450
                                                                                       .getInRasterDataType()));
474
                    if (filterStack.getInitDataType() != 
475
                    	filterStack.get(i - 1).getInRasterDataType()) {
476
                        String oldClass = filterStack.get(i - 1).
477
											getClass().
478
                                            toString().
479
											substring(filterStack.get(i - 1).
480
														getClass().
481
														toString().
482
														lastIndexOf(".") +1,
483
                                                        filterStack.get(i - 1).
484
                                                        getClass().
485
                                                        toString().
486
                                                        length());
487
                        Pattern p = Pattern.compile(RasterBuf.typesToString(filterStack.get(i - 1).getInRasterDataType()));
451 488
                        Matcher m = p.matcher(oldClass);
452 489
                        String newClass = m.replaceAll(RasterBuf.typesToString(filterStack.getInitDataType()));
453 490

  
454
                        //System.out.println("==>"+oldClass+" "+newClass);
455 491
                        try {
456 492
                            Class filterClass = Class.forName("org.cresques.io.raster." +
457 493
                                                              newClass);
......
466 502
                    }
467 503

  
468 504
                    //Desde el filtro 2 en adelante se compara la salida de uno con la entrada del siguiente
469
                } else if (filterStack.get(i).getOutRasterDataType() != filterStack.get(i -
470
                                                                                            1)
471
                                                                                       .getInRasterDataType()) {
472
                    String oldClass = filterStack.get(i - 1).getClass()
473
                                                 .toString().substring(filterStack.get(i -
474
                                                                                       1)
475
                                                                                  .getClass()
476
                                                                                  .toString()
477
                                                                                  .lastIndexOf(".") +
478
                                                                       1,
479
                                                                       filterStack.get(i -
480
                                                                                       1)
481
                                                                                  .getClass()
482
                                                                                  .toString()
483
                                                                                  .length());
484
                    Pattern p = Pattern.compile(RasterBuf.typesToString(filterStack.get(i -
485
                                                                                        1)
486
                                                                                   .getInRasterDataType()));
505
                } else if (filterStack.get(i).getOutRasterDataType() != 
506
                			filterStack.get(i - 1).getInRasterDataType()) {
507
                    String oldClass = filterStack.get(i - 1).getClass().
508
                                      toString().substring(filterStack.get(i - 1).
509
                                      						getClass().
510
															toString().
511
															lastIndexOf(".") + 1,
512
                                                            filterStack.get(i - 1).
513
                                                            getClass().
514
                                                            toString().
515
                                                            length());
516
                    Pattern p = Pattern.compile(RasterBuf.typesToString(filterStack.get(i - 1).getInRasterDataType()));
487 517
                    Matcher m = p.matcher(oldClass);
488
                    String newClass = m.replaceAll(RasterBuf.typesToString(filterStack.get(i)
489
                                                                                      .getOutRasterDataType()));
518
                    String newClass = m.replaceAll(RasterBuf.typesToString(filterStack.get(i).getOutRasterDataType()));
490 519

  
491
                    //System.out.println("==>"+oldClass+" "+newClass);
492 520
                    try {
493 521
                        Class filterClass = Class.forName("org.cresques.io.raster." +
494 522
                                                          newClass);
......
660 688
                    getValue(fil).equals("true")) {
661 689
                filters.remove(filteri);
662 690

  
663
                boolean remove = false;
664

  
665 691
                for (int propFilter = 0; propFilter < filters.size();
666 692
                         propFilter++) {
667 693
                    String elem = (String) filters.get(propFilter);
......
711 737
                    getValue(fil).equals("true")) {
712 738
                filters.remove(filteri);
713 739

  
714
                boolean remove = false;
715

  
716 740
                for (int propFilter = 0; propFilter < filters.size();
717 741
                         propFilter++) {
718 742
                    String elem = (String) filters.get(propFilter);
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/GdalWriter.java
23 23
 */
24 24
package org.cresques.io;
25 25

  
26
import java.io.BufferedOutputStream;
27
import java.io.DataOutputStream;
28
import java.io.File;
29
import java.io.FileOutputStream;
30
import java.io.IOException;
31

  
32
import org.cresques.cts.IProjection;
33
import org.cresques.px.PxRaster;
34

  
26 35
import es.gva.cit.jecwcompress.EcwException;
27 36
import es.gva.cit.jgdal.Gdal;
28 37
import es.gva.cit.jgdal.GdalBuffer;
......
32 41
import es.gva.cit.jgdal.GeoTransform;
33 42
import es.gva.cit.jogr.OGRSpatialReference;
34 43

  
35
import org.cresques.px.PxRaster;
36 44

  
37
import java.io.IOException;
38

  
39

  
40 45
/**
41 46
 * Driver para la escritura a trav?s de Gdal.
42 47
 * Puede exportar un fichero de un formato a otro desde un GeoRasterFile
......
55 60
public class GdalWriter extends GeoRasterWriter {
56 61
    static {
57 62
        GeoRasterWriter.registerWriterExtension("tif", GdalWriter.class);
63
        GeoRasterWriter.registerWriterExtension("jpg", GdalWriter.class);
64
        GeoRasterWriter.registerWriterExtension("jpeg", GdalWriter.class);
58 65
    }
59 66

  
60 67
    public final int windowSizeX = 386;
......
66 73
    private Gdal dset_destino = null;
67 74
    private GdalRasterBand rband = null;
68 75
    private String drvType = null; //Tipo de driver
69
    private String[] supportedDrv = { "GTiff" }; //Lista de drivers de escritura que soporta
76
    private String[] supportedDrv = { "GTiff", "JPEG" }; //Lista de drivers de escritura que soporta
70 77
    private GeoTransform geot = null; //Datos de georeferenciaci?n
71 78
    private OGRSpatialReference oSRS; //Datos de proyecci?n						
72 79
    private GdalBuffer buf = null; //Buffer de origen de gdal
......
86 93
    public GdalWriter(String drvType) {
87 94
        this.support = new GdalSupportOptions(drvType);
88 95
        this.ident = this.drvType = drvType;
89
        this.driver = "tif";
96
        if(drvType.equals("GTiff"))
97
        	this.driver = "tif";
98
        else if(drvType.equals("JPEG"))
99
        	this.driver = "jpg";
90 100
        this.support.setBlockSize(64);
91 101
        this.support.setPhotometric("RGB");
92 102
        this.support.setInterleave("BAND");
......
108 118
                      String drvType) throws GdalException, IOException {
109 119
        this.support = new GdalSupportOptions(drvType);
110 120
        this.ident = this.drvType = drvType;
111
        this.driver = "tif";
112

  
121
        if(drvType.equals("GTiff"))
122
        	this.driver = "tif";
123
        else if(drvType.equals("JPEG"))
124
        	this.driver = "jpg";
125
        
113 126
        this.outfilename = outfilename;
114 127
        this.infilename = infilename;
115 128
        this.currentRaster = raster;
......
134 147

  
135 148
        nBands = currentRaster.getBandCount();
136 149

  
137
        this.support.setBlockSize(currentRaster.getBlockSize());
150
        this.support.setBlockSize(64/*currentRaster.getBlockSize()*/);
138 151

  
139 152
        if ((sizeWindowX < 0) || (sizeWindowY < 0)) {
140 153
            throw new IOException("Tama?o del fichero de salida erroneo.");
......
187 200
               throws GdalException, IOException {
188 201
        this.support = new GdalSupportOptions(drvType);
189 202
        this.ident = this.drvType = drvType;
190
        this.driver = "tif";
203
        if(drvType.equals("GTiff"))
204
        	this.driver = "tif";
205
        else if(drvType.equals("JPEG"))
206
        	this.driver = "jpg";
191 207

  
192 208
        this.dataWriter = dataWriter;
193 209
        this.outfilename = outFilename;
......
286 302
        }
287 303

  
288 304
        //Obtenemos el driver y creamos el dataset del destino
305
        drv = Gdal.getDriverByName(drvType);
289 306
        
290
        drv = Gdal.getDriverByName(drvType);
291

  
307
        /*try{
308
        	drv = Gdal.getDriverByName("JPEG");
309
        	Gdal src = new Gdal();
310
        	src.open("/home/nacho/imagenes/q101866.tif", 0);
311
        	drv.createCopy( "/home/nacho/outgvGIG.jpg", src, false );
312
        }catch(IOException e){}
313
        return;*/
314
        
292 315
        //System.out.println("++++++>"+params.length);
293 316
        //for(int i=0;i<params.length;i++)System.out.println("=====>"+params[i]);
317
        
294 318
        if (dset_destino != null) {
295 319
            dset_destino.close();
296 320
            dset_destino = null;
......
513 537
    }
514 538

  
515 539
    /**
540
     * Realiza una copia en el formato especificado.
541
     * @throws IOException
542
     */
543
    public static void createCopy(GdalDriver driverDst, String dst, String src, boolean bstrict, String[] params, IProjection proj) throws IOException, GdalException {
544
        if (dst == null || src == null) {
545
            throw new IOException("No se ha asignado un fichero de entrada.");
546
        }
547

  
548
        GdalFile gdalFile = new GdalFile(proj, src);
549
        driverDst.createCopy(dst, gdalFile.file, bstrict, params);
550
        if(dst.endsWith(".jpg") || dst.endsWith(".jpeg"))
551
        	GdalWriter.createWorldFile(dst, gdalFile);
552
        gdalFile.close();
553
    }
554
    
555
    /**
556
	 * Crea un fichero de georeferenciaci?n
557
	 * @param img
558
	 * @param name
559
	 * @return
560
	 * @throws IOException
561
	 */
562
	private static void createWorldFile(String name, GdalFile gdalFile) throws IOException{
563
    	File tfw = null;
564
	    
565
    	String extWorldFile = ".wld";
566
	    if(name.endsWith("tif"))
567
	    	extWorldFile = ".tfw";
568
	    if(name.endsWith("jpg") || name.endsWith("jpeg"))
569
	    	extWorldFile = ".jpgw";
570
	    	    	
571
	    tfw = new File(name.substring(0, name.lastIndexOf(".")) + extWorldFile);
572
	    
573
	    //Generamos un world file para gdal
574
	    DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(tfw)) );
575
	    dos.writeBytes((gdalFile.getExtent().getMax().getX() - gdalFile.getExtent().getMin().getX())/gdalFile.getWidth()+"\n");
576
	    dos.writeBytes("0.0\n");
577
	    dos.writeBytes("0.0\n");
578
	    dos.writeBytes((gdalFile.getExtent().getMax().getY() - gdalFile.getExtent().getMin().getY())/gdalFile.getHeight()+"\n");
579
	    dos.writeBytes(""+gdalFile.getExtent().getMin().getX()+"\n");
580
	    dos.writeBytes(""+gdalFile.getExtent().getMin().getY()+"\n");
581
	    dos.close();    
582
	}
583

  
584
    
585
    /**
516 586
     * Realiza la escritura de datos con los datos que le pasa el cliente.
517 587
     * @throws IOException
518 588
     */
trunk/libraries/libCq CMS for java.old/src/org/cresques/px/PxRaster.java
213 213
            geoFile = listFiles;
214 214
        } else {
215 215
            System.err.println("PxRaster.addFile(): Imagen no cargada.");
216

  
217 216
            return;
218 217
        }
219 218
    }
......
778 777
                    stackManager.addTailFilter(this.percentFilterInit, 0D, false);
779 778
                }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff