gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / test / impl / TestInterpolationNearestIncrease.java @ 1965
History | View | Annotate | Download (2.67 KB)
1 |
package org.gvsig.raster.cache.buffer.impl; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import junit.framework.TestCase; |
6 |
|
7 |
import org.gvsig.jgdal.GdalException; |
8 |
import org.gvsig.raster.cache.buffer.Buffer; |
9 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
10 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
11 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
12 |
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite; |
13 |
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer; |
14 |
|
15 |
/**
|
16 |
* Copy the band 0 from a buffer over the band 2 in the same buffer using the
|
17 |
* method getBandCopy.
|
18 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
19 |
*/
|
20 |
public class TestInterpolationNearestIncrease extends TestCase { |
21 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
22 |
private String rasterOut = "/tmp/out-interpNearest.tif"; |
23 |
private static int REL = 2; |
24 |
|
25 |
public void start() { |
26 |
this.setUp();
|
27 |
this.testStack();
|
28 |
} |
29 |
|
30 |
public void setUp() { |
31 |
System.err.println("MemoryBuffer TestCopyBand running..."); |
32 |
} |
33 |
|
34 |
public void testStack() { |
35 |
long t1 = System.currentTimeMillis(); |
36 |
GdalRead input = null;
|
37 |
GdalWrite out = null;
|
38 |
try {
|
39 |
//Read input data
|
40 |
input = new GdalRead(rasterIn);
|
41 |
int readSize = 10; |
42 |
Object dataIn = input.readBlock(0, 0, readSize, readSize); |
43 |
|
44 |
//Create Buffer
|
45 |
Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
46 |
readSize, |
47 |
readSize, |
48 |
input.getBandCount(), |
49 |
true);
|
50 |
|
51 |
//Set data to buffer
|
52 |
setLines(dataIn, buf1); |
53 |
Buffer buf = buf1.getAdjustedWindow(readSize * REL, readSize * REL, BufferInterpolationImpl.INTERPOLATION_NearestNeighbour);
|
54 |
|
55 |
//Write output file
|
56 |
out = new GdalWrite(rasterOut, 3, input.getDataType(), buf.getWidth(), buf.getHeight(), GdalWrite.COLOR_INTERP_RGB); |
57 |
out.writeBands(buf.getBands()); |
58 |
out.close(); |
59 |
|
60 |
buf1.free(); |
61 |
} catch (GdalException e) {
|
62 |
e.printStackTrace(); |
63 |
} catch (IOException e) { |
64 |
e.printStackTrace(); |
65 |
} catch (ProcessInterruptedException e) {
|
66 |
e.printStackTrace(); |
67 |
} catch (OperationNotSupportedException e) { |
68 |
e.printStackTrace(); |
69 |
} |
70 |
long t2 = System.currentTimeMillis(); |
71 |
System.out.println("Tiempo MemoryBuffer TestCopyBand: " + (t2 - t1) + " milisegundos"); |
72 |
} |
73 |
|
74 |
private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
75 |
if(dataIn instanceof byte[][][]) { |
76 |
byte[][][] d = (byte[][][])dataIn; |
77 |
for (int iBand = 0; iBand < d.length; iBand++) { |
78 |
for (int row = 0; row < d[iBand].length; row++) { |
79 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
80 |
} |
81 |
} |
82 |
} |
83 |
} |
84 |
|
85 |
} |
86 |
|