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/brightness/BrightnessOperation.java
BrightnessOperation.java | ||
---|---|---|
22 | 22 |
*/ |
23 | 23 |
package org.gvsig.raster.lib.legend.impl.operations.brightness; |
24 | 24 |
|
25 |
import java.util.ArrayList; |
|
26 |
import java.util.Iterator; |
|
27 |
import java.util.List; |
|
28 | 25 |
|
29 | 26 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
30 | 27 |
import org.gvsig.raster.lib.buffer.api.Band; |
... | ... | |
59 | 56 |
* |
60 | 57 |
*/ |
61 | 58 |
public BrightnessOperation(OperationFactory factory) { |
62 |
this.factory = factory;
|
|
59 |
super(factory);
|
|
63 | 60 |
} |
64 | 61 |
|
65 | 62 |
@Override |
... | ... | |
68 | 65 |
BufferManager manager = BufferLocator.getBufferManager(); |
69 | 66 |
RasterLegendManager legendManager = RasterLegendLocator.getRasterLegendManager(); |
70 | 67 |
|
71 |
brightness = (Integer) this.parameters.getDynValue(BRIGHTNESS_PARAM);
|
|
68 |
brightness = (Integer) this.getParameter(BRIGHTNESS_PARAM,0);
|
|
72 | 69 |
|
73 |
int bands = this.buffer.getBandCount();
|
|
70 |
int bands = this.getInputBuffer().getBandCount();
|
|
74 | 71 |
NoData[] noData; |
75 |
if (copyUnprocessedBands) {
|
|
76 |
this.parameters.setDynValue(OUTPUT_COLOR_INTERPRETATION_PARAM, colorInterpretation);
|
|
77 |
noData = this.buffer.getBandNoData();
|
|
72 |
if (mustCopyUnprocessedBands()) {
|
|
73 |
this.setParameter(OUTPUT_COLOR_INTERPRETATION_PARAM, getInputColorInterpretation());
|
|
74 |
noData = this.getInputBuffer().getBandNoData();
|
|
78 | 75 |
try { |
79 |
this.outputBuffer = |
|
80 |
manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), this.buffer.getBandTypes(), |
|
81 |
this.buffer.getBandNoData(), this.buffer.getProjection(), this.buffer.getEnvelope()); |
|
82 |
} catch (LocatorException | BufferException | CreateEnvelopeException e) { |
|
76 |
this.setOutputBuffer( |
|
77 |
manager.createBuffer( |
|
78 |
this.getInputBuffer().getRows(), |
|
79 |
this.getInputBuffer().getColumns(), |
|
80 |
this.getInputBuffer().getBandTypes(), |
|
81 |
this.getInputBuffer().getBandNoData(), |
|
82 |
this.getInputBuffer().getProjection(), |
|
83 |
this.getInputBuffer().getEnvelope())); |
|
84 |
} catch (Exception e) { |
|
83 | 85 |
throw new ProcessingOperationException(e); |
84 | 86 |
} |
85 | 87 |
} else { |
86 |
List<String> colorInterpretations = new ArrayList<String>(); |
|
87 |
List<NoData> noDatas = new ArrayList<NoData>(); |
|
88 |
List<Integer> types = new ArrayList<Integer>(); |
|
89 |
for (int band = 0; band < bands; band++) { |
|
90 |
if (isProcessableBand(band)) { |
|
91 |
colorInterpretations.add(colorInterpretation.get(band)); |
|
92 |
noDatas.add(this.buffer.getBandNoData()[band]); |
|
93 |
types.add(this.buffer.getBandTypes()[band]); |
|
94 |
} |
|
95 |
} |
|
96 |
if (colorInterpretation.hasAlphaBand()) { |
|
97 |
colorInterpretations.add(ColorInterpretation.ALPHA_BAND); |
|
98 |
} |
|
99 |
outputColorInterpretation = legendManager.createColorInterpretation(colorInterpretations.toArray(new String[0])); |
|
100 |
this.parameters.setDynValue(OUTPUT_COLOR_INTERPRETATION_PARAM, outputColorInterpretation); |
|
101 |
int[] typesInt = new int[types.size()]; |
|
102 |
for (Iterator iterator = types.iterator(); iterator.hasNext();) { |
|
103 |
int i = 0; |
|
104 |
Integer type = (Integer) iterator.next(); |
|
105 |
typesInt[i] = type.intValue(); |
|
106 |
} |
|
88 |
String[] colorInterpretations = this.getProcessableBandColorInterpretationsAsArray(); |
|
89 |
setOutputColorInterpretation(legendManager.createColorInterpretation(colorInterpretations)); |
|
90 |
this.setParameter(OUTPUT_COLOR_INTERPRETATION_PARAM, getOutputColorInterpretation()); |
|
107 | 91 |
try { |
108 |
this.outputBuffer = |
|
109 |
manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), typesInt, |
|
110 |
noDatas.toArray(new NoData[0]), this.buffer.getProjection(), this.buffer.getEnvelope()); |
|
92 |
this.setOutputBuffer( |
|
93 |
manager.createBuffer( |
|
94 |
this.getInputBuffer().getRows(), |
|
95 |
this.getInputBuffer().getColumns(), |
|
96 |
this.getProcessableBandTypesAsArray(), |
|
97 |
this.getProcessableBandNoDatasAsArray(), |
|
98 |
this.getInputBuffer().getProjection(), |
|
99 |
this.getInputBuffer().getEnvelope())); |
|
111 | 100 |
} catch (LocatorException | BufferException | CreateEnvelopeException e) { |
112 | 101 |
throw new ProcessingOperationException(e); |
113 | 102 |
} |
... | ... | |
117 | 106 |
@Override |
118 | 107 |
public void process() throws ProcessingOperationException { |
119 | 108 |
super.process(); |
120 |
for (int band = 0; band < this.buffer.getBandCount(); band++) {
|
|
109 |
for (int band = 0; band < this.getInputBuffer().getBandCount(); band++) {
|
|
121 | 110 |
rowProcessor = new ByteRowProcessor(band); |
122 | 111 |
if (isProcessableBand(band)) { |
123 |
Band bufferBand = this.buffer.getBand(band);
|
|
124 |
Band outputBufferBand = this.outputBuffer.getBand(band);
|
|
112 |
Band bufferBand = this.getInputBuffer().getBand(band);
|
|
113 |
Band outputBufferBand = this.getOutputBuffer().getBand(band);
|
|
125 | 114 |
|
126 |
for (int row = 0; row < this.buffer.getRows(); row++) {
|
|
115 |
for (int row = 0; row < this.getInputBuffer().getRows(); row++) {
|
|
127 | 116 |
Object rowBuffer = bufferBand.createRowBuffer(); |
128 | 117 |
bufferBand.fetchRow(row, rowBuffer); |
129 | 118 |
|
... | ... | |
133 | 122 |
|
134 | 123 |
outputBufferBand.putRow(row, outputRowBuffer); |
135 | 124 |
} |
136 |
} else if (copyUnprocessedBands) {
|
|
125 |
} else if (mustCopyUnprocessedBands()) {
|
|
137 | 126 |
try { |
138 |
this.outputBuffer.getBand(band).copyFrom(this.buffer.getBand(band));
|
|
127 |
this.getOutputBuffer().getBand(band).copyFrom(this.getInputBuffer().getBand(band));
|
|
139 | 128 |
} catch (BandException e) { |
140 | 129 |
throw new ProcessingOperationException(e); |
141 | 130 |
} |
142 |
} else if (colorInterpretation.isAlphaInterpretation(band)) {
|
|
131 |
} else if (getInputColorInterpretation().isAlphaInterpretation(band)) {
|
|
143 | 132 |
try { |
144 |
this.outputBuffer.getBand(outputColorInterpretation.getAlphaBand()).copyFrom(this.buffer.getBand(band));
|
|
133 |
this.getOutputBuffer().getBand(getOutputColorInterpretation().getAlphaBand()).copyFrom(this.getInputBuffer().getBand(band));
|
|
145 | 134 |
} catch (BandException e) { |
146 | 135 |
throw new ProcessingOperationException(e); |
147 | 136 |
} |
... | ... | |
153 | 142 |
* @param band |
154 | 143 |
* @return |
155 | 144 |
*/ |
156 |
private boolean isProcessableBand(int band) { |
|
157 |
return isRGBorGrayBand(band) && this.buffer.getBandTypes()[band] == BufferManager.TYPE_BYTE; |
|
145 |
@Override |
|
146 |
protected boolean isProcessableBand(int band) { |
|
147 |
return isRGBorGrayBand(band) && this.getInputBuffer().getBandTypes()[band] == BufferManager.TYPE_BYTE; |
|
158 | 148 |
} |
159 | 149 |
|
160 | 150 |
private boolean isRGBorGrayBand(int band) { |
161 |
String bandColorInterpretation = colorInterpretation.get(band);
|
|
151 |
String bandColorInterpretation = getInputColorInterpretation().get(band);
|
|
162 | 152 |
return (bandColorInterpretation.equals(ColorInterpretation.RED_BAND) || |
163 | 153 |
bandColorInterpretation.equals(ColorInterpretation.GREEN_BAND) || |
164 | 154 |
bandColorInterpretation.equals(ColorInterpretation.BLUE_BAND) || |
... | ... | |
186 | 176 |
|
187 | 177 |
public AbstractRowProcessor(int band) { |
188 | 178 |
// this.band = band; |
189 |
noData = buffer.getBand(band).getNoData();
|
|
179 |
noData = getInputBuffer().getBand(band).getNoData();
|
|
190 | 180 |
if (noData.isDefined()) { |
191 | 181 |
minResult = (byte) 1; |
192 | 182 |
} |
... | ... | |
214 | 204 |
return (byte) value; |
215 | 205 |
} |
216 | 206 |
|
217 |
int iValue = 0xFF & ((Byte) value).byteValue();
|
|
207 |
int iValue = 0xFF & ((Byte) value); |
|
218 | 208 |
int result = iValue + brightness; |
219 | 209 |
if (result > maxResult) { |
220 | 210 |
result = maxResult; |
Also available in: Unified diff