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/equalization/EqualizationOperation.java

View differences:

EqualizationOperation.java
38 38
import org.gvsig.raster.lib.buffer.api.statistics.HistogramBand;
39 39
import org.gvsig.raster.lib.buffer.api.statistics.Statistics;
40 40
import org.gvsig.raster.lib.buffer.spi.exceptions.ProcessingOperationException;
41
import org.gvsig.raster.lib.buffer.spi.operations.AbstractOperation;
42 41
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
43 42
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
44 43
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
......
71 70
     *
72 71
     */
73 72
    public EqualizationOperation(OperationFactory factory) {
74
        this.factory = factory;
73
        super(factory);
75 74
    }
76 75

  
77 76
    @Override
......
80 79
        BufferManager manager = BufferLocator.getBufferManager();
81 80
        RasterLegendManager legendManager = RasterLegendLocator.getRasterLegendManager();
82 81

  
83
        if(this.parameters.getDynClass().getDynField(STATISTICS_PARAM)!=null) {
84
            statistics = (Statistics) this.parameters.getDynValue(STATISTICS_PARAM);
82
        statistics = (Statistics) this.getParameter(STATISTICS_PARAM,null);
83
        if (statistics==null) {
84
            statistics = this.getInputBuffer().getStatistics(null);
85 85
        }
86
        if (statistics==null) {
87
            statistics = this.buffer.getStatistics(null);
88
        };
89 86
        histogramBands = statistics.getHistogram();
90 87

  
91
        int bands = this.buffer.getBandCount();
92
        NoData[] noData = this.buffer.getBandNoData();
88
        int bands = this.getInputBuffer().getBandCount();
89
        NoData[] noData = this.getInputBuffer().getBandNoData();
93 90

  
94 91

  
95
        if (copyUnprocessedBands) {
96
            this.parameters.setDynValue(OUTPUT_COLOR_INTERPRETATION_PARAM, colorInterpretation);
97
            noData = this.buffer.getBandNoData();
92
        if (mustCopyUnprocessedBands()) {
93
            this.setParameter(OUTPUT_COLOR_INTERPRETATION_PARAM, getInputColorInterpretation());
94
            noData = this.getInputBuffer().getBandNoData();
98 95
            try {
99
                this.outputBuffer =
100
                    manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), this.buffer.getBandTypes(),
101
                        this.buffer.getBandNoData(), this.buffer.getProjection(), this.buffer.getEnvelope());
96
                this.setOutputBuffer(
97
                    manager.createBuffer(
98
                            this.getInputBuffer().getRows(), 
99
                            this.getInputBuffer().getColumns(), 
100
                            this.getInputBuffer().getBandTypes(),
101
                            this.getInputBuffer().getBandNoData(), 
102
                            this.getInputBuffer().getProjection(), 
103
                            this.getInputBuffer().getEnvelope()));
102 104
            } catch (LocatorException | BufferException | CreateEnvelopeException e) {
103 105
                throw new ProcessingOperationException(e);
104 106
            }
105 107
        } else {
106
            List<String> colorInterpretations = new ArrayList<String>();
107
            List<NoData> noDatas = new ArrayList<NoData>();
108
            List<Integer> types = new ArrayList<Integer>();
108
            List<String> colorInterpretations = new ArrayList<>();
109
            List<NoData> noDatas = new ArrayList<>();
110
            List<Integer> types = new ArrayList<>();
109 111
            for (int band = 0; band < bands; band++) {
110 112
                if (isProcessableBand(band)) {
111
                    colorInterpretations.add(colorInterpretation.get(band));
112
                    noDatas.add(this.buffer.getBandNoData()[band]);
113
                    types.add(this.buffer.getBandTypes()[band]);
113
                    colorInterpretations.add(getInputColorInterpretation().get(band));
114
                    noDatas.add(this.getInputBuffer().getBandNoData()[band]);
115
                    types.add(this.getInputBuffer().getBandTypes()[band]);
114 116
                }
115 117
            }
116
            if (colorInterpretation.hasAlphaBand()) {
118
            if (getInputColorInterpretation().hasAlphaBand()) {
117 119
                colorInterpretations.add(ColorInterpretation.ALPHA_BAND);
118 120
            }
119
            outputColorInterpretation = legendManager.createColorInterpretation(colorInterpretations.toArray(new String[0]));
120
            this.parameters.setDynValue(OUTPUT_COLOR_INTERPRETATION_PARAM, outputColorInterpretation);
121
            int[] typesInt = new int[types.size()];
122
            for (Iterator iterator = types.iterator(); iterator.hasNext();) {
123
                int i = 0;
124
                Integer type = (Integer) iterator.next();
125
                typesInt[i] = type.intValue();
126
            }
121
            setOutputColorInterpretation(
122
                    legendManager.createColorInterpretation(colorInterpretations));
123
            this.setParameter(OUTPUT_COLOR_INTERPRETATION_PARAM, getOutputColorInterpretation());
127 124
            try {
128
                this.outputBuffer =
129
                    manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), typesInt,
130
                        noDatas.toArray(new NoData[0]), this.buffer.getProjection(), this.buffer.getEnvelope());
131
            } catch (LocatorException | BufferException | CreateEnvelopeException e) {
125
                this.setOutputBuffer(
126
                    manager.createBuffer(
127
                            this.getInputBuffer().getRows(), 
128
                            this.getInputBuffer().getColumns(), 
129
                            this.getTypesAsArray(types),
130
                            this.getNoDatasAsArray(noDatas), 
131
                            this.getInputBuffer().getProjection(), 
132
                            this.getInputBuffer().getEnvelope()));
133
            } catch (Exception e) {
132 134
                throw new ProcessingOperationException(e);
133 135
            }
134 136
        }
......
139 141
            throw new ProcessingOperationException("There is no RGB band.", null);
140 142
        }
141 143
        for (Iterator<Integer> iterator = getBandsToProcess().iterator(); iterator.hasNext();) {
142
            Integer band = (Integer) iterator.next();
143
            int bandType = this.buffer.getBand(band).getDataType();
144
            Integer band = iterator.next();
145
            int bandType = this.getInputBuffer().getBand(band).getDataType();
144 146
            if(dataType!=null) {
145 147
                if(dataType!=bandType){
146 148
                    throw new IllegalArgumentException("All bands must be of same data type.");
......
302 304
    @Override
303 305
    public void process() throws ProcessingOperationException {
304 306
        super.process();
305
        for (int band=0; band<this.buffer.getBandCount(); band++){
307
        for (int band=0; band<this.getInputBuffer().getBandCount(); band++){
306 308
            if (getBandsToProcess().contains(band)) {
307
                Band bufferBand = this.buffer.getBand(band);
308
                Band outputBufferBand = this.outputBuffer.getBand(band);
309
                Band bufferBand = this.getInputBuffer().getBand(band);
310
                Band outputBufferBand = this.getOutputBuffer().getBand(band);
309 311

  
310
                for (int row = 0; row < this.buffer.getRows(); row++) {
312
                for (int row = 0; row < this.getInputBuffer().getRows(); row++) {
311 313
                    Object rowBuffer = bufferBand.createRowBuffer();
312 314
                    bufferBand.fetchRow(row, rowBuffer);
313 315

  
......
320 322
                }
321 323
            } else {
322 324
                try {
323
                    this.outputBuffer.getBand(band).copyFrom(this.buffer.getBand(band));
325
                    this.getOutputBuffer().getBand(band).copyFrom(this.getInputBuffer().getBand(band));
324 326
                } catch (BandException e) {
325 327
                    throw new ProcessingOperationException(e);
326 328
                }
......
356 358
     */
357 359
    private List<Integer> getBandsToProcess() {
358 360
        if(bandsToProcess == null){
359
            int bands = this.buffer.getBandCount();
360
            bandsToProcess = new ArrayList<Integer>();
361
            int bands = this.getInputBuffer().getBandCount();
362
            bandsToProcess = new ArrayList<>();
361 363

  
362 364
            for (int band = 0; band < bands; band++) {
363 365
                if (isProcessableBand(band)) {
......
372 374
     * @param band
373 375
     * @return
374 376
     */
375
    private boolean isProcessableBand(int band) {
376
        return isRGBBand(band) && (this.buffer.getBandTypes()[band] == BufferManager.TYPE_BYTE
377
            || this.buffer.getBandTypes()[band] == BufferManager.TYPE_SHORT
378
            || this.buffer.getBandTypes()[band] == BufferManager.TYPE_USHORT
379
            || this.buffer.getBandTypes()[band] == BufferManager.TYPE_INT
377
    @Override
378
    protected boolean isProcessableBand(int band) {
379
        return isRGBBand(band) && (this.getInputBuffer().getBandTypes()[band] == BufferManager.TYPE_BYTE
380
            || this.getInputBuffer().getBandTypes()[band] == BufferManager.TYPE_SHORT
381
            || this.getInputBuffer().getBandTypes()[band] == BufferManager.TYPE_USHORT
382
            || this.getInputBuffer().getBandTypes()[band] == BufferManager.TYPE_INT
380 383
        );
381 384
    }
382 385

  
383 386
    private boolean isRGBBand(int band) {
384
        String bandColorInterpretation = colorInterpretation.get(band);
387
        String bandColorInterpretation = getInputColorInterpretation().get(band);
385 388
        return (bandColorInterpretation.equals(ColorInterpretation.RED_BAND) ||
386 389
            bandColorInterpretation.equals(ColorInterpretation.GREEN_BAND) ||
387 390
            bandColorInterpretation.equals(ColorInterpretation.BLUE_BAND));
......
401 404
        public AbstractRowProcessor(int band) {
402 405
            this.band = band;
403 406
            this.histogram = statistics.getHistogram()[this.band];
404
            this.noData = buffer.getBand(this.band).getNoData();
407
            this.noData = getInputBuffer().getBand(this.band).getNoData();
405 408
        }
406 409
    }
407 410

  
......
429 432
            }
430 433

  
431 434
            //M?todo lahe
432
            int intValue = 0xFF & ((Byte) value).byteValue();
433
            int equalizationPositive = (int)lahe[getBandsToProcess().indexOf(new Integer(band))][intValue % (int)histogram.getNumValues()];
434
            int equalizationNegative = (int)laheNegative[getBandsToProcess().indexOf(new Integer(band))][nElements - (intValue % (int)histogram.getNumValues())];
435
            int intValue = 0xFF & ((Byte) value);
436
            int equalizationPositive = (int)lahe[getBandsToProcess().indexOf(band)][intValue % (int)histogram.getNumValues()];
437
            int equalizationNegative = (int)laheNegative[getBandsToProcess().indexOf(band)][nElements - (intValue % (int)histogram.getNumValues())];
435 438

  
436 439
            int resValue = ((nElements - equalizationNegative) + equalizationPositive) / 2;
437 440
            return (byte)(resValue & 0x000000ff);
......
461 464

  
462 465
            //M?todo lahe
463 466
            int intValue = ((Short) value).byteValue();
464
            int equalizationPositive = (int)lahe[getBandsToProcess().indexOf(new Integer(band))][intValue % (int)histogram.getNumValues()];
465
            int equalizationNegative = (int)laheNegative[getBandsToProcess().indexOf(new Integer(band))][nElements - (intValue % (int)histogram.getNumValues())];
467
            int equalizationPositive = (int)lahe[getBandsToProcess().indexOf(band)][intValue % (int)histogram.getNumValues()];
468
            int equalizationNegative = (int)laheNegative[getBandsToProcess().indexOf(band)][nElements - (intValue % (int)histogram.getNumValues())];
466 469

  
467 470
            int resValue = ((nElements - equalizationNegative) + equalizationPositive) / 2;
468 471
            return (short)resValue;
......
493 496

  
494 497
            //M?todo lahe
495 498
            int intValue = 0xFFFF & ((Short) value).byteValue();
496
            int equalizationPositive = (int)lahe[getBandsToProcess().indexOf(new Integer(band))][intValue % (int)histogram.getNumValues()];
497
            int equalizationNegative = (int)laheNegative[getBandsToProcess().indexOf(new Integer(band))][nElements - (intValue % (int)histogram.getNumValues())];
499
            int equalizationPositive = (int)lahe[getBandsToProcess().indexOf(band)][intValue % (int)histogram.getNumValues()];
500
            int equalizationNegative = (int)laheNegative[getBandsToProcess().indexOf(band)][nElements - (intValue % (int)histogram.getNumValues())];
498 501

  
499 502
            int resValue = ((nElements - equalizationNegative) + equalizationPositive) / 2;
500 503
            return (short)resValue;
......
526 529
            Double dValue = ((Number) value).doubleValue();
527 530

  
528 531
            //M?todo lahe
529
            int intValue = ((Integer) value).intValue();
530
            int equalizationPositive = (int)lahe[getBandsToProcess().indexOf(new Integer(band))][intValue % (int)histogram.getNumValues()];
531
            int equalizationNegative = (int)laheNegative[getBandsToProcess().indexOf(new Integer(band))][nElements - (intValue % (int)histogram.getNumValues())];
532
            int intValue = ((Integer) value);
533
            int equalizationPositive = (int)lahe[getBandsToProcess().indexOf(band)][intValue % (int)histogram.getNumValues()];
534
            int equalizationNegative = (int)laheNegative[getBandsToProcess().indexOf(band)][nElements - (intValue % (int)histogram.getNumValues())];
532 535

  
533 536
            int resValue = ((nElements - equalizationNegative) + equalizationPositive) / 2;
534 537
            return (int)resValue;

Also available in: Unified diff