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/hsltorgb/HSLToRGBOperation.java
HSLToRGBOperation.java | ||
---|---|---|
56 | 56 |
* |
57 | 57 |
*/ |
58 | 58 |
public HSLToRGBOperation(OperationFactory factory) { |
59 |
this.factory = factory;
|
|
59 |
super(factory);
|
|
60 | 60 |
} |
61 | 61 |
|
62 | 62 |
@Override |
... | ... | |
66 | 66 |
RasterLegendManager legendManager = RasterLegendLocator.getRasterLegendManager(); |
67 | 67 |
|
68 | 68 |
try { |
69 |
if (!colorInterpretation.isHSL()) {
|
|
70 |
throw new UnsupportedOperationException("The color interpretation of input buffer isn't HSL");
|
|
69 |
if (!getInputColorInterpretation().isHSL()) {
|
|
70 |
throw new UnsupportedOperationException("The color interpretation of input getInputBuffer() isn't HSL");
|
|
71 | 71 |
} |
72 | 72 |
|
73 |
int[] inputBandTypes = buffer.getBandTypes();
|
|
74 |
if (inputBandTypes[colorInterpretation.getBand(ColorInterpretation.HUE_BAND)] != BufferManager.TYPE_BYTE
|
|
75 |
|| inputBandTypes[colorInterpretation.getBand(ColorInterpretation.SATURATION_BAND)] != BufferManager.TYPE_BYTE
|
|
76 |
|| inputBandTypes[colorInterpretation.getBand(ColorInterpretation.LIGHTNESS_BAND)] != BufferManager.TYPE_BYTE) {
|
|
73 |
int[] inputBandTypes = getInputBuffer().getBandTypes();
|
|
74 |
if (inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.HUE_BAND)] != BufferManager.TYPE_BYTE
|
|
75 |
|| inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.SATURATION_BAND)] != BufferManager.TYPE_BYTE
|
|
76 |
|| inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.LIGHTNESS_BAND)] != BufferManager.TYPE_BYTE) {
|
|
77 | 77 |
throw new UnsupportedOperationException("The type of bands isn't BYTE"); |
78 | 78 |
} |
79 | 79 |
|
80 |
int sourceBands = this.buffer.getBandCount();
|
|
81 |
NoData[] sourceNoDatas = this.buffer.getBandNoData();
|
|
82 |
int[] sourceTypes = this.buffer.getBandTypes();
|
|
80 |
int sourceBands = this.getInputBuffer().getBandCount();
|
|
81 |
NoData[] sourceNoDatas = this.getInputBuffer().getBandNoData();
|
|
82 |
int[] sourceTypes = this.getInputBuffer().getBandTypes();
|
|
83 | 83 |
|
84 | 84 |
List<String> colorInterpretations = new ArrayList<String>(); |
85 | 85 |
List<NoData> noDatas = new ArrayList<NoData>(); |
... | ... | |
97 | 97 |
noDatas.add(null); |
98 | 98 |
noDatas.add(null); |
99 | 99 |
|
100 |
if (colorInterpretation.hasAlphaBand()) {
|
|
101 |
int alphaBand = colorInterpretation.getAlphaBand();
|
|
100 |
if (getInputColorInterpretation().hasAlphaBand()) {
|
|
101 |
int alphaBand = getInputColorInterpretation().getAlphaBand();
|
|
102 | 102 |
if(sourceTypes[alphaBand]!=BufferManager.TYPE_BYTE){ |
103 | 103 |
throw new UnsupportedOperationException("The type of ALPHA band isn't BYTE"); |
104 | 104 |
} |
... | ... | |
107 | 107 |
noDatas.add(sourceNoDatas[alphaBand]); |
108 | 108 |
} |
109 | 109 |
|
110 |
if (copyUnprocessedBands) {
|
|
110 |
if (mustCopyUnprocessedBands()) {
|
|
111 | 111 |
for (int band = 0; band < sourceBands; band++) { |
112 |
if (!isProcessableBand(band) && !colorInterpretation.isAlphaInterpretation(band)) {
|
|
113 |
colorInterpretations.add(colorInterpretation.get(band));
|
|
112 |
if (!isProcessableBand(band) && !getInputColorInterpretation().isAlphaInterpretation(band)) {
|
|
113 |
colorInterpretations.add(getInputColorInterpretation().get(band));
|
|
114 | 114 |
noDatas.add(sourceNoDatas[band]); |
115 |
types.add(this.buffer.getBandTypes()[band]);
|
|
115 |
types.add(this.getInputBuffer().getBandTypes()[band]);
|
|
116 | 116 |
} |
117 | 117 |
} |
118 | 118 |
} |
119 | 119 |
|
120 |
outputColorInterpretation = |
|
121 |
legendManager.createColorInterpretation(colorInterpretations.toArray(new String[0])); |
|
122 |
this.parameters.setDynValue(OUTPUT_COLOR_INTERPRETATION_PARAM, outputColorInterpretation); |
|
123 |
int[] typesInt = new int[types.size()]; |
|
124 |
for (Iterator<Integer> iterator = types.iterator(); iterator.hasNext();) { |
|
125 |
int i = 0; |
|
126 |
Integer type = (Integer) iterator.next(); |
|
127 |
typesInt[i] = type.intValue(); |
|
128 |
} |
|
129 |
|
|
130 |
this.outputBuffer = |
|
131 |
manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), typesInt, |
|
132 |
noDatas.toArray(new NoData[0]), this.buffer.getProjection(), this.buffer.getEnvelope()); |
|
133 |
} catch (LocatorException | BufferException | CreateEnvelopeException e) { |
|
120 |
setOutputColorInterpretation( |
|
121 |
legendManager.createColorInterpretation(colorInterpretations)); |
|
122 |
this.setParameter(OUTPUT_COLOR_INTERPRETATION_PARAM, getOutputColorInterpretation()); |
|
123 |
this.setOutputBuffer( |
|
124 |
manager.createBuffer( |
|
125 |
this.getInputBuffer().getRows(), |
|
126 |
this.getInputBuffer().getColumns(), |
|
127 |
this.getTypesAsArray(types), |
|
128 |
this.getNoDatasAsArray(noDatas), |
|
129 |
this.getInputBuffer().getProjection(), |
|
130 |
this.getInputBuffer().getEnvelope())); |
|
131 |
} catch (Exception e) { |
|
134 | 132 |
throw new ProcessingOperationException(e); |
135 | 133 |
} |
136 | 134 |
} |
... | ... | |
142 | 140 |
|
143 | 141 |
// List<Integer> bandsToProcess = new ArrayList<Integer>(); |
144 | 142 |
|
145 |
if (copyUnprocessedBands) {
|
|
146 |
int bands = this.buffer.getBandCount();
|
|
147 |
int outBand = colorInterpretation.hasAlphaBand() ? 4 : 3;
|
|
143 |
if (mustCopyUnprocessedBands()) {
|
|
144 |
int bands = this.getInputBuffer().getBandCount();
|
|
145 |
int outBand = getInputColorInterpretation().hasAlphaBand() ? 4 : 3;
|
|
148 | 146 |
for (int band = 0; band < bands; band++) { |
149 |
if (colorInterpretation.isAlphaInterpretation(band)) {
|
|
150 |
outputBuffer.getBand(outputColorInterpretation.getAlphaBand()).copyFrom(
|
|
151 |
this.buffer.getBand(band));
|
|
147 |
if (getInputColorInterpretation().isAlphaInterpretation(band)) {
|
|
148 |
getOutputBuffer().getBand(getOutputColorInterpretation().getAlphaBand()).copyFrom(
|
|
149 |
this.getInputBuffer().getBand(band));
|
|
152 | 150 |
} else if (!isProcessableBand(band)) { |
153 |
outputBuffer.getBand(outBand).copyFrom(this.buffer.getBand(band));
|
|
151 |
getOutputBuffer().getBand(outBand).copyFrom(this.getInputBuffer().getBand(band));
|
|
154 | 152 |
outBand++; |
155 | 153 |
} |
156 | 154 |
} |
... | ... | |
158 | 156 |
|
159 | 157 |
Object[] rowBandsBuffer = new Object[3]; |
160 | 158 |
|
161 |
for (int row = 0; row < this.buffer.getRows(); row++) {
|
|
162 |
Band bufferBandHue = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.HUE_BAND));
|
|
159 |
for (int row = 0; row < this.getInputBuffer().getRows(); row++) {
|
|
160 |
Band bufferBandHue = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.HUE_BAND));
|
|
163 | 161 |
rowBandsBuffer[0] = bufferBandHue.createRowBuffer(); |
164 | 162 |
bufferBandHue.fetchRow(row, rowBandsBuffer[0]); |
165 |
Band bufferBandSaturation = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.SATURATION_BAND));
|
|
163 |
Band bufferBandSaturation = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.SATURATION_BAND));
|
|
166 | 164 |
rowBandsBuffer[1] = bufferBandSaturation.createRowBuffer(); |
167 | 165 |
bufferBandSaturation.fetchRow(row, rowBandsBuffer[1]); |
168 |
Band bufferBandLightness = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.LIGHTNESS_BAND));
|
|
166 |
Band bufferBandLightness = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.LIGHTNESS_BAND));
|
|
169 | 167 |
rowBandsBuffer[2] = bufferBandLightness.createRowBuffer(); |
170 | 168 |
bufferBandLightness.fetchRow(row, rowBandsBuffer[2]); |
171 | 169 |
|
172 | 170 |
List<Object> outputRowBuffers = new ArrayList<Object>(); |
173 | 171 |
for (int band = 0; band < 3; band++) { |
174 |
Band outputBufferBand = outputBuffer.getBand(band);
|
|
172 |
Band outputBufferBand = getOutputBuffer().getBand(band);
|
|
175 | 173 |
Object outputRowBuffer = outputBufferBand.createRowBuffer(); |
176 | 174 |
outputRowBuffers.add(outputRowBuffer); |
177 | 175 |
} |
... | ... | |
179 | 177 |
processRow(rowBandsBuffer, outputRowBuffers); |
180 | 178 |
|
181 | 179 |
for (int band = 0; band < 3; band++) { |
182 |
Band outputBufferBand = outputBuffer.getBand(band);
|
|
180 |
Band outputBufferBand = getOutputBuffer().getBand(band);
|
|
183 | 181 |
outputBufferBand.putRow(row, outputRowBuffers.get(band)); |
184 | 182 |
} |
185 | 183 |
|
... | ... | |
216 | 214 |
* @param band |
217 | 215 |
* @return |
218 | 216 |
*/ |
219 |
private boolean isProcessableBand(int band) { |
|
220 |
return isHSLBand(band) && this.buffer.getBandTypes()[band] == BufferManager.TYPE_BYTE; |
|
217 |
@Override |
|
218 |
protected boolean isProcessableBand(int band) { |
|
219 |
return isHSLBand(band) && this.getInputBuffer().getBandTypes()[band] == BufferManager.TYPE_BYTE; |
|
221 | 220 |
} |
222 | 221 |
|
223 | 222 |
private boolean isHSLBand(int band) { |
224 |
String bandColorInterpretation = colorInterpretation.get(band);
|
|
223 |
String bandColorInterpretation = getInputColorInterpretation().get(band);
|
|
225 | 224 |
return (bandColorInterpretation.equals(ColorInterpretation.HUE_BAND) |
226 | 225 |
|| bandColorInterpretation.equals(ColorInterpretation.SATURATION_BAND) |
227 | 226 |
|| bandColorInterpretation.equals(ColorInterpretation.LIGHTNESS_BAND)); |
Also available in: Unified diff