Revision 12475
org.gvsig.raster.ermapper/tags/org.gvsig.raster.ermapper-2.2.115/org.gvsig.raster.ermapper.io/src/main/java/org/gvsig/raster/ermapper/io/ErmapperFilesystemServerExplorer.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.raster.ermapper.io; |
|
29 |
|
|
30 |
import java.awt.geom.AffineTransform; |
|
31 |
import java.io.File; |
|
32 |
import java.io.IOException; |
|
33 |
|
|
34 |
import org.gvsig.fmap.dal.DALLocator; |
|
35 |
import org.gvsig.fmap.dal.DataManager; |
|
36 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
37 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
38 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
39 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
40 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
|
41 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
42 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
43 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
44 |
import org.gvsig.fmap.dal.coverage.store.DataServerWriter; |
|
45 |
import org.gvsig.fmap.dal.coverage.store.RasterWriter; |
|
46 |
import org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters; |
|
47 |
import org.gvsig.fmap.dal.exception.CreateException; |
|
48 |
import org.gvsig.fmap.dal.exception.DataException; |
|
49 |
import org.gvsig.fmap.dal.exception.RemoveException; |
|
50 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider; |
|
51 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices; |
|
52 |
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters; |
|
53 |
import org.gvsig.tools.locator.LocatorException; |
|
54 |
|
|
55 |
public class ErmapperFilesystemServerExplorer extends AbstractFilesystemServerExplorerProvider { |
|
56 |
|
|
57 |
/* |
|
58 |
* (non-Javadoc) |
|
59 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#canCreate() |
|
60 |
*/ |
|
61 |
public boolean canCreate() { |
|
62 |
return false; |
|
63 |
} |
|
64 |
|
|
65 |
/* |
|
66 |
* (non-Javadoc) |
|
67 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#canCreate(org.gvsig.fmap.dal.NewDataStoreParameters) |
|
68 |
*/ |
|
69 |
public boolean canCreate(NewDataStoreParameters parameters) { |
|
70 |
return false; |
|
71 |
} |
|
72 |
|
|
73 |
/* |
|
74 |
* (non-Javadoc) |
|
75 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#create(org.gvsig.fmap.dal.NewDataStoreParameters, boolean) |
|
76 |
*/ |
|
77 |
public void create(NewDataStoreParameters parameters, boolean overwrite) |
|
78 |
throws CreateException { |
|
79 |
NewRasterStoreParameters p = null; |
|
80 |
if(parameters instanceof NewRasterStoreParameters) |
|
81 |
p = (NewRasterStoreParameters)parameters; |
|
82 |
|
|
83 |
DataServerWriter dataWriter = p.getDataServer(); |
|
84 |
if(dataWriter == null) |
|
85 |
dataWriter = RasterLocator.getManager().createDataServerWriter(); |
|
86 |
dataWriter.setBuffer(p.getBuffer(), p.getBand()); |
|
87 |
Params params; |
|
88 |
try { |
|
89 |
if(p.getDriverParams() != null) |
|
90 |
params = p.getDriverParams(); |
|
91 |
else |
|
92 |
params = RasterLocator.getManager().createWriter(p.getFileName()).getParams(); |
|
93 |
|
|
94 |
AffineTransform affineTransform = p.getAffineTransform(); |
|
95 |
if(affineTransform == null) { |
|
96 |
if(p.getBuffer().getDataExtent() != null) { |
|
97 |
double x = p.getBuffer().getDataExtent().getMinX(); |
|
98 |
double y = p.getBuffer().getDataExtent().getMaxY(); |
|
99 |
double pixelSizeX = p.getBuffer().getDataExtent().getWidth() / p.getBuffer().getWidth(); |
|
100 |
double pixelSizeY = p.getBuffer().getDataExtent().getHeight() / p.getBuffer().getHeight(); |
|
101 |
affineTransform = new AffineTransform(pixelSizeX, 0, 0, pixelSizeY, x, y); |
|
102 |
} else { |
|
103 |
affineTransform = new AffineTransform(); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
RasterWriter writer = RasterLocator.getManager().createWriter( |
|
108 |
dataWriter, |
|
109 |
p.getPath() + File.separator + p.getFileName(), |
|
110 |
p.getBand() < 0 ? p.getBuffer().getBandCount() : 1, |
|
111 |
affineTransform, |
|
112 |
p.getBuffer().getWidth(), |
|
113 |
p.getBuffer().getHeight(), |
|
114 |
p.getBuffer().getDataType(), |
|
115 |
params, |
|
116 |
null); |
|
117 |
if(p.getColorInterpretation() != null) |
|
118 |
writer.setColorBandsInterpretation(p.getColorInterpretation()); |
|
119 |
writer.setWkt(p.getWktProjection()); |
|
120 |
|
|
121 |
writer.dataWrite(); |
|
122 |
writer.writeClose(); |
|
123 |
} catch (LocatorException e) { |
|
124 |
throw new CreateException("", e); |
|
125 |
} catch (NotSupportedExtensionException e) { |
|
126 |
throw new CreateException("", e); |
|
127 |
} catch (RasterDriverException e) { |
|
128 |
throw new CreateException("", e); |
|
129 |
} catch (ProcessInterruptedException e) { |
|
130 |
//Fin del proceso |
|
131 |
} catch (IOException e) { |
|
132 |
throw new CreateException("", e); |
|
133 |
} |
|
134 |
} |
|
135 |
|
|
136 |
/* |
|
137 |
* (non-Javadoc) |
|
138 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#getCreateParameters() |
|
139 |
*/ |
|
140 |
public NewDataStoreParameters getCreateParameters() throws DataException { |
|
141 |
return new ErmapperNewRasterStoreParameters(); |
|
142 |
} |
|
143 |
|
|
144 |
/* |
|
145 |
* (non-Javadoc) |
|
146 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#initialize(org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices) |
|
147 |
*/ |
|
148 |
public void initialize( |
|
149 |
FilesystemServerExplorerProviderServices serverExplorer) { |
|
150 |
} |
|
151 |
|
|
152 |
/* |
|
153 |
* (non-Javadoc) |
|
154 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider#remove(org.gvsig.fmap.dal.DataStoreParameters) |
|
155 |
*/ |
|
156 |
public void remove(DataStoreParameters parameters) throws RemoveException { |
|
157 |
throw new UnsupportedOperationException(); |
|
158 |
} |
|
159 |
|
|
160 |
/* |
|
161 |
* (non-Javadoc) |
|
162 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemFileFilter#getDataStoreProviderName() |
|
163 |
*/ |
|
164 |
public String getDataStoreProviderName() { |
|
165 |
return ErmapperProvider.NAME; |
|
166 |
} |
|
167 |
|
|
168 |
/* |
|
169 |
* (non-Javadoc) |
|
170 |
* @see java.io.FileFilter#accept(java.io.File) |
|
171 |
*/ |
|
172 |
public boolean accept(File pathname) { |
|
173 |
return RasterLocator.getManager().getProviderServices().isExtensionSupported( |
|
174 |
pathname.getAbsolutePath(), |
|
175 |
ErmapperProvider.class); |
|
176 |
} |
|
177 |
|
|
178 |
/* |
|
179 |
* (non-Javadoc) |
|
180 |
* @see org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemFileFilter#getDescription() |
|
181 |
*/ |
|
182 |
public String getDescription() { |
|
183 |
return ErmapperProvider.DESCRIPTION; |
|
184 |
} |
|
185 |
|
|
186 |
public DataStoreParameters getParameters(File file) throws DataException { |
|
187 |
DataManager manager = DALLocator.getDataManager(); |
|
188 |
AbstractRasterFileDataParameters params = (AbstractRasterFileDataParameters) manager |
|
189 |
.createStoreParameters(this.getDataStoreProviderName()); |
|
190 |
params.setFile(file); |
|
191 |
return params; |
|
192 |
} |
|
193 |
|
|
194 |
public int getMode() { |
|
195 |
return DataServerExplorer.MODE_RASTER; |
|
196 |
} |
|
197 |
} |
|
0 | 198 |
org.gvsig.raster.ermapper/tags/org.gvsig.raster.ermapper-2.2.115/org.gvsig.raster.ermapper.io/src/main/java/org/gvsig/raster/ermapper/io/ErmapperWriter.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.ermapper.io; |
|
23 |
|
|
24 |
import java.awt.geom.AffineTransform; |
|
25 |
import java.awt.geom.Point2D; |
|
26 |
import java.io.File; |
|
27 |
import java.io.IOException; |
|
28 |
|
|
29 |
import org.cresques.cts.IProjection; |
|
30 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
|
31 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
32 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
33 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
|
34 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
35 |
import org.gvsig.fmap.dal.coverage.process.CancelEvent; |
|
36 |
import org.gvsig.fmap.dal.coverage.process.TaskEventManager; |
|
37 |
import org.gvsig.fmap.dal.coverage.store.DataServerWriter; |
|
38 |
import org.gvsig.fmap.dal.coverage.store.ExternalCancellable; |
|
39 |
import org.gvsig.raster.impl.store.ParamImpl; |
|
40 |
import org.gvsig.raster.impl.store.WriteFileFormatFeatures; |
|
41 |
import org.gvsig.raster.impl.store.writer.DefaultRasterWriter; |
|
42 |
import org.gvsig.raster.util.DefaultProviderServices; |
|
43 |
import org.gvsig.tools.ToolsLocator; |
|
44 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
45 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
46 |
|
|
47 |
import es.gva.cit.jecwcompress.EcwException; |
|
48 |
import es.gva.cit.jecwcompress.JniObject; |
|
49 |
import es.gva.cit.jecwcompress.NCSEcwCompressClient; |
|
50 |
import es.gva.cit.jecwcompress.ReadCallBack; |
|
51 |
/** |
|
52 |
* Driver para la compresi?n en formato Ecw. |
|
53 |
* |
|
54 |
* Puede exportar un fichero desde un GeoRasterFile en cualquier formato soportado |
|
55 |
* por los drivers de lectura a uno en formato Ecw. |
|
56 |
* |
|
57 |
* Puede salvar a disco en formato Ecw obteniendo los datos que van siendo servidos |
|
58 |
* desde el cliente. Este cliente debe implementar un DataServerWriter o tener un objeto |
|
59 |
* que lo implemente. Inicialmente le pasar? los par?metros de la imagen de salida |
|
60 |
* y cuando el driver comience a escribir le ir? solicitando m?s a trav?s del m?todo |
|
61 |
* readData de DataServerWriter. El cliente ser? el que lleve el control de lo que va |
|
62 |
* sirviendo y lo que le queda por servir. |
|
63 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
64 |
*/ |
|
65 |
public class ErmapperWriter extends DefaultRasterWriter { |
|
66 |
|
|
67 |
public static void register() { |
|
68 |
DefaultProviderServices pInfo = (DefaultProviderServices)RasterLocator.getManager().getProviderServices(); |
|
69 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
|
70 |
ExtensionPoint point = extensionPoints.get("RasterWriter"); |
|
71 |
WriteFileFormatFeatures features = null; |
|
72 |
|
|
73 |
String os = System.getProperties().getProperty("os.version"); |
|
74 |
if (os.startsWith("2.4")){ |
|
75 |
point.append("ecw", "", ErmapperWriter.class); |
|
76 |
features = new WriteFileFormatFeatures("Ecw", "ecw", new int[]{3}, null, ErmapperWriter.class); |
|
77 |
pInfo.getFileFeature().put("ecw", features); |
|
78 |
} |
|
79 |
point.append("jp2", "", ErmapperWriter.class); |
|
80 |
features = new WriteFileFormatFeatures("Jpeg2000", "jp2", new int[]{3}, null, ErmapperWriter.class); |
|
81 |
pInfo.getFileFeature().put("jp2", features); |
|
82 |
} |
|
83 |
|
|
84 |
public final int windowSizeX = 386; |
|
85 |
public final int windowSizeY = 220; |
|
86 |
public final int panelSizeX = 358; |
|
87 |
public final int panelSizeY = 125; |
|
88 |
public final String panelLayout = "BorderLayout"; |
|
89 |
private NCSEcwCompressClient compressclient = null; |
|
90 |
private Reader readerObj; |
|
91 |
private double pixelSizeX; |
|
92 |
private double pixelSizeY; |
|
93 |
private double geoCoordOrigenX; |
|
94 |
private double geoCoordOrigenY; |
|
95 |
private boolean consulta = false; |
|
96 |
|
|
97 |
/** |
|
98 |
* Carga los par?metros de este driver. |
|
99 |
*/ |
|
100 |
public void loadParams() { |
|
101 |
WriteFileFormatFeatures wfff = new WriteFileFormatFeatures(); |
|
102 |
wfff.loadParams(); |
|
103 |
driverParams = wfff.getParams(); |
|
104 |
|
|
105 |
driverParams.setParam( "compression", |
|
106 |
new Integer(10), |
|
107 |
Params.SLIDER, |
|
108 |
new String[]{ "1", "20", "10", "1", "5" }); //min, max, valor defecto, intervalo peque?o, intervalo grande; |
|
109 |
|
|
110 |
driverParams.setParam( "format", |
|
111 |
new Integer(4), |
|
112 |
Params.CHOICE, |
|
113 |
new String[]{ "NONE", "UINT8", "YUV", "MULTI", "RGB"}); |
|
114 |
} |
|
115 |
|
|
116 |
/* |
|
117 |
* (non-Javadoc) |
|
118 |
* @see org.gvsig.fmap.dal.coverage.store.RasterWriter#getProviderName() |
|
119 |
*/ |
|
120 |
public String getProviderName() { |
|
121 |
return ErmapperProvider.NAME; |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Constructor para la obtenci?n de par?metros del driver. |
|
126 |
*/ |
|
127 |
public ErmapperWriter(String fileName) { |
|
128 |
DefaultProviderServices pInfo = (DefaultProviderServices)RasterLocator.getManager().getProviderServices(); |
|
129 |
ident = fileUtil.getExtensionFromFileName(fileName); |
|
130 |
driver = ((WriteFileFormatFeatures)pInfo.getFileFeature().get(ident)).getDriverName(); |
|
131 |
|
|
132 |
loadParams(); |
|
133 |
|
|
134 |
consulta = true; |
|
135 |
} |
|
136 |
|
|
137 |
/** |
|
138 |
* Constructor para la lectura de datos desde el objeto cliente a partir de un |
|
139 |
* viewport dado. |
|
140 |
* @param dataWriter Objeto que sirve datos para el escritor |
|
141 |
* @param outFileName Fichero de salida |
|
142 |
* @param nBands N?mero de bandas |
|
143 |
* @param at |
|
144 |
* @param outSizeX |
|
145 |
* @param outSizeY |
|
146 |
* @param dataType |
|
147 |
* @param params |
|
148 |
* @param proj |
|
149 |
* @param geo |
|
150 |
* @throws EcwException |
|
151 |
* @throws IOException |
|
152 |
*/ |
|
153 |
public ErmapperWriter( DataServerWriter dataWriter, |
|
154 |
String outFileName, |
|
155 |
Integer nBands, |
|
156 |
AffineTransform at, |
|
157 |
Integer outSizeX, |
|
158 |
Integer outSizeY, |
|
159 |
Integer dataType, |
|
160 |
Params params, |
|
161 |
IProjection proj, |
|
162 |
Boolean geo) throws EcwException, IOException { |
|
163 |
DefaultProviderServices pInfo = (DefaultProviderServices)RasterLocator.getManager().getProviderServices(); |
|
164 |
//La libreria de ECW no se traga caracteres raros al escribir. Los cambiamos por X de momento y ya se apa?a el usuario |
|
165 |
|
|
166 |
String ext = fileUtil.getExtensionFromFileName(outFileName); |
|
167 |
String fname = outFileName.substring(outFileName.lastIndexOf(File.separator) + 1, outFileName.lastIndexOf(".")).replaceAll("[^a-zA-Z0-9_]", "X"); |
|
168 |
outFileName = outFileName.substring(0, outFileName.lastIndexOf(File.separator) + 1) + fname + "." + ext; |
|
169 |
|
|
170 |
this.proj = proj; |
|
171 |
ident = fileUtil.getExtensionFromFileName(outFileName); |
|
172 |
driver = ((WriteFileFormatFeatures)pInfo.getFileFeature().get(ident)).getDriverName(); |
|
173 |
this.dataType = dataType.intValue(); |
|
174 |
|
|
175 |
if (nBands.intValue() <= 0) |
|
176 |
throw new EcwException("N?mero de bandas erroneo."); |
|
177 |
|
|
178 |
this.outFileName = outFileName; |
|
179 |
this.dataWriter = dataWriter; |
|
180 |
|
|
181 |
this.nBands = nBands.intValue(); |
|
182 |
|
|
183 |
this.sizeWindowX = outSizeX.intValue(); |
|
184 |
this.sizeWindowY = outSizeY.intValue(); |
|
185 |
|
|
186 |
//Calculamos la georeferenciaci?n a partir del extend pasado por el cliente. |
|
187 |
geoCoordOrigenX = at.getTranslateX(); |
|
188 |
geoCoordOrigenY = at.getTranslateY(); |
|
189 |
|
|
190 |
pixelSizeX = (at.getScaleX() > 0) ? at.getScaleX() : -at.getScaleX(); |
|
191 |
pixelSizeY = (at.getScaleY() < 0) ? at.getScaleY() : -at.getScaleY(); |
|
192 |
|
|
193 |
String outRmf = fileUtil.getNameWithoutExtension(outFileName); |
|
194 |
if(geo.booleanValue()) |
|
195 |
rasterUtil.saveGeoInfo(outRmf, at, new Point2D.Double(sizeWindowX, sizeWindowY)); |
|
196 |
|
|
197 |
if (pixelSizeX == 0) |
|
198 |
pixelSizeX = 1.0; |
|
199 |
|
|
200 |
if (pixelSizeY == 0) |
|
201 |
pixelSizeY = 1.0; |
|
202 |
|
|
203 |
if(params == null) |
|
204 |
loadParams(); |
|
205 |
else |
|
206 |
driverParams = params; |
|
207 |
|
|
208 |
init(); |
|
209 |
} |
|
210 |
|
|
211 |
/** |
|
212 |
* Inicializaci?n de los par?metros del compresor que ser?n obtenidos |
|
213 |
* de PxRaster. |
|
214 |
* @throws EcwException |
|
215 |
*/ |
|
216 |
private void init() throws EcwException { |
|
217 |
percent = 0; |
|
218 |
int comp = ((Integer)(((ParamImpl)driverParams.getParamById("compression"))).getDefaultValue()).intValue(); |
|
219 |
ParamImpl param = (ParamImpl)driverParams.getParamById("format"); |
|
220 |
String format = param.getList()[((Integer)param.getDefaultValue()).intValue()]; |
|
221 |
if ( comp == 0 ) |
|
222 |
driverParams.changeParamValue("compression", "1"); |
|
223 |
|
|
224 |
if (compressclient == null) |
|
225 |
compressclient = new NCSEcwCompressClient(); |
|
226 |
|
|
227 |
compressclient.setOutputFilename(outFileName); |
|
228 |
compressclient.setInputFilename(inFileName); |
|
229 |
compressclient.setTargetCompress(comp); |
|
230 |
compressclient.setInOutSizeX(sizeWindowX); |
|
231 |
compressclient.setInOutSizeY(sizeWindowY); |
|
232 |
compressclient.setInputBands(nBands); |
|
233 |
compressclient.setCompressFormat(convertFormatToInt(format)); |
|
234 |
|
|
235 |
/* boolean georef = new Boolean(((Param)driverParams.getParamById("georef")).defaultValue).booleanValue(); |
|
236 |
if (georef) {*/ |
|
237 |
compressclient.setCellIncrementX(pixelSizeX); |
|
238 |
compressclient.setCellIncrementY(pixelSizeY); |
|
239 |
compressclient.setOriginX(geoCoordOrigenX); |
|
240 |
compressclient.setOriginY(geoCoordOrigenY); |
|
241 |
//} |
|
242 |
|
|
243 |
compressclient.setCellSizeUnits(1); |
|
244 |
int blocksize = RasterLibrary.blockHeight; |
|
245 |
|
|
246 |
if (dataWriter != null) |
|
247 |
readerObj = new Reader(dataWriter, compressclient, sizeWindowX, |
|
248 |
sizeWindowY, blocksize, nBands, this, dataType); |
|
249 |
} |
|
250 |
|
|
251 |
/** |
|
252 |
* Convierte la cadena que representa el formato en un valor n?merico |
|
253 |
* que entiende el driver. |
|
254 |
* @param format Cadena que representa el formato |
|
255 |
* @return Entero que representa a la cadena |
|
256 |
*/ |
|
257 |
private int convertFormatToInt(String format) { |
|
258 |
if(format.compareTo("NONE") == 0) |
|
259 |
return 0; |
|
260 |
if(format.compareTo("UINT8") == 0) |
|
261 |
return 1; |
|
262 |
if(format.compareTo("YUV") == 0) |
|
263 |
return 2; |
|
264 |
if(format.compareTo("MULTI") == 0) |
|
265 |
return 3; |
|
266 |
if(format.compareTo("RGB") == 0) |
|
267 |
return 4; |
|
268 |
return -1; |
|
269 |
} |
|
270 |
/** |
|
271 |
* A partir de un elemento que contiene una propiedad y un valor |
|
272 |
* lo parsea y asigna el valor a su variable. |
|
273 |
* @param propValue elemento con la forma propiedad=valor |
|
274 |
*/ |
|
275 |
private void readProperty(String propValue) { |
|
276 |
String prop = propValue.substring(0, propValue.indexOf("=")); |
|
277 |
|
|
278 |
if (propValue.startsWith(prop)) { |
|
279 |
String value = propValue.substring(propValue.indexOf("=") + 1, propValue.length()); |
|
280 |
|
|
281 |
if ((value != null) && !value.equals("")) { |
|
282 |
if (prop.equals("BLOCKSIZE")) |
|
283 |
driverParams.changeParamValue("blocksize", value); |
|
284 |
if (prop.equals("FORMAT")) |
|
285 |
driverParams.changeParamValue("format", value); |
|
286 |
if (prop.equals("COMPRESSION")) |
|
287 |
driverParams.changeParamValue("compression", value); |
|
288 |
} |
|
289 |
} |
|
290 |
} |
|
291 |
|
|
292 |
/** |
|
293 |
* Asigna propiedades al driver a partir de un vector de |
|
294 |
* strings donde cada elemento tiene la estructura de |
|
295 |
* propiedad=valor. |
|
296 |
* @param props Propiedades |
|
297 |
*/ |
|
298 |
public void setProps(String[] props) { |
|
299 |
for (int iProps = 0; iProps < props.length; iProps++) |
|
300 |
readProperty(props[iProps]); |
|
301 |
|
|
302 |
loadParams(); |
|
303 |
|
|
304 |
try { |
|
305 |
if (!consulta) |
|
306 |
init(); |
|
307 |
} catch (EcwException e) { |
|
308 |
e.printStackTrace(); |
|
309 |
} |
|
310 |
} |
|
311 |
|
|
312 |
/** |
|
313 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile. |
|
314 |
* @throws IOException |
|
315 |
*/ |
|
316 |
public void fileWrite() throws IOException { |
|
317 |
/* try { |
|
318 |
compressclient.NCSEcwCompressOpen(false); |
|
319 |
compressclient.NCSEcwCompress(readerObj); |
|
320 |
} catch (EcwException e) { |
|
321 |
e.printStackTrace(); |
|
322 |
}*/ |
|
323 |
//TODO: FUNCIONALIDAD: Compresi?n a partir de un dataset. De momento no es necesario y es posible que nunca lo sea. |
|
324 |
} |
|
325 |
|
|
326 |
/** |
|
327 |
* Realiza la funci?n de compresi?n a partir de los datos pasados por el cliente. |
|
328 |
* @throws IOException |
|
329 |
*/ |
|
330 |
public void dataWrite() throws IOException, ProcessInterruptedException { |
|
331 |
if (dataWriter == null) |
|
332 |
throw new IOException("No se ha obtenido un objeto para la lectura valido."); |
|
333 |
|
|
334 |
try { |
|
335 |
compressclient.NCSEcwCompressOpen(false); |
|
336 |
compressclient.NCSEcwCompress(readerObj); |
|
337 |
} catch (EcwException e) { |
|
338 |
throw new IOException("Error en la compresi?n."); |
|
339 |
} |
|
340 |
} |
|
341 |
|
|
342 |
/** |
|
343 |
* Cierra el compresor ecw. |
|
344 |
*/ |
|
345 |
public void writeClose() { |
|
346 |
try { |
|
347 |
compressclient.NCSEcwCompressClose(); |
|
348 |
} catch (EcwException e) { |
|
349 |
e.printStackTrace(); |
|
350 |
} |
|
351 |
} |
|
352 |
|
|
353 |
/** |
|
354 |
* Cancela el compresor ecw. |
|
355 |
*/ |
|
356 |
public void writeCancel() { |
|
357 |
try { |
|
358 |
if(readerObj != null) |
|
359 |
readerObj.setWrite(false); |
|
360 |
compressclient.NCSEcwCompressCancel(); |
|
361 |
} catch (EcwException e) { |
|
362 |
e.printStackTrace(); |
|
363 |
} |
|
364 |
} |
|
365 |
|
|
366 |
/* |
|
367 |
* (non-Javadoc) |
|
368 |
* @see org.gvsig.raster.dataset.GeoRasterWriter#setWkt(java.lang.String) |
|
369 |
*/ |
|
370 |
public void setWkt(String wkt) { |
|
371 |
//TODO: FUNCIONALIDAD: La asignaci?n de proyecci?n en Ecw falla haciendo petar la aplicaci?n. |
|
372 |
/*if(compressclient != null && wkt != null && wkt.compareTo("unknown") != 0) { |
|
373 |
WktUtils wktutil = new WktUtils(wkt); |
|
374 |
compressclient.setProjection("EPSG:" + wktutil.getEPSG()); |
|
375 |
}*/ |
|
376 |
} |
|
377 |
|
|
378 |
/* |
|
379 |
* (non-Javadoc) |
|
380 |
* @see org.gvsig.raster.dataset.GeoRasterWriter#setCancellableRasterDriver(org.gvsig.raster.dataset.io.IExternalCancellable) |
|
381 |
*/ |
|
382 |
public void setCancellableRasterDriver(ExternalCancellable cancellable) { |
|
383 |
super.setCancellableRasterDriver(cancellable); |
|
384 |
if(readerObj != null) |
|
385 |
readerObj.setCancellableRasterDriver(cancellable); |
|
386 |
} |
|
387 |
|
|
388 |
} |
|
389 |
|
|
390 |
|
|
391 |
/** |
|
392 |
* Clase que se encarga de la lectura de datos que ser?n escritos. Hereda de JniObject |
|
393 |
* para asegurar para asegurar que el interfaz de la libreria tiene acceso a variables |
|
394 |
* necesarias para la petici?n de datos cuando vacia el buffer. Implementa ReadCallBack |
|
395 |
* para obligar escribir el m?todo loadBuffer encargado de servir los datos cuando el |
|
396 |
* buffer se vacia. |
|
397 |
* |
|
398 |
*/ |
|
399 |
class Reader extends JniObject implements ReadCallBack { |
|
400 |
private NCSEcwCompressClient compressclient = null; |
|
401 |
private int width; |
|
402 |
//private int height; |
|
403 |
//private int ulX; |
|
404 |
//private int ulY; |
|
405 |
private DataServerWriter dataWriter = null; |
|
406 |
//private GdalRasterBand rband = null; |
|
407 |
private DefaultRasterWriter writer = null; |
|
408 |
private int blockSizeRead = 1; //Alto del bloque leido de la imagen origen |
|
409 |
private int countLine = 1; //Contador de l?neas procesadas en cada lectura de bloque |
|
410 |
byte[][] buf = null; |
|
411 |
byte[] bufband1 = null; |
|
412 |
byte[] bufband2 = null; |
|
413 |
byte[] bufband3 = null; |
|
414 |
byte[] bufband4 = null; |
|
415 |
byte[] bufband5 = null; |
|
416 |
byte[] bufband6 = null; |
|
417 |
int[] dataBuffer = null; |
|
418 |
byte[][] byteBuffer = null; |
|
419 |
private int lineasBloqueFinal = 0; //N?mero de l?neas leidas del bloque final |
|
420 |
private int nBlocks = 0; //N?mero de bloques completos |
|
421 |
private int countBlock = 1; //Contador de bloques completos procesados |
|
422 |
private int nBands = 0; |
|
423 |
private boolean write = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido |
|
424 |
private int dataType = Buffer.TYPE_BYTE; |
|
425 |
protected ExternalCancellable extCancellable = null; |
|
426 |
|
|
427 |
/** |
|
428 |
* Constructor para que los datos sean servidos desde el cliente a trav?s de un |
|
429 |
* DataServerWriter. |
|
430 |
* @param dataWriter Objeto servidor de datos del driver |
|
431 |
* @param compressclient Objeto que representa al compresor ecw |
|
432 |
* @param width Ancho de la imagen |
|
433 |
* @param height Alto de la imagen |
|
434 |
* @param blockSizeRead Altura del bloque en la lectura |
|
435 |
* @param nBands N?mero de bandas |
|
436 |
*/ |
|
437 |
public Reader(DataServerWriter dataWriter, NCSEcwCompressClient compressclient, |
|
438 |
int width, int height, int blockSizeRead, int nBands, |
|
439 |
DefaultRasterWriter writer, int dataType) { |
|
440 |
this.compressclient = compressclient; |
|
441 |
this.width = width; |
|
442 |
//this.height = height; |
|
443 |
this.dataWriter = dataWriter; |
|
444 |
this.nBands = nBands; |
|
445 |
this.writer = writer; |
|
446 |
this.dataType = dataType; |
|
447 |
|
|
448 |
if (blockSizeRead != 0) |
|
449 |
this.blockSizeRead = blockSizeRead; |
|
450 |
|
|
451 |
nBlocks = (height / this.blockSizeRead); |
|
452 |
lineasBloqueFinal = height - (nBlocks * this.blockSizeRead); |
|
453 |
} |
|
454 |
|
|
455 |
/** |
|
456 |
* Lectura de bandas llamando al objeto cliente para que nos cargue el buffer |
|
457 |
* @param width Ancho de la imagen |
|
458 |
* @param height Alto de la imagen |
|
459 |
*/ |
|
460 |
/*private void readBands(int width, int height) { |
|
461 |
if(dataType == IBuffer.TYPE_IMAGE) |
|
462 |
dataBuffer = dataWriter.readARGBData(width, height, 0); |
|
463 |
if(dataType == IBuffer.TYPE_BYTE) { |
|
464 |
byte[][] b = dataWriter.readByteData(width, height); |
|
465 |
|
|
466 |
} |
|
467 |
}*/ |
|
468 |
|
|
469 |
public void setCancellableRasterDriver(ExternalCancellable cancellable) { |
|
470 |
this.extCancellable = cancellable; |
|
471 |
} |
|
472 |
|
|
473 |
/** |
|
474 |
* M?todo obligado por el interfaz y que es llamado desde C cuando el |
|
475 |
* compresor necesita que le sirvan m?s datos. |
|
476 |
*/ |
|
477 |
public void loadBuffer() { |
|
478 |
TaskEventManager taskEventManager = RasterLocator.getManager().getRasterTask(); |
|
479 |
if(taskEventManager.getEvent() != null) { |
|
480 |
if (taskEventManager.getEvent() instanceof CancelEvent) { |
|
481 |
try { |
|
482 |
if (extCancellable != null) |
|
483 |
extCancellable.processFinalize(); |
|
484 |
compressclient.NCSEcwCompressCancel(); |
|
485 |
} catch (EcwException e1) { |
|
486 |
} |
|
487 |
return; |
|
488 |
} |
|
489 |
} |
|
490 |
|
|
491 |
int lineasLeidas = 0; |
|
492 |
|
|
493 |
//si se leen bloques completos lineasLeidas es == al tama?o de bloque sino |
|
494 |
//es que es el ?ltimo con lo que ser? del tama?o del bloque final |
|
495 |
if (countBlock <= nBlocks) |
|
496 |
lineasLeidas = blockSizeRead; |
|
497 |
else |
|
498 |
lineasLeidas = lineasBloqueFinal; |
|
499 |
|
|
500 |
try { |
|
501 |
// Leemos un bloque nuevo cuando se han procesado todas las l?neas |
|
502 |
// del anterior |
|
503 |
if ((nNextLine % blockSizeRead) == 0) { |
|
504 |
if (dataWriter != null) { |
|
505 |
if (dataType == Buffer.TYPE_IMAGE) |
|
506 |
dataBuffer = dataWriter.readARGBData(width, |
|
507 |
lineasLeidas, 0); |
|
508 |
if (dataType == Buffer.TYPE_BYTE) |
|
509 |
byteBuffer = dataWriter.readByteData(width, |
|
510 |
lineasLeidas); |
|
511 |
} |
|
512 |
|
|
513 |
countLine = 0; |
|
514 |
countBlock++; |
|
515 |
} |
|
516 |
|
|
517 |
if (dataType == Buffer.TYPE_IMAGE) |
|
518 |
loadBufferFromImageDataType(dataBuffer); |
|
519 |
if (dataType == Buffer.TYPE_BYTE) |
|
520 |
loadBufferFromByteDataType(byteBuffer); |
|
521 |
} catch (ProcessInterruptedException e) { |
|
522 |
|
|
523 |
} |
|
524 |
|
|
525 |
} |
|
526 |
|
|
527 |
/** |
|
528 |
* Carga el buffer de datos desde elementos de tipo entero con contenido ARGB |
|
529 |
* @param data Array de datos enteros |
|
530 |
*/ |
|
531 |
private void loadBufferFromImageDataType(int[] data) { |
|
532 |
for (int iBand = 0; iBand < this.nBands; iBand++) |
|
533 |
for (int pos = 0; pos < width; pos++) { |
|
534 |
switch(iBand) { |
|
535 |
case 0: |
|
536 |
compressclient.buffer[pos + (width * iBand)] = |
|
537 |
(byte) ((data[pos + (width * countLine)] & 0xff0000) >> 16); |
|
538 |
break; |
|
539 |
case 1: |
|
540 |
compressclient.buffer[pos + (width * iBand)] = |
|
541 |
(byte) ((data[pos + (width * countLine)] & 0xff00) >> 8); |
|
542 |
break; |
|
543 |
case 2: |
|
544 |
compressclient.buffer[pos + (width * iBand)] = |
|
545 |
(byte) (data[pos + (width * countLine)] & 0xff); |
|
546 |
break; |
|
547 |
} |
|
548 |
if ((pos == (width - 1)) && (iBand == (this.nBands - 1))) |
|
549 |
countLine++; |
|
550 |
} |
|
551 |
} |
|
552 |
|
|
553 |
/** |
|
554 |
* Carga el buffer de datos a comprimir desde un buffer byte[][] donde la primera dimensi?n |
|
555 |
* es el n?mero de bandas y la segunda los elementos en lista (Ancho X Alto) |
|
556 |
* @param b Buffer de datos de tipo byte[][] |
|
557 |
*/ |
|
558 |
private void loadBufferFromByteDataType(byte[][] b) { |
|
559 |
for (int iBand = 0; iBand < this.nBands; iBand++) |
|
560 |
for (int pos = 0; pos < width; pos++) { |
|
561 |
compressclient.buffer[pos + (width * iBand)] = b[iBand][pos + (width * countLine)]; |
|
562 |
if ((pos == (width - 1)) && (iBand == (this.nBands - 1))) |
|
563 |
countLine++; |
|
564 |
} |
|
565 |
} |
|
566 |
|
|
567 |
/** |
|
568 |
* M?todo obligado por el interfaz y que es llamado desde C cuando el |
|
569 |
* compresor actualiza el porcentaje de compresi?n |
|
570 |
*/ |
|
571 |
public void updatePercent() { |
|
572 |
writer.setPercent(compressclient.getPercent()); |
|
573 |
//System.out.println(compressclient.getPercent() + "%"); |
|
574 |
} |
|
575 |
|
|
576 |
/** |
|
577 |
* Obtiene el valor a la variable write que estar? a true cuando se est? escribiendo |
|
578 |
* o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura |
|
579 |
* pondr? esta variable a false deteniendose la escritura y cerrandose el dataset |
|
580 |
* de salida. |
|
581 |
* @return True si puede escribirse y false si no puede |
|
582 |
*/ |
|
583 |
public boolean isWrite() { |
|
584 |
return write; |
|
585 |
} |
|
586 |
|
|
587 |
/** |
|
588 |
* Asigna el valor a la variable write que estar? a true cuando se est? escribiendo |
|
589 |
* o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura |
|
590 |
* pondr? esta variable a false deteniendose la escritura y cerrandose el dataset |
|
591 |
* de salida. |
|
592 |
* @param write Variable booleana. True si puede escribirse y false si no puede |
|
593 |
*/ |
|
594 |
public void setWrite(boolean write) { |
|
595 |
this.write = write; |
|
596 |
} |
|
597 |
|
|
598 |
} |
|
0 | 599 |
org.gvsig.raster.ermapper/tags/org.gvsig.raster.ermapper-2.2.115/org.gvsig.raster.ermapper.io/src/main/java/org/gvsig/raster/ermapper/io/ErmapperDataParameters.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.raster.ermapper.io; |
|
29 |
|
|
30 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
|
31 |
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters; |
|
32 |
import org.gvsig.tools.ToolsLocator; |
|
33 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
34 |
import org.gvsig.tools.dynobject.DynStruct; |
|
35 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
36 |
|
|
37 |
/** |
|
38 |
* Parameters for the Ecw provider |
|
39 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
40 |
*/ |
|
41 |
public class ErmapperDataParameters extends AbstractRasterFileDataParameters { |
|
42 |
|
|
43 |
public ErmapperDataParameters() { |
|
44 |
initialize(); |
|
45 |
} |
|
46 |
|
|
47 |
protected void initialize() { |
|
48 |
this.delegatedDynObject = (DelegatedDynObject) ToolsLocator |
|
49 |
.getDynObjectManager().createDynObject( |
|
50 |
registerDynClass()); |
|
51 |
} |
|
52 |
|
|
53 |
public String getDataStoreName() { |
|
54 |
return ErmapperProvider.NAME; |
|
55 |
} |
|
56 |
|
|
57 |
public String getDescription() { |
|
58 |
return ErmapperProvider.DESCRIPTION; |
|
59 |
} |
|
60 |
|
|
61 |
public static DynStruct registerDynClass() { |
|
62 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
63 |
DynStruct definition = manager.getDefinition("ErmapperDataParameters_Persistent"); |
|
64 |
if( definition == null ) { |
|
65 |
|
|
66 |
definition = manager.addDefinition( |
|
67 |
ErmapperDataParameters.class, |
|
68 |
"ErmapperDataParameters_Persistent", |
|
69 |
"ErmapperDataParameters Persistent", |
|
70 |
null, |
|
71 |
null |
|
72 |
); |
|
73 |
AbstractRasterDataParameters.registerDynClass(definition); |
|
74 |
} |
|
75 |
return definition; |
|
76 |
} |
|
77 |
} |
|
0 | 78 |
org.gvsig.raster.ermapper/tags/org.gvsig.raster.ermapper-2.2.115/org.gvsig.raster.ermapper.io/src/main/java/org/gvsig/raster/ermapper/io/DefaultErmapperIOLibrary.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.ermapper.io; |
|
23 |
|
|
24 |
import org.gvsig.fmap.dal.DALFileLibrary; |
|
25 |
import org.gvsig.fmap.dal.DALLibrary; |
|
26 |
import org.gvsig.raster.impl.store.AbstractNewRasterStoreParameters; |
|
27 |
import org.gvsig.tools.ToolsLibrary; |
|
28 |
import org.gvsig.tools.library.AbstractLibrary; |
|
29 |
import org.gvsig.tools.library.Library; |
|
30 |
import org.gvsig.tools.library.LibraryException; |
|
31 |
/** |
|
32 |
* |
|
33 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
34 |
*/ |
|
35 |
public class DefaultErmapperIOLibrary extends AbstractLibrary { |
|
36 |
|
|
37 |
@SuppressWarnings("deprecation") |
|
38 |
public DefaultErmapperIOLibrary() { |
|
39 |
super(DefaultErmapperIOLibrary.class,Library.TYPE.IMPL); |
|
40 |
require(ToolsLibrary.class); |
|
41 |
require(DALLibrary.class); |
|
42 |
require(DALFileLibrary.class); |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
protected void doInitialize() throws LibraryException { |
|
47 |
//RasterLibrary.wakeUp(); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
protected void doPostInitialize() throws LibraryException { |
|
52 |
AbstractNewRasterStoreParameters.registerDynClass(); |
|
53 |
|
|
54 |
// Registro de los drivers de lectura |
|
55 |
ErmapperProvider.register(); |
|
56 |
|
|
57 |
// Registro de los drivers de escritura |
|
58 |
ErmapperWriter.register(); |
|
59 |
ErmapperDataParameters.registerDynClass(); |
|
60 |
} |
|
61 |
} |
|
0 | 62 |
org.gvsig.raster.ermapper/tags/org.gvsig.raster.ermapper-2.2.115/org.gvsig.raster.ermapper.io/src/main/java/org/gvsig/raster/ermapper/io/ErmapperProvider.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.ermapper.io; |
|
23 |
|
|
24 |
import java.awt.geom.AffineTransform; |
|
25 |
import java.awt.geom.NoninvertibleTransformException; |
|
26 |
import java.awt.geom.Point2D; |
|
27 |
import java.io.BufferedReader; |
|
28 |
import java.io.File; |
|
29 |
import java.io.FileReader; |
|
30 |
import java.net.URI; |
|
31 |
import java.net.URISyntaxException; |
|
32 |
|
|
33 |
import org.cresques.cts.ICoordTrans; |
|
34 |
import org.slf4j.Logger; |
|
35 |
import org.slf4j.LoggerFactory; |
|
36 |
|
|
37 |
import org.gvsig.fmap.dal.DALFileLocator; |
|
38 |
import org.gvsig.fmap.dal.DALLocator; |
|
39 |
import org.gvsig.fmap.dal.DataStore; |
|
40 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
41 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
42 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
|
43 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
44 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
|
45 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
|
46 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
47 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException; |
|
48 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
49 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
|
50 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
51 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
52 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
|
53 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterFileStoreParameters; |
|
54 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
|
55 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
56 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
57 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
58 |
import org.gvsig.metadata.MetadataLocator; |
|
59 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
|
60 |
import org.gvsig.raster.impl.buffer.SpiRasterQuery; |
|
61 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
|
62 |
import org.gvsig.raster.impl.process.RasterTask; |
|
63 |
import org.gvsig.raster.impl.process.RasterTaskQueue; |
|
64 |
import org.gvsig.raster.impl.provider.AbstractRasterProvider; |
|
65 |
import org.gvsig.raster.impl.provider.RasterProvider; |
|
66 |
import org.gvsig.raster.impl.provider.tile.FileTileServer; |
|
67 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
|
68 |
import org.gvsig.raster.impl.store.DefaultRasterStore; |
|
69 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
|
70 |
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation; |
|
71 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
|
72 |
import org.gvsig.tools.ToolsLocator; |
|
73 |
import org.gvsig.tools.task.TaskStatus; |
|
74 |
|
|
75 |
import com.ermapper.ecw.JNCSException; |
|
76 |
import com.ermapper.ecw.JNCSFile; |
|
77 |
import com.ermapper.ecw.JNCSFileNotOpenException; |
|
78 |
import com.ermapper.ecw.JNCSInvalidSetViewException; |
|
79 |
import com.ermapper.ecw.JNCSProgressiveUpdate; |
|
80 |
|
|
81 |
/** |
|
82 |
* Driver de Ecw |
|
83 |
* |
|
84 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
85 |
*/ |
|
86 |
public class ErmapperProvider extends AbstractRasterProvider implements JNCSProgressiveUpdate { |
|
87 |
|
|
88 |
private static final Logger logger = LoggerFactory.getLogger(ErmapperProvider.class); |
|
89 |
public static String NAME = "Ermapper Store"; |
|
90 |
public static String DESCRIPTION = "Ermapper Raster file"; |
|
91 |
public static final String METADATA_DEFINITION_NAME = "ErmapperStore"; |
|
92 |
private JNCSFile file = null; |
|
93 |
protected Transparency fileTransparency = null; |
|
94 |
private Extent viewRequest = null; |
|
95 |
private DataStoreColorInterpretation colorInterpr = null; |
|
96 |
private boolean open = false; |
|
97 |
protected static String[] formatList = null; |
|
98 |
|
|
99 |
public static void register() { |
|
100 |
RasterLocator.getManager().getProviderServices().registerFileProvidersTiled(ErmapperProvider.class); |
|
101 |
registerFormats(); |
|
102 |
|
|
103 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
104 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
|
105 |
dataman.registerStoreProvider(NAME, ErmapperProvider.class, ErmapperDataParameters.class); |
|
106 |
} |
|
107 |
|
|
108 |
if (DALFileLocator.getFilesystemServerExplorerManager() != null) |
|
109 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider(NAME, DESCRIPTION, |
|
110 |
ErmapperFilesystemServerExplorer.class); |
|
111 |
|
|
112 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
|
113 |
} |
|
114 |
|
|
115 |
private static void registerFormats() { |
|
116 |
formatList = new String[] { "ecw", "jp2" }; |
|
117 |
for (int i = 0; i < formatList.length; i++) |
|
118 |
RasterLocator.getManager().getProviderServices().addFormat(formatList[i], ErmapperProvider.class); |
|
119 |
} |
|
120 |
|
|
121 |
public String[] getFormatList() { |
|
122 |
return formatList; |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Returns true if the extension is supported and false if doesn't |
|
127 |
* |
|
128 |
* @param ext |
|
129 |
* @return |
|
130 |
*/ |
|
131 |
public boolean isExtensionSupported(String ext) { |
|
132 |
if (ext.indexOf(".") != -1) |
|
133 |
ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length()); |
|
134 |
for (int i = 0; i < formatList.length; i++) { |
|
135 |
if (formatList[i].compareTo(ext) == 0) |
|
136 |
return true; |
|
137 |
} |
|
138 |
return false; |
|
139 |
} |
|
140 |
|
|
141 |
/** |
|
142 |
* Mandatory constructor to instantiate an empty provider |
|
143 |
*/ |
|
144 |
public ErmapperProvider() { |
|
145 |
} |
|
146 |
|
|
147 |
/** |
|
148 |
* Constructor. Abre el dataset. |
|
149 |
* |
|
150 |
* @param proj |
|
151 |
* Proyecci?n |
|
152 |
* @param fName |
|
153 |
* Nombre del fichero ecw |
|
154 |
* @throws NotSupportedExtensionException |
|
155 |
* @throws OpenException |
|
156 |
* @deprecated use {@link #ErmapperProvider(URI)}, this constructor will be removed in gvSIG 2.5 |
|
157 |
*/ |
|
158 |
public ErmapperProvider(String params) throws NotSupportedExtensionException, OpenException { |
|
159 |
super(params); |
|
160 |
logger.info("Deprecated use of ErmapperProvider constructor"); |
|
161 |
if (params instanceof String) { |
|
162 |
ErmapperDataParameters p = new ErmapperDataParameters(); |
|
163 |
try { |
|
164 |
p.setURI(new URI((String) params)); |
|
165 |
} catch (URISyntaxException e) { |
|
166 |
throw new OpenException("Can't create URI from" + (String) params, e); |
|
167 |
} |
|
168 |
super.init( |
|
169 |
p, |
|
170 |
null, |
|
171 |
ToolsLocator.getDynObjectManager().createDynObject( |
|
172 |
MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME))); |
|
173 |
init(p, null); |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
178 |
* Constructor. Abre el dataset. |
|
179 |
* |
|
180 |
* @param proj |
|
181 |
* Proyecci?n |
|
182 |
* @param uri |
|
183 |
* uri del fichero ecw |
|
184 |
* @throws NotSupportedExtensionException |
|
185 |
*/ |
|
186 |
public ErmapperProvider(URI uri) throws NotSupportedExtensionException { |
|
187 |
super(uri); |
|
188 |
ErmapperDataParameters p = new ErmapperDataParameters(); |
|
189 |
p.setURI(uri); |
|
190 |
super.init( |
|
191 |
p, |
|
192 |
null, |
|
193 |
ToolsLocator.getDynObjectManager().createDynObject( |
|
194 |
MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME))); |
|
195 |
init(p, null); |
|
196 |
} |
|
197 |
|
|
198 |
public ErmapperProvider(ErmapperDataParameters params, DataStoreProviderServices storeServices) |
|
199 |
throws NotSupportedExtensionException { |
|
200 |
super(params, storeServices, ToolsLocator.getDynObjectManager().createDynObject( |
|
201 |
MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME))); |
|
202 |
init(params, storeServices); |
|
203 |
} |
|
204 |
|
|
205 |
/** |
|
206 |
* Abre el dataset. |
|
207 |
* |
|
208 |
* @param proj |
|
209 |
* Proyecci?n |
|
210 |
* @param fName |
|
211 |
* Nombre del fichero ecw |
|
212 |
* @throws NotSupportedExtensionException |
|
213 |
*/ |
|
214 |
public void init(AbstractRasterDataParameters params, DataStoreProviderServices storeServices) |
|
215 |
throws NotSupportedExtensionException { |
|
216 |
setParam(storeServices, params); |
|
217 |
if (!((RasterFileStoreParameters) param).getFile().exists() |
|
218 |
&& !("ecwp".equalsIgnoreCase(((RasterDataParameters) param).getURI().getScheme()))) { |
|
219 |
throw new NotSupportedExtensionException("Extension not supported"); |
|
220 |
} |
|
221 |
|
|
222 |
try { |
|
223 |
String stringPath = ((RasterFileStoreParameters) param).getFile().getPath(); |
|
224 |
file = new JNCSFile(stringPath, false); |
|
225 |
} catch (JNCSException e1) { |
|
226 |
throw new NotSupportedExtensionException("Error loading the ecw file", e1); |
|
227 |
} |
|
228 |
|
|
229 |
/* |
|
230 |
* TODO: Leer proyecciones ECW |
|
231 |
* |
|
232 |
* wktProjection = null;//getWKTFromEcw_csFile(file.projection); |
|
233 |
* if(wktProjection != null && wktProjection != "") { |
|
234 |
* try { |
|
235 |
* proj = |
|
236 |
* RasterLocator.getManager().getCRSUtils().convertWktToIProjection |
|
237 |
* (wktProjection); |
|
238 |
* } catch (Exception e) { |
|
239 |
* logger.info("Error reading WKT from the raster provider", e); |
|
240 |
* } |
|
241 |
* } |
|
242 |
*/ |
|
243 |
|
|
244 |
load(); |
|
245 |
bandCount = file.numBands; |
|
246 |
|
|
247 |
int[] dt = new int[bandCount]; |
|
248 |
for (int i = 0; i < bandCount; i++) |
|
249 |
dt[i] = Buffer.TYPE_BYTE; |
|
250 |
setDataType(dt); |
|
251 |
|
|
252 |
super.init(); |
|
253 |
|
|
254 |
try { |
|
255 |
loadFromRmf(getRmfBlocksManager()); |
|
256 |
} catch (ParsingException e) { |
|
257 |
// No lee desde rmf |
|
258 |
} |
|
259 |
open = true; |
|
260 |
} |
|
261 |
|
|
262 |
@SuppressWarnings("unused") |
|
263 |
private String getWKTFromEcw_csFile(String identifier) { |
|
264 |
File file = new File("./"); |
|
265 |
file = |
|
266 |
new File(file.getAbsoluteFile() + File.separator + "data" + File.separator + "gdal" + File.separator |
|
267 |
+ "ecw_cs.wkt"); |
|
268 |
if (file.exists()) { |
|
269 |
FileReader fr = null; |
|
270 |
BufferedReader br = null; |
|
271 |
try { |
|
272 |
fr = new FileReader(file); |
|
273 |
br = new BufferedReader(fr); |
|
274 |
|
|
275 |
String line; |
|
276 |
while ((line = br.readLine()) != null) { |
|
277 |
if (line.startsWith(identifier + ",")) { |
|
278 |
int index = line.indexOf(",") + 1; |
|
279 |
return line.substring(index); |
|
280 |
} |
|
281 |
} |
|
282 |
} catch (Exception e) { |
|
283 |
return null; |
|
284 |
} finally { |
|
285 |
try { |
|
286 |
if (fr != null) |
|
287 |
fr.close(); |
|
288 |
} catch (Exception e2) { |
|
289 |
e2.printStackTrace(); |
|
290 |
} |
|
291 |
} |
|
292 |
} |
|
293 |
return null; |
|
294 |
} |
|
295 |
|
|
296 |
public RasterProvider load() { |
|
297 |
ownTransformation = |
|
298 |
new AffineTransform(file.cellIncrementX, 0, 0, file.cellIncrementY, file.originX, file.originY); |
|
299 |
externalTransformation = (AffineTransform) ownTransformation.clone(); |
|
300 |
return this; |
|
301 |
} |
|
302 |
|
|
303 |
public boolean isOpen() { |
|
304 |
return open; |
|
305 |
} |
|
306 |
|
|
307 |
public void close() { |
|
308 |
if (file != null) { |
|
309 |
open = false; |
|
310 |
// Cuando se abren varios datastores del mismo fichero y se cierra |
|
311 |
// uno de ellos se cierra la aplicaci?n en el siguiente dibujado |
|
312 |
// Se deber?a buscar una soluci?n ya que en los PrepareLayer se abre |
|
313 |
// y cierra para hacer comprobaciones. |
|
314 |
// file.close(false); |
|
315 |
file = null; |
|
316 |
} |
|
317 |
} |
|
318 |
|
|
319 |
public Transparency getTransparency() { |
|
320 |
if (fileTransparency == null) |
|
321 |
fileTransparency = new DataStoreTransparency(getColorInterpretation()); |
|
322 |
return fileTransparency; |
|
323 |
} |
|
324 |
|
|
325 |
public double getWidth() { |
|
326 |
return file.width; |
|
327 |
} |
|
328 |
|
|
329 |
public double getHeight() { |
|
330 |
return file.height; |
|
331 |
} |
|
332 |
|
|
333 |
public Extent getView() { |
|
334 |
return viewRequest; |
|
335 |
} |
|
336 |
|
|
337 |
public void setView(Extent e) { |
|
338 |
viewRequest = new ExtentImpl(e); |
|
339 |
} |
|
340 |
|
|
341 |
@Override |
|
342 |
public void loadBuffer(SpiRasterQuery query) throws ProcessInterruptedException, RasterDriverException { |
|
343 |
setView(transformExternalGeorefToOwnGeoref(query.getAdjustedRequestBoundingBox())); |
|
344 |
int bufWidth = query.getAdjustedBufWidth(); |
|
345 |
int bufHeight = query.getAdjustedBufHeight(); |
|
346 |
int[] stpBuffer = new int[] { 0, 0, bufWidth, bufHeight }; |
|
347 |
loadBuffer(viewRequest, bufWidth, bufHeight, query.getBufferForProviders(), query.getBandList(), stpBuffer, |
|
348 |
query.getTaskStatus()); |
|
349 |
} |
|
350 |
|
|
351 |
/** |
|
352 |
* Converts coordinates from the external transformation to the own |
|
353 |
* transformation. |
|
354 |
* This is useful when the user assigns a transformation or the own raster |
|
355 |
* has one |
|
356 |
* in the rmf file. Ecw need this function because the data window are |
|
357 |
* requested to |
|
358 |
* the library in world coordinates. |
|
359 |
* |
|
360 |
* @param ext |
|
361 |
* @return |
|
362 |
*/ |
|
363 |
private Extent transformExternalGeorefToOwnGeoref(Extent ext) { |
|
364 |
if (externalTransformation.equals(ownTransformation)) |
|
365 |
return ext; |
|
366 |
|
|
367 |
Point2D ul = ext.getUL(); |
|
368 |
Point2D lr = ext.getLR(); |
|
369 |
|
|
370 |
Point2D p1 = new Point2D.Double(); |
|
371 |
Point2D p2 = new Point2D.Double(); |
|
372 |
|
|
373 |
try { |
|
374 |
externalTransformation.inverseTransform(ul, p1); |
|
375 |
} catch (NoninvertibleTransformException e) { |
|
376 |
e.printStackTrace(); |
|
377 |
} |
|
378 |
ownTransformation.transform(p1, p1); |
|
379 |
|
|
380 |
try { |
|
381 |
externalTransformation.inverseTransform(lr, p2); |
|
382 |
} catch (NoninvertibleTransformException e) { |
|
383 |
e.printStackTrace(); |
|
384 |
} |
|
385 |
ownTransformation.transform(p2, p2); |
|
386 |
|
|
387 |
return RasterLocator.getManager().getDataStructFactory().createExtent(p1, p2); |
|
388 |
} |
|
389 |
|
|
390 |
/** |
|
391 |
* Carga el buffer con las bandas RGB del raster con los par?metros |
|
392 |
* especificados de extensi?n |
|
393 |
* y tama?o de buffer. El problema de ecw es que solo podemos leer 3 bandas |
|
394 |
* de una vez ya que solo disponemos |
|
395 |
* de una llamada readLineRGBA. Para leer m?s bandas tendremos que hacer |
|
396 |
* multiples llamadas a setView para leer |
|
397 |
* 3 cada vez. |
|
398 |
* |
|
399 |
* Si por ejemplo tenemos un ecw de 6 bandas [0, 1, 2, 3, 4, 5] y queremos |
|
400 |
* cargar un buffer con el siguiente orden |
|
401 |
* [0, -, 2, -, 4, -] La variable readBandsFromECW har? la llamada a setView |
|
402 |
* con los valores [0, 2, 4, 0, 0, 0]. La |
|
403 |
* funci?n drawRGB ser? la encargada de hacer el switch para obtener [0, -, |
|
404 |
* 2, -, 4, -]. |
|
405 |
* |
|
406 |
* Bug#1: Si se dispone de un ecw de m?s de tres bandas podemos llamar a |
|
407 |
* setView con readBandsFromECW con el orden |
|
408 |
* que queramos, por ejemplo [3, 2, 5, 1, 0] pero para ecw de 3 bandas la |
|
409 |
* llamada con las bandas cambiadas no |
|
410 |
* hace caso. El caso de readBandsFromECW = [2, 0, 1] ser? tomado siempre |
|
411 |
* como [0, 1, 2]. |
|
412 |
* |
|
413 |
* @param selectedExtent |
|
414 |
* Extensi?n seleccionada |
|
415 |
* @param bufWidth |
|
416 |
* Ancho de buffer |
|
417 |
* @param bufHeight |
|
418 |
* Alto de buffer |
|
419 |
* @param rasterBuf |
|
420 |
* Buffer de datos |
|
421 |
*/ |
|
422 |
private void loadBuffer(Extent selectedExtent, int bufWidth, int bufHeight, Buffer rasterBuf, BandList bandList, |
|
423 |
int[] stpBuffer, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
424 |
try { |
|
425 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().getId() + ""); |
|
426 |
|
|
427 |
int[] readBandsFromECW = new int[Math.max(file.numBands, 3)]; |
|
428 |
|
|
429 |
for (int i = 0; i < readBandsFromECW.length; i++) { |
|
430 |
readBandsFromECW[i] = i; |
|
431 |
} |
|
432 |
|
|
433 |
if (task.getEvent() != null) |
|
434 |
task.manageEvent(task.getEvent()); |
|
435 |
if (status != null && status.isCancelled()) |
|
436 |
return; |
|
437 |
|
|
438 |
if (bufWidth > Math.round(Math.abs(selectedExtent.width() / file.cellIncrementX))) |
|
439 |
bufWidth = (int) Math.round(Math.abs(selectedExtent.width() / file.cellIncrementX)); |
|
440 |
if (bufHeight > Math.round(Math.abs(selectedExtent.height() / file.cellIncrementY))) |
|
441 |
bufHeight = (int) Math.round(Math.abs(selectedExtent.height() / file.cellIncrementY)); |
|
442 |
file.setView(file.numBands, readBandsFromECW, selectedExtent.minX(), selectedExtent.maxY(), |
|
443 |
selectedExtent.maxX(), selectedExtent.minY(), bufWidth, bufHeight); |
|
444 |
|
|
445 |
// Escribimos el raster sobre un Buffer |
|
446 |
int[] pRGBArray = new int[bufWidth]; |
|
447 |
drawRGB2(rasterBuf, pRGBArray, bandList, status); |
|
448 |
|
|
449 |
} catch (JNCSInvalidSetViewException exc) { |
|
450 |
throw new RasterDriverException("Error setting coords"); |
|
451 |
} catch (JNCSFileNotOpenException e) { |
|
452 |
throw new RasterDriverException("Error opening file"); |
|
453 |
} catch (JNCSException ex) { |
|
454 |
throw new RasterDriverException("Error reading data"); |
|
455 |
} |
|
456 |
|
|
457 |
} |
|
458 |
|
|
459 |
private void drawRGB2(Buffer rasterBuf, int[] pRGBArray, BandList bandList, TaskStatus status) |
|
460 |
throws JNCSException, ProcessInterruptedException { |
|
461 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().getId() + ""); |
|
462 |
int[] drawableBands = null; |
|
463 |
|
|
464 |
String absolutePath = new File(getURIOfFirstProvider()).getAbsolutePath(); |
|
465 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
|
466 |
try { |
|
467 |
file.readLineRGBA(pRGBArray); |
|
468 |
for (int col = 0; col < pRGBArray.length; col++) { |
|
469 |
drawableBands = bandList.getBufferBandToDraw(absolutePath, 0); |
|
470 |
if (drawableBands != null) { |
|
471 |
for (int i = 0; i < drawableBands.length; i++) { |
|
472 |
if (drawableBands[i] != -1) |
|
473 |
rasterBuf.setElem(line, col, drawableBands[i], |
|
474 |
(byte) ((pRGBArray[col] & 0x00ff0000) >> 16)); |
|
475 |
} |
|
476 |
} |
|
477 |
drawableBands = bandList.getBufferBandToDraw(absolutePath, 1); |
|
478 |
if (drawableBands != null) { |
|
479 |
for (int i = 0; i < drawableBands.length; i++) { |
|
480 |
if (drawableBands[i] != -1) |
|
481 |
rasterBuf.setElem(line, col, drawableBands[i], |
|
482 |
(byte) ((pRGBArray[col] & 0x0000ff00) >> 8)); |
|
483 |
} |
|
484 |
} |
|
485 |
drawableBands = bandList.getBufferBandToDraw(absolutePath, 2); |
|
486 |
if (drawableBands != null) { |
|
487 |
for (int i = 0; i < drawableBands.length; i++) { |
|
488 |
if (drawableBands[i] != -1) |
|
489 |
rasterBuf.setElem(line, col, drawableBands[i], (byte) (pRGBArray[col] & 0x000000ff)); |
|
490 |
} |
|
491 |
} |
|
492 |
} |
|
493 |
} catch (JNCSException exc) { |
|
494 |
} |
|
495 |
if (task.getEvent() != null) |
|
496 |
task.manageEvent(task.getEvent()); |
|
497 |
if (status != null && status.isCancelled()) |
|
498 |
return; |
|
499 |
} |
|
500 |
return; |
|
501 |
} |
|
502 |
|
|
503 |
@SuppressWarnings("unused") |
|
504 |
private void drawRGB(Buffer rasterBuf, int[] pRGBArray, int[] readBands, BandList bandList, RasterTask task) |
|
505 |
throws JNCSException, ProcessInterruptedException { |
|
506 |
int bandR = readBands[0]; |
|
507 |
int bandG = (readBands.length > 1) ? readBands[1] : -1; |
|
508 |
int bandB = (readBands.length > 2) ? readBands[2] : -1; |
|
509 |
|
|
510 |
// ********* caso especial que resuelve Bug#1 ********************** |
|
511 |
if (file.numBands == 3 && bandList.getDrawableBandsCount() < 3) { |
|
512 |
for (int i = 0; i < 3; i++) { |
|
513 |
int[] b = bandList.getBand(i).getBufferBandListToDraw(); |
|
514 |
if (b != null) { |
|
515 |
bandG = 1; |
|
516 |
bandR = 0; |
|
517 |
bandB = 2; |
|
518 |
} |
|
519 |
} |
Also available in: Unified diff