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 / memory / TestMemoryBuffer.java @ 1023
History | View | Annotate | Download (2.08 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.memory; |
---|---|
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 |
|
14 |
/**
|
15 |
*
|
16 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
17 |
*/
|
18 |
public class TestMemoryBuffer extends TestCase { |
19 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
20 |
private String rasterOut = "/tmp/out.tif"; |
21 |
|
22 |
public void start() { |
23 |
this.setUp();
|
24 |
this.testStack();
|
25 |
} |
26 |
|
27 |
public void setUp() { |
28 |
System.err.println("MemoryBuffer TestMemoryBuffer running..."); |
29 |
} |
30 |
|
31 |
public void testStack() { |
32 |
long t1 = System.currentTimeMillis(); |
33 |
GdalRead input = null;
|
34 |
GdalWrite out = null;
|
35 |
try {
|
36 |
input = new GdalRead(rasterIn);
|
37 |
Object data = input.readBlock(0, 0, input.getWidth(), input.getHeight()); |
38 |
|
39 |
Buffer buf = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
40 |
input.getWidth(), |
41 |
input.getHeight(), |
42 |
input.getBandCount(), |
43 |
true);
|
44 |
|
45 |
if(data instanceof byte[][][]) { |
46 |
byte[][][] d = (byte[][][])data; |
47 |
for (int i = 0; i < d.length; i++) { |
48 |
for (int j = 0; j < d[i].length; j++) { |
49 |
buf.setLineInBandByte(d[i][j], j, i); |
50 |
} |
51 |
} |
52 |
} |
53 |
out = new GdalWrite(rasterOut, input.getBandCount(), input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_RGB);
|
54 |
out.writeBands(buf.getBands()); |
55 |
out.close(); |
56 |
|
57 |
} catch (GdalException e) {
|
58 |
e.printStackTrace(); |
59 |
} catch (IOException e) { |
60 |
e.printStackTrace(); |
61 |
} catch (ProcessInterruptedException e) {
|
62 |
e.printStackTrace(); |
63 |
} catch (OperationNotSupportedException e) { |
64 |
e.printStackTrace(); |
65 |
} |
66 |
long t2 = System.currentTimeMillis(); |
67 |
System.out.println("Tiempo MemoryBuffer TestMemoryBuffer: " + (t2 - t1) + " milisegundos"); |
68 |
} |
69 |
|
70 |
} |