Revision 8682 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
DefaultRasterLegend.java | ||
---|---|---|
6 | 6 |
import java.awt.geom.NoninvertibleTransformException; |
7 | 7 |
import java.awt.image.BufferedImage; |
8 | 8 |
import java.util.ArrayList; |
9 |
import java.util.Iterator; |
|
9 | 10 |
import java.util.List; |
10 | 11 |
|
11 | 12 |
import org.cresques.cts.ICoordTrans; |
12 | 13 |
import org.slf4j.Logger; |
13 | 14 |
import org.slf4j.LoggerFactory; |
14 | 15 |
|
16 |
import org.gvsig.fmap.dal.DALLocator; |
|
17 |
import org.gvsig.fmap.dal.DataStore; |
|
18 |
import org.gvsig.fmap.dal.raster.api.RasterStore; |
|
15 | 19 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
16 | 20 |
import org.gvsig.fmap.geom.GeometryLocator; |
17 | 21 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
... | ... | |
33 | 37 |
import org.gvsig.raster.lib.buffer.api.BufferLocator; |
34 | 38 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
35 | 39 |
import org.gvsig.raster.lib.buffer.api.NoData; |
40 |
import org.gvsig.raster.lib.buffer.api.OperationManager; |
|
36 | 41 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferException; |
37 | 42 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException; |
38 | 43 |
import org.gvsig.raster.lib.buffer.api.operations.Operation; |
39 | 44 |
import org.gvsig.raster.lib.buffer.api.operations.OperationList; |
40 |
import org.gvsig.raster.lib.buffer.impl.operations.linearstretchenhancement.LinearStretchEnhancementOperation; |
|
41 |
import org.gvsig.raster.lib.buffer.spi.OperationListManager; |
|
45 |
import org.gvsig.raster.lib.buffer.api.operations.OperationListEntry; |
|
46 |
import org.gvsig.raster.lib.buffer.api.operations.SpecifiedBandsOperation; |
|
47 |
import org.gvsig.raster.lib.buffer.spi.operations.AbstractOperation; |
|
48 |
import org.gvsig.raster.lib.buffer.spi.operations.AbstractSpecifiedBandsOperation; |
|
42 | 49 |
import org.gvsig.raster.lib.legend.api.RasterLegend; |
43 | 50 |
import org.gvsig.raster.lib.legend.api.Transparency; |
44 | 51 |
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation; |
45 | 52 |
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretationNotification; |
46 | 53 |
import org.gvsig.raster.lib.legend.api.colortable.ColorTable; |
54 |
import org.gvsig.raster.lib.legend.api.operations.ColoredOperation; |
|
47 | 55 |
import org.gvsig.raster.lib.legend.impl.operations.cmyktorgb.CMYKToRGBOperation; |
48 | 56 |
import org.gvsig.raster.lib.legend.impl.operations.cmyktorgb.CMYKToRGBOperationFactory; |
49 | 57 |
import org.gvsig.raster.lib.legend.impl.operations.colortable.ColorTableOperation; |
... | ... | |
52 | 60 |
import org.gvsig.raster.lib.legend.impl.operations.hsltorgb.HSLToRGBOperationFactory; |
53 | 61 |
import org.gvsig.tools.ToolsLocator; |
54 | 62 |
import org.gvsig.tools.dispose.DisposeUtils; |
63 |
import org.gvsig.tools.dynobject.DynClass; |
|
55 | 64 |
import org.gvsig.tools.dynobject.DynObject; |
65 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
56 | 66 |
import org.gvsig.tools.dynobject.DynStruct; |
67 |
import org.gvsig.tools.dynobject.impl.DefaultDynObjectManager; |
|
57 | 68 |
import org.gvsig.tools.locator.LocatorException; |
58 | 69 |
import org.gvsig.tools.observer.Observable; |
59 | 70 |
import org.gvsig.tools.operations.OperationException; |
60 | 71 |
import org.gvsig.tools.persistence.PersistenceManager; |
72 |
import org.gvsig.tools.persistence.Persistent; |
|
61 | 73 |
import org.gvsig.tools.persistence.PersistentState; |
62 | 74 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
63 | 75 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
... | ... | |
243 | 255 |
} |
244 | 256 |
} |
245 | 257 |
|
246 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
|
258 |
OperationManager operationManager = BufferLocator.getOperationManager(); |
|
259 |
|
|
247 | 260 |
if (bufferToDraw != null && bufferToDraw.getColumns()>0 && bufferToDraw.getRows()>0) { |
248 | 261 |
|
249 | 262 |
// Draw buffer |
250 | 263 |
Image image = null; |
251 | 264 |
try { |
265 |
DynObjectManager dynObjectManager = new DefaultDynObjectManager(); |
|
266 |
DynClass parametersClass = dynObjectManager.createDynClass("Parameters", "Parameters to find through ultimately."); |
|
267 |
parametersClass.addDynFieldObject(ColoredOperation.OUTPUT_COLOR_INTERPRETATION_PARAM); |
|
268 |
DynObject defaultParameters = dynObjectManager.createDynObject(parametersClass); |
|
269 |
defaultParameters.setDynValue(ColoredOperation.OUTPUT_COLOR_INTERPRETATION_PARAM, colorInterpretation); |
|
270 |
|
|
271 |
getFilters().setDefaultParameters(defaultParameters); |
|
272 |
|
|
252 | 273 |
Object oColorInterpretation = null; |
253 | 274 |
Buffer filteredBuffer = bufferToDraw; |
254 | 275 |
filteredBuffer = getFilters().execute(bufferToDraw); |
255 |
oColorInterpretation = getFilters().getThrownDynValue(ColorTableOperation.OUTPUT_COLOR_INTERPRETATION_PARAM);
|
|
276 |
oColorInterpretation = getFilters().getParameterValue(ColoredOperation.OUTPUT_COLOR_INTERPRETATION_PARAM);
|
|
256 | 277 |
ColorInterpretation colorInterpretationAfterFilters = null; |
257 | 278 |
if (oColorInterpretation != null) { |
258 | 279 |
colorInterpretationAfterFilters = (ColorInterpretation) oColorInterpretation; |
... | ... | |
263 | 284 |
|
264 | 285 |
if (colorInterpretationAfterFilters.isPalette()) { |
265 | 286 |
DynObject colorTableOperationParameters = |
266 |
bufferManager.createOperationParameters(ColorTableOperationFactory.NAME);
|
|
267 |
colorTableOperationParameters.setDynValue(ColorTableOperation.COLOR_INTERPRETATION_PARAM,
|
|
287 |
operationManager.createOperationParameters(ColoredOperation.COLOR_TABLE_OPERATION_NAME);
|
|
288 |
colorTableOperationParameters.setDynValue(ColoredOperation.COLOR_INTERPRETATION_PARAM,
|
|
268 | 289 |
colorInterpretationAfterFilters); |
269 |
colorTableOperationParameters.setDynValue(ColorTableOperation.COPY_UNPROCESSED_BANDS_PARAM,
|
|
270 |
true); |
|
290 |
// colorTableOperationParameters.setDynValue(ColoredOperation.COPY_UNPROCESSED_BANDS_PARAM,
|
|
291 |
// true);
|
|
271 | 292 |
Buffer rgbBuffer = |
272 |
bufferManager.execute(ColorTableOperationFactory.NAME, filteredBuffer,
|
|
293 |
operationManager.execute(ColoredOperation.COLOR_TABLE_OPERATION_NAME, filteredBuffer,
|
|
273 | 294 |
colorTableOperationParameters); |
274 | 295 |
image = |
275 | 296 |
drawRGBBuffer(graphics, rgbBuffer, |
276 | 297 |
(ColorInterpretation) colorTableOperationParameters |
277 |
.getDynValue(ColorTableOperation.OUTPUT_COLOR_INTERPRETATION_PARAM), transparency,
|
|
298 |
.getDynValue(ColoredOperation.OUTPUT_COLOR_INTERPRETATION_PARAM), transparency,
|
|
278 | 299 |
getFilters()); |
279 | 300 |
|
280 | 301 |
} else if (colorInterpretationAfterFilters.hasAnyGrayBand()) { |
281 | 302 |
// Draw buffer with gray scale |
282 |
image = drawGrayBuffer(graphics, bufferToDraw, transparency, filters);
|
|
303 |
image = drawGrayBuffer(graphics, filteredBuffer, colorInterpretationAfterFilters, transparency, filters);
|
|
283 | 304 |
// } else if (this.colorInterpretation.isRGBA() || |
284 | 305 |
// this.colorInterpretation.isRGB() |
285 | 306 |
// || this.colorInterpretation.isBGR() || |
... | ... | |
295 | 316 |
// colorInterpretation, transparency, filters); |
296 | 317 |
|
297 | 318 |
DynObject hSLToRGBOperationParameters = |
298 |
bufferManager.createOperationParameters(HSLToRGBOperationFactory.NAME);
|
|
299 |
hSLToRGBOperationParameters.setDynValue(HSLToRGBOperation.COLOR_INTERPRETATION_PARAM,
|
|
319 |
operationManager.createOperationParameters(HSLToRGBOperationFactory.NAME);
|
|
320 |
hSLToRGBOperationParameters.setDynValue(ColoredOperation.COLOR_INTERPRETATION_PARAM,
|
|
300 | 321 |
colorInterpretationAfterFilters); |
301 |
hSLToRGBOperationParameters.setDynValue(HSLToRGBOperation.COPY_UNPROCESSED_BANDS_PARAM, true);
|
|
322 |
// hSLToRGBOperationParameters.setDynValue(ColoredOperation.COPY_UNPROCESSED_BANDS_PARAM, true);
|
|
302 | 323 |
Buffer rgbBuffer = |
303 |
bufferManager.execute(ColorTableOperationFactory.NAME, filteredBuffer,
|
|
324 |
operationManager.execute(HSLToRGBOperationFactory.NAME, filteredBuffer,
|
|
304 | 325 |
hSLToRGBOperationParameters); |
305 | 326 |
image = |
306 | 327 |
drawRGBBuffer(graphics, rgbBuffer, |
307 | 328 |
(ColorInterpretation) hSLToRGBOperationParameters |
308 |
.getDynValue(ColorTableOperation.OUTPUT_COLOR_INTERPRETATION_PARAM), transparency,
|
|
329 |
.getDynValue(ColoredOperation.OUTPUT_COLOR_INTERPRETATION_PARAM), transparency,
|
|
309 | 330 |
filters); |
310 | 331 |
|
311 | 332 |
} else if (colorInterpretationAfterFilters.hasAnyCMYKBand()) { |
312 | 333 |
// Draw CMYK buffer without color table |
313 |
image = drawCMYKBuffer(graphics, bufferToDraw, colorInterpretation, transparency, filters);
|
|
334 |
// image = drawCMYKBuffer(graphics, filteredBuffer, colorInterpretationAfterFilters, transparency, filters);
|
|
314 | 335 |
|
315 | 336 |
DynObject cmykToRGBOperationParameters = |
316 |
bufferManager.createOperationParameters(CMYKToRGBOperationFactory.NAME);
|
|
317 |
cmykToRGBOperationParameters.setDynValue(CMYKToRGBOperation.COLOR_INTERPRETATION_PARAM,
|
|
337 |
operationManager.createOperationParameters(CMYKToRGBOperationFactory.NAME);
|
|
338 |
cmykToRGBOperationParameters.setDynValue(ColoredOperation.COLOR_INTERPRETATION_PARAM,
|
|
318 | 339 |
colorInterpretationAfterFilters); |
319 |
cmykToRGBOperationParameters.setDynValue(CMYKToRGBOperation.COPY_UNPROCESSED_BANDS_PARAM, true); |
|
340 |
// cmykToRGBOperationParameters.setDynValue(CMYKToRGBOperation.COPY_UNPROCESSED_BANDS_PARAM, true);
|
|
320 | 341 |
Buffer rgbBuffer = |
321 |
bufferManager.execute(ColorTableOperationFactory.NAME, filteredBuffer,
|
|
342 |
operationManager.execute(CMYKToRGBOperationFactory.NAME, filteredBuffer,
|
|
322 | 343 |
cmykToRGBOperationParameters); |
323 | 344 |
image = |
324 | 345 |
drawRGBBuffer(graphics, rgbBuffer, |
325 | 346 |
(ColorInterpretation) cmykToRGBOperationParameters |
326 |
.getDynValue(ColorTableOperation.OUTPUT_COLOR_INTERPRETATION_PARAM), transparency,
|
|
347 |
.getDynValue(ColoredOperation.OUTPUT_COLOR_INTERPRETATION_PARAM), transparency,
|
|
327 | 348 |
filters); |
328 | 349 |
|
329 | 350 |
} else if (colorInterpretationAfterFilters.hasAnyYCBCRBand()) { |
... | ... | |
418 | 439 |
Buffer byteBuffer = convertToByteBuffer(buffer); |
419 | 440 |
Buffer bufferToDraw = byteBuffer; |
420 | 441 |
|
421 |
// //Pruebas de filtros |
|
422 |
// |
|
423 |
// BufferManager bufferManager = BufferLocator.getBufferManager(); |
|
424 |
// DynObject parameters = bufferManager.createOperationParameters("RGBToHSL"); |
|
425 |
// parameters.setDynValue(RGBToHSLOperation.COLOR_INTERPRETATION_PARAM, colorInterpretation); |
|
426 |
// |
|
427 |
//// parameters.setDynValue(ColorBalanceHSLOperation.LIGHTNESS_PARAM, 50); |
|
428 |
//// parameters.setDynValue(ColorBalanceHSLOperation.SATURATION_PARAM, 25); |
|
429 |
//// parameters.setDynValue(FirstDerivativeOperation.UMBRAL_PARAM, 0); |
|
430 |
//// double customK[][] = {{-1,-1,-1},{-1,9,-1},{-1,-1,-1}}; |
|
431 |
//// Kernel customKernel = bufferManager.createKernel(customK); |
|
432 |
//// parameters.setDynValue(ConvolutionOperation.OPERATOR_PARAM, ConvolutionOperation.CUSTOM_OPERATOR_STRING); |
|
433 |
//// parameters.setDynValue(ConvolutionOperation.CUSTOM_KERNEL_PARAM, customKernel); |
|
434 |
//// parameters.setDynValue(FirstDerivativeOperation.COMPARE_PARAM, true); |
|
435 |
// try { |
|
436 |
// Buffer tempBuffer = bufferManager.execute("RGBToHSL", byteBuffer, parameters); |
|
437 |
// ColorInterpretation outputColorInterpretation = (ColorInterpretation) parameters.getDynValue(RGBToHSLOperation.OUTPUT_COLOR_INTERPRETATION_PARAM); |
|
438 |
// |
|
439 |
//// return drawHSLBuffer(graphics, tempBuffer, outputColorInterpretation, transparency, filters); |
|
440 |
// |
|
441 |
//// bufferToDraw = tempBuffer; |
|
442 |
// |
|
443 |
// DynObject parameters2 = bufferManager.createOperationParameters("HSLToRGB"); |
|
444 |
// parameters2.setDynValue(HSLToRGBOperation.COLOR_INTERPRETATION_PARAM, outputColorInterpretation); |
|
445 |
// bufferToDraw = bufferManager.execute("HSLToRGB", tempBuffer, parameters2); |
|
446 |
// colorInterpretation = (ColorInterpretation) parameters2.getDynValue(HSLToRGBOperation.OUTPUT_COLOR_INTERPRETATION_PARAM); |
|
447 |
// |
|
448 |
// } catch (BufferOperationException e) { |
|
449 |
// // TODO Auto-generated catch block |
|
450 |
// e.printStackTrace(); |
|
451 |
// } |
|
452 |
// |
|
453 |
// |
|
454 |
// //Fin de pruebas de filtros |
|
455 |
|
|
456 | 442 |
BufferedImage image = null; |
457 | 443 |
|
458 | 444 |
if (colorInterpretation.isRGB() || colorInterpretation.isRGBA() || colorInterpretation.hasAnyRGBBand()) { |
... | ... | |
517 | 503 |
NoData noData = greenBand.getNoData(); |
518 | 504 |
if(noData != null){ |
519 | 505 |
if(greenValue.equals(noData.getValue())){ |
520 |
alphaByteValue = 0; |
|
506 |
alphaByteValue = (alphaByteValue!=0)?255:0;
|
|
521 | 507 |
greenByteValue = 0; |
522 | 508 |
} else { |
523 | 509 |
alphaByteValue = 255; |
... | ... | |
533 | 519 |
NoData noData = blueBand.getNoData(); |
534 | 520 |
if(noData != null){ |
535 | 521 |
if(blueValue.equals(noData.getValue())){ |
536 |
alphaByteValue = 0; |
|
522 |
alphaByteValue = (alphaByteValue!=0)?255:0;
|
|
537 | 523 |
blueByteValue = 0; |
538 | 524 |
} else { |
539 | 525 |
alphaByteValue = 255; |
... | ... | |
599 | 585 |
return image; |
600 | 586 |
} |
601 | 587 |
|
602 |
// /** |
|
603 |
// * Conversi?n logaritmica de los valores del dominio de entrada a valores del dominio de BYTE |
|
604 |
// * para poder ser representados en RGB. |
|
605 |
// * |
|
606 |
// * @param n |
|
607 |
// * @return |
|
608 |
// */ |
|
609 |
// private int logarithmicConversionToByteRange(Number n) { |
|
610 |
// int b = 0; |
|
611 |
// if (n instanceof Byte) { |
|
612 |
// b = n.byteValue(); |
|
613 |
// if(b<0){ |
|
614 |
// b=256+b; |
|
615 |
// } |
|
616 |
// } else if (n instanceof Short) { |
|
617 |
// // Because Math.log(Short.MAX_VALUE-Short.MIN_VALUE)/Math.log(256) = 2; |
|
618 |
// b = (new Double(Math.round(Math.pow(n.shortValue(), 1d / 2d)))).intValue(); |
|
619 |
// } else if (n instanceof Integer) { |
|
620 |
// // Because |
|
621 |
// // Math.log(Integer.MAX_VALUE/256-Integer.MIN_VALUE/256)/Math.log(256) = 4; |
|
622 |
// b = (new Double(Math.round(Math.pow(n.intValue(), 1d / 4d)))).intValue(); |
|
623 |
// } else if (n instanceof Float) { |
|
624 |
// // Because Math.log(Float.MAX_VALUE-Float.MIN_VALUE)/Math.log(256) = 16; |
|
625 |
// double root = 16d; // Math.log(Float.MAX_VALUE-Float.MIN_VALUE)/Math.log(256); |
|
626 |
// b = (new Double(Math.round(Math.pow(n.floatValue(), 1d / root)))).intValue(); |
|
627 |
// } else if (n instanceof Double) { |
|
628 |
// // Because Math.log(Double.MAX_VALUE-Double.MIN_VALUE)/Math.log(256) = 128; |
|
629 |
// double root = 128d; |
|
630 |
// b = (new Double(Math.round(Math.pow(n.doubleValue(), 1d / root)))).intValue(); |
|
631 |
// } |
|
632 |
// return b; |
|
633 |
// } |
|
634 |
|
|
635 |
// /** |
|
636 |
// * Conversi?n logaritmica de los valores del dominio de entrada a valores del dominio de BYTE |
|
637 |
// * para poder ser representados en RGB. |
|
638 |
// * Aplica un factor de correcci?n que depende de los valores de entrada. |
|
639 |
// * |
|
640 |
// * @param n |
|
641 |
// * @param max |
|
642 |
// * @return |
|
643 |
// */ |
|
644 |
// private int logarithmicConversionToByteRange(Number n, double max) { |
|
645 |
// int b = 0; |
|
646 |
// if (n instanceof Byte) { |
|
647 |
// b = n.byteValue(); |
|
648 |
// if(b<0){ |
|
649 |
// b=256+b; |
|
650 |
// } |
|
651 |
// } else if (n instanceof Short) { |
|
652 |
// short value = n.shortValue(); |
|
653 |
// double factor = Short.MAX_VALUE / max; |
|
654 |
// // Because Math.log(Short.MAX_VALUE-Short.MIN_VALUE)/Math.log(256) = 2; |
|
655 |
// double root = 2d; |
|
656 |
// b = (new Double(Math.round(Math.pow(value, 1d / root)*factor))).intValue(); |
|
657 |
// } else if (n instanceof Integer) { |
|
658 |
// int value = n.intValue(); |
|
659 |
// double factor = Integer.MAX_VALUE / max; |
|
660 |
// // Because Math.log(Integer.MAX_VALUE/256-Integer.MIN_VALUE/256)/Math.log(256) = 4; |
|
661 |
// double root = 4d; |
|
662 |
// b = (new Double(Math.round(Math.pow(value, 1d / root)*factor))).intValue(); |
|
663 |
// } else if (n instanceof Float) { |
|
664 |
// float value = n.floatValue(); |
|
665 |
// double factor = Float.MAX_VALUE / max; |
|
666 |
// // Because Math.log(Float.MAX_VALUE-Float.MIN_VALUE)/Math.log(256) = 16; |
|
667 |
// double root = 16d; |
|
668 |
// b = (new Double(Math.round(Math.pow(value, 1d / root)*factor))).intValue(); |
|
669 |
// } else if (n instanceof Double) { |
|
670 |
// double value = n.doubleValue(); |
|
671 |
// double factor = Double.MAX_VALUE / max; |
|
672 |
// // Because Math.log(Double.MAX_VALUE-Double.MIN_VALUE)/Math.log(256) = 128; |
|
673 |
// double root = 128d; |
|
674 |
// b = (new Double(Math.round(Math.pow(value, 1d / root)*factor))).intValue(); |
|
675 |
// } |
|
676 |
// return b; |
|
677 |
// } |
|
678 |
|
|
679 |
// /** |
|
680 |
// * Conversi?n lineal de los valores del dominio de entrada a valores del dominio de BYTE |
|
681 |
// * para poder ser representados en RGB. |
|
682 |
// * |
|
683 |
// * @param n |
|
684 |
// * @return |
|
685 |
// */ |
|
686 |
// private int linearConversionToByteRange(Number n){ |
|
687 |
// int b=0; |
|
688 |
// if(n instanceof Byte){ |
|
689 |
// b = n.byteValue(); |
|
690 |
// if(b<0){ |
|
691 |
// b=256+b; |
|
692 |
// } |
|
693 |
// |
|
694 |
// } else if(n instanceof Short){ |
|
695 |
// // 65536/256 = 256 |
|
696 |
// b = (new Double(n.shortValue()/256)).intValue(); |
|
697 |
// } else if(n instanceof Integer){ |
|
698 |
// // (Integer.MAX_VALUE-Integer.MIN_VALUE)/256 = 16777215 |
|
699 |
// b = (new Double(n.intValue()/16777215)).intValue(); |
|
700 |
// } else if(n instanceof Float){ |
|
701 |
// // (Float.MAX_VALUE-Float.MIN_VALUE)/256 = 1.3292279E36 |
|
702 |
// b = (new Double(n.floatValue()/1.3292279E36)).intValue(); |
|
703 |
// } else if(n instanceof Double){ |
|
704 |
// // (Double.MAX_VALUE-Double.MIN_VALUE)/256 = 7.022238808055921E305; |
|
705 |
// b = (new Double(n.doubleValue()/7.022238808055921E305)).intValue(); |
|
706 |
// } |
|
707 |
// return b; |
|
708 |
// } |
|
709 |
|
|
710 |
// /** |
|
711 |
// * Conversi?n lineal de los valores de entrada a valores del dominio de BYTE |
|
712 |
// * para poder ser representados en RGB. |
|
713 |
// * Depende del rango de valores del buffer a representar. |
|
714 |
// * |
|
715 |
// * @param n |
|
716 |
// * @param maximum |
|
717 |
// * @param minimum |
|
718 |
// * @return |
|
719 |
// */ |
|
720 |
// private int proportionalConversionToByteRange(Number n, double maximum, double minimum){ |
|
721 |
// int b=0; |
|
722 |
// double ratio = (maximum-minimum)/256; |
|
723 |
// if(n instanceof Byte){ |
|
724 |
// b = n.byteValue(); |
|
725 |
// if(b<0){ |
|
726 |
// b=256+b; |
|
727 |
// } |
|
728 |
// } else if(n instanceof Short){ |
|
729 |
// // 65536/256 = 256 |
|
730 |
// b = (new Double((n.shortValue()-minimum)/ratio)).intValue(); |
|
731 |
// } else if(n instanceof Integer){ |
|
732 |
// // (Integer.MAX_VALUE-Integer.MIN_VALUE)/256 = 16777215 |
|
733 |
// b = (new Double((n.intValue()-minimum)/ratio)).intValue(); |
|
734 |
// } else if(n instanceof Float){ |
|
735 |
// // (Float.MAX_VALUE-Float.MIN_VALUE)/256 = 1.3292279E36 |
|
736 |
// b = (new Double((n.floatValue()-minimum)/ratio)).intValue(); |
|
737 |
// } else if(n instanceof Double){ |
|
738 |
// // (Double.MAX_VALUE-Double.MIN_VALUE)/256 = 7.022238808055921E305; |
|
739 |
// b = (new Double((n.doubleValue()-minimum)/ratio)).intValue(); |
|
740 |
// } |
|
741 |
// return b; |
|
742 |
// } |
|
743 |
|
|
744 |
|
|
745 | 588 |
private Image drawHSLBuffer(Graphics graphics, Buffer buffer, |
746 | 589 |
ColorInterpretation colorInterpretation,Transparency transparency, |
747 | 590 |
OperationList filters) throws BufferOperationException { |
... | ... | |
939 | 782 |
* @return |
940 | 783 |
* @throws OperationException |
941 | 784 |
*/ |
942 |
private Image drawGrayBuffer(Graphics graphics, Buffer buffer, Transparency transparency, OperationList filters) throws BufferOperationException { |
|
785 |
private Image drawGrayBuffer(Graphics graphics, Buffer buffer, ColorInterpretation colorInterpretation, Transparency transparency, OperationList filters) throws BufferOperationException {
|
|
943 | 786 |
|
944 | 787 |
BufferedImage image = null; |
945 | 788 |
Buffer byteBuffer = convertToByteBuffer(buffer); |
... | ... | |
947 | 790 |
image = ToolsSwingLocator.getToolsSwingManager().createBufferedImage(byteBuffer.getColumns(), byteBuffer.getRows(), |
948 | 791 |
BufferedImage.TYPE_INT_ARGB); |
949 | 792 |
|
950 |
Band greyBand = byteBuffer.getBand(0);
|
|
793 |
Band grayBand = byteBuffer.getBand(colorInterpretation.getBand(ColorInterpretation.GRAY_BAND));
|
|
951 | 794 |
|
952 | 795 |
for (int i = 0; i < byteBuffer.getRows(); i++) { |
953 | 796 |
for (int j = 0; j < byteBuffer.getColumns(); j++) { |
954 |
int greyByteValue = 0;
|
|
797 |
int grayByteValue = 0;
|
|
955 | 798 |
int alphaByteValue = (byte)255; |
956 |
Number greyValue = (Number) greyBand.get(i, j);
|
|
957 |
NoData noData = greyBand.getNoData();
|
|
799 |
Number grayValue = (Number) grayBand.get(i, j);
|
|
800 |
NoData noData = grayBand.getNoData();
|
|
958 | 801 |
if(noData != null){ |
959 |
if(greyValue.equals(noData.getValue())){
|
|
802 |
if(grayValue.equals(noData.getValue())){
|
|
960 | 803 |
alphaByteValue = 0; |
961 |
greyByteValue = 0;
|
|
804 |
grayByteValue = 0;
|
|
962 | 805 |
} else { |
963 | 806 |
alphaByteValue = 255; |
964 |
greyByteValue = greyValue.byteValue();
|
|
807 |
grayByteValue = grayValue.byteValue();
|
|
965 | 808 |
} |
966 | 809 |
} else { |
967 |
greyByteValue = greyValue.byteValue();
|
|
810 |
grayByteValue = grayValue.byteValue();
|
|
968 | 811 |
} |
969 | 812 |
|
970 | 813 |
if (alphaByteValue != 0 && transparency != null) { |
971 | 814 |
// Apply defined transparency ranges |
972 | 815 |
|
973 | 816 |
// alphaByteValue = alphaValue.byteValue() & 0xFF; |
974 |
int newAlpha = transparency.getTransparencyRangeAlpha(greyByteValue, greyByteValue, greyByteValue);
|
|
817 |
int newAlpha = transparency.getTransparencyRangeAlpha(grayByteValue, grayByteValue, grayByteValue);
|
|
975 | 818 |
alphaByteValue = getNewAlpha(alphaByteValue, newAlpha); |
976 | 819 |
|
977 | 820 |
// Apply general transparency |
... | ... | |
984 | 827 |
} |
985 | 828 |
|
986 | 829 |
int intARGB = (((byte)alphaByteValue & 0xFF) << 24) | // alpha |
987 |
(((byte)greyByteValue & 0xFF)<< 16) | // red
|
|
988 |
(((byte)greyByteValue & 0xFF)<< 8) | // green
|
|
989 |
(((byte)greyByteValue & 0xFF)); // blue
|
|
830 |
(((byte)grayByteValue & 0xFF)<< 16) | // red
|
|
831 |
(((byte)grayByteValue & 0xFF)<< 8) | // green
|
|
832 |
(((byte)grayByteValue & 0xFF)); // blue
|
|
990 | 833 |
|
991 | 834 |
image.setRGB(j, i, intARGB); |
992 | 835 |
} |
... | ... | |
1006 | 849 |
} |
1007 | 850 |
} |
1008 | 851 |
if(mustConvert){ |
1009 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
|
1010 |
DynObject parameters = bufferManager.createOperationParameters("LinearStretchEnhancement"); |
|
1011 |
parameters.setDynValue(LinearStretchEnhancementOperation.BANDS_TO_PROCESS_PARAM, bandsToProcess); |
|
1012 |
// parameters.setDynValue(LinearStretchEnhancementOperation.TAIL_TRIM_PARAM, true); |
|
1013 |
// parameters.setDynValue(LinearStretchEnhancementOperation.TAIL_TRIM_PERCENT_PARAM, 20.0); |
|
1014 |
return bufferManager.execute("LinearStretchEnhancement", buffer, parameters); |
|
852 |
OperationManager operationManager = BufferLocator.getOperationManager(); |
|
853 |
DynObject parameters = operationManager.createOperationParameters(SpecifiedBandsOperation.LINEAR_STRETCH_ENHANCEMENT_NAME); |
|
854 |
parameters.setDynValue(AbstractSpecifiedBandsOperation.BANDS_TO_PROCESS_PARAM, bandsToProcess); |
|
855 |
return operationManager.execute(SpecifiedBandsOperation.LINEAR_STRETCH_ENHANCEMENT_NAME, buffer, parameters); |
|
1015 | 856 |
} |
1016 | 857 |
return buffer; |
1017 | 858 |
} |
... | ... | |
1066 | 907 |
|
1067 | 908 |
@Override |
1068 | 909 |
public void setColorInterpretation(ColorInterpretation colorInterpretation) { |
1069 |
if(this.colorInterpretation!=null){
|
|
910 |
if (this.colorInterpretation != null) {
|
|
1070 | 911 |
this.colorInterpretation.deleteObserver(this); |
1071 | 912 |
} |
1072 | 913 |
this.colorInterpretation = colorInterpretation; |
1073 | 914 |
this.colorInterpretation.addObserver(this); |
1074 |
}
|
|
915 |
} |
|
1075 | 916 |
|
1076 | 917 |
@Override |
1077 | 918 |
public OperationList getFilters() { |
1078 | 919 |
if(this.filters == null){ |
1079 | 920 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
1080 |
this.filters = ((OperationListManager)bufferManager).createOperationList();
|
|
921 |
this.filters = ((OperationManager)bufferManager).createOperationList(); |
|
1081 | 922 |
} |
1082 | 923 |
return this.filters; |
1083 | 924 |
} |
... | ... | |
1107 | 948 |
@Override |
1108 | 949 |
public void saveToState(PersistentState state) throws PersistenceException { |
1109 | 950 |
state.set(COLOR_INTERPRETATION_PERSISTENCE_FIELD, this.getColorInterpretation()); |
1110 |
state.set(FILTERS_PERSISTENCE_FIELD, this.getFilters()); |
|
951 |
state.set(FILTERS_PERSISTENCE_FIELD, (Persistent)this.getFilters());
|
|
1111 | 952 |
} |
1112 | 953 |
|
1113 | 954 |
@Override |
... | ... | |
1248 | 1089 |
private void removeLegendListener(RasterLegendChangedListener listener) { |
1249 | 1090 |
listeners.remove(listener); |
1250 | 1091 |
} |
1092 |
|
|
1093 |
@Override |
|
1094 |
public void addColorTableOperation(ColorInterpretation colorInterpretation, int index) { |
|
1095 |
|
|
1096 |
removeOperationIfExists(SpecifiedBandsOperation.LINEAR_STRETCH_ENHANCEMENT_NAME); |
|
1097 |
removeOperationIfExists(ColoredOperation.COLOR_TABLE_OPERATION_NAME); |
|
1098 |
|
|
1099 |
OperationManager operationManager = BufferLocator.getOperationManager(); |
|
1100 |
Operation colorTableOperation = operationManager.createOperation(ColoredOperation.COLOR_TABLE_OPERATION_NAME); |
|
1101 |
DynObject colorTableOperationParameters = operationManager.createOperationParameters(ColoredOperation.COLOR_TABLE_OPERATION_NAME); |
|
1102 |
colorTableOperationParameters.setDynValue(ColoredOperation.COLOR_INTERPRETATION_PARAM, colorInterpretation); |
|
1103 |
colorTableOperationParameters.setDynValue(AbstractOperation.COPY_UNPROCESSED_BANDS_PARAM, true); |
|
1104 |
OperationListEntry colorTableEntry = operationManager.createOperationListEntry(colorTableOperation, colorTableOperationParameters); |
|
1105 |
getFilters().add(index, colorTableEntry); |
|
1106 |
} |
|
1107 |
|
|
1108 |
@Override |
|
1109 |
public void addLinearStretchEnhancementOperationIfNeeded(ColorInterpretation colorInterpretation, |
|
1110 |
RasterStore store, int index) { |
|
1111 |
|
|
1112 |
removeOperationIfExists(SpecifiedBandsOperation.LINEAR_STRETCH_ENHANCEMENT_NAME); |
|
1113 |
removeOperationIfExists(ColoredOperation.COLOR_TABLE_OPERATION_NAME); |
|
1114 |
|
|
1115 |
RasterStore rasterStore = (RasterStore) store; |
|
1116 |
|
|
1117 |
OperationManager operationManager = BufferLocator.getOperationManager(); |
|
1118 |
if ((!colorInterpretation.isPalette()) |
|
1119 |
&& (colorInterpretation.hasAnyColorInterpretationBand() || colorInterpretation.hasAlphaBand() || colorInterpretation |
|
1120 |
.hasAnyGrayBand())) { |
|
1121 |
|
|
1122 |
List<Integer> bandsToProcess = new ArrayList<Integer>(); |
|
1123 |
for (int i = 0; i < rasterStore.getBands(); i++) { |
|
1124 |
if ((colorInterpretation.isColorInterpretation(i) || colorInterpretation.isAlphaInterpretation(i) || colorInterpretation |
|
1125 |
.isGrayInterpretation(i)) |
|
1126 |
&& (rasterStore.getBandDescriptor(i).getDataType() != BufferManager.TYPE_BYTE)) { |
|
1127 |
bandsToProcess.add(i); |
|
1128 |
} |
|
1129 |
} |
|
1130 |
|
|
1131 |
if (!bandsToProcess.isEmpty()) { |
|
1132 |
Operation linearStretchEnhancementOperation = operationManager.createOperation(SpecifiedBandsOperation.LINEAR_STRETCH_ENHANCEMENT_NAME); |
|
1133 |
DynObject linearStretchEnhancementOperationParameters = |
|
1134 |
operationManager.createOperationParameters(SpecifiedBandsOperation.LINEAR_STRETCH_ENHANCEMENT_NAME); |
|
1135 |
linearStretchEnhancementOperationParameters.setDynValue( |
|
1136 |
AbstractSpecifiedBandsOperation.BANDS_TO_PROCESS_PARAM, bandsToProcess); |
|
1137 |
OperationListEntry colorTableEntry = |
|
1138 |
((OperationManager) operationManager).createOperationListEntry(linearStretchEnhancementOperation, |
|
1139 |
linearStretchEnhancementOperationParameters); |
|
1140 |
getFilters().add(index, colorTableEntry); |
|
1141 |
} |
|
1142 |
} |
|
1143 |
} |
|
1144 |
|
|
1145 |
@Override |
|
1146 |
public void removeOperationIfExists(String name) { |
|
1147 |
int removed = 0; |
|
1148 |
int size = getFilters().size(); |
|
1149 |
for (Iterator<OperationListEntry> iterator = getFilters().iterator(); iterator.hasNext();) { |
|
1150 |
OperationListEntry entry = (OperationListEntry) iterator.next(); |
|
1151 |
Operation operation = entry.getOperation(); |
|
1152 |
if (operation.getFactory().getName().equals(name)) { |
|
1153 |
iterator.remove(); |
|
1154 |
removed++; |
|
1155 |
} |
|
1156 |
} |
|
1157 |
if(getFilters().size()!=size-removed){ |
|
1158 |
LOG.warn("NO SE HAN ELIMINADO CORRECTAMENTE LAS ENTRADAS DE LA OPERATION_LIST."); |
|
1159 |
} |
|
1160 |
} |
|
1161 |
|
|
1251 | 1162 |
} |
Also available in: Unified diff