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/cmyktorgb/CMYKToRGBOperation.java

View differences:

CMYKToRGBOperation.java
23 23
package org.gvsig.raster.lib.legend.impl.operations.cmyktorgb;
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;
......
35 34
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException;
36 35
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory;
37 36
import org.gvsig.raster.lib.buffer.spi.exceptions.ProcessingOperationException;
38
import org.gvsig.raster.lib.buffer.spi.operations.AbstractOperation;
39 37
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
40 38
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
41 39
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
......
56 54
     *
57 55
     */
58 56
    public CMYKToRGBOperation(OperationFactory factory) {
59
        this.factory = factory;
57
        super(factory);
60 58
    }
61 59

  
62 60
    @Override
......
67 65

  
68 66

  
69 67
        try {
70
            if (!colorInterpretation.isCMYK()) {
68
            if (!this.getInputColorInterpretation().isCMYK()) {
71 69
                throw new UnsupportedOperationException("The color interpretation of input buffer isn't CMYK");
72 70
            }
73 71

  
74
            int[] inputBandTypes = buffer.getBandTypes();
75
            if (inputBandTypes[colorInterpretation.getBand(ColorInterpretation.CYAN_BAND)] != BufferManager.TYPE_BYTE
76
                || inputBandTypes[colorInterpretation.getBand(ColorInterpretation.MAGENTA_BAND)] != BufferManager.TYPE_BYTE
77
                || inputBandTypes[colorInterpretation.getBand(ColorInterpretation.YELLOW_BAND)] != BufferManager.TYPE_BYTE
78
                || inputBandTypes[colorInterpretation.getBand(ColorInterpretation.BLACK_BAND)] != BufferManager.TYPE_BYTE) {
72
            int[] inputBandTypes = getInputBuffer().getBandTypes();
73
            if (inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.CYAN_BAND)] != BufferManager.TYPE_BYTE
74
                || inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.MAGENTA_BAND)] != BufferManager.TYPE_BYTE
75
                || inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.YELLOW_BAND)] != BufferManager.TYPE_BYTE
76
                || inputBandTypes[getInputColorInterpretation().getBand(ColorInterpretation.BLACK_BAND)] != BufferManager.TYPE_BYTE) {
79 77
                throw new UnsupportedOperationException("The type of bands isn't BYTE");
80 78
            }
81 79

  
82
            int sourceBands = this.buffer.getBandCount();
83
            NoData[] sourceNoDatas = this.buffer.getBandNoData();
84
            int[] sourceTypes = this.buffer.getBandTypes();
80
            int sourceBands = this.getInputBuffer().getBandCount();
81
            NoData[] sourceNoDatas = this.getInputBuffer().getBandNoData();
82
            int[] sourceTypes = this.getInputBuffer().getBandTypes();
85 83

  
86
            List<String> colorInterpretations = new ArrayList<String>();
87
            List<NoData> noDatas = new ArrayList<NoData>();
88
            List<Integer> types = new ArrayList<Integer>();
84
            List<String> colorInterpretations = new ArrayList<>();
85
            List<NoData> noDatas = new ArrayList<>();
86
            List<Integer> types = new ArrayList<>();
89 87

  
90 88
            colorInterpretations.add(ColorInterpretation.RED_BAND);
91 89
            colorInterpretations.add(ColorInterpretation.GREEN_BAND);
......
99 97
            noDatas.add(null);
100 98
            noDatas.add(null);
101 99

  
102
            if (colorInterpretation.hasAlphaBand()) {
103
                int alphaBand = colorInterpretation.getAlphaBand();
100
            if (getInputColorInterpretation().hasAlphaBand()) {
101
                int alphaBand = getInputColorInterpretation().getAlphaBand();
104 102
                if(sourceTypes[alphaBand]!=BufferManager.TYPE_BYTE){
105 103
                    throw new UnsupportedOperationException("The type of ALPHA band isn't BYTE");
106 104
                }
......
109 107
                noDatas.add(sourceNoDatas[alphaBand]);
110 108
            }
111 109

  
112
            if (copyUnprocessedBands) {
110
            if (mustCopyUnprocessedBands()) {
113 111
                for (int band = 0; band < sourceBands; band++) {
114
                    if (!isProcessableBand(band) && !colorInterpretation.isAlphaInterpretation(band)) {
112
                    if (!isProcessableBand(band) && !getInputColorInterpretation().isAlphaInterpretation(band)) {
115 113
                        colorInterpretations.add(ColorInterpretation.UNDEFINED_BAND);
116 114
                        noDatas.add(sourceNoDatas[band]);
117
                        types.add(this.buffer.getBandTypes()[band]);
115
                        types.add(this.getInputBuffer().getBandTypes()[band]);
118 116
                    }
119 117
                }
120 118
            }
121 119

  
122
            outputColorInterpretation =
123
                legendManager.createColorInterpretation(colorInterpretations.toArray(new String[0]));
124
            this.parameters.setDynValue(OUTPUT_COLOR_INTERPRETATION_PARAM, outputColorInterpretation);
125
            int[] typesInt = new int[types.size()];
126
            for (Iterator<Integer> iterator = types.iterator(); iterator.hasNext();) {
127
                int i = 0;
128
                Integer type = (Integer) iterator.next();
129
                typesInt[i] = type.intValue();
130
            }
120
            setOutputColorInterpretation(
121
                legendManager.createColorInterpretation(colorInterpretations));
122
            this.setParameter(
123
                    OUTPUT_COLOR_INTERPRETATION_PARAM, 
124
                    getOutputColorInterpretation());
131 125

  
132
            this.outputBuffer =
133
                manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), typesInt,
134
                    noDatas.toArray(new NoData[0]), this.buffer.getProjection(), this.buffer.getEnvelope());
126

  
127
            this.setOutputBuffer(
128
                manager.createBuffer(
129
                        this.getInputBuffer().getRows(), 
130
                        this.getInputBuffer().getColumns(), 
131
                        this.getTypesAsArray(types),
132
                        this.getNoDatasAsArray(noDatas), 
133
                        this.getInputBuffer().getProjection(), 
134
                        this.getInputBuffer().getEnvelope()));
135 135
        } catch (LocatorException | BufferException | CreateEnvelopeException e) {
136 136
            throw new ProcessingOperationException(e);
137 137
        }
......
143 143
            super.process();
144 144
            // List<Integer> bandsToProcess = new ArrayList<Integer>();
145 145

  
146
            if (copyUnprocessedBands) {
147
                int bands = this.buffer.getBandCount();
148
                int outBand = colorInterpretation.hasAlphaBand() ? 4 : 3;
146
            if (mustCopyUnprocessedBands()) {
147
                int bands = this.getInputBuffer().getBandCount();
148
                int outBand = getInputColorInterpretation().hasAlphaBand() ? 4 : 3;
149 149
                for (int band = 0; band < bands; band++) {
150
                    if (colorInterpretation.isAlphaInterpretation(band)) {
151
                        outputBuffer.getBand(outputColorInterpretation.getAlphaBand()).copyFrom(
152
                            this.buffer.getBand(band));
150
                    if (getInputColorInterpretation().isAlphaInterpretation(band)) {
151
                        getOutputBuffer().getBand(getInputColorInterpretation().getAlphaBand()).copyFrom(
152
                            this.getInputBuffer().getBand(band));
153 153
                    } else if (!isProcessableBand(band)) {
154
                        outputBuffer.getBand(outBand).copyFrom(this.buffer.getBand(band));
154
                        getOutputBuffer().getBand(outBand).copyFrom(this.getInputBuffer().getBand(band));
155 155
                        outBand++;
156 156
                    }
157 157
                }
......
159 159

  
160 160
            Object[] rowBandsBuffer = new Object[4];
161 161

  
162
            for (int row = 0; row < this.buffer.getRows(); row++) {
163
                Band bufferBandCyan = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.CYAN_BAND));
162
            for (int row = 0; row < this.getInputBuffer().getRows(); row++) {
163
                Band bufferBandCyan = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.CYAN_BAND));
164 164
                rowBandsBuffer[0] = bufferBandCyan.createRowBuffer();
165 165
                bufferBandCyan.fetchRow(row, rowBandsBuffer[0]);
166
                Band bufferBandMagenta = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.MAGENTA_BAND));
166
                Band bufferBandMagenta = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.MAGENTA_BAND));
167 167
                rowBandsBuffer[1] = bufferBandMagenta.createRowBuffer();
168 168
                bufferBandMagenta.fetchRow(row, rowBandsBuffer[1]);
169
                Band bufferBandYellow = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.YELLOW_BAND));
169
                Band bufferBandYellow = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.YELLOW_BAND));
170 170
                rowBandsBuffer[2] = bufferBandYellow.createRowBuffer();
171 171
                bufferBandYellow.fetchRow(row, rowBandsBuffer[2]);
172
                Band bufferBandBlack = buffer.getBand(colorInterpretation.getBand(ColorInterpretation.BLACK_BAND));
172
                Band bufferBandBlack = getInputBuffer().getBand(getInputColorInterpretation().getBand(ColorInterpretation.BLACK_BAND));
173 173
                rowBandsBuffer[3] = bufferBandBlack.createRowBuffer();
174 174
                bufferBandBlack.fetchRow(row, rowBandsBuffer[3]);
175 175

  
176
                List<Object> outputRowBuffers = new ArrayList<Object>();
176
                List<Object> outputRowBuffers = new ArrayList<>();
177 177
                for (int band = 0; band < 3; band++) {
178
                    Band outputBufferBand = outputBuffer.getBand(band);
178
                    Band outputBufferBand = getOutputBuffer().getBand(band);
179 179
                    Object outputRowBuffer = outputBufferBand.createRowBuffer();
180 180
                    outputRowBuffers.add(outputRowBuffer);
181 181
                }
......
183 183
                processRow(rowBandsBuffer, outputRowBuffers);
184 184

  
185 185
                for (int band = 0; band < 3; band++) {
186
                    Band outputBufferBand = outputBuffer.getBand(band);
186
                    Band outputBufferBand = getOutputBuffer().getBand(band);
187 187
                    outputBufferBand.putRow(row, outputRowBuffers.get(band));
188 188
                }
189 189

  
......
221 221
     * @param band
222 222
     * @return
223 223
     */
224
    private boolean isProcessableBand(int band) {
225
        return isCMYKBand(band) && this.buffer.getBandTypes()[band] == BufferManager.TYPE_BYTE;
224
    @Override
225
    protected boolean isProcessableBand(int band) {
226
        return isCMYKBand(band) && this.getInputBuffer().getBandTypes()[band] == BufferManager.TYPE_BYTE;
226 227
    }
227 228

  
228 229
    private boolean isCMYKBand(int band) {
229
        String bandColorInterpretation = colorInterpretation.get(band);
230
        String bandColorInterpretation = getInputColorInterpretation().get(band);
230 231
        return (bandColorInterpretation.equals(ColorInterpretation.CYAN_BAND)
231 232
            || bandColorInterpretation.equals(ColorInterpretation.MAGENTA_BAND)
232 233
            || bandColorInterpretation.equals(ColorInterpretation.YELLOW_BAND)

Also available in: Unified diff