Revision 12333 trunk/libraries/libRaster/src/org/gvsig/raster/dataset/io/ErmapperWriter.java
ErmapperWriter.java | ||
---|---|---|
54 | 54 |
* @author Nacho Brodin (brodin_ign@gva.es) |
55 | 55 |
*/ |
56 | 56 |
public class ErmapperWriter extends GeoRasterWriter { |
57 |
|
|
57 |
|
|
58 | 58 |
public static void register() { |
59 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
|
|
60 |
WriteFileFormatFeatures features = null;
|
|
61 |
|
|
62 |
String os = System.getProperties().getProperty("os.version");
|
|
63 |
if (os.startsWith("2.4")){
|
|
64 |
extensionPoints.add("RasterWriter", "ecw", ErmapperWriter.class);
|
|
65 |
features = new WriteFileFormatFeatures("Ecw", "ecw", -1, null, ErmapperWriter.class);
|
|
66 |
fileFeature.put("ecw", features);
|
|
67 |
}
|
|
68 |
extensionPoints.add("RasterWriter", "jp2", ErmapperWriter.class);
|
|
69 |
features = new WriteFileFormatFeatures("Jpeg2000", "jp2", -1, null, ErmapperWriter.class);
|
|
59 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
|
|
60 |
WriteFileFormatFeatures features = null;
|
|
61 |
|
|
62 |
String os = System.getProperties().getProperty("os.version");
|
|
63 |
if (os.startsWith("2.4")){
|
|
64 |
extensionPoints.add("RasterWriter", "ecw", ErmapperWriter.class);
|
|
65 |
features = new WriteFileFormatFeatures("Ecw", "ecw", -1, null, ErmapperWriter.class);
|
|
66 |
fileFeature.put("ecw", features);
|
|
67 |
}
|
|
68 |
extensionPoints.add("RasterWriter", "jp2", ErmapperWriter.class);
|
|
69 |
features = new WriteFileFormatFeatures("Jpeg2000", "jp2", -1, null, ErmapperWriter.class);
|
|
70 | 70 |
fileFeature.put("jp2", features); |
71 |
}
|
|
71 |
}
|
|
72 | 72 |
|
73 |
public final int windowSizeX = 386;
|
|
74 |
public final int windowSizeY = 220;
|
|
75 |
public final int panelSizeX = 358;
|
|
76 |
public final int panelSizeY = 125;
|
|
77 |
public final String panelLayout = "BorderLayout";
|
|
78 |
private NCSEcwCompressClient compressclient = null;
|
|
79 |
private Reader readerObj;
|
|
80 |
private double pixelSizeX;
|
|
81 |
private double pixelSizeY;
|
|
82 |
private double geoCoordOrigenX;
|
|
83 |
private double geoCoordOrigenY;
|
|
84 |
private boolean consulta = false;
|
|
73 |
public final int windowSizeX = 386;
|
|
74 |
public final int windowSizeY = 220;
|
|
75 |
public final int panelSizeX = 358;
|
|
76 |
public final int panelSizeY = 125;
|
|
77 |
public final String panelLayout = "BorderLayout";
|
|
78 |
private NCSEcwCompressClient compressclient = null;
|
|
79 |
private Reader readerObj;
|
|
80 |
private double pixelSizeX;
|
|
81 |
private double pixelSizeY;
|
|
82 |
private double geoCoordOrigenX;
|
|
83 |
private double geoCoordOrigenY;
|
|
84 |
private boolean consulta = false;
|
|
85 | 85 |
|
86 |
/**
|
|
87 |
* Carga los par?metros de este driver.
|
|
88 |
*/
|
|
89 |
public void loadParams() {
|
|
90 |
WriteFileFormatFeatures wfff = new WriteFileFormatFeatures();
|
|
91 |
wfff.loadParams();
|
|
92 |
driverParams = wfff.getParams();
|
|
93 |
|
|
94 |
driverParams.setParam( "compression",
|
|
95 |
"10",
|
|
96 |
Params.SLIDER,
|
|
86 |
/**
|
|
87 |
* Carga los par?metros de este driver.
|
|
88 |
*/
|
|
89 |
public void loadParams() {
|
|
90 |
WriteFileFormatFeatures wfff = new WriteFileFormatFeatures();
|
|
91 |
wfff.loadParams();
|
|
92 |
driverParams = wfff.getParams();
|
|
93 |
|
|
94 |
driverParams.setParam( "compression",
|
|
95 |
"10", |
|
96 |
Params.SLIDER, |
|
97 | 97 |
new String[]{ "0", "20", "10", "1", "5" }); //min, max, valor defecto, intervalo peque?o, intervalo grande; |
98 |
|
|
99 |
driverParams.setParam( "format",
|
|
100 |
"RGB",
|
|
101 |
Params.CHOICE,
|
|
98 |
|
|
99 |
driverParams.setParam( "format",
|
|
100 |
"RGB", |
|
101 |
Params.CHOICE, |
|
102 | 102 |
new String[]{ "NONE", "UINT8", "YUV", "MULTI", "RGB"}); |
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Constructor para la obtenci?n de par?metros del driver. |
|
107 |
*/ |
|
108 |
public ErmapperWriter(String fileName) { |
|
109 |
ident = RasterUtilities.getExtensionFromFileName(fileName); |
|
110 |
driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName(); |
|
111 |
|
|
112 |
loadParams(); |
|
103 |
} |
|
113 | 104 |
|
114 |
consulta = true; |
|
115 |
} |
|
105 |
/** |
|
106 |
* Constructor para la obtenci?n de par?metros del driver. |
|
107 |
*/ |
|
108 |
public ErmapperWriter(String fileName) { |
|
109 |
ident = RasterUtilities.getExtensionFromFileName(fileName); |
|
110 |
driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName(); |
|
116 | 111 |
|
117 |
/** |
|
118 |
* Constructor para la lectura de datos desde el objeto cliente a partir |
|
119 |
* de un viewport dado. |
|
120 |
* @param dataWriter Objeto que sirve datos para el escritor |
|
121 |
* @param vp viewport de origen |
|
122 |
* @param outFileName Fichero de salida |
|
123 |
* @param blockSize Tama?o de bloque |
|
124 |
* @param nBands N?mero de bandas |
|
125 |
* @param compresion Compresi?n |
|
126 |
* @throws EcwException |
|
127 |
* @throws IOException |
|
128 |
*/ |
|
129 |
public ErmapperWriter( IDataWriter dataWriter, |
|
130 |
String outFileName, |
|
131 |
Integer nBands, |
|
132 |
Extent ex, |
|
133 |
Integer outSizeX, |
|
134 |
Integer outSizeY, |
|
135 |
Integer dataType, |
|
136 |
Params params) throws EcwException, IOException { |
|
137 |
ident = RasterUtilities.getExtensionFromFileName(outFileName); |
|
138 |
driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName(); |
|
139 |
this.dataType = dataType.intValue(); |
|
140 |
|
|
141 |
if (nBands.intValue() <= 0) |
|
142 |
throw new EcwException("N?mero de bandas erroneo."); |
|
112 |
loadParams(); |
|
143 | 113 |
|
144 |
if ((ex.width() <= 0) || (ex.height() <= 0)) { |
|
145 |
throw new EcwException("Tama?o de la imagen de salida erroneo."); |
|
146 |
} |
|
114 |
consulta = true; |
|
115 |
} |
|
147 | 116 |
|
148 |
this.outFileName = outFileName; |
|
149 |
this.dataWriter = dataWriter; |
|
150 |
|
|
151 |
this.nBands = nBands.intValue(); |
|
117 |
/** |
|
118 |
* Constructor para la lectura de datos desde el objeto cliente a partir |
|
119 |
* de un viewport dado. |
|
120 |
* @param dataWriter Objeto que sirve datos para el escritor |
|
121 |
* @param vp viewport de origen |
|
122 |
* @param outFileName Fichero de salida |
|
123 |
* @param blockSize Tama?o de bloque |
|
124 |
* @param nBands N?mero de bandas |
|
125 |
* @param compresion Compresi?n |
|
126 |
* @throws EcwException |
|
127 |
* @throws IOException |
|
128 |
*/ |
|
129 |
public ErmapperWriter( IDataWriter dataWriter, |
|
130 |
String outFileName, |
|
131 |
Integer nBands, |
|
132 |
Extent ex, |
|
133 |
Integer outSizeX, |
|
134 |
Integer outSizeY, |
|
135 |
Integer dataType, |
|
136 |
Params params) throws EcwException, IOException { |
|
137 |
ident = RasterUtilities.getExtensionFromFileName(outFileName); |
|
138 |
driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName(); |
|
139 |
this.dataType = dataType.intValue(); |
|
152 | 140 |
|
153 |
this.sizeWindowX = outSizeX.intValue(); |
|
154 |
this.sizeWindowY = outSizeY.intValue(); |
|
155 |
|
|
156 |
//Calculamos la georeferenciaci?n a partir del extend pasado por el cliente. |
|
157 |
double maxX = ex.maxX(); |
|
158 |
geoCoordOrigenX = ex.minX(); |
|
159 |
geoCoordOrigenY = ex.maxY(); |
|
141 |
if (nBands.intValue() <= 0) |
|
142 |
throw new EcwException("N?mero de bandas erroneo."); |
|
160 | 143 |
|
161 |
double minY = ex.minY();
|
|
162 |
pixelSizeX = (maxX - geoCoordOrigenX) / outSizeX.intValue();
|
|
163 |
pixelSizeY = (minY - geoCoordOrigenY) / outSizeY.intValue();
|
|
144 |
if ((ex.width() <= 0) || (ex.height() <= 0)) {
|
|
145 |
throw new EcwException("Tama?o de la imagen de salida erroneo.");
|
|
146 |
}
|
|
164 | 147 |
|
165 |
if (pixelSizeX == 0)
|
|
166 |
pixelSizeX = 1.0;
|
|
148 |
this.outFileName = outFileName;
|
|
149 |
this.dataWriter = dataWriter;
|
|
167 | 150 |
|
168 |
if (pixelSizeY == 0) |
|
169 |
pixelSizeY = 1.0; |
|
170 |
|
|
171 |
if(params == null) |
|
172 |
loadParams(); |
|
173 |
else |
|
174 |
driverParams = params; |
|
151 |
this.nBands = nBands.intValue(); |
|
175 | 152 |
|
176 |
init();
|
|
177 |
}
|
|
153 |
this.sizeWindowX = outSizeX.intValue();
|
|
154 |
this.sizeWindowY = outSizeY.intValue();
|
|
178 | 155 |
|
179 |
/** |
|
180 |
* Inicializaci?n de los par?metros del compresor que ser?n obtenidos |
|
181 |
* de PxRaster. |
|
182 |
* @throws EcwException |
|
183 |
*/ |
|
184 |
private void init() throws EcwException { |
|
185 |
percent = 0; |
|
186 |
int comp = new Integer(((Param)driverParams.getParamById("compression")).defaultValue).intValue(); |
|
187 |
String format = ((Param)driverParams.getParamById("format")).defaultValue; |
|
188 |
if ( comp == 0 ) |
|
189 |
driverParams.changeParamValue("compression", "1"); |
|
190 |
|
|
191 |
if (compressclient == null) |
|
192 |
compressclient = new NCSEcwCompressClient(); |
|
193 |
|
|
194 |
compressclient.setOutputFilename(outFileName); |
|
195 |
compressclient.setInputFilename(inFileName); |
|
196 |
compressclient.setTargetCompress(comp); |
|
197 |
compressclient.setInOutSizeX(sizeWindowX); |
|
198 |
compressclient.setInOutSizeY(sizeWindowY); |
|
199 |
compressclient.setInputBands(nBands); |
|
200 |
compressclient.setCompressFormat(convertFormatToInt(format)); |
|
156 |
//Calculamos la georeferenciaci?n a partir del extend pasado por el cliente. |
|
157 |
double maxX = ex.maxX(); |
|
158 |
geoCoordOrigenX = ex.minX(); |
|
159 |
geoCoordOrigenY = ex.maxY(); |
|
201 | 160 |
|
202 |
/* boolean georef = new Boolean(((Param)driverParams.getParamById("georef")).defaultValue).booleanValue(); |
|
203 |
if (georef) {*/ |
|
204 |
compressclient.setCellIncrementX(pixelSizeX); |
|
205 |
compressclient.setCellIncrementY(pixelSizeY); |
|
206 |
compressclient.setOriginX(geoCoordOrigenX); |
|
207 |
compressclient.setOriginY(geoCoordOrigenY); |
|
208 |
//} |
|
161 |
double minY = ex.minY(); |
|
162 |
pixelSizeX = (maxX - geoCoordOrigenX) / outSizeX.intValue(); |
|
163 |
pixelSizeY = (minY - geoCoordOrigenY) / outSizeY.intValue(); |
|
209 | 164 |
|
210 |
compressclient.setCellSizeUnits(1); |
|
211 |
|
|
212 |
int blocksize = new Integer(((Param)driverParams.getParamById("blocksize")).defaultValue).intValue(); |
|
213 |
if (dataWriter != null) { |
|
214 |
readerObj = new Reader(dataWriter, compressclient, sizeWindowX, |
|
215 |
sizeWindowY, blocksize, nBands, this, dataType); |
|
216 |
} |
|
217 |
} |
|
165 |
if (pixelSizeX == 0) |
|
166 |
pixelSizeX = 1.0; |
|
218 | 167 |
|
219 |
/** |
|
220 |
* Convierte la cadena que representa el formato en un valor n?merico |
|
221 |
* que entiende el driver. |
|
222 |
* @param format Cadena que representa el formato |
|
223 |
* @return Entero que representa a la cadena |
|
224 |
*/ |
|
225 |
private int convertFormatToInt(String format) { |
|
226 |
if(format.compareTo("NONE") == 0) |
|
227 |
return 0; |
|
228 |
if(format.compareTo("UINT8") == 0) |
|
229 |
return 1; |
|
230 |
if(format.compareTo("YUV") == 0) |
|
231 |
return 2; |
|
232 |
if(format.compareTo("MULTI") == 0) |
|
233 |
return 3; |
|
234 |
if(format.compareTo("RGB") == 0) |
|
235 |
return 4; |
|
236 |
return -1; |
|
237 |
} |
|
238 |
/** |
|
239 |
* A partir de un elemento que contiene una propiedad y un valor |
|
240 |
* lo parsea y asigna el valor a su variable. |
|
241 |
* @param propValue elemento con la forma propiedad=valor |
|
242 |
*/ |
|
243 |
private void readProperty(String propValue) { |
|
244 |
String prop = propValue.substring(0, propValue.indexOf("=")); |
|
168 |
if (pixelSizeY == 0) |
|
169 |
pixelSizeY = 1.0; |
|
245 | 170 |
|
246 |
if (propValue.startsWith(prop)) { |
|
247 |
String value = propValue.substring(propValue.indexOf("=") + 1, propValue.length()); |
|
171 |
if(params == null) |
|
172 |
loadParams(); |
|
173 |
else |
|
174 |
driverParams = params; |
|
248 | 175 |
|
249 |
if ((value != null) && !value.equals("")) { |
|
250 |
if (prop.equals("BLOCKSIZE")) |
|
251 |
driverParams.changeParamValue("blocksize", value); |
|
252 |
if (prop.equals("FORMAT")) |
|
253 |
driverParams.changeParamValue("format", value); |
|
254 |
if (prop.equals("COMPRESSION")) |
|
255 |
driverParams.changeParamValue("compression", value); |
|
256 |
} |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
261 |
* Asigna propiedades al driver a partir de un vector de |
|
262 |
* strings donde cada elemento tiene la estructura de |
|
263 |
* propiedad=valor. |
|
264 |
* @param props Propiedades |
|
265 |
*/ |
|
266 |
public void setProps(String[] props) { |
|
267 |
for (int iProps = 0; iProps < props.length; iProps++) |
|
268 |
readProperty(props[iProps]); |
|
176 |
init(); |
|
177 |
} |
|
269 | 178 |
|
270 |
loadParams(); |
|
271 |
|
|
272 |
try { |
|
273 |
if (!consulta) { |
|
274 |
init(); |
|
275 |
} |
|
276 |
} catch (EcwException e) { |
|
277 |
e.printStackTrace(); |
|
278 |
} |
|
279 |
} |
|
179 |
/** |
|
180 |
* Inicializaci?n de los par?metros del compresor que ser?n obtenidos |
|
181 |
* de PxRaster. |
|
182 |
* @throws EcwException |
|
183 |
*/ |
|
184 |
private void init() throws EcwException { |
|
185 |
percent = 0; |
|
186 |
int comp = new Integer((String) ((Param)driverParams.getParamById("compression")).defaultValue).intValue(); |
|
187 |
String format = (String) ((Param)driverParams.getParamById("format")).defaultValue; |
|
188 |
if ( comp == 0 ) |
|
189 |
driverParams.changeParamValue("compression", "1"); |
|
280 | 190 |
|
281 |
/** |
|
282 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile. |
|
283 |
* @throws IOException |
|
284 |
*/ |
|
285 |
public void fileWrite() throws IOException { |
|
286 |
/* try { |
|
287 |
compressclient.NCSEcwCompressOpen(false); |
|
288 |
compressclient.NCSEcwCompress(readerObj); |
|
289 |
} catch (EcwException e) { |
|
290 |
e.printStackTrace(); |
|
291 |
}*/ |
|
292 |
//TODO: FUNCIONALIDAD: Compresi?n a partir de un dataset. De momento no es necesario y es posible que nunca lo sea. |
|
293 |
} |
|
191 |
if (compressclient == null) |
|
192 |
compressclient = new NCSEcwCompressClient(); |
|
294 | 193 |
|
295 |
/** |
|
296 |
* Realiza la funci?n de compresi?n a partir de los datos pasados por el cliente. |
|
297 |
* @throws IOException |
|
298 |
*/ |
|
299 |
public void dataWrite() throws IOException { |
|
300 |
if (dataWriter == null) { |
|
301 |
throw new IOException("No se ha obtenido un objeto para la lectura valido."); |
|
302 |
} |
|
194 |
compressclient.setOutputFilename(outFileName); |
|
195 |
compressclient.setInputFilename(inFileName); |
|
196 |
compressclient.setTargetCompress(comp); |
|
197 |
compressclient.setInOutSizeX(sizeWindowX); |
|
198 |
compressclient.setInOutSizeY(sizeWindowY); |
|
199 |
compressclient.setInputBands(nBands); |
|
200 |
compressclient.setCompressFormat(convertFormatToInt(format)); |
|
303 | 201 |
|
304 |
try {
|
|
305 |
compressclient.NCSEcwCompressOpen(false);
|
|
306 |
compressclient.NCSEcwCompress(readerObj);
|
|
307 |
} catch (EcwException e) {
|
|
308 |
e.printStackTrace();
|
|
309 |
}
|
|
310 |
}
|
|
202 |
/* boolean georef = new Boolean(((Param)driverParams.getParamById("georef")).defaultValue).booleanValue();
|
|
203 |
if (georef) {*/
|
|
204 |
compressclient.setCellIncrementX(pixelSizeX);
|
|
205 |
compressclient.setCellIncrementY(pixelSizeY);
|
|
206 |
compressclient.setOriginX(geoCoordOrigenX);
|
|
207 |
compressclient.setOriginY(geoCoordOrigenY);
|
|
208 |
//}
|
|
311 | 209 |
|
312 |
/** |
|
313 |
* Cierra el compresor ecw. |
|
314 |
*/ |
|
315 |
public void writeClose() { |
|
316 |
try { |
|
317 |
compressclient.NCSEcwCompressClose(); |
|
318 |
} catch (EcwException e) { |
|
319 |
e.printStackTrace(); |
|
320 |
} |
|
321 |
} |
|
322 |
|
|
323 |
/** |
|
324 |
* Cancela el compresor ecw. |
|
325 |
*/ |
|
326 |
public void writeCancel() { |
|
327 |
try { |
|
328 |
if(readerObj != null) |
|
329 |
readerObj.setWrite(false); |
|
330 |
compressclient.NCSEcwCompressCancel(); |
|
331 |
} catch (EcwException e) { |
|
332 |
e.printStackTrace(); |
|
333 |
} |
|
334 |
} |
|
335 |
|
|
210 |
compressclient.setCellSizeUnits(1); |
|
211 |
|
|
212 |
int blocksize = new Integer((String) ((Param)driverParams.getParamById("blocksize")).defaultValue).intValue(); |
|
213 |
if (dataWriter != null) { |
|
214 |
readerObj = new Reader(dataWriter, compressclient, sizeWindowX, |
|
215 |
sizeWindowY, blocksize, nBands, this, dataType); |
|
216 |
} |
|
217 |
} |
|
218 |
|
|
219 |
/** |
|
220 |
* Convierte la cadena que representa el formato en un valor n?merico |
|
221 |
* que entiende el driver. |
|
222 |
* @param format Cadena que representa el formato |
|
223 |
* @return Entero que representa a la cadena |
|
224 |
*/ |
|
225 |
private int convertFormatToInt(String format) { |
|
226 |
if(format.compareTo("NONE") == 0) |
|
227 |
return 0; |
|
228 |
if(format.compareTo("UINT8") == 0) |
|
229 |
return 1; |
|
230 |
if(format.compareTo("YUV") == 0) |
|
231 |
return 2; |
|
232 |
if(format.compareTo("MULTI") == 0) |
|
233 |
return 3; |
|
234 |
if(format.compareTo("RGB") == 0) |
|
235 |
return 4; |
|
236 |
return -1; |
|
237 |
} |
|
238 |
/** |
|
239 |
* A partir de un elemento que contiene una propiedad y un valor |
|
240 |
* lo parsea y asigna el valor a su variable. |
|
241 |
* @param propValue elemento con la forma propiedad=valor |
|
242 |
*/ |
|
243 |
private void readProperty(String propValue) { |
|
244 |
String prop = propValue.substring(0, propValue.indexOf("=")); |
|
245 |
|
|
246 |
if (propValue.startsWith(prop)) { |
|
247 |
String value = propValue.substring(propValue.indexOf("=") + 1, propValue.length()); |
|
248 |
|
|
249 |
if ((value != null) && !value.equals("")) { |
|
250 |
if (prop.equals("BLOCKSIZE")) |
|
251 |
driverParams.changeParamValue("blocksize", value); |
|
252 |
if (prop.equals("FORMAT")) |
|
253 |
driverParams.changeParamValue("format", value); |
|
254 |
if (prop.equals("COMPRESSION")) |
|
255 |
driverParams.changeParamValue("compression", value); |
|
256 |
} |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
261 |
* Asigna propiedades al driver a partir de un vector de |
|
262 |
* strings donde cada elemento tiene la estructura de |
|
263 |
* propiedad=valor. |
|
264 |
* @param props Propiedades |
|
265 |
*/ |
|
266 |
public void setProps(String[] props) { |
|
267 |
for (int iProps = 0; iProps < props.length; iProps++) |
|
268 |
readProperty(props[iProps]); |
|
269 |
|
|
270 |
loadParams(); |
|
271 |
|
|
272 |
try { |
|
273 |
if (!consulta) { |
|
274 |
init(); |
|
275 |
} |
|
276 |
} catch (EcwException e) { |
|
277 |
e.printStackTrace(); |
|
278 |
} |
|
279 |
} |
|
280 |
|
|
281 |
/** |
|
282 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile. |
|
283 |
* @throws IOException |
|
284 |
*/ |
|
285 |
public void fileWrite() throws IOException { |
|
286 |
/* try { |
|
287 |
compressclient.NCSEcwCompressOpen(false); |
|
288 |
compressclient.NCSEcwCompress(readerObj); |
|
289 |
} catch (EcwException e) { |
|
290 |
e.printStackTrace(); |
|
291 |
}*/ |
|
292 |
//TODO: FUNCIONALIDAD: Compresi?n a partir de un dataset. De momento no es necesario y es posible que nunca lo sea. |
|
293 |
} |
|
294 |
|
|
295 |
/** |
|
296 |
* Realiza la funci?n de compresi?n a partir de los datos pasados por el cliente. |
|
297 |
* @throws IOException |
|
298 |
*/ |
|
299 |
public void dataWrite() throws IOException { |
|
300 |
if (dataWriter == null) { |
|
301 |
throw new IOException("No se ha obtenido un objeto para la lectura valido."); |
|
302 |
} |
|
303 |
|
|
304 |
try { |
|
305 |
compressclient.NCSEcwCompressOpen(false); |
|
306 |
compressclient.NCSEcwCompress(readerObj); |
|
307 |
} catch (EcwException e) { |
|
308 |
e.printStackTrace(); |
|
309 |
} |
|
310 |
} |
|
311 |
|
|
312 |
/** |
|
313 |
* Cierra el compresor ecw. |
|
314 |
*/ |
|
315 |
public void writeClose() { |
|
316 |
try { |
|
317 |
compressclient.NCSEcwCompressClose(); |
|
318 |
} catch (EcwException e) { |
|
319 |
e.printStackTrace(); |
|
320 |
} |
|
321 |
} |
|
322 |
|
|
323 |
/** |
|
324 |
* Cancela el compresor ecw. |
|
325 |
*/ |
|
326 |
public void writeCancel() { |
|
327 |
try { |
|
328 |
if(readerObj != null) |
|
329 |
readerObj.setWrite(false); |
|
330 |
compressclient.NCSEcwCompressCancel(); |
|
331 |
} catch (EcwException e) { |
|
332 |
e.printStackTrace(); |
|
333 |
} |
|
334 |
} |
|
335 |
|
|
336 | 336 |
} |
337 | 337 |
|
338 | 338 |
|
... | ... | |
345 | 345 |
* |
346 | 346 |
*/ |
347 | 347 |
class Reader extends JniObject implements ReadCallBack { |
348 |
private NCSEcwCompressClient compressclient = null;
|
|
349 |
private int width;
|
|
350 |
private int height;
|
|
351 |
private int ulX;
|
|
352 |
private int ulY;
|
|
353 |
private GeoRasterFile grf = null;
|
|
354 |
private IDataWriter dataWriter = null;
|
|
355 |
private GdalRasterBand rband = null;
|
|
356 |
private GeoRasterWriter writer = null;
|
|
357 |
private int blockSizeRead = 1; //Alto del bloque leido de la imagen origen
|
|
358 |
private int countLine = 1; //Contador de l?neas procesadas en cada lectura de bloque
|
|
359 |
byte[][] buf = null;
|
|
360 |
byte[] bufband1 = null;
|
|
361 |
byte[] bufband2 = null;
|
|
362 |
byte[] bufband3 = null;
|
|
363 |
byte[] bufband4 = null;
|
|
364 |
byte[] bufband5 = null;
|
|
365 |
byte[] bufband6 = null;
|
|
366 |
int[] dataBuffer = null;
|
|
367 |
byte[][] byteBuffer = null;
|
|
368 |
private int lineasBloqueFinal = 0; //N?mero de l?neas leidas del bloque final
|
|
369 |
private int nBlocks = 0; //N?mero de bloques completos
|
|
370 |
private int countBlock = 1; //Contador de bloques completos procesados
|
|
371 |
private int nBands = 0;
|
|
372 |
private boolean write = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido
|
|
373 |
private int dataType = IBuffer.TYPE_BYTE;
|
|
348 |
private NCSEcwCompressClient compressclient = null;
|
|
349 |
private int width;
|
|
350 |
private int height;
|
|
351 |
private int ulX;
|
|
352 |
private int ulY;
|
|
353 |
private GeoRasterFile grf = null;
|
|
354 |
private IDataWriter dataWriter = null;
|
|
355 |
private GdalRasterBand rband = null;
|
|
356 |
private GeoRasterWriter writer = null;
|
|
357 |
private int blockSizeRead = 1; //Alto del bloque leido de la imagen origen
|
|
358 |
private int countLine = 1; //Contador de l?neas procesadas en cada lectura de bloque
|
|
359 |
byte[][] buf = null;
|
|
360 |
byte[] bufband1 = null;
|
|
361 |
byte[] bufband2 = null;
|
|
362 |
byte[] bufband3 = null;
|
|
363 |
byte[] bufband4 = null;
|
|
364 |
byte[] bufband5 = null;
|
|
365 |
byte[] bufband6 = null;
|
|
366 |
int[] dataBuffer = null;
|
|
367 |
byte[][] byteBuffer = null;
|
|
368 |
private int lineasBloqueFinal = 0; //N?mero de l?neas leidas del bloque final
|
|
369 |
private int nBlocks = 0; //N?mero de bloques completos
|
|
370 |
private int countBlock = 1; //Contador de bloques completos procesados
|
|
371 |
private int nBands = 0;
|
|
372 |
private boolean write = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido
|
|
373 |
private int dataType = IBuffer.TYPE_BYTE;
|
|
374 | 374 |
|
375 |
/** |
|
376 |
* Constructor para la escritura de un fichero desde un GeoRasterFile |
|
377 |
* @param grf GeorasterFile del fichero de origen |
|
378 |
* @param compressclient Objeto que representa al compresor ecw |
|
379 |
* @param ulx Coordenada X de la esquina superior izquierda |
|
380 |
* @param uly Coordenada Y de la esquina superior izquierda |
|
381 |
* @param width Ancho de la imagen |
|
382 |
* @param height Alto de la imagen |
|
383 |
* @param blockSizeRead Altura del bloque en la lectura |
|
384 |
*/ |
|
385 |
public Reader(GeoRasterFile grf, NCSEcwCompressClient compressclient, |
|
386 |
int ulx, int uly, int width, int height, int blockSizeRead, int dataType) { |
|
387 |
this.compressclient = compressclient; |
|
388 |
this.width = width; |
|
389 |
this.height = height; |
|
390 |
this.ulX = ulx; |
|
391 |
this.ulY = uly; |
|
392 |
this.grf = grf; |
|
393 |
this.nBands = grf.getBandCount(); |
|
394 |
this.dataType = dataType; |
|
395 |
|
|
396 |
if (blockSizeRead != 0) { |
|
397 |
this.blockSizeRead = blockSizeRead; |
|
398 |
} |
|
375 |
/** |
|
376 |
* Constructor para la escritura de un fichero desde un GeoRasterFile |
|
377 |
* @param grf GeorasterFile del fichero de origen |
|
378 |
* @param compressclient Objeto que representa al compresor ecw |
|
379 |
* @param ulx Coordenada X de la esquina superior izquierda |
|
380 |
* @param uly Coordenada Y de la esquina superior izquierda |
|
381 |
* @param width Ancho de la imagen |
|
382 |
* @param height Alto de la imagen |
|
383 |
* @param blockSizeRead Altura del bloque en la lectura |
|
384 |
*/ |
|
385 |
public Reader(GeoRasterFile grf, NCSEcwCompressClient compressclient, |
|
386 |
int ulx, int uly, int width, int height, int blockSizeRead, int dataType) { |
|
387 |
this.compressclient = compressclient; |
|
388 |
this.width = width; |
|
389 |
this.height = height; |
|
390 |
this.ulX = ulx; |
|
391 |
this.ulY = uly; |
|
392 |
this.grf = grf; |
|
393 |
this.nBands = grf.getBandCount(); |
|
394 |
this.dataType = dataType; |
|
399 | 395 |
|
400 |
nBlocks = (int) (height / this.blockSizeRead); |
|
401 |
lineasBloqueFinal = height - (nBlocks * this.blockSizeRead); |
|
396 |
if (blockSizeRead != 0) { |
|
397 |
this.blockSizeRead = blockSizeRead; |
|
398 |
} |
|
402 | 399 |
|
403 |
} |
|
400 |
nBlocks = (int) (height / this.blockSizeRead); |
|
401 |
lineasBloqueFinal = height - (nBlocks * this.blockSizeRead); |
|
404 | 402 |
|
405 |
/** |
|
406 |
* Constructor para que los datos sean servidos desde el cliente a trav?s de un |
|
407 |
* IDataWriter. |
|
408 |
* @param dataWriter Objeto servidor de datos del driver |
|
409 |
* @param compressclient Objeto que representa al compresor ecw |
|
410 |
* @param width Ancho de la imagen |
|
411 |
* @param height Alto de la imagen |
|
412 |
* @param blockSizeRead Altura del bloque en la lectura |
|
413 |
* @param nBands N?mero de bandas |
|
414 |
*/ |
|
415 |
public Reader(IDataWriter dataWriter, NCSEcwCompressClient compressclient, |
|
416 |
int width, int height, int blockSizeRead, int nBands, |
|
417 |
GeoRasterWriter writer, int dataType) { |
|
418 |
this.compressclient = compressclient; |
|
419 |
this.width = width; |
|
420 |
this.height = height; |
|
421 |
this.dataWriter = dataWriter; |
|
422 |
this.nBands = nBands; |
|
423 |
this.writer = writer; |
|
424 |
this.dataType = dataType; |
|
425 |
|
|
426 |
if (blockSizeRead != 0) { |
|
427 |
this.blockSizeRead = blockSizeRead; |
|
428 |
} |
|
403 |
} |
|
429 | 404 |
|
430 |
nBlocks = (int) (height / this.blockSizeRead); |
|
431 |
lineasBloqueFinal = height - (nBlocks * this.blockSizeRead); |
|
432 |
} |
|
405 |
/** |
|
406 |
* Constructor para que los datos sean servidos desde el cliente a trav?s de un |
|
407 |
* IDataWriter. |
|
408 |
* @param dataWriter Objeto servidor de datos del driver |
|
409 |
* @param compressclient Objeto que representa al compresor ecw |
|
410 |
* @param width Ancho de la imagen |
|
411 |
* @param height Alto de la imagen |
|
412 |
* @param blockSizeRead Altura del bloque en la lectura |
|
413 |
* @param nBands N?mero de bandas |
|
414 |
*/ |
|
415 |
public Reader(IDataWriter dataWriter, NCSEcwCompressClient compressclient, |
|
416 |
int width, int height, int blockSizeRead, int nBands, |
|
417 |
GeoRasterWriter writer, int dataType) { |
|
418 |
this.compressclient = compressclient; |
|
419 |
this.width = width; |
|
420 |
this.height = height; |
|
421 |
this.dataWriter = dataWriter; |
|
422 |
this.nBands = nBands; |
|
423 |
this.writer = writer; |
|
424 |
this.dataType = dataType; |
|
433 | 425 |
|
434 |
/** |
|
435 |
* Lectura de bandas desde un GeoRasterFile |
|
436 |
* @param ulX Coordenada X de la esquina superior izquierda |
|
437 |
* @param ulY Coordenada Y de la esquina superior izquierda |
|
438 |
* @param width Ancho de la imagen |
|
439 |
* @param lineasLeidas N?mero de l?neas a leer del origen |
|
440 |
*/ |
|
441 |
private void readBandsGRFile(int ulX, int ulY, int width, int lineasLeidas) { |
|
442 |
if (nBands >= 1) |
|
443 |
bufband1 = grf.getWindow(ulX, ulY, width, lineasLeidas, 1); |
|
444 |
|
|
445 |
if (nBands >= 2) |
|
446 |
bufband2 = grf.getWindow(ulX, ulY, width, lineasLeidas, 2); |
|
447 |
|
|
448 |
if (nBands >= 3) |
|
449 |
bufband3 = grf.getWindow(ulX, ulY, width, lineasLeidas, 3); |
|
450 |
|
|
451 |
if (nBands >= 4) |
|
452 |
bufband4 = grf.getWindow(ulX, ulY, width, lineasLeidas, 4); |
|
453 |
|
|
454 |
if (nBands >= 5) |
|
455 |
bufband5 = grf.getWindow(ulX, ulY, width, lineasLeidas, 5); |
|
456 |
|
|
457 |
if (nBands >= 6) |
|
458 |
bufband6 = grf.getWindow(ulX, ulY, width, lineasLeidas, 6); |
|
459 |
} |
|
426 |
if (blockSizeRead != 0) { |
|
427 |
this.blockSizeRead = blockSizeRead; |
|
428 |
} |
|
460 | 429 |
|
461 |
/** |
|
462 |
* Lectura de bandas llamando al objeto cliente para que nos cargue el buffer |
|
463 |
* @param width Ancho de la imagen |
|
464 |
* @param height Alto de la imagen |
|
465 |
*/ |
|
466 |
private void readBands(int width, int height) { |
|
467 |
if(dataType == IBuffer.TYPE_IMAGE) |
|
468 |
dataBuffer = dataWriter.readARGBData(width, height, 0); |
|
469 |
if(dataType == IBuffer.TYPE_BYTE) { |
|
470 |
byte[][] b = dataWriter.readByteData(width, height); |
|
471 |
|
|
472 |
} |
|
473 |
} |
|
430 |
nBlocks = (int) (height / this.blockSizeRead); |
|
431 |
lineasBloqueFinal = height - (nBlocks * this.blockSizeRead); |
|
432 |
} |
|
474 | 433 |
|
475 |
/** |
|
476 |
* M?todo obligado por el interfaz y que es llamado desde C cuando el |
|
477 |
* compresor necesita que le sirvan m?s datos. |
|
478 |
*/ |
|
479 |
public void loadBuffer() { |
|
480 |
int lineasLeidas = 0; |
|
434 |
/** |
|
435 |
* Lectura de bandas desde un GeoRasterFile |
|
436 |
* @param ulX Coordenada X de la esquina superior izquierda |
|
437 |
* @param ulY Coordenada Y de la esquina superior izquierda |
|
438 |
* @param width Ancho de la imagen |
|
439 |
* @param lineasLeidas N?mero de l?neas a leer del origen |
|
440 |
*/ |
|
441 |
private void readBandsGRFile(int ulX, int ulY, int width, int lineasLeidas) { |
|
442 |
if (nBands >= 1) |
|
443 |
bufband1 = grf.getWindow(ulX, ulY, width, lineasLeidas, 1); |
|
481 | 444 |
|
482 |
//si se leen bloques completos lineasLeidas es == al tama?o de bloque sino |
|
483 |
//es que es el ?ltimo con lo que ser? del tama?o del bloque final |
|
484 |
if (countBlock <= nBlocks) |
|
485 |
lineasLeidas = blockSizeRead; |
|
486 |
else |
|
487 |
lineasLeidas = lineasBloqueFinal; |
|
488 |
|
|
489 |
//Leemos un bloque nuevo cuando se han procesado todas las l?neas del anterior |
|
490 |
if ((nNextLine % blockSizeRead) == 0) { |
|
491 |
if (grf != null) |
|
492 |
readBandsGRFile(ulX, ulY + nNextLine, width, lineasLeidas); |
|
493 |
else if (dataWriter != null) { |
|
494 |
if(dataType == IBuffer.TYPE_IMAGE) |
|
495 |
dataBuffer = dataWriter.readARGBData(width, lineasLeidas, 0); |
|
496 |
if(dataType == IBuffer.TYPE_BYTE) |
|
497 |
byteBuffer = dataWriter.readByteData(width, lineasLeidas); |
|
498 |
} |
|
445 |
if (nBands >= 2) |
|
446 |
bufband2 = grf.getWindow(ulX, ulY, width, lineasLeidas, 2); |
|
499 | 447 |
|
500 |
countLine = 0; |
|
501 |
countBlock++; |
|
502 |
} |
|
503 |
|
|
504 |
if(dataType == IBuffer.TYPE_IMAGE) |
|
505 |
loadBufferFromImageDataType(dataBuffer); |
|
506 |
if(dataType == IBuffer.TYPE_BYTE) |
|
507 |
loadBufferFromByteDataType(byteBuffer); |
|
448 |
if (nBands >= 3) |
|
449 |
bufband3 = grf.getWindow(ulX, ulY, width, lineasLeidas, 3); |
|
508 | 450 |
|
509 |
/* for (int iBand = 0; iBand < this.nBands; iBand++) { |
|
510 |
for (int pos = 0; pos < width; pos++) { |
|
511 |
if (grf != null && write) { |
|
512 |
if (iBand == 0) |
|
513 |
compressclient.buffer[pos + (width * iBand)] = |
|
514 |
bufband1[pos + (width * countLine)]; |
|
451 |
if (nBands >= 4) |
|
452 |
bufband4 = grf.getWindow(ulX, ulY, width, lineasLeidas, 4); |
|
515 | 453 |
|
516 |
if (iBand == 1) |
|
517 |
compressclient.buffer[pos + (width * iBand)] = |
|
518 |
bufband2[pos + (width * countLine)]; |
|
454 |
if (nBands >= 5) |
|
455 |
bufband5 = grf.getWindow(ulX, ulY, width, lineasLeidas, 5); |
|
519 | 456 |
|
520 |
if (iBand == 2)
|
|
521 |
compressclient.buffer[pos + (width * iBand)] =
|
|
522 |
bufband3[pos + (width * countLine)];
|
|
457 |
if (nBands >= 6)
|
|
458 |
bufband6 = grf.getWindow(ulX, ulY, width, lineasLeidas, 6);
|
|
459 |
}
|
|
523 | 460 |
|
524 |
if (iBand == 3) |
|
525 |
compressclient.buffer[pos + (width * iBand)] = |
|
526 |
bufband4[pos + (width * countLine)]; |
|
461 |
/** |
|
462 |
* Lectura de bandas llamando al objeto cliente para que nos cargue el buffer |
|
463 |
* @param width Ancho de la imagen |
|
464 |
* @param height Alto de la imagen |
|
465 |
*/ |
|
466 |
private void readBands(int width, int height) { |
|
467 |
if(dataType == IBuffer.TYPE_IMAGE) |
|
468 |
dataBuffer = dataWriter.readARGBData(width, height, 0); |
|
469 |
if(dataType == IBuffer.TYPE_BYTE) { |
|
470 |
byte[][] b = dataWriter.readByteData(width, height); |
|
527 | 471 |
|
528 |
if (iBand == 4) |
|
529 |
compressclient.buffer[pos + (width * iBand)] = |
|
530 |
bufband5[pos + (width * countLine)]; |
|
531 |
|
|
532 |
if (iBand == 5) |
|
533 |
compressclient.buffer[pos + (width * iBand)] = |
|
534 |
bufband6[pos + (width * countLine)]; |
|
535 |
|
|
536 |
} else { |
|
537 |
if (iBand == 0) |
|
538 |
compressclient.buffer[pos + (width * iBand)] = |
|
539 |
(byte) ((dataBuffer[pos + (width * countLine)] & 0xff0000) >> 16); |
|
540 |
|
|
472 |
} |
|
473 |
} |
|
541 | 474 |
|
542 |
if (iBand == 1) |
|
543 |
compressclient.buffer[pos + (width * iBand)] = |
|
544 |
(byte) ((dataBuffer[pos + (width * countLine)] & 0xff00) >> 8); |
|
545 |
|
|
475 |
/** |
|
476 |
* M?todo obligado por el interfaz y que es llamado desde C cuando el |
|
477 |
* compresor necesita que le sirvan m?s datos. |
|
478 |
*/ |
|
479 |
public void loadBuffer() { |
|
480 |
int lineasLeidas = 0; |
|
546 | 481 |
|
547 |
if (iBand == 2) |
|
548 |
compressclient.buffer[pos + (width * iBand)] = |
|
549 |
(byte) (dataBuffer[pos + (width * countLine)] & 0xff); |
|
550 |
|
|
551 |
} |
|
482 |
//si se leen bloques completos lineasLeidas es == al tama?o de bloque sino |
|
483 |
//es que es el ?ltimo con lo que ser? del tama?o del bloque final |
|
484 |
if (countBlock <= nBlocks) |
|
485 |
lineasLeidas = blockSizeRead; |
|
486 |
else |
|
487 |
lineasLeidas = lineasBloqueFinal; |
|
552 | 488 |
|
553 |
if ((pos == (width - 1)) && (iBand == (this.nBands - 1))) { |
|
554 |
countLine++; |
|
555 |
} |
|
556 |
} |
|
557 |
}*/ |
|
558 |
} |
|
559 |
|
|
560 |
/** |
|
561 |
* Carga el buffer de datos desde elementos de tipo entero con contenido ARGB |
|
562 |
* @param data Array de datos enteros |
|
563 |
*/ |
|
564 |
private void loadBufferFromImageDataType(int[] data) { |
|
565 |
for (int iBand = 0; iBand < this.nBands; iBand++) { |
|
566 |
for (int pos = 0; pos < width; pos++) { |
|
567 |
switch(iBand) { |
|
568 |
case 0: |
|
569 |
compressclient.buffer[pos + (width * iBand)] = |
|
570 |
(byte) ((data[pos + (width * countLine)] & 0xff0000) >> 16); |
|
571 |
break; |
|
572 |
case 1: |
|
573 |
compressclient.buffer[pos + (width * iBand)] = |
|
574 |
(byte) ((data[pos + (width * countLine)] & 0xff00) >> 8); |
|
575 |
break; |
|
576 |
case 2: |
|
577 |
compressclient.buffer[pos + (width * iBand)] = |
|
578 |
(byte) (data[pos + (width * countLine)] & 0xff); |
|
579 |
break; |
|
580 |
} |
|
581 |
if ((pos == (width - 1)) && (iBand == (this.nBands - 1))) |
|
582 |
countLine++; |
|
583 |
} |
|
584 |
} |
|
585 |
} |
|
586 |
|
|
587 |
/** |
|
588 |
* Carga el buffer de datos a comprimir desde un buffer byte[][] donde la primera dimensi?n |
|
589 |
* es el n?mero de bandas y la segunda los elementos en lista (Ancho X Alto) |
|
590 |
* @param b Buffer de datos de tipo byte[][] |
|
591 |
*/ |
|
592 |
private void loadBufferFromByteDataType(byte[][] b) { |
|
593 |
for (int iBand = 0; iBand < this.nBands; iBand++) { |
|
594 |
for (int pos = 0; pos < width; pos++) { |
|
595 |
compressclient.buffer[pos + (width * iBand)] = b[iBand][pos + (width * countLine)]; |
|
596 |
if ((pos == (width - 1)) && (iBand == (this.nBands - 1))) |
|
597 |
countLine++; |
|
598 |
} |
|
599 |
} |
|
600 |
} |
|
489 |
//Leemos un bloque nuevo cuando se han procesado todas las l?neas del anterior |
|
490 |
if ((nNextLine % blockSizeRead) == 0) { |
|
491 |
if (grf != null) |
|
492 |
readBandsGRFile(ulX, ulY + nNextLine, width, lineasLeidas); |
|
493 |
else if (dataWriter != null) { |
|
494 |
if(dataType == IBuffer.TYPE_IMAGE) |
|
495 |
dataBuffer = dataWriter.readARGBData(width, lineasLeidas, 0); |
|
496 |
if(dataType == IBuffer.TYPE_BYTE) |
|
497 |
byteBuffer = dataWriter.readByteData(width, lineasLeidas); |
|
498 |
} |
|
601 | 499 |
|
602 |
/** |
|
603 |
* M?todo obligado por el interfaz y que es llamado desde C cuando el |
|
604 |
* compresor actualiza el porcentaje de compresi?n |
|
605 |
*/ |
|
606 |
public void updatePercent() { |
|
607 |
writer.setPercent(compressclient.getPercent()); |
|
608 |
//System.out.println(compressclient.getPercent() + "%"); |
|
609 |
} |
|
610 |
|
|
611 |
/** |
|
612 |
* Obtiene el valor a la variable write que estar? a true cuando se est? escribiendo |
|
613 |
* o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura |
|
614 |
* pondr? esta variable a false deteniendose la escritura y cerrandose el dataset |
|
615 |
* de salida. |
|
616 |
* @return True si puede escribirse y false si no puede |
|
617 |
*/ |
|
618 |
public boolean isWrite() { |
|
500 |
countLine = 0; |
|
501 |
countBlock++; |
|
502 |
} |
|
503 |
|
|
504 |
if(dataType == IBuffer.TYPE_IMAGE) |
|
505 |
loadBufferFromImageDataType(dataBuffer); |
|
506 |
if(dataType == IBuffer.TYPE_BYTE) |
|
507 |
loadBufferFromByteDataType(byteBuffer); |
|
508 |
|
|
509 |
/* for (int iBand = 0; iBand < this.nBands; iBand++) { |
|
510 |
for (int pos = 0; pos < width; pos++) { |
|
511 |
if (grf != null && write) { |
|
512 |
if (iBand == 0) |
|
513 |
compressclient.buffer[pos + (width * iBand)] = |
|
514 |
bufband1[pos + (width * countLine)]; |
|
515 |
|
|
516 |
if (iBand == 1) |
|
517 |
compressclient.buffer[pos + (width * iBand)] = |
|
518 |
bufband2[pos + (width * countLine)]; |
|
519 |
|
|
520 |
if (iBand == 2) |
|
521 |
compressclient.buffer[pos + (width * iBand)] = |
|
522 |
bufband3[pos + (width * countLine)]; |
|
523 |
|
|
524 |
if (iBand == 3) |
|
525 |
compressclient.buffer[pos + (width * iBand)] = |
|
526 |
bufband4[pos + (width * countLine)]; |
|
527 |
|
|
528 |
if (iBand == 4) |
|
529 |
compressclient.buffer[pos + (width * iBand)] = |
|
530 |
bufband5[pos + (width * countLine)]; |
|
531 |
|
|
532 |
if (iBand == 5) |
|
533 |
compressclient.buffer[pos + (width * iBand)] = |
|
534 |
bufband6[pos + (width * countLine)]; |
|
535 |
|
|
536 |
} else { |
|
537 |
if (iBand == 0) |
|
538 |
compressclient.buffer[pos + (width * iBand)] = |
|
539 |
(byte) ((dataBuffer[pos + (width * countLine)] & 0xff0000) >> 16); |
|
540 |
|
|
541 |
|
|
542 |
if (iBand == 1) |
|
543 |
compressclient.buffer[pos + (width * iBand)] = |
|
544 |
(byte) ((dataBuffer[pos + (width * countLine)] & 0xff00) >> 8); |
|
545 |
|
|
546 |
|
|
547 |
if (iBand == 2) |
|
548 |
compressclient.buffer[pos + (width * iBand)] = |
|
549 |
(byte) (dataBuffer[pos + (width * countLine)] & 0xff); |
|
550 |
|
|
551 |
} |
|
552 |
|
|
553 |
if ((pos == (width - 1)) && (iBand == (this.nBands - 1))) { |
|
554 |
countLine++; |
|
555 |
} |
|
556 |
} |
|
557 |
}*/ |
|
558 |
} |
|
559 |
|
|
560 |
/** |
|
561 |
* Carga el buffer de datos desde elementos de tipo entero con contenido ARGB |
|
562 |
* @param data Array de datos enteros |
|
563 |
*/ |
|
564 |
private void loadBufferFromImageDataType(int[] data) { |
|
565 |
for (int iBand = 0; iBand < this.nBands; iBand++) { |
|
566 |
for (int pos = 0; pos < width; pos++) { |
|
567 |
switch(iBand) { |
|
568 |
case 0: |
|
569 |
compressclient.buffer[pos + (width * iBand)] = |
|
570 |
(byte) ((data[pos + (width * countLine)] & 0xff0000) >> 16); |
|
571 |
break; |
|
572 |
case 1: |
|
573 |
compressclient.buffer[pos + (width * iBand)] = |
|
574 |
(byte) ((data[pos + (width * countLine)] & 0xff00) >> 8); |
|
575 |
break; |
|
576 |
case 2: |
|
577 |
compressclient.buffer[pos + (width * iBand)] = |
|
578 |
(byte) (data[pos + (width * countLine)] & 0xff); |
|
579 |
break; |
|
580 |
} |
|
581 |
if ((pos == (width - 1)) && (iBand == (this.nBands - 1))) |
|
582 |
countLine++; |
|
583 |
} |
|
584 |
} |
|
585 |
} |
|
586 |
|
|
587 |
/** |
|
588 |
* Carga el buffer de datos a comprimir desde un buffer byte[][] donde la primera dimensi?n |
|
589 |
* es el n?mero de bandas y la segunda los elementos en lista (Ancho X Alto) |
|
590 |
* @param b Buffer de datos de tipo byte[][] |
|
591 |
*/ |
|
592 |
private void loadBufferFromByteDataType(byte[][] b) { |
|
593 |
for (int iBand = 0; iBand < this.nBands; iBand++) { |
|
594 |
for (int pos = 0; pos < width; pos++) { |
|
595 |
compressclient.buffer[pos + (width * iBand)] = b[iBand][pos + (width * countLine)]; |
|
596 |
if ((pos == (width - 1)) && (iBand == (this.nBands - 1))) |
|
597 |
countLine++; |
|
598 |
} |
|
599 |
} |
|
600 |
} |
|
601 |
|
|
602 |
/** |
|
603 |
* M?todo obligado por el interfaz y que es llamado desde C cuando el |
|
604 |
* compresor actualiza el porcentaje de compresi?n |
|
605 |
*/ |
|
606 |
public void updatePercent() { |
|
607 |
writer.setPercent(compressclient.getPercent()); |
|
608 |
//System.out.println(compressclient.getPercent() + "%"); |
|
609 |
} |
|
610 |
|
|
611 |
/** |
|
612 |
* Obtiene el valor a la variable write que estar? a true cuando se est? escribiendo |
|
613 |
* o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura |
|
614 |
* pondr? esta variable a false deteniendose la escritura y cerrandose el dataset |
|
615 |
* de salida. |
|
616 |
* @return True si puede escribirse y false si no puede |
|
617 |
*/ |
|
618 |
public boolean isWrite() { |
|
619 | 619 |
return write; |
620 | 620 |
} |
621 | 621 |
|
622 |
/**
|
|
623 |
* Asigna el valor a la variable write que estar? a true cuando se est? escribiendo
|
|
624 |
* o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
|
|
625 |
* pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
|
|
626 |
* de salida.
|
|
627 |
* @param write Variable booleana. True si puede escribirse y false si no puede
|
|
628 |
*/
|
|
622 |
/**
|
|
623 |
* Asigna el valor a la variable write que estar? a true cuando se est? escribiendo
|
|
624 |
* o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
|
|
625 |
* pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
|
|
626 |
* de salida.
|
|
627 |
* @param write Variable booleana. True si puede escribirse y false si no puede
|
|
628 |
*/
|
|
629 | 629 |
public void setWrite(boolean write) { |
630 | 630 |
this.write = write; |
631 | 631 |
} |
632 |
|
|
632 |
|
|
633 | 633 |
} |
Also available in: Unified diff