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/rgbtohsl/RGBToHSLOperation.java
RGBToHSLOperation.java | ||
---|---|---|
23 | 23 |
package org.gvsig.raster.lib.legend.impl.operations.rgbtohsl; |
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; |
... | ... | |
55 | 54 |
* |
56 | 55 |
*/ |
57 | 56 |
public RGBToHSLOperation(OperationFactory factory) { |
58 |
this.factory = factory;
|
|
57 |
super(factory);
|
|
59 | 58 |
} |
60 | 59 |
|
61 | 60 |
@Override |
... | ... | |
65 | 64 |
RasterLegendManager legendManager = RasterLegendLocator.getRasterLegendManager(); |
66 | 65 |
|
67 | 66 |
try { |
68 |
if (!(colorInterpretation.isGray() || colorInterpretation.isRGB())) {
|
|
67 |
if (!(getInputColorInterpretation().isGray() || getInputColorInterpretation().isRGB())) {
|
|
69 | 68 |
throw new UnsupportedOperationException( |
70 | 69 |
"The color interpretation of input buffer isn't RGB nor GRAYSCALE"); |
71 | 70 |
} |
72 | 71 |
|
73 |
int[] inputBandTypes = buffer.getBandTypes();
|
|
74 |
if (colorInterpretation.isGray()) {
|
|
75 |
if (inputBandTypes[colorInterpretation.getBand(ColorInterpretation.GRAY_BAND)] != BufferManager.TYPE_BYTE) {
|
|
72 |
int[] inputBandTypes = getInputBuffer().getBandTypes();
|
|
73 |
if (getInputColorInterpretation().isGray()) {
|
|
74 |
if (inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.GRAY_BAND)] != BufferManager.TYPE_BYTE) {
|
|
76 | 75 |
throw new UnsupportedOperationException("The type of GRAY band isn't BYTE"); |
77 | 76 |
} |
78 |
} else if (colorInterpretation.isRGB()) {
|
|
79 |
if (inputBandTypes[colorInterpretation.getBand(ColorInterpretation.RED_BAND)] != BufferManager.TYPE_BYTE
|
|
80 |
|| inputBandTypes[colorInterpretation.getBand(ColorInterpretation.GREEN_BAND)] != BufferManager.TYPE_BYTE
|
|
81 |
|| inputBandTypes[colorInterpretation.getBand(ColorInterpretation.BLUE_BAND)] != BufferManager.TYPE_BYTE) {
|
|
77 |
} else if (getInputColorInterpretation().isRGB()) {
|
|
78 |
if (inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.RED_BAND)] != BufferManager.TYPE_BYTE
|
|
79 |
|| inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.GREEN_BAND)] != BufferManager.TYPE_BYTE
|
|
80 |
|| inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.BLUE_BAND)] != BufferManager.TYPE_BYTE) {
|
|
82 | 81 |
throw new UnsupportedOperationException("The type of RGB bands isn't BYTE"); |
83 | 82 |
} |
84 | 83 |
} else { |
... | ... | |
86 | 85 |
"The color interpretation of input buffer isn't RGB nor GRAYSCALE"); |
87 | 86 |
} |
88 | 87 |
|
89 |
int sourceBands = this.buffer.getBandCount();
|
|
90 |
NoData[] sourceNoDatas = this.buffer.getBandNoData();
|
|
91 |
int[] sourceTypes = this.buffer.getBandTypes();
|
|
88 |
int sourceBands = this.getInputBuffer().getBandCount();
|
|
89 |
NoData[] sourceNoDatas = this.getInputBuffer().getBandNoData();
|
|
90 |
int[] sourceTypes = this.getInputBuffer().getBandTypes();
|
|
92 | 91 |
|
93 |
List<String> colorInterpretations = new ArrayList<String>();
|
|
94 |
List<NoData> noDatas = new ArrayList<NoData>();
|
|
95 |
List<Integer> types = new ArrayList<Integer>();
|
|
92 |
List<String> colorInterpretations = new ArrayList<>(); |
|
93 |
List<NoData> noDatas = new ArrayList<>(); |
|
94 |
List<Integer> types = new ArrayList<>(); |
|
96 | 95 |
|
97 | 96 |
colorInterpretations.add(ColorInterpretation.HUE_BAND); |
98 | 97 |
colorInterpretations.add(ColorInterpretation.SATURATION_BAND); |
... | ... | |
106 | 105 |
noDatas.add(null); |
107 | 106 |
noDatas.add(null); |
108 | 107 |
|
109 |
if (colorInterpretation.hasAlphaBand()) {
|
|
110 |
int alphaBand = colorInterpretation.getAlphaBand();
|
|
108 |
if (getInputColorInterpretation().hasAlphaBand()) {
|
|
109 |
int alphaBand = getInputColorInterpretation().getAlphaBand();
|
|
111 | 110 |
if(sourceTypes[alphaBand]!=BufferManager.TYPE_BYTE){ |
112 | 111 |
throw new UnsupportedOperationException("The type of ALPHA band isn't BYTE"); |
113 | 112 |
} |
... | ... | |
116 | 115 |
noDatas.add(sourceNoDatas[alphaBand]); |
117 | 116 |
} |
118 | 117 |
|
119 |
if (copyUnprocessedBands) {
|
|
118 |
if (mustCopyUnprocessedBands()) {
|
|
120 | 119 |
for (int band = 0; band < sourceBands; band++) { |
121 |
if (!isProcessableBand(band) && !colorInterpretation.isAlphaInterpretation(band)) {
|
|
122 |
colorInterpretations.add(colorInterpretation.get(band));
|
|
120 |
if (!isProcessableBand(band) && !getInputColorInterpretation().isAlphaInterpretation(band)) {
|
|
121 |
colorInterpretations.add(getInputColorInterpretation().get(band));
|
|
123 | 122 |
noDatas.add(sourceNoDatas[band]); |
124 |
types.add(this.buffer.getBandTypes()[band]);
|
|
123 |
types.add(this.getInputBuffer().getBandTypes()[band]);
|
|
125 | 124 |
} |
126 | 125 |
} |
127 | 126 |
} |
128 | 127 |
|
129 |
outputColorInterpretation = |
|
130 |
legendManager.createColorInterpretation(colorInterpretations.toArray(new String[0])); |
|
131 |
this.parameters.setDynValue(OUTPUT_COLOR_INTERPRETATION_PARAM, outputColorInterpretation); |
|
132 |
int[] typesInt = new int[types.size()]; |
|
133 |
for (Iterator<Integer> iterator = types.iterator(); iterator.hasNext();) { |
|
134 |
int i = 0; |
|
135 |
Integer type = (Integer) iterator.next(); |
|
136 |
typesInt[i] = type.intValue(); |
|
137 |
} |
|
128 |
setOutputColorInterpretation( |
|
129 |
legendManager.createColorInterpretation(colorInterpretations)); |
|
130 |
this.setParameter(OUTPUT_COLOR_INTERPRETATION_PARAM, getOutputColorInterpretation()); |
|
138 | 131 |
|
139 |
this.outputBuffer = |
|
140 |
manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), typesInt, |
|
141 |
noDatas.toArray(new NoData[0]), this.buffer.getProjection(), this.buffer.getEnvelope()); |
|
132 |
this.setOutputBuffer( |
|
133 |
manager.createBuffer( |
|
134 |
this.getInputBuffer().getRows(), |
|
135 |
this.getInputBuffer().getColumns(), |
|
136 |
this.getTypesAsArray(types), |
|
137 |
this.getNoDatasAsArray(noDatas), |
|
138 |
this.getInputBuffer().getProjection(), |
|
139 |
this.getInputBuffer().getEnvelope())); |
|
142 | 140 |
} catch (LocatorException | BufferException | CreateEnvelopeException e) { |
143 | 141 |
throw new ProcessingOperationException(e); |
144 | 142 |
} |
... | ... | |
151 | 149 |
|
152 | 150 |
// List<Integer> bandsToProcess = new ArrayList<Integer>(); |
153 | 151 |
|
154 |
if (copyUnprocessedBands) {
|
|
155 |
int bands = this.buffer.getBandCount();
|
|
156 |
int outBand = colorInterpretation.hasAlphaBand() ? 5 : 4;
|
|
152 |
if (mustCopyUnprocessedBands()) {
|
|
153 |
int bands = this.getInputBuffer().getBandCount();
|
|
154 |
int outBand = getInputColorInterpretation().hasAlphaBand() ? 5 : 4;
|
|
157 | 155 |
for (int band = 0; band < bands; band++) { |
158 |
if (colorInterpretation.isAlphaInterpretation(band)) {
|
|
159 |
outputBuffer.getBand(outputColorInterpretation.getAlphaBand()).copyFrom(
|
|
160 |
this.buffer.getBand(band));
|
|
156 |
if (getInputColorInterpretation().isAlphaInterpretation(band)) {
|
|
157 |
getOutputBuffer().getBand(getOutputColorInterpretation().getAlphaBand()).copyFrom(
|
|
158 |
this.getInputBuffer().getBand(band));
|
|
161 | 159 |
} else if (!isProcessableBand(band)) { |
162 |
outputBuffer.getBand(outBand).copyFrom(this.buffer.getBand(band));
|
|
160 |
getOutputBuffer().getBand(outBand).copyFrom(this.getInputBuffer().getBand(band));
|
|
163 | 161 |
outBand++; |
164 | 162 |
} |
165 | 163 |
} |
... | ... | |
167 | 165 |
|
168 | 166 |
Object[] rowBandsBuffer = new Object[3]; |
169 | 167 |
|
170 |
for (int row = 0; row < this.buffer.getRows(); row++) {
|
|
171 |
if (colorInterpretation.isGray()) {
|
|
172 |
Band bufferBandGray = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.GRAY_BAND));
|
|
168 |
for (int row = 0; row < this.getInputBuffer().getRows(); row++) {
|
|
169 |
if (getInputColorInterpretation().isGray()) {
|
|
170 |
Band bufferBandGray = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.GRAY_BAND));
|
|
173 | 171 |
rowBandsBuffer[0] = bufferBandGray.createRowBuffer(); |
174 | 172 |
bufferBandGray.fetchRow(row, rowBandsBuffer[0]); |
175 | 173 |
rowBandsBuffer[1] = bufferBandGray.createRowBuffer(); |
... | ... | |
177 | 175 |
rowBandsBuffer[2] = bufferBandGray.createRowBuffer(); |
178 | 176 |
bufferBandGray.fetchRow(row, rowBandsBuffer[2]); |
179 | 177 |
} else { |
180 |
Band bufferBandRed = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.RED_BAND));
|
|
178 |
Band bufferBandRed = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.RED_BAND));
|
|
181 | 179 |
rowBandsBuffer[0] = bufferBandRed.createRowBuffer(); |
182 | 180 |
bufferBandRed.fetchRow(row, rowBandsBuffer[0]); |
183 |
Band bufferBandGreen = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.GREEN_BAND));
|
|
181 |
Band bufferBandGreen = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.GREEN_BAND));
|
|
184 | 182 |
rowBandsBuffer[1] = bufferBandGreen.createRowBuffer(); |
185 | 183 |
bufferBandGreen.fetchRow(row, rowBandsBuffer[1]); |
186 |
Band bufferBandBlue = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.BLUE_BAND));
|
|
184 |
Band bufferBandBlue = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.BLUE_BAND));
|
|
187 | 185 |
rowBandsBuffer[2] = bufferBandBlue.createRowBuffer(); |
188 | 186 |
bufferBandBlue.fetchRow(row, rowBandsBuffer[2]); |
189 | 187 |
} |
190 | 188 |
|
191 |
List<Object> outputRowBuffers = new ArrayList<Object>();
|
|
189 |
List<Object> outputRowBuffers = new ArrayList<>(); |
|
192 | 190 |
for (int band = 0; band < 3; band++) { |
193 |
Band outputBufferBand = outputBuffer.getBand(band);
|
|
191 |
Band outputBufferBand = getOutputBuffer().getBand(band);
|
|
194 | 192 |
Object outputRowBuffer = outputBufferBand.createRowBuffer(); |
195 | 193 |
outputRowBuffers.add(outputRowBuffer); |
196 | 194 |
} |
... | ... | |
198 | 196 |
processRow(rowBandsBuffer, outputRowBuffers); |
199 | 197 |
|
200 | 198 |
for (int band = 0; band < 3; band++) { |
201 |
Band outputBufferBand = outputBuffer.getBand(band);
|
|
199 |
Band outputBufferBand = getOutputBuffer().getBand(band);
|
|
202 | 200 |
outputBufferBand.putRow(row, outputRowBuffers.get(band)); |
203 | 201 |
} |
204 | 202 |
|
... | ... | |
233 | 231 |
* @param band |
234 | 232 |
* @return |
235 | 233 |
*/ |
236 |
private boolean isProcessableBand(int band) { |
|
237 |
return isRGBorGrayBand(band) && this.buffer.getBandTypes()[band] == BufferManager.TYPE_BYTE; |
|
234 |
@Override |
|
235 |
protected boolean isProcessableBand(int band) { |
|
236 |
return isRGBorGrayBand(band) && this.getInputBuffer().getBandTypes()[band] == BufferManager.TYPE_BYTE; |
|
238 | 237 |
} |
239 | 238 |
|
240 | 239 |
private boolean isRGBorGrayBand(int band) { |
241 |
String bandColorInterpretation = colorInterpretation.get(band);
|
|
240 |
String bandColorInterpretation = getInputColorInterpretation().get(band);
|
|
242 | 241 |
return (bandColorInterpretation.equals(ColorInterpretation.RED_BAND) |
243 | 242 |
|| bandColorInterpretation.equals(ColorInterpretation.GREEN_BAND) |
244 | 243 |
|| bandColorInterpretation.equals(ColorInterpretation.BLUE_BAND) || bandColorInterpretation |
Also available in: Unified diff