gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / src / test / java / org / gvsig / raster / cache / buffer / impl / rocache / TestGetBufferWithOneBand.java @ 999
History | View | Annotate | Download (2.98 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.rocache; |
---|---|
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.BufferDataSource; |
10 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
11 |
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl; |
12 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
13 |
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite; |
14 |
|
15 |
/**
|
16 |
* This test gets bands from a raster with the method getBufferWithOneBand() and compare
|
17 |
* each band from original source with obtained bands
|
18 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
19 |
*/
|
20 |
public class TestGetBufferWithOneBand extends TestCase { |
21 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
22 |
private String rasterOut1 = "/tmp/out-b1.tif"; |
23 |
private String rasterOut2 = "/tmp/out-b2.tif"; |
24 |
private String rasterOut3 = "/tmp/out-b3.tif"; |
25 |
|
26 |
public void start() { |
27 |
this.setUp();
|
28 |
this.testStack();
|
29 |
} |
30 |
|
31 |
public void setUp() { |
32 |
System.err.println("ROCache TestGetBufferWithOneBand running..."); |
33 |
} |
34 |
|
35 |
public void testStack() { |
36 |
long t1 = System.currentTimeMillis(); |
37 |
GdalRead input = null;
|
38 |
try {
|
39 |
//Read input data
|
40 |
input = new GdalRead(rasterIn);
|
41 |
|
42 |
BufferDataSource ds = null;
|
43 |
try {
|
44 |
ds = new BufferDataSourceImpl(rasterIn);
|
45 |
} catch (IOException e) { |
46 |
e.printStackTrace(); |
47 |
} |
48 |
Buffer buf = new RasterReadOnlyBuffer(ds); |
49 |
|
50 |
Buffer b0 = buf.getBufferWithOneBand(0); |
51 |
Buffer b1 = buf.getBufferWithOneBand(1); |
52 |
Buffer b2 = buf.getBufferWithOneBand(2); |
53 |
|
54 |
//Write output file
|
55 |
GdalWrite out1 = new GdalWrite(rasterOut1, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY); |
56 |
out1.writeBands(b0.getBands()); |
57 |
out1.close(); |
58 |
|
59 |
GdalWrite out2 = new GdalWrite(rasterOut2, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY); |
60 |
out2.writeBands(b1.getBands()); |
61 |
out2.close(); |
62 |
|
63 |
GdalWrite out3 = new GdalWrite(rasterOut3, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY); |
64 |
out3.writeBands(b2.getBands()); |
65 |
out3.close(); |
66 |
|
67 |
for (int row = 0; row < buf.getHeight(); row++) { |
68 |
for (int col = 0; col < buf.getWidth(); col++) { |
69 |
byte b_0 = buf.getElemByte(row, col, 0); |
70 |
byte b_1 = buf.getElemByte(row, col, 1); |
71 |
byte b_2 = buf.getElemByte(row, col, 2); |
72 |
assertEquals(b_0, b0.getElemByte(row, col, 0));
|
73 |
assertEquals(b_1, b1.getElemByte(row, col, 0));
|
74 |
assertEquals(b_2, b2.getElemByte(row, col, 0));
|
75 |
} |
76 |
} |
77 |
|
78 |
b0.free(); |
79 |
b1.free(); |
80 |
b2.free(); |
81 |
buf.free(); |
82 |
|
83 |
} catch (GdalException e) {
|
84 |
e.printStackTrace(); |
85 |
} catch (IOException e) { |
86 |
e.printStackTrace(); |
87 |
} catch (OperationNotSupportedException e) { |
88 |
e.printStackTrace(); |
89 |
} |
90 |
long t2 = System.currentTimeMillis(); |
91 |
System.out.println("Tiempo ROCache TestGetBufferWithOneBand: " + (t2 - t1) + " milisegundos"); |
92 |
} |
93 |
|
94 |
} |