Revision 8682 org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.legend/org.gvsig.raster.lib.legend.impl/src/main/java/org/gvsig/raster/lib/legend/impl/operations/grayscale/GrayScaleOperation.java
GrayScaleOperation.java | ||
---|---|---|
34 | 34 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferException; |
35 | 35 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException; |
36 | 36 |
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory; |
37 |
import org.gvsig.raster.lib.buffer.impl.exceptions.ProcessingOperationException;
|
|
37 |
import org.gvsig.raster.lib.buffer.spi.exceptions.ProcessingOperationException;
|
|
38 | 38 |
import org.gvsig.raster.lib.buffer.spi.operations.AbstractOperation; |
39 | 39 |
import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
40 | 40 |
import org.gvsig.raster.lib.legend.api.RasterLegendManager; |
41 | 41 |
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation; |
42 |
import org.gvsig.raster.lib.legend.spi.AbstractColoredOperation; |
|
42 | 43 |
import org.gvsig.tools.locator.LocatorException; |
43 | 44 |
|
44 | 45 |
|
... | ... | |
46 | 47 |
* @author fdiaz |
47 | 48 |
* |
48 | 49 |
*/ |
49 |
public class GrayScaleOperation extends AbstractOperation { |
|
50 |
public class GrayScaleOperation extends AbstractColoredOperation {
|
|
50 | 51 |
|
51 |
static public String COLOR_INTERPRETATION_PARAM = "color_interpretation"; |
|
52 |
static public String COPY_UNPROCESSED_BANDS_PARAM = "copy_unprocessed_bands"; |
|
53 |
static public String OUTPUT_COLOR_INTERPRETATION_PARAM = "output_color_interpretation"; |
|
54 |
|
|
55 |
private ColorInterpretation colorInterpretation; |
|
56 |
private boolean copyUnprocessedBands; |
|
57 |
private ColorInterpretation outputColorInterpretation; |
|
58 |
|
|
59 | 52 |
/** |
60 | 53 |
* @param factory |
61 | 54 |
* |
... | ... | |
66 | 59 |
|
67 | 60 |
@Override |
68 | 61 |
public void preProcess() throws BufferOperationException { |
62 |
super.preProcess(); |
|
69 | 63 |
BufferManager manager = BufferLocator.getBufferManager(); |
70 | 64 |
RasterLegendManager legendManager = RasterLegendLocator.getRasterLegendManager(); |
71 | 65 |
|
72 |
colorInterpretation = (ColorInterpretation) this.parameters.getDynValue(COLOR_INTERPRETATION_PARAM); |
|
73 |
if(this.parameters.hasDynValue(COPY_UNPROCESSED_BANDS_PARAM)) { |
|
74 |
copyUnprocessedBands = (Boolean)this.parameters.getDynValue(COPY_UNPROCESSED_BANDS_PARAM); |
|
75 |
} else { |
|
76 |
copyUnprocessedBands = true; |
|
77 |
} |
|
78 | 66 |
try { |
79 | 67 |
|
80 |
if (!colorInterpretation.isRGB()) {
|
|
68 |
if (!(colorInterpretation.hasAnyRGBBand() || colorInterpretation.hasAnyGrayBand())) {
|
|
81 | 69 |
throw new UnsupportedOperationException( |
82 | 70 |
"The color interpretation of input buffer isn't RGB nor GRAYSCALE"); |
83 | 71 |
} |
84 | 72 |
|
85 | 73 |
int[] inputBandTypes = buffer.getBandTypes(); |
86 |
if (colorInterpretation.isRGB()) {
|
|
87 |
if (inputBandTypes[colorInterpretation.getBand(ColorInterpretation.RED_BAND)] != BufferManager.TYPE_BYTE
|
|
88 |
|| inputBandTypes[colorInterpretation.getBand(ColorInterpretation.GREEN_BAND)] != BufferManager.TYPE_BYTE
|
|
89 |
|| inputBandTypes[colorInterpretation.getBand(ColorInterpretation.BLUE_BAND)] != BufferManager.TYPE_BYTE) {
|
|
74 |
if (colorInterpretation.hasAnyRGBBand()) {
|
|
75 |
if ((colorInterpretation.getBand(ColorInterpretation.RED_BAND)>=0 && inputBandTypes[colorInterpretation.getBand(ColorInterpretation.RED_BAND)] != BufferManager.TYPE_BYTE)
|
|
76 |
|| (colorInterpretation.getBand(ColorInterpretation.GREEN_BAND)>=0 && inputBandTypes[colorInterpretation.getBand(ColorInterpretation.GREEN_BAND)] != BufferManager.TYPE_BYTE)
|
|
77 |
|| (colorInterpretation.getBand(ColorInterpretation.BLUE_BAND)>=0 && inputBandTypes[colorInterpretation.getBand(ColorInterpretation.BLUE_BAND)] != BufferManager.TYPE_BYTE)) {
|
|
90 | 78 |
throw new UnsupportedOperationException("The type of bands isn't BYTE"); |
91 | 79 |
} |
80 |
} else if (colorInterpretation.hasAnyGrayBand()) { |
|
81 |
if ((colorInterpretation.getBand(ColorInterpretation.GRAY_BAND)>=0 && inputBandTypes[colorInterpretation.getBand(ColorInterpretation.GRAY_BAND)] != BufferManager.TYPE_BYTE)) { |
|
82 |
throw new UnsupportedOperationException("The type of band gray isn't BYTE"); |
|
83 |
} |
|
92 | 84 |
} else { |
93 | 85 |
throw new UnsupportedOperationException( |
94 | 86 |
"The color interpretation of input buffer isn't RGB nor GRAYSCALE"); |
... | ... | |
144 | 136 |
@Override |
145 | 137 |
public void process() throws ProcessingOperationException { |
146 | 138 |
try { |
139 |
super.process(); |
|
147 | 140 |
List<Integer> bandsToProcess = new ArrayList<Integer>(); |
148 | 141 |
|
149 | 142 |
Band outputBufferBand = outputBuffer.getBand(0); |
... | ... | |
209 | 202 |
|
210 | 203 |
@Override |
211 | 204 |
public void postProcess() throws BufferOperationException { |
212 |
// TODO Auto-generated method stub |
|
213 |
|
|
205 |
super.postProcess(); |
|
214 | 206 |
} |
215 | 207 |
|
216 | 208 |
private void processRow(Object[] inputRows, Object outputRow) { |
... | ... | |
220 | 212 |
} |
221 | 213 |
byte[] outputByteRow = (byte[]) outputRow; |
222 | 214 |
for (int i = 0; i < inputByteRows[0].length; i++) { |
223 |
outputByteRow[i] = 0; |
|
215 |
|
|
216 |
int tmp = 0; |
|
217 |
|
|
224 | 218 |
for (int band = 0; band < inputRows.length; band++) { |
225 |
outputByteRow[i] += 0xFF & ((Byte) inputByteRows[band][i]).byteValue();
|
|
219 |
tmp += 0xFF & ((Byte) inputByteRows[band][i]).byteValue();
|
|
226 | 220 |
} |
227 |
outputByteRow[i] = (byte) (outputByteRow[i] / inputRows.length);
|
|
221 |
outputByteRow[i] = (byte) (tmp / inputRows.length);
|
|
228 | 222 |
} |
229 | 223 |
} |
230 | 224 |
} |
Also available in: Unified diff