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/colorbalancergb/AbstractColorBalanceOperation.java
AbstractColorBalanceOperation.java | ||
---|---|---|
23 | 23 |
package org.gvsig.raster.lib.legend.impl.operations.colorbalancergb; |
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; |
... | ... | |
34 | 33 |
import org.gvsig.raster.lib.buffer.api.exceptions.BandException; |
35 | 34 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferException; |
36 | 35 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException; |
36 |
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory; |
|
37 | 37 |
import org.gvsig.raster.lib.buffer.spi.exceptions.ProcessingOperationException; |
38 | 38 |
import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
39 | 39 |
import org.gvsig.raster.lib.legend.api.RasterLegendManager; |
... | ... | |
52 | 52 |
* @param factory |
53 | 53 |
* |
54 | 54 |
*/ |
55 |
public AbstractColorBalanceOperation() { |
|
56 |
// Nothing to do
|
|
55 |
public AbstractColorBalanceOperation(OperationFactory factory) {
|
|
56 |
super(factory);
|
|
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
abstract protected void initialiceParams(); |
... | ... | |
67 | 67 |
initialiceParams(); |
68 | 68 |
|
69 | 69 |
try { |
70 |
if (!(colorInterpretation.isGray() || colorInterpretation.isRGB())) {
|
|
70 |
if (!(getInputColorInterpretation().isGray() || getInputColorInterpretation().isRGB())) {
|
|
71 | 71 |
throw new UnsupportedOperationException( |
72 | 72 |
"The color interpretation of input buffer isn't RGB nor GRAYSCALE"); |
73 | 73 |
} |
74 | 74 |
|
75 |
int[] inputBandTypes = buffer.getBandTypes();
|
|
76 |
if (colorInterpretation.isGray()) {
|
|
77 |
if (inputBandTypes[colorInterpretation.getBand(ColorInterpretation.GRAY_BAND)] != BufferManager.TYPE_BYTE) {
|
|
75 |
int[] inputBandTypes = getInputBuffer().getBandTypes();
|
|
76 |
if (getInputColorInterpretation().isGray()) {
|
|
77 |
if (inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.GRAY_BAND)] != BufferManager.TYPE_BYTE) {
|
|
78 | 78 |
throw new UnsupportedOperationException("The type of GRAY band isn't BYTE"); |
79 | 79 |
} |
80 |
} else if (colorInterpretation.isRGB()) {
|
|
81 |
if (inputBandTypes[colorInterpretation.getBand(ColorInterpretation.RED_BAND)] != BufferManager.TYPE_BYTE
|
|
82 |
|| inputBandTypes[colorInterpretation.getBand(ColorInterpretation.GREEN_BAND)] != BufferManager.TYPE_BYTE
|
|
83 |
|| inputBandTypes[colorInterpretation.getBand(ColorInterpretation.BLUE_BAND)] != BufferManager.TYPE_BYTE) {
|
|
80 |
} else if (getInputColorInterpretation().isRGB()) {
|
|
81 |
if (inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.RED_BAND)] != BufferManager.TYPE_BYTE
|
|
82 |
|| inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.GREEN_BAND)] != BufferManager.TYPE_BYTE
|
|
83 |
|| inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.BLUE_BAND)] != BufferManager.TYPE_BYTE) {
|
|
84 | 84 |
throw new UnsupportedOperationException("The type of RGB bands isn't BYTE"); |
85 | 85 |
} |
86 | 86 |
} else { |
... | ... | |
88 | 88 |
"The color interpretation of input buffer isn't RGB nor GRAYSCALE"); |
89 | 89 |
} |
90 | 90 |
|
91 |
int sourceBands = this.buffer.getBandCount();
|
|
92 |
NoData[] sourceNoDatas = this.buffer.getBandNoData();
|
|
93 |
int[] sourceTypes = this.buffer.getBandTypes();
|
|
91 |
int sourceBands = this.getInputBuffer().getBandCount();
|
|
92 |
NoData[] sourceNoDatas = this.getInputBuffer().getBandNoData();
|
|
93 |
int[] sourceTypes = this.getInputBuffer().getBandTypes();
|
|
94 | 94 |
|
95 |
List<String> colorInterpretations = new ArrayList<String>();
|
|
96 |
List<NoData> noDatas = new ArrayList<NoData>();
|
|
97 |
List<Integer> types = new ArrayList<Integer>();
|
|
95 |
List<String> colorInterpretations = new ArrayList<>(); |
|
96 |
List<NoData> noDatas = new ArrayList<>(); |
|
97 |
List<Integer> types = new ArrayList<>(); |
|
98 | 98 |
|
99 | 99 |
colorInterpretations.add(ColorInterpretation.RED_BAND); |
100 | 100 |
colorInterpretations.add(ColorInterpretation.GREEN_BAND); |
... | ... | |
108 | 108 |
noDatas.add(null); |
109 | 109 |
noDatas.add(null); |
110 | 110 |
|
111 |
if (colorInterpretation.hasAlphaBand()) {
|
|
112 |
int alphaBand = colorInterpretation.getAlphaBand();
|
|
111 |
if (getInputColorInterpretation().hasAlphaBand()) {
|
|
112 |
int alphaBand = getInputColorInterpretation().getAlphaBand();
|
|
113 | 113 |
if(sourceTypes[alphaBand]!=BufferManager.TYPE_BYTE){ |
114 | 114 |
throw new UnsupportedOperationException("The type of ALPHA band isn't BYTE"); |
115 | 115 |
} |
... | ... | |
118 | 118 |
noDatas.add(sourceNoDatas[alphaBand]); |
119 | 119 |
} |
120 | 120 |
|
121 |
if (copyUnprocessedBands) {
|
|
121 |
if (mustCopyUnprocessedBands()) {
|
|
122 | 122 |
for (int band = 0; band < sourceBands; band++) { |
123 |
if (!isProcessableBand(band) && !colorInterpretation.isAlphaInterpretation(band)) {
|
|
124 |
colorInterpretations.add(colorInterpretation.get(band));
|
|
123 |
if (!isProcessableBand(band) && !getInputColorInterpretation().isAlphaInterpretation(band)) {
|
|
124 |
colorInterpretations.add(getInputColorInterpretation().get(band));
|
|
125 | 125 |
noDatas.add(sourceNoDatas[band]); |
126 |
types.add(this.buffer.getBandTypes()[band]);
|
|
126 |
types.add(this.getInputBuffer().getBandTypes()[band]);
|
|
127 | 127 |
} |
128 | 128 |
} |
129 | 129 |
} |
130 | 130 |
|
131 |
outputColorInterpretation = |
|
132 |
legendManager.createColorInterpretation(colorInterpretations.toArray(new String[0])); |
|
133 |
this.parameters.setDynValue(OUTPUT_COLOR_INTERPRETATION_PARAM, outputColorInterpretation); |
|
134 |
int[] typesInt = new int[types.size()]; |
|
135 |
for (Iterator<Integer> iterator = types.iterator(); iterator.hasNext();) { |
|
136 |
int i = 0; |
|
137 |
Integer type = (Integer) iterator.next(); |
|
138 |
typesInt[i] = type.intValue(); |
|
139 |
} |
|
140 |
|
|
141 |
this.outputBuffer = |
|
142 |
manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), typesInt, |
|
143 |
noDatas.toArray(new NoData[0]), this.buffer.getProjection(), this.buffer.getEnvelope()); |
|
131 |
setOutputColorInterpretation( |
|
132 |
legendManager.createColorInterpretation(colorInterpretations)); |
|
133 |
this.setParameter(OUTPUT_COLOR_INTERPRETATION_PARAM, getOutputColorInterpretation()); |
|
134 |
this.setOutputBuffer( |
|
135 |
manager.createBuffer( |
|
136 |
this.getInputBuffer().getRows(), |
|
137 |
this.getInputBuffer().getColumns(), |
|
138 |
this.getTypesAsArray(types), |
|
139 |
this.getNoDatasAsArray(noDatas), |
|
140 |
this.getInputBuffer().getProjection(), |
|
141 |
this.getInputBuffer().getEnvelope())); |
|
144 | 142 |
} catch (LocatorException | BufferException | CreateEnvelopeException e) { |
145 | 143 |
throw new BufferOperationException(e); |
146 | 144 |
} |
... | ... | |
149 | 147 |
@Override |
150 | 148 |
public void process() throws ProcessingOperationException { |
151 | 149 |
super.process(); |
152 |
if (colorInterpretation.hasAlphaBand()) {
|
|
150 |
if (getInputColorInterpretation().hasAlphaBand()) {
|
|
153 | 151 |
try { |
154 |
outputBuffer.getBand(3).copyFrom(this.buffer.getBand(colorInterpretation.getAlphaBand()));
|
|
152 |
getOutputBuffer().getBand(3).copyFrom(this.getInputBuffer().getBand(getInputColorInterpretation().getAlphaBand()));
|
|
155 | 153 |
} catch (BandException e) { |
156 | 154 |
throw new ProcessingOperationException(e); |
157 | 155 |
} |
158 | 156 |
} |
159 | 157 |
Object[] rowBandsBuffer = new Object[3]; |
160 | 158 |
|
161 |
for (int row = 0; row < this.buffer.getRows(); row++) {
|
|
162 |
if(colorInterpretation.isGray()){
|
|
163 |
Band bufferBandGray = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.GRAY_BAND));
|
|
159 |
for (int row = 0; row < this.getInputBuffer().getRows(); row++) {
|
|
160 |
if(getInputColorInterpretation().isGray()){
|
|
161 |
Band bufferBandGray = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.GRAY_BAND));
|
|
164 | 162 |
rowBandsBuffer[0] = bufferBandGray.createRowBuffer(); |
165 | 163 |
bufferBandGray.fetchRow(row, rowBandsBuffer[0]); |
166 | 164 |
rowBandsBuffer[1] = bufferBandGray.createRowBuffer(); |
167 | 165 |
bufferBandGray.fetchRow(row, rowBandsBuffer[0]); |
168 | 166 |
rowBandsBuffer[2] = bufferBandGray.createRowBuffer(); |
169 | 167 |
bufferBandGray.fetchRow(row, rowBandsBuffer[0]); |
170 |
} else if (colorInterpretation.isRGB()){
|
|
171 |
Band bufferBandRed = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.RED_BAND));
|
|
168 |
} else if (getInputColorInterpretation().isRGB()){
|
|
169 |
Band bufferBandRed = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.RED_BAND));
|
|
172 | 170 |
rowBandsBuffer[0] = bufferBandRed.createRowBuffer(); |
173 | 171 |
bufferBandRed.fetchRow(row, rowBandsBuffer[0]); |
174 |
Band bufferBandGreen = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.GREEN_BAND));
|
|
172 |
Band bufferBandGreen = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.GREEN_BAND));
|
|
175 | 173 |
rowBandsBuffer[1] = bufferBandGreen.createRowBuffer(); |
176 | 174 |
bufferBandGreen.fetchRow(row, rowBandsBuffer[1]); |
177 |
Band bufferBandBlue = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.BLUE_BAND));
|
|
175 |
Band bufferBandBlue = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.BLUE_BAND));
|
|
178 | 176 |
rowBandsBuffer[2] = bufferBandBlue.createRowBuffer(); |
179 | 177 |
bufferBandBlue.fetchRow(row, rowBandsBuffer[2]); |
180 | 178 |
} else { //No deber?a pasar por aqu? |
181 | 179 |
throw new UnsupportedOperationException("The color interpretation of input buffer isn't RGB nor GRAYSCALE"); |
182 | 180 |
} |
183 | 181 |
|
184 |
List<Object> outputRowBuffers = new ArrayList<Object>();
|
|
182 |
List<Object> outputRowBuffers = new ArrayList<>(); |
|
185 | 183 |
for (int band = 0; band<3; band++){ |
186 |
Band outputBufferBand = outputBuffer.getBand(band);
|
|
184 |
Band outputBufferBand = getOutputBuffer().getBand(band);
|
|
187 | 185 |
Object outputRowBuffer = outputBufferBand.createRowBuffer(); |
188 | 186 |
outputRowBuffers.add(outputRowBuffer); |
189 | 187 |
} |
... | ... | |
191 | 189 |
processRow(rowBandsBuffer, outputRowBuffers); |
192 | 190 |
|
193 | 191 |
for (int band = 0; band<3; band++){ |
194 |
Band outputBufferBand = outputBuffer.getBand(band);
|
|
192 |
Band outputBufferBand = getOutputBuffer().getBand(band);
|
|
195 | 193 |
outputBufferBand.putRow(row, outputRowBuffers.get(band)); |
196 | 194 |
} |
197 | 195 |
|
... | ... | |
209 | 207 |
* @param band |
210 | 208 |
* @return |
211 | 209 |
*/ |
210 |
@Override |
|
212 | 211 |
protected boolean isProcessableBand(int band) { |
213 |
return isRGBorGrayBand(band) && this.buffer.getBandTypes()[band] == BufferManager.TYPE_BYTE;
|
|
212 |
return isRGBorGrayBand(band) && this.getInputBuffer().getBandTypes()[band] == BufferManager.TYPE_BYTE;
|
|
214 | 213 |
} |
215 | 214 |
|
216 | 215 |
protected boolean isRGBorGrayBand(int band) { |
217 |
String bandColorInterpretation = colorInterpretation.get(band);
|
|
216 |
String bandColorInterpretation = getInputColorInterpretation().get(band);
|
|
218 | 217 |
return (bandColorInterpretation.equals(ColorInterpretation.RED_BAND) || |
219 | 218 |
bandColorInterpretation.equals(ColorInterpretation.GREEN_BAND) || |
220 | 219 |
bandColorInterpretation.equals(ColorInterpretation.BLUE_BAND) || |
Also available in: Unified diff