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