Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / driver / TestReadLineEcw.java @ 10768

History | View | Annotate | Download (5.81 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.driver;
20

    
21
import junit.framework.TestCase;
22

    
23
import org.gvsig.raster.driver.FileNotOpenException;
24
import org.gvsig.raster.driver.IBuffer;
25
import org.gvsig.raster.driver.InvalidSetViewException;
26
import org.gvsig.raster.driver.NotSupportedExtensionException;
27
import org.gvsig.raster.driver.RasterDataset;
28
import org.gvsig.raster.driver.RasterDriverException;
29
import org.gvsig.raster.shared.RasterLibrary;
30

    
31
/**
32
 * Test para validar la lectura por l?neas de un ecw.
33
 * Muestrea valores sobre toda la extensi?n leida y comprueba que el resultado sea correcto
34
 * @author Nacho Brodin (nachobrodin@gmail.com)
35
 *
36
 */
37
public class TestReadLineEcw extends TestCase{
38

    
39
        private String baseDir = "./test-images/";
40
        private String path1 = baseDir + "miniraster30x30.jp2";
41
        
42
        private RasterDataset f1 = null;
43
        
44
        static{
45
                RasterLibrary.wakeUp();
46
        }
47
        
48
        public void start(){
49
                this.setUp();
50
                this.testStack();
51
        }
52
        
53
        public void setUp() {
54
                System.err.println("TestReadLineEcw running...");
55
                try {
56
                        f1 = RasterDataset.openFile(null, path1);
57
                } catch (NotSupportedExtensionException e1) {
58
                        e1.printStackTrace();
59
                } catch (RasterDriverException e1) {
60
                        e1.printStackTrace();
61
                }
62
                
63
        }
64
        
65
        public void testStack(){
66
                try {
67
                        Object line = null;
68
                        for(int iBand = 0; iBand < f1.getBandCount(); iBand ++){
69
                                for(int iLine = 0; iLine < f1.getHeight(); iLine ++){
70
                                        line = f1.readCompletetLine(iLine, iBand);
71
                                        if(f1.getDataType() == IBuffer.TYPE_BYTE){
72
                                                byte[] b = (byte[])line;
73
                                                //printByteLine(b, iLine);
74
                                                if(iBand == 0 && iLine == 0)
75
                                                        testLine0_Banda0(b);
76
                                                if(iBand == 0 && iLine == 9)
77
                                                        testLine9_Banda0(b);
78
                                                if(iBand == 0 && iLine == 19)
79
                                                        testLine19_Banda0(b);
80
                                                if(iBand == 0 && iLine == 29)
81
                                                        testLine29_Banda0(b);
82
                                                
83
                                                if(iBand == 2 && iLine == 0)
84
                                                        testLine0_Banda2(b);
85
                                                if(iBand == 2 && iLine == 9)
86
                                                        testLine9_Banda2(b);
87
                                                if(iBand == 2 && iLine == 19)
88
                                                        testLine19_Banda2(b);
89
                                                if(iBand == 2 && iLine == 29)
90
                                                        testLine29_Banda2(b);
91
                                        }
92
                                }
93
                        }
94
                } catch (InvalidSetViewException e) {
95
                        e.printStackTrace();
96
                } catch (FileNotOpenException e) {
97
                        e.printStackTrace();
98
                } catch (RasterDriverException e) {
99
                        e.printStackTrace();
100
                }
101
        }
102
        
103
        private void printByteLine(byte[] line, int nLine){
104
                System.out.print("L?nea: " + nLine + "| ");
105
                for (int i = 0; i < line.length; i++)
106
                        System.out.print((int)(line[i] & 0x000000ff) + " ");
107
                System.out.println();
108
        }
109
        
110
        public void testLine0_Banda0(byte[] line)throws InvalidSetViewException, FileNotOpenException, RasterDriverException{
111
                assertEquals((int)(line[0] & 0x000000ff), 43);
112
                assertEquals((int)(line[9] & 0x000000ff), 83);
113
                assertEquals((int)(line[19] & 0x000000ff), 75);
114
                assertEquals((int)(line[29] & 0x000000ff), 255);
115
        }
116
        
117
        public void testLine9_Banda0(byte[] line)throws InvalidSetViewException, FileNotOpenException, RasterDriverException{
118
                assertEquals((int)(line[0] & 0x000000ff), 118);
119
                assertEquals((int)(line[9] & 0x000000ff), 81);
120
                assertEquals((int)(line[19] & 0x000000ff), 105);
121
                assertEquals((int)(line[29] & 0x000000ff), 114);
122
        }
123
        
124
        public void testLine19_Banda0(byte[] line)throws InvalidSetViewException, FileNotOpenException, RasterDriverException{
125
                assertEquals((int)(line[0] & 0x000000ff), 70);
126
                assertEquals((int)(line[9] & 0x000000ff), 49);
127
                assertEquals((int)(line[19] & 0x000000ff), 63);
128
                assertEquals((int)(line[29] & 0x000000ff), 147);
129
        }
130
        
131
        public void testLine29_Banda0(byte[] line)throws InvalidSetViewException, FileNotOpenException, RasterDriverException{
132
                assertEquals((int)(line[0] & 0x000000ff), 175);
133
                assertEquals((int)(line[9] & 0x000000ff), 129);
134
                assertEquals((int)(line[19] & 0x000000ff), 15);
135
                assertEquals((int)(line[29] & 0x000000ff), 126);
136
        }
137
        
138
        public void testLine0_Banda2(byte[] line)throws InvalidSetViewException, FileNotOpenException, RasterDriverException{
139
                assertEquals((int)(line[0] & 0x000000ff), 26);
140
                assertEquals((int)(line[9] & 0x000000ff), 68);
141
                assertEquals((int)(line[19] & 0x000000ff), 70);
142
                assertEquals((int)(line[29] & 0x000000ff), 246);
143
        }
144
        
145
        public void testLine9_Banda2(byte[] line)throws InvalidSetViewException, FileNotOpenException, RasterDriverException{
146
                assertEquals((int)(line[0] & 0x000000ff), 96);
147
                assertEquals((int)(line[9] & 0x000000ff), 93);
148
                assertEquals((int)(line[19] & 0x000000ff), 93);
149
                assertEquals((int)(line[29] & 0x000000ff), 102);
150
        }
151
        
152
        public void testLine19_Banda2(byte[] line)throws InvalidSetViewException, FileNotOpenException, RasterDriverException{
153
                assertEquals((int)(line[0] & 0x000000ff), 81);
154
                assertEquals((int)(line[9] & 0x000000ff), 46);
155
                assertEquals((int)(line[19] & 0x000000ff), 63);
156
                assertEquals((int)(line[29] & 0x000000ff), 123);
157
        }
158
        
159
        public void testLine29_Banda2(byte[] line)throws InvalidSetViewException, FileNotOpenException, RasterDriverException{
160
                assertEquals((int)(line[0] & 0x000000ff), 147);
161
                assertEquals((int)(line[9] & 0x000000ff), 110);
162
                assertEquals((int)(line[19] & 0x000000ff), 14);
163
                assertEquals((int)(line[29] & 0x000000ff), 111);
164
        }
165

    
166
}