Revision 43862 branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/java/org/gvsig/raster/lib/legend/impl/operations/contrast/ContrastOperation.java
ContrastOperation.java | ||
---|---|---|
23 | 23 |
package org.gvsig.raster.lib.legend.impl.operations.contrast; |
24 | 24 |
|
25 | 25 |
import java.util.ArrayList; |
26 |
import java.util.Iterator; |
|
27 | 26 |
import java.util.List; |
28 | 27 |
|
29 | 28 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
... | ... | |
36 | 35 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException; |
37 | 36 |
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory; |
38 | 37 |
import org.gvsig.raster.lib.buffer.spi.exceptions.ProcessingOperationException; |
39 |
import org.gvsig.raster.lib.buffer.spi.operations.AbstractOperation; |
|
40 | 38 |
import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
41 | 39 |
import org.gvsig.raster.lib.legend.api.RasterLegendManager; |
42 | 40 |
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation; |
... | ... | |
60 | 58 |
* |
61 | 59 |
*/ |
62 | 60 |
public ContrastOperation(OperationFactory factory) { |
63 |
this.factory = factory;
|
|
61 |
super(factory);
|
|
64 | 62 |
} |
65 | 63 |
|
66 | 64 |
@Override |
... | ... | |
69 | 67 |
BufferManager manager = BufferLocator.getBufferManager(); |
70 | 68 |
RasterLegendManager legendManager = RasterLegendLocator.getRasterLegendManager(); |
71 | 69 |
|
72 |
contrast = (Integer) this.parameters.getDynValue(CONTRAST_PARAM);
|
|
70 |
contrast = (Integer) this.getParameter(CONTRAST_PARAM,0);
|
|
73 | 71 |
|
74 |
int bands = this.buffer.getBandCount();
|
|
72 |
int bands = this.getInputBuffer().getBandCount();
|
|
75 | 73 |
NoData[] noData; |
76 |
if (copyUnprocessedBands) {
|
|
77 |
this.parameters.setDynValue(OUTPUT_COLOR_INTERPRETATION_PARAM, colorInterpretation);
|
|
78 |
noData = this.buffer.getBandNoData();
|
|
74 |
if (mustCopyUnprocessedBands()) {
|
|
75 |
this.setParameter(OUTPUT_COLOR_INTERPRETATION_PARAM, getInputColorInterpretation());
|
|
76 |
noData = this.getInputBuffer().getBandNoData();
|
|
79 | 77 |
try { |
80 |
this.outputBuffer = |
|
81 |
manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), this.buffer.getBandTypes(), |
|
82 |
this.buffer.getBandNoData(), this.buffer.getProjection(), this.buffer.getEnvelope()); |
|
83 |
} catch (LocatorException | BufferException | CreateEnvelopeException e) { |
|
78 |
this.setOutputBuffer( |
|
79 |
manager.createBuffer( |
|
80 |
this.getInputBuffer().getRows(), |
|
81 |
this.getInputBuffer().getColumns(), |
|
82 |
this.getInputBuffer().getBandTypes(), |
|
83 |
this.getInputBuffer().getBandNoData(), |
|
84 |
this.getInputBuffer().getProjection(), |
|
85 |
this.getInputBuffer().getEnvelope())); |
|
86 |
} catch (Exception e) { |
|
84 | 87 |
throw new ProcessingOperationException(e); |
85 | 88 |
} |
86 | 89 |
} else { |
87 |
List<String> colorInterpretations = new ArrayList<String>();
|
|
88 |
List<NoData> noDatas = new ArrayList<NoData>();
|
|
89 |
List<Integer> types = new ArrayList<Integer>();
|
|
90 |
List<String> colorInterpretations = new ArrayList<>(); |
|
91 |
List<NoData> noDatas = new ArrayList<>(); |
|
92 |
List<Integer> types = new ArrayList<>(); |
|
90 | 93 |
for (int band = 0; band < bands; band++) { |
91 | 94 |
if (isProcessableBand(band)) { |
92 |
colorInterpretations.add(colorInterpretation.get(band));
|
|
93 |
noDatas.add(this.buffer.getBandNoData()[band]);
|
|
94 |
types.add(this.buffer.getBandTypes()[band]);
|
|
95 |
colorInterpretations.add(getInputColorInterpretation().get(band));
|
|
96 |
noDatas.add(this.getInputBuffer().getBandNoData()[band]);
|
|
97 |
types.add(this.getInputBuffer().getBandTypes()[band]);
|
|
95 | 98 |
} |
96 | 99 |
} |
97 |
if (colorInterpretation.hasAlphaBand()) {
|
|
100 |
if (getInputColorInterpretation().hasAlphaBand()) {
|
|
98 | 101 |
colorInterpretations.add(ColorInterpretation.ALPHA_BAND); |
99 | 102 |
} |
100 |
outputColorInterpretation = legendManager.createColorInterpretation(colorInterpretations.toArray(new String[0])); |
|
101 |
this.parameters.setDynValue(OUTPUT_COLOR_INTERPRETATION_PARAM, outputColorInterpretation); |
|
102 |
int[] typesInt = new int[types.size()]; |
|
103 |
for (Iterator iterator = types.iterator(); iterator.hasNext();) { |
|
104 |
int i = 0; |
|
105 |
Integer type = (Integer) iterator.next(); |
|
106 |
typesInt[i] = type.intValue(); |
|
107 |
} |
|
103 |
setOutputColorInterpretation(legendManager.createColorInterpretation( |
|
104 |
colorInterpretations)); |
|
105 |
this.setParameter( |
|
106 |
OUTPUT_COLOR_INTERPRETATION_PARAM, |
|
107 |
getOutputColorInterpretation()); |
|
108 | 108 |
try { |
109 |
this.outputBuffer = |
|
110 |
manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), typesInt, |
|
111 |
noDatas.toArray(new NoData[0]), this.buffer.getProjection(), this.buffer.getEnvelope()); |
|
109 |
this.setOutputBuffer( |
|
110 |
manager.createBuffer( |
|
111 |
this.getInputBuffer().getRows(), |
|
112 |
this.getInputBuffer().getColumns(), |
|
113 |
this.getTypesAsArray(types), |
|
114 |
this.getNoDatasAsArray(noDatas), |
|
115 |
this.getInputBuffer().getProjection(), |
|
116 |
this.getInputBuffer().getEnvelope())); |
|
112 | 117 |
} catch (LocatorException | BufferException | CreateEnvelopeException e) { |
113 | 118 |
throw new ProcessingOperationException(e); |
114 | 119 |
} |
... | ... | |
119 | 124 |
@Override |
120 | 125 |
public void process() throws ProcessingOperationException { |
121 | 126 |
super.process(); |
122 |
for (int band=0; band<this.buffer.getBandCount(); band++){
|
|
127 |
for (int band=0; band<this.getInputBuffer().getBandCount(); band++){
|
|
123 | 128 |
rowProcessor = new ByteRowProcessor(band); |
124 | 129 |
if (isProcessableBand(band)) { |
125 |
Band bufferBand = this.buffer.getBand(band);
|
|
126 |
Band outputBufferBand = this.outputBuffer.getBand(band);
|
|
130 |
Band bufferBand = this.getInputBuffer().getBand(band);
|
|
131 |
Band outputBufferBand = this.getOutputBuffer().getBand(band);
|
|
127 | 132 |
|
128 |
for (int row = 0; row < this.buffer.getRows(); row++) {
|
|
133 |
for (int row = 0; row < this.getInputBuffer().getRows(); row++) {
|
|
129 | 134 |
Object rowBuffer = bufferBand.createRowBuffer(); |
130 | 135 |
bufferBand.fetchRow(row, rowBuffer); |
131 | 136 |
|
... | ... | |
136 | 141 |
|
137 | 142 |
outputBufferBand.putRow(row, outputRowBuffer); |
138 | 143 |
} |
139 |
} else if (copyUnprocessedBands) {
|
|
144 |
} else if (mustCopyUnprocessedBands()) {
|
|
140 | 145 |
try { |
141 |
this.outputBuffer.getBand(band).copyFrom(this.buffer.getBand(band));
|
|
146 |
this.getOutputBuffer().getBand(band).copyFrom(this.getInputBuffer().getBand(band));
|
|
142 | 147 |
} catch (BandException e) { |
143 | 148 |
throw new ProcessingOperationException(e); |
144 | 149 |
} |
145 |
} else if (colorInterpretation.isAlphaInterpretation(band)) {
|
|
150 |
} else if (getInputColorInterpretation().isAlphaInterpretation(band)) {
|
|
146 | 151 |
try { |
147 |
this.outputBuffer.getBand(outputColorInterpretation.getAlphaBand()).copyFrom(this.buffer.getBand(band));
|
|
152 |
this.getOutputBuffer().getBand(getOutputColorInterpretation().getAlphaBand()).copyFrom(this.getInputBuffer().getBand(band));
|
|
148 | 153 |
} catch (BandException e) { |
149 | 154 |
throw new ProcessingOperationException(e); |
150 | 155 |
} |
... | ... | |
156 | 161 |
* @param band |
157 | 162 |
* @return |
158 | 163 |
*/ |
159 |
private boolean isProcessableBand(int band) { |
|
160 |
return isRGBorGrayBand(band) && this.buffer.getBandTypes()[band]==BufferManager.TYPE_BYTE; |
|
164 |
@Override |
|
165 |
protected boolean isProcessableBand(int band) { |
|
166 |
return isRGBorGrayBand(band) && this.getInputBuffer().getBandTypes()[band]==BufferManager.TYPE_BYTE; |
|
161 | 167 |
} |
162 | 168 |
|
163 | 169 |
private boolean isRGBorGrayBand(int band) { |
164 |
String bandColorInterpretation = colorInterpretation.get(band);
|
|
170 |
String bandColorInterpretation = getInputColorInterpretation().get(band);
|
|
165 | 171 |
return (bandColorInterpretation.equals(ColorInterpretation.RED_BAND) || |
166 | 172 |
bandColorInterpretation.equals(ColorInterpretation.GREEN_BAND) || |
167 | 173 |
bandColorInterpretation.equals(ColorInterpretation.BLUE_BAND) || |
... | ... | |
186 | 192 |
|
187 | 193 |
public AbstractRowProcessor(int band) { |
188 | 194 |
// this.band = band; |
189 |
noData = buffer.getBand(band).getNoData();
|
|
195 |
noData = getInputBuffer().getBand(band).getNoData();
|
|
190 | 196 |
if(noData.isDefined()) { |
191 | 197 |
minResult = (byte)1; |
192 | 198 |
} |
... | ... | |
215 | 221 |
return (byte)value; |
216 | 222 |
} |
217 | 223 |
|
218 |
int iValue = 0xFF & ((Byte) value).byteValue();
|
|
224 |
int iValue = 0xFF & ((Byte) value); |
|
219 | 225 |
|
220 | 226 |
//FIXME: Copiado del raster viejo. No entiendo los c?lculos |
221 | 227 |
|
Also available in: Unified diff