Revision 8588 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/cmyktorgb/CMYKToRGBOperation.java
CMYKToRGBOperation.java | ||
---|---|---|
54 | 54 |
static public String COPY_UNPROCESSED_BANDS_PARAM = "copy_unprocessed_bands"; |
55 | 55 |
static public String OUTPUT_COLOR_INTERPRETATION_PARAM = "output_color_interpretation"; |
56 | 56 |
|
57 |
protected ColorInterpretation colorInterpretation;
|
|
58 |
protected boolean copyUnprocessedBands;
|
|
57 |
private ColorInterpretation colorInterpretation;
|
|
58 |
private boolean copyUnprocessedBands;
|
|
59 | 59 |
private ColorInterpretation outputColorInterpretation; |
60 | 60 |
|
61 | 61 |
/** |
... | ... | |
79 | 79 |
} |
80 | 80 |
|
81 | 81 |
try { |
82 |
if (!colorInterpretation.isHSL()) {
|
|
82 |
if (!colorInterpretation.isCMYK()) {
|
|
83 | 83 |
throw new UnsupportedOperationException("The color interpretation of input buffer isn't HSL"); |
84 | 84 |
} |
85 | 85 |
|
... | ... | |
100 | 100 |
List<Integer> types = new ArrayList<Integer>(); |
101 | 101 |
|
102 | 102 |
colorInterpretations.add(ColorInterpretation.RED_BAND); |
103 |
colorInterpretations.add(ColorInterpretation.GRAY_BAND);
|
|
103 |
colorInterpretations.add(ColorInterpretation.GREEN_BAND);
|
|
104 | 104 |
colorInterpretations.add(ColorInterpretation.BLUE_BAND); |
105 | 105 |
|
106 | 106 |
types.add(BufferManager.TYPE_BYTE); |
... | ... | |
123 | 123 |
|
124 | 124 |
if (copyUnprocessedBands) { |
125 | 125 |
for (int band = 0; band < sourceBands; band++) { |
126 |
if (!isProcessableBand(sourceBands) && !colorInterpretation.isAlphaInterpretation(band)) {
|
|
127 |
colorInterpretations.add(colorInterpretation.get(band));
|
|
126 |
if (!isProcessableBand(band) && !colorInterpretation.isAlphaInterpretation(band)) {
|
|
127 |
colorInterpretations.add(ColorInterpretation.UNDEFINED_BAND);
|
|
128 | 128 |
noDatas.add(sourceNoDatas[band]); |
129 | 129 |
types.add(this.buffer.getBandTypes()[band]); |
130 | 130 |
} |
... | ... | |
185 | 185 |
rowBandsBuffer[3] = bufferBandBlack.createRowBuffer(); |
186 | 186 |
bufferBandBlack.fetchRow(row, rowBandsBuffer[3]); |
187 | 187 |
|
188 |
Object[] outputRowsBuffer = new Object[3];
|
|
188 |
List<Object> outputRowBuffers = new ArrayList<Object>();
|
|
189 | 189 |
for (int band = 0; band < 3; band++) { |
190 | 190 |
Band outputBufferBand = outputBuffer.getBand(band); |
191 |
outputRowsBuffer[band] = outputBufferBand.createRowBuffer(); |
|
191 |
Object outputRowBuffer = outputBufferBand.createRowBuffer(); |
|
192 |
outputRowBuffers.add(outputRowBuffer); |
|
192 | 193 |
} |
193 | 194 |
|
194 |
processRow(rowBandsBuffer, outputRowsBuffer);
|
|
195 |
processRow(rowBandsBuffer, outputRowBuffers);
|
|
195 | 196 |
|
196 | 197 |
for (int band = 0; band < 3; band++) { |
197 | 198 |
Band outputBufferBand = outputBuffer.getBand(band); |
198 |
outputBufferBand.putRow(row, outputRowsBuffer[band]);
|
|
199 |
outputBufferBand.putRow(row, outputRowBuffers.get(band));
|
|
199 | 200 |
} |
200 | 201 |
|
201 | 202 |
} |
... | ... | |
211 | 212 |
|
212 | 213 |
} |
213 | 214 |
|
214 |
private void processRow(Object[] inputRows, Object[] outputRows) {
|
|
215 |
private void processRow(Object[] inputRows, List outputRows) {
|
|
215 | 216 |
ColorManager colorManager = ((RasterLegendManagerServices)RasterLegendLocator.getRasterLegendManager()).getColorManager(); |
216 | 217 |
byte[][] inputByteRows = new byte[inputRows.length][((byte[]) inputRows[0]).length]; |
217 | 218 |
for (int i = 0; i < inputRows.length; i++) { |
218 | 219 |
inputByteRows[i] = (byte[]) inputRows[i]; |
219 | 220 |
} |
220 |
byte[][] outputByteRow = (byte[][]) outputRows; |
|
221 | 221 |
int[] convertedValues = new int[3]; |
222 | 222 |
for (int i = 0; i < inputByteRows[0].length; i++) { |
223 | 223 |
|
224 |
double[] rgb = colorManager.CMYKtoRGB(inputByteRows[i][0], inputByteRows[i][1], inputByteRows[i][2], inputByteRows[i][2]); |
|
225 |
for (int band = 0; band < 3; band++) { |
|
226 |
convertedValues[band] = (int)(rgb[band] * 255); |
|
227 |
} |
|
224 |
double[] rgb = colorManager.CMYKtoRGB((0xFF & inputByteRows[0][i])/255D, (0xFF & inputByteRows[1][i])/255D, (0xFF & inputByteRows[2][i])/255D, (0xFF & inputByteRows[3][i])/255D); |
|
228 | 225 |
|
229 |
for (int band = 0; band < inputRows.length; band++) {
|
|
230 |
outputByteRow[i][band] = new Integer(convertedValues[i]).byteValue();
|
|
226 |
for (int band = 0; band < outputRows.size(); band++) {
|
|
227 |
((byte[])(outputRows.get(band)))[i] = new Double(rgb[band] * 255).byteValue();
|
|
231 | 228 |
} |
232 | 229 |
} |
233 | 230 |
} |
Also available in: Unified diff