Statistics
| Revision:

gvsig-raster / org.gvsig.raster.ermapper / trunk / org.gvsig.raster.ermapper / org.gvsig.raster.ermapper.jni / src / test / java / com / ermapper / ecw / TestCompressImage.java @ 2449

History | View | Annotate | Download (3.64 KB)

1
package com.ermapper.ecw;
2

    
3
import junit.framework.TestCase;
4
import es.gva.cit.jecwcompress.CompressFormat;
5
import es.gva.cit.jecwcompress.EcwException;
6
import es.gva.cit.jecwcompress.JniObject;
7
import es.gva.cit.jecwcompress.NCSEcwCompressClient;
8
import es.gva.cit.jecwcompress.ReadCallBack;
9

    
10
public class TestCompressImage extends TestCase{
11

    
12
        private JNCSFile                                 file = null;
13
        
14
        private String                                         fileName = "miniraster30x30.jp2";
15
        private String                                        outFileName = "compressTestOutput.jp2";
16
        private String                                         baseDir = "./test-images/";
17
        private String                                         file1 = baseDir + fileName;
18
        private String                                        outFile = baseDir + outFileName;
19
        
20
        private NCSEcwCompressClient         client = null;
21
        private Read                                         lectura=null;
22
        
23
        private int                                                numBands = 0;
24
        private int                                                xSize = 0;
25
        private int                                                ySize = 0;
26
        
27
        
28
        public void start(){
29
                setUp();
30
                testStack();
31
        }
32
        
33
        public void setUp(){
34
                try {
35
                        file = new JNCSFile();
36
                        file.open(file1, true);
37
                        numBands = file.numBands;
38
                        xSize = file.width;
39
                        ySize = file.height;
40
                } catch (JNCSException e) {
41
                } 
42
                
43

    
44
                  try{
45
                          client = new NCSEcwCompressClient();
46
                  
47
                          client.setOutputFilename(outFile);          
48
                          client.setInputFilename(file1);
49
                        client.setTargetCompress(10.0);
50
                    client.setInOutSizeX(xSize);
51
                    client.setInOutSizeY(ySize);
52
                    client.setInputBands(numBands);
53
                    
54
                    client.setCompressFormat(CompressFormat.COMPRESS_NONE);
55
                        
56
                        client.setProjection("WGS84");
57
                        client.setCellIncrementX(file.cellIncrementX);
58
                        client.setCellIncrementY(file.cellIncrementY);
59
                        client.setOriginX(file.originX);
60
                        client.setOriginY(file.originY);
61
                        client.setCellSizeUnits(1);
62
                
63
                        lectura = new Read(file, client, 0, ySize, xSize, ySize);
64
                        client.NCSEcwCompressOpen(false);
65
                        client.NCSEcwCompress(lectura);
66
                        client.NCSEcwCompressClose();
67
                                          
68
                  }catch(EcwException e){
69
                          assertNotNull(client);
70
                  }
71
                
72
        }
73
        
74
        public void testStack(){
75
                
76
        }
77
}
78

    
79
/**
80
*
81
* Para la lectura hay que hacer una clase que extienda de JniObject e implemente ReadCallBack
82
* . Esto obliga a crear un m?todo loadBuffer. En el hay que meter la funcionalidad para que
83
* llene el buffer. El buffer esta en la clase cliente y tendr? una longitud de 
84
* ancho de una l?nea * n?mero de bandas
85
*/
86

    
87
class Read extends JniObject implements ReadCallBack {
88
        
89
        private JNCSFile miecw=null;
90
        private NCSEcwCompressClient client=null;
91
        private int width, height;
92
        private int ulX, ulY;
93
        private int[] readBandsFromECW = null;
94
        private int[] inputRow = null;
95
        
96
        public Read(JNCSFile ecw, NCSEcwCompressClient client,int ulx, int uly, int width, int height){
97
                this.miecw = ecw;
98
                this.client = client;
99
                this.width = width;
100
                this.height = height;
101
                this.ulX = ulx;
102
                this.ulY = uly;
103
                readBandsFromECW = new int[Math.max(miecw.numBands, 3)];
104
                inputRow = new int[miecw.width];
105
        }
106

    
107
        public void loadBuffer(){
108
                try {
109
                        readBandsFromECW = new int[]{0, 1, 2};
110
                        miecw.setView(miecw.numBands, readBandsFromECW, miecw.originX, miecw.originY + (miecw.cellIncrementY * nNextLine),
111
                                        miecw.originX + (miecw.cellIncrementX * miecw.width), 
112
                                        miecw.originY + (miecw.cellIncrementY * (nNextLine + 1)), 
113
                                        miecw.width, 1);
114

    
115
                        miecw.readLineRGBA(inputRow);
116
                        for(int col=0 ; col<inputRow.length ; col++){                                
117
                                client.buffer[col+(width*0)]=(byte)Math.abs(((inputRow[col] & 0x00ff0000) >> 16));
118
                                client.buffer[col+(width*1)]=(byte)Math.abs(((inputRow[col] & 0x0000ff00) >> 8));
119
                                client.buffer[col+(width*2)]=(byte)Math.abs((inputRow[col] & 0x000000ff));
120
                        }
121
                } catch (JNCSFileNotOpenException e) {
122
                } catch (JNCSInvalidSetViewException e) {
123
                } catch (JNCSException e) {
124
                }
125
        }
126

    
127
        public void updatePercent(){
128
                System.out.println(client.getPercent()+"%");
129
        }
130
}