Revision 22422 trunk/libraries/libRaster/src/org/gvsig/raster/dataset/io/JpegWriter.java
JpegWriter.java | ||
---|---|---|
34 | 34 |
import org.gvsig.raster.dataset.io.features.JpegFeatures; |
35 | 35 |
import org.gvsig.raster.dataset.io.features.WriteFileFormatFeatures; |
36 | 36 |
import org.gvsig.raster.util.RasterUtilities; |
37 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
|
38 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
|
37 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoint; |
|
39 | 38 |
|
40 | 39 |
import es.gva.cit.jgdal.Gdal; |
41 | 40 |
import es.gva.cit.jgdal.GdalDriver; |
... | ... | |
54 | 53 |
*/ |
55 | 54 |
public class JpegWriter extends GeoRasterWriter { |
56 | 55 |
|
57 |
|
|
58 |
//Datos de registro de drivers |
|
59 |
public static void register() { |
|
60 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
61 |
|
|
62 |
extensionPoints.add("RasterWriter", "jpg", JpegWriter.class); |
|
56 |
// Datos de registro de drivers |
|
57 |
public static void register() { |
|
58 |
ExtensionPoint point = ExtensionPoint.getExtensionPoint("RasterWriter"); |
|
59 |
point.register("jpg", JpegWriter.class); |
|
63 | 60 |
fileFeature.put("jpg", new JpegFeatures()); |
64 |
}
|
|
61 |
}
|
|
65 | 62 |
|
66 |
private GdalWriter gdalWriter = null;
|
|
67 |
private String outTif = null;
|
|
68 |
private String outJpg = null;
|
|
69 |
|
|
63 |
private GdalWriter gdalWriter = null;
|
|
64 |
private String outTif = null;
|
|
65 |
private String outJpg = null;
|
|
66 |
|
|
70 | 67 |
/** |
71 | 68 |
* Carga los par?metros de este driver. |
72 | 69 |
*/ |
... | ... | |
76 | 73 |
driverParams = wfff.getParams(); |
77 | 74 |
} |
78 | 75 |
|
79 |
/**
|
|
80 |
* Constructor para la obtenci?n de par?metros del driver
|
|
81 |
* @param drvType Tipo de driver
|
|
82 |
*/
|
|
83 |
public JpegWriter(String fileName) {
|
|
76 |
/**
|
|
77 |
* Constructor para la obtenci?n de par?metros del driver
|
|
78 |
* @param drvType Tipo de driver
|
|
79 |
*/
|
|
80 |
public JpegWriter(String fileName) {
|
|
84 | 81 |
ident = RasterUtilities.getExtensionFromFileName(fileName); |
85 | 82 |
driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName(); |
86 |
gdalWriter = new GdalWriter(fileName);
|
|
87 |
|
|
83 |
gdalWriter = new GdalWriter(fileName);
|
|
84 |
|
|
88 | 85 |
loadParams(ident); |
89 |
}
|
|
86 |
}
|
|
90 | 87 |
|
91 |
/**
|
|
92 |
* Constructor para salvar datos servidos por el cliente
|
|
93 |
* @param dataWriter Objeto servidor de datos para el driver de escritura
|
|
94 |
* @param outSizeX N?mero de pixels en X de la imagen de salida
|
|
95 |
* @param outSizeY N?mero de pixels en Y de la imagen de salida
|
|
96 |
* @param outFilename Fichero de salida
|
|
97 |
* @param extentMaxX Posici?n en X m?xima del extent
|
|
98 |
* @param extentMinX Posici?n en X m?nima del extent
|
|
99 |
* @param extentMaxY Posici?n en Y m?xima del extent
|
|
100 |
* @param extentMinY Posici?n en Y m?nima del extent
|
|
101 |
* @param nBands N?mero de bandas
|
|
102 |
* @param drvType Tipo de driver
|
|
103 |
* @throws GdalException
|
|
104 |
* @throws IOException
|
|
105 |
*/
|
|
106 |
public JpegWriter( IDataWriter dataWriter,
|
|
107 |
String outFileName,
|
|
108 |
Integer nBands,
|
|
109 |
AffineTransform at,
|
|
110 |
Integer outSizeX,
|
|
111 |
Integer outSizeY,
|
|
112 |
Integer dataType,
|
|
113 |
Params params,
|
|
114 |
IProjection proj,
|
|
115 |
Boolean geo)throws GdalException, IOException {
|
|
116 |
ident = RasterUtilities.getExtensionFromFileName(outFileName);
|
|
88 |
/**
|
|
89 |
* Constructor para salvar datos servidos por el cliente
|
|
90 |
* @param dataWriter Objeto servidor de datos para el driver de escritura
|
|
91 |
* @param outSizeX N?mero de pixels en X de la imagen de salida
|
|
92 |
* @param outSizeY N?mero de pixels en Y de la imagen de salida
|
|
93 |
* @param outFilename Fichero de salida
|
|
94 |
* @param extentMaxX Posici?n en X m?xima del extent
|
|
95 |
* @param extentMinX Posici?n en X m?nima del extent
|
|
96 |
* @param extentMaxY Posici?n en Y m?xima del extent
|
|
97 |
* @param extentMinY Posici?n en Y m?nima del extent
|
|
98 |
* @param nBands N?mero de bandas
|
|
99 |
* @param drvType Tipo de driver
|
|
100 |
* @throws GdalException
|
|
101 |
* @throws IOException
|
|
102 |
*/
|
|
103 |
public JpegWriter( IDataWriter dataWriter,
|
|
104 |
String outFileName,
|
|
105 |
Integer nBands,
|
|
106 |
AffineTransform at,
|
|
107 |
Integer outSizeX,
|
|
108 |
Integer outSizeY,
|
|
109 |
Integer dataType,
|
|
110 |
Params params,
|
|
111 |
IProjection proj,
|
|
112 |
Boolean geo)throws GdalException, IOException {
|
|
113 |
ident = RasterUtilities.getExtensionFromFileName(outFileName);
|
|
117 | 114 |
driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName(); |
118 |
outJpg = outFileName;
|
|
119 |
outTif = outFileName.substring(0, outFileName.lastIndexOf("."));
|
|
120 |
outTif += ".tif";
|
|
121 |
|
|
122 |
gdalWriter = new GdalWriter(dataWriter, outTif, nBands,
|
|
123 |
at, outSizeX, outSizeY, dataType, params, proj, geo);
|
|
115 |
outJpg = outFileName;
|
|
116 |
outTif = outFileName.substring(0, outFileName.lastIndexOf("."));
|
|
117 |
outTif += ".tif";
|
|
118 |
|
|
119 |
gdalWriter = new GdalWriter(dataWriter, outTif, nBands,
|
|
120 |
at, outSizeX, outSizeY, dataType, params, proj, geo);
|
|
124 | 121 |
if(params == null) |
125 | 122 |
loadParams(ident); |
126 | 123 |
else |
127 | 124 |
this.driverParams = params; |
128 |
}
|
|
125 |
}
|
|
129 | 126 |
|
130 |
|
|
131 |
/**
|
|
132 |
* Asigna el tipo de driver con el que se salvar? la imagen
|
|
133 |
* @param drvType Tipo de driver
|
|
134 |
*/
|
|
135 |
public void setDriverType(String drvType) {
|
|
136 |
gdalWriter.setDriverType(drvType);
|
|
137 |
}
|
|
138 |
|
|
139 |
/**
|
|
140 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
|
|
141 |
* @throws IOException
|
|
142 |
*/
|
|
143 |
public void fileWrite() throws IOException, InterruptedException {
|
|
144 |
gdalWriter.fileWrite();
|
|
145 |
}
|
|
127 |
|
|
128 |
/**
|
|
129 |
* Asigna el tipo de driver con el que se salvar? la imagen
|
|
130 |
* @param drvType Tipo de driver
|
|
131 |
*/
|
|
132 |
public void setDriverType(String drvType) {
|
|
133 |
gdalWriter.setDriverType(drvType);
|
|
134 |
}
|
|
135 |
|
|
136 |
/**
|
|
137 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
|
|
138 |
* @throws IOException
|
|
139 |
*/
|
|
140 |
public void fileWrite() throws IOException, InterruptedException {
|
|
141 |
gdalWriter.fileWrite();
|
|
142 |
}
|
|
146 | 143 |
|
147 |
/**
|
|
148 |
* Realiza una copia en el formato especificado.
|
|
149 |
* @throws IOException
|
|
150 |
*/
|
|
151 |
public static void createCopy(GdalDriver driverDst, String dst, String src,
|
|
152 |
boolean bstrict, String[] params, IProjection proj) throws IOException, GdalException {
|
|
153 |
GdalWriter.createCopy(driverDst, dst, src, bstrict, params, proj);
|
|
154 |
}
|
|
155 |
|
|
156 |
/**
|
|
157 |
* Realiza la escritura de datos con los datos que le pasa el cliente.
|
|
158 |
* @throws IOException
|
|
159 |
*/
|
|
160 |
public void dataWrite() throws IOException, InterruptedException {
|
|
161 |
if(colorInterp != null)
|
|
162 |
gdalWriter.setColorBandsInterpretation(colorInterp.getValues());
|
|
163 |
gdalWriter.dataWrite();
|
|
164 |
if(gdalWriter.isWrite()){
|
|
165 |
gdalWriter.writeClose();
|
|
166 |
if(outTif != null){
|
|
167 |
GdalDriver driver = null;
|
|
168 |
try{
|
|
169 |
driver = Gdal.getDriverByName("JPEG");
|
|
170 |
GdalWriter.createCopy(driver, outJpg, outTif, false, gdalWriter.gdalParamsFromRasterParams(driverParams), null);
|
|
171 |
}catch(GdalException exc){
|
|
172 |
throw new IOException("No se ha podido obtener el driver.");
|
|
173 |
}
|
|
174 |
File file = new File(outTif);
|
|
175 |
file.delete();
|
|
176 |
}
|
|
177 |
}
|
|
178 |
}
|
|
144 |
/**
|
|
145 |
* Realiza una copia en el formato especificado.
|
|
146 |
* @throws IOException
|
|
147 |
*/
|
|
148 |
public static void createCopy(GdalDriver driverDst, String dst, String src,
|
|
149 |
boolean bstrict, String[] params, IProjection proj) throws IOException, GdalException {
|
|
150 |
GdalWriter.createCopy(driverDst, dst, src, bstrict, params, proj);
|
|
151 |
}
|
|
152 |
|
|
153 |
/**
|
|
154 |
* Realiza la escritura de datos con los datos que le pasa el cliente.
|
|
155 |
* @throws IOException
|
|
156 |
*/
|
|
157 |
public void dataWrite() throws IOException, InterruptedException {
|
|
158 |
if(colorInterp != null)
|
|
159 |
gdalWriter.setColorBandsInterpretation(colorInterp.getValues());
|
|
160 |
gdalWriter.dataWrite();
|
|
161 |
if(gdalWriter.isWrite()){
|
|
162 |
gdalWriter.writeClose();
|
|
163 |
if(outTif != null){
|
|
164 |
GdalDriver driver = null;
|
|
165 |
try{
|
|
166 |
driver = Gdal.getDriverByName("JPEG");
|
|
167 |
GdalWriter.createCopy(driver, outJpg, outTif, false, gdalWriter.gdalParamsFromRasterParams(driverParams), null);
|
|
168 |
}catch(GdalException exc){
|
|
169 |
throw new IOException("No se ha podido obtener el driver.");
|
|
170 |
}
|
|
171 |
File file = new File(outTif);
|
|
172 |
file.delete();
|
|
173 |
}
|
|
174 |
}
|
|
175 |
}
|
|
179 | 176 |
|
180 |
/**
|
|
181 |
* Cierra el compresor ecw.
|
|
182 |
* @throws GdalException
|
|
183 |
*/
|
|
184 |
public void writeClose() {
|
|
185 |
//El close del tif se hizo en dataWrite
|
|
186 |
}
|
|
177 |
/**
|
|
178 |
* Cierra el compresor ecw.
|
|
179 |
* @throws GdalException
|
|
180 |
*/
|
|
181 |
public void writeClose() {
|
|
182 |
//El close del tif se hizo en dataWrite
|
|
183 |
}
|
|
187 | 184 |
|
188 |
/**
|
|
189 |
* Cancela el salvado de datos.
|
|
190 |
*/
|
|
191 |
public void writeCancel() {
|
|
192 |
gdalWriter.setWrite(false);
|
|
193 |
}
|
|
194 |
|
|
195 |
/*
|
|
196 |
* (non-Javadoc)
|
|
197 |
* @see org.gvsig.raster.dataset.GeoRasterWriter#setParams(org.gvsig.raster.dataset.Params)
|
|
198 |
*/
|
|
185 |
/**
|
|
186 |
* Cancela el salvado de datos.
|
|
187 |
*/
|
|
188 |
public void writeCancel() {
|
|
189 |
gdalWriter.setWrite(false);
|
|
190 |
}
|
|
191 |
|
|
192 |
/*
|
|
193 |
* (non-Javadoc)
|
|
194 |
* @see org.gvsig.raster.dataset.GeoRasterWriter#setParams(org.gvsig.raster.dataset.Params)
|
|
195 |
*/
|
|
199 | 196 |
public void setParams(Params params) { |
200 | 197 |
driverParams = params; |
201 | 198 |
if(gdalWriter != null) |
202 | 199 |
gdalWriter.setParams(params); |
203 | 200 |
} |
204 |
|
|
201 |
|
|
205 | 202 |
/* |
206 | 203 |
* (non-Javadoc) |
207 | 204 |
* @see org.gvsig.raster.dataset.GeoRasterWriter#setWkt(java.lang.String) |
Also available in: Unified diff