Revision 1533

View differences:

branches/v02_desarrollo/libraries/libCq CMS for java.old/src-dvp/org/cresques/io/GdalFile.java
207 207
	
208 208
	int lastY = -1;
209 209
	
210
	public void readLine(int[][] line) throws GdalException {
210
	public void readLine(short[][] line) throws GdalException {
211 211
		int err = 0;
212 212
		int nbands = getRasterCount();
213 213
		GdalRasterBand band = null;
......
235 235
	      			i++, j+=step, i2 = (((int) j)*2)+1) {
236 236
	      			line[i] = a + ((r[i2-1]) << 8) + r[i2];
237 237
	      		}*/
238
  		  		for (i=0, j=0F; i<currentViewWidth && j<r.getSize(); i++, j+=step) {
239
	      			line[0][i] = r.buffShort[(int) j] & 0xffff;
240
	      			line[1][i] = r.buffShort[(int) j] & 0xffff;
241
	      			line[2][i] = r.buffShort[(int) j] & 0xffff;
238
  				for (int k=0; k<3; k++)
239
  					for (i=0, j=0F; i<currentViewWidth && j<r.getSize(); i++, j+=step) {
240
  						line[i][k] = (short) (r.buffShort[(int) j] & 0xffff);
242 241
	      		}
243 242
  			else { // Multiband
244 243
  				short px;
245 244
  				//System.err.println("readLine(): Raster 16bits multibanda");
246
	      		for (i=0, j=0F; i<currentViewWidth && j<r.getSize(); i++, j+=step) {
247
	      			line[0][i] = r.buffShort[(int) j] & 0xffff;
248
	      			line[1][i] = g.buffShort[(int) j] & 0xffff;
249
	      			line[2][i] = b.buffShort[(int) j] & 0xffff;
250
	      		}
245
  				GdalBuffer [] bands = {r,g,b};
246
  				for (int k=0; k<3; k++)
247
		      		for (i=0, j=0F; i<currentViewWidth && j<r.getSize(); i++, j+=step)
248
		      			line[i][k] = (short) (bands[k].buffShort[(int) j] & 0xffff);
251 249
  			}
252
	    //for (int i=0; i<currentViewWidth; i++) line[i] = 128+128*256+128*256*256;
253

  
254 250
		return;
255 251
	}
256 252
	
......
507 503
		return image;
508 504
	}
509 505
	
510
	public Raster getRaster(int width, int height, ICoordTrans rp) {
506
	public RasterBuf getRaster(int width, int height, ICoordTrans rp) {
511 507
		double dFileAspect, dWindowAspect;
512 508
		int line, pRGBArray[][] = null;
513
		WritableRaster raster = null;
509
		RasterBuf raster = null;
514 510

  
515 511
		// Work out the correct aspect for the setView call.
516 512
		dFileAspect = (double)v.width()/(double)v.height();
......
526 522
		file.setView(v.minX(), v.maxY(), v.maxX(), v.minY(),
527 523
			width, height);
528 524
		
529
		raster = Raster.createBandedRaster(getDataType(), width, height, 3, new Point(0,0));
530
		//image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
531
		pRGBArray = new int[3][width/**BAND_HEIGHT*/];
525
		raster = new RasterBuf(getDataType(), width, height, 3, new Point(0,0));
532 526
		try {
533 527
			//int nLin = height % BAND_HEIGHT;
534 528
			file.setAlpha(getAlpha());
......
536 530
			setBand(GREEN_BAND, gBandNr);
537 531
			setBand(BLUE_BAND,  bBandNr);
538 532
			for (line=0; line < height; line++) { //+=BAND_HEIGHT) {
539
				//int bandH = Math.min(BAND_HEIGHT, height-line);
540
				//file.readBandRGBA(bandH, BAND_HEIGHT, pRGBArray);
541
				file.readLine(pRGBArray);
542
				raster.setSamples(0, line, width, 1, 0, pRGBArray[0]);
543
				raster.setSamples(0, line, width, 1, 1, pRGBArray[1]);
544
				raster.setSamples(0, line, width, 1, 2, pRGBArray[2]);
545
//				setRGBLine((BufferedImage) image, 0, line, width, 1/*bandH*/, pRGBArray, 0, width);
533
				file.readLine(raster.getLineShort(line));
546 534
			}
547 535
		} catch (Exception e) {
548 536
			// TODO Auto-generated catch block
......
551 539
		
552 540
		return raster;
553 541
	}
542
	
554 543
	protected void setRGBLine(BufferedImage image, int startX, int startY, int w, int h, int[] rgbArray, 
555 544
			 int offset, int scansize) {
556 545
		image.setRGB(startX, startY, w, h, rgbArray, offset, scansize);
branches/v02_desarrollo/libraries/libCq CMS for java.old/.classpath
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<classpath>
3 3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="src" path="src-dvp"/>
4 5
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5 6
	<classpathentry kind="lib" path="lib/geojava.jar"/>
6 7
	<classpathentry kind="lib" path="lib/jmgeoraster.jar"/>
......
9 10
	<classpathentry kind="lib" path="lib/geoapi-SNAPSHOT.jar"/>
10 11
	<classpathentry sourcepath="/gt/module/main/src" kind="lib" path="lib/main-2.1.x.jar"/>
11 12
	<classpathentry sourcepath="C:/downloads/java/tar/javatar-2.5/source" kind="lib" path="lib/tar.jar"/>
13
	<classpathentry kind="lib" path="lib/jmrsid.jar"/>
14
	<classpathentry sourcepath="/jni-libgdal/src" kind="lib" path="/jni-libgdal/dist/jbsb.jar"/>
15
	<classpathentry sourcepath="/jni-libgdal/src" kind="lib" path="/jni-libgdal/dist/jgdal.jar"/>
16
	<classpathentry kind="lib" path="/jni-libgdal/dist/jogr.jar"/>
12 17
	<classpathentry kind="output" path="bin"/>
13 18
</classpath>
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/io/RasterBuf.java
1
/*
2
 * Created on 22-feb-2005
3
 */
4
package org.cresques.io;
5

  
6
import java.awt.Point;
7
import java.awt.image.DataBuffer;
8

  
9
/**
10
 * Rectangulo de pixeles. parecido a java.awt.image.Raster
11
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
12
 */
13
public class RasterBuf {
14
	private byte  [][][] byteBuf;
15
	private short [][][] shortBuf;
16
	private int   [][][] intBuf;
17
	private int width, height, bandNr;
18
	private int dataType;
19
	
20
	public RasterBuf(int dataType, int width, int height, int bandNr, Point orig) {
21
		this.dataType = dataType;
22
		this.width = width;
23
		this.height = height;
24
		this.bandNr = bandNr;
25
		if (dataType == DataBuffer.TYPE_BYTE)
26
			byteBuf  = new byte[height][width][bandNr];
27
		else if (dataType == DataBuffer.TYPE_SHORT | dataType == DataBuffer.TYPE_USHORT)
28
			shortBuf = new short[height][width][bandNr];
29
		else if (dataType == DataBuffer.TYPE_INT)
30
			intBuf   = new int[height][width][bandNr];
31
	}
32
	
33
	public int getWidth() { return width; }
34
	
35
	public int getHeight() { return height; }
36
	
37
	public int getDataType() { return dataType; }
38
	
39
	public int getDataSize() {
40
		if (dataType == DataBuffer.TYPE_BYTE)
41
			return 1;
42
		else if (dataType == DataBuffer.TYPE_SHORT | dataType == DataBuffer.TYPE_USHORT)
43
			return 2;
44
		else if (dataType == DataBuffer.TYPE_INT)
45
			return 4;
46
		return 0;
47
	}
48
	
49
	public int sizeof() {
50
		return getDataSize()*width*height*bandNr;
51
	}
52
	
53
	public byte [][] getLineByte(int y) {	return byteBuf[y]; }
54
	
55
	public short [][] getLineShort(int y) {	return shortBuf[y]; }
56
	
57
	public int [][] getLineInt(int y) {	return intBuf[y]; }
58

  
59
	public void setPixelShort(int x, int y, int [] px) {
60
		for (int i=0; i<bandNr; i++) shortBuf[y][x][i] = (short) px[i];
61
	}
62
	
63
	public void getPixelShort(int x, int y, int [] px) {
64
		for (int i=0; i<bandNr; i++) px[i] = shortBuf[y][x][i];
65
	}
66

  
67
	public void setPixelInt(int x, int y, int [] px) {
68
		for (int i=0; i<bandNr; i++) intBuf[y][x][i] = px[i];
69
	}
70
	
71
	public void getPixelInt(int x, int y, int [] px) {
72
		for (int i=0; i<bandNr; i++) px[i] = intBuf[y][x][i];
73
	}
74
}
0 75

  
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/io/EcwFile.java
69 69
			file = new JNCSFile(fName, false);
70 70
			//file = new JNCSFile(fName, true);
71 71
		    //file.addProgressiveUpdateListener(this);
72

  
73 72
			load();
73
			bandCount = file.numBands;
74
			if ( bandCount > 2) {
75
				setBand(RED_BAND,   0);
76
				setBand(GREEN_BAND, 1);
77
				setBand(BLUE_BAND,  2);
78
			} else
79
				setBand(RED_BAND|GREEN_BAND|BLUE_BAND, 0);
74 80
		} catch(Exception e) {
75 81
		  bErrorOnOpen = true;
76 82
		  errorMessage = e.getMessage();
......
263 269
			pRGBArray = new int[width];
264 270

  
265 271
			// Setup the view parameters for the ecw file.
266
			bandlist = new int[file.numBands];
267
			for (int i=0; i< file.numBands; i++) {
268
			  bandlist[i] = i;
272

  
273
			if ( bandCount > 2) {
274
				bandlist = new int[bandCount];
275
				bandlist[0] = getBand(RED_BAND);
276
				bandlist[1] = getBand(GREEN_BAND);
277
				bandlist[2] = getBand(BLUE_BAND);
278
				if (bandCount > 3)
279
					for (int i=3; i< bandCount; i++) {
280
						 bandlist[i] = 0;
281
					}
282
			} else {
283
				bandlist = new int[bandCount];
284
				for (int i=0; i< bandCount; i++) {
285
				  bandlist[i] = i;
286
				}
269 287
			}
270 288
			
271 289
			for (int nChunk=0; nChunk<frames.length; nChunk++) {
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/PxRaster.java
12 12
import java.awt.image.BufferedImage;
13 13
import java.awt.image.DataBuffer;
14 14
import java.awt.image.ImageObserver;
15
import java.awt.image.Raster;
16 15
import java.util.Date;
17 16
import java.util.Vector;
18 17

  
......
22 21
import org.cresques.geo.ViewPortData;
23 22
import org.cresques.io.GdalFile;
24 23
import org.cresques.io.GeoRasterFile;
24
import org.cresques.io.RasterBuf;
25 25

  
26 26
public class PxRaster extends PxObj implements Projected {
27 27
	protected GeoRasterFile geoFile = null;
......
31 31
	protected GeoRasterFile [] colorBand = null;
32 32
	protected int rBand = 1, gBand = 2, bBand = 3;
33 33
	
34
	int [] minBandValue = {Integer.MAX_VALUE,Integer.MAX_VALUE,Integer.MAX_VALUE};
35
	int [] maxBandValue = {Integer.MIN_VALUE,Integer.MIN_VALUE,Integer.MIN_VALUE};
36

  
34 37
	int transparente = 0x10ffff80;
35 38

  
36 39
	String vName = null;
......
282 285
				(geoFile.getDataType() != DataBuffer.TYPE_BYTE)) {
283 286
				System.out.println("PxRaster: Has dado con un Raster de 16 bits");
284 287
				System.out.println("Dibujando PxRaster sz=("+wImg+","+hImg+"...");
285
				Raster raster = ((GdalFile) geoFile).getRaster(wImg, hImg, rp);
288
				RasterBuf raster = ((GdalFile) geoFile).getRaster(wImg, hImg, rp);
289
				t2 = new Date().getTime();
290
				System.out.println("Dibujando PxRaster: "+(t2-t1)/1000D+", secs. Obteniendo"); t1 = t2;
286 291
				geoImage = renderizeRaster(raster);
287 292
				t2 = new Date().getTime();
288
				System.out.println("Dibujando PxRaster: "+(t2-t1)/1000D+", secs. Obteniendo");
293
				System.out.println("Dibujando PxRaster: "+(t2-t1)/1000D+", secs. Filtrando/Renderizando");t1 = t2;
289 294

  
290 295
				g.drawImage(geoImage, (int) Math.round(pt.getX()), (int) Math.round(pt.getY()), component);
291
				t1 = new Date().getTime();
292
				System.out.println("Dibujando PxRaster: "+(t1-t2)/1000D+", secs. Renderizando");
296
				t2 = new Date().getTime();
297
				System.out.println("Dibujando PxRaster: "+(t2-t1)/1000D+", secs. Dibujando");
293 298
			} else if (colorBand != null) { // multiBands
294 299
				System.out.println("Dibujando PxRaster (Multifile) ...");
295 300
    			//if (doTransparency)
......
323 328
		}
324 329
	}
325 330
	
326
	public Image renderizeRaster(Raster raster) {
327
		int [] px = new int[3];
328
		int rgb = 0;
329
		int [] minBandValue = {Integer.MAX_VALUE,Integer.MAX_VALUE,Integer.MAX_VALUE};
330
		int [] maxBandValue = {Integer.MIN_VALUE,Integer.MIN_VALUE,Integer.MIN_VALUE};
331
		for (int y=0; y<raster.getHeight(); y++)
332
			for (int x=0; x<raster.getWidth(); x++) {
333
				raster.getPixel(x, y, px);
334
				for (int i=0; i<3; i++) {
335
					minBandValue[i] = Math.min(minBandValue[i], px[i]);
336
					maxBandValue[i] = Math.max(maxBandValue[i], px[i]);
331
	/**
332
	 * Filtro para raster. Ancestro de todos los filtros.
333
	 * @author Luis W. Sevilla (sevilla_lui@gva.es)
334
	 */
335
	abstract class RasterFilter {
336
		protected RasterBuf raster = null;
337
		protected int [] px = new int[3];
338
		private int height = 0;
339
		private int width = 0;
340
		
341
		public RasterFilter(RasterBuf raster) {
342
			this.raster = raster;
343
			height = raster.getHeight();
344
			width = raster.getWidth();
345
		}
346
		
347
		public void execute() {
348
			for (int y=0; y<height; y++)
349
				for (int x=0; x<width; x++) {
350
					process(x, y);
337 351
				}
352
		}
353
		
354
		abstract public void process(int x, int y);
355
	}
356
	
357
	/**
358
	 * Calcula el m?ximo y el m?nimo de un raster.
359
	 * @author Luis W. Sevilla (sevilla_lui@gva.es)
360
	 */
361
	class ComputeMinMaxFilter extends RasterFilter {
362
		private int [] min = {Integer.MAX_VALUE,Integer.MAX_VALUE,Integer.MAX_VALUE};
363
		private int [] max = {Integer.MIN_VALUE,Integer.MIN_VALUE,Integer.MIN_VALUE};
364
		
365
		public ComputeMinMaxFilter(RasterBuf raster, int [] min, int [] max) {
366
			super(raster);
367
			this.raster = raster;
368
			this.min = new int[min.length];
369
			this.max = new int[max.length];
370
			for (int i=0; i<min.length; i++) {
371
				this.min[i] = min[i];
372
				this.max[i] = max[i];
338 373
			}
339
		double [] scale = new double[3];
340
		double [] offset = new double[3];
341
		for (int i=0; i<3; i++) {
342
			scale[i] = 255D/(maxBandValue[i]-minBandValue[i]);
343
			offset[i] = (255D*minBandValue[i])/(minBandValue[i]-maxBandValue[i]);
374
			execute();
344 375
		}
376
		
377
		public void process(int x, int y) {
378
			raster.getPixelShort(x, y, px);
379
			for (int i=0; i<3; i++) {
380
				min[i] = Math.min(min[i], px[i]);
381
				max[i] = Math.max(max[i], px[i]);
382
			}
383
		}
345 384

  
346
		BufferedImage image = new BufferedImage(raster.getWidth(), raster.getHeight(), BufferedImage.TYPE_INT_ARGB);
385
		public int getMin(int bandNr) { return min[bandNr]; }
347 386

  
348
		int alpha = (getAlpha() & 0xff) << 24;
349
		for (int y=0; y<raster.getHeight(); y++)
350
			for (int x=0; x<raster.getWidth(); x++) {
351
				raster.getPixel(x, y, px);
352
				/*rgb = alpha | (((px[0] & 0xffff) << 12) & 0xff0000 ) | 
353
				  (((px[1] & 0xffff) << 4 ) & 0xff00 ) |
354
				  (((px[2] & 0xffff) >> 4 ) & 0xff );*/
355
				rgb = alpha | (((int) (((double)px[0])*scale[0] + offset[0])) & 0xff) << 16 |
356
							  (((int) (((double)px[1])*scale[1] + offset[1])) & 0xff) << 8 |
357
							  (((int) (((double)px[2])*scale[2] + offset[2])) & 0xff);
358
				
359
				image.setRGB(x, y, rgb);
387
		public int getMax(int bandNr) { return max[bandNr]; }
388
	}
389
	
390
	/**
391
	 * Realzado Lineal (Amplitude Rescaling).
392
	 * @author Luis W. Sevilla (sevilla_lui@gva.es)
393
	 */
394
	class LinearEnhancementFilter extends RasterFilter {
395
		private double [] scale = new double[3];
396
		private double [] offset = new double[3];
397
		public LinearEnhancementFilter(RasterBuf raster, int [] min, int [] max) {
398
			super(raster);
399
			for (int i=0; i<3; i++) {
400
				scale[i] = 255D/(max[i]-min[i]);
401
				offset[i] = (255D*min[i])/(min[i]-max[i]);
360 402
			}
403
			execute();
404
		}
405

  
406
		public void process(int x, int y) {
407
			raster.getPixelShort(x, y, px);
408
			px[0] = (((int) (((double)px[0])*scale[0] + offset[0])) & 0xff);
409
			px[1] = (((int) (((double)px[1])*scale[1] + offset[1])) & 0xff);
410
			px[2] = (((int) (((double)px[2])*scale[2] + offset[2])) & 0xff);
411
			raster.setPixelShort(x, y, px);
412
		}
413
	}
414
	
415
	/**
416
	 * Renderiza el raster.
417
	 * @author Luis W. Sevilla (sevilla_lui@gva.es)
418
	 */
419
	
420
	class RasterToImageFilter extends RasterFilter {
421
		private BufferedImage image;
422
		private int alpha;
423
		private int rgb;
424
		public RasterToImageFilter(RasterBuf raster, int a) {
425
			super(raster);
426
			this.alpha = (a & 0xff) << 24;
427
			image = new BufferedImage(raster.getWidth(), raster.getHeight(), BufferedImage.TYPE_INT_ARGB);
428
			execute();
429
		}
361 430
		
431
		/* (non-Javadoc)
432
		 * @see org.cresques.px.PxRaster.RasterFilter#process(int, int)
433
		 */
434
		public void process(int x, int y) {
435
			raster.getPixelShort(x, y, px);
436
			rgb = alpha | ((px[0] & 0xff) << 16) |
437
					((px[1] & 0xff) << 8) | (px[2] & 0xff);
438
			
439
			image.setRGB(x, y, rgb);
440
		}
441
		
442
		public Image getImage() { return image; }
443
	}
444
	
445
	public Image renderizeRaster(RasterBuf raster) {
446
		ComputeMinMaxFilter filter = 
447
			new ComputeMinMaxFilter(raster, minBandValue, maxBandValue);
448
		for (int i=0; i<3; i++) {
449
			minBandValue[i] = filter.getMin(i);
450
			maxBandValue[i] = filter.getMax(i);
451
		}
452

  
453
		LinearEnhancementFilter lEFilter = 
454
			new LinearEnhancementFilter(raster, minBandValue, maxBandValue);
455

  
456
		Image image = new RasterToImageFilter(raster, getAlpha()).getImage();
457
		
362 458
		for (int i=0; i<3; i++)
363 459
			System.out.println("  Banda ["+i+"]: "+minBandValue[i]+"..."+maxBandValue[i]);
364 460
		return image;
365 461
	}
462
	
366 463
	public void drawMarco(Graphics2D g, ViewPortData vp) {
367 464
//		Color color = new Color(255,222,165,128), fillColor = new Color(255,214,132,128);
368 465
		Color color = new Color(128,128,128), fillColor = new Color(255,220,220,0x20);

Also available in: Unified diff