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 / TestInterpolationBicubicReduction.java @ 1023

History | View | Annotate | Download (2.71 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 TestInterpolationBicubicReduction extends TestCase {
21
        private String         rasterIn  = "./src/test/resources/image/001m09_1_0.tif";
22
        private String         rasterOut = "/tmp/out-interpBicubicReduction.tif";
23
        private static int     REL       = 5;
24
        
25
        public void start() {
26
                this.setUp();
27
                this.testStack();
28
        }
29

    
30
        public void setUp() {
31
                System.err.println("TestInterpolationBicubicReduction 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
                        Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
42
                                                
43
                        //Create Buffer
44
                        Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
45
                                                                                                                input.getWidth(), 
46
                                                                                                                input.getHeight(),
47
                                                                                                                input.getBandCount(),
48
                                                                                                                true);
49
                        
50
                        //Set data to buffer
51
                        setLines(dataIn, buf1);
52
                        Buffer buf = buf1.getAdjustedWindow(input.getWidth() / REL, input.getHeight() / REL, BufferInterpolationImpl.INTERPOLATION_Bicubic);
53
                                                
54
                        //Write output file 
55
                        out = new GdalWrite(rasterOut, 3, input.getDataType(), buf.getWidth(), buf.getHeight(), GdalWrite.COLOR_INTERP_RGB);
56
                        out.writeBands(buf.getBands());
57
                        out.close();        
58
                        
59
                        buf1.free();
60
                } catch (GdalException e) {
61
                        e.printStackTrace();
62
                } catch (IOException e) {
63
                        e.printStackTrace();
64
                } catch (ProcessInterruptedException e) {
65
                        e.printStackTrace();
66
                } catch (OperationNotSupportedException e) {
67
                        e.printStackTrace();
68
                }
69
                long t2 = System.currentTimeMillis();
70
                System.out.println("Tiempo TestInterpolationBicubicReduction: " + (t2 - t1) + " milisegundos");
71
        }
72
        
73
        private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
74
                if(dataIn instanceof byte[][][]) {
75
                    byte[][][] d = (byte[][][])dataIn;
76
                    for (int iBand = 0; iBand < d.length; iBand++) {
77
                                for (int row = 0; row < d[iBand].length; row++) {
78
                                        buf.setLineInBandByte(d[iBand][row], row, iBand);
79
                                }
80
                        }
81
            }
82
        }
83
        
84
}
85