Revision 130 trunk/libraries/libCq CMS for java.old/src/org/cresques/io/EcwFile.java
EcwFile.java | ||
---|---|---|
7 | 7 |
import java.awt.image.BufferedImage; |
8 | 8 |
|
9 | 9 |
import com.ermapper.ecw.JNCSFile; |
10 |
import com.ermapper.ecw.JNCSProgressiveUpdate; |
|
10 | 11 |
import com.ermapper.util.JNCSDatasetPoint; |
11 | 12 |
|
12 | 13 |
import org.cresques.cts.ICoordTrans; |
... | ... | |
72 | 73 |
/** |
73 | 74 |
* Soporte para los ficheros .ecw de ErMapper |
74 | 75 |
* |
76 |
* NOTA: El SDK que ermapper ha puesto a disposici?n del p?blico en java |
|
77 |
* es una versi?n 2.45, de 19/11/2001. Est? implementada usando JNI que |
|
78 |
* se apoya en tres librer?as din?micas (dll), y presenta deficiencias |
|
79 |
* muy graves a la hora de acceder a la informaci?n. Hasta el momento |
|
80 |
* hemos detectado 3 de ellas: |
|
81 |
* 1?.- No soporta ampliaciones superiores a 1:1. si se intenta acceder |
|
82 |
* a un ecw con un zoom mayor da una excepci?n del tipo |
|
83 |
* com.ermapper.ecw.JNCSInvalidSetViewException, que de no ser tenida encuenta |
|
84 |
* acaba tirando abajo la m?quina virtual de java. |
|
85 |
* 2?.- La longitud m?xima de l?nea que adminte el m?todo readLineRGBA es |
|
86 |
* de unos 2500 pixeles, lo que hace el uso para la impresi?n en formatos |
|
87 |
* superiorea a A4 a 300 ppp o m?s inviable. |
|
88 |
* 3?.- La actualizaci?n progresiva usando el interface JNCSProgressiveUpdate |
|
89 |
* con el JNCSFile hace que el equipo genere un error severo y se apague. Este |
|
90 |
* error imposibilita esta t?cnica de acceso a ECW. |
|
91 |
* |
|
75 | 92 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es> |
76 | 93 |
*/ |
77 | 94 |
|
78 |
public class EcwFile extends GeoRasterFile { |
|
79 |
JNCSFile file = null; |
|
80 |
boolean bErrorOnOpen = false; |
|
81 |
String errorMessage = null; |
|
95 |
public class EcwFile extends GeoRasterFile implements JNCSProgressiveUpdate {
|
|
96 |
private JNCSFile file = null;
|
|
97 |
private boolean bErrorOnOpen = false;
|
|
98 |
private String errorMessage = null;
|
|
82 | 99 |
|
83 |
Extent v = null; |
|
84 |
boolean doTransparency = false; |
|
85 |
PixelFilter tFilter = null; |
|
100 |
private Extent v = null;
|
|
101 |
private boolean doTransparency = false;
|
|
102 |
private PixelFilter tFilter = null;
|
|
86 | 103 |
|
104 |
// Ultimo porcentaje de refresco. Se carga en el update y se |
|
105 |
// actualiza en el refreshUpdate |
|
106 |
private int lastRefreshPercent = 0; |
|
107 |
|
|
87 | 108 |
public EcwFile(IProjection proj, String fName) { |
88 | 109 |
super(proj, null); |
89 | 110 |
fName = DataSource.normalize(fName); |
... | ... | |
91 | 112 |
extent = new Extent(); |
92 | 113 |
try { |
93 | 114 |
System.err.println("Abriendo "+fName); |
94 |
file = new JNCSFile(fName, false); |
|
115 |
file = new JNCSFile(fName, true); |
|
116 |
file.addProgressiveUpdateListener(this); |
|
117 |
|
|
95 | 118 |
load(); |
96 | 119 |
} catch(Exception e) { |
97 | 120 |
bErrorOnOpen = true; |
... | ... | |
137 | 160 |
file.close(true); |
138 | 161 |
file = null; |
139 | 162 |
} |
163 |
|
|
164 |
public int getWidth() { return file.width; } |
|
165 |
public int getHeight() { return file.height; } |
|
140 | 166 |
|
141 | 167 |
/** |
142 | 168 |
* Obtiene un trozo de imagen (determinado por la vista y los par?metros. |
... | ... | |
145 | 171 |
* @param height |
146 | 172 |
*/ |
147 | 173 |
|
148 |
public Image updateImage(int width, int height, ICoordTrans rp) { |
|
149 |
// TODO reproyectar |
|
174 |
public synchronized Image updateImage(int width, int height, ICoordTrans rp) { |
|
175 |
// TODO reproyectar para devolver el trozo de imagen pedida sobre ... |
|
176 |
// la proyecci?n de destino. |
|
150 | 177 |
BufferedImage ecwImage = null; |
151 |
if (file != null) {
|
|
152 |
try {
|
|
178 |
if (file == null) return ecwImage;
|
|
179 |
try { |
|
153 | 180 |
double dFileAspect, dWindowAspect; |
154 | 181 |
//double dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY; |
155 | 182 |
int bandlist[]; |
... | ... | |
182 | 209 |
JNCSDatasetPoint ptMax = file.convertWorldToDataset(v.maxX(), v.maxY()); |
183 | 210 |
System.out.println("Dataset coords Width = "+(ptMax.x-ptMin.x)+", px width ="+width); |
184 | 211 |
// Set the view |
185 |
try { |
|
186 |
file.setView(file.numBands, bandlist, |
|
187 |
v.minX(), v.maxY(), v.maxX(), v.minY(), |
|
188 |
width, height); |
|
189 |
} catch (com.ermapper.ecw.JNCSInvalidSetViewException e) { |
|
190 |
System.err.println(errorMessage); |
|
191 |
e.printStackTrace(); |
|
192 |
} |
|
212 |
file.setView(file.numBands, bandlist, |
|
213 |
v.minX(), v.maxY(), v.maxX(), v.minY(), |
|
214 |
width, height); |
|
193 | 215 |
|
194 | 216 |
// Read the scan lines |
195 | 217 |
for (line=0; line < height; line++) { |
196 |
file.readLineRGBA(pRGBArray);
|
|
197 |
// Prueba de sustituci?n de color transparente
|
|
198 |
if (doTransparency) {
|
|
218 |
file.readLineRGBA(pRGBArray);
|
|
219 |
// Prueba de sustituci?n de color transparente
|
|
220 |
if (doTransparency) {
|
|
199 | 221 |
if (line == 0) tFilter.debug = true; |
200 | 222 |
tFilter.filterLine(pRGBArray); |
201 | 223 |
tFilter.debug = false; |
202 |
|
|
203 |
} |
|
204 |
ecwImage.setRGB(0, line, width, 1, pRGBArray, 0, width); |
|
224 |
} |
|
225 |
ecwImage.setRGB(0, line, width, 1, pRGBArray, 0, width); |
|
205 | 226 |
} |
206 | 227 |
updateImage(width, height); |
207 |
} catch(Exception e) { |
|
228 |
/* |
|
229 |
* La excepci?n atrapada es la de 'zoom > 1:1 no valido' |
|
230 |
} catch (com.ermapper.ecw.JNCSInvalidSetViewException e) { |
|
231 |
System.err.println(errorMessage); |
|
232 |
e.printStackTrace(); */ |
|
233 |
} catch(Exception e) { |
|
208 | 234 |
bErrorOnOpen = true; |
209 | 235 |
errorMessage = e.getMessage(); |
210 | 236 |
// g.drawString(errorMessage, 0, 50); |
211 | 237 |
System.err.println(errorMessage); |
212 | 238 |
e.printStackTrace(); |
213 |
} |
|
214 | 239 |
} |
240 |
lastRefreshPercent = file.getPercentComplete(); |
|
215 | 241 |
return ecwImage; |
216 | 242 |
} |
217 | 243 |
|
218 | 244 |
private void updateImage(int width, int height) { |
219 |
|
|
220 | 245 |
} |
221 |
|
|
222 | 246 |
|
223 | 247 |
/** |
224 |
* Cambia el raster de proyecci?n.
|
|
248 |
* Reproyecta el raster.
|
|
225 | 249 |
*/ |
226 |
|
|
227 | 250 |
public void reProject(ICoordTrans rp) { |
228 | 251 |
// TODO metodo reProject pendiente de implementar |
229 | 252 |
} |
230 | 253 |
|
254 |
|
|
255 |
/** |
|
256 |
* Soporte para actualizaci?n de la imagen |
|
257 |
* @see com.ermapper.ecw.JNCSProgressiveUpdate#refreshUpdate(int, int, double, double, double, double) |
|
258 |
*/ |
|
259 |
public void refreshUpdate(int nWidth, int nHeight, double dWorldTLX, double dWorldTLY, double dWorldBRX, double dWorldBRY) { |
|
260 |
int completado = file.getPercentComplete(); |
|
261 |
System.out.println("EcwFile: se actualiza 1: "+completado+" % completado"); |
|
262 |
if ((updatable != null) && (lastRefreshPercent < 100)) { |
|
263 |
if ((completado-lastRefreshPercent > 25) || completado == 100) { |
|
264 |
lastRefreshPercent = file.getPercentComplete(); |
|
265 |
updatable.repaint(); |
|
266 |
} |
|
267 |
} |
|
268 |
} |
|
269 |
|
|
270 |
public void refreshUpdate(int nWidth, int nHeight, int dDatasetTLX, int dDatasetTLY, int dDatasetBRX, int dDatasetBRY) { |
|
271 |
System.out.println("EcwFile: se actualiza 2"); |
|
272 |
} |
|
231 | 273 |
} |
Also available in: Unified diff