28 |
28 |
|
29 |
29 |
import org.cresques.cts.IProjection;
|
30 |
30 |
import org.cresques.geo.ViewPortData;
|
|
31 |
import org.cresques.io.GdalWriter.GdalSupportOptions;
|
31 |
32 |
import org.cresques.px.PxRaster;
|
32 |
33 |
|
33 |
34 |
import es.gva.cit.jgdal.Gdal;
|
... | ... | |
46 |
47 |
@author Nacho Brodin (brodin_ign@gva.es)
|
47 |
48 |
*/
|
48 |
49 |
public class JpegWriter extends GeoRasterWriter {
|
49 |
|
|
|
50 |
|
|
51 |
public final int windowSizeX = 386;
|
|
52 |
public final int windowSizeY = 215;
|
|
53 |
public final int panelSizeX = 358;
|
|
54 |
public final int panelSizeY = 125;
|
|
55 |
|
50 |
56 |
//Datos de registro de drivers
|
51 |
57 |
static {
|
52 |
58 |
GeoRasterWriter.registerWriterExtension("jpg", JpegWriter.class);
|
... | ... | |
55 |
61 |
typeList.put("jpeg", "Jpeg");
|
56 |
62 |
}
|
57 |
63 |
|
58 |
|
private GdalWriter gdalWriter = null;
|
59 |
|
private String outTif = null;
|
60 |
|
private String outJpg = null;
|
61 |
|
private String[] props = null;
|
62 |
|
private ViewPortData viewPort = null;
|
|
64 |
private GdalWriter gdalWriter = null;
|
|
65 |
private JpegSupportOptions support = null;
|
|
66 |
private String outTif = null;
|
|
67 |
private String outJpg = null;
|
|
68 |
private String[] props = null;
|
|
69 |
private ViewPortData viewPort = null;
|
|
70 |
private String[] params = null; //Par?metros de creaci?n del dataset.
|
63 |
71 |
|
64 |
72 |
/**
|
65 |
73 |
* Constructor para la obtenci?n de par?metros del driver
|
66 |
74 |
* @param drvType Tipo de driver
|
67 |
75 |
*/
|
68 |
76 |
public JpegWriter(String fileName) {
|
|
77 |
ident = fileName.toLowerCase().substring(fileName.lastIndexOf(".") + 1);
|
|
78 |
driver = (String)typeList.get(ident);
|
|
79 |
support = new JpegSupportOptions(driver);
|
69 |
80 |
gdalWriter = new GdalWriter(fileName);
|
|
81 |
gdalWriter.getSupport().setTfw(true);
|
|
82 |
setParams();
|
70 |
83 |
}
|
71 |
84 |
|
72 |
85 |
/**
|
... | ... | |
76 |
89 |
* @param infilename Nombre del fichero de entrada
|
77 |
90 |
* @param drvType Tipo de driver
|
78 |
91 |
*/
|
79 |
|
public JpegWriter(PxRaster raster, String outFileName, String inFileName) throws GdalException, IOException {
|
|
92 |
public JpegWriter(PxRaster raster, String outFileName, String inFileName) throws GdalException, IOException {
|
|
93 |
ident = inFileName.toLowerCase().substring(inFileName.lastIndexOf(".") + 1);
|
|
94 |
driver = (String)typeList.get(ident);
|
|
95 |
support = new JpegSupportOptions(driver);
|
80 |
96 |
gdalWriter = new GdalWriter(raster, outFileName, inFileName);
|
|
97 |
gdalWriter.getSupport().setTfw(true);
|
|
98 |
setParams();
|
81 |
99 |
}
|
82 |
100 |
|
83 |
101 |
/**
|
... | ... | |
103 |
121 |
Integer compresion,
|
104 |
122 |
Integer outSizeX,
|
105 |
123 |
Integer outSizeY)throws GdalException, IOException {
|
|
124 |
ident = outFileName.toLowerCase().substring(outFileName.lastIndexOf(".") + 1);
|
|
125 |
driver = (String)typeList.get(ident);
|
|
126 |
support = new JpegSupportOptions(driver);
|
106 |
127 |
outJpg = outFileName;
|
107 |
128 |
outTif = outFileName.substring(0, outFileName.lastIndexOf(".") + 1);
|
108 |
129 |
outTif = outTif + "tif";
|
109 |
130 |
this.viewPort = vp;
|
110 |
131 |
gdalWriter = new GdalWriter(dataWriter, outTif, blockSize, nBands,
|
111 |
132 |
vp, compresion, outSizeX, outSizeY);
|
|
133 |
gdalWriter.getSupport().setTfw(true);
|
|
134 |
setParams();
|
112 |
135 |
}
|
113 |
136 |
|
114 |
137 |
|
... | ... | |
121 |
144 |
}
|
122 |
145 |
|
123 |
146 |
/**
|
|
147 |
* A partir de un elemento que contiene una propiedad y un valor
|
|
148 |
* lo parsea y asigna el valor a su variable.
|
|
149 |
* @param propValue elemento con la forma propiedad=valor
|
|
150 |
*/
|
|
151 |
private void readProperty(String propValue) {
|
|
152 |
String prop = propValue.substring(0, propValue.indexOf("="));
|
|
153 |
|
|
154 |
if (propValue.startsWith(prop)) {
|
|
155 |
String value = propValue.substring(propValue.indexOf("=") + 1,
|
|
156 |
propValue.length());
|
|
157 |
|
|
158 |
if ((value != null) && !value.equals("")) {
|
|
159 |
if (prop.equals("COMPRESSION"))
|
|
160 |
support.setCompressionDefault(Integer.parseInt(value));
|
|
161 |
|
|
162 |
if (prop.equals("PROGRESSIVE")) {
|
|
163 |
boolean prog = true;
|
|
164 |
|
|
165 |
if (value.equals("yes")) {
|
|
166 |
prog = true;
|
|
167 |
} else {
|
|
168 |
prog = false;
|
|
169 |
}
|
|
170 |
|
|
171 |
support.setProgressive(prog);
|
|
172 |
}
|
|
173 |
}
|
|
174 |
}
|
|
175 |
}
|
|
176 |
|
|
177 |
/**
|
124 |
178 |
* Asigna propiedades al driver a partir de un vector de
|
125 |
179 |
* strings donde cada elemento tiene la estructura de
|
126 |
180 |
* propiedad=valor.
|
... | ... | |
128 |
182 |
*/
|
129 |
183 |
public void setProps(String[] props) {
|
130 |
184 |
this.props = props;
|
131 |
|
gdalWriter.setProps(props);
|
|
185 |
for (int iProps = 0; iProps < props.length; iProps++)
|
|
186 |
readProperty(props[iProps]);
|
|
187 |
setParams();
|
132 |
188 |
}
|
133 |
189 |
|
134 |
190 |
/**
|
... | ... | |
149 |
205 |
}
|
150 |
206 |
|
151 |
207 |
/**
|
|
208 |
*Asigna par?metros de creaci?n del dataset de Gdal
|
|
209 |
*/
|
|
210 |
private void setParams() {
|
|
211 |
params = new String[3];
|
|
212 |
|
|
213 |
params[0] = new String("WORLDFILE=ON");
|
|
214 |
params[1] = new String("QUALITY=" + support.getCompressionRealValue());
|
|
215 |
String prog = null;
|
|
216 |
|
|
217 |
if (support.isProgressive()) {
|
|
218 |
prog = new String("ON");
|
|
219 |
} else {
|
|
220 |
prog = new String("NO");
|
|
221 |
}
|
|
222 |
params[2] = new String("PROGRESSIVE=" + prog);
|
|
223 |
}
|
|
224 |
|
|
225 |
/**
|
152 |
226 |
* Realiza la escritura de datos con los datos que le pasa el cliente.
|
153 |
227 |
* @throws IOException
|
154 |
228 |
*/
|
... | ... | |
162 |
236 |
driver = Gdal.getDriverByName("JPEG");
|
163 |
237 |
|
164 |
238 |
GdalWriter.createCopy(driver, outJpg, outTif, false,
|
165 |
|
props, viewPort.getProjection());
|
|
239 |
params, viewPort.getProjection());
|
166 |
240 |
}catch(GdalException exc){
|
167 |
241 |
System.err.println("No se ha podido obtener el driver.");
|
168 |
242 |
}
|
... | ... | |
193 |
267 |
* @return XML de configuraci?n del dialogo.
|
194 |
268 |
*/
|
195 |
269 |
public String getXMLPropertiesDialog() {
|
196 |
|
return gdalWriter.getXMLPropertiesDialog();
|
|
270 |
StringBuffer options = null;
|
|
271 |
options = new StringBuffer();
|
|
272 |
options.append("<window sizex=\"" + windowSizeX + "\" sizey=\"" +
|
|
273 |
windowSizeY + "\">");
|
|
274 |
options.append("<panel sizex=\"" + panelSizeX + "\" sizey=\"" +
|
|
275 |
panelSizeY + "\" layout=\"" + gdalWriter.panelLayout +
|
|
276 |
"\" border=\"yes\">");
|
|
277 |
|
|
278 |
options.append("<panel layout=\"FlowLayout\" position=\"North\" align=\"left\">");
|
|
279 |
options.append("<label>Block size:</label>");
|
|
280 |
options.append("<combo ident=\"BLOCKSIZE\" selected=\"" +
|
|
281 |
gdalWriter.getSupport().getBlockSize() + "\">");
|
|
282 |
|
|
283 |
for (int i = 0; i < gdalWriter.getSupport().getBlockSizeList().length; i++)
|
|
284 |
options.append("<elem>" + gdalWriter.getSupport().getBlockSizeList()[i] +
|
|
285 |
"</elem>");
|
|
286 |
|
|
287 |
options.append("</combo>");
|
|
288 |
options.append("</panel>");
|
|
289 |
|
|
290 |
|
|
291 |
options.append("<panel layout=\"FlowLayout\" position=\"Center\">");
|
|
292 |
options.append("<slider ident=\"COMPRESSION\" name=\"Compression\" sizex=\"370\" sizey=\"20\">");
|
|
293 |
options.append("<min>" + support.getCompressionList()[0] +
|
|
294 |
"</min>");
|
|
295 |
options.append("<max>" + support.getCompressionList()[1] +
|
|
296 |
"</max>");
|
|
297 |
options.append("<value>" + support.getCompressionDefault() + "</value>");
|
|
298 |
options.append("<minorspacing>" + support.getCompressionList()[3] +
|
|
299 |
"</minorspacing>");
|
|
300 |
options.append("<majorspacing>" + support.getCompressionList()[4] +
|
|
301 |
"</majorspacing>");
|
|
302 |
options.append("</slider>");
|
|
303 |
options.append("</panel>");
|
|
304 |
|
|
305 |
|
|
306 |
options.append("<panel layout=\"FlowLayout\" position=\"South\" align=\"left\">");
|
|
307 |
options.append("<label>Progressive:</label>");
|
|
308 |
String sel = null;
|
|
309 |
if (support.isProgressive()) {
|
|
310 |
sel = new String("yes");
|
|
311 |
} else {
|
|
312 |
sel = new String("no");
|
|
313 |
}
|
|
314 |
options.append("<check ident=\"PROGRESSIVE\" selected=\"" + sel +
|
|
315 |
"\" text=\"\">");
|
|
316 |
options.append("</check>");
|
|
317 |
|
|
318 |
options.append("</panel>");
|
|
319 |
|
|
320 |
options.append("</panel>");
|
|
321 |
options.append("</window>");
|
|
322 |
|
|
323 |
return options.toString();
|
197 |
324 |
}
|
|
325 |
|
|
326 |
/**
|
|
327 |
*
|
|
328 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
|
329 |
*
|
|
330 |
* Opciones que soporta el driver de escritura de Jpeg.
|
|
331 |
*/
|
|
332 |
public class JpegSupportOptions extends WriterSupportOptions {
|
|
333 |
private boolean progressive = true;
|
|
334 |
private String[] compresionListValues = { "10", "100", "16", "5", "30" }; //min, max, valor defecto, intervalo peque?o, intervalo grande;
|
|
335 |
private int compresionDefaultValue = 16;
|
|
336 |
|
|
337 |
public JpegSupportOptions(String ext) {
|
|
338 |
super(ext);
|
|
339 |
}
|
|
340 |
|
|
341 |
/**
|
|
342 |
* Obtiene la compresion seleccionada
|
|
343 |
* @return Compresi?n seleccionada
|
|
344 |
*/
|
|
345 |
public int getCompressionDefault() {
|
|
346 |
return compresionDefaultValue;
|
|
347 |
}
|
|
348 |
|
|
349 |
/**
|
|
350 |
* Obtiene la compresion seleccionada en el valor real que necesita gdal. Por defecto gdal
|
|
351 |
* tiene un valor de 75 en un rango de 10-100 donde 10 es la m?xima compresi?n.
|
|
352 |
* Como el slider est? en un rango de 0-100 donde el 100 es la m?xima compresi?n y 0
|
|
353 |
* la m?nima hay que hacer una conversi?n.
|
|
354 |
* @return Compresi?n seleccionada
|
|
355 |
*/
|
|
356 |
public int getCompressionRealValue() {
|
|
357 |
return 110 - compresionDefaultValue;
|
|
358 |
}
|
|
359 |
|
|
360 |
|
|
361 |
/**
|
|
362 |
* Obtiene la lista de los valores para la generaci?n de la barra de
|
|
363 |
* compresi?n. Son cinco valores m?nimo, m?ximo, seleccionado,
|
|
364 |
* intervalo peque?o, intervalo grande.
|
|
365 |
* @return lista de valores de compresi?n
|
|
366 |
*/
|
|
367 |
public String[] getCompressionList() {
|
|
368 |
return compresionListValues;
|
|
369 |
}
|
|
370 |
|
|
371 |
/**
|
|
372 |
* Asigna el nivel de compresi?npor defecto
|
|
373 |
* @param compress Nivel de compresi?n
|
|
374 |
*/
|
|
375 |
public void setCompressionDefault(int compress) {
|
|
376 |
this.compresionDefaultValue = compress;
|
|
377 |
}
|
|
378 |
|
|
379 |
/**
|
|
380 |
* Asigna la lista de valores de compresi?n
|
|
381 |
* @param compresion lista de valores
|
|
382 |
*/
|
|
383 |
public void setCompressionList(String[] compresion) {
|
|
384 |
this.compresionListValues = compresion;
|
|
385 |
}
|
|
386 |
|
|
387 |
public boolean isProgressive() {
|
|
388 |
return progressive;
|
|
389 |
}
|
|
390 |
|
|
391 |
public void setProgressive(boolean progressive) {
|
|
392 |
this.progressive = progressive;
|
|
393 |
}
|
|
394 |
}
|
198 |
395 |
}
|