Revision 13130 trunk/libraries/libCresques/src/org/cresques/io/MrSidFile.java

View differences:

MrSidFile.java
51 51
 * @author Nacho Brodin (brodin_ign@gva.es)
52 52
 */
53 53
class MrSidNative extends MrSIDImageReader {
54
    static boolean WITH_OVERVIEWS = true;
54
		static boolean WITH_OVERVIEWS = true;
55 55

  
56
    /**
57
     * Contorno en coordenadas geogr?ficas. (y Extent del raster).
58
     */
59
    public Contour 					esq = new Contour();
60
    public int 						width = 0;
61
    public int 						height = 0;
62
    public double 					originX = 0D;
63
    public double 					originY = 0D;
64
    public String 					version = "";
65
    public LTIMetadataDatabase 		metadata;
66
    public LTIPixel 				pixel = null;
67
    private int 					alpha = 0;
68
    protected int 					rBandNr = 1;
69
    protected int 					gBandNr = 2;
70
    protected int 					bBandNr = 3;
71
    protected byte[] 				bandR;
72
    protected byte[] 				bandG;
73
    protected byte[] 				bandB;
74
    private int 					dataType = LTIDataType.LTI_DATATYPE_UINT8;
56
		/**
57
		 * Contorno en coordenadas geogr?ficas. (y Extent del raster).
58
		 */
59
		public Contour 					esq = new Contour();
60
		public int 						width = 0;
61
		public int 						height = 0;
62
		public double 					originX = 0D;
63
		public double 					originY = 0D;
64
		public String 					version = "";
65
		public LTIMetadataDatabase 		metadata;
66
		public LTIPixel 				pixel = null;
67
		private int 					alpha = 0;
68
		protected int 					rBandNr = 1;
69
		protected int 					gBandNr = 2;
70
		protected int 					bBandNr = 3;
71
		protected byte[] 				bandR;
72
		protected byte[] 				bandG;
73
		protected byte[] 				bandB;
74
		private int 					dataType = LTIDataType.LTI_DATATYPE_UINT8;
75 75

  
76
    //View
77
    private double 					zoomoverview = 0.0;
78
    private int 					eColorSpace;
79
    private int 					eSampleType;
80
    private int 					noverviews;
81
    public int 						xini;
82
    public int 						yini;
83
    /**
84
     * Ancho y alto de la overview
85
     */
86
    public int 						anchoOver;
87
    public int 						altoOver;
88
    public int 						blocksize = 1;
89
    /**
90
     * N?mero de bandas de la imagen
91
     */
92
    public int 						nbands;
93
    /**
94
     * N?mero de overview actualmente seleccionada
95
     */
96
    private int 					currentOverview = -1;
97
    /**
98
     * Posici?n de la esquina superior izquierda en coordenadas pixel
99
     */
100
    private double 					currentViewY = -1;
101
    private double 					currentViewX = 0D;
102
    /**
103
     * Ancho y alto de la im?gen (pixeles en pantalla)
104
     */
105
    private int 					currentViewWidth = -1;
106
    private int 					currentViewHeight = -1;
107
    /**
108
     * Ancho y alto de la imagen completa en pixeles
109
     */
110
    private int 					currentFullWidth = -1;
111
    private int 					currentFullHeight = -1;
112
    /**
113
     * Escala del viewport en X e Y
114
     */
115
    private double 					viewportScaleX = 0D;
116
    private double 					viewportScaleY = 0D;
117
    /**
118
     * ?ltimo extent de la ventana seleccionada por el usuario. Este extent corresponde al de la
119
     * imagen, no al del viewport de la vista.
120
     */
121
    private double[]				currentImageView = new double[4]; 
76
		//View
77
		private double 					zoomoverview = 0.0;
78
		private int 					eColorSpace;
79
		private int 					eSampleType;
80
		private int 					noverviews;
81
		public int 						xini;
82
		public int 						yini;
83
		/**
84
		 * Ancho y alto de la overview
85
		 */
86
		public int 						anchoOver;
87
		public int 						altoOver;
88
		public int 						blocksize = 1;
89
		/**
90
		 * N?mero de bandas de la imagen
91
		 */
92
		public int 						nbands;
93
		/**
94
		 * Posici?n de la esquina superior izquierda en coordenadas pixel
95
		 */
96
		private double 					currentViewY = -1;
97
		private double 					currentViewX = 0D;
98
		/**
99
		 * Ancho y alto de la im?gen (pixeles en pantalla)
100
		 */
101
		private int 					currentViewWidth = -1;
102
		private int 					currentViewHeight = -1;
103
		/**
104
		 * Ancho y alto de la imagen completa en pixeles
105
		 */
106
		private int 					currentFullWidth = -1;
107
		private int 					currentFullHeight = -1;
108
		/**
109
		 * Escala del viewport en X e Y
110
		 */
111
		private double 					viewportScaleX = 0D;
112
		private double 					viewportScaleY = 0D;
113
		/**
114
		 * ?ltimo extent de la ventana seleccionada por el usuario. Este extent corresponde al de la
115
		 * imagen, no al del viewport de la vista.
116
		 */
117
		private double[]				currentImageView = new double[4];
122 118

  
123
    /**
124
     * Constructor
125
     * @param fName
126
     * @throws MrSIDException
127
     * @throws IOException
128
     */
129
    public MrSidNative(String fName) throws MrSIDException, IOException {
130
        super(fName);
131
        init(fName);
132
    }
133
    
134
    /**
135
     * Inicializa las variables de instancia con los valores de la imagen
136
     * @param fName
137
     * @throws MrSIDException
138
     * @throws IOException
139
     */
140
    private void init(String fName) throws MrSIDException, IOException {
141
        this.initialize();
119
		/**
120
		 * Constructor
121
		 * @param fName
122
		 * @throws MrSIDException
123
		 * @throws IOException
124
		 */
125
		public MrSidNative(String fName) throws MrSIDException, IOException {
126
				super(fName);
127
				init(fName);
128
		}
142 129

  
143
        String ext = fName.toLowerCase().substring(fName.lastIndexOf('.') + 1);
130
		/**
131
		 * Inicializa las variables de instancia con los valores de la imagen
132
		 * @param fName
133
		 * @throws MrSIDException
134
		 * @throws IOException
135
		 */
136
		private void init(String fName) throws MrSIDException, IOException {
137
				this.initialize();
144 138

  
145
        width = this.getWidth();
146
        height = this.getHeight();
147
        eSampleType = this.getDataType();
148
        nbands = this.getNumBands();
149
        eColorSpace = this.getColorSpace();
150
        noverviews = this.getNumLevels();
139
				width = this.getWidth();
140
				height = this.getHeight();
141
				eSampleType = this.getDataType();
142
				nbands = this.getNumBands();
143
				eColorSpace = this.getColorSpace();
144
				noverviews = this.getNumLevels();
151 145

  
152
        metadata = this.getMetadata();
146
				metadata = this.getMetadata();
153 147

  
154
        double ox = 0D;
155
        double oy = 0D;
156
        double resx = 0D;
157
        double resy = 0D;
148
				double ox = 0D;
149
				double oy = 0D;
150
				double resx = 0D;
151
				double resy = 0D;
158 152

  
159
        LTIGeoCoord geoc = this.getGeoCoord();
153
				LTIGeoCoord geoc = this.getGeoCoord();
160 154

  
161
        ox = geoc.getX();
162
        oy = geoc.getY();
163
        resx = geoc.getXRes();
164
        resy = geoc.getYRes();
155
				ox = geoc.getX();
156
				oy = geoc.getY();
157
				resx = geoc.getXRes();
158
				resy = geoc.getYRes();
165 159

  
166
        System.out.println("Origin = (" + ox + "," + oy + ")");
167
        System.out.println("Pixel Size = (" + resx + "," + resy + ")");
168
        esq.add(new Point2D.Double(ox, oy));
169
        esq.add(new Point2D.Double(ox + (resx * width), oy));
170
        esq.add(new Point2D.Double(ox, oy + (resy * height)));
171
        esq.add(new Point2D.Double(ox + (resx * width), oy + (resy * height)));
160
				System.out.println("Origin = (" + ox + "," + oy + ")");
161
				System.out.println("Pixel Size = (" + resx + "," + resy + ")");
162
				esq.add(new Point2D.Double(ox, oy));
163
				esq.add(new Point2D.Double(ox + (resx * width), oy));
164
				esq.add(new Point2D.Double(ox, oy + (resy * height)));
165
				esq.add(new Point2D.Double(ox + (resx * width), oy + (resy * height)));
172 166

  
173
        blocksize = this.getStripHeight();
174
        System.out.println("StripHeight = (" + blocksize + ")");
175
    }
167
				blocksize = this.getStripHeight();
168
				System.out.println("StripHeight = (" + blocksize + ")");
169
		}
176 170

  
177
    /**
178
     * Asigna el valor de Alpha
179
     * @param a        alpha
180
     */
181
    public void setAlpha(int a) {
182
        alpha = a;
183
    }
171
		/**
172
		 * Asigna el valor de Alpha
173
		 * @param a        alpha
174
		 */
175
		public void setAlpha(int a) {
176
				alpha = a;
177
		}
184 178

  
185
    /**
186
     * Asigna el tipo de datos
187
     * @param dt        tipo de datos
188
     */
189
    public void setDataType(int dt) {
190
        dataType = dt;
191
    }
179
		/**
180
		 * Asigna el tipo de datos
181
		 * @param dt        tipo de datos
182
		 */
183
		public void setDataType(int dt) {
184
				dataType = dt;
185
		}
192 186

  
193
    /**
194
     * Obtiene un punto 2D con las coordenadas del raster a partir de uno en coordenadas
195
     * del punto real.
196
     * @param pt        punto en coordenadas del punto real
197
     * @return        punto en coordenadas del raster
198
     */
199
    public Point2D worldToRaster(Point2D pt) {
200
        double x = (((double) currentFullWidth) / (esq.maxX - esq.minX)) * (pt.getX() - esq.minX);
201
        double y = (((double) currentFullHeight) / (esq.maxY - esq.minY)) * (esq.maxY - pt.getY());
202
        Point2D ptRes = new Point2D.Double(x, y);
203
        return ptRes;
204
    }
187
		/**
188
		 * Obtiene un punto 2D con las coordenadas del raster a partir de uno en coordenadas
189
		 * del punto real.
190
		 * @param pt        punto en coordenadas del punto real
191
		 * @return        punto en coordenadas del raster
192
		 */
193
		public Point2D worldToRaster(Point2D pt) {
194
				double x = (((double) currentFullWidth) / (esq.maxX - esq.minX)) * (pt.getX() - esq.minX);
195
				double y = (((double) currentFullHeight) / (esq.maxY - esq.minY)) * (esq.maxY - pt.getY());
196
				Point2D ptRes = new Point2D.Double(x, y);
197
				return ptRes;
198
		}
205 199

  
206
    /**
207
     * Calcula el overview a usar de la imagen y el viewport a partir del ancho, alto y
208
     * coordenadas del mundo real
209
     * @param dWorldTLX        Coordenada X superior izquierda
210
     * @param dWorldTLY        Coordenada Y superior izquierda
211
     * @param dWorldBRX        Coordenada X inferior derecha
212
     * @param dWorldBRY        Coordenada Y inferior derecha
213
     * @param nWidth        ancho
214
     * @param nHeight        alto
215
     */
216
    public void setView(double dWorldTLX, double dWorldTLY, double dWorldBRX,
217
                        double dWorldBRY, int nWidth, int nHeight) {
218
    	currentImageView[0] = dWorldTLX;
219
    	currentImageView[1] = dWorldTLY;
220
    	currentImageView[2] = dWorldBRX;
221
    	currentImageView[3] = dWorldBRY;
222
    	
223
        //Ancho y alto de la im?gen en pixeles (pixeles de la overview)
224
        currentFullWidth = width;
225
        currentFullHeight = height;
200
		/**
201
		 * Calcula el overview a usar de la imagen y el viewport a partir del ancho, alto y
202
		 * coordenadas del mundo real
203
		 * @param dWorldTLX        Coordenada X superior izquierda
204
		 * @param dWorldTLY        Coordenada Y superior izquierda
205
		 * @param dWorldBRX        Coordenada X inferior derecha
206
		 * @param dWorldBRY        Coordenada Y inferior derecha
207
		 * @param nWidth        ancho
208
		 * @param nHeight        alto
209
		 */
210
		public void setView(double dWorldTLX, double dWorldTLY, double dWorldBRX,
211
												double dWorldBRY, int nWidth, int nHeight) {
212
			currentImageView[0] = dWorldTLX;
213
			currentImageView[1] = dWorldTLY;
214
			currentImageView[2] = dWorldBRX;
215
			currentImageView[3] = dWorldBRY;
226 216

  
227
        //Ventana de la imagen. (en tama?o completo)
228
        //tl->esq sup izda en pixeles
229
        //br->esq inf der en pixeles
230
        Point2D tl = worldToRaster(new Point2D.Double(dWorldTLX, dWorldTLY));
231
        Point2D br = worldToRaster(new Point2D.Double(dWorldBRX, dWorldBRY));
217
				//Ancho y alto de la im?gen en pixeles (pixeles de la overview)
218
				currentFullWidth = width;
219
				currentFullHeight = height;
232 220

  
233
        //Ancho y alto de la im?gen (pixeles en pantalla)
234
        currentViewWidth = nWidth;
235
        currentViewHeight = nHeight;
221
				//Ventana de la imagen. (en tama?o completo)
222
				//tl->esq sup izda en pixeles
223
				//br->esq inf der en pixeles
224
				Point2D tl = worldToRaster(new Point2D.Double(dWorldTLX, dWorldTLY));
225
				Point2D br = worldToRaster(new Point2D.Double(dWorldBRX, dWorldBRY));
236 226

  
237
        //Posici?n de la esquina superior izquierda en coordenadas pixel
238
        currentViewX = tl.getX();
239
        currentViewY = tl.getY();
227
				//Ancho y alto de la im?gen (pixeles en pantalla)
228
				currentViewWidth = nWidth;
229
				currentViewHeight = nHeight;
240 230

  
241
        //Escala de la vista en X e Y
242
        viewportScaleX = (double) currentViewWidth / (br.getX() - tl.getX());
243
        viewportScaleY = (double) currentViewHeight / (br.getY() - tl.getY());
244
       
245
        try {
246
            // calcula el overview a usar
247
            int[] dims = null;
248
            double zoom = 1.0;
249
            zoomoverview = 1.0;
250
            currentOverview = -1;
231
				//Posici?n de la esquina superior izquierda en coordenadas pixel
232
				currentViewX = tl.getX();
233
				currentViewY = tl.getY();
251 234

  
252
            if (WITH_OVERVIEWS && ((noverviews - 1) > 0)) {
253
                for (int i = (noverviews - 1); i > 0; i--) {
254
                    zoom = LTIUtils.levelToMag(i);
255
                    dims = this.getDimsAtMag(zoom);
235
				//Escala de la vista en X e Y
236
				viewportScaleX = (double) currentViewWidth / (br.getX() - tl.getX());
237
				viewportScaleY = (double) currentViewHeight / (br.getY() - tl.getY());
256 238

  
257
                    if (dims[0] > (this.getWidth() * viewportScaleX)) {
258
                        currentOverview = i;
259
                        zoomoverview = zoom;
260
                        viewportScaleX /= zoomoverview;
261
                        viewportScaleY /= zoomoverview;
262
                        currentFullWidth = dims[0];
263
                        currentFullHeight = dims[1];
264
                        tl = worldToRaster(new Point2D.Double(dWorldTLX, dWorldTLY));
265
                        currentViewX = tl.getX();
266
                        currentViewY = tl.getY();
239
				try {
240
						// calcula el overview a usar
241
						int[] dims = null;
242
						double zoom = 1.0;
243
						zoomoverview = 1.0;
267 244

  
268
                        break;
269
                    }
270
                }
271
            }
245
						if (WITH_OVERVIEWS && ((noverviews - 1) > 0)) {
246
								for (int i = (noverviews - 1); i > 0; i--) {
247
										zoom = LTIUtils.levelToMag(i);
248
										dims = this.getDimsAtMag(zoom);
272 249

  
273
            setDataType(eSampleType);
274
        } catch (MrSIDException e) {
275
            e.printStackTrace();
276
        }
277
    }
250
										if (dims[0] > (this.getWidth() * viewportScaleX)) {
251
												zoomoverview = zoom;
252
												viewportScaleX /= zoomoverview;
253
												viewportScaleY /= zoomoverview;
254
												currentFullWidth = dims[0];
255
												currentFullHeight = dims[1];
256
												tl = worldToRaster(new Point2D.Double(dWorldTLX, dWorldTLY));
257
												currentViewX = tl.getX();
258
												currentViewY = tl.getY();
278 259

  
279
    /**
280
     * Muestra alguna informaci?n para la depuraci?n
281
     */
282
    void pintaInfo() {
283
        try {
284
            System.out.println("GeoTransform:");
260
												break;
261
										}
262
								}
263
						}
285 264

  
286
            LTIGeoCoord geoc = this.getGeoCoord();
265
						setDataType(eSampleType);
266
				} catch (MrSIDException e) {
267
						e.printStackTrace();
268
				}
269
		}
287 270

  
288
            System.out.println("  param[0]=" + geoc.getX());
289
            System.out.println("  param[0]=" + geoc.getY());
290
            System.out.println("  param[0]=" + geoc.getXRes());
291
            System.out.println("  param[0]=" + geoc.getYRes());
292
            System.out.println("  param[0]=" + geoc.getXRot());
293
            System.out.println("  param[0]=" + geoc.getYRot());
294
            System.out.println("Metadata:");
271
		/**
272
		 * Muestra alguna informaci?n para la depuraci?n
273
		 */
274
		void pintaInfo() {
275
				try {
276
						System.out.println("GeoTransform:");
295 277

  
296
            LTIMetadataDatabase metadata = this.getMetadata();
278
						LTIGeoCoord geoc = this.getGeoCoord();
297 279

  
298
            for (int i = 0; i < metadata.getIndexCount(); i++) {
299
                LTIMetadataRecord rec = null;
300
                rec = metadata.getDataByIndex(i);
301
                System.out.println(rec.getTagName());
280
						System.out.println("  param[0]=" + geoc.getX());
281
						System.out.println("  param[0]=" + geoc.getY());
282
						System.out.println("  param[0]=" + geoc.getXRes());
283
						System.out.println("  param[0]=" + geoc.getYRes());
284
						System.out.println("  param[0]=" + geoc.getXRot());
285
						System.out.println("  param[0]=" + geoc.getYRot());
286
						System.out.println("Metadata:");
302 287

  
303
                if (rec.isScalar()) {
304
                    System.out.println(rec.getScalarData());
305
                } else if (rec.isVector()) {
306
                    String[] s = rec.getVectorData();
288
						LTIMetadataDatabase metadata = this.getMetadata();
307 289

  
308
                    for (int j = 0; j < s.length; j++)
309
                        System.out.println("V" + j + "->" + s[j]);
310
                } else if (rec.isArray()) {
311
                    String[] s = rec.getArrayData();
290
						for (int i = 0; i < metadata.getIndexCount(); i++) {
291
								LTIMetadataRecord rec = null;
292
								rec = metadata.getDataByIndex(i);
293
								System.out.println(rec.getTagName());
312 294

  
313
                    for (int j = 0; j < s.length; j++)
314
                        System.out.println("A" + j + "->" + s[j]);
315
                } else {
316
                    System.out.println("");
317
                }
318
            }
319
        } catch (MrSIDException e) {
320
            // TODO Auto-generated catch block
321
            e.printStackTrace();
322
        }
323
    }
295
								if (rec.isScalar()) {
296
										System.out.println(rec.getScalarData());
297
								} else if (rec.isVector()) {
298
										String[] s = rec.getVectorData();
324 299

  
325
    void pintaPaleta() {
326
    }
300
										for (int j = 0; j < s.length; j++)
301
												System.out.println("V" + j + "->" + s[j]);
302
								} else if (rec.isArray()) {
303
										String[] s = rec.getArrayData();
327 304

  
328
    public LTISceneBuffer readBuffer(int x, int y, int SceneWidth, int SceneHeight)throws MrSIDException{
329
    	LTISceneBuffer buffer = null;
330
    	LTIScene scene = new LTIScene(x, y, SceneWidth, SceneHeight, zoomoverview);
331
    	buffer = new LTISceneBuffer(pixel, SceneWidth, SceneHeight, true);
332
    	((LTIImageStage) this).read(scene, buffer);
333
    	return buffer;
334
    }
335
    
336
    /**
337
     * Lee la escena de la imagen correspondiente a la vista seleccionada con
338
     * currentView a trav?s de la libreria de MrSid. Esta escena es cargada sobre
339
     * un buffer y asignada al par?metro de salida.
340
     * @param line        Escena leida
341
     * @throws MrSIDException Lanzada si ocurre un error en la lectura de la escena
342
     */
343
    public void readScene(int[] line) throws MrSIDException {
344
    	//Posici?n de inicio de la escena en entero para la petici?n a la libreria
345
        int x = (int) Math.floor(currentViewX);
346
        int y = (int) Math.floor(currentViewY);
347
        //Ancho y alto de la escena en pixeles
348
        int SceneWidth = 0;
349
        int SceneHeight = 0;
305
										for (int j = 0; j < s.length; j++)
306
												System.out.println("A" + j + "->" + s[j]);
307
								} else {
308
										System.out.println("");
309
								}
310
						}
311
				} catch (MrSIDException e) {
312
						// TODO Auto-generated catch block
313
						e.printStackTrace();
314
				}
315
		}
350 316

  
351
        try {
317
		void pintaPaleta() {
318
		}
319

  
320
		public LTISceneBuffer readBuffer(int x, int y, int SceneWidth, int SceneHeight)throws MrSIDException{
321
			LTISceneBuffer buffer = null;
322
			LTIScene scene = new LTIScene(x, y, SceneWidth, SceneHeight, zoomoverview);
323
			buffer = new LTISceneBuffer(pixel, SceneWidth, SceneHeight, true);
324
			((LTIImageStage) this).read(scene, buffer);
325
			return buffer;
326
		}
327

  
328
		/**
329
		 * Lee la escena de la imagen correspondiente a la vista seleccionada con
330
		 * currentView a trav?s de la libreria de MrSid. Esta escena es cargada sobre
331
		 * un buffer y asignada al par?metro de salida.
332
		 * @param line        Escena leida
333
		 * @throws MrSIDException Lanzada si ocurre un error en la lectura de la escena
334
		 */
335
		public void readScene(int[] line) throws MrSIDException {
336
			//Posici?n de inicio de la escena en entero para la petici?n a la libreria
337
				int x = (int) Math.floor(currentViewX);
338
				int y = (int) Math.floor(currentViewY);
339
				//Ancho y alto de la escena en pixeles
340
				int SceneWidth = 0;
341
				int SceneHeight = 0;
342

  
343
				try {
352 344
			SceneWidth = (int) Math.ceil((((double) currentViewWidth) / viewportScaleX) + 1);
353 345
			if (SceneWidth > currentFullWidth)
354 346
				SceneWidth = currentFullWidth;
355 347
			SceneHeight = (int) Math.ceil((((double) currentViewHeight) / viewportScaleY) + 1);
356
		    if (SceneHeight > currentFullHeight)
357
		       	SceneHeight = currentFullHeight;
358
          
359
            if (SceneWidth == 0) 
360
                SceneWidth = 1;
361
           
362
            if (SceneHeight == 0)
363
                SceneHeight = 1;
364
            
365
            if (pixel == null)
366
                pixel = new LTIPixel(eColorSpace, nbands, eSampleType);
367
            
368
            LTISceneBuffer buffer = null;
369
            
370
            boolean  sizeOk = false;
348
				if (SceneHeight > currentFullHeight)
349
						 SceneHeight = currentFullHeight;
350

  
351
						if (SceneWidth == 0)
352
								SceneWidth = 1;
353

  
354
						if (SceneHeight == 0)
355
								SceneHeight = 1;
356

  
357
						if (pixel == null)
358
								pixel = new LTIPixel(eColorSpace, nbands, eSampleType);
359

  
360
						LTISceneBuffer buffer = null;
361

  
362
						boolean  sizeOk = false;
371 363
			while (!sizeOk){
372 364
				sizeOk = true;
373
	            try {
374
	            	buffer = readBuffer(x, y, SceneWidth, SceneHeight);
375
	            } catch (MrSIDException ex) {
376
	            	SceneWidth-- ;
377
	            	try{
378
	            		buffer = readBuffer(x, y, SceneWidth, SceneHeight);
379
	            	} catch (MrSIDException ex1) {
380
	            		SceneWidth++;
381
	            		SceneHeight--;
382
	                	try{
383
	                		buffer = readBuffer(x, y, SceneWidth, SceneHeight);
384
	                	} catch (MrSIDException ex2) {
385
	                		SceneWidth-- ;
386
	                    	try{
387
	                    		buffer = readBuffer(x, y, SceneWidth, SceneHeight);
388
	                    	} catch (MrSIDException ex3) {
389
	                    		sizeOk = false;
390
	                    	}
391
	                	}
392
	            	}
393
	            }
365
							try {
366
								buffer = readBuffer(x, y, SceneWidth, SceneHeight);
367
							} catch (MrSIDException ex) {
368
								SceneWidth-- ;
369
								try{
370
									buffer = readBuffer(x, y, SceneWidth, SceneHeight);
371
								} catch (MrSIDException ex1) {
372
									SceneWidth++;
373
									SceneHeight--;
374
										try{
375
											buffer = readBuffer(x, y, SceneWidth, SceneHeight);
376
										} catch (MrSIDException ex2) {
377
											SceneWidth-- ;
378
												try{
379
													buffer = readBuffer(x, y, SceneWidth, SceneHeight);
380
												} catch (MrSIDException ex3) {
381
													sizeOk = false;
382
												}
383
										}
384
								}
385
							}
394 386
			}
395
            
396
            			
397
            if ((dataType == LTIDataType.LTI_DATATYPE_UINT8) ||
398
                    (dataType == LTIDataType.LTI_DATATYPE_SINT8) ||
399
                    (dataType == LTIDataType.LTI_DATATYPE_SINT16) ||
400
                    (dataType == LTIDataType.LTI_DATATYPE_SINT32) ||
401
                    (dataType == LTIDataType.LTI_DATATYPE_UINT16) ||
402
                    (dataType == LTIDataType.LTI_DATATYPE_UINT32)) {
403
                int kd;
404
                int k;
405
                double scaleX = 1 / viewportScaleX;
406
                double scaleY = 1 / viewportScaleY;
407
                int alpha = (this.alpha & 0xff) << 24;
408
                             
409
                if (rBandNr == 1) {
410
                    bandR = buffer.buf1;
411
                } else if (rBandNr == 2) {
412
                    bandR = buffer.buf2;
413
                } else if (rBandNr == 3) {
414
                    bandR = buffer.buf3;
415
                }
416 387

  
417
                if (gBandNr == 1) {
418
                    bandG = buffer.buf1;
419
                } else if (gBandNr == 2) {
420
                    bandG = buffer.buf2;
421
                } else if (gBandNr == 3) {
422
                    bandG = buffer.buf3;
423
                }
424 388

  
425
                if (bBandNr == 1) {
426
                    bandB = buffer.buf1;
427
                } else if (bBandNr == 2) {
428
                    bandB = buffer.buf2;
429
                } else if (bBandNr == 3) {
430
                    bandB = buffer.buf3;
431
                }
432
                
433
                //Desplazamiento para la X y la Y leidas. Estas tienen efecto cuando un pixel no empieza a visualizarse
434
                //justo en su esquina superior izquierda y tiene que ser cortado en la visualizaci?n.
435
                double offsetX = Math.abs(currentViewX - ((int)currentViewX));
436
                double offsetY = Math.abs(currentViewY - ((int)currentViewY));
437
                for (int y1 = 0; y1 < currentViewHeight; y1++){
438
                   for (int x1 = 0; x1 < currentViewWidth; x1++) {
439
                      kd = (y1 * currentViewWidth) + x1;
440
                      k = (((int) ((y1 * scaleY) + offsetY)) * SceneWidth) + 
441
                      		(int) ((x1 * scaleX) + offsetX);
389
						if ((dataType == LTIDataType.LTI_DATATYPE_UINT8) ||
390
										(dataType == LTIDataType.LTI_DATATYPE_SINT8) ||
391
										(dataType == LTIDataType.LTI_DATATYPE_SINT16) ||
392
										(dataType == LTIDataType.LTI_DATATYPE_SINT32) ||
393
										(dataType == LTIDataType.LTI_DATATYPE_UINT16) ||
394
										(dataType == LTIDataType.LTI_DATATYPE_UINT32)) {
395
								int kd;
396
								int k;
397
								double scaleX = 1 / viewportScaleX;
398
								double scaleY = 1 / viewportScaleY;
399
								int alpha = (this.alpha & 0xff) << 24;
442 400

  
443
                      try {
444
                            line[kd] = alpha + ((0xff & bandR[k]) << 16) + ((0xff & bandG[k]) << 8) + (0xff & bandB[k]);
445
                      } catch (java.lang.ArrayIndexOutOfBoundsException e) {
446
                      }
447
                   }
448
                }
449
            }
450
            
451
            buffer = null;
452
        } catch (MrSIDException e) {
453
            e.printStackTrace();
454
        }
455
    }
401
								if (rBandNr == 1) {
402
										bandR = buffer.buf1;
403
								} else if (rBandNr == 2) {
404
										bandR = buffer.buf2;
405
								} else if (rBandNr == 3) {
406
										bandR = buffer.buf3;
407
								}
456 408

  
457
    /**
458
     * Lee una ventana de la imagen y devuelve un buffer de bytes
459
     * @param ulX        Coordenada X de la esquina superior izquierda
460
     * @param ulY        Coordenada Y de la esquina superior izquierda
461
     * @param sizeX        Tama?o X de la imagen
462
     * @param sizeY        Tama?o Y de la image
463
     * @param band        N?mero de bandas
464
     * @return        buffer con la ventana leida
465
     * @throws MrSIDException
466
     */
467
    public byte[] getWindow(int ulX, int ulY, int sizeX, int sizeY, int band)
468
                     throws MrSIDException {
469
        if (pixel == null) {
470
            pixel = new LTIPixel(eColorSpace, nbands, eSampleType);
471
        }
409
								if (gBandNr == 1) {
410
										bandG = buffer.buf1;
411
								} else if (gBandNr == 2) {
412
										bandG = buffer.buf2;
413
								} else if (gBandNr == 3) {
414
										bandG = buffer.buf3;
415
								}
472 416

  
473
        LTIScene scene = new LTIScene(ulX, ulY, sizeX, sizeY, 1.0);
474
        LTISceneBuffer buffer = new LTISceneBuffer(pixel, sizeX, sizeY, true);
475
        ((LTIImageStage) this).read(scene, buffer);
417
								if (bBandNr == 1) {
418
										bandB = buffer.buf1;
419
								} else if (bBandNr == 2) {
420
										bandB = buffer.buf2;
421
								} else if (bBandNr == 3) {
422
										bandB = buffer.buf3;
423
								}
476 424

  
477
        if (band == 1) {
478
            return buffer.buf1;
479
        } else if (band == 2) {
480
            return buffer.buf2;
481
        } else if (band == 3) {
482
            return buffer.buf3;
483
        }
425
								//Desplazamiento para la X y la Y leidas. Estas tienen efecto cuando un pixel no empieza a visualizarse
426
								//justo en su esquina superior izquierda y tiene que ser cortado en la visualizaci?n.
427
								double offsetX = Math.abs(currentViewX - ((int)currentViewX));
428
								double offsetY = Math.abs(currentViewY - ((int)currentViewY));
429
								for (int y1 = 0; y1 < currentViewHeight; y1++){
430
									 for (int x1 = 0; x1 < currentViewWidth; x1++) {
431
											kd = (y1 * currentViewWidth) + x1;
432
											k = (((int) ((y1 * scaleY) + offsetY)) * SceneWidth) +
433
													(int) ((x1 * scaleX) + offsetX);
484 434

  
485
        return null;
486
    }
435
											try {
436
														line[kd] = alpha + ((0xff & bandR[k]) << 16) + ((0xff & bandG[k]) << 8) + (0xff & bandB[k]);
437
											} catch (java.lang.ArrayIndexOutOfBoundsException e) {
438
											}
439
									 }
440
								}
441
						}
487 442

  
488
    // Polilinea con extent
489
    class Contour extends Vector {
490
        final private static long serialVersionUID = -3370601314380922368L;
491
        public double minX = Double.MAX_VALUE;
492
        public double minY = Double.MAX_VALUE;
493
        public double maxX = -Double.MAX_VALUE;
494
        public double maxY = -Double.MAX_VALUE;
443
						buffer = null;
444
				} catch (MrSIDException e) {
445
						e.printStackTrace();
446
				}
447
		}
495 448

  
496
        public Contour() {
497
            super();
498
        }
449
		/**
450
		 * Lee una ventana de la imagen y devuelve un buffer de bytes
451
		 * @param ulX        Coordenada X de la esquina superior izquierda
452
		 * @param ulY        Coordenada Y de la esquina superior izquierda
453
		 * @param sizeX        Tama?o X de la imagen
454
		 * @param sizeY        Tama?o Y de la image
455
		 * @param band        N?mero de bandas
456
		 * @return        buffer con la ventana leida
457
		 * @throws MrSIDException
458
		 */
459
		public byte[] getWindow(int ulX, int ulY, int sizeX, int sizeY, int band)
460
										 throws MrSIDException {
461
				if (pixel == null) {
462
						pixel = new LTIPixel(eColorSpace, nbands, eSampleType);
463
				}
499 464

  
500
        public void add(Point2D pt) {
501
            super.add(pt);
465
				LTIScene scene = new LTIScene(ulX, ulY, sizeX, sizeY, 1.0);
466
				LTISceneBuffer buffer = new LTISceneBuffer(pixel, sizeX, sizeY, true);
467
				((LTIImageStage) this).read(scene, buffer);
502 468

  
503
            if (pt.getX() > maxX) {
504
                maxX = pt.getX();
505
            }
469
				if (band == 1) {
470
						return buffer.buf1;
471
				} else if (band == 2) {
472
						return buffer.buf2;
473
				} else if (band == 3) {
474
						return buffer.buf3;
475
				}
506 476

  
507
            if (pt.getX() < minX) {
508
                minX = pt.getX();
509
            }
477
				return null;
478
		}
510 479

  
511
            if (pt.getY() > maxY) {
512
                maxY = pt.getY();
513
            }
480
		// Polilinea con extent
481
		class Contour extends Vector {
482
				final private static long serialVersionUID = -3370601314380922368L;
483
				public double minX = Double.MAX_VALUE;
484
				public double minY = Double.MAX_VALUE;
485
				public double maxX = -Double.MAX_VALUE;
486
				public double maxY = -Double.MAX_VALUE;
514 487

  
515
            if (pt.getY() < minY) {
516
                minY = pt.getY();
517
            }
518
        }
519
    }
488
				public Contour() {
489
						super();
490
				}
491

  
492
				public void add(Point2D pt) {
493
						super.add(pt);
494

  
495
						if (pt.getX() > maxX) {
496
								maxX = pt.getX();
497
						}
498

  
499
						if (pt.getX() < minX) {
500
								minX = pt.getX();
501
						}
502

  
503
						if (pt.getY() > maxY) {
504
								maxY = pt.getY();
505
						}
506

  
507
						if (pt.getY() < minY) {
508
								minY = pt.getY();
509
						}
510
				}
511
		}
520 512
}
521 513

  
522 514

  
......
527 519
 * son registrados con la extensi?n sid
528 520
 */
529 521
public class MrSidFile extends GeoRasterFile {
530
    public final static int BAND_HEIGHT = 64;
522
		public final static int BAND_HEIGHT = 64;
531 523

  
532
    static {
533
        GeoRasterFile.registerExtension("sid", MrSidFile.class);
534
    }
524
		static {
525
				GeoRasterFile.registerExtension("sid", MrSidFile.class);
526
		}
535 527

  
536
    protected MrSidNative file = null;
537
    private Extent v = null;
528
		protected MrSidNative file = null;
529
		private Extent v = null;
538 530

  
539
    /**
540
     * Contructor. Abre el fichero mrsid
541
     * @param proj        Proyecci?n
542
     * @param fName        Nombre del fichero mrsid
543
     */
544
    public MrSidFile(IProjection proj, String fName) {
545
        super(proj, fName);
546
        
547
        extent = new Extent();
531
		/**
532
		 * Contructor. Abre el fichero mrsid
533
		 * @param proj        Proyecci?n
534
		 * @param fName        Nombre del fichero mrsid
535
		 */
536
		public MrSidFile(IProjection proj, String fName) {
537
				super(proj, fName);
548 538

  
549
        try {
550
            file = new MrSidNative(fName);
551
            showOnOpen();
552
            load();
553
            bandCount = file.nbands;
539
				extent = new Extent();
554 540

  
555
            if (bandCount > 2) {
556
                setBand(RED_BAND, 0);
557
                setBand(GREEN_BAND, 1);
558
                setBand(BLUE_BAND, 2);
559
            } else {
560
                setBand(RED_BAND | GREEN_BAND | BLUE_BAND, 0);
561
            }
562
        } catch (Exception e) {
563
            System.out.println("Error en constructor de MrSID");
564
            e.printStackTrace();
565
            file = null;
566
        }
567
    }
541
				try {
542
						file = new MrSidNative(fName);
543
						showOnOpen();
544
						load();
545
						bandCount = file.nbands;
568 546

  
547
						if (bandCount > 2) {
548
								setBand(RED_BAND, 0);
549
								setBand(GREEN_BAND, 1);
550
								setBand(BLUE_BAND, 2);
551
						} else {
552
								setBand(RED_BAND | GREEN_BAND | BLUE_BAND, 0);
553
						}
554
				} catch (Exception e) {
555
						System.out.println("Error en constructor de MrSID");
556
						e.printStackTrace();
557
						file = null;
558
				}
559
		}
560

  
569 561
	/**
570 562
	 * Obtenemos o calculamos el extent de la imagen.
571 563
	 */
572
    public GeoFile load() {
573
    	
574
   		extent = new Extent(file.esq.minX, file.esq.minY, file.esq.maxX, file.esq.maxY);
575
   		requestExtent = extent;
576
    	
577
    	/*if((this.assignedExtent == GeoRasterFile.IMAGE_EXTENT || this.assignedExtent == GeoRasterFile.ORDER ) 
578
    		&& file !=null	&& file.esq != null){
579
    		extent = new Extent(file.esq.minX, file.esq.minY, file.esq.maxX, file.esq.maxY);
580
    		return this;
581
    	}
582
    	
583
    	if((this.assignedExtent == GeoRasterFile.ASSIGNED_EXTENT || this.assignedExtent == GeoRasterFile.ORDER ) 
584
    		&& this.getTempExtent() != null){
585
        
586
        	extent = this.getTempExtent();
564
		public GeoFile load() {
565

  
566
			 extent = new Extent(file.esq.minX, file.esq.minY, file.esq.maxX, file.esq.maxY);
567
			 requestExtent = extent;
568

  
569
			/*if((this.assignedExtent == GeoRasterFile.IMAGE_EXTENT || this.assignedExtent == GeoRasterFile.ORDER )
570
				&& file !=null	&& file.esq != null){
571
				extent = new Extent(file.esq.minX, file.esq.minY, file.esq.maxX, file.esq.maxY);
572
				return this;
573
			}
574

  
575
			if((this.assignedExtent == GeoRasterFile.ASSIGNED_EXTENT || this.assignedExtent == GeoRasterFile.ORDER )
576
				&& this.getTempExtent() != null){
577

  
578
					extent = this.getTempExtent();
587 579
			file.esq = file.new Contour();
588
  			file.esq.add(new Point2D.Double(extent.minX(), extent.minY()));
589
  			file.esq.add(new Point2D.Double(extent.minX()+(extent.maxX() - extent.minX()), extent.minY()));
590
  			file.esq.add(new Point2D.Double(extent.minX(), extent.minY()+(extent.maxY() - extent.minY())));
591
  			file.esq.add(new Point2D.Double(extent.minX()+(extent.maxX() - extent.minX()), extent.minY()+(extent.maxY() - extent.minY())));
592
        }*/ 
593
        
594
        return this;
595
    }
580
				file.esq.add(new Point2D.Double(extent.minX(), extent.minY()));
581
				file.esq.add(new Point2D.Double(extent.minX()+(extent.maxX() - extent.minX()), extent.minY()));
582
				file.esq.add(new Point2D.Double(extent.minX(), extent.minY()+(extent.maxY() - extent.minY())));
583
				file.esq.add(new Point2D.Double(extent.minX()+(extent.maxX() - extent.minX()), extent.minY()+(extent.maxY() - extent.minY())));
584
				}*/
596 585

  
597
    /**
598
     * Libera el objeto que ha abierto el fichero
599
     */
600
    public void close() {
601
    	if(file != null){
602
    		file.close();
603
    		file = null;
604
    	}
605
    }
586
				return this;
587
		}
606 588

  
607
    /**
608
     * Asigna una banda R, G o B
609
     */
610
    public void setBand(int flag, int bandNr) {
611
        super.setBand(flag, bandNr);
589
		/**
590
		 * Libera el objeto que ha abierto el fichero
591
		 */
592
		public void close() {
593
			if(file != null){
594
				file.close();
595
				file = null;
596
			}
597
		}
612 598

  
613
        if ((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND) {
614
            file.rBandNr = bandNr + 1;
615
        }
599
		/**
600
		 * Asigna una banda R, G o B
601
		 */
602
		public void setBand(int flag, int bandNr) {
603
				super.setBand(flag, bandNr);
616 604

  
617
        if ((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) {
618
            file.gBandNr = bandNr + 1;
619
        }
605
				if ((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND) {
606
						file.rBandNr = bandNr + 1;
607
				}
620 608

  
621
        if ((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) {
622
            file.bBandNr = bandNr + 1;
623
        }
624
    }
609
				if ((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) {
610
						file.gBandNr = bandNr + 1;
611
				}
625 612

  
626
    /**
627
     * Asigna el extent de la vista
628
     */
629
    public void setView(Extent e) {
630
        v = new Extent(e);
631
    }
613
				if ((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) {
614
						file.bBandNr = bandNr + 1;
615
				}
616
		}
632 617

  
633
    /**
634
     * Obtiene el Extent de la vista
635
     */
636
    public Extent getView() {
637
        return v;
638
    }
618
		/**
619
		 * Asigna el extent de la vista
620
		 */
621
		public void setView(Extent e) {
622
				v = new Extent(e);
623
		}
639 624

  
640
    /**
641
     * Obtiene el ancho de la imagen
642
     */
643
    public int getWidth() {
644
        return file.width;
645
    }
625
		/**
626
		 * Obtiene el Extent de la vista
627
		 */
628
		public Extent getView() {
629
				return v;
630
		}
646 631

  
647
    /**
648
     * Obtiene el alto de la imagen
649
     */
650
    public int getHeight() {
651
        return file.height;
652
    }
632
		/**
633
		 * Obtiene el ancho de la imagen
634
		 */
635
		public int getWidth() {
636
				return file.width;
637
		}
653 638

  
654
    public void reProject(ICoordTrans rp) {
655
        // TODO Auto-generated method stub	
656
    }
639
		/**
640
		 * Obtiene el alto de la imagen
641
		 */
642
		public int getHeight() {
643
				return file.height;
644
		}
657 645

  
658
    /**
659
     * Actualiza la imagen. Se encarga de llamar a la funci?n que calcula la vista
660
     * y luego a la que lee la escena sobre un buffer. Vuelca la informaci?n obtenida
661
     * sobre el Image que la visualiza.
662
     */
663
    public Image updateImage(int width, int height, ICoordTrans rp) {
664
        int line;
665
        int[] pRGBArray = null;
666
        Image image = null;
667
        
668
        if(mustVerifySize()){
669
	        // Work out the correct aspect for the setView call.
670
	        double dFileAspect = (double) v.width() / (double) v.height();
671
	        double dWindowAspect = (double) width / (double) height;
672
	
673
	        if (dFileAspect > dWindowAspect) {
674
	            height = (int) ((double) width / dFileAspect);
675
	        } else {
676
	            width = (int) ((double) height * dFileAspect);
677
	        }
678
        }
679
        
680
        // Set the view
681
        file.setView(v.minX(), v.maxY(), v.maxX(), v.minY(), width, height);
646
		public void reProject(ICoordTrans rp) {
647
				// TODO Auto-generated method stub
648
		}
682 649

  
683
        //Impedimos que los valores de ancho y alto de la im?gen sean menores que 1
684
        if (width <= 0) {
685
            width = 1;
686
        }
650
		/**
651
		 * Actualiza la imagen. Se encarga de llamar a la funci?n que calcula la vista
652
		 * y luego a la que lee la escena sobre un buffer. Vuelca la informaci?n obtenida
653
		 * sobre el Image que la visualiza.
654
		 */
655
		public Image updateImage(int width, int height, ICoordTrans rp) {
656
				int[] pRGBArray = null;
657
				Image image = null;
687 658

  
688
        if (height <= 0) {
689
            height = 1;
690
        }
659
				if(mustVerifySize()){
660
					// Work out the correct aspect for the setView call.
661
					double dFileAspect = (double) v.width() / (double) v.height();
662
					double dWindowAspect = (double) width / (double) height;
691 663

  
692
        image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
693
        pRGBArray = new int[width * height];
664
					if (dFileAspect > dWindowAspect) {
665
							height = (int) ((double) width / dFileAspect);
666
					} else {
667
							width = (int) ((double) height * dFileAspect);
668
					}
669
				}
694 670

  
695
        try {
696
            file.setAlpha(getAlpha());
697
            
698
            setBand(RED_BAND, rBandNr);
699
            setBand(GREEN_BAND, gBandNr);
700
            setBand(BLUE_BAND, bBandNr);
701
                     
671
				// Set the view
672
				file.setView(v.minX(), v.maxY(), v.maxX(), v.minY(), width, height);
702 673

  
703
            file.readScene(pRGBArray);
704
            ((BufferedImage) image).setRGB(0, 0, width, height, pRGBArray, 0,
705
                                           width);
706
        } catch (Exception e) {
707
            e.printStackTrace();
708
        }
674
				//Impedimos que los valores de ancho y alto de la im?gen sean menores que 1
675
				if (width <= 0) {
676
						width = 1;
677
				}
709 678

  
710
        return image;
711
    }
679
				if (height <= 0) {
680
						height = 1;
681
				}
712 682

  
713
    /**
714
     * Muestra informaci?n del fichero abierto.
715
     *
716
     */
717
    private void showOnOpen() {
718
        // Report en la apertura (quitar)
719
        System.out.println("Fichero MrSID '" + getName() + "' abierto.");
720
        System.out.println("Version = " + file.version);
721
        System.out.println("   Size = (" + file.width + "," + file.height +
722
                           ")");
723
        System.out.println("   NumBands = (" + file.nbands + ")");
683
				image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
684
				pRGBArray = new int[width * height];
724 685

  
725
        //file.pintaInfo();
726
        file.pintaPaleta();
727
    }
686
				try {
687
						file.setAlpha(getAlpha());
728 688

  
729
    /**
730
     * Asigna al objeto Image los valores con los dato de la imagen contenidos en el
731
     * vector de enteros.
732
     * @param image        imagen con los datos actuales
733
     * @param startX        inicio de la posici?n en X dentro de la imagen
734
     * @param startY        inicio de la posici?n en X dentro de la imagen
735
     * @param w        Ancho de la imagen
736
     * @param h        Alto de la imagen
737
     * @param rgbArray        vector que contiene la banda que se va a sustituir
738
     * @param offset        desplazamiento
739
     * @param scansize        tama?o de imagen recorrida por cada p
740
     */
741
    protected void setRGBLine(BufferedImage image, int startX, int startY,
742
                              int w, int h, int[] rgbArray, int offset,
743
                              int scansize) {
744
        image.setRGB(startX, startY, w, h, rgbArray, offset, scansize);
745
    }
689
						setBand(RED_BAND, rBandNr);
690
						setBand(GREEN_BAND, gBandNr);
691
						setBand(BLUE_BAND, bBandNr);
746 692

  
747
    /**
748
     * Asigna al objeto Image la mezcla entre los valores que ya tiene y los valores
749
     * con los datos de la imagen contenidos en el vector de enteros. De los valores RGB
750
     * que ya contiene se mantienen las bandas que no coinciden con el valor de flags. La
751
     * banda correspondiente a flags es sustituida por los datos del vector.
752
     * @param image        imagen con los datos actuales
753
     * @param startX        inicio de la posici?n en X dentro de la imagen
754
     * @param startY        inicio de la posici?n en X dentro de la imagen
755
     * @param w        Ancho de la imagen
756
     * @param h        Alto de la imagen
757
     * @param rgbArray        vector que contiene la banda que se va a sustituir
758
     * @param offset        desplazamiento
759
     * @param scansize        tama?o de imagen recorrida por cada paso
760
     * @param flags        banda que se va a sustituir (Ctes de GeoRasterFile)
761
     */
762
    protected void setRGBLine(BufferedImage image, int startX, int startY,
763
                              int w, int h, int[] rgbArray, int offset,
764
                              int scansize, int flags) {
765
        int[] line = new int[rgbArray.length];
766
        image.getRGB(startX, startY, w, h, line, offset, scansize);
767 693

  
768
        if (flags == GeoRasterFile.RED_BAND) {
769
            for (int i = 0; i < line.length; i++)
770
                line[i] = (line[i] & 0x0000ffff) | (rgbArray[i] & 0xffff0000);
771
        } else if (flags == GeoRasterFile.GREEN_BAND) {
772
            for (int i = 0; i < line.length; i++)
773
                line[i] = (line[i] & 0x00ff00ff) | (rgbArray[i] & 0xff00ff00);
774
        } else if (flags == GeoRasterFile.BLUE_BAND) {
775
            for (int i = 0; i < line.length; i++)
776
                line[i] = (line[i] & 0x00ffff00) | (rgbArray[i] & 0xff0000ff);
777
        }
694
						file.readScene(pRGBArray);
695
						((BufferedImage) image).setRGB(0, 0, width, height, pRGBArray, 0,
696
																					 width);
697
				} catch (Exception e) {
698
						e.printStackTrace();
699
				}
778 700

  
779
        image.setRGB(startX, startY, w, h, line, offset, scansize);
780
    }
701
				return image;
702
		}
781 703

  
782
    /**
783
     * Asigna al objeto Image la mezcla entre los valores que ya tiene y los valores
784
     * con los dato de la imagen contenidos en el vector de enteros. De los valores RGB
785
     * que ya contiene se mantienen las bandas que no coinciden con el valor de flags. La
786
     * banda correspondiente a flags es sustituida por los datos del vector.
787
     * @param image        imagen con los datos actuales
788
     * @param startX        inicio de la posici?n en X dentro de la imagen
789
     * @param startY        inicio de la posici?n en X dentro de la imagen
790
     * @param w        Ancho de la imagen
791
     * @param h        Alto de la imagen
792
     * @param rgbArray        vector que contiene la banda que se va a sustituir
793
     * @param offset        desplazamiento
794
     * @param scansize        tama?o de imagen recorrida por cada paso
795
     * @param origBand        Banda origen del GeoRasterFile
796
     * @param destBandFlag        banda que se va a sustituir (Ctes de GeoRasterFile)
797
     */
798
    protected void setRGBLine(BufferedImage image, int startX, int startY,
799
                              int w, int h, int[] rgbArray, int offset,
800
                              int scansize, int origBand, int destBandFlag) {
801
        int[] line = new int[rgbArray.length];
802
        image.getRGB(startX, startY, w, h, line, offset, scansize);
704
		/**
705
		 * Muestra informaci?n del fichero abierto.
706
		 *
707
		 */
708
		private void showOnOpen() {
709
				// Report en la apertura (quitar)
710
				System.out.println("Fichero MrSID '" + getName() + "' abierto.");
711
				System.out.println("Version = " + file.version);
712
				System.out.println("   Size = (" + file.width + "," + file.height +
713
													 ")");
714
				System.out.println("   NumBands = (" + file.nbands + ")");
803 715

  
804
        if ((origBand == 0) && (destBandFlag == GeoRasterFile.RED_BAND)) {
805
            for (int i = 0; i < line.length; i++)
806
                line[i] = (line[i] & 0x0000ffff) | (rgbArray[i] & 0xffff0000);
807
        } else if ((origBand == 1) &&
808
                       (destBandFlag == GeoRasterFile.GREEN_BAND)) {
809
            for (int i = 0; i < line.length; i++)
810
                line[i] = (line[i] & 0x00ff00ff) | (rgbArray[i] & 0xff00ff00);
811
        } else if ((origBand == 2) &&
812
                       (destBandFlag == GeoRasterFile.BLUE_BAND)) {
813
            for (int i = 0; i < line.length; i++)
814
                line[i] = (line[i] & 0x00ffff00) | (rgbArray[i] & 0xff0000ff);
815
        } else if ((origBand == 0) &&
816
                       (destBandFlag == GeoRasterFile.GREEN_BAND)) {
817
            for (int i = 0; i < line.length; i++)
818
                line[i] = (line[i] & 0xffff00ff) |
819
                          ((rgbArray[i] & 0x00ff0000) >> 8);
820
        } else if ((origBand == 0) &&
821
                       (destBandFlag == GeoRasterFile.BLUE_BAND)) {
822
            for (int i = 0; i < line.length; i++)
823
                line[i] = (line[i] & 0xffffff00) |
824
                          ((rgbArray[i] & 0x00ff0000) >> 16);
825
        } else if ((origBand == 1) && (destBandFlag == GeoRasterFile.RED_BAND)) {
826
            for (int i = 0; i < line.length; i++)
827
                line[i] = (line[i] & 0xff00ffff) |
828
                          ((rgbArray[i] & 0x0000ff00) << 8);
829
        } else if ((origBand == 1) &&
830
                       (destBandFlag == GeoRasterFile.BLUE_BAND)) {
831
            for (int i = 0; i < line.length; i++)
832
                line[i] = (line[i] & 0xffffff00) |
833
                          ((rgbArray[i] & 0x0000ff00) >> 8);
834
        } else if ((origBand == 2) && (destBandFlag == GeoRasterFile.RED_BAND)) {
835
            for (int i = 0; i < line.length; i++)
836
                line[i] = (line[i] & 0xff00ffff) |
837
                          ((rgbArray[i] & 0x000000ff) << 16);
838
        } else if ((origBand == 2) &&
839
                       (destBandFlag == GeoRasterFile.GREEN_BAND)) {
840
            for (int i = 0; i < line.length; i++)
841
                line[i] = (line[i] & 0xffff00ff) |
842
                          ((rgbArray[i] & 0x000000ff) << 8);
843
        }
716
				//file.pintaInfo();
717
				file.pintaPaleta();
718
		}
844 719

  
845
        image.setRGB(startX, startY, w, h, line, offset, scansize);
846
    }
720
		/**
721
		 * Asigna al objeto Image los valores con los dato de la imagen contenidos en el
722
		 * vector de enteros.
723
		 * @param image        imagen con los datos actuales
724
		 * @param startX        inicio de la posici?n en X dentro de la imagen
725
		 * @param startY        inicio de la posici?n en X dentro de la imagen
726
		 * @param w        Ancho de la imagen
727
		 * @param h        Alto de la imagen
728
		 * @param rgbArray        vector que contiene la banda que se va a sustituir
729
		 * @param offset        desplazamiento
730
		 * @param scansize        tama?o de imagen recorrida por cada p
731
		 */
732
		protected void setRGBLine(BufferedImage image, int startX, int startY,
733
															int w, int h, int[] rgbArray, int offset,
734
															int scansize) {
735
				image.setRGB(startX, startY, w, h, rgbArray, offset, scansize);
736
		}
847 737

  
848
    /* (non-Javadoc)
849
     * @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans, java.awt.Image, int)
850
     */
851
    public Image updateImage(int width, int height, ICoordTrans rp, Image img,
852
                             int origBand, int destBandFlag) throws SupersamplingNotSupportedException{
853
        int line;
854
        int[] pRGBArray = null;
855
        Image mrSidImage = null;
738
		/**
739
		 * Asigna al objeto Image la mezcla entre los valores que ya tiene y los valores
740
		 * con los datos de la imagen contenidos en el vector de enteros. De los valores RGB
741
		 * que ya contiene se mantienen las bandas que no coinciden con el valor de flags. La
742
		 * banda correspondiente a flags es sustituida por los datos del vector.
743
		 * @param image        imagen con los datos actuales
744
		 * @param startX        inicio de la posici?n en X dentro de la imagen
745
		 * @param startY        inicio de la posici?n en X dentro de la imagen
746
		 * @param w        Ancho de la imagen
747
		 * @param h        Alto de la imagen
748
		 * @param rgbArray        vector que contiene la banda que se va a sustituir
749
		 * @param offset        desplazamiento
750
		 * @param scansize        tama?o de imagen recorrida por cada paso
751
		 * @param flags        banda que se va a sustituir (Ctes de GeoRasterFile)
752
		 */
753
		protected void setRGBLine(BufferedImage image, int startX, int startY,
754
															int w, int h, int[] rgbArray, int offset,
755
															int scansize, int flags) {
756
				int[] line = new int[rgbArray.length];
757
				image.getRGB(startX, startY, w, h, line, offset, scansize);
856 758

  
857
        if(mustVerifySize()){
858
	        // Work out the correct aspect for the setView call.
859
	        double dFileAspect = (double) v.width() / (double) v.height();
860
	        double dWindowAspect = (double) width / (double) height;
861
	
862
	        if (dFileAspect > dWindowAspect) {
863
	            height = (int) ((double) width / dFileAspect);
864
	        } else {
865
	            width = (int) ((double) height * dFileAspect);
866
	        }
867
        }
868
        // Set the view
869
        file.setView(v.minX(), v.maxY(), v.maxX(), v.minY(), width, height);
759
				if (flags == GeoRasterFile.RED_BAND) {
760
						for (int i = 0; i < line.length; i++)
761
								line[i] = (line[i] & 0x0000ffff) | (rgbArray[i] & 0xffff0000);
762
				} else if (flags == GeoRasterFile.GREEN_BAND) {
763
						for (int i = 0; i < line.length; i++)
764
								line[i] = (line[i] & 0x00ff00ff) | (rgbArray[i] & 0xff00ff00);
765
				} else if (flags == GeoRasterFile.BLUE_BAND) {
766
						for (int i = 0; i < line.length; i++)
767
								line[i] = (line[i] & 0x00ffff00) | (rgbArray[i] & 0xff0000ff);
768
				}
870 769

  
871
        //Impedimos que los valores de ancho y alto de la im?gen sean menores que 1
872
        if (width <= 0) {
873
            width = 1;
874
        }
770
				image.setRGB(startX, startY, w, h, line, offset, scansize);
771
		}
875 772

  
876
        if (height <= 0) {
877
            height = 1;
878
        }
773
		/**
774
		 * Asigna al objeto Image la mezcla entre los valores que ya tiene y los valores
775
		 * con los dato de la imagen contenidos en el vector de enteros. De los valores RGB
776
		 * que ya contiene se mantienen las bandas que no coinciden con el valor de flags. La
777
		 * banda correspondiente a flags es sustituida por los datos del vector.
778
		 * @param image        imagen con los datos actuales
779
		 * @param startX        inicio de la posici?n en X dentro de la imagen
780
		 * @param startY        inicio de la posici?n en X dentro de la imagen
781
		 * @param w        Ancho de la imagen
782
		 * @param h        Alto de la imagen
783
		 * @param rgbArray        vector que contiene la banda que se va a sustituir
784
		 * @param offset        desplazamiento
785
		 * @param scansize        tama?o de imagen recorrida por cada paso
786
		 * @param origBand        Banda origen del GeoRasterFile
787
		 * @param destBandFlag        banda que se va a sustituir (Ctes de GeoRasterFile)
788
		 */
789
		protected void setRGBLine(BufferedImage image, int startX, int startY,
790
															int w, int h, int[] rgbArray, int offset,
791
															int scansize, int origBand, int destBandFlag) {
792
				int[] line = new int[rgbArray.length];
793
				image.getRGB(startX, startY, w, h, line, offset, scansize);
879 794

  
880
        file.setAlpha(getAlpha());
881
      
882
        setBand(RED_BAND, rBandNr);
883
        setBand(GREEN_BAND, gBandNr);
884
        setBand(BLUE_BAND, bBandNr);
885
       
886
        pRGBArray = new int[width * height];
795
				if ((origBand == 0) && (destBandFlag == GeoRasterFile.RED_BAND)) {
796
						for (int i = 0; i < line.length; i++)
797
								line[i] = (line[i] & 0x0000ffff) | (rgbArray[i] & 0xffff0000);
798
				} else if ((origBand == 1) &&
799
											 (destBandFlag == GeoRasterFile.GREEN_BAND)) {
800
						for (int i = 0; i < line.length; i++)
801
								line[i] = (line[i] & 0x00ff00ff) | (rgbArray[i] & 0xff00ff00);
802
				} else if ((origBand == 2) &&
803
											 (destBandFlag == GeoRasterFile.BLUE_BAND)) {
804
						for (int i = 0; i < line.length; i++)
805
								line[i] = (line[i] & 0x00ffff00) | (rgbArray[i] & 0xff0000ff);
806
				} else if ((origBand == 0) &&
807
											 (destBandFlag == GeoRasterFile.GREEN_BAND)) {
808
						for (int i = 0; i < line.length; i++)
809
								line[i] = (line[i] & 0xffff00ff) |
810
													((rgbArray[i] & 0x00ff0000) >> 8);
811
				} else if ((origBand == 0) &&
812
											 (destBandFlag == GeoRasterFile.BLUE_BAND)) {
813
						for (int i = 0; i < line.length; i++)
814
								line[i] = (line[i] & 0xffffff00) |
815
													((rgbArray[i] & 0x00ff0000) >> 16);
816
				} else if ((origBand == 1) && (destBandFlag == GeoRasterFile.RED_BAND)) {
817
						for (int i = 0; i < line.length; i++)
818
								line[i] = (line[i] & 0xff00ffff) |
819
													((rgbArray[i] & 0x0000ff00) << 8);
820
				} else if ((origBand == 1) &&
821
											 (destBandFlag == GeoRasterFile.BLUE_BAND)) {
822
						for (int i = 0; i < line.length; i++)
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff