Revision 5751
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.legend/org.gvsig.raster.lib.legend.impl/src/test/java/org/gvsig/raster/lib/legend/impl/DefaultRasterLegendTest.java | ||
---|---|---|
4 | 4 |
import java.awt.Dimension; |
5 | 5 |
import java.awt.image.BufferedImage; |
6 | 6 |
import java.io.File; |
7 |
import java.io.IOException; |
|
7 | 8 |
import java.net.URL; |
8 | 9 |
import java.util.ArrayList; |
9 | 10 |
import java.util.Arrays; |
10 | 11 |
import java.util.List; |
11 | 12 |
|
13 |
import javax.imageio.ImageIO; |
|
14 |
|
|
12 | 15 |
import org.cresques.cts.IProjection; |
13 | 16 |
import org.gvsig.fmap.crs.CRSFactory; |
14 | 17 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
... | ... | |
107 | 110 |
viewPort.refreshExtent(); |
108 | 111 |
|
109 | 112 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null); |
113 |
|
|
114 |
try { |
|
115 |
File file = File.createTempFile("test", "png"); |
|
116 |
ImageIO.write(image, "png", file); |
|
117 |
} catch (IOException e) { |
|
118 |
// TODO Auto-generated catch block |
|
119 |
e.printStackTrace(); |
|
120 |
} |
|
121 |
|
|
110 | 122 |
} |
111 | 123 |
|
112 | 124 |
public void testDrawRGBBufferWithTransparency() { |
... | ... | |
167 | 179 |
viewPort.refreshExtent(); |
168 | 180 |
|
169 | 181 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null); |
182 |
|
|
183 |
try { |
|
184 |
File file = File.createTempFile("test", "png"); |
|
185 |
ImageIO.write(image, "png", file); |
|
186 |
} catch (IOException e) { |
|
187 |
// TODO Auto-generated catch block |
|
188 |
e.printStackTrace(); |
|
189 |
} |
|
190 |
|
|
170 | 191 |
} |
171 | 192 |
|
172 | 193 |
public void testDrawRGBBufferProjected(){ |
... | ... | |
193 | 214 |
SUBTYPES.GEOM2D)); |
194 | 215 |
bufferEnvelope.setUpperCorner(geometryManager.createPoint(654602.5, 4466602.5, |
195 | 216 |
SUBTYPES.GEOM2D)); |
196 |
envelope.setLowerCorner(geometryManager.createPoint(-1.57, 40.11, SUBTYPES.GEOM2D));
|
|
197 |
envelope.setUpperCorner(geometryManager.createPoint(-1.11, 40.37, SUBTYPES.GEOM2D));
|
|
217 |
envelope.setLowerCorner(geometryManager.createPoint(-1.58, 40.06, SUBTYPES.GEOM2D));
|
|
218 |
envelope.setUpperCorner(geometryManager.createPoint(-1.12, 40.45, SUBTYPES.GEOM2D));
|
|
198 | 219 |
} catch (CreateGeometryException e) { |
199 | 220 |
fail("Can create point to set envelope"); |
200 | 221 |
} |
... | ... | |
234 | 255 |
viewPort.refreshExtent(); |
235 | 256 |
|
236 | 257 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null); |
258 |
|
|
259 |
try { |
|
260 |
File file = File.createTempFile("test", "png"); |
|
261 |
ImageIO.write(image, "png", file); |
|
262 |
} catch (IOException e) { |
|
263 |
// TODO Auto-generated catch block |
|
264 |
e.printStackTrace(); |
|
265 |
} |
|
266 |
|
|
237 | 267 |
} |
268 |
|
|
269 |
public void testDrawRGBBufferProjected2(){ |
|
270 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
|
238 | 271 |
|
272 |
int[] bandDataTypes = |
|
273 |
new int[] { BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE}; |
|
274 |
|
|
275 |
NoData[] bandNodata = new NoData[6]; |
|
276 |
Arrays.fill(bandNodata, |
|
277 |
BufferLocator.getBufferManager().createNoData(noDataValue, defaultNoDataValue)); |
|
278 |
|
|
279 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
280 |
Envelope envelope = null; |
|
281 |
Envelope bufferEnvelope = null; |
|
282 |
try { |
|
283 |
bufferEnvelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
|
284 |
envelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
|
285 |
} catch (CreateEnvelopeException e) { |
|
286 |
fail("Can create envelope of buffer"); |
|
287 |
} |
|
288 |
try { |
|
289 |
bufferEnvelope.setLowerCorner(geometryManager.createPoint(625397.5, 4446997.5, |
|
290 |
SUBTYPES.GEOM2D)); |
|
291 |
bufferEnvelope.setUpperCorner(geometryManager.createPoint(654602.5, 4466602.5, |
|
292 |
SUBTYPES.GEOM2D)); |
|
293 |
envelope.setLowerCorner(geometryManager.createPoint(-1.29, 40.089, SUBTYPES.GEOM2D)); |
|
294 |
envelope.setUpperCorner(geometryManager.createPoint(-0.95, 40.43, SUBTYPES.GEOM2D)); |
|
295 |
} catch (CreateGeometryException e) { |
|
296 |
fail("Can create point to set envelope"); |
|
297 |
} |
|
298 |
|
|
299 |
Buffer buffer = null; |
|
300 |
IProjection epsg25830 = CRSFactory.getCRS("EPSG:25830"); |
|
301 |
try { |
|
302 |
byte[] byteData = new byte[1000]; |
|
303 |
for(int i = 0; i < 1000; i++){ |
|
304 |
byteData[i] = (byte) (i * 255 / 1000); |
|
305 |
} |
|
306 |
|
|
307 |
buffer = |
|
308 |
bufferManager.createBuffer(1000, 1000, bandDataTypes, bandNodata, epsg25830, bufferEnvelope); |
|
309 |
|
|
310 |
for (int i = 0; i < 1000; i++) { |
|
311 |
buffer.getBand(0).putRow(i, byteData); |
|
312 |
buffer.getBand(1).putRow(i, byteData); |
|
313 |
buffer.getBand(2).putRow(i, byteData); |
|
314 |
} |
|
315 |
|
|
316 |
} catch (BufferException e) { |
|
317 |
fail("Error creating buffer"); |
|
318 |
} |
|
319 |
|
|
320 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
|
321 |
ColorInterpretation colorInterpretation = |
|
322 |
rasterLegendManager.createColorInterpretation(ColorInterpretation.RGB); |
|
323 |
rasterLegend = |
|
324 |
rasterLegendManager.createLegend(colorInterpretation, null, null, null); |
|
325 |
|
|
326 |
BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB); |
|
327 |
IProjection epsg4326 = CRSFactory.getCRS("EPSG:4326"); |
|
328 |
ViewPort viewPort = new ViewPort(epsg4326); |
|
329 |
viewPort.setEnvelope(envelope); |
|
330 |
viewPort.setImageSize(new Dimension(500, 500)); |
|
331 |
viewPort.refreshExtent(); |
|
332 |
|
|
333 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null); |
|
334 |
|
|
335 |
try { |
|
336 |
File file = File.createTempFile("test", "png"); |
|
337 |
ImageIO.write(image, "png", file); |
|
338 |
} catch (IOException e) { |
|
339 |
// TODO Auto-generated catch block |
|
340 |
e.printStackTrace(); |
|
341 |
} |
|
342 |
|
|
343 |
} |
|
344 |
|
|
345 |
public void testDrawRGBBufferProjected3(){ |
|
346 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
|
347 |
|
|
348 |
int[] bandDataTypes = |
|
349 |
new int[] { BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE, BufferManager.TYPE_BYTE}; |
|
350 |
|
|
351 |
NoData[] bandNodata = new NoData[6]; |
|
352 |
Arrays.fill(bandNodata, |
|
353 |
BufferLocator.getBufferManager().createNoData(noDataValue, defaultNoDataValue)); |
|
354 |
|
|
355 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
356 |
Envelope envelope = null; |
|
357 |
Envelope bufferEnvelope = null; |
|
358 |
try { |
|
359 |
bufferEnvelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
|
360 |
envelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
|
361 |
} catch (CreateEnvelopeException e) { |
|
362 |
fail("Can create envelope of buffer"); |
|
363 |
} |
|
364 |
try { |
|
365 |
bufferEnvelope.setLowerCorner(geometryManager.createPoint(625397.5, 4446997.5, |
|
366 |
SUBTYPES.GEOM2D)); |
|
367 |
bufferEnvelope.setUpperCorner(geometryManager.createPoint(654602.5, 4466602.5, |
|
368 |
SUBTYPES.GEOM2D)); |
|
369 |
envelope.setLowerCorner(geometryManager.createPoint(-1.38, 40.19, SUBTYPES.GEOM2D)); |
|
370 |
envelope.setUpperCorner(geometryManager.createPoint(-1.27, 40.29, SUBTYPES.GEOM2D)); |
|
371 |
} catch (CreateGeometryException e) { |
|
372 |
fail("Can create point to set envelope"); |
|
373 |
} |
|
374 |
|
|
375 |
Buffer buffer = null; |
|
376 |
IProjection epsg25830 = CRSFactory.getCRS("EPSG:25830"); |
|
377 |
try { |
|
378 |
byte[] byteData = new byte[1000]; |
|
379 |
for(int i = 0; i < 1000; i++){ |
|
380 |
byteData[i] = (byte) (i * 255 / 1000); |
|
381 |
} |
|
382 |
|
|
383 |
buffer = |
|
384 |
bufferManager.createBuffer(1000, 1000, bandDataTypes, bandNodata, epsg25830, bufferEnvelope); |
|
385 |
|
|
386 |
for (int i = 0; i < 1000; i++) { |
|
387 |
buffer.getBand(0).putRow(i, byteData); |
|
388 |
buffer.getBand(1).putRow(i, byteData); |
|
389 |
buffer.getBand(2).putRow(i, byteData); |
|
390 |
} |
|
391 |
|
|
392 |
} catch (BufferException e) { |
|
393 |
fail("Error creating buffer"); |
|
394 |
} |
|
395 |
|
|
396 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
|
397 |
ColorInterpretation colorInterpretation = |
|
398 |
rasterLegendManager.createColorInterpretation(ColorInterpretation.RGB); |
|
399 |
rasterLegend = |
|
400 |
rasterLegendManager.createLegend(colorInterpretation, null, null, null); |
|
401 |
|
|
402 |
BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB); |
|
403 |
IProjection epsg4326 = CRSFactory.getCRS("EPSG:4326"); |
|
404 |
ViewPort viewPort = new ViewPort(epsg4326); |
|
405 |
viewPort.setEnvelope(envelope); |
|
406 |
viewPort.setImageSize(new Dimension(500, 500)); |
|
407 |
viewPort.refreshExtent(); |
|
408 |
|
|
409 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null); |
|
410 |
|
|
411 |
try { |
|
412 |
File file = File.createTempFile("test", "png"); |
|
413 |
ImageIO.write(image, "png", file); |
|
414 |
} catch (IOException e) { |
|
415 |
// TODO Auto-generated catch block |
|
416 |
e.printStackTrace(); |
|
417 |
} |
|
418 |
|
|
419 |
} |
|
420 |
|
|
239 | 421 |
public void testDrawARGBBuffer() { |
240 | 422 |
|
241 | 423 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
... | ... | |
302 | 484 |
viewPort.refreshExtent(); |
303 | 485 |
|
304 | 486 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null); |
487 |
|
|
488 |
|
|
489 |
try { |
|
490 |
File file = File.createTempFile("test", "png"); |
|
491 |
ImageIO.write(image, "png", file); |
|
492 |
} catch (IOException e) { |
|
493 |
// TODO Auto-generated catch block |
|
494 |
e.printStackTrace(); |
|
495 |
} |
|
496 |
|
|
305 | 497 |
} |
306 | 498 |
|
307 | 499 |
public void testDrawGreyBuffer() { |
... | ... | |
376 | 568 |
viewPort.refreshExtent(); |
377 | 569 |
|
378 | 570 |
rasterLegend.draw(image.getGraphics(), buffer, viewPort, null); |
571 |
|
|
572 |
try { |
|
573 |
File file = File.createTempFile("test", "png"); |
|
574 |
ImageIO.write(image, "png", file); |
|
575 |
} catch (IOException e) { |
|
576 |
// TODO Auto-generated catch block |
|
577 |
e.printStackTrace(); |
|
578 |
} |
|
379 | 579 |
} |
380 | 580 |
|
381 | 581 |
public void testGetColorTable() { |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.legend/org.gvsig.raster.lib.legend.impl/src/main/java/org/gvsig/raster/lib/legend/impl/DefaultRasterLegend.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.awt.Graphics; |
4 | 4 |
import java.awt.Image; |
5 |
import java.awt.geom.Point2D; |
|
5 |
import java.awt.geom.AffineTransform; |
|
6 |
import java.awt.geom.NoninvertibleTransformException; |
|
6 | 7 |
import java.awt.image.BufferedImage; |
7 | 8 |
|
8 | 9 |
import org.cresques.cts.ICoordTrans; |
10 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
11 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
12 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
9 | 13 |
import org.gvsig.fmap.geom.primitive.Envelope; |
14 |
import org.gvsig.fmap.geom.primitive.Point; |
|
10 | 15 |
import org.gvsig.fmap.mapcontext.ViewPort; |
11 | 16 |
import org.gvsig.raster.lib.buffer.api.Band; |
12 | 17 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
... | ... | |
27 | 32 |
import org.slf4j.LoggerFactory; |
28 | 33 |
|
29 | 34 |
/** |
35 |
* Default implementation of {@link RasterLegend}. This object can draw buffers |
|
36 |
* with a {@link ColorInterpretation}, {@link ColorTable} and {@link FilterList} |
|
37 |
* |
|
38 |
* |
|
30 | 39 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
31 | 40 |
* |
32 | 41 |
*/ |
... | ... | |
109 | 118 |
|
110 | 119 |
if (this.colorInterpretation == null || !this.colorInterpretation.hasInterpretation() |
111 | 120 |
|| this.colorInterpretation.isUndefined()) { |
121 |
taskStatus.abort(); |
|
112 | 122 |
throw new IllegalStateException( |
113 | 123 |
"To draw buffer, raster legend has to have a color interpretation"); |
114 | 124 |
} |
115 | 125 |
|
116 | 126 |
if ((this.colorInterpretation.isRGB() || this.colorInterpretation.isBGR() || this.colorInterpretation |
117 | 127 |
.isRGBA()) && this.colorTable != null) { |
128 |
taskStatus.abort(); |
|
118 | 129 |
throw new IllegalStateException( |
119 | 130 |
"If color interpretation is RGB, RGBA or BGR, raster legend can not have a color table"); |
120 | 131 |
} |
121 | 132 |
|
122 | 133 |
// Check if viewport projection is the same as buffer projection |
134 |
Buffer bufferToDraw = null; |
|
123 | 135 |
if (!viewPort.getProjection().equals(buffer.getProjection())) { |
124 | 136 |
|
125 | 137 |
// Convert extension to check if envelopes intersect |
126 | 138 |
ICoordTrans coordTrans = viewPort.getProjection().getCT(buffer.getProjection()); |
127 |
Envelope convertedViewportEnvelope = viewPort.getEnvelope().convert(coordTrans);
|
|
128 |
if (!convertedViewportEnvelope.intersects(buffer.getEnvelope())) {
|
|
139 |
Envelope convertedEnvelope = viewPort.getEnvelope().convert(coordTrans); |
|
140 |
if (!convertedEnvelope.intersects(buffer.getEnvelope())) { |
|
129 | 141 |
return; |
130 |
} else { |
|
131 |
try { |
|
132 |
buffer = buffer.convert(coordTrans.getInverted(), taskStatus); |
|
133 |
} catch (BufferException e) { |
|
134 |
LOG.warn("Buffer can not be converted to {}", coordTrans.getInverted() |
|
135 |
.getPOrig().getAbrev()); |
|
136 |
return; |
|
137 |
} |
|
138 | 142 |
} |
143 |
try { |
|
144 |
// Clip buffer with doubled converted envelope |
|
145 |
bufferToDraw = buffer.clip(convertedEnvelope); |
|
139 | 146 |
|
140 |
} else if (!viewPort.getEnvelope().intersects(buffer.getEnvelope())) { |
|
141 |
return; |
|
142 |
} |
|
147 |
// Convert interpolated clipped buffer |
|
148 |
bufferToDraw = bufferToDraw.convert(coordTrans.getInverted(), taskStatus); |
|
143 | 149 |
|
144 |
double dist1pixel = viewPort.getDist1pixel(); |
|
145 |
Envelope envelope = buffer.getEnvelope(); |
|
146 |
double widthEnvelope = envelope.getLength(0); |
|
147 |
double heigthEnvelope = envelope.getLength(1); |
|
150 |
double widthPixel = |
|
151 |
getWidthPixel(bufferToDraw.getEnvelope(), viewPort.getEnvelope().getLength(0) |
|
152 |
/ viewPort.getImageWidth()); |
|
153 |
double heightPixel = |
|
154 |
getHeightPixel(bufferToDraw.getEnvelope(), viewPort.getEnvelope().getLength(1) |
|
155 |
/ viewPort.getImageWidth()); |
|
148 | 156 |
|
149 |
double widthPixel = widthEnvelope / dist1pixel; |
|
150 |
double heightPixel = heigthEnvelope / dist1pixel; |
|
157 |
bufferToDraw = |
|
158 |
bufferToDraw.createInterpolated((int) Math.floor(heightPixel), |
|
159 |
(int) Math.floor(widthPixel), Buffer.INTERPOLATION_BicubicSpline, |
|
160 |
taskStatus); |
|
151 | 161 |
|
152 |
Buffer interpolatedClippedBuffer = null; |
|
153 |
try { |
|
154 |
interpolatedClippedBuffer = buffer.clip(viewPort.getEnvelope()); |
|
155 |
interpolatedClippedBuffer = |
|
156 |
interpolatedClippedBuffer |
|
157 |
.createInterpolated((int) Math.floor(heightPixel), |
|
162 |
} catch (BufferException e) { |
|
163 |
LOG.warn("Buffer can not be clipped, converted or interpolated", e); |
|
164 |
taskStatus.abort(); |
|
165 |
return; |
|
166 |
} |
|
167 |
} else if (viewPort.getEnvelope().intersects(buffer.getEnvelope())) { |
|
168 |
|
|
169 |
double widthPixel = 0; |
|
170 |
double heightPixel = 0; |
|
171 |
try { |
|
172 |
// Clip and interpolate buffer with view port envelope |
|
173 |
bufferToDraw = buffer.clip(viewPort.getEnvelope()); |
|
174 |
widthPixel = |
|
175 |
getWidthPixel(bufferToDraw.getEnvelope(), viewPort.getEnvelope().getLength(0) |
|
176 |
/ viewPort.getImageWidth()); |
|
177 |
heightPixel = |
|
178 |
getHeightPixel(bufferToDraw.getEnvelope(), viewPort.getEnvelope().getLength(1) |
|
179 |
/ viewPort.getImageWidth()); |
|
180 |
|
|
181 |
bufferToDraw = |
|
182 |
bufferToDraw.createInterpolated((int) Math.floor(heightPixel), |
|
158 | 183 |
(int) Math.floor(widthPixel), Buffer.INTERPOLATION_NearestNeighbour, |
159 | 184 |
taskStatus); |
160 |
} catch (BufferException e) { |
|
161 |
LOG.warn( |
|
162 |
"Buffer can not be interpolated with [rows: {} , columns: {}, method: {}", |
|
163 |
new String[] { String.valueOf((int) Math.floor(heightPixel)), |
|
164 |
String.valueOf((int) Math.floor(widthPixel)), |
|
165 |
String.valueOf(Buffer.INTERPOLATION_NearestNeighbour) }); |
|
185 |
} catch (BufferException e) { |
|
186 |
LOG.warn( |
|
187 |
"Buffer can not be interpolated with [rows: {} , columns: {}, method: {}]", |
|
188 |
new String[] { String.valueOf((int) Math.floor(heightPixel)), |
|
189 |
String.valueOf((int) Math.floor(widthPixel)), |
|
190 |
String.valueOf(Buffer.INTERPOLATION_NearestNeighbour) }); |
|
191 |
taskStatus.abort(); |
|
192 |
return; |
|
193 |
} |
|
194 |
} else { |
|
195 |
// Do nothing view port envelope does not intersect with buffer |
|
166 | 196 |
return; |
167 | 197 |
} |
168 | 198 |
|
199 |
// Draw buffer |
|
169 | 200 |
Image image = null; |
170 | 201 |
if (this.colorInterpretation.isGray() && this.colorTable != null) { |
171 | 202 |
|
172 | 203 |
// Draw buffer with table color |
173 |
image = |
|
174 |
drawBuffer(graphics, interpolatedClippedBuffer, colorTable, transparency, filters); |
|
204 |
image = drawBuffer(graphics, bufferToDraw, colorTable, transparency, filters); |
|
175 | 205 |
|
176 | 206 |
} else if (this.colorInterpretation.isRGBA() || this.colorInterpretation.isRGB() |
177 | 207 |
|| this.colorInterpretation.isBGR()) { |
178 | 208 |
|
179 | 209 |
// Draw RGB, RGBA or BGR buffer without color table |
180 |
image = |
|
181 |
drawBuffer(graphics, interpolatedClippedBuffer, colorInterpretation, transparency, |
|
182 |
filters); |
|
210 |
image = drawBuffer(graphics, bufferToDraw, colorInterpretation, transparency, filters); |
|
211 |
} |
|
183 | 212 |
|
184 |
} |
|
213 |
// Calculate where image has to be drawn |
|
214 |
double x = bufferToDraw.getEnvelope().getMinimum(0); |
|
215 |
double y = bufferToDraw.getEnvelope().getMaximum(1); |
|
216 |
AffineTransform affineTransform = |
|
217 |
calculateAffineTransform(viewPort.getEnvelope(), viewPort.getImageWidth(), |
|
218 |
viewPort.getImageHeight()); |
|
185 | 219 |
|
186 |
double x = buffer.getEnvelope().getMinimum(0); |
|
187 |
double y = buffer.getEnvelope().getMaximum(1); |
|
220 |
Point point; |
|
221 |
try { |
|
222 |
point = GeometryLocator.getGeometryManager().createPoint(x, y, SUBTYPES.GEOM2D); |
|
223 |
point.transform(affineTransform.createInverse()); |
|
224 |
graphics.drawImage(image, (int) Math.floor(point.getX()), |
|
225 |
(int) Math.floor(point.getY()), null); |
|
226 |
} catch (CreateGeometryException | NoninvertibleTransformException e) { |
|
227 |
LOG.warn("Can not calculate the point of buffer in viewport image", e); |
|
228 |
taskStatus.abort(); |
|
229 |
return; |
|
230 |
} |
|
188 | 231 |
|
189 |
Point2D pixelPoint = viewPort.fromMapPoint(x, y); |
|
190 |
graphics.drawImage(image, (int) Math.floor(pixelPoint.getX()), |
|
191 |
(int) Math.floor(pixelPoint.getY()), null); |
|
192 |
|
|
193 | 232 |
if (!isMyTask) { |
194 | 233 |
taskStatus.pop(); |
195 | 234 |
} |
196 | 235 |
} |
197 | 236 |
|
237 |
private AffineTransform calculateAffineTransform(Envelope envelope, double imageWidth, |
|
238 |
double imageHeight) { |
|
239 |
double pixelSizeX = envelope.getLength(0) / imageWidth; |
|
240 |
double rotationX = 0; |
|
241 |
double x = envelope.getMinimum(0); |
|
242 |
double rotationY = 0; |
|
243 |
double pixelSizeY = -envelope.getLength(1) / imageHeight; |
|
244 |
double y = envelope.getMaximum(1); |
|
245 |
return new AffineTransform(pixelSizeX, rotationY, rotationX, pixelSizeY, x, y); |
|
246 |
} |
|
247 |
|
|
248 |
private double getWidthPixel(Envelope envelope, double dist1pixel) { |
|
249 |
double widthEnvelope = envelope.getLength(0); |
|
250 |
return widthEnvelope / dist1pixel; |
|
251 |
} |
|
252 |
|
|
253 |
private double getHeightPixel(Envelope envelope, double dist1pixel) { |
|
254 |
double heightEnvelope = envelope.getLength(1); |
|
255 |
return heightEnvelope / dist1pixel; |
|
256 |
} |
|
257 |
|
|
198 | 258 |
private Image drawBuffer(Graphics graphics, Buffer buffer, |
199 | 259 |
ColorInterpretation colorInterpretation, Transparency transparency, FilterList filters) { |
200 | 260 |
|
... | ... | |
264 | 324 |
((greenValue.byteValue() & 0xFF) << 8) | // green |
265 | 325 |
((blueValue.byteValue() & 0xFF) << 0); // blue |
266 | 326 |
} else if (colorInterpretation.isBGR()) { |
267 |
intRGB = ((blueValue.byteValue() & 0xFF) << 16 | // blue
|
|
327 |
intRGB = ((blueValue.byteValue() & 0xFF) << 16 | // blue |
|
268 | 328 |
((greenValue.byteValue() & 0xFF) << 8) | // green |
269 | 329 |
((redValue.byteValue() & 0xFF) << 0)); // red |
270 |
|
|
330 |
|
|
271 | 331 |
} |
272 | 332 |
image.setRGB(j, i, intRGB); |
273 | 333 |
} |
Also available in: Unified diff