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/colortable/ColorTableOperation.java
ColorTableOperation.java | ||
---|---|---|
23 | 23 |
package org.gvsig.raster.lib.legend.impl.operations.colortable; |
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; |
... | ... | |
35 | 34 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException; |
36 | 35 |
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory; |
37 | 36 |
import org.gvsig.raster.lib.buffer.spi.exceptions.ProcessingOperationException; |
38 |
import org.gvsig.raster.lib.buffer.spi.operations.AbstractOperation; |
|
39 | 37 |
import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
40 | 38 |
import org.gvsig.raster.lib.legend.api.RasterLegendManager; |
41 | 39 |
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation; |
42 |
import org.gvsig.raster.lib.legend.impl.ColorManager; |
|
43 |
import org.gvsig.raster.lib.legend.impl.RasterLegendManagerServices; |
|
44 | 40 |
import org.gvsig.raster.lib.legend.spi.AbstractColoredOperation; |
45 | 41 |
import org.gvsig.tools.locator.LocatorException; |
46 | 42 |
|
... | ... | |
59 | 55 |
* |
60 | 56 |
*/ |
61 | 57 |
public ColorTableOperation(OperationFactory factory) { |
62 |
this.factory = factory;
|
|
58 |
super(factory);
|
|
63 | 59 |
} |
64 | 60 |
|
65 | 61 |
@Override |
... | ... | |
69 | 65 |
RasterLegendManager legendManager = RasterLegendLocator.getRasterLegendManager(); |
70 | 66 |
|
71 | 67 |
try { |
72 |
if (!colorInterpretation.isPalette()) {
|
|
68 |
if (!getInputColorInterpretation().isPalette()) {
|
|
73 | 69 |
throw new UnsupportedOperationException("The color interpretation of input buffer isn't Palette"); |
74 | 70 |
} |
75 | 71 |
|
76 |
int bandType = this.buffer.getBand(colorInterpretation.getPaletteBand()).getDataType();
|
|
72 |
int bandType = this.getInputBuffer().getBand(getInputColorInterpretation().getPaletteBand()).getDataType();
|
|
77 | 73 |
switch (bandType) { |
78 | 74 |
case BufferManager.TYPE_BYTE: |
79 | 75 |
rowProcessor = new ByteRowProcessor(); |
... | ... | |
94 | 90 |
rowProcessor = new DoubleRowProcessor(); |
95 | 91 |
break; |
96 | 92 |
default: |
97 |
throw new IllegalArgumentException("Unknow type of band '"+colorInterpretation.getPaletteBand()+"'");
|
|
93 |
throw new IllegalArgumentException("Unknow type of band '"+getInputColorInterpretation().getPaletteBand()+"'");
|
|
98 | 94 |
} |
99 | 95 |
|
100 | 96 |
|
101 |
int sourceBands = this.buffer.getBandCount();
|
|
102 |
NoData[] sourceNoDatas = this.buffer.getBandNoData();
|
|
103 |
int[] sourceTypes = this.buffer.getBandTypes();
|
|
97 |
int sourceBands = this.getInputBuffer().getBandCount();
|
|
98 |
NoData[] sourceNoDatas = this.getInputBuffer().getBandNoData();
|
|
99 |
// int[] sourceTypes = this.getInputBuffer().getBandTypes();
|
|
104 | 100 |
|
105 |
List<String> colorInterpretations = new ArrayList<String>();
|
|
106 |
List<NoData> noDatas = new ArrayList<NoData>();
|
|
107 |
List<Integer> types = new ArrayList<Integer>();
|
|
101 |
List<String> colorInterpretations = new ArrayList<>(); |
|
102 |
List<NoData> noDatas = new ArrayList<>(); |
|
103 |
List<Integer> types = new ArrayList<>(); |
|
108 | 104 |
|
109 | 105 |
colorInterpretations.add(ColorInterpretation.RED_BAND); |
110 | 106 |
colorInterpretations.add(ColorInterpretation.GREEN_BAND); |
... | ... | |
121 | 117 |
noDatas.add(null); |
122 | 118 |
noDatas.add(null); |
123 | 119 |
|
124 |
// if (colorInterpretation.hasAlphaBand()) {
|
|
125 |
// int alphaBand = colorInterpretation.getAlphaBand();
|
|
120 |
// if (getInputColorInterpretation().hasAlphaBand()) {
|
|
121 |
// int alphaBand = getInputColorInterpretation().getAlphaBand();
|
|
126 | 122 |
// if(sourceTypes[alphaBand]!=BufferManager.TYPE_BYTE){ |
127 | 123 |
// throw new UnsupportedOperationException("The type of ALPHA band isn't BYTE"); |
128 | 124 |
// } |
... | ... | |
131 | 127 |
// noDatas.add(sourceNoDatas[alphaBand]); |
132 | 128 |
// } |
133 | 129 |
|
134 |
if (copyUnprocessedBands) {
|
|
130 |
if (mustCopyUnprocessedBands()) {
|
|
135 | 131 |
for (int band = 0; band < sourceBands; band++) { |
136 | 132 |
if (!isProcessableBand(band)) { |
137 | 133 |
colorInterpretations.add(ColorInterpretation.UNDEFINED_BAND); |
138 | 134 |
noDatas.add(sourceNoDatas[band]); |
139 |
types.add(this.buffer.getBandTypes()[band]);
|
|
135 |
types.add(this.getInputBuffer().getBandTypes()[band]);
|
|
140 | 136 |
} |
141 | 137 |
} |
142 | 138 |
} |
143 | 139 |
|
144 |
outputColorInterpretation = |
|
145 |
legendManager.createColorInterpretation(colorInterpretations.toArray(new String[0])); |
|
146 |
this.parameters.setDynValue(OUTPUT_COLOR_INTERPRETATION_PARAM, outputColorInterpretation); |
|
147 |
int[] typesInt = new int[types.size()]; |
|
148 |
for (Iterator<Integer> iterator = types.iterator(); iterator.hasNext();) { |
|
149 |
int i = 0; |
|
150 |
Integer type = (Integer) iterator.next(); |
|
151 |
typesInt[i] = type.intValue(); |
|
152 |
} |
|
140 |
setOutputColorInterpretation( |
|
141 |
legendManager.createColorInterpretation(colorInterpretations)); |
|
142 |
this.setParameter(OUTPUT_COLOR_INTERPRETATION_PARAM, getOutputColorInterpretation()); |
|
153 | 143 |
|
154 |
this.outputBuffer = |
|
155 |
manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), typesInt, |
|
156 |
noDatas.toArray(new NoData[0]), this.buffer.getProjection(), this.buffer.getEnvelope()); |
|
144 |
this.setOutputBuffer( |
|
145 |
manager.createBuffer( |
|
146 |
this.getInputBuffer().getRows(), |
|
147 |
this.getInputBuffer().getColumns(), |
|
148 |
this.getTypesAsArray(types), |
|
149 |
this.getNoDatasAsArray(noDatas), |
|
150 |
this.getInputBuffer().getProjection(), |
|
151 |
this.getInputBuffer().getEnvelope())); |
|
157 | 152 |
} catch (LocatorException | BufferException | CreateEnvelopeException e) { |
158 | 153 |
throw new ProcessingOperationException(e); |
159 | 154 |
} |
... | ... | |
166 | 161 |
|
167 | 162 |
// List<Integer> bandsToProcess = new ArrayList<Integer>(); |
168 | 163 |
|
169 |
if (copyUnprocessedBands) {
|
|
170 |
int bands = this.buffer.getBandCount();
|
|
171 |
int outBand = 4; //colorInterpretation.hasAlphaBand() ? 4 : 3;
|
|
164 |
if (mustCopyUnprocessedBands()) {
|
|
165 |
int bands = this.getInputBuffer().getBandCount();
|
|
166 |
int outBand = 4; //getInputColorInterpretation().hasAlphaBand() ? 4 : 3;
|
|
172 | 167 |
for (int band = 0; band < bands; band++) { |
173 | 168 |
if (!isProcessableBand(band)) { |
174 |
outputBuffer.getBand(outBand).copyFrom(this.buffer.getBand(band));
|
|
169 |
getOutputBuffer().getBand(outBand).copyFrom(this.getInputBuffer().getBand(band));
|
|
175 | 170 |
outBand++; |
176 | 171 |
} |
177 | 172 |
} |
178 | 173 |
} |
179 | 174 |
|
180 |
for (int row = 0; row < this.buffer.getRows(); row++) {
|
|
181 |
Band bufferPaletteBand = buffer.getBand(colorInterpretation.getPaletteBand());
|
|
175 |
for (int row = 0; row < this.getInputBuffer().getRows(); row++) {
|
|
176 |
Band bufferPaletteBand = getInputBuffer().getBand(getInputColorInterpretation().getPaletteBand());
|
|
182 | 177 |
Object rowBandBuffer = bufferPaletteBand.createRowBuffer(); |
183 | 178 |
bufferPaletteBand.fetchRow(row, rowBandBuffer); |
184 | 179 |
|
185 |
List<Object> outputRowBuffers = new ArrayList<Object>();
|
|
180 |
List<Object> outputRowBuffers = new ArrayList<>(); |
|
186 | 181 |
for (int band = 0; band < 4; band++) { |
187 |
Band outputBufferBand = outputBuffer.getBand(band);
|
|
182 |
Band outputBufferBand = getOutputBuffer().getBand(band);
|
|
188 | 183 |
Object outputRowBuffer = outputBufferBand.createRowBuffer(); |
189 | 184 |
outputRowBuffers.add(outputRowBuffer); |
190 | 185 |
} |
... | ... | |
192 | 187 |
rowProcessor.processRow(rowBandBuffer, outputRowBuffers); |
193 | 188 |
|
194 | 189 |
for (int band = 0; band < 4; band++) { |
195 |
Band outputBufferBand = outputBuffer.getBand(band);
|
|
190 |
Band outputBufferBand = getOutputBuffer().getBand(band);
|
|
196 | 191 |
outputBufferBand.putRow(row, outputRowBuffers.get(band)); |
197 | 192 |
} |
198 | 193 |
|
... | ... | |
212 | 207 |
* @param band |
213 | 208 |
* @return |
214 | 209 |
*/ |
215 |
private boolean isProcessableBand(int band) { |
|
210 |
@Override |
|
211 |
protected boolean isProcessableBand(int band) { |
|
216 | 212 |
return isPaletteBand(band); |
217 | 213 |
} |
218 | 214 |
|
219 | 215 |
private boolean isPaletteBand(int band) { |
220 |
return (colorInterpretation.getPaletteBand() == band);
|
|
216 |
return (getInputColorInterpretation().getPaletteBand() == band);
|
|
221 | 217 |
} |
222 | 218 |
|
223 | 219 |
|
... | ... | |
231 | 227 |
NoData noData; |
232 | 228 |
|
233 | 229 |
public AbstractRowProcessor() { |
234 |
noData = buffer.getBand(colorInterpretation.getPaletteBand()).getNoData();
|
|
230 |
noData = getInputBuffer().getBand(getInputColorInterpretation().getPaletteBand()).getNoData();
|
|
235 | 231 |
} |
236 | 232 |
} |
237 | 233 |
|
... | ... | |
265 | 261 |
} |
266 | 262 |
} |
267 | 263 |
|
268 |
return colorInterpretation.getPalette().getRGBA(0xFF & (byte)value);
|
|
264 |
return getInputColorInterpretation().getPalette().getRGBA(0xFF & (byte)value);
|
|
269 | 265 |
} |
270 | 266 |
|
271 | 267 |
} |
... | ... | |
295 | 291 |
return result; |
296 | 292 |
} |
297 | 293 |
|
298 |
return colorInterpretation.getPalette().getRGBA(value);
|
|
294 |
return getInputColorInterpretation().getPalette().getRGBA(value);
|
|
299 | 295 |
} |
300 | 296 |
|
301 | 297 |
} |
... | ... | |
325 | 321 |
return result; |
326 | 322 |
} |
327 | 323 |
|
328 |
return colorInterpretation.getPalette().getRGBA(0xFFFF & (byte)value);
|
|
324 |
return getInputColorInterpretation().getPalette().getRGBA(0xFFFF & (byte)value);
|
|
329 | 325 |
} |
330 | 326 |
|
331 | 327 |
} |
... | ... | |
355 | 351 |
return result; |
356 | 352 |
} |
357 | 353 |
|
358 |
return colorInterpretation.getPalette().getRGBA(value);
|
|
354 |
return getInputColorInterpretation().getPalette().getRGBA(value);
|
|
359 | 355 |
} |
360 | 356 |
|
361 | 357 |
} |
... | ... | |
384 | 380 |
return result; |
385 | 381 |
} |
386 | 382 |
|
387 |
return colorInterpretation.getPalette().getRGBA(value);
|
|
383 |
return getInputColorInterpretation().getPalette().getRGBA(value);
|
|
388 | 384 |
} |
389 | 385 |
|
390 | 386 |
} |
... | ... | |
415 | 411 |
return result; |
416 | 412 |
} |
417 | 413 |
|
418 |
return colorInterpretation.getPalette().getRGBA(value);
|
|
414 |
return getInputColorInterpretation().getPalette().getRGBA(value);
|
|
419 | 415 |
} |
420 | 416 |
|
421 | 417 |
} |
Also available in: Unified diff