Revision 1033 org.gvsig.raster.lizardtech/trunk/org.gvsig.raster.lizardtech/org.gvsig.raster.lizardtech.io/src/main/java/org/gvsig/raster/lizardtech/io/LizardTechNative.java

View differences:

LizardTechNative.java
485 485

  
486 486
		buffer = null;
487 487
	}
488
	
489
	/**
490
	 * Reads a window of data. The size of the input window may not coincide 
491
	 * with the size of the buffer. In that case would have to resize
492
	 * @param buf
493
	 * @param bandList
494
	 * @param x
495
	 *        Initial X position in input buffer
496
	 * @param y
497
	 *        Initial Y position in input buffer
498
	 * @throws MrSIDException
499
	 * @throws ProcessInterruptedException
500
	 */
501
	public void readWindow(Buffer buf, 
502
			BandList bandList, 
503
			int x, int y, int w, int h, 
504
			int bufWidth, int bufHeight) throws MrSIDException, ProcessInterruptedException {
505
		if(bufWidth > buf.getWidth())
506
			bufWidth = buf.getWidth();
507
		
508
		if(bufHeight > buf.getHeight())
509
			bufHeight = buf.getHeight();
510
		
511
		if(buf.isCached()) {
512
			int nBlocks = (int)(bufHeight / buf.getBlockHeight());
513
			int lastBlock = bufHeight - (nBlocks * buf.getBlockHeight());
514
			int lastBlockSrc = (lastBlock * h) / bufHeight;
515
			int sizeBlockSrc = (buf.getBlockHeight() * h) / bufHeight;
516
			if(lastBlock > 0)
517
				nBlocks ++;
518
			int initSrc = y;
519
			int init = 0;
520
			for (int i = 0; i < nBlocks; i++) {
521
				if(lastBlock > 0 && i == (nBlocks - 1)) {
522
					double[] stepSrc = new double[]{x, initSrc, w, lastBlockSrc};
523
					int[] stepDst = new int[]{0, init, bufWidth, init + lastBlock};
524
					readWindowInMemory(buf, bandList, stepSrc, stepDst, w, lastBlock);
525
				} else {
526
					double[] stepSrc = new double[]{x, initSrc, w, sizeBlockSrc};
527
					int[] stepDst = new int[]{0, init, bufWidth, init + buf.getBlockHeight()};
528
					readWindowInMemory(buf, bandList, stepSrc, stepDst, w, buf.getBlockHeight());
529
					init += buf.getBlockHeight();
530
					initSrc += sizeBlockSrc;
531
				}
532
			}
533
		} else {
534
			readWindowInMemory(buf, bandList, x, y, w, h);
535
		}
536
	}
537
	
538
	/**
539
	 * Reads a window of data. The width and height is indicated by the size of the buffer 
540
	 * @param buf
541
	 * @param bandList
542
	 * @param x
543
	 *        Initial X position in input buffer
544
	 * @param y
545
	 *        Initial Y position in input buffer
546
	 * @throws MrSIDException
547
	 * @throws ProcessInterruptedException
548
	 */
549
	public void readWindow(Buffer buf, BandList bandList, int x, int y) throws MrSIDException, ProcessInterruptedException {
550
		int w = (x + buf.getWidth()) > getWidth() ? getWidth() - x : buf.getWidth();
551
		int h = (y + buf.getHeight()) > getHeight() ? getHeight() - y : buf.getHeight();
552
		
553
		if(buf.isCached()) {
554
			int nBlocks = (int)(buf.getHeight() / buf.getBlockHeight());
555
			int lastBlock = buf.getHeight() - (nBlocks * buf.getBlockHeight());
556
			if(lastBlock > 0)
557
				nBlocks ++;
558
			int init = 0;
559
			for (int i = 0; i < nBlocks; i++) {
560
				if(lastBlock > 0 && i == (nBlocks - 1)) {
561
					double[] stepSrc = new double[]{x, init, w, lastBlock};
562
					int[] stepDst = new int[]{0, init, w, init + lastBlock};
563
					readWindowInMemory(buf, bandList, stepSrc, stepDst, w, lastBlock);
564
				} else {
565
					double[] stepSrc = new double[]{x, init, w, buf.getBlockHeight()};
566
					int[] stepDst = new int[]{0, init, w, init + buf.getBlockHeight()};
567
					readWindowInMemory(buf, bandList, stepSrc, stepDst, w, buf.getBlockHeight());
568
					init += buf.getBlockHeight();
569
				}
570
			}
571
		} else {
572
			readWindowInMemory(buf, bandList, x, y, w, h);
573
		}
574
	}
575
	
488 576

  
577
	private void readWindowInMemory(Buffer buf, BandList bandList, double[] srcPxPos, int[] stepDst, int sizeSrcX, int sizeSrcY) throws MrSIDException, ProcessInterruptedException {
578
		RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
579
		
580
		isSupersampling = false;
581
	
582
		LTISceneBuffer buffer = ((LTIImageStage) this).readScene(
583
					srcPxPos[0], srcPxPos[1], srcPxPos[2], srcPxPos[3], 
584
					1.0, 
585
					(MrSIDImageReader)this, 
586
					sizeSrcX, sizeSrcY, 
587
					true);
588
		
589
		byte[] bandBuf = null;
590
		for(int iBand = 0; iBand < getNumBands(); iBand++) {
591
			int[] drawableBands = bandList.getBufferBandToDraw(fileName, iBand);
592
			if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1))
593
				continue;
594
			switch(iBand) {
595
			case 0:  bandBuf = buffer.buf1; break;
596
			case 1:  bandBuf = buffer.buf2; break;
597
			case 2:  bandBuf = buffer.buf3; break;
598
			}
599
			
600
			int lineSrc = 0;
601
			for (int line = stepDst[1]; line < stepDst[3]; line++) {
602
				int colSrc = 0;
603
				for (int col = stepDst[0]; col < stepDst[2]; col++) {
604
					int kd = (int)((lineSrc * srcPxPos[2]) + colSrc);
605
					buf.setElem(line, col, iBand, (byte)bandBuf[kd]);
606
					colSrc ++;
607
				}
608
				lineSrc ++;
609
				if(task.getEvent() != null)
610
					task.manageEvent(task.getEvent());
611
			}
612
		}
613
	}
614

  
489 615
	/**
490 616
	 * Lee una ventana de datos sin resampleo a partir de coordenadas en pixeles.
491 617
	 * @param buf Buffer donde se almacenan los datos
......
495 621
	 * @param w Ancho en pixeles
496 622
	 * @param h Alto en pixeles
497 623
	 */
498
	public void readWindow(Buffer buf, BandList bandList, int x, int y, int w, int h) throws MrSIDException, ProcessInterruptedException {
624
	private void readWindowInMemory(Buffer buf, BandList bandList, int x, int y, int w, int h) throws MrSIDException, ProcessInterruptedException {
499 625
		RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
500 626
		
501 627
		isSupersampling = false;

Also available in: Unified diff