Statistics
| Revision:

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 / TestAddBand.java @ 991

History | View | Annotate | Download (1.94 KB)

1
package org.gvsig.raster.cache.buffer.impl.rocache;
2

    
3
import java.awt.image.DataBuffer;
4
import java.io.IOException;
5

    
6
import junit.framework.TestCase;
7

    
8
import org.gvsig.jgdal.GdalException;
9
import org.gvsig.raster.cache.buffer.Band;
10
import org.gvsig.raster.cache.buffer.BufferDataSource;
11
import org.gvsig.raster.cache.buffer.Buffer;
12
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
13
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
14

    
15
/**
16
 * This test add a band in a raster of 3 bands. As a result of this test a raster
17
 * of four bands is created and saved in the hard disk. The value of additional band
18
 * is zero in all its elements. Finally it gets the band added and compare each values 
19
 * with 0. 
20
 *  
21
 * @author Nacho Brodin (nachobrodin@gmail.com)
22
 */
23
public class TestAddBand extends TestCase {
24
        private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
25
        
26
        public void start() {
27
                this.setUp();
28
                this.testStack();
29
        }
30

    
31
        public void setUp() {
32
                System.err.println("ROCache TestAddBand 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(DataBuffer.TYPE_BYTE, 
49
                                        input.getWidth(), 
50
                                        input.getHeight(), 
51
                                        input.getBandCount(), 
52
                                        ds);
53
                        buf.addBand(1);
54
                                                
55
                        Band band = buf.getBand(1);
56
                        for (int i = 0; i < band.getHeight(); i++) {
57
                                for (int j = 0; j < band.getWidth(); j++) {
58
                                        byte b = band.getElemByte(i, j);
59
                                        assertEquals(0, b);
60
                                }
61
                        }
62
                        
63
                        buf.free();
64
                } catch (GdalException e) {
65
                        e.printStackTrace();
66
                } catch (IOException e) {
67
                        e.printStackTrace();
68
                }
69
                long t2 = System.currentTimeMillis();
70
                System.out.println("Tiempo ROCache TestAddBand: " + (t2 - t1) + " milisegundos");
71
        }        
72
}