Statistics
| Revision:

gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / test / impl / memory / TestRWTiffAndCompareData.java @ 1965

History | View | Annotate | Download (3.13 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
 * This test reads a Tiff from disk with the class TIFFRead and load data in
16
 * a memory buffer. Then it saves those bytes in a new out file in the same format.
17
 * Finally it compares the intput data with the output data to test if there are some
18
 * diferences.
19
 * 
20
 * @author Nacho Brodin (nachobrodin@gmail.com)
21
 */
22
public class TestRWTiffAndCompareData extends TestCase {
23
        private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
24
        private String rasterOut = "/tmp/out.tif";
25
        
26
        public void start() {
27
                this.setUp();
28
                this.testStack();
29
        }
30

    
31
        public void setUp() {
32
                System.err.println("MemoryBuffer TestRWTiffAndCompareData running...");
33
        }
34
        
35
        public void testStack() {
36
                long t1 = System.currentTimeMillis();
37
                GdalRead input = null;
38
                GdalWrite out = null;
39
                try {
40
                        
41
                        //Read input data
42
                        input = new GdalRead(rasterIn);
43
                        Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
44
                        
45
                        //Create Buffer
46
                        Buffer buf = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
47
                                                                                                                input.getWidth(), 
48
                                                                                                                input.getHeight(),
49
                                                                                                                input.getBandCount(),
50
                                                                                                                true);
51
                        
52
                        //Set data to buffer
53
                        if(dataIn instanceof byte[][][]) {
54
                            byte[][][] d = (byte[][][])dataIn;
55
                            for (int i = 0; i < d.length; i++) {
56
                                        for (int j = 0; j < d[i].length; j++) {
57
                                                buf.setLineInBandByte(d[i][j], j, i);
58
                                        }
59
                                }
60
                    }
61
                        
62
                        //Write output file 
63
                        out = new GdalWrite(rasterOut, input.getBandCount(), input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_RGB);
64
                        out.writeBands(buf.getBands());
65
                        out.close();        
66
                        
67
                        //Open output file and compare
68
                        GdalRead newFile = new GdalRead(rasterOut);
69
                        Object dataOut = newFile.readBlock(0, 0, input.getWidth(), input.getHeight());
70
                        
71
                        byte[][][] d1 = (byte[][][])dataIn;
72
                        byte[][][] d2 = (byte[][][])dataOut;
73
                        for (int iBand = 0; iBand < buf.getBandCount(); iBand++) {
74
                                for (int row = 0; row < buf.getHeight(); row++) {
75
                                        for (int col = 0; col < buf.getWidth(); col++) {
76
                                                if(d1[iBand][row][col] != d2[iBand][row][col])
77
                                                        System.out.println("BAND:" + iBand +" ROW:" + row + " COL:" + col + " " + d1[iBand][row][col] + " " + d2[iBand][row][col]);
78
                                                assertEquals(d1[iBand][row][col], d2[iBand][row][col]);
79
                                        }
80
                                }
81
                        }
82
                                
83
                } catch (GdalException e) {
84
                        e.printStackTrace();
85
                } catch (IOException e) {
86
                        e.printStackTrace();
87
                } catch (ProcessInterruptedException e) {
88
                        e.printStackTrace();
89
                } catch (OperationNotSupportedException e) {
90
                        e.printStackTrace();
91
                }
92
                long t2 = System.currentTimeMillis();
93
                System.out.println("Tiempo MemoryBuffer TestRWTiffAndCompareData: " + (t2 - t1) + " milisegundos");
94
        }
95
        
96
}